33 #include "pg_config_paths.h"
41 #define _WIN32_IE 0x0500
66 #define LDAP_DEPRECATED 1
68 typedef struct timeval LDAP_TIMEVAL;
75 #define PGPASSFILE ".pgpass"
77 #define PGPASSFILE "pgpass.conf"
86 #define ERRCODE_APPNAME_UNKNOWN "42704"
89 #define ERRCODE_INVALID_PASSWORD "28P01"
91 #define ERRCODE_CANNOT_CONNECT_NOW "57P03"
97 #if defined(TCP_KEEPIDLE)
99 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
100 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
101 #elif defined(TCP_KEEPALIVE_THRESHOLD)
103 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
104 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
105 #elif defined(TCP_KEEPALIVE) && defined(__darwin__)
108 #define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
109 #define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
116 #define DefaultHost "localhost"
117 #define DefaultOption ""
119 #define DefaultChannelBinding "prefer"
121 #define DefaultChannelBinding "disable"
123 #define DefaultTargetSessionAttrs "any"
124 #define DefaultLoadBalanceHosts "disable"
126 #define DefaultSSLMode "prefer"
127 #define DefaultSSLCertMode "allow"
129 #define DefaultSSLMode "disable"
130 #define DefaultSSLCertMode "disable"
134 #define DefaultGSSMode "prefer"
136 #define DefaultGSSMode "disable"
190 {
"service",
"PGSERVICE", NULL, NULL,
191 "Database-Service",
"", 20, -1},
193 {
"user",
"PGUSER", NULL, NULL,
194 "Database-User",
"", 20,
195 offsetof(
struct pg_conn, pguser)},
197 {
"password",
"PGPASSWORD", NULL, NULL,
198 "Database-Password",
"*", 20,
199 offsetof(
struct pg_conn, pgpass)},
201 {
"passfile",
"PGPASSFILE", NULL, NULL,
202 "Database-Password-File",
"", 64,
203 offsetof(
struct pg_conn, pgpassfile)},
206 "Channel-Binding",
"", 8,
207 offsetof(
struct pg_conn, channel_binding)},
209 {
"connect_timeout",
"PGCONNECT_TIMEOUT", NULL, NULL,
210 "Connect-timeout",
"", 10,
211 offsetof(
struct pg_conn, connect_timeout)},
213 {
"dbname",
"PGDATABASE", NULL, NULL,
214 "Database-Name",
"", 20,
217 {
"host",
"PGHOST", NULL, NULL,
218 "Database-Host",
"", 40,
221 {
"hostaddr",
"PGHOSTADDR", NULL, NULL,
222 "Database-Host-IP-Address",
"", 45,
223 offsetof(
struct pg_conn, pghostaddr)},
225 {
"port",
"PGPORT", DEF_PGPORT_STR, NULL,
226 "Database-Port",
"", 6,
229 {
"client_encoding",
"PGCLIENTENCODING", NULL, NULL,
230 "Client-Encoding",
"", 10,
231 offsetof(
struct pg_conn, client_encoding_initial)},
234 "Backend-Options",
"", 40,
235 offsetof(
struct pg_conn, pgoptions)},
237 {
"application_name",
"PGAPPNAME", NULL, NULL,
238 "Application-Name",
"", 64,
239 offsetof(
struct pg_conn, appname)},
241 {
"fallback_application_name", NULL, NULL, NULL,
242 "Fallback-Application-Name",
"", 64,
243 offsetof(
struct pg_conn, fbappname)},
245 {
"keepalives", NULL, NULL, NULL,
246 "TCP-Keepalives",
"", 1,
247 offsetof(
struct pg_conn, keepalives)},
249 {
"keepalives_idle", NULL, NULL, NULL,
250 "TCP-Keepalives-Idle",
"", 10,
251 offsetof(
struct pg_conn, keepalives_idle)},
253 {
"keepalives_interval", NULL, NULL, NULL,
254 "TCP-Keepalives-Interval",
"", 10,
255 offsetof(
struct pg_conn, keepalives_interval)},
257 {
"keepalives_count", NULL, NULL, NULL,
258 "TCP-Keepalives-Count",
"", 10,
259 offsetof(
struct pg_conn, keepalives_count)},
261 {
"tcp_user_timeout", NULL, NULL, NULL,
262 "TCP-User-Timeout",
"", 10,
263 offsetof(
struct pg_conn, pgtcp_user_timeout)},
273 offsetof(
struct pg_conn, sslmode)},
275 {
"sslcompression",
"PGSSLCOMPRESSION",
"0", NULL,
276 "SSL-Compression",
"", 1,
277 offsetof(
struct pg_conn, sslcompression)},
279 {
"sslcert",
"PGSSLCERT", NULL, NULL,
280 "SSL-Client-Cert",
"", 64,
281 offsetof(
struct pg_conn, sslcert)},
283 {
"sslkey",
"PGSSLKEY", NULL, NULL,
284 "SSL-Client-Key",
"", 64,
285 offsetof(
struct pg_conn, sslkey)},
287 {
"sslcertmode",
"PGSSLCERTMODE", NULL, NULL,
288 "SSL-Client-Cert-Mode",
"", 8,
289 offsetof(
struct pg_conn, sslcertmode)},
291 {
"sslpassword", NULL, NULL, NULL,
292 "SSL-Client-Key-Password",
"*", 20,
293 offsetof(
struct pg_conn, sslpassword)},
295 {
"sslrootcert",
"PGSSLROOTCERT", NULL, NULL,
296 "SSL-Root-Certificate",
"", 64,
297 offsetof(
struct pg_conn, sslrootcert)},
299 {
"sslcrl",
"PGSSLCRL", NULL, NULL,
300 "SSL-Revocation-List",
"", 64,
301 offsetof(
struct pg_conn, sslcrl)},
303 {
"sslcrldir",
"PGSSLCRLDIR", NULL, NULL,
304 "SSL-Revocation-List-Dir",
"", 64,
305 offsetof(
struct pg_conn, sslcrldir)},
307 {
"sslsni",
"PGSSLSNI",
"1", NULL,
309 offsetof(
struct pg_conn, sslsni)},
311 {
"requirepeer",
"PGREQUIREPEER", NULL, NULL,
312 "Require-Peer",
"", 10,
313 offsetof(
struct pg_conn, requirepeer)},
315 {
"require_auth",
"PGREQUIREAUTH", NULL, NULL,
316 "Require-Auth",
"", 14,
317 offsetof(
struct pg_conn, require_auth)},
319 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2", NULL,
320 "SSL-Minimum-Protocol-Version",
"", 8,
323 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION", NULL, NULL,
324 "SSL-Maximum-Protocol-Version",
"", 8,
332 "GSSENC-Mode",
"", 8,
333 offsetof(
struct pg_conn, gssencmode)},
336 {
"krbsrvname",
"PGKRBSRVNAME", PG_KRB_SRVNAM, NULL,
337 "Kerberos-service-name",
"", 20,
338 offsetof(
struct pg_conn, krbsrvname)},
340 {
"gsslib",
"PGGSSLIB", NULL, NULL,
341 "GSS-library",
"", 7,
342 offsetof(
struct pg_conn, gsslib)},
344 {
"gssdelegation",
"PGGSSDELEGATION",
"0", NULL,
345 "GSS-delegation",
"", 1,
346 offsetof(
struct pg_conn, gssdelegation)},
348 {
"replication", NULL, NULL, NULL,
349 "Replication",
"D", 5,
350 offsetof(
struct pg_conn, replication)},
352 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
354 "Target-Session-Attrs",
"", 15,
355 offsetof(
struct pg_conn, target_session_attrs)},
357 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
359 "Load-Balance-Hosts",
"", 8,
360 offsetof(
struct pg_conn, load_balance_hosts)},
363 {NULL, NULL, NULL, NULL,
371 "PGDATESTYLE",
"datestyle"
411 bool use_defaults,
int expand_dbname);
424 const char *keyword);
426 const char *keyword,
const char *
value,
427 PQExpBuffer errorMessage,
bool ignoreMissing,
bool uri_decode);
429 const char *keyword);
441 const char *
username,
const char *pgpassfile);
447 const char *context);
495 if (
conn->gcred != GSS_C_NO_CREDENTIAL)
497 gss_release_cred(&min_s, &
conn->gcred);
498 conn->gcred = GSS_C_NO_CREDENTIAL;
501 gss_delete_sec_context(&min_s, &
conn->gctx, GSS_C_NO_BUFFER);
503 gss_release_name(&min_s, &
conn->gtarg_nam);
504 if (
conn->gss_SendBuffer)
507 conn->gss_SendBuffer = NULL;
509 if (
conn->gss_RecvBuffer)
512 conn->gss_RecvBuffer = NULL;
514 if (
conn->gss_ResultBuffer)
517 conn->gss_ResultBuffer = NULL;
519 conn->gssenc =
false;
523 if (
conn->sspitarget)
526 conn->sspitarget = NULL;
530 FreeCredentialsHandle(
conn->sspicred);
532 conn->sspicred = NULL;
536 DeleteSecurityContext(
conn->sspictx);
538 conn->sspictx = NULL;
556 while (queue != NULL)
587 while (notify != NULL)
591 notify = notify->
next;
598 while (pstatus != NULL)
602 pstatus = pstatus->
next;
677 const char *
const *
values,
695 const char *
const *
values,
779 const char *
const *
values,
799 true, expand_dbname);
800 if (connOptions == NULL)
917 char **connmember = (
char **) ((
char *)
conn +
option->connofs);
920 *connmember = strdup(tmp);
921 if (*connmember == NULL)
953 if (connOptions == NULL)
1009 char *s = *startptr;
1018 while (*
e !=
'\0' && *
e !=
',')
1020 *more = (*
e ==
',');
1023 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1044 struct timeval tval = {0};
1051 rseed = ((uintptr_t)
conn) ^
1052 ((uint64) getpid()) ^
1053 ((uint64) tval.tv_usec) ^
1054 ((uint64) tval.tv_sec);
1146 else if (ch->
host != NULL && ch->
host[0] !=
'\0')
1170 if (ch->
host == NULL)
1198 if (
i == 1 && !more)
1276 if (pwhost == NULL || pwhost[0] ==
'\0')
1297 bool negated =
false;
1306 for (first =
true, more =
true; more; first =
false)
1355 if (strcmp(method,
"password") == 0)
1359 else if (strcmp(method,
"md5") == 0)
1363 else if (strcmp(method,
"gss") == 0)
1368 else if (strcmp(method,
"sspi") == 0)
1373 else if (strcmp(method,
"scram-sha-256") == 0)
1380 else if (strcmp(method,
"none") == 0)
1409 "require_auth", method);
1558 "ssl_min_protocol_version",
1566 "ssl_max_protocol_version",
1609 #ifndef HAVE_SSL_CTX_SET_CERT_CB
1683 "target_session_attrs",
1704 "load_balance_hosts",
1789 if (connOptions != NULL)
1817 const char *pgtty,
const char *
dbName,
const char *login,
1879 if (pgoptions && pgoptions[0] !=
'\0')
1887 if (login && login[0] !=
'\0')
1895 if (pwd && pwd[0] !=
'\0')
1936 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_NODELAY,
1961 if (addr->ss_family == AF_INET)
1964 &((
struct sockaddr_in *) addr)->sin_addr.s_addr,
1966 host_addr, host_addr_len) == NULL)
1967 host_addr[0] =
'\0';
1969 else if (addr->ss_family == AF_INET6)
1972 &((
struct sockaddr_in6 *) addr)->sin6_addr.s6_addr,
1974 host_addr, host_addr_len) == NULL)
1975 host_addr[0] =
'\0';
1978 host_addr[0] =
'\0';
1994 char service[NI_MAXHOST];
1998 service,
sizeof(service),
2001 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
2006 const char *displayed_host;
2007 const char *displayed_port;
2015 if (displayed_port == NULL || displayed_port[0] ==
'\0')
2016 displayed_port = DEF_PGPORT_STR;
2025 strcmp(displayed_host, host_addr) != 0)
2027 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
2028 displayed_host, host_addr,
2032 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2076 return val != 0 ? 1 : 0;
2086 const char *context)
2097 numval = strtol(
value, &end, 10);
2103 if (
value == end || errno != 0 || numval != (
int) numval)
2110 while (*end !=
'\0' && isspace((
unsigned char) *end))
2143 #ifdef PG_TCP_KEEPALIVE_IDLE
2144 if (setsockopt(
conn->
sock, IPPROTO_TCP, PG_TCP_KEEPALIVE_IDLE,
2145 (
char *) &idle,
sizeof(idle)) < 0)
2151 PG_TCP_KEEPALIVE_IDLE_STR,
2172 "keepalives_interval"))
2177 #ifdef TCP_KEEPINTVL
2178 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPINTVL,
2207 "keepalives_count"))
2213 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_KEEPCNT,
2214 (
char *) &count,
sizeof(count)) < 0)
2229 #ifdef SIO_KEEPALIVE_VALS
2239 struct tcp_keepalive ka;
2248 ka.keepalivetime = idle * 1000;
2249 ka.keepaliveinterval =
interval * 1000;
2277 "keepalives_interval"))
2283 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2304 "tcp_user_timeout"))
2310 #ifdef TCP_USER_TIMEOUT
2311 if (setsockopt(
conn->
sock, IPPROTO_TCP, TCP_USER_TIMEOUT,
2312 (
char *) &timeout,
sizeof(timeout)) < 0)
2341 goto connect_errReturn;
2352 "libpq is incorrectly linked to backend functions\n");
2353 goto connect_errReturn;
2408 time_t finish_time = ((time_t) -1);
2410 int last_whichhost = -2;
2411 int last_whichaddr = -2;
2457 finish_time = time(NULL) + timeout;
2543 bool reset_connection_state_machine =
false;
2544 bool need_new_connection =
false;
2609 reset_connection_state_machine =
true;
2620 struct addrinfo hint;
2621 struct addrinfo *addrlist;
2660 MemSet(&hint, 0,
sizeof(hint));
2661 hint.ai_socktype = SOCK_STREAM;
2662 hint.ai_family = AF_UNSPEC;
2665 if (ch->
port == NULL || ch->
port[0] ==
'\0')
2666 thisport = DEF_PGPORT;
2672 if (thisport < 1 || thisport > 65535)
2678 snprintf(portstr,
sizeof(portstr),
"%d", thisport);
2686 if (ret || !addrlist)
2689 ch->
host, gai_strerror(ret));
2695 hint.ai_flags = AI_NUMERICHOST;
2698 if (ret || !addrlist)
2707 hint.ai_family = AF_UNIX;
2723 if (ret || !addrlist)
2726 portstr, gai_strerror(ret));
2767 reset_connection_state_machine =
true;
2772 if (reset_connection_state_machine)
2791 reset_connection_state_machine =
false;
2792 need_new_connection =
true;
2796 if (need_new_connection)
2813 need_new_connection =
false;
2830 char host_addr[NI_MAXHOST];
2862 sock_type = SOCK_STREAM;
2871 sock_type |= SOCK_CLOEXEC;
2873 #ifdef SOCK_NONBLOCK
2879 sock_type |= SOCK_NONBLOCK;
2918 if (addr_cur->
family != AF_UNIX)
2927 #ifndef SOCK_NONBLOCK
2937 #ifndef SOCK_CLOEXEC
2939 if (fcntl(
conn->
sock, F_SETFD, FD_CLOEXEC) == -1)
2949 if (addr_cur->
family != AF_UNIX)
2957 if (usekeepalives < 0)
2962 else if (usekeepalives == 0)
2968 SOL_SOCKET, SO_KEEPALIVE,
2969 (
char *) &on,
sizeof(on)) < 0)
2982 #ifdef SIO_KEEPALIVE_VALS
2983 else if (!prepKeepalivesWin32(
conn))
3029 if (setsockopt(
conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
3030 (
char *) &optval,
sizeof(optval)) == 0)
3095 if (getsockopt(
conn->
sock, SOL_SOCKET, SO_ERROR,
3096 (
char *) &optval, &optlen) == -1)
3102 else if (optval != 0)
3150 char *remote_username;
3162 if (errno == ENOSYS)
3173 if (remote_username == NULL)
3180 free(remote_username);
3183 free(remote_username);
3194 conn->allow_ssl_try =
false;
3197 conn->try_gss =
false;
3231 "GSSAPI encryption required but was impossible (possibly no credential cache, no server support, or using a local socket)");
3253 if (
conn->allow_ssl_try && !
conn->wait_ssl_try &&
3366 else if (SSLok ==
'N')
3380 conn->allow_ssl_try =
false;
3385 else if (SSLok ==
'E')
3437 &&
conn->allow_ssl_try
3438 && !
conn->wait_ssl_try)
3441 conn->allow_ssl_try =
false;
3442 need_new_connection =
true;
3473 else if (rdresult == 0)
3489 conn->try_gss =
false;
3490 need_new_connection =
true;
3506 conn->try_gss =
false;
3511 else if (gss_ok !=
'G')
3547 conn->try_gss =
false;
3548 need_new_connection =
true;
3624 (msgLength < 8 || msgLength > 2000))
3630 (msgLength < 8 || msgLength > 2000))
3636 #define MAX_ERRLEN 30000
3686 if (avail < msgLength)
3737 conn->try_gss =
false;
3738 need_new_connection =
true;
3751 &&
conn->allow_ssl_try
3752 &&
conn->wait_ssl_try)
3755 conn->wait_ssl_try =
false;
3756 need_new_connection =
true;
3766 &&
conn->allow_ssl_try
3767 && !
conn->wait_ssl_try)
3770 conn->allow_ssl_try =
false;
3771 need_new_connection =
true;
3882 const char *sqlstate;
3890 need_new_connection =
true;
3922 bool read_only_server;
3942 "SHOW transaction_read_only"))
3955 read_only_server : !read_only_server)
4000 "SELECT pg_catalog.pg_is_in_recovery()"))
4111 if (strncmp(
val,
"on", 2) == 0)
4133 "SHOW transaction_read_only");
4167 if (strncmp(
val,
"t", 1) == 0)
4183 "SELECT pg_is_in_recovery()");
4196 "invalid connection state %d, probably indicative of memory corruption",
4301 static bool wsastartup_done =
false;
4303 if (!wsastartup_done)
4307 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
4309 wsastartup_done =
true;
4485 struct addrinfo *ai = addrlist;
4734 conn,
"tcp_user_timeout"))
4741 conn,
"keepalives"))
4748 conn,
"keepalives_idle"))
4755 conn,
"keepalives_interval"))
4762 conn,
"keepalives_count"))
4787 #if defined(TCP_USER_TIMEOUT) || !defined(WIN32)
4793 if (setsockopt(
fd, protoid, optid, (
char *) &
value,
sizeof(
value)) < 0)
4834 strlcpy(errbuf,
"PQcancel() -- no cancel object supplied", errbufsize);
4846 strlcpy(errbuf,
"PQcancel() -- socket() failed: ", errbufsize);
4847 goto cancel_errReturn;
4860 if (cancel->
raddr.
addr.ss_family != AF_UNIX &&
4866 strlcpy(errbuf,
"PQcancel() -- setsockopt(SO_KEEPALIVE) failed: ", errbufsize);
4867 goto cancel_errReturn;
4870 #ifdef PG_TCP_KEEPALIVE_IDLE
4874 strlcpy(errbuf,
"PQcancel() -- setsockopt(" PG_TCP_KEEPALIVE_IDLE_STR
") failed: ", errbufsize);
4875 goto cancel_errReturn;
4879 #ifdef TCP_KEEPINTVL
4883 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_KEEPINTVL) failed: ", errbufsize);
4884 goto cancel_errReturn;
4892 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_KEEPCNT) failed: ", errbufsize);
4893 goto cancel_errReturn;
4899 #ifdef SIO_KEEPALIVE_VALS
4900 if (!setKeepalivesWin32(tmpsock,
4904 strlcpy(errbuf,
"PQcancel() -- WSAIoctl(SIO_KEEPALIVE_VALS) failed: ", errbufsize);
4905 goto cancel_errReturn;
4911 #ifdef TCP_USER_TIMEOUT
4915 strlcpy(errbuf,
"PQcancel() -- setsockopt(TCP_USER_TIMEOUT) failed: ", errbufsize);
4916 goto cancel_errReturn;
4928 strlcpy(errbuf,
"PQcancel() -- connect() failed: ", errbufsize);
4929 goto cancel_errReturn;
4940 if (
send(tmpsock, (
char *) &crp,
sizeof(crp), 0) != (
int)
sizeof(crp))
4945 strlcpy(errbuf,
"PQcancel() -- send() failed: ", errbufsize);
4946 goto cancel_errReturn;
4957 if (
recv(tmpsock, (
char *) &crp, 1, 0) < 0)
4976 maxlen = errbufsize - strlen(errbuf) - 2;
4988 bufp =
buf +
sizeof(
buf) - 1;
4992 *(--bufp) = (
val % 10) +
'0';
4996 memcpy(bufp,
"error ", 6);
4997 strncat(errbuf, bufp, maxlen);
4998 strcat(errbuf,
"\n");
5032 "PQrequestCancel() -- connection is not open\n",
5078 const void *
buf,
size_t buf_len)
5101 #define LDAP_URL "ldap://"
5102 #define LDAP_DEF_PORT 389
5103 #define PGLDAP_TIMEOUT 2
5105 #define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5106 #define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5132 int port = LDAP_DEF_PORT,
5155 char *attrs[2] = {NULL, NULL};
5160 LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5162 if ((url = strdup(purl)) == NULL)
5177 "invalid LDAP URL \"%s\": scheme must be ldap://", purl);
5188 p = strchr(url + strlen(LDAP_URL),
'/');
5189 if (p == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5192 "invalid LDAP URL \"%s\": missing distinguished name",
5201 if ((p = strchr(dn,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5204 "invalid LDAP URL \"%s\": must have exactly one attribute",
5213 if ((p = strchr(attrs[0],
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5216 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5225 if ((p = strchr(scopestr,
'?')) == NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5228 "invalid LDAP URL \"%s\": no filter",
5235 if ((p = strchr(filter,
'?')) != NULL)
5239 if ((p1 = strchr(
hostname,
':')) != NULL)
5246 lport = strtol(portstr, &endptr, 10);
5247 if (*portstr ==
'\0' || *endptr !=
'\0' || errno || lport < 0 || lport > 65535)
5250 "invalid LDAP URL \"%s\": invalid port number",
5259 if (strchr(attrs[0],
',') != NULL)
5262 "invalid LDAP URL \"%s\": must have exactly one attribute",
5270 scope = LDAP_SCOPE_BASE;
5272 scope = LDAP_SCOPE_ONELEVEL;
5274 scope = LDAP_SCOPE_SUBTREE;
5278 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5306 if (ldap_connect(ld, &time) != LDAP_SUCCESS)
5315 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5323 if ((msgid = ldap_simple_bind(ld, NULL, NULL)) == -1)
5333 if ((rc = ldap_result(ld, msgid, LDAP_MSG_ALL, &time, &
res)) == -1 ||
5347 if (ldap_set_option(ld, LDAP_OPT_NETWORK_TIMEOUT, &time) != LDAP_SUCCESS)
5357 if ((rc = ldap_search_st(ld, dn, scope, filter, attrs, 0, &time, &
res))
5362 libpq_append_error(errorMessage,
"lookup on LDAP server failed: %s", ldap_err2string(rc));
5369 if ((rc = ldap_count_entries(ld,
res)) != 1)
5382 if ((entry = ldap_first_entry(ld,
res)) == NULL)
5393 if ((
values = ldap_get_values_len(ld, entry, attrs[0])) == NULL)
5408 ldap_value_free_len(
values);
5416 size +=
values[
i]->bv_len + 1;
5417 if ((result =
malloc(size)) == NULL)
5420 ldap_value_free_len(
values);
5433 ldap_value_free_len(
values);
5437 oldstate =
state = 0;
5438 for (p = result; *p !=
'\0'; ++p)
5443 if (!ld_is_sp_tab(*p) && !ld_is_nl_cr(*p))
5450 if (ld_is_sp_tab(*p))
5455 else if (ld_is_nl_cr(*p))