PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <netdb.h>
#include <time.h>
#include <unistd.h>
#include "common/ip.h"
#include "common/link-canary.h"
#include "common/scram-common.h"
#include "common/string.h"
#include "fe-auth.h"
#include "libpq-fe.h"
#include "libpq-int.h"
#include "mb/pg_wchar.h"
#include "pg_config_paths.h"
#include "port/pg_bswap.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <pthread.h>
Go to the source code of this file.
Data Structures | |
struct | _internalPQconninfoOption |
Macros | |
#define | PGPASSFILE ".pgpass" |
#define | ERRCODE_APPNAME_UNKNOWN "42704" |
#define | ERRCODE_INVALID_PASSWORD "28P01" |
#define | ERRCODE_CANNOT_CONNECT_NOW "57P03" |
#define | DefaultHost "localhost" |
#define | DefaultOption "" |
#define | DefaultChannelBinding "disable" |
#define | DefaultTargetSessionAttrs "any" |
#define | DefaultLoadBalanceHosts "disable" |
#define | DefaultSSLMode "disable" |
#define | DefaultSSLCertMode "disable" |
#define | DefaultGSSMode "disable" |
#define | MAX_ERRLEN 30000 |
Typedefs | |
typedef struct _internalPQconninfoOption | internalPQconninfoOption |
Variables | |
static const internalPQconninfoOption | PQconninfoOptions [] |
static const PQEnvironmentOption | EnvironmentOptions [] |
static const char | uri_designator [] = "postgresql://" |
static const char | short_uri_designator [] = "postgres://" |
pgthreadlock_t | pg_g_threadlock = default_threadlock |
#define DefaultChannelBinding "disable" |
Definition at line 121 of file fe-connect.c.
#define DefaultGSSMode "disable" |
Definition at line 136 of file fe-connect.c.
#define DefaultHost "localhost" |
Definition at line 116 of file fe-connect.c.
#define DefaultLoadBalanceHosts "disable" |
Definition at line 124 of file fe-connect.c.
#define DefaultOption "" |
Definition at line 117 of file fe-connect.c.
#define DefaultSSLCertMode "disable" |
Definition at line 130 of file fe-connect.c.
#define DefaultSSLMode "disable" |
Definition at line 129 of file fe-connect.c.
#define DefaultTargetSessionAttrs "any" |
Definition at line 123 of file fe-connect.c.
#define ERRCODE_APPNAME_UNKNOWN "42704" |
Definition at line 86 of file fe-connect.c.
#define ERRCODE_CANNOT_CONNECT_NOW "57P03" |
Definition at line 91 of file fe-connect.c.
#define ERRCODE_INVALID_PASSWORD "28P01" |
Definition at line 89 of file fe-connect.c.
#define MAX_ERRLEN 30000 |
#define PGPASSFILE ".pgpass" |
Definition at line 75 of file fe-connect.c.
typedef struct _internalPQconninfoOption internalPQconninfoOption |
|
static |
Definition at line 4563 of file fe-connect.c.
References pg_conn::asyncStatus, conn, CONNECTION_BAD, pg_conn::nonblocking, PGASYNC_IDLE, pg_conn::pipelineStatus, PQ_PIPELINE_OFF, pqClearAsyncResult(), pqClearConnErrorState, pqDropConnection(), pqDropServerData(), PQTRANS_IDLE, release_conn_addrinfo(), sendTerminateConn(), pg_conn::status, and pg_conn::xactStatus.
Referenced by PQfinish(), PQreset(), and PQresetStart().
|
static |
Definition at line 2405 of file fe-connect.c.
References conn, pg_conn::connect_timeout, CONNECTION_BAD, CONNECTION_NEEDED, flag(), parse_int_param(), PGRES_POLLING_OK, PGRES_POLLING_READING, PGRES_POLLING_WRITING, PQconnectPoll(), pqWaitTimed(), pg_conn::status, pg_conn::try_next_addr, pg_conn::whichaddr, and pg_conn::whichhost.
Referenced by internal_ping(), PQconnectdb(), PQconnectdbParams(), PQreset(), and PQsetdbLogin().
|
static |
Definition at line 2335 of file fe-connect.c.
References appendPQExpBufferStr(), conn, CONNECTION_BAD, CONNECTION_NEEDED, pg_conn::errorMessage, pg_conn::inCursor, pg_conn::inEnd, pg_conn::inStart, pg_conn::options_valid, pg_conn::outCount, pg_link_canary_is_frontend(), PGRES_POLLING_WRITING, PQconnectPoll(), pqDropConnection(), SERVER_TYPE_PREFER_STANDBY, SERVER_TYPE_PREFER_STANDBY_PASS2, pg_conn::status, pg_conn::target_server_type, pg_conn::try_next_addr, pg_conn::try_next_host, and pg_conn::whichhost.
Referenced by PQconnectStart(), PQconnectStartParams(), PQreset(), PQresetStart(), and PQsetdbLogin().
|
static |
Definition at line 2046 of file fe-connect.c.
References SockAddr::addr, appendPQExpBuffer(), conn, pg_conn::errorMessage, libpq_append_conn_error(), PG_STRERROR_R_BUFLEN, pg_conn::raddr, and SOCK_STRERROR.
Referenced by PQconnectPoll().
|
static |
Definition at line 1931 of file fe-connect.c.
References conn, libpq_append_conn_error(), PG_STRERROR_R_BUFLEN, pg_conn::sock, SOCK_ERRNO, and SOCK_STRERROR.
Referenced by PQconnectPoll().
Definition at line 945 of file fe-connect.c.
References conn, CONNECTION_BAD, pg_conn::errorMessage, fillPGconn(), parse_connection_string(), PQconninfoFree(), and pg_conn::status.
Referenced by PQconnectStart(), and PQsetdbLogin().
Definition at line 1068 of file fe-connect.c.
References pg_conn::allowed_auth_methods, Assert(), AUTH_REQ_GSS, AUTH_REQ_GSS_CONT, AUTH_REQ_MD5, AUTH_REQ_PASSWORD, AUTH_REQ_SASL, AUTH_REQ_SASL_CONT, AUTH_REQ_SASL_FIN, AUTH_REQ_SSPI, pg_conn::auth_required, calloc, pg_conn::channel_binding, CHT_HOST_ADDRESS, CHT_HOST_NAME, CHT_UNIX_SOCKET, pg_conn::client_encoding_initial, conn, CONNECTION_BAD, pg_conn::connhost, count_comma_separated_elems(), pg_conn::dbName, DEFAULT_PGSOCKET_DIR, DefaultChannelBinding, DefaultGSSMode, DefaultHost, DefaultSSLCertMode, DefaultSSLMode, pg_conn::errorMessage, free, pg_conn::gssencmode, pg_conn_host::host, pg_conn_host::hostaddr, i, is_unixsock_path(), j, libpq_append_conn_error(), libpq_prng_init(), LOAD_BALANCE_DISABLE, pg_conn::load_balance_hosts, LOAD_BALANCE_RANDOM, pg_conn::load_balance_type, malloc, MAXPGPATH, pg_conn::nconnhost, pg_conn::options_valid, parse_comma_separated_list(), pg_conn_host::password, passwordFromFile(), pg_encoding_to_char(), pg_fe_getauthname(), pg_get_encoding_from_locale(), pg_prng_uint64_range(), pg_conn::pghost, pg_conn::pghostaddr, pg_conn::pgpass, PGPASSFILE, pg_conn::pgpassfile, pg_conn::pgport, pg_conn::pguser, pg_conn_host::port, pqGetHomeDirectory(), pg_conn::prng_state, pg_conn::require_auth, SERVER_TYPE_ANY, SERVER_TYPE_PREFER_STANDBY, SERVER_TYPE_PRIMARY, SERVER_TYPE_READ_ONLY, SERVER_TYPE_READ_WRITE, SERVER_TYPE_STANDBY, snprintf, pg_conn::ssl_max_protocol_version, pg_conn::ssl_min_protocol_version, pg_conn::sslcertmode, pg_conn::sslmode, pg_conn::sslrootcert, sslVerifyProtocolRange(), sslVerifyProtocolVersion(), pg_conn::status, pg_conn::target_server_type, pg_conn::target_session_attrs, pg_conn_host::type, and pg_conn::whichhost.
Referenced by PQconnectStart(), PQconnectStartParams(), and PQsetdbLogin().
|
static |
Definition at line 6278 of file fe-connect.c.
References free, libpq_append_error(), parseServiceInfo(), pg_fe_getauthname(), option::val, and _PQconninfoOption::val.
Referenced by conninfo_array_parse(), conninfo_parse(), conninfo_uri_parse(), and PQconndefaults().
|
static |
Definition at line 6120 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), free, i, _PQconninfoOption::keyword, libpq_append_error(), options, parse_connection_string(), PQconninfoFree(), recognized_connection_string(), option::val, val, _PQconninfoOption::val, and values.
Referenced by PQconnectStartParams().
|
static |
Definition at line 7019 of file fe-connect.c.
Referenced by conninfo_getval(), and conninfo_storeval().
|
static |
Definition at line 6929 of file fe-connect.c.
References conninfo_find(), and option::val.
Referenced by fillPGconn(), and parseServiceInfo().
|
static |
Definition at line 5851 of file fe-connect.c.
References _internalPQconninfoOption::keyword, libpq_append_error(), malloc, MemSet, options, and PQconninfoOptions.
Referenced by conninfo_array_parse(), conninfo_parse(), conninfo_uri_parse(), PQconndefaults(), and PQconninfo().
|
static |
Definition at line 5944 of file fe-connect.c.
References buf, conninfo_add_defaults(), conninfo_init(), conninfo_storeval(), free, libpq_append_error(), options, and PQconninfoFree().
Referenced by parse_connection_string().
|
static |
Definition at line 6955 of file fe-connect.c.
References conninfo_find(), conninfo_uri_decode(), free, libpq_append_error(), option::val, and value.
Referenced by conninfo_parse(), conninfo_uri_parse_options(), conninfo_uri_parse_params(), and PQconninfo().
|
static |
Definition at line 6840 of file fe-connect.c.
References buf, free, get_hexdigit(), libpq_append_error(), malloc, and generate_unaccent_rules::str.
Referenced by conninfo_storeval(), and conninfo_uri_parse_params().
|
static |
Definition at line 6413 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), conninfo_uri_parse_options(), options, and PQconninfoFree().
Referenced by parse_connection_string().
|
static |
Definition at line 6466 of file fe-connect.c.
References appendPQExpBufferChar(), appendPQExpBufferStr(), buf, cleanup(), conninfo_storeval(), conninfo_uri_parse_params(), PQExpBufferData::data, dbname, free, initPQExpBuffer(), libpq_append_error(), password, port, PQExpBufferDataBroken, termPQExpBuffer(), uri_prefix_length(), and user.
Referenced by conninfo_uri_parse().
|
static |
Definition at line 6707 of file fe-connect.c.
References conninfo_storeval(), conninfo_uri_decode(), free, PQExpBufferData::len, libpq_append_error(), and value.
Referenced by conninfo_uri_parse_options().
|
static |
Definition at line 982 of file fe-connect.c.
References input.
Referenced by connectOptions2().
|
static |
Definition at line 7788 of file fe-connect.c.
References Assert(), pthread_mutex_init(), pthread_mutex_lock(), and pthread_mutex_unlock().
Referenced by PQregisterThreadLock().
|
static |
|
static |
Definition at line 7450 of file fe-connect.c.
References arg, pg_result::noticeHooks, PGNoticeHooks::noticeProc, PGNoticeHooks::noticeProcArg, PQresultErrorMessage(), and res.
Referenced by makeEmptyPGconn().
|
static |
Definition at line 1990 of file fe-connect.c.
References SockAddr::addr, appendPQExpBuffer(), CHT_HOST_ADDRESS, conn, pg_conn::connhost, pg_conn::errorMessage, pg_conn_host::host, pg_conn_host::hostaddr, libpq_gettext, pg_getnameinfo_all(), pg_conn_host::port, pg_conn::raddr, SockAddr::salen, pg_conn_host::type, and pg_conn::whichhost.
Referenced by PQconnectPoll().
|
static |
Definition at line 905 of file fe-connect.c.
References conn, conninfo_getval(), free, libpq_append_conn_error(), and PQconninfoOptions.
Referenced by connectOptions1(), and PQconnectStartParams().
|
static |
Definition at line 4387 of file fe-connect.c.
References pg_conn::appname, pg_conn::channel_binding, pg_conn::client_encoding_initial, conn, PGEventConnDestroy::conn, pg_conn::connect_timeout, pg_conn::connhost, pg_conn::connip, pg_conn::dbName, pg_conn::errorMessage, pg_conn::events, explicit_bzero(), pg_conn::fbappname, free, pg_conn::gssdelegation, pg_conn::gssencmode, pg_conn::gsslib, pg_conn_host::host, pg_conn_host::hostaddr, i, pg_conn::inBuffer, pg_conn::keepalives, pg_conn::keepalives_count, pg_conn::keepalives_idle, pg_conn::keepalives_interval, pg_conn::krbsrvname, pg_conn::load_balance_hosts, PGEvent::name, pg_conn::nconnhost, pg_conn::nEvents, pg_conn::outBuffer, PGEvent::passThrough, pg_conn_host::password, PGEVT_CONNDESTROY, pg_conn::pghost, pg_conn::pghostaddr, pg_conn::pgoptions, pg_conn::pgpass, pg_conn::pgpassfile, pg_conn::pgport, pg_conn::pgtcp_user_timeout, pg_conn::pguser, pg_conn_host::port, PGEvent::proc, pg_conn::replication, pg_conn::require_auth, pg_conn::requirepeer, pg_conn::rowBuf, pg_conn::ssl_max_protocol_version, pg_conn::ssl_min_protocol_version, pg_conn::sslcert, pg_conn::sslcertmode, pg_conn::sslcompression, pg_conn::sslcrl, pg_conn::sslcrldir, pg_conn::sslkey, pg_conn::sslmode, pg_conn::sslpassword, pg_conn::sslrootcert, pg_conn::sslsni, pg_conn::target_session_attrs, termPQExpBuffer(), pg_conn::workBuffer, and pg_conn::write_err_msg.
Referenced by makeEmptyPGconn(), and PQfinish().
|
static |
Definition at line 6908 of file fe-connect.c.
References value.
Referenced by conninfo_uri_decode().
|
static |
Definition at line 1957 of file fe-connect.c.
References SockAddr::addr, conn, pg_inet_net_ntop(), and pg_conn::raddr.
Referenced by PQconnectPoll().
Definition at line 4224 of file fe-connect.c.
References pg_conn::auth_req_received, conn, connectDBComplete(), CONNECTION_BAD, ERRCODE_CANNOT_CONNECT_NOW, pg_conn::last_sqlstate, pg_conn::options_valid, PQPING_NO_ATTEMPT, PQPING_NO_RESPONSE, PQPING_OK, PQPING_REJECT, and pg_conn::status.
Referenced by PQping(), and PQpingParams().
|
static |
Definition at line 1041 of file fe-connect.c.
References conn, gettimeofday(), pg_prng_seed(), pg_prng_strong_seed, and pg_conn::prng_state.
Referenced by connectOptions2().
|
static |
Definition at line 4288 of file fe-connect.c.
References pg_conn::asyncStatus, pg_conn::client_encoding, conn, CONNECTION_BAD, pg_conn::default_transaction_read_only, defaultNoticeProcessor(), defaultNoticeReceiver(), pg_conn::errorMessage, freePGconn(), pg_conn::in_hot_standby, pg_conn::inBuffer, pg_conn::inBufSize, initPQExpBuffer(), malloc, MemSet, pg_conn::nonblocking, pg_conn::noticeHooks, PGNoticeHooks::noticeProc, PGNoticeHooks::noticeRec, pg_conn::options_valid, pg_conn::outBuffer, pg_conn::outBufSize, pg_conn::Pfdebug, PG_BOOL_UNKNOWN, PG_SQL_ASCII, PGASYNC_IDLE, PGINVALID_SOCKET, pg_conn::pipelineStatus, PQ_PIPELINE_OFF, PQERRORS_DEFAULT, PQExpBufferBroken, PQSHOW_CONTEXT_ERRORS, PQTRANS_IDLE, pg_conn::rowBuf, pg_conn::rowBufLen, SCRAM_SHA_256_DEFAULT_ITERATIONS, pg_conn::scram_sha_256_iterations, pg_conn::show_context, pg_conn::sock, pg_conn::status, pg_conn::std_strings, pg_conn::verbosity, pg_conn::workBuffer, and pg_conn::xactStatus.
Referenced by PQconnectStart(), PQconnectStartParams(), and PQsetdbLogin().
|
static |
|
static |
|
static |
Definition at line 5890 of file fe-connect.c.
References conninfo_parse(), conninfo_uri_parse(), connstr, and uri_prefix_length().
Referenced by connectOptions1(), conninfo_array_parse(), and PQconninfoParse().
|
static |
Definition at line 2085 of file fe-connect.c.
References Assert(), conn, error(), libpq_append_conn_error(), and value.
Referenced by connectDBComplete(), PQconnectPoll(), PQgetCancel(), setKeepalivesCount(), setKeepalivesIdle(), setKeepalivesInterval(), and setTCPUserTimeout().
|
static |
Definition at line 5651 of file fe-connect.c.
References buf, exit(), i, sort-test::key, len, libpq_append_error(), and val.
Referenced by parseServiceInfo().
|
static |
Definition at line 5583 of file fe-connect.c.
References conninfo_getval(), libpq_append_error(), MAXPGPATH, parseServiceFile(), pqGetHomeDirectory(), snprintf, stat, and strlcpy().
Referenced by conninfo_add_defaults().
|
static |
Definition at line 7514 of file fe-connect.c.
References buf, dbname, DEFAULT_PGSOCKET_DIR, DefaultHost, enlargePQExpBuffer(), explicit_bzero(), fprintf, hostname, initPQExpBuffer(), is_unixsock_path(), len, libpq_gettext, p2, pg_strip_crlf(), port, pwdfMatchesString(), S_IRWXG, S_IRWXO, S_ISREG, stat::st_mode, stat, termPQExpBuffer(), and username.
Referenced by connectOptions2().
|
static |
Definition at line 7654 of file fe-connect.c.
References conn, pg_conn::connhost, ERRCODE_INVALID_PASSWORD, libpq_append_conn_error(), pg_conn_host::password, pg_conn::password_needed, PG_DIAG_SQLSTATE, pg_conn::pgpassfile, PQresultErrorField(), pg_conn::result, and pg_conn::whichhost.
Referenced by PQconnectPoll().
int PQbackendPID | ( | const PGconn * | conn | ) |
Definition at line 7282 of file fe-connect.c.
References pg_conn::be_pid, conn, CONNECTION_OK, and pg_conn::status.
Referenced by get_prompt(), libpqrcv_get_backend_pid(), main(), and StartLogStreamer().
int PQcancel | ( | PGcancel * | cancel, |
char * | errbuf, | ||
int | errbufsize | ||
) |
Definition at line 4821 of file fe-connect.c.
References SockAddr::addr, pg_cancel::be_key, pg_cancel::be_pid, buf, CANCEL_REQUEST_CODE, closesocket, connect, EINTR, pg_cancel::keepalives, pg_cancel::keepalives_count, pg_cancel::keepalives_idle, pg_cancel::keepalives_interval, optional_setsockopt(), pg_hton32, PGINVALID_SOCKET, pg_cancel::pgtcp_user_timeout, pg_cancel::raddr, recv, SockAddr::salen, send, SOCK_ERRNO, SOCK_ERRNO_SET, socket, strlcpy(), and val.
Referenced by dblink_cancel_query(), DisconnectDatabase(), disconnectDatabase(), handle_sigint(), pgfdw_cancel_query_begin(), PQrequestCancel(), ShutdownWorkersHard(), sigTermHandler(), and try_complete_step().
int PQclientEncoding | ( | const PGconn * | conn | ) |
Definition at line 7336 of file fe-connect.c.
References pg_conn::client_encoding, conn, CONNECTION_OK, and pg_conn::status.
Referenced by appendQualifiedRelation(), appendStringLiteralConn(), dblink_connect(), dblink_get_conn(), exec_command_encoding(), main(), processSQLNamePattern(), SendQuery(), setup_connection(), SyncVariables(), and vacuum_one_database().
PQconninfoOption* PQconndefaults | ( | void | ) |
Definition at line 1778 of file fe-connect.c.
References conninfo_add_defaults(), conninfo_init(), initPQExpBuffer(), PQconninfoFree(), PQExpBufferDataBroken, and termPQExpBuffer().
Referenced by check_pghost_envvar(), dblink_fdw_validator(), do_connect(), get_connect_string(), InitPgFdwOptions(), and main().
PGconn* PQconnectdb | ( | const char * | conninfo | ) |
Definition at line 731 of file fe-connect.c.
References conn, connectDBComplete(), CONNECTION_BAD, PQconnectStart(), and pg_conn::status.
Referenced by get_db_conn(), and main().
PGconn* PQconnectdbParams | ( | const char *const * | keywords, |
const char *const * | values, | ||
int | expand_dbname | ||
) |
Definition at line 676 of file fe-connect.c.
References conn, connectDBComplete(), CONNECTION_BAD, PQconnectStartParams(), pg_conn::status, and values.
Referenced by ConnectDatabase(), connectDatabase(), do_connect(), doConnect(), ECPGconnect(), GetConnection(), main(), sql_conn(), and vacuumlo().
int PQconnectionNeedsPassword | ( | const PGconn * | conn | ) |
Definition at line 7299 of file fe-connect.c.
References conn, password, pg_conn::password_needed, and PQpass().
Referenced by ConnectDatabase(), connectDatabase(), do_connect(), doConnect(), GetConnection(), main(), sql_conn(), and vacuumlo().
int PQconnectionUsedGSSAPI | ( | const PGconn * | conn | ) |
Definition at line 7325 of file fe-connect.c.
References conn, and pg_conn::gssapi_used.
Referenced by dblink_security_check(), and pgfdw_security_check().
int PQconnectionUsedPassword | ( | const PGconn * | conn | ) |
Definition at line 7314 of file fe-connect.c.
References conn, and pg_conn::password_needed.
Referenced by ConnectDatabase(), dblink_security_check(), libpqrcv_connect(), and pgfdw_security_check().
PostgresPollingStatusType PQconnectPoll | ( | PGconn * | conn | ) |
Definition at line 2541 of file fe-connect.c.