36#include "pg_config_paths.h"
44#define _WIN32_IE 0x0500
70#define LDAP_DEPRECATED 1
79#define PGPASSFILE ".pgpass"
81#define PGPASSFILE "pgpass.conf"
90#define ERRCODE_APPNAME_UNKNOWN "42704"
93#define ERRCODE_INVALID_PASSWORD "28P01"
95#define ERRCODE_CANNOT_CONNECT_NOW "57P03"
101#if defined(TCP_KEEPIDLE)
103#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPIDLE
104#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPIDLE"
105#elif defined(TCP_KEEPALIVE_THRESHOLD)
107#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE_THRESHOLD
108#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE_THRESHOLD"
109#elif defined(TCP_KEEPALIVE) && defined(__darwin__)
112#define PG_TCP_KEEPALIVE_IDLE TCP_KEEPALIVE
113#define PG_TCP_KEEPALIVE_IDLE_STR "TCP_KEEPALIVE"
120#define DefaultHost "localhost"
121#define DefaultOption ""
123#define DefaultChannelBinding "prefer"
125#define DefaultChannelBinding "disable"
127#define DefaultTargetSessionAttrs "any"
128#define DefaultLoadBalanceHosts "disable"
130#define DefaultSSLMode "prefer"
131#define DefaultSSLCertMode "allow"
133#define DefaultSSLMode "disable"
134#define DefaultSSLCertMode "disable"
136#define DefaultSSLNegotiation "postgres"
139#define DefaultGSSMode "prefer"
141#define DefaultGSSMode "disable"
201 {
"service",
"PGSERVICE",
NULL,
NULL,
202 "Database-Service",
"", 20,
205 {
"servicefile",
"PGSERVICEFILE",
NULL,
NULL,
206 "Database-Service-File",
"", 64,
210 "Database-User",
"", 20,
213 {
"password",
"PGPASSWORD",
NULL,
NULL,
214 "Database-Password",
"*", 20,
217 {
"passfile",
"PGPASSFILE",
NULL,
NULL,
218 "Database-Password-File",
"", 64,
222 "Channel-Binding",
"", 8,
225 {
"connect_timeout",
"PGCONNECT_TIMEOUT",
NULL,
NULL,
226 "Connect-timeout",
"", 10,
229 {
"dbname",
"PGDATABASE",
NULL,
NULL,
230 "Database-Name",
"", 20,
234 "Database-Host",
"", 40,
237 {
"hostaddr",
"PGHOSTADDR",
NULL,
NULL,
238 "Database-Host-IP-Address",
"", 45,
242 "Database-Port",
"", 6,
245 {
"client_encoding",
"PGCLIENTENCODING",
NULL,
NULL,
246 "Client-Encoding",
"", 10,
250 "Backend-Options",
"", 40,
253 {
"application_name",
"PGAPPNAME",
NULL,
NULL,
254 "Application-Name",
"", 64,
258 "Fallback-Application-Name",
"", 64,
262 "TCP-Keepalives",
"", 1,
266 "TCP-Keepalives-Idle",
"", 10,
270 "TCP-Keepalives-Interval",
"", 10,
274 "TCP-Keepalives-Count",
"", 10,
278 "TCP-User-Timeout",
"", 10,
292 "SSL-Negotiation",
"", 9,
295 {
"sslcompression",
"PGSSLCOMPRESSION",
"0",
NULL,
296 "SSL-Compression",
"", 1,
299 {
"sslcert",
"PGSSLCERT",
NULL,
NULL,
300 "SSL-Client-Cert",
"", 64,
304 "SSL-Client-Key",
"", 64,
307 {
"sslcertmode",
"PGSSLCERTMODE",
NULL,
NULL,
308 "SSL-Client-Cert-Mode",
"", 8,
312 "SSL-Client-Key-Password",
"*", 20,
315 {
"sslrootcert",
"PGSSLROOTCERT",
NULL,
NULL,
316 "SSL-Root-Certificate",
"", 64,
320 "SSL-Revocation-List",
"", 64,
323 {
"sslcrldir",
"PGSSLCRLDIR",
NULL,
NULL,
324 "SSL-Revocation-List-Dir",
"", 64,
327 {
"sslsni",
"PGSSLSNI",
"1",
NULL,
331 {
"requirepeer",
"PGREQUIREPEER",
NULL,
NULL,
332 "Require-Peer",
"", 10,
335 {
"require_auth",
"PGREQUIREAUTH",
NULL,
NULL,
336 "Require-Auth",
"", 14,
339 {
"min_protocol_version",
"PGMINPROTOCOLVERSION",
341 "Min-Protocol-Version",
"", 6,
344 {
"max_protocol_version",
"PGMAXPROTOCOLVERSION",
346 "Max-Protocol-Version",
"", 6,
349 {
"ssl_min_protocol_version",
"PGSSLMINPROTOCOLVERSION",
"TLSv1.2",
NULL,
350 "SSL-Minimum-Protocol-Version",
"", 8,
353 {
"ssl_max_protocol_version",
"PGSSLMAXPROTOCOLVERSION",
NULL,
NULL,
354 "SSL-Maximum-Protocol-Version",
"", 8,
362 "GSSENC-Mode",
"", 8,
367 "Kerberos-service-name",
"", 20,
371 "GSS-library",
"", 7,
374 {
"gssdelegation",
"PGGSSDELEGATION",
"0",
NULL,
375 "GSS-delegation",
"", 1,
379 "Replication",
"D", 5,
382 {
"target_session_attrs",
"PGTARGETSESSIONATTRS",
384 "Target-Session-Attrs",
"", 15,
387 {
"load_balance_hosts",
"PGLOADBALANCEHOSTS",
389 "Load-Balance-Hosts",
"", 8,
400 "OAuth-Issuer",
"", 40,
404 "OAuth-Client-ID",
"", 40,
408 "OAuth-Client-Secret",
"*", 40,
412 "OAuth-Scope",
"", 15,
416 "SSL-Key-Log-File",
"D", 64,
428 "PGDATESTYLE",
"datestyle"
447#define SASL_MECHANISM_COUNT lengthof(supported_sasl_mechs)
455#if defined(USE_SSL) || defined(ENABLE_GSS)
489 const char *keyword);
491 const char *keyword,
const char *
value,
494 const char *keyword);
507 const char *pgpassfile,
const char **
errmsg);
582 if (
conn->gss_SendBuffer)
587 if (
conn->gss_RecvBuffer)
592 if (
conn->gss_ResultBuffer)
597 conn->gssenc =
false;
601 if (
conn->sspitarget)
634 while (queue !=
NULL)
676 while (pstatus !=
NULL)
680 pstatus = pstatus->
next;
771 const char *
const *
values,
789 const char *
const *
values,
873 const char *
const *
values,
1005 if (
option->connofs >= 0)
1044 if (
option->connofs >= 0)
1046 const char **tmp = (
const char **) ((
char *)
srcConn +
option->connofs);
1142 char *s = *startptr;
1151 while (*
e !=
'\0' && *
e !=
',')
1153 *
more = (*
e ==
',');
1156 p = (
char *)
malloc(
sizeof(
char) * (
len + 1));
1211 "conn->allowed_sasl_mechs[] is not sufficiently large for holding all supported SASL mechanisms");
1328 if (
ch->hostaddr !=
NULL &&
ch->hostaddr[0] !=
'\0')
1330 else if (
ch->host !=
NULL &&
ch->host[0] !=
'\0')
1382 if (
i == 1 && !
more)
1500 for (first =
true,
more =
true;
more; first =
false)
1555 if (
strcmp(method,
"password") == 0)
1559 else if (
strcmp(method,
"md5") == 0)
1563 else if (
strcmp(method,
"gss") == 0)
1568 else if (
strcmp(method,
"sspi") == 0)
1580 else if (
strcmp(method,
"scram-sha-256") == 0)
1584 else if (
strcmp(method,
"oauth") == 0)
1592 else if (
strcmp(method,
"none") == 0)
1621 "require_auth", method);
1662 "internal error: no space in allowed_sasl_mechs");
1713 bool allowed =
false;
1863 libpq_append_conn_error(
conn,
"weak sslmode \"%s\" may not be used with sslnegotiation=direct (use \"require\", \"verify-ca\", or \"verify-full\")",
1899 "ssl_min_protocol_version",
1907 "ssl_max_protocol_version",
1950#ifndef HAVE_SSL_CTX_SET_CERT_CB
2024 "target_session_attrs",
2091 "load_balance_hosts",
2308 if (pgoptions && pgoptions[0] !=
'\0')
2324 if (
pwd &&
pwd[0] !=
'\0')
2390 if (addr->ss_family ==
AF_INET)
2398 else if (addr->ss_family ==
AF_INET6)
2430 libpq_gettext(
"connection to server on socket \"%s\" failed: "),
2456 libpq_gettext(
"connection to server at \"%s\" (%s), port %s failed: "),
2461 libpq_gettext(
"connection to server at \"%s\", port %s failed: "),
2505 return val != 0 ? 1 : 0;
2526#ifdef PG_TCP_KEEPALIVE_IDLE
2555 "keepalives_interval"))
2590 "keepalives_count"))
2597 (
char *) &count,
sizeof(count)) < 0)
2612#ifdef SIO_KEEPALIVE_VALS
2631 ka.keepalivetime =
idle * 1000;
2660 "keepalives_interval"))
2666 "WSAIoctl",
"SIO_KEEPALIVE_VALS",
2687 "tcp_user_timeout"))
2693#ifdef TCP_USER_TIMEOUT
2735 "libpq is incorrectly linked to backend functions\n");
3046 MemSet(&hint, 0,
sizeof(hint));
3051 if (
ch->port ==
NULL ||
ch->port[0] ==
'\0')
3201#define ENCRYPTION_NEGOTIATION_FAILED(msg) \
3203 switch (encryption_negotiation_failed(conn)) \
3206 libpq_append_conn_error(conn, (msg)); \
3207 goto error_return; \
3209 conn->status = CONNECTION_MADE; \
3210 return PGRES_POLLING_WRITING; \
3212 need_new_connection = true; \
3222#define CONNECTION_FAILED() \
3224 if (connection_failed(conn)) \
3226 need_new_connection = true; \
3230 goto error_return; \
3277 "GSSAPI encryption required but it is not supported over a local socket");
3285 "GSSAPI encryption required but no credential cache");
3381#ifndef SOCK_NONBLOCK
3423 (
char *) &
on,
sizeof(
on)) < 0)
3436#ifdef SIO_KEEPALIVE_VALS
3813 else if (
SSLok ==
'N')
3828 else if (
SSLok ==
'E')
4067#define MAX_ERRLEN 30000
4268 "internal error: async authentication has no handler");
4293 "internal error: async cleanup did not release polling socket");
4316 "internal error: async authentication did not set a socket for polling");
4363 const char *sqlstate;
4423 "SHOW transaction_read_only"))
4481 "SELECT pg_catalog.pg_is_in_recovery()"))
4623 "SHOW transaction_read_only");
4673 "SELECT pg_is_in_recovery()");
4686 "invalid connection state %d, probably indicative of memory corruption",
4724 "GSSAPI encryption required but it is not supported over a local socket");
4773#if defined(USE_SSL) || defined(ENABLE_GSS)
4819#define SELECT_NEXT_METHOD(method) \
4821 if ((remaining_methods & method) != 0) \
4823 conn->current_enc_method = method; \
4853 "GSSAPI encryption required but no credential cache");
4880#undef SELECT_NEXT_METHOD
5448#define LDAP_URL "ldap://"
5449#define LDAP_DEF_PORT 389
5450#define PGLDAP_TIMEOUT 2
5452#define ld_is_sp_tab(x) ((x) == ' ' || (x) == '\t')
5453#define ld_is_nl_cr(x) ((x) == '\r' || (x) == '\n')
5525 "invalid LDAP URL \"%s\": scheme must be ldap://",
purl);
5537 if (p ==
NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5540 "invalid LDAP URL \"%s\": missing distinguished name",
5549 if ((p =
strchr(
dn,
'?')) ==
NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5552 "invalid LDAP URL \"%s\": must have exactly one attribute",
5561 if ((p =
strchr(
attrs[0],
'?')) ==
NULL || *(p + 1) ==
'\0' || *(p + 1) ==
'?')
5564 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5576 "invalid LDAP URL \"%s\": no filter",
5598 "invalid LDAP URL \"%s\": invalid port number",
5610 "invalid LDAP URL \"%s\": must have exactly one attribute",
5626 "invalid LDAP URL \"%s\": must have search scope (base/one/sub)",
5778 "connection info string size exceeds the maximum allowed (%d)",
5785 size +=
values[
i]->bv_len + 1;
5809 for (p = result; *p !=
'\0'; ++p)
5829 "missing \"=\" after \"%s\" in connection info string",
5848 "missing \"=\" after \"%s\" in connection info string",
5885 else if (*p ==
'\\')
5934 "unterminated quoted string in connection info string");
6057 "line %d too long in service file \"%s\"",
6070 while (*line &&
isspace((
unsigned char) line[0]))
6074 if (line[0] ==
'\0' || line[0] ==
'#')
6104 if (
strncmp(line,
"ldap", 4) == 0)
6128 "syntax error in service file \"%s\", line %d",
6136 if (
strcmp(key,
"service") == 0)
6139 "nested \"service\" specifications not supported in service file \"%s\", line %d",
6146 if (
strcmp(key,
"servicefile") == 0)
6149 "nested \"servicefile\" specifications not supported in service file \"%s\", line %d",
6181 "syntax error in service file \"%s\", line %d",
6413 "missing \"=\" after \"%s\" in connection info string",
6461 libpq_append_error(errorMessage,
"unterminated quoted string in connection info string");
6617 for (k = 0;
options[k].keyword; k++)
6694 *sslrootcert =
NULL;
6802 if (sslrootcert->val &&
strcmp(sslrootcert->val,
"system") == 0)
6888 bool retval =
false;
6915 "invalid URI propagated to internal parser routine: \"%s\"",
6923 while (*p && *p !=
'@' && *p !=
'/')
6934 while (*p !=
':' && *p !=
'@')
6943 errorMessage,
false,
true))
6956 errorMessage,
false,
true))
6987 while (*p && *p !=
']')
6992 "end of string reached when looking for matching \"]\" in IPv6 host address in URI: \"%s\"",
6999 "IPv6 host address may not be empty in URI: \"%s\"",
7011 if (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
7014 "unexpected character \"%c\" at position %d in URI (expected \":\" or \"/\"): \"%s\"",
7015 *p, (
int) (p -
buf + 1),
uri);
7028 while (*p && *p !=
':' && *p !=
'/' && *p !=
'?' && *p !=
',')
7040 const char *
port = ++p;
7042 while (*p && *p !=
'/' && *p !=
'?' && *p !=
',')
7063 errorMessage,
false,
true))
7067 errorMessage,
false,
true))
7072 const char *
dbname = ++p;
7075 while (*p && *p !=
'?')
7088 errorMessage,
false,
true))
7125 char *keyword = params;
7143 "extra key/value separator \"=\" in URI query parameter: \"%s\"",
7151 else if (*p ==
'&' || *p ==
'\0')
7163 "missing key/value separator \"=\" in URI query parameter: \"%s\"",
7175 if (keyword ==
NULL)
7192 if (
strcmp(keyword,
"ssl") == 0 &&
7199 keyword =
"sslmode";
7210 errorMessage,
true,
false))
7215 "invalid URI query parameter: \"%s\"",
7256 const char *q =
str;
7267 for (
const char *s = q; *s ==
' '; s++)
7278 if (*q ==
' ' || *q ==
'\0')
7299 "invalid percent-encoded token: \"%s\"",
7309 "forbidden value %%00 in percent-encoded value: \"%s\"",
7321 for (
const char *s = q; *s ==
' '; s++)
7331 "unexpected spaces found in \"%s\", use percent-encoded spaces (%%20) instead",
7374 const char *keyword)
7400 const char *keyword,
const char *
value,
7412 if (
strcmp(keyword,
"requiressl") == 0)
7414 keyword =
"sslmode";
7415 if (
value[0] ==
'1')
7426 "invalid connection option \"%s\"",
7668 return pstatus->
value;
7805 static const char query[] =
"set client_encoding to '%s'";
7945 if (
tbuf[0] ==
'*' &&
tbuf[1] ==
':')
7979 const char *pgpassfile,
const char **
errmsg)
8011 fp =
fopen(pgpassfile,
"r");
8025 libpq_gettext(
"WARNING: password file \"%s\" is not a plain file\n"),
8035 libpq_gettext(
"WARNING: password file \"%s\" has group or world access; permissions should be u=rw (0600) or less\n"),
8066 if (!(
buf.len > 0 &&
buf.data[
buf.len - 1] ==
'\n') && !
feof(fp))
8070 if (
buf.data[0] !=
'#')
8102 for (
p1 =
p2 = ret; *
p1 !=
':' && *
p1 !=
'\0'; ++
p1, ++
p2)
8104 if (*
p1 ==
'\\' &&
p1[1] !=
'\0')
8159 if (!version ||
strlen(version) == 0)
8274 const char *context)
8298 while (*end !=
'\0' &&
isspace((
unsigned char) *end))
8319 const char *context)
int pg_b64_dec_len(int srclen)
int pg_b64_decode(const char *src, int len, uint8 *dst, int dstlen)
int ssl_min_protocol_version
int ssl_max_protocol_version
static Datum values[MAXATTR]
static void cleanup(void)
#define Assert(condition)
#define MemSet(start, val, len)
#define StaticAssertDecl(condition, errmessage)
#define fprintf(file, fmt, msg)
int errmsg(const char *fmt,...)
void err(int eval, const char *fmt,...)
const pg_fe_sasl_mech pg_oauth_mech
void pqClearOAuthToken(PGconn *conn)
const pg_fe_sasl_mech pg_scram_mech
int pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn, bool *async)
char * pg_fe_getauthname(PQExpBuffer errorMessage)
char * pg_fe_getusername(uid_t user_id, PQExpBuffer errorMessage)
int PQsendCancelRequest(PGconn *cancelConn)
PostgresPollingStatusType PQcancelPoll(PGcancelConn *cancelConn)
static void pqFreeCommandQueue(PGcmdQueueEntry *queue)
int PQserverVersion(const PGconn *conn)
static const char * conninfo_getval(PQconninfoOption *connOptions, const char *keyword)
int PQprotocolVersion(const PGconn *conn)
void pqDropConnection(PGconn *conn, bool flushInput)
int PQresetStart(PGconn *conn)
static bool connectOptions1(PGconn *conn, const char *conninfo)
static const PQEnvironmentOption EnvironmentOptions[]
#define CONNECTION_FAILED()
bool pqConnectOptions2(PGconn *conn)
static PQconninfoOption * conninfo_init(PQExpBuffer errorMessage)
static void sendTerminateConn(PGconn *conn)
char * PQoptions(const PGconn *conn)
static int setKeepalivesCount(PGconn *conn)
static PQconninfoOption * parse_connection_string(const char *connstr, PQExpBuffer errorMessage, bool use_defaults)
static int useKeepalives(PGconn *conn)
char * PQdb(const PGconn *conn)
static void defaultNoticeReceiver(void *arg, const PGresult *res)
static int uri_prefix_length(const char *connstr)
static bool pqParseProtocolVersion(const char *value, ProtocolVersion *result, PGconn *conn, const char *context)
static int store_conn_addrinfo(PGconn *conn, struct addrinfo *addrlist)
static int parseServiceFile(const char *serviceFile, const char *service, PQconninfoOption *options, PQExpBuffer errorMessage, bool *group_found)
static void connectFailureMessage(PGconn *conn, int errorno)
static bool sslVerifyProtocolRange(const char *min, const char *max)
static void default_threadlock(int acquire)
int PQfullProtocolVersion(const PGconn *conn)
static void libpq_prng_init(PGconn *conn)
void PQreset(PGconn *conn)
void pqClosePGconn(PGconn *conn)
static char * passwordFromFile(const char *hostname, const char *port, const char *dbname, const char *username, const char *pgpassfile, const char **errmsg)
bool pqGetHomeDirectory(char *buf, int bufsize)
struct _internalPQconninfoOption internalPQconninfoOption
static const char short_uri_designator[]
static void release_conn_addrinfo(PGconn *conn)
char * PQport(const PGconn *conn)
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
static int count_comma_separated_elems(const char *input)
static bool conninfo_add_defaults(PQconninfoOption *options, PQExpBuffer errorMessage)
static bool select_next_encryption_method(PGconn *conn, bool have_valid_connection)
PGconn * PQconnectdb(const char *conninfo)
char * PQhost(const PGconn *conn)
#define ERRCODE_APPNAME_UNKNOWN
static bool conninfo_uri_parse_params(char *params, PQconninfoOption *connOptions, PQExpBuffer errorMessage)
int PQconnectionUsedPassword(const PGconn *conn)
static void clear_allowed_sasl_mechs(PGconn *conn)
PQconninfoOption * PQconninfo(PGconn *conn)
static char * conninfo_uri_decode(const char *str, PQExpBuffer errorMessage)
static int setKeepalivesInterval(PGconn *conn)
static void fill_allowed_sasl_mechs(PGconn *conn)
static int setKeepalivesIdle(PGconn *conn)
PostgresPollingStatusType PQconnectPoll(PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
#define DefaultChannelBinding
bool pqParseIntParam(const char *value, int *result, PGconn *conn, const char *context)
static void defaultNoticeProcessor(void *arg, const char *message)
static void pgpassfileWarning(PGconn *conn)
char * PQtty(const PGconn *conn)
static int index_of_allowed_sasl_mech(PGconn *conn, const pg_fe_sasl_mech *mech)
static PGPing internal_ping(PGconn *conn)
static PQconninfoOption * conninfo_find(PQconninfoOption *connOptions, const char *keyword)
static const char uri_designator[]
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
static bool sslVerifyProtocolVersion(const char *version)
#define SELECT_NEXT_METHOD(method)
int PQconnectionNeedsPassword(const PGconn *conn)
char * PQpass(const PGconn *conn)
PostgresPollingStatusType PQresetPoll(PGconn *conn)
int PQconnectionUsedGSSAPI(const PGconn *conn)
static PQconninfoOption * conninfo_uri_parse(const char *uri, PQExpBuffer errorMessage, bool use_defaults)
void pqReleaseConnHosts(PGconn *conn)
static void emitHostIdentityInfo(PGconn *conn, const char *host_addr)
static bool connection_failed(PGconn *conn)
pgthreadlock_t pg_g_threadlock
ConnStatusType PQstatus(const PGconn *conn)
PGconn * PQconnectStart(const char *conninfo)
static int setTCPUserTimeout(PGconn *conn)
static PQconninfoOption * conninfo_array_parse(const char *const *keywords, const char *const *values, PQExpBuffer errorMessage, bool use_defaults, int expand_dbname)
int PQclientEncoding(const PGconn *conn)
PGconn * PQconnectStartParams(const char *const *keywords, const char *const *values, int expand_dbname)
static PQconninfoOption * conninfo_parse(const char *conninfo, PQExpBuffer errorMessage, bool use_defaults)
void PQfinish(PGconn *conn)
static void pqDropServerData(PGconn *conn)
PGconn * pqMakeEmptyPGconn(void)
PGPing PQping(const char *conninfo)
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
#define DefaultLoadBalanceHosts
static int connectNoDelay(PGconn *conn)
#define DefaultSSLNegotiation
PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, PQnoticeReceiver proc, void *arg)
PGconn * PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, const char *dbName, const char *login, const char *pwd)
char * PQhostaddr(const PGconn *conn)
int PQbackendPID(const PGconn *conn)
PQconninfoOption * PQconndefaults(void)
static PQconninfoOption * conninfo_storeval(PQconninfoOption *connOptions, const char *keyword, const char *value, PQExpBuffer errorMessage, bool ignoreMissing, bool uri_decode)
static bool conninfo_uri_parse_options(PQconninfoOption *options, const char *uri, PQExpBuffer errorMessage)
int pqConnectDBStart(PGconn *conn)
static void getHostaddr(PGconn *conn, char *host_addr, int host_addr_len)
char * PQuser(const PGconn *conn)
static void freePGconn(PGconn *conn)
bool pqCopyPGconn(PGconn *srcConn, PGconn *dstConn)
static char * pwdfMatchesString(char *buf, const char *token)
PGpipelineStatus PQpipelineStatus(const PGconn *conn)
static bool get_hexdigit(char digit, int *value)
#define ERRCODE_INVALID_PASSWORD
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
#define SASL_MECHANISM_COUNT
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
#define DefaultSSLCertMode
#define ERRCODE_CANNOT_CONNECT_NOW
static const internalPQconninfoOption PQconninfoOptions[]
#define ENCRYPTION_NEGOTIATION_FAILED(msg)
static bool recognized_connection_string(const char *connstr)
#define DefaultTargetSessionAttrs
static int parseServiceInfo(PQconninfoOption *options, PQExpBuffer errorMessage)
char * PQerrorMessage(const PGconn *conn)
static bool init_allowed_encryption_methods(PGconn *conn)
static const pg_fe_sasl_mech * supported_sasl_mechs[]
PGPing PQpingParams(const char *const *keywords, const char *const *values, int expand_dbname)
int PQsocket(const PGconn *conn)
int pqConnectDBComplete(PGconn *conn)
int PQsetClientEncoding(PGconn *conn, const char *encoding)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
static char * parse_comma_separated_list(char **startptr, bool *more)
int pqPacketSend(PGconn *conn, char pack_type, const void *buf, size_t buf_len)
static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions)
pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler)
int PQsendQueryContinue(PGconn *conn, const char *query)
int PQconsumeInput(PGconn *conn)
void pqClearAsyncResult(PGconn *conn)
int PQisBusy(PGconn *conn)
PGresult * PQexec(PGconn *conn, const char *query)
bool pg_GSS_have_cred_cache(gss_cred_id_t *cred_out)
int pqReadData(PGconn *conn)
int pqFlush(PGconn *conn)
void pqParseDone(PGconn *conn, int newInStart)
int pqPutMsgStart(char msg_type, PGconn *conn)
int pqGetc(char *result, PGconn *conn)
int pqGetInt(int *result, size_t bytes, PGconn *conn)
int pqPutnchar(const void *s, size_t len, PGconn *conn)
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
pg_usec_time_t PQgetCurrentTimeUSec(void)
void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, pg_usec_time_t end_time)
int pqGets_append(PQExpBuffer buf, PGconn *conn)
int pqPutMsgEnd(PGconn *conn)
char * pqBuildStartupPacket3(PGconn *conn, int *packetlen, const PQEnvironmentOption *options)
int pqGetNegotiateProtocolVersion3(PGconn *conn)
int pqGetErrorNotice3(PGconn *conn, bool isError)
PostgresPollingStatusType pqsecure_open_gss(PGconn *conn)
PostgresPollingStatusType pqsecure_open_client(PGconn *conn)
void pqsecure_close(PGconn *conn)
void pqTraceOutputCharResponse(PGconn *conn, const char *responseType, char response)
void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo *ai)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
int pg_getaddrinfo_all(const char *hostname, const char *servname, const struct addrinfo *hintp, struct addrinfo **result)
static const JsonPathKeyword keywords[]
#define PQresultErrorMessage
#define PQresultErrorField
@ CONNECTION_AUTHENTICATING
@ CONNECTION_CHECK_STANDBY
@ CONNECTION_AWAITING_RESPONSE
@ CONNECTION_CHECK_WRITABLE
@ CONNECTION_CHECK_TARGET
void(* pgthreadlock_t)(int acquire)
void(* PQnoticeReceiver)(void *arg, const PGresult *res)
void(* PQnoticeProcessor)(void *arg, const char *message)
PostgresPollingStatusType
#define pqClearConnErrorState(conn)
@ SERVER_TYPE_PREFER_STANDBY_PASS2
@ SERVER_TYPE_PREFER_STANDBY
bool pg_link_canary_is_frontend(void)
void libpq_append_conn_error(PGconn *conn, const char *fmt,...)
#define DEFAULT_PGSOCKET_DIR
static const char * connstr
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
#define pg_prng_strong_seed(state)
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_encoding_to_char
static const char * pghost
static const char * pgport
static const char * dbName
#define PG_STRERROR_R_BUFLEN
int pg_strcasecmp(const char *s1, const char *s2)
char * pg_inet_net_ntop(int af, const void *src, int bits, char *dst, size_t size)
bool pg_set_noblock(pgsocket sock)
void explicit_bzero(void *buf, size_t len)
int pg_get_encoding_from_locale(const char *ctype, bool write_message)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
int getpeereid(int sock, uid_t *uid, gid_t *gid)
#define PG_PROTOCOL_MAJOR(v)
#define PG_PROTOCOL_EARLIEST
#define PG_PROTOCOL_FULL(v)
static bool is_unixsock_path(const char *path)
#define PG_PROTOCOL_LATEST
#define UNIXSOCK_PATH(path, port, sockdir)
#define UNIXSOCK_PATH_BUFLEN
#define NEGOTIATE_GSS_CODE
#define NEGOTIATE_SSL_CODE
#define PG_PROTOCOL(m, n)
void initPQExpBuffer(PQExpBuffer str)
int enlargePQExpBuffer(PQExpBuffer str, size_t needed)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
#define PQExpBufferBroken(str)
#define PQExpBufferDataBroken(buf)
#define AUTH_REQ_SASL_CONT
#define PqMsg_AuthenticationRequest
#define PqMsg_NegotiateProtocolVersion
#define AUTH_REQ_PASSWORD
#define AUTH_REQ_GSS_CONT
#define PqMsg_ErrorResponse
#define AUTH_REQ_SASL_FIN
int pthread_mutex_unlock(pthread_mutex_t *mp)
int pthread_mutex_lock(pthread_mutex_t *mp)
#define PTHREAD_MUTEX_INITIALIZER
#define SCRAM_MAX_KEY_LEN
#define SCRAM_SHA_256_DEFAULT_ITERATIONS
const char * gai_strerror(int errcode)
int pg_strip_crlf(char *str)
PQnoticeReceiver noticeRec
PQnoticeProcessor noticeProc
struct sockaddr_storage addr
struct pgParameterStatus * next
uint8 * scram_client_key_binary
char * oauth_discovery_uri
PGTransactionStatusType xactStatus
const pg_fe_sasl_mech * sasl
size_t scram_client_key_len
char * ssl_max_protocol_version
PGTernaryBool in_hot_standby
uint8 * scram_server_key_binary
void(* cleanup_async_auth)(PGconn *conn)
bool client_finished_auth
PGcmdQueueEntry * cmd_queue_recycle
ProtocolVersion min_pversion
uint32 allowed_auth_methods
char * target_session_attrs
PGcmdQueueEntry * cmd_queue_tail
PQExpBufferData workBuffer
char * oauth_client_secret
char * max_protocol_version
char * load_balance_hosts
PGTernaryBool default_transaction_read_only
pgParameterStatus * pstatus
char * min_protocol_version
char * client_encoding_initial
char * keepalives_interval
char * pgtcp_user_timeout
char * ssl_min_protocol_version
PQExpBufferData errorMessage
ProtocolVersion max_pversion
PostgresPollingStatusType(* async_auth)(PGconn *conn)
PGAsyncStatusType asyncStatus
PGLoadBalanceType load_balance_type
int scram_sha_256_iterations
PGpipelineStatus pipelineStatus
uint8 allowed_enc_methods
PGNoticeHooks noticeHooks
PGTargetServerType target_server_type
size_t scram_server_key_len
PGcmdQueueEntry * cmd_queue_head
const pg_fe_sasl_mech * allowed_sasl_mechs[2]
PGContextVisibility show_context
void(* free)(void *state)
PGNoticeHooks noticeHooks
ExecStatusType resultStatus
static StringInfoData tmpbuf
#define socket(af, type, protocol)
#define connect(s, name, namelen)
int gettimeofday(struct timeval *tp, void *tzp)