diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/c.h | 24 | ||||
-rw-r--r-- | src/include/libpq/auth.h | 26 | ||||
-rw-r--r-- | src/include/libpq/crypt.h | 4 | ||||
-rw-r--r-- | src/include/libpq/hba.h | 36 | ||||
-rw-r--r-- | src/include/libpq/libpq-be.h | 137 | ||||
-rw-r--r-- | src/include/libpq/libpq.h | 36 | ||||
-rw-r--r-- | src/include/libpq/password.h | 9 | ||||
-rw-r--r-- | src/include/libpq/pqcomm.h | 229 |
8 files changed, 271 insertions, 230 deletions
diff --git a/src/include/c.h b/src/include/c.h index e6ec2c65597..549f3481a68 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -7,7 +7,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: c.h,v 1.28 1998/01/24 22:47:43 momjian Exp $ + * $Id: c.h,v 1.29 1998/01/26 01:41:49 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -204,21 +204,23 @@ typedef char *Pointer; /* * intN -- - * Signed integer, AT LEAST N BITS IN SIZE, - * used for numerical computations. + * Signed integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. */ -typedef signed char int8; /* >= 8 bits */ -typedef signed short int16; /* >= 16 bits */ -typedef signed int int32; /* >= 32 bits */ +typedef signed char int8; /* == 8 bits */ +typedef signed short int16; /* == 16 bits */ +typedef signed int int32; /* == 32 bits */ /* * uintN -- - * Unsigned integer, AT LEAST N BITS IN SIZE, - * used for numerical computations. + * Unsigned integer, EXACTLY N BITS IN SIZE, + * used for numerical computations and the + * frontend/backend protocol. */ -typedef unsigned char uint8; /* >= 8 bits */ -typedef unsigned short uint16; /* >= 16 bits */ -typedef unsigned int uint32; /* >= 32 bits */ +typedef unsigned char uint8; /* == 8 bits */ +typedef unsigned short uint16; /* == 16 bits */ +typedef unsigned int uint32; /* == 32 bits */ /* * floatN -- diff --git a/src/include/libpq/auth.h b/src/include/libpq/auth.h index 6a4160e65df..bf85ee59961 100644 --- a/src/include/libpq/auth.h +++ b/src/include/libpq/auth.h @@ -6,40 +6,22 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: auth.h,v 1.7 1997/09/08 21:52:28 momjian Exp $ + * $Id: auth.h,v 1.8 1998/01/26 01:42:05 scrappy Exp $ * *------------------------------------------------------------------------- */ #ifndef AUTH_H #define AUTH_H -#include <libpq/pqcomm.h> +#include "libpq/libpq-be.h" /*---------------------------------------------------------------- * Common routines and definitions *---------------------------------------------------------------- */ -/* what we call "no authentication system" */ -#define UNAUTHNAME "unauth" - -/* what a frontend uses by default */ -#if !defined(KRB4) && !defined(KRB5) -#define DEFAULT_CLIENT_AUTHSVC UNAUTHNAME -#else /* KRB4 || KRB5 */ -#define DEFAULT_CLIENT_AUTHSVC "kerberos" -#endif /* KRB4 || KRB5 */ - -extern int fe_sendauth(MsgType msgtype, Port *port, char *hostname); -extern void fe_setauthsvc(char *name); -extern MsgType fe_getauthsvc(); -extern char *fe_getauthname(void); -extern int be_recvauth(MsgType msgtype, Port *port, char *username, StartupInfo *sp); -extern void be_setauthsvc(char *name); - -/* the value that matches any dbName value when doing - host based authentication*/ -#define ALL_DBNAME "*" +void be_recvauth(Port *port); +void auth_failed(Port *port); #define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */ #define PG_KRB5_VERSION "PGVER5.1" diff --git a/src/include/libpq/crypt.h b/src/include/libpq/crypt.h index 928ff86a9c4..77d4fb7d03b 100644 --- a/src/include/libpq/crypt.h +++ b/src/include/libpq/crypt.h @@ -9,7 +9,7 @@ #ifndef PG_CRYPT_H #define PG_CRYPT_H -#include <libpq/pqcomm.h> +#include <libpq/libpq-be.h> #define CRYPT_PWD_FILE "pg_pwd" #define CRYPT_PWD_FILE_SEPCHAR "'\\t'" @@ -21,7 +21,9 @@ extern int pwd_cache_count; extern char* crypt_getpwdfilename(void); extern char* crypt_getpwdreloadfilename(void); +#ifdef 0 extern MsgType crypt_salt(const char* user); +#endif extern int crypt_verify(Port* port, const char* user, const char* pgpass); #endif diff --git a/src/include/libpq/hba.h b/src/include/libpq/hba.h index 31ae6f2c0db..fdadfc0d85c 100644 --- a/src/include/libpq/hba.h +++ b/src/include/libpq/hba.h @@ -4,14 +4,17 @@ * Interface to hba.c * * - * $Id: hba.h,v 1.6 1998/01/24 22:49:15 momjian Exp $ + * $Id: hba.h,v 1.7 1998/01/26 01:42:15 scrappy Exp $ * *------------------------------------------------------------------------- */ #ifndef HBA_H #define HBA_H -#include <libpq/pqcomm.h> +#include <netinet/in.h> + +#include "libpq/libpq-be.h" + #define CONF_FILE "pg_hba.conf" /* Name of the config file */ @@ -28,7 +31,7 @@ #define MAX_TOKEN 80 /* Maximum size of one token in the configuration file */ -#define USERMAP_NAME_SIZE 16 /* Max size of a usermap name */ +#define MAX_AUTH_ARG 80 /* Max size of an authentication arg */ #define IDENT_PORT 113 /* Standard TCP port number for Ident service. Assigned by IANA */ @@ -36,18 +39,19 @@ #define IDENT_USERNAME_MAX 512 /* Max size of username ident server can return */ -enum Userauth -{ - Trust, Ident, - Password -}; - -extern int hba_recvauth(const Port *port, const char database[], const char user[], - const char DataDir[]); -void -find_hba_entry(const char DataDir[], const struct in_addr ip_addr, - const char database[], - bool *host_ok_p, enum Userauth * userauth_p, - char usermap_name[], bool find_password_entries); +typedef enum UserAuth { + uaReject, + uaKrb4, + uaKrb5, + uaTrust, + uaIdent, + uaPassword, + uaCrypt +} UserAuth; + +int hba_getauthmethod(SockAddr *raddr, char *database, char *auth_arg, + UserAuth *auth_method); +int authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr, + const char postgres_username[], const char auth_arg[]); #endif diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h index e65d9b3232c..4d0e186198c 100644 --- a/src/include/libpq/libpq-be.h +++ b/src/include/libpq/libpq-be.h @@ -7,45 +7,126 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-be.h,v 1.8 1998/01/24 22:49:18 momjian Exp $ + * $Id: libpq-be.h,v 1.9 1998/01/26 01:42:17 scrappy Exp $ * *------------------------------------------------------------------------- */ #ifndef LIBPQ_BE_H #define LIBPQ_BE_H -#include <access/htup.h> -#include <access/tupdesc.h> -#include <libpq/libpq.h> +#include <stdio.h> +#include <sys/types.h> -/* ---------------- - * include stuff common to fe and be - * ---------------- +#include "libpq/pqcomm.h" +#include "libpq/hba.h" + + +/* Protocol v0 password packet. */ + +typedef struct PasswordPacketV0 { + uint32 unused; + char data[288]; /* User and password as strings. */ +} PasswordPacketV0; + + +/* + * Password packet. The length of the password can be changed without + * affecting anything. */ + +typedef struct PasswordPacket { + char passwd[100]; /* The password. */ +} PasswordPacket; + + +/* Error message packet. */ + +typedef struct ErrorMessagePacket { + char data[1 + 100]; /* 'E' + the message. */ +} ErrorMessagePacket; + + +/* Authentication request packet. */ + +typedef struct AuthRequestPacket { + char data[1 + sizeof (AuthRequest) + 2]; /* 'R' + the request + optional salt. */ +} AuthRequestPacket; + + +/* These are used by the packet handling routines. */ +typedef enum { + Idle, + ReadingPacketLength, + ReadingPacket, + WritingPacket +} PacketState; -/* ---------------- - * declarations for backend libpq support routines - * ---------------- +typedef struct Packet { + PacketState state; /* What's in progress. */ + PacketLen len; /* Actual length */ + int nrtodo; /* Bytes still to transfer */ + char *ptr; /* Buffer pointer */ + void (*iodone)(); /* I/O complete callback */ + char *arg; /* Argument to callback */ + + /* A union of all the different packets. */ + + union { + /* These are outgoing so have no packet length prepended. */ + + ErrorMessagePacket em; + AuthRequestPacket ar; + + /* These are incoming and have a packet length prepended. */ + + StartupPacket si; + PasswordPacketV0 pwv0; + PasswordPacket pw; + } pkt; +} Packet; + + +/* + * This is used by the postmaster in its communication with frontends. It is + * contains all state information needed during this communication before the + * backend is run. */ + +typedef struct Port { + int sock; /* File descriptor */ + Packet pktInfo; /* For the packet handlers */ + SockAddr laddr; /* local addr (us) */ + SockAddr raddr; /* remote addr (them) */ + char salt[2]; /* Password salt */ + + /* + * Information that needs to be held during the fe/be authentication + * handshake. + */ + + ProtocolVersion proto; + char database[SM_DATABASE + 1]; + char user[SM_USER + 1]; + char options[SM_OPTIONS + 1]; + char tty[SM_TTY + 1]; + char auth_arg[MAX_AUTH_ARG]; + UserAuth auth_method; +} Port; -/* in be-dumpdata.c */ -extern void be_portalinit(void); -extern void be_portalpush(PortalEntry *entry); -extern PortalEntry *be_portalpop(void); -extern PortalEntry *be_currentportal(void); -extern PortalEntry *be_newportal(void); -extern void be_typeinit(PortalEntry *entry, TupleDesc attrs, - int natts); -extern void be_printtup(HeapTuple tuple, TupleDesc typeinfo); - - -/* in be-pqexec.c */ -extern char * PQfn(int fnid, int *result_buf, int result_len, int result_is_int, - PQArgBlock *args, int nargs); -extern char *PQexec(char *query); -extern int pqtest_PQexec(char *q); -extern int pqtest_PQfn(char *q); -extern int32 pqtest(struct varlena * vlena); +extern FILE *Pfout, *Pfin; +extern int PQAsyncNotifyWaiting; +extern ProtocolVersion FrontendProtocol; + + +/* + * prototypes for functions in pqpacket.c + */ +void PacketReceiveSetup(Packet *pkt, void (*iodone)(), char *arg); +int PacketReceiveFragment(Packet *pkt, int sock); +void PacketSendSetup(Packet *pkt, int nbytes, void (*iodone)(), char *arg); +int PacketSendFragment(Packet *pkt, int sock); +void PacketSendError(Packet *pkt, char *errormsg); + #endif /* LIBPQ_BE_H */ diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h index 19e5ca8fa54..a77a2afccff 100644 --- a/src/include/libpq/libpq.h +++ b/src/include/libpq/libpq.h @@ -6,20 +6,19 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: libpq.h,v 1.9 1998/01/24 22:49:21 momjian Exp $ - * - * NOTES - * This file contains definitions for structures and - * externs for functions used by both frontend applications - * and the POSTGRES backend. See the files libpq-fe.h and - * libpq-be.h for frontend/backend specific information + * $Id: libpq.h,v 1.10 1998/01/26 01:42:18 scrappy Exp $ * *------------------------------------------------------------------------- */ #ifndef LIBPQ_H #define LIBPQ_H -#include <libpq/pqcomm.h> +#include <netinet/in.h> + +#include "libpq/libpq-be.h" +#include "access/htup.h" +#include "access/tupdesc.h" + /* ---------------- * PQArgBlock -- @@ -228,6 +227,27 @@ extern int pbuf_findFnumber(GroupBuffer *group, char *field_name); extern void pbuf_checkFnumber(GroupBuffer *group, int field_number); extern char *pbuf_findFname(GroupBuffer *group, int field_number); +/* in be-dumpdata.c */ +extern void be_portalinit(void); +extern void be_portalpush(PortalEntry *entry); +extern PortalEntry *be_portalpop(void); +extern PortalEntry *be_currentportal(void); +extern PortalEntry *be_newportal(void); +extern void +be_typeinit(PortalEntry *entry, TupleDesc attrs, + int natts); +extern void be_printtup(HeapTuple tuple, TupleDesc typeinfo); + + +/* in be-pqexec.c */ +extern char * +PQfn(int fnid, int *result_buf, int result_len, int result_is_int, + PQArgBlock *args, int nargs); +extern char *PQexec(char *query); +extern int pqtest_PQexec(char *q); +extern int pqtest_PQfn(char *q); +extern int32 pqtest(struct varlena * vlena); + /* * prototypes for functions in pqcomm.c */ diff --git a/src/include/libpq/password.h b/src/include/libpq/password.h index 28b279a7c08..f0c24794c3e 100644 --- a/src/include/libpq/password.h +++ b/src/include/libpq/password.h @@ -1,13 +1,6 @@ #ifndef PASSWORD_H #define PASSWORD_H -#include <libpq/hba.h> -#include <libpq/pqcomm.h> - -#define PWFILE_NAME_SIZE USERMAP_NAME_SIZE - -int -verify_password(char *user, char *password, Port *port, - char *database, char *DataDir); +int verify_password(char *auth_arg, char *user, char *password); #endif diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h index 1b2823b7b1b..5f8633f7e4c 100644 --- a/src/include/libpq/pqcomm.h +++ b/src/include/libpq/pqcomm.h @@ -1,15 +1,12 @@ /*------------------------------------------------------------------------- * * pqcomm.h-- - * Parameters for the communication module + * Definitions common to frontends and backends. * * * Copyright (c) 1994, Regents of the University of California * - * $Id: pqcomm.h,v 1.18 1998/01/24 22:49:23 momjian Exp $ - * - * NOTES - * Some of this should move to libpq.h + * $Id: pqcomm.h,v 1.19 1998/01/26 01:42:21 scrappy Exp $ * *------------------------------------------------------------------------- */ @@ -18,134 +15,105 @@ #include <stdio.h> #include <sys/types.h> -#include <netinet/in.h> +#include <sys/socket.h> #include <sys/un.h> +#include <netinet/in.h> + +#include "c.h" + + +/* Define a generic socket address type. */ + +typedef union SockAddr { + struct sockaddr sa; + struct sockaddr_in in; + struct sockaddr_un un; +} SockAddr; + + +/* Configure the UNIX socket address for the well known port. */ + +#define UNIXSOCK_PATH(sun,port) \ + (sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)) + \ + sizeof ((sun).sun_family)) + + +/* + * 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 + * versions m.0..n]. Backend support for version m-1 can be dropped after a + * `reasonable' length of time. + * + * A frontend isn't required to support anything other than the current + * version. + */ + +#define PG_PROTOCOL_MAJOR(v) ((v) >> 16) +#define PG_PROTOCOL_MINOR(v) ((v) & 0x0000ffff) +#define PG_PROTOCOL(m,n) (((m) << 16) | (n)) +/* The earliest and latest frontend/backend protocol version supported. */ + +#define PG_PROTOCOL_EARLIEST PG_PROTOCOL(0,0) +#define PG_PROTOCOL_LATEST PG_PROTOCOL(1,0) /* - * startup msg parameters: path length, argument string length + * All packets sent to the postmaster start with the length. This is omitted + * from the different packet definitions specified below. */ -#define PATH_SIZE 64 -#define ARGV_SIZE 64 - -#define UNIXSOCK_PATH(sun,port) \ - sprintf(sun.sun_path,"/tmp/.s.PGSQL.%d",port) + sizeof(sun.sun_family) + 1; - - -/* The various kinds of startup messages are for the various kinds of - user authentication systems. In the beginning, there was only - STARTUP_MSG and all connections were unauthenticated. Now, there are - several choices of authentication method (the client picks one, but - the server needn't necessarily accept it). So now, the STARTUP_MSG - message means to start either an unauthenticated or a host-based - authenticated connection, depending on what the server prefers. This - is possible because the protocol between server and client is the same - in both cases (basically, no negotiation is required at all). - */ - -typedef enum _MsgType -{ - ACK_MSG = 0, /* acknowledge a message */ - ERROR_MSG = 1, /* error response to client from server */ - RESET_MSG = 2, /* client must reset connection */ - PRINT_MSG = 3, /* tuples for client from server */ - NET_ERROR = 4, /* error in net system call */ - FUNCTION_MSG = 5, /* fastpath call (unused) */ - QUERY_MSG = 6, /* client query to server */ - STARTUP_MSG = 7, /* initialize a connection with a backend */ - DUPLICATE_MSG = 8, /* duplicate msg arrived (errors msg only) */ - INVALID_MSG = 9, /* for some control functions */ - STARTUP_KRB4_MSG = 10, /* krb4 session follows startup packet */ - STARTUP_KRB5_MSG = 11, /* krb5 session follows startup packet */ - STARTUP_HBA_MSG = 12, /* use host-based authentication */ - STARTUP_UNAUTH_MSG = 13, /* use unauthenticated connection */ - STARTUP_PASSWORD_MSG = 14, /* use plaintext password authentication */ - /* The following three are not really a named authentication method - * since the front end has no choice in choosing the method. The - * backend sends the SALT/UNSALT messages back to the frontend after - * the USER login has been given to the backend. - */ - STARTUP_CRYPT_MSG = 15, /* use crypt()'ed password authentication */ - STARTUP_USER_MSG = 16, /* send user name to check pg_user for password */ - STARTUP_SALT_MSG = 17, /* frontend should crypt the password it sends */ - STARTUP_UNSALT_MSG = 18 /* frontend should NOT crypt the password it sends */ - /* insert new values here -- DO NOT REORDER OR DELETE ENTRIES */ - /* also change LAST_AUTHENTICATION_TYPE below and add to the */ - /* authentication_type_name[] array in pqcomm.c */ -} MsgType; - -#define LAST_AUTHENTICATION_TYPE 14 - -typedef char *Addr; -typedef int PacketLen; /* packet length */ - - -typedef struct StartupInfo -{ -/* PacketHdr hdr; */ - char database[PATH_SIZE]; /* database name */ - char user[NAMEDATALEN]; /* user name */ - char options[ARGV_SIZE]; /* possible additional args */ - char execFile[ARGV_SIZE]; /* possible backend to use */ - char tty[PATH_SIZE]; /* possible tty for debug output */ -} StartupInfo; - -/* amount of available data in a packet buffer */ -#define MESSAGE_SIZE sizeof(StartupInfo) - -/* I/O can be blocking or non-blocking */ -#define BLOCKING (FALSE) -#define NON_BLOCKING (TRUE) - -/* a PacketBuf gets shipped from client to server so be careful - of differences in representation. - Be sure to use htonl() and ntohl() on the len and msgtype fields! */ -typedef struct PacketBuf -{ - int len; - MsgType msgtype; - char data[MESSAGE_SIZE]; -} PacketBuf; - -/* update the conversion routines - StartupInfo2PacketBuf() and PacketBuf2StartupInfo() (decl. below) - if StartupInfo or PacketBuf structs ever change */ +typedef uint32 PacketLen; + + /* - * socket descriptor port - * we need addresses of both sides to do authentication calls + * Startup message parameters sizes. These must not be changed without changing + * the protcol version. These are all strings that are '\0' terminated only if + * there is room. */ -typedef struct Port -{ - int sock; /* file descriptor */ - int mask; /* select mask */ - int nBytes; /* nBytes read in so far */ - /* local addr (us) */ - union { struct sockaddr_in in; struct sockaddr_un un; } laddr; - /* remote addr (them) */ - union { struct sockaddr_in in; struct sockaddr_un un; } raddr; - /* - * PacketBufId id; -*//* id of packet buf currently in use */ - PacketBuf buf; /* stream implementation (curr pack buf) */ - char salt[2]; -} Port; - -/* invalid socket descriptor */ -#define INVALID_SOCK (-1) - -#define INVALID_ID (-1) -#define MAX_CONNECTIONS 10 -#define N_PACK_BUFS 20 - -/* no multi-packet messages yet */ -#define MAX_PACKET_BACKLOG 1 - -#define DEFAULT_STRING "" - -extern FILE *Pfout, - *Pfin; -extern int PQAsyncNotifyWaiting; + +#define SM_DATABASE 64 +#define SM_USER 32 +#define SM_OPTIONS 64 +#define SM_UNUSED 64 +#define SM_TTY 64 + +typedef uint32 ProtocolVersion; /* Fe/Be protocol version nr. */ + +typedef struct StartupPacket { + ProtocolVersion protoVersion; /* Protocol version */ + char database[SM_DATABASE]; /* Database name */ + char user[SM_USER]; /* User name */ + char options[SM_OPTIONS]; /* Optional additional args */ + char unused[SM_UNUSED]; /* Unused */ + char tty[SM_TTY]; /* Tty for debug output */ +} StartupPacket; + + +/* These are the authentication requests sent by the backend. */ + +#define AUTH_REQ_OK 0 /* User is authenticated */ +#define AUTH_REQ_KRB4 1 /* Kerberos V4 */ +#define AUTH_REQ_KRB5 2 /* Kerberos V5 */ +#define AUTH_REQ_PASSWORD 3 /* Password */ +#define AUTH_REQ_CRYPT 4 /* Encrypted password */ + +typedef uint32 AuthRequest; + + +/* This next section is to maintain compatibility with protocol v0.0. */ + +#define STARTUP_MSG 7 /* Initialise a connection */ +#define STARTUP_KRB4_MSG 10 /* krb4 session follows */ +#define STARTUP_KRB5_MSG 11 /* krb5 session follows */ +#define STARTUP_PASSWORD_MSG 14 /* Password follows */ + +typedef ProtocolVersion MsgType; + /* in pqcompriv.c */ int pqGetShort(int *, FILE *); @@ -160,15 +128,4 @@ int pqPutNBytes(const char *, size_t, FILE *); int pqPutString(const char *, FILE *); int pqPutByte(int, FILE *); -/* - * prototypes for functions in pqpacket.c - */ -extern int PacketReceive(Port *port, PacketBuf *buf, char nonBlocking); -extern int PacketSend(Port *port, PacketBuf *buf, - PacketLen len, char nonBlocking); - -/* extern PacketBuf* StartupInfo2PacketBuf(StartupInfo*); */ -/* extern StartupInfo* PacketBuf2StartupInfo(PacketBuf*); */ -extern char *name_of_authentication_type(int type); - #endif /* PQCOMM_H */ |