104 (
errmsg(
"SSL configuration could not be loaded in child process")));
146 char remote_host[NI_MAXHOST];
147 char remote_port[NI_MAXSERV];
183 port->remote_host =
"";
184 port->remote_port =
"";
204 remote_host[0] =
'\0';
205 remote_port[0] =
'\0';
207 remote_host,
sizeof(remote_host),
208 remote_port,
sizeof(remote_port),
209 (
log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV)) != 0)
226 (
errmsg(
"connection received: host=%s port=%s",
231 (
errmsg(
"connection received: host=%s",
236#ifdef USE_INJECTION_POINTS
246 elog(
FATAL,
"protocol version 2 error triggered");
263 strspn(remote_host,
"0123456789.") < strlen(remote_host) &&
264 strspn(remote_host,
"0123456789ABCDEFabcdef:") < strlen(remote_host))
309 errmsg(
"the database system is starting up")));
315 errmsg(
"the database system is not accepting connections"),
316 errdetail(
"Hot standby mode is disabled.")));
320 errmsg(
"the database system is not yet accepting connections"),
321 errdetail(
"Recovery snapshot is not yet ready for hot standby."),
322 errhint(
"To enable hot standby, close write transactions with more than %d subtransactions on the primary server.",
327 errmsg(
"the database system is not yet accepting connections"),
328 errdetail(
"Consistent recovery state has not been yet reached.")));
333 errmsg(
"the database system is shutting down")));
338 errmsg(
"the database system is in recovery mode")));
342 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
343 errmsg(
"sorry, too many clients already")));
354 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
382 if (
port->database_name[0] !=
'\0')
385 if (
port->remote_port[0] !=
'\0')
410 if (firstbyte == EOF)
419 if (firstbyte != 0x16)
449 if (!
port->alpn_used)
452 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
453 errmsg(
"received direct SSL connection request without ALPN protocol negotiation extension")));
459 (
errmsg(
"direct SSL connection accepted")));
469 (
errmsg(
"direct SSL connection rejected")));
525 if (!ssl_done && !gss_done)
527 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
528 errmsg(
"incomplete startup packet")));
539 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
540 errmsg(
"invalid length of startup packet")));
555 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
556 errmsg(
"incomplete startup packet")));
597 (
errmsg(
"SSLRequest accepted")));
600 (
errmsg(
"SSLRequest rejected")));
609 errmsg(
"failed to send SSL negotiation response: %m")));
626 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
627 errmsg(
"received unencrypted data after SSL request"),
628 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
643 if (
port->laddr.addr.ss_family != AF_UNIX)
651 (
errmsg(
"GSSENCRequest accepted")));
654 (
errmsg(
"GSSENCRequest rejected")));
663 errmsg(
"failed to send GSSAPI negotiation response: %m")));
680 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
681 errmsg(
"received unencrypted data after GSSAPI encryption request"),
682 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
708 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
709 errmsg(
"unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
724 List *unrecognized_protocol_options =
NIL;
735 char *nameptr =
buf + offset;
739 if (*nameptr ==
'\0')
741 valoffset = offset + strlen(nameptr) + 1;
742 if (valoffset >=
len)
744 valptr =
buf + valoffset;
746 if (strcmp(nameptr,
"database") == 0)
748 else if (strcmp(nameptr,
"user") == 0)
750 else if (strcmp(nameptr,
"options") == 0)
752 else if (strcmp(nameptr,
"replication") == 0)
761 if (strcmp(valptr,
"database") == 0)
768 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
769 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
772 errhint(
"Valid values are: \"false\", 0, \"true\", 1, \"database\".")));
774 else if (strncmp(nameptr,
"_pq_.", 5) == 0)
781 unrecognized_protocol_options =
798 if (strcmp(nameptr,
"application_name") == 0)
803 offset = valoffset + strlen(valptr) + 1;
810 if (offset !=
len - 1)
812 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
813 errmsg(
"invalid startup packet layout: expected terminator as last byte")));
822 unrecognized_protocol_options !=
NIL)
827 if (
port->user_name == NULL ||
port->user_name[0] ==
'\0')
829 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
830 errmsg(
"no PostgreSQL user name specified in startup packet")));
833 if (
port->database_name == NULL ||
port->database_name[0] ==
'\0')
859 port->database_name[0] =
'\0';
883 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
884 errmsg(
"invalid length of query cancel packet")));
888 if (
len == 0 ||
len > 256)
891 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
892 errmsg(
"invalid length of query cancel key")));
925 foreach(lc, unrecognized_protocol_options)
1013 for (
size_t i = 0;
i <
lengthof(compat_options);
i++)
1022 GUC_check_errdetail(
"Cannot specify log_connections option \"%s\" in a list with other options.",
1032 foreach(l, elemlist)
1103 *((
int *) *extra) = flags;
bool check_log_connections(char **newval, void **extra, GucSource source)
bool Trace_connection_negotiation
ConnectionTiming conn_timing
static void SendNegotiateProtocolVersion(List *unrecognized_protocol_options)
static void process_startup_packet_die(SIGNAL_ARGS)
static void StartupPacketTimeoutHandler(void)
static void BackendInitialize(ClientSocket *client_sock, CAC_state cac)
static int ProcessSSLStartup(Port *port)
char * log_connections_string
static void ProcessCancelRequestPacket(Port *port, void *pkt, int pktlen)
void assign_log_connections(const char *newval, void *extra)
void BackendMain(const void *startup_data, size_t startup_data_len)
static int ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
static bool validate_log_connections_options(List *elemlist, uint32 *flags)
@ LOG_CONNECTION_AUTHORIZATION
@ LOG_CONNECTION_SETUP_DURATIONS
@ LOG_CONNECTION_AUTHENTICATION
ssize_t secure_open_gssapi(Port *port)
int secure_initialize(bool isServerStart)
ssize_t secure_write(Port *port, const void *ptr, size_t len)
int secure_open_server(Port *port)
bool parse_bool(const char *value, bool *result)
#define TIMESTAMP_MINUS_INFINITY
int errcode_for_socket_access(void)
int errmsg_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ReserveExternalFD(void)
#define ERRCODE_CANNOT_CONNECT_NOW
struct ClientSocket * MyClientSocket
ProtocolVersion FrontendProtocol
void * guc_malloc(int elevel, size_t size)
#define GUC_check_errdetail
Assert(PointerIsAligned(start, uint64))
#define INJECTION_POINT(name)
#define IS_INJECTION_POINT_ATTACHED(name)
int pg_getnameinfo_all(const struct sockaddr_storage *addr, int salen, char *node, int nodelen, char *service, int servicelen, int flags)
void check_on_shmem_exit_lists_are_empty(void)
List * lappend(List *list, void *datum)
void list_free(List *list)
char * MemoryContextStrdup(MemoryContext context, const char *string)
char * pstrdup(const char *in)
void pfree(void *pointer)
MemoryContext TopMemoryContext
const char * GetBackendTypeDesc(BackendType backendType)
BackendType MyBackendType
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
static rewind_source * source
int pg_strcasecmp(const char *s1, const char *s2)
CommandDest whereToSendOutput
void PostgresMain(const char *dbname, const char *username)
bool ClientAuthInProgress
int AuthenticationTimeout
PGDLLIMPORT bool LoadedSSL
Port * pq_init(ClientSocket *client_sock)
ssize_t pq_buffer_remaining_data(void)
int pq_getbytes(void *b, size_t len)
void pq_startmsgread(void)
#define PG_PROTOCOL_MAJOR(v)
#define PG_PROTOCOL_EARLIEST
#define CANCEL_REQUEST_CODE
#define MAX_STARTUP_PACKET_LENGTH
#define PG_PROTOCOL_LATEST
#define NEGOTIATE_GSS_CODE
#define NEGOTIATE_SSL_CODE
#define PG_PROTOCOL(m, n)
#define PG_PROTOCOL_MINOR(v)
#define PGPROC_MAX_CACHED_SUBXIDS
void SendCancelRequest(int backendPID, char *cancel_key, int cancel_key_len)
#define PqMsg_NegotiateProtocolVersion
void init_ps_display(const char *fixed_part)
static void set_ps_display(const char *activity)
void pg_usleep(long microsec)
const char * gai_strerror(int ecode)
char * pg_clean_ascii(const char *str, int alloc_flags)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
CAC_state canAcceptConnections
char cancelAuthCode[FLEXIBLE_ARRAY_MEMBER]
TimestampTz ready_for_use
void enable_timeout_after(TimeoutId id, int delay_ms)
void InitializeTimeouts(void)
void disable_timeout(TimeoutId id, bool keep_indicator)
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)