summaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
authorPavan Deolasee2017-06-15 07:41:07 +0000
committerPavan Deolasee2017-06-15 07:41:07 +0000
commit0ffa504a17f58f2bc045b0039f40e4917ee50d20 (patch)
treec629c449bcfcc45de1d03b2586e89932d546e8ba /src/interfaces
parent36ccc8d64e61fe9d77bb7ac62267945f7c146baa (diff)
parente800656d9a9b40b2f55afabe76354ab6d93353b3 (diff)
Merge 'remotes/PGSQL/master' into xl10devel
Merge upstream master branch upto e800656d9a9b40b2f55afabe76354ab6d93353b3. Code compiles and regression works ok (with lots and lots of failures though).
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/ecpg/ecpglib/pg_type.h28
-rw-r--r--src/interfaces/libpq/fe-auth.c19
-rw-r--r--src/interfaces/libpq/fe-connect.c137
-rw-r--r--src/interfaces/libpq/test/README2
4 files changed, 112 insertions, 74 deletions
diff --git a/src/interfaces/ecpg/ecpglib/pg_type.h b/src/interfaces/ecpg/ecpglib/pg_type.h
index a2f44324ba..48ae480129 100644
--- a/src/interfaces/ecpg/ecpglib/pg_type.h
+++ b/src/interfaces/ecpg/ecpglib/pg_type.h
@@ -57,23 +57,23 @@
#define ZPBITOID 1560
#define VARBITOID 1562
#define NUMERICOID 1700
-#define REFCURSOROID 1790
+#define REFCURSOROID 1790
#define REGPROCEDUREOID 2202
-#define REGOPEROID 2203
-#define REGOPERATOROID 2204
-#define REGCLASSOID 2205
-#define REGTYPEOID 2206
-#define REGROLEOID 4096
-#define REGNAMESPACEOID 4089
+#define REGOPEROID 2203
+#define REGOPERATOROID 2204
+#define REGCLASSOID 2205
+#define REGTYPEOID 2206
+#define REGROLEOID 4096
+#define REGNAMESPACEOID 4089
#define REGTYPEARRAYOID 2211
#define UUIDOID 2950
-#define LSNOID 3220
-#define TSVECTOROID 3614
-#define GTSVECTOROID 3642
-#define TSQUERYOID 3615
-#define REGCONFIGOID 3734
-#define REGDICTIONARYOID 3769
+#define LSNOID 3220
+#define TSVECTOROID 3614
+#define GTSVECTOROID 3642
+#define TSQUERYOID 3615
+#define REGCONFIGOID 3734
+#define REGDICTIONARYOID 3769
#define JSONBOID 3802
-#define INT4RANGEOID 3904
+#define INT4RANGEOID 3904
#endif /* PG_TYPE_H */
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 16956dc3f7..74086545bf 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -136,6 +136,11 @@ pg_GSS_continue(PGconn *conn, int payloadlen)
return STATUS_ERROR;
}
}
+ else
+ {
+ ginbuf.length = 0;
+ ginbuf.value = NULL;
+ }
maj_stat = gss_init_sec_context(&min_stat,
GSS_C_NO_CREDENTIAL,
@@ -145,13 +150,13 @@ pg_GSS_continue(PGconn *conn, int payloadlen)
GSS_C_MUTUAL_FLAG,
0,
GSS_C_NO_CHANNEL_BINDINGS,
- (conn->gctx == GSS_C_NO_CONTEXT) ? GSS_C_NO_BUFFER : &ginbuf,
+ (ginbuf.value == NULL) ? GSS_C_NO_BUFFER : &ginbuf,
NULL,
&goutbuf,
NULL,
NULL);
- if (conn->gctx != GSS_C_NO_CONTEXT)
+ if (ginbuf.value)
free(ginbuf.value);
if (goutbuf.length != 0)
@@ -414,7 +419,12 @@ pg_SSPI_startup(PGconn *conn, int use_negotiate, int payloadlen)
TimeStamp expire;
char *host = PQhost(conn);
- conn->sspictx = NULL;
+ if (conn->sspictx)
+ {
+ printfPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("duplicate SSPI authentication request\n"));
+ return STATUS_ERROR;
+ }
/*
* Retrieve credentials handle
@@ -1211,7 +1221,8 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
else
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unknown password encryption algorithm\n"));
+ libpq_gettext("unrecognized password encryption algorithm \"%s\"\n"),
+ algorithm);
return NULL;
}
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index f2c9bf7a88..02ec8f0cea 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -406,15 +406,59 @@ pqDropConnection(PGconn *conn, bool flushInput)
{
/* Drop any SSL state */
pqsecure_close(conn);
+
/* Close the socket itself */
if (conn->sock != PGINVALID_SOCKET)
closesocket(conn->sock);
conn->sock = PGINVALID_SOCKET;
+
/* Optionally discard any unread data */
if (flushInput)
conn->inStart = conn->inCursor = conn->inEnd = 0;
+
/* Always discard any unsent data */
conn->outCount = 0;
+
+ /* Free authentication state */
+#ifdef ENABLE_GSS
+ {
+ OM_uint32 min_s;
+
+ if (conn->gctx)
+ gss_delete_sec_context(&min_s, &conn->gctx, GSS_C_NO_BUFFER);
+ if (conn->gtarg_nam)
+ gss_release_name(&min_s, &conn->gtarg_nam);
+ }
+#endif
+#ifdef ENABLE_SSPI
+ if (conn->sspitarget)
+ {
+ free(conn->sspitarget);
+ conn->sspitarget = NULL;
+ }
+ if (conn->sspicred)
+ {
+ FreeCredentialsHandle(conn->sspicred);
+ free(conn->sspicred);
+ conn->sspicred = NULL;
+ }
+ if (conn->sspictx)
+ {
+ DeleteSecurityContext(conn->sspictx);
+ free(conn->sspictx);
+ conn->sspictx = NULL;
+ }
+ conn->usesspi = 0;
+#endif
+ if (conn->sasl_state)
+ {
+ /*
+ * XXX: if support for more authentication mechanisms is added, this
+ * needs to call the right 'free' function.
+ */
+ pg_fe_scram_free(conn->sasl_state);
+ conn->sasl_state = NULL;
+ }
}
@@ -1598,7 +1642,6 @@ connectDBStart(PGconn *conn)
for (i = 0; i < conn->nconnhost; ++i)
{
pg_conn_host *ch = &conn->connhost[i];
- char *node = ch->host;
struct addrinfo hint;
int thisport;
@@ -1624,17 +1667,29 @@ connectDBStart(PGconn *conn)
}
snprintf(portstr, sizeof(portstr), "%d", thisport);
- /* Set up for name resolution. */
+ /* Use pg_getaddrinfo_all() to resolve the address */
+ ret = 1;
switch (ch->type)
{
case CHT_HOST_NAME:
+ ret = pg_getaddrinfo_all(ch->host, portstr, &hint, &ch->addrlist);
+ if (ret || !ch->addrlist)
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("could not translate host name \"%s\" to address: %s\n"),
+ ch->host, gai_strerror(ret));
break;
+
case CHT_HOST_ADDRESS:
hint.ai_flags = AI_NUMERICHOST;
+ ret = pg_getaddrinfo_all(ch->host, portstr, &hint, &ch->addrlist);
+ if (ret || !ch->addrlist)
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("could not parse network address \"%s\": %s\n"),
+ ch->host, gai_strerror(ret));
break;
+
case CHT_UNIX_SOCKET:
#ifdef HAVE_UNIX_SOCKETS
- node = NULL;
hint.ai_family = AF_UNIX;
UNIXSOCK_PATH(portstr, thisport, ch->host);
if (strlen(portstr) >= UNIXSOCK_PATH_BUFLEN)
@@ -1646,24 +1701,25 @@ connectDBStart(PGconn *conn)
conn->options_valid = false;
goto connect_errReturn;
}
+
+ /*
+ * NULL hostname tells pg_getaddrinfo_all to parse the service
+ * name as a Unix-domain socket path.
+ */
+ ret = pg_getaddrinfo_all(NULL, portstr, &hint, &ch->addrlist);
+ if (ret || !ch->addrlist)
+ appendPQExpBuffer(&conn->errorMessage,
+ libpq_gettext("could not translate Unix-domain socket path \"%s\" to address: %s\n"),
+ portstr, gai_strerror(ret));
+ break;
#else
Assert(false);
+ conn->options_valid = false;
+ goto connect_errReturn;
#endif
- break;
}
-
- /* Use pg_getaddrinfo_all() to resolve the address */
- ret = pg_getaddrinfo_all(node, portstr, &hint, &ch->addrlist);
if (ret || !ch->addrlist)
{
- if (node)
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("could not translate host name \"%s\" to address: %s\n"),
- node, gai_strerror(ret));
- else
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("could not translate Unix-domain socket path \"%s\" to address: %s\n"),
- portstr, gai_strerror(ret));
if (ch->addrlist)
{
pg_freeaddrinfo_all(hint.ai_family, ch->addrlist);
@@ -1786,16 +1842,23 @@ connectDBComplete(PGconn *conn)
return 0;
}
- if (ret == 1) /* connect_timeout elapsed */
+ if (ret == 1) /* connect_timeout elapsed */
{
- /* If there are no more hosts, return (the error message is already set) */
+ /*
+ * If there are no more hosts, return (the error message is
+ * already set)
+ */
if (++conn->whichhost >= conn->nconnhost)
{
conn->whichhost = 0;
conn->status = CONNECTION_BAD;
return 0;
}
- /* Attempt connection to the next host, starting the connect_timeout timer */
+
+ /*
+ * Attempt connection to the next host, starting the
+ * connect_timeout timer
+ */
pqDropConnection(conn, true);
conn->addr_cur = conn->connhost[conn->whichhost].addrlist;
conn->status = CONNECTION_NEEDED;
@@ -3043,7 +3106,7 @@ keep_going: /* We will come back to here until there is
restoreErrorMessage(conn, &savedMessage);
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("test \"SHOW transaction_read_only\" failed "
- " on \"%s:%s\"\n"),
+ "on server \"%s:%s\"\n"),
conn->connhost[conn->whichhost].host,
conn->connhost[conn->whichhost].port);
conn->status = CONNECTION_OK;
@@ -3475,42 +3538,6 @@ closePGconn(PGconn *conn)
if (conn->lobjfuncs)
free(conn->lobjfuncs);
conn->lobjfuncs = NULL;
-#ifdef ENABLE_GSS
- {
- OM_uint32 min_s;
-
- if (conn->gctx)
- gss_delete_sec_context(&min_s, &conn->gctx, GSS_C_NO_BUFFER);
- if (conn->gtarg_nam)
- gss_release_name(&min_s, &conn->gtarg_nam);
- }
-#endif
-#ifdef ENABLE_SSPI
- if (conn->sspitarget)
- free(conn->sspitarget);
- conn->sspitarget = NULL;
- if (conn->sspicred)
- {
- FreeCredentialsHandle(conn->sspicred);
- free(conn->sspicred);
- conn->sspicred = NULL;
- }
- if (conn->sspictx)
- {
- DeleteSecurityContext(conn->sspictx);
- free(conn->sspictx);
- conn->sspictx = NULL;
- }
-#endif
- if (conn->sasl_state)
- {
- /*
- * XXX: if support for more authentication mechanisms is added, this
- * needs to call the right 'free' function.
- */
- pg_fe_scram_free(conn->sasl_state);
- conn->sasl_state = NULL;
- }
}
/*
diff --git a/src/interfaces/libpq/test/README b/src/interfaces/libpq/test/README
index 001ecc378d..a05eb6bb3b 100644
--- a/src/interfaces/libpq/test/README
+++ b/src/interfaces/libpq/test/README
@@ -1,7 +1,7 @@
This is a testsuite for testing libpq URI connection string syntax.
To run the suite, use 'make installcheck' command. It works by
-running 'regress.sh' from this directory with appropriate environment
+running 'regress.pl' from this directory with appropriate environment
set up, which in turn feeds up lines from 'regress.in' to
'uri-regress' test program and compares the output against the correct
one in 'expected.out' file.