1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* pqcomm.h
|
1998-02-26 05:46:47 +01:00
|
|
|
* Definitions common to frontends and backends.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1999-04-25 05:19:27 +02:00
|
|
|
* NOTE: for historical reasons, this does not correspond to pqcomm.c.
|
|
|
|
* pqcomm.c's routines are declared in libpq.h.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2003-05-08 20:16:37 +02:00
|
|
|
* $Id: pqcomm.h,v 1.84 2003/05/08 18:16:37 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef PQCOMM_H
|
1997-09-07 07:04:48 +02:00
|
|
|
#define PQCOMM_H
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-08-29 06:05:46 +02:00
|
|
|
#ifdef WIN32
|
2001-03-22 05:01:46 +01:00
|
|
|
#include <winsock.h>
|
2001-09-06 05:18:12 +02:00
|
|
|
/* workaround for clashing defines of "ERROR" */
|
|
|
|
#ifdef ELOG_H
|
|
|
|
#undef ERROR
|
|
|
|
#define ERROR (-1)
|
|
|
|
#endif
|
2001-03-22 05:01:46 +01:00
|
|
|
#else /* not WIN32 */
|
|
|
|
#include <sys/socket.h>
|
2003-01-06 06:33:45 +01:00
|
|
|
#include <netdb.h>
|
2001-03-22 05:01:46 +01:00
|
|
|
#ifdef HAVE_SYS_UN_H
|
|
|
|
#include <sys/un.h>
|
|
|
|
#endif
|
|
|
|
#include <netinet/in.h>
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* not WIN32 */
|
2000-09-27 17:17:57 +02:00
|
|
|
|
|
|
|
|
2003-01-06 10:58:36 +01:00
|
|
|
#ifndef INET_ADDRSTRLEN
|
|
|
|
#define INET_ADDRSTRLEN 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INET6_ADDRSTRLEN
|
|
|
|
#define INET6_ADDRSTRLEN 46
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2000-09-27 17:17:57 +02:00
|
|
|
#ifndef HAVE_STRUCT_SOCKADDR_UN
|
|
|
|
struct sockaddr_un
|
|
|
|
{
|
|
|
|
short int sun_family; /* AF_UNIX */
|
2001-03-22 05:01:46 +01:00
|
|
|
char sun_path[108]; /* path name (gag) */
|
2000-09-27 17:17:57 +02:00
|
|
|
};
|
1998-08-29 06:05:46 +02:00
|
|
|
#endif
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
/* Define a generic socket address type. */
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef union SockAddr
|
|
|
|
{
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in in;
|
2003-01-06 04:18:27 +01:00
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
struct sockaddr_in6 in6;
|
|
|
|
#endif
|
1998-02-26 05:46:47 +01:00
|
|
|
struct sockaddr_un un;
|
1998-01-26 02:42:53 +01:00
|
|
|
} SockAddr;
|
|
|
|
|
|
|
|
|
2000-12-01 00:19:04 +01:00
|
|
|
/* Configure the UNIX socket location for the well known port. */
|
1998-03-02 06:42:15 +01:00
|
|
|
|
2000-11-22 04:40:19 +01:00
|
|
|
#define UNIXSOCK_PATH(sun,port,defpath) \
|
2002-08-12 16:35:26 +02:00
|
|
|
snprintf((sun).sun_path, sizeof((sun).sun_path), "%s/.s.PGSQL.%d", \
|
2000-12-01 00:19:04 +01:00
|
|
|
((defpath) && *(defpath) != '\0') ? (defpath) : \
|
|
|
|
DEFAULT_PGSOCKET_DIR, \
|
|
|
|
(port))
|
2000-11-22 04:40:19 +01:00
|
|
|
|
1998-01-27 16:35:30 +01:00
|
|
|
/*
|
1998-01-28 03:29:40 +01:00
|
|
|
* We do this because sun_len is in BSD's struct, while others don't.
|
|
|
|
* We never actually set BSD's sun_len, and I can't think of a
|
1998-01-27 16:35:30 +01:00
|
|
|
* platform-safe way of doing it, but the code still works. bjm
|
|
|
|
*/
|
2000-12-01 00:19:04 +01:00
|
|
|
#if defined(SUN_LEN)
|
|
|
|
#define UNIXSOCK_LEN(sun) \
|
|
|
|
(SUN_LEN(&(sun)))
|
|
|
|
#else
|
|
|
|
#define UNIXSOCK_LEN(sun) \
|
|
|
|
(strlen((sun).sun_path) + offsetof(struct sockaddr_un, sun_path))
|
|
|
|
#endif
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These manipulate the frontend/backend protocol version number.
|
|
|
|
*
|
|
|
|
* The major number should be incremented for incompatible changes. The minor
|
|
|
|
* number should be incremented for compatible changes (eg. additional
|
|
|
|
* functionality).
|
|
|
|
*
|
|
|
|
* If a backend supports version m.n of the protocol it must actually support
|
2003-04-18 00:26:02 +02:00
|
|
|
* versions m.[0..n]. Backend support for version m-1 can be dropped after a
|
1998-01-26 02:42:53 +01:00
|
|
|
* `reasonable' length of time.
|
|
|
|
*
|
|
|
|
* A frontend isn't required to support anything other than the current
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define PG_PROTOCOL_MAJOR(v) ((v) >> 16)
|
|
|
|
#define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff)
|
|
|
|
#define PG_PROTOCOL(m,n) (((m) << 16) | (n))
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-01-26 02:42:53 +01:00
|
|
|
/* The earliest and latest frontend/backend protocol version supported. */
|
|
|
|
|
2002-08-29 05:22:01 +02:00
|
|
|
#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(1,0)
|
2003-05-08 20:16:37 +02:00
|
|
|
#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,108) /* XXX temporary value */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2003-04-18 00:26:02 +02:00
|
|
|
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2003-04-18 00:26:02 +02:00
|
|
|
typedef ProtocolVersion MsgType;
|
1998-01-26 02:42:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/*
|
2003-04-18 00:26:02 +02:00
|
|
|
* Packet lengths are 4 bytes in network byte order.
|
|
|
|
*
|
|
|
|
* The initial length is omitted from the packet layouts appearing below.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-01-26 02:42:53 +01:00
|
|
|
|
2003-04-18 00:26:02 +02:00
|
|
|
typedef uint32 PacketLen;
|
|
|
|
|
|
|
|
|
2002-08-27 17:15:23 +02:00
|
|
|
/*
|
2003-04-18 00:26:02 +02:00
|
|
|
* Old-style startup packet layout with fixed-width fields. This is used in
|
|
|
|
* protocol 1.0 and 2.0, but not in later versions. Note that the fields
|
|
|
|
* in this layout are '\0' terminated only if there is room.
|
2002-08-27 17:15:23 +02:00
|
|
|
*/
|
2002-09-04 22:31:48 +02:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
#define SM_DATABASE 64
|
|
|
|
#define SM_USER 32
|
2002-08-18 05:03:26 +02:00
|
|
|
/* We append database name if db_user_namespace true. */
|
2002-09-04 22:31:48 +02:00
|
|
|
#define SM_DATABASE_USER (SM_DATABASE+SM_USER+1) /* +1 for @ */
|
1998-02-26 05:46:47 +01:00
|
|
|
#define SM_OPTIONS 64
|
|
|
|
#define SM_UNUSED 64
|
|
|
|
#define SM_TTY 64
|
1998-01-26 02:42:53 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
typedef struct StartupPacket
|
|
|
|
{
|
|
|
|
ProtocolVersion protoVersion; /* Protocol version */
|
1998-01-26 02:42:53 +01:00
|
|
|
char database[SM_DATABASE]; /* Database name */
|
2002-09-04 22:31:48 +02:00
|
|
|
/* Db_user_namespace appends dbname */
|
1998-02-26 05:46:47 +01:00
|
|
|
char user[SM_USER]; /* User name */
|
1998-01-26 02:42:53 +01:00
|
|
|
char options[SM_OPTIONS]; /* Optional additional args */
|
1998-02-26 05:46:47 +01:00
|
|
|
char unused[SM_UNUSED]; /* Unused */
|
|
|
|
char tty[SM_TTY]; /* Tty for debug output */
|
1998-01-26 02:42:53 +01:00
|
|
|
} StartupPacket;
|
|
|
|
|
2002-08-18 05:03:26 +02:00
|
|
|
extern bool Db_user_namespace;
|
1998-01-26 02:42:53 +01:00
|
|
|
|
2003-04-18 00:26:02 +02:00
|
|
|
/*
|
|
|
|
* In protocol 3.0 and later, the startup packet length is not fixed, but
|
|
|
|
* we set an arbitrary limit on it anyway. This is just to prevent simple
|
|
|
|
* denial-of-service attacks via sending enough data to run the server
|
|
|
|
* out of memory.
|
|
|
|
*/
|
|
|
|
#define MAX_STARTUP_PACKET_LENGTH 10000
|
|
|
|
|
|
|
|
|
|
|
|
/* These are the authentication request codes sent by the backend. */
|
1998-01-26 02:42:53 +01:00
|
|
|
|
2001-08-15 20:42:16 +02:00
|
|
|
#define AUTH_REQ_OK 0 /* User is authenticated */
|
1998-02-26 05:46:47 +01:00
|
|
|
#define AUTH_REQ_KRB4 1 /* Kerberos V4 */
|
|
|
|
#define AUTH_REQ_KRB5 2 /* Kerberos V5 */
|
|
|
|
#define AUTH_REQ_PASSWORD 3 /* Password */
|
2001-08-15 20:42:16 +02:00
|
|
|
#define AUTH_REQ_CRYPT 4 /* crypt password */
|
|
|
|
#define AUTH_REQ_MD5 5 /* md5 password */
|
2001-08-21 02:33:28 +02:00
|
|
|
#define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */
|
1998-01-26 02:42:53 +01:00
|
|
|
|
|
|
|
typedef uint32 AuthRequest;
|
|
|
|
|
|
|
|
|
2003-04-18 00:26:02 +02:00
|
|
|
/*
|
|
|
|
* A client can also send a cancel-current-operation request to the postmaster.
|
1998-07-09 05:29:11 +02:00
|
|
|
* This is uglier than sending it directly to the client's backend, but it
|
|
|
|
* avoids depending on out-of-band communication facilities.
|
2003-04-18 00:26:02 +02:00
|
|
|
*
|
|
|
|
* The cancel request code must not match any protocol version number
|
1998-07-09 05:29:11 +02:00
|
|
|
* we're ever likely to use. This random choice should do.
|
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
|
1998-07-09 05:29:11 +02:00
|
|
|
|
|
|
|
typedef struct CancelRequestPacket
|
|
|
|
{
|
|
|
|
/* Note that each field is stored in network byte order! */
|
1998-09-01 06:40:42 +02:00
|
|
|
MsgType cancelRequestCode; /* code to identify a cancel
|
|
|
|
* request */
|
|
|
|
uint32 backendPID; /* PID of client's backend */
|
|
|
|
uint32 cancelAuthCode; /* secret key to authorize cancel */
|
1999-05-26 00:43:53 +02:00
|
|
|
} CancelRequestPacket;
|
1998-07-09 05:29:11 +02:00
|
|
|
|
1999-09-27 05:13:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A client can also start by sending a SSL negotiation request, to get a
|
|
|
|
* secure channel.
|
|
|
|
*/
|
|
|
|
#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* PQCOMM_H */
|