1 /*-------------------------------------------------------------------------
4 * Definitions common to frontends and backends.
6 * NOTE: for historical reasons, this does not correspond to pqcomm.c.
7 * pqcomm.c's routines are declared in libpq.h.
9 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
10 * Portions Copyright (c) 1994, Regents of the University of California
12 * src/include/libpq/pqcomm.h
14 *-------------------------------------------------------------------------
19 #include <sys/socket.h>
22 #include <netinet/in.h>
26 struct sockaddr_storage addr
;
30 /* Configure the UNIX socket location for the well known port. */
32 #define UNIXSOCK_PATH(path, port, sockdir) \
33 (AssertMacro(sockdir), \
34 AssertMacro(*(sockdir) != '\0'), \
35 snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
39 * The maximum workable length of a socket path is what will fit into
40 * struct sockaddr_un. This is usually only 100 or so bytes :-(.
42 * For consistency, always pass a MAXPGPATH-sized buffer to UNIXSOCK_PATH(),
43 * then complain if the resulting string is >= UNIXSOCK_PATH_BUFLEN bytes.
44 * (Because the standard API for getaddrinfo doesn't allow it to complain in
45 * a useful way when the socket pathname is too long, we have to test for
46 * this explicitly, instead of just letting the subroutine return an error.)
48 #define UNIXSOCK_PATH_BUFLEN sizeof(((struct sockaddr_un *) NULL)->sun_path)
51 * A host that looks either like an absolute path or starts with @ is
52 * interpreted as a Unix-domain socket address.
55 is_unixsock_path(const char *path
)
57 return is_absolute_path(path
) || path
[0] == '@';
61 * These manipulate the frontend/backend protocol version number.
63 * The major number should be incremented for incompatible changes. The minor
64 * number should be incremented for compatible changes (eg. additional
67 * If a backend supports version m.n of the protocol it must actually support
68 * versions m.[0..n]. Backend support for version m-1 can be dropped after a
69 * `reasonable' length of time.
71 * A frontend isn't required to support anything other than the current
75 #define PG_PROTOCOL_MAJOR(v) ((v) >> 16)
76 #define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff)
77 #define PG_PROTOCOL(m,n) (((m) << 16) | (n))
80 * The earliest and latest frontend/backend protocol version supported.
81 * (Only protocol version 3 is currently supported)
84 #define PG_PROTOCOL_EARLIEST PG_PROTOCOL(3,0)
85 #define PG_PROTOCOL_LATEST PG_PROTOCOL(3,0)
87 typedef uint32 ProtocolVersion
; /* FE/BE protocol version number */
89 typedef ProtocolVersion MsgType
;
93 * Packet lengths are 4 bytes in network byte order.
95 * The initial length is omitted from the packet layouts appearing below.
98 typedef uint32 PacketLen
;
100 extern PGDLLIMPORT
bool Db_user_namespace
;
103 * In protocol 3.0 and later, the startup packet length is not fixed, but
104 * we set an arbitrary limit on it anyway. This is just to prevent simple
105 * denial-of-service attacks via sending enough data to run the server
108 #define MAX_STARTUP_PACKET_LENGTH 10000
111 /* These are the authentication request codes sent by the backend. */
113 #define AUTH_REQ_OK 0 /* User is authenticated */
114 #define AUTH_REQ_KRB4 1 /* Kerberos V4. Not supported any more. */
115 #define AUTH_REQ_KRB5 2 /* Kerberos V5. Not supported any more. */
116 #define AUTH_REQ_PASSWORD 3 /* Password */
117 #define AUTH_REQ_CRYPT 4 /* crypt password. Not supported any more. */
118 #define AUTH_REQ_MD5 5 /* md5 password */
119 #define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */
120 #define AUTH_REQ_GSS 7 /* GSSAPI without wrap() */
121 #define AUTH_REQ_GSS_CONT 8 /* Continue GSS exchanges */
122 #define AUTH_REQ_SSPI 9 /* SSPI negotiate without wrap() */
123 #define AUTH_REQ_SASL 10 /* Begin SASL authentication */
124 #define AUTH_REQ_SASL_CONT 11 /* Continue SASL authentication */
125 #define AUTH_REQ_SASL_FIN 12 /* Final SASL message */
127 typedef uint32 AuthRequest
;
131 * A client can also send a cancel-current-operation request to the postmaster.
132 * This is uglier than sending it directly to the client's backend, but it
133 * avoids depending on out-of-band communication facilities.
135 * The cancel request code must not match any protocol version number
136 * we're ever likely to use. This random choice should do.
138 #define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
140 typedef struct CancelRequestPacket
142 /* Note that each field is stored in network byte order! */
143 MsgType cancelRequestCode
; /* code to identify a cancel request */
144 uint32 backendPID
; /* PID of client's backend */
145 uint32 cancelAuthCode
; /* secret key to authorize cancel */
146 } CancelRequestPacket
;
150 * A client can also start by sending a SSL or GSSAPI negotiation request to
151 * get a secure channel.
153 #define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
154 #define NEGOTIATE_GSS_CODE PG_PROTOCOL(1234,5680)
156 #endif /* PQCOMM_H */