33 #include "pg_config_paths.h"
41 #define _WIN32_IE 0x0500
55 #ifdef ENABLE_THREAD_SAFETY
68 #define LDAP_DEPRECATED 1
70 typedef struct timeval LDAP_TIMEVAL;
77 #define PGPASSFILE ".pgpass"
79 #define PGPASSFILE "pgpass.conf"
88 #define ERRCODE_APPNAME_UNKNOWN "42704"
91 #define ERRCODE_INVALID_PASSWORD "28P01"
93 #define ERRCODE_CANNOT_CONNECT_NOW "57P03"
99 #if defined(TCP_KEEPIDLE)
101 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
102 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
103 #elif defined(TCP_KEEPALIVE_THRESHOLD)
105 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
106 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
107 #elif defined(TCP_KEEPALIVE) && defined(__darwin__)
110 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
111 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
118 #define DefaultHost "localhost"
119 #define DefaultOption ""
121 #define DefaultChannelBinding "prefer"
123 #define DefaultChannelBinding "disable"
125 #define DefaultTargetSessionAttrs "any"
126 #define DefaultLoadBalanceHosts "disable"
128 #define DefaultSSLMode "prefer"
129 #define DefaultSSLCertMode "allow"
131 #define DefaultSSLMode "disable"
132 #define DefaultSSLCertMode "disable"
136 #define DefaultGSSMode "prefer"
138 #define DefaultGSSMode "disable"
192 {
"service",
"PGSERVICE", NULL, NULL,
193 "Database-Service",
"", 20, -1},
195 {
"user",
"PGUSER", NULL, NULL,
196 "Database-User",
"", 20,
197 offsetof(
struct pg_conn, pguser)},
199 {
"password",
"PGPASSWORD", NULL, NULL,
200 "Database-Password",
"*", 20,
201 offsetof(
struct pg_conn, pgpass)},
203 {
"passfile",
"PGPASSFILE", NULL, NULL,
204 "Database-Password-File",
"", 64,
205 offsetof(
struct pg_conn, pgpassfile)},
208 "Channel-Binding",
"", 8,
209 offsetof(
struct pg_conn, channel_binding)},
211 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
212 "Connect-timeout",
"", 10,
213 offsetof(
struct pg_conn, connect_timeout)},
215 {
"dbname",
"PGDATABASE", NULL, NULL,
216 "Database-Name",
"", 20,
219 {
"host",
"PGHOST", NULL, NULL,
220 "Database-Host",
"", 40,
223 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
224 "Database-Host-IP-Address",
"", 45,
225 offsetof(
struct pg_conn, pghostaddr)},
227 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
228 "Database-Port",
"", 6,
231 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
232 "Client-Encoding",
"", 10,
233 offsetof(
struct pg_conn, client_encoding_initial)},
236 "Backend-Options",
"", 40,
237 offsetof(
struct pg_conn, pgoptions)},
239 {
"application_name",
"PGAPPNAME", NULL, NULL,
240 "Application-Name",
"", 64,
241 offsetof(
struct pg_conn, appname)},
243 {
"fallback_application_name", NULL, NULL, NULL,
244 "Fallback-Application-Name",
"", 64,
245 offsetof(
struct pg_conn, fbappname)},
247 {
"keepalives", NULL, NULL, NULL,
248 "TCP-Keepalives",
"", 1,
249 offsetof(
struct pg_conn, keepalives)},
251 {
"keepalives_idle", NULL, NULL, NULL,
252 "TCP-Keepalives-Idle",
"", 10,
253 offsetof(
struct pg_conn, keepalives_idle)},
255 {
"keepalives_interval", NULL, NULL, NULL,
256 "TCP-Keepalives-Interval",
"", 10,
257 offsetof(
struct pg_conn, keepalives_interval)},
259 {
"keepalives_count", NULL, NULL, NULL,
260 "TCP-Keepalives-Count",
"", 10,
261 offsetof(
struct pg_conn, keepalives_count)},
263 {
"tcp_user_timeout", NULL, NULL, NULL,
264 "TCP-User-Timeout",
"", 10,
265 offsetof(
struct pg_conn, pgtcp_user_timeout)},
275 offsetof(
struct pg_conn, sslmode)},
277 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
278 "SSL-Compression",
"", 1,
279 offsetof(
struct pg_conn, sslcompression)},
281 {
"sslcert",
"PGSSLCERT", NULL, NULL,
282 "SSL-Client-Cert",
"", 64,
283 offsetof(
struct pg_conn, sslcert)},
285 {
"sslkey",
"PGSSLKEY", NULL, NULL,
286 "SSL-Client-Key",
"", 64,
287 offsetof(
struct pg_conn, sslkey)},
289 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
290 "SSL-Client-Cert-Mode",
"", 8,
291 offsetof(
struct pg_conn, sslcertmode)},
293 {
"sslpassword", NULL, NULL, NULL,
294 "SSL-Client-Key-Password",
"*", 20,
295 offsetof(
struct pg_conn, sslpassword)},
297 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
298 "SSL-Root-Certificate",
"", 64,
299 offsetof(
struct pg_conn, sslrootcert)},
301 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
302 "SSL-Revocation-List",
"", 64,
303 offsetof(
struct pg_conn, sslcrl)},
305 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
306 "SSL-Revocation-List-Dir",
"", 64,
307 offsetof(
struct pg_conn, sslcrldir)},
309 {
"sslsni",
"PGSSLSNI",
"1", NULL,
311 offsetof(
struct pg_conn, sslsni)},
313 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
314 "Require-Peer",
"", 10,
315 offsetof(
struct pg_conn, requirepeer)},
317 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
318 "Require-Auth",
"", 14,
319 offsetof(
struct pg_conn, require_auth)},
321 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
322 "SSL-Minimum-Protocol-Version",
"", 8,
325 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
326 "SSL-Maximum-Protocol-Version",
"", 8,
334 "GSSENC-Mode",
"", 8,
335 offsetof(
struct pg_conn, gssencmode)},
338 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
339 "Kerberos-service-name",
"", 20,
340 offsetof(
struct pg_conn, krbsrvname)},
342 {
"gsslib",
"PGGSSLIB", NULL, NULL,
343 "GSS-library",
"", 7,
344 offsetof(
struct pg_conn, gsslib)},
346 {
"replication", NULL, NULL, NULL,
347 "Replication",
"D", 5,
348 offsetof(
struct pg_conn, replication)},
350 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
352 "Target-Session-Attrs",
"", 15,
353 offsetof(
struct pg_conn, target_session_attrs)},
355 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
357 "Load-Balance-Hosts",
"", 8,
358 offsetof(
struct pg_conn, load_balance_hosts)},
361 {NULL, NULL, NULL, NULL,
369 "PGDATESTYLE",
"datestyle"
409 bool use_defaults,
int expand_dbname);
422 const char *keyword);
424 const char *keyword,
const char *
value,
425 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
427 const char *keyword);
439 const char *
username,
const char *pgpassfile);
445 const char *context);
493 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
495 gss_release_cred(&min_s, &
conn->gcred);
496 conn->gcred = GSS_C_NO_CREDENTIAL;
499 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
501 gss_release_name(&min_s, &
conn->gtarg_nam);
502 if (
conn->gss_SendBuffer)
505 conn->gss_SendBuffer = NULL;
507 if (
conn->gss_RecvBuffer)
510 conn->gss_RecvBuffer = NULL;
512 if (
conn->gss_ResultBuffer)
515 conn->gss_ResultBuffer = NULL;
517 conn->gssenc =
false;
521 if (
conn->sspitarget)
524 conn->sspitarget = NULL;
528 FreeCredentialsHandle(
conn->sspicred);
530 conn->sspicred = NULL;
534 DeleteSecurityContext(
conn->sspictx);
536 conn->sspictx = NULL;
554 while (queue != NULL)
585 while (notify != NULL)
589 notify = notify->
next;
596 while (pstatus != NULL)
600 pstatus = pstatus->
next;
674 const char *
const *
values,
692 const char *
const *
values,
776 const char *
const *
values,
796 true, expand_dbname);
797 if (connOptions == NULL)
914 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
917 *connmember = strdup(tmp);
918 if (*connmember == NULL)
950 if (connOptions == NULL)
1006 char *s = *startptr;
1015 while (*
e !=
'\0' && *
e !=
',')
1017 *more = (*
e ==
',');
1020 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1041 struct timeval tval = {0};
1048 rseed = ((uintptr_t)
conn) ^
1049 ((uint64) getpid()) ^
1050 ((uint64) tval.tv_usec) ^
1051 ((uint64) tval.tv_sec);
1143 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1167 if (ch->
host == NULL)
1195 if (
i == 1 && !more)
1273 if (pwhost == NULL || pwhost[0] ==
'\0')
1294 bool negated =
false;
1303 for (first =
true, more =
true; more; first =
false)
1352 if (strcmp(method,
"password") == 0)
1356 else if (strcmp(method,
"md5") == 0)
1360 else if (strcmp(method,
"gss") == 0)
1365 else if (strcmp(method,
"sspi") == 0)
1370 else if (strcmp(method,
"scram-sha-256") == 0)
1377 else if (strcmp(method,
"none") == 0)
1522 "ssl_min_protocol_version",
1530 "ssl_max_protocol_version",
1573 #ifndef HAVE_SSL_CTX_SET_CERT_CB
1647 "target_session_attrs",
1668 "load_balance_hosts",
1753 if (connOptions != NULL)
1781 const char *pgtty,
const char *
dbName,
const char *login,
1843 if (pgoptions && pgoptions[0] !=
'\0')
1851 if (login && login[0] !=
'\0')
1859 if (pwd && pwd[0] !=
'\0')
1900 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_NODELAY,
1925 if (addr->ss_family == AF_INET)
1928 &((
struct sockaddr_in *) addr)->sin_addr.s_addr,
1930 host_addr, host_addr_len) == NULL)
1931 host_addr[0] =
'\0';
1933 else if (addr->ss_family == AF_INET6)
1936 &((
struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
1938 host_addr, host_addr_len) == NULL)
1939 host_addr[0] =
'\0';
1942 host_addr[0] =
'\0';
1958 char service[NI_MAXHOST];
1962 service,
sizeof(service),
1965 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
1970 const char *displayed_host;
1971 const char *displayed_port;
1979 if (displayed_port == NULL || displayed_port[0] ==
'\0')
1980 displayed_port = DEF_PGPORT_STR;
1989 strcmp(displayed_host, host_addr) != 0)
1991 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
1992 displayed_host, host_addr,
1996 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2040 return val != 0 ? 1 : 0;
2050 const char *context)
2061 numval = strtol(
value, &end, 10);
2067 if (
value == end || errno != 0 || numval != (
int) numval)
2074 while (*end !=
'\0' && isspace((
unsigned char) *end))
2107 #ifdef PG_TCP_KEEPALIVE_IDLE
2108 if (setsockopt(
conn->
sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
2109 (
char *) &idle,
sizeof(idle)) < 0)
2115 PG_TCP_KEEPALIVE_IDLE_STR,
2136 "keepalives_interval"))
2141 #ifdef TCP_KEEPINTVL
2142 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPINTVL,
2171 "keepalives_count"))
2177 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPCNT,
2178 (
char *) &count,
sizeof(count)) < 0)
2193 #ifdef SIO_KEEPALIVE_VALS
2203 struct tcp_keepalive ka;
2212 ka.keepalivetime = idle * 1000;
2213 ka.keepaliveinterval =
interval * 1000;
2241 "keepalives_interval"))
2247 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2268 "tcp_user_timeout"))
2274 #ifdef TCP_USER_TIMEOUT
2275 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
2276 (
char *) &timeout,
sizeof(timeout)) < 0)
2305 goto connect_errReturn;
2316 "libpq is incorrectly linked to backend functions\n");
2317 goto connect_errReturn;
2372 time_t finish_time = ((time_t) -1);
2374 int last_whichhost = -2;
2375 int last_whichaddr = -2;
2421 finish_time = time(NULL) + timeout;
2507 bool reset_connection_state_machine =
false;
2508 bool need_new_connection =
false;
2573 reset_connection_state_machine =
true;
2584 struct addrinfo hint;
2585 struct addrinfo *addrlist;
2624 MemSet(&hint, 0,
sizeof(hint));
2625 hint.ai_socktype = SOCK_STREAM;
2626 hint.ai_family = AF_UNSPEC;
2629 if (ch->
port == NULL || ch->
port[0] ==
'\0')
2630 thisport = DEF_PGPORT;
2636 if (thisport < 1 || thisport > 65535)
2642 snprintf(portstr,
sizeof(portstr),
"%d", thisport);
2650 if (ret || !addrlist)
2653 ch->
host, gai_strerror(ret));
2659 hint.ai_flags = AI_NUMERICHOST;
2662 if (ret || !addrlist)
2671 hint.ai_family = AF_UNIX;
2687 if (ret || !addrlist)
2690 portstr, gai_strerror(ret));
2731 reset_connection_state_machine =
true;
2736 if (reset_connection_state_machine)
2755 reset_connection_state_machine =
false;
2756 need_new_connection =
true;
2760 if (need_new_connection)
2777 need_new_connection =
false;
2794 char host_addr[NI_MAXHOST];
2826 sock_type = SOCK_STREAM;
2835 sock_type |= SOCK_CLOEXEC;
2837 #ifdef SOCK_NONBLOCK
2843 sock_type |= SOCK_NONBLOCK;
2882 if (addr_cur->
family != AF_UNIX)
2891 #ifndef SOCK_NONBLOCK
2901 #ifndef SOCK_CLOEXEC
2903 if (fcntl(
conn->
sock, F_SETFD, FD_CLOEXEC) == -1)
2913 if (addr_cur->
family != AF_UNIX)
2921 if (usekeepalives < 0)
2926 else if (usekeepalives == 0)
2932 SOL_SOCKET, SO_KEEPALIVE,
2933 (
char *) &on,
sizeof(on)) < 0)
2946 #ifdef SIO_KEEPALIVE_VALS
2947 else if (!prepKeepalivesWin32(
conn))
2993 if (setsockopt(
conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
2994 (
char *) &optval,
sizeof(optval)) == 0)
3059 if (getsockopt(
conn->
sock, SOL_SOCKET, SO_ERROR,
3060 (
char *) &optval, &optlen) == -1)
3066 else if (optval != 0)
3114 char *remote_username;
3126 if (errno == ENOSYS)
3137 if (remote_username == NULL)
3144 free(remote_username);
3147 free(remote_username);
3158 conn->allow_ssl_try =
false;
3161 conn->try_gss =
false;
3195 "GSSAPI encryption required but was impossible (possibly no credential cache, no server support, or using a local socket)");
3217 if (
conn->allow_ssl_try && !
conn->wait_ssl_try &&
3330 else if (SSLok ==
'N')
3344 conn->allow_ssl_try =
false;
3349 else if (SSLok ==
'E')
3401 &&
conn->allow_ssl_try
3402 && !
conn->wait_ssl_try)
3405 conn->allow_ssl_try =
false;
3406 need_new_connection =
true;
3437 else if (rdresult == 0)
3453 conn->try_gss =
false;
3454 need_new_connection =
true;
3470 conn->try_gss =
false;
3475 else if (gss_ok !=
'G')
3511 conn->try_gss =
false;
3512 need_new_connection =
true;
3558 if (!(beresp ==
'R' || beresp ==
'v' || beresp ==
'E'))
3585 if (beresp ==
'R' && (msgLength < 8 || msgLength > 2000))
3590 if (beresp ==
'v' && (msgLength < 8 || msgLength > 2000))
3596 #define MAX_ERRLEN 30000
3597 if (beresp ==
'E' && (msgLength < 8 || msgLength >
MAX_ERRLEN))
3645 if (avail < msgLength)
3696 conn->try_gss =
false;
3697 need_new_connection =
true;
3710 &&
conn->allow_ssl_try
3711 &&
conn->wait_ssl_try)
3714 conn->wait_ssl_try =
false;
3715 need_new_connection =
true;
3725 &&
conn->allow_ssl_try
3726 && !
conn->wait_ssl_try)
3729 conn->allow_ssl_try =
false;
3730 need_new_connection =
true;
3737 else if (beresp ==
'v')
3841 const char *sqlstate;
3849 need_new_connection =
true;
3881 bool read_only_server;
3901 "SHOW transaction_read_only"))
3914 read_only_server : !read_only_server)
3959 "SELECT pg_catalog.pg_is_in_recovery()"))
4070 if (strncmp(
val,
"on", 2) == 0)
4092 "SHOW transaction_read_only");
4126 if (strncmp(
val,
"t", 1) == 0)
4142 "SELECT pg_is_in_recovery()");
4155 "invalid connection state %d, probably indicative of memory corruption",
4260 static bool wsastartup_done =
false;
4262 if (!wsastartup_done)
4266 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
4268 wsastartup_done =
true;
4443 struct addrinfo *ai = addrlist;
4692 conn,
"tcp_user_timeout"))
4699 conn,
"keepalives"))
4706 conn,
"keepalives_idle"))
4713 conn,
"keepalives_interval"))
4720 conn,
"keepalives_count"))
4745 #if defined(TCP_USER_TIMEOUT) || !defined(WIN32)
4751 if (setsockopt(
fd, protoid, optid, (
char *) &
value,
sizeof(
value)) < 0)
4792 strlcpy(errbuf,
"PQcancel() -- no cancel object supplied", errbufsize);
4804 strlcpy(errbuf,
"PQcancel() -- socket() failed: ", errbufsize);
4805 goto cancel_errReturn;
4818 if (cancel->
raddr.
addr.ss_family != AF_UNIX &&
4824 strlcpy(errbuf,
"PQcancel() -- setsockopt(SO_KEEPALIVE) failed: ", errbufsize);
4825 goto cancel_errReturn;
4828 #ifdef PG_TCP_KEEPALIVE_IDLE
4832 strlcpy(errbuf,
"PQcancel() -- setsockopt(" PG_TCP_KEEPALIVE_IDLE_STR
") failed: ", errbufsize);
4833 goto cancel_errReturn;
4837 #ifdef TCP_KEEPINTVL
4841 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_KEEPINTVL) failed: ", errbufsize);
4842 goto cancel_errReturn;
4850 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_KEEPCNT) failed: ", errbufsize);
4851 goto cancel_errReturn;
4857 #ifdef SIO_KEEPALIVE_VALS
4858 if (!setKeepalivesWin32(tmpsock,
4862 strlcpy(errbuf,
"PQcancel() -- WSAIoctl(SIO_KEEPALIVE_VALS) failed: ", errbufsize);
4863 goto cancel_errReturn;
4869 #ifdef TCP_USER_TIMEOUT
4873 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_USER_TIMEOUT) failed: ", errbufsize);
4874 goto cancel_errReturn;
4886 strlcpy(errbuf,
"PQcancel() -- connect() failed: ", errbufsize);
4887 goto cancel_errReturn;
4898 if (
send(tmpsock, (
char *) &crp,
sizeof(crp), 0) != (
int)
sizeof(crp))
4903 strlcpy(errbuf,
"PQcancel() -- send() failed: ", errbufsize);
4904 goto cancel_errReturn;
4915 if (
recv(tmpsock, (
char *) &crp, 1, 0) < 0)
4934 maxlen = errbufsize - strlen(errbuf) - 2;
4946 bufp =
buf +
sizeof(
buf) - 1;
4950 *(--bufp) = (
val % 10) +
'0';
4954 memcpy(bufp,
"error ", 6);
4955 strncat(errbuf, bufp, maxlen);
4956 strcat(errbuf,
"\n");
4990 "PQrequestCancel() -- connection is not open\n",
5036 const void *
buf,
size_t buf_len)
5059 #define LDAP_URL "ldap://"
5060 #define LDAP_DEF_PORT 389
5061 #define PGLDAP_TIMEOUT 2
5063 #define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5064 #define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5090 int port = LDAP_DEF_PORT,
5113 char *attrs[2] = {NULL, NULL};
5118 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5120 if ((url = strdup(purl)) == NULL)
5135 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5146 p = strchr(url + strlen(LDAP_URL),
'/');
5147 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5150 "invalid LDAP URL \"%s\": missing distinguished name",
5159 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5162 "invalid LDAP URL \"%s\": must have exactly one attribute",
5171 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5174 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5183 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5186 "invalid LDAP URL \"%s\": no filter",
5193 if ((p = strchr(filter,
'?')) != NULL)
5197 if ((p1 = strchr(
hostname,
':')) != NULL)
5204 lport = strtol(portstr, &endptr, 10);
5205 if (*portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5208 "invalid LDAP URL \"%s\": invalid port number",
5217 if (strchr(attrs[0],
',') != NULL)
5220 "invalid LDAP URL \"%s\": must have exactly one attribute",
5228 scope = LDAP_SCOPE_BASE;
5230 scope = LDAP_SCOPE_ONELEVEL;
5232 scope = LDAP_SCOPE_SUBTREE;
5236 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5264 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5273 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5281 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5291 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &
res)) == -1 ||
5305 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5315 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &
res))
5320 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5327 if ((rc = ldap_count_entries(ld,
res)) != 1)
5340 if ((entry = ldap_first_entry(ld,
res)) == NULL)
5351 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5366 ldap_value_free_len(
values);
5374 size +=
values[
i]->bv_len + 1;
5375 if ((result =
malloc(size)) == NULL)
5378 ldap_value_free_len(
values);
5391 ldap_value_free_len(
values);
5395 oldstate =
state = 0;
5396 for (p = result; *p !=
'\0'; ++p)
5401 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5408 if (ld_is_sp_tab(*p))
5413 else if (ld_is_nl_cr(*p))
5416 "missing \"=\" after \"%s\" in connection info string",
5432 else if (!ld_is_sp_tab(*p))
5435 "missing \"=\" after \"%s\" in connection info string",
5448 else if (ld_is_nl_cr(*p))
5450 optval = optname + strlen(optname);
5453 else if (!ld_is_sp_tab(*p))
5460 if (ld_is_sp_tab(*p) || ld_is_nl_cr(*p))
5472 else if (*p ==
'\\')