init
This commit is contained in:
31
pg_include/libpq/auth.h
Executable file
31
pg_include/libpq/auth.h
Executable file
@@ -0,0 +1,31 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* auth.h
|
||||
* Definitions for network authentication routines
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/auth.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef AUTH_H
|
||||
#define AUTH_H
|
||||
|
||||
#include "libpq/libpq-be.h"
|
||||
|
||||
extern char *pg_krb_server_keyfile;
|
||||
extern char *pg_krb_srvnam;
|
||||
extern bool pg_krb_caseins_users;
|
||||
extern char *pg_krb_server_hostname;
|
||||
extern char *pg_krb_realm;
|
||||
|
||||
extern void ClientAuthentication(Port *port);
|
||||
|
||||
/* Hook for plugins to get control in ClientAuthentication() */
|
||||
typedef void (*ClientAuthentication_hook_type) (Port *, int);
|
||||
extern PGDLLIMPORT ClientAuthentication_hook_type ClientAuthentication_hook;
|
||||
|
||||
#endif /* AUTH_H */
|
||||
60
pg_include/libpq/be-fsstubs.h
Executable file
60
pg_include/libpq/be-fsstubs.h
Executable file
@@ -0,0 +1,60 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* be-fsstubs.h
|
||||
*
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/be-fsstubs.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef BE_FSSTUBS_H
|
||||
#define BE_FSSTUBS_H
|
||||
|
||||
#include "fmgr.h"
|
||||
|
||||
/*
|
||||
* LO functions available via pg_proc entries
|
||||
*/
|
||||
extern Datum lo_import(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_import_with_oid(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_export(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum lo_creat(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_create(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum lo_open(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_close(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum loread(PG_FUNCTION_ARGS);
|
||||
extern Datum lowrite(PG_FUNCTION_ARGS);
|
||||
|
||||
extern Datum lo_lseek(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_tell(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_unlink(PG_FUNCTION_ARGS);
|
||||
extern Datum lo_truncate(PG_FUNCTION_ARGS);
|
||||
|
||||
/*
|
||||
* compatibility option for access control
|
||||
*/
|
||||
extern bool lo_compat_privileges;
|
||||
|
||||
/*
|
||||
* These are not fmgr-callable, but are available to C code.
|
||||
* Probably these should have had the underscore-free names,
|
||||
* but too late now...
|
||||
*/
|
||||
extern int lo_read(int fd, char *buf, int len);
|
||||
extern int lo_write(int fd, const char *buf, int len);
|
||||
|
||||
/*
|
||||
* Cleanup LOs at xact commit/abort
|
||||
*/
|
||||
extern void AtEOXact_LargeObject(bool isCommit);
|
||||
extern void AtEOSubXact_LargeObject(bool isCommit, SubTransactionId mySubid,
|
||||
SubTransactionId parentSubid);
|
||||
|
||||
#endif /* BE_FSSTUBS_H */
|
||||
21
pg_include/libpq/crypt.h
Executable file
21
pg_include/libpq/crypt.h
Executable file
@@ -0,0 +1,21 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* crypt.h
|
||||
* Interface to libpq/crypt.c
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/crypt.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PG_CRYPT_H
|
||||
#define PG_CRYPT_H
|
||||
|
||||
#include "libpq/libpq-be.h"
|
||||
|
||||
extern int md5_crypt_verify(const Port *port, const char *user,
|
||||
char *client_pass);
|
||||
|
||||
#endif
|
||||
96
pg_include/libpq/hba.h
Executable file
96
pg_include/libpq/hba.h
Executable file
@@ -0,0 +1,96 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* hba.h
|
||||
* Interface to hba.c
|
||||
*
|
||||
*
|
||||
* src/include/libpq/hba.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef HBA_H
|
||||
#define HBA_H
|
||||
|
||||
#include "libpq/pqcomm.h" /* pgrminclude ignore */ /* needed for NetBSD */
|
||||
#include "nodes/pg_list.h"
|
||||
|
||||
|
||||
typedef enum UserAuth
|
||||
{
|
||||
uaReject,
|
||||
uaImplicitReject,
|
||||
uaKrb5,
|
||||
uaTrust,
|
||||
uaIdent,
|
||||
uaPassword,
|
||||
uaMD5,
|
||||
uaGSS,
|
||||
uaSSPI,
|
||||
uaPAM,
|
||||
uaLDAP,
|
||||
uaCert,
|
||||
uaRADIUS,
|
||||
uaPeer
|
||||
} UserAuth;
|
||||
|
||||
typedef enum IPCompareMethod
|
||||
{
|
||||
ipCmpMask,
|
||||
ipCmpSameHost,
|
||||
ipCmpSameNet,
|
||||
ipCmpAll
|
||||
} IPCompareMethod;
|
||||
|
||||
typedef enum ConnType
|
||||
{
|
||||
ctLocal,
|
||||
ctHost,
|
||||
ctHostSSL,
|
||||
ctHostNoSSL
|
||||
} ConnType;
|
||||
|
||||
typedef struct HbaLine
|
||||
{
|
||||
int linenumber;
|
||||
ConnType conntype;
|
||||
List *databases;
|
||||
List *roles;
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_storage mask;
|
||||
IPCompareMethod ip_cmp_method;
|
||||
char *hostname;
|
||||
UserAuth auth_method;
|
||||
|
||||
char *usermap;
|
||||
char *pamservice;
|
||||
bool ldaptls;
|
||||
char *ldapserver;
|
||||
int ldapport;
|
||||
char *ldapbinddn;
|
||||
char *ldapbindpasswd;
|
||||
char *ldapsearchattribute;
|
||||
char *ldapbasedn;
|
||||
char *ldapprefix;
|
||||
char *ldapsuffix;
|
||||
bool clientcert;
|
||||
char *krb_server_hostname;
|
||||
char *krb_realm;
|
||||
bool include_realm;
|
||||
char *radiusserver;
|
||||
char *radiussecret;
|
||||
char *radiusidentifier;
|
||||
int radiusport;
|
||||
} HbaLine;
|
||||
|
||||
/* kluge to avoid including libpq/libpq-be.h here */
|
||||
typedef struct Port hbaPort;
|
||||
|
||||
extern bool load_hba(void);
|
||||
extern void load_ident(void);
|
||||
extern void hba_getauthmethod(hbaPort *port);
|
||||
extern int check_usermap(const char *usermap_name,
|
||||
const char *pg_role, const char *auth_user,
|
||||
bool case_sensitive);
|
||||
extern bool pg_isblank(const char c);
|
||||
|
||||
#endif /* HBA_H */
|
||||
56
pg_include/libpq/ip.h
Executable file
56
pg_include/libpq/ip.h
Executable file
@@ -0,0 +1,56 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ip.h
|
||||
* Definitions for IPv6-aware network access.
|
||||
*
|
||||
* These definitions are used by both frontend and backend code. Be careful
|
||||
* what you include here!
|
||||
*
|
||||
* Copyright (c) 2003-2012, PostgreSQL Global Development Group
|
||||
*
|
||||
* src/include/libpq/ip.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef IP_H
|
||||
#define IP_H
|
||||
|
||||
#include "getaddrinfo.h" /* pgrminclude ignore */
|
||||
#include "libpq/pqcomm.h" /* pgrminclude ignore */
|
||||
|
||||
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
#define IS_AF_UNIX(fam) ((fam) == AF_UNIX)
|
||||
#else
|
||||
#define IS_AF_UNIX(fam) (0)
|
||||
#endif
|
||||
|
||||
typedef void (*PgIfAddrCallback) (struct sockaddr * addr,
|
||||
struct sockaddr * netmask,
|
||||
void *cb_data);
|
||||
|
||||
extern int pg_getaddrinfo_all(const char *hostname, const char *servname,
|
||||
const struct addrinfo * hintp,
|
||||
struct addrinfo ** result);
|
||||
extern void pg_freeaddrinfo_all(int hint_ai_family, struct addrinfo * ai);
|
||||
|
||||
extern int pg_getnameinfo_all(const struct sockaddr_storage * addr, int salen,
|
||||
char *node, int nodelen,
|
||||
char *service, int servicelen,
|
||||
int flags);
|
||||
|
||||
extern int pg_range_sockaddr(const struct sockaddr_storage * addr,
|
||||
const struct sockaddr_storage * netaddr,
|
||||
const struct sockaddr_storage * netmask);
|
||||
|
||||
extern int pg_sockaddr_cidr_mask(struct sockaddr_storage * mask,
|
||||
char *numbits, int family);
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
extern void pg_promote_v4_to_v6_addr(struct sockaddr_storage * addr);
|
||||
extern void pg_promote_v4_to_v6_mask(struct sockaddr_storage * addr);
|
||||
#endif
|
||||
|
||||
extern int pg_foreach_ifaddr(PgIfAddrCallback callback, void *cb_data);
|
||||
|
||||
#endif /* IP_H */
|
||||
196
pg_include/libpq/libpq-be.h
Executable file
196
pg_include/libpq/libpq-be.h
Executable file
@@ -0,0 +1,196 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* libpq_be.h
|
||||
* This file contains definitions for structures and externs used
|
||||
* by the postmaster during client authentication.
|
||||
*
|
||||
* Note that this is backend-internal and is NOT exported to clients.
|
||||
* Structs that need to be client-visible are in pqcomm.h.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/libpq-be.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef LIBPQ_BE_H
|
||||
#define LIBPQ_BE_H
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef USE_SSL
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/err.h>
|
||||
#endif
|
||||
#ifdef HAVE_NETINET_TCP_H
|
||||
#include <netinet/tcp.h>
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_GSS
|
||||
#if defined(HAVE_GSSAPI_H)
|
||||
#include <gssapi.h>
|
||||
#else
|
||||
#include <gssapi/gssapi.h>
|
||||
#endif /* HAVE_GSSAPI_H */
|
||||
/*
|
||||
* GSSAPI brings in headers that set a lot of things in the global namespace on win32,
|
||||
* that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore,
|
||||
* but also defines a symbol that simply does not exist. Undefine it again.
|
||||
*/
|
||||
#ifdef WIN32_ONLY_COMPILER
|
||||
#undef HAVE_GETADDRINFO
|
||||
#endif
|
||||
#endif /* ENABLE_GSS */
|
||||
|
||||
#ifdef ENABLE_SSPI
|
||||
#define SECURITY_WIN32
|
||||
#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
|
||||
#include <ntsecapi.h>
|
||||
#endif
|
||||
#include <security.h>
|
||||
#undef SECURITY_WIN32
|
||||
|
||||
#ifndef ENABLE_GSS
|
||||
/*
|
||||
* Define a fake structure compatible with GSSAPI on Unix.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
void *value;
|
||||
int length;
|
||||
} gss_buffer_desc;
|
||||
#endif
|
||||
#endif /* ENABLE_SSPI */
|
||||
|
||||
#include "datatype/timestamp.h"
|
||||
#include "libpq/hba.h"
|
||||
#include "libpq/pqcomm.h"
|
||||
|
||||
|
||||
typedef enum CAC_state
|
||||
{
|
||||
CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
|
||||
CAC_WAITBACKUP
|
||||
} CAC_state;
|
||||
|
||||
|
||||
/*
|
||||
* GSSAPI specific state information
|
||||
*/
|
||||
#if defined(ENABLE_GSS) | defined(ENABLE_SSPI)
|
||||
typedef struct
|
||||
{
|
||||
gss_buffer_desc outbuf; /* GSSAPI output token buffer */
|
||||
#ifdef ENABLE_GSS
|
||||
gss_cred_id_t cred; /* GSSAPI connection cred's */
|
||||
gss_ctx_id_t ctx; /* GSSAPI connection context */
|
||||
gss_name_t name; /* GSSAPI client name */
|
||||
#endif
|
||||
} pg_gssinfo;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This is used by the postmaster in its communication with frontends. It
|
||||
* contains all state information needed during this communication before the
|
||||
* backend is run. The Port structure is kept in malloc'd memory and is
|
||||
* still available when a backend is running (see MyProcPort). The data
|
||||
* it points to must also be malloc'd, or else palloc'd in TopMemoryContext,
|
||||
* so that it survives into PostgresMain execution!
|
||||
*/
|
||||
|
||||
typedef struct Port
|
||||
{
|
||||
pgsocket sock; /* File descriptor */
|
||||
bool noblock; /* is the socket in non-blocking mode? */
|
||||
ProtocolVersion proto; /* FE/BE protocol version */
|
||||
SockAddr laddr; /* local addr (postmaster) */
|
||||
SockAddr raddr; /* remote addr (client) */
|
||||
char *remote_host; /* name (or ip addr) of remote host */
|
||||
char *remote_hostname;/* name (not ip addr) of remote host, if
|
||||
* available */
|
||||
int remote_hostname_resolv; /* +1 = remote_hostname is known to
|
||||
* resolve to client's IP address; -1
|
||||
* = remote_hostname is known NOT to
|
||||
* resolve to client's IP address; 0 =
|
||||
* we have not done the forward DNS
|
||||
* lookup yet */
|
||||
char *remote_port; /* text rep of remote port */
|
||||
CAC_state canAcceptConnections; /* postmaster connection status */
|
||||
|
||||
/*
|
||||
* Information that needs to be saved from the startup packet and passed
|
||||
* into backend execution. "char *" fields are NULL if not set.
|
||||
* guc_options points to a List of alternating option names and values.
|
||||
*/
|
||||
char *database_name;
|
||||
char *user_name;
|
||||
char *cmdline_options;
|
||||
List *guc_options;
|
||||
|
||||
/*
|
||||
* Information that needs to be held during the authentication cycle.
|
||||
*/
|
||||
HbaLine *hba;
|
||||
char md5Salt[4]; /* Password salt */
|
||||
|
||||
/*
|
||||
* Information that really has no business at all being in struct Port,
|
||||
* but since it gets used by elog.c in the same way as database_name and
|
||||
* other members of this struct, we may as well keep it here.
|
||||
*/
|
||||
TimestampTz SessionStartTime; /* backend start time */
|
||||
|
||||
/*
|
||||
* TCP keepalive settings.
|
||||
*
|
||||
* default values are 0 if AF_UNIX or not yet known; current values are 0
|
||||
* if AF_UNIX or using the default. Also, -1 in a default value means we
|
||||
* were unable to find out the default (getsockopt failed).
|
||||
*/
|
||||
int default_keepalives_idle;
|
||||
int default_keepalives_interval;
|
||||
int default_keepalives_count;
|
||||
int keepalives_idle;
|
||||
int keepalives_interval;
|
||||
int keepalives_count;
|
||||
|
||||
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
|
||||
|
||||
/*
|
||||
* If GSSAPI is supported, store GSSAPI information. Otherwise, store a
|
||||
* NULL pointer to make sure offsets in the struct remain the same.
|
||||
*/
|
||||
pg_gssinfo *gss;
|
||||
#else
|
||||
void *gss;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SSL structures (keep these last so that USE_SSL doesn't affect
|
||||
* locations of other fields)
|
||||
*/
|
||||
#ifdef USE_SSL
|
||||
SSL *ssl;
|
||||
X509 *peer;
|
||||
char *peer_cn;
|
||||
unsigned long count;
|
||||
#endif
|
||||
} Port;
|
||||
|
||||
|
||||
extern ProtocolVersion FrontendProtocol;
|
||||
|
||||
/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
|
||||
|
||||
extern int pq_getkeepalivesidle(Port *port);
|
||||
extern int pq_getkeepalivesinterval(Port *port);
|
||||
extern int pq_getkeepalivescount(Port *port);
|
||||
|
||||
extern int pq_setkeepalivesidle(int idle, Port *port);
|
||||
extern int pq_setkeepalivesinterval(int interval, Port *port);
|
||||
extern int pq_setkeepalivescount(int count, Port *port);
|
||||
|
||||
#endif /* LIBPQ_BE_H */
|
||||
24
pg_include/libpq/libpq-fs.h
Executable file
24
pg_include/libpq/libpq-fs.h
Executable file
@@ -0,0 +1,24 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* libpq-fs.h
|
||||
* definitions for using Inversion file system routines (ie, large objects)
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/libpq-fs.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef LIBPQ_FS_H
|
||||
#define LIBPQ_FS_H
|
||||
|
||||
/*
|
||||
* Read/write mode flags for inversion (large object) calls
|
||||
*/
|
||||
|
||||
#define INV_WRITE 0x00020000
|
||||
#define INV_READ 0x00040000
|
||||
|
||||
#endif /* LIBPQ_FS_H */
|
||||
86
pg_include/libpq/libpq.h
Executable file
86
pg_include/libpq/libpq.h
Executable file
@@ -0,0 +1,86 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* libpq.h
|
||||
* POSTGRES LIBPQ buffer structure definitions.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/libpq.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef LIBPQ_H
|
||||
#define LIBPQ_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "lib/stringinfo.h"
|
||||
#include "libpq/libpq-be.h"
|
||||
|
||||
/* ----------------
|
||||
* PQArgBlock
|
||||
* Information (pointer to array of this structure) required
|
||||
* for the PQfn() call. (This probably ought to go somewhere else...)
|
||||
* ----------------
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int len;
|
||||
int isint;
|
||||
union
|
||||
{
|
||||
int *ptr; /* can't use void (dec compiler barfs) */
|
||||
int integer;
|
||||
} u;
|
||||
} PQArgBlock;
|
||||
|
||||
/*
|
||||
* External functions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* prototypes for functions in pqcomm.c
|
||||
*/
|
||||
extern int StreamServerPort(int family, char *hostName,
|
||||
unsigned short portNumber, char *unixSocketName, pgsocket ListenSocket[],
|
||||
int MaxListen);
|
||||
extern int StreamConnection(pgsocket server_fd, Port *port);
|
||||
extern void StreamClose(pgsocket sock);
|
||||
extern void TouchSocketFile(void);
|
||||
extern void pq_init(void);
|
||||
extern void pq_comm_reset(void);
|
||||
extern int pq_getbytes(char *s, size_t len);
|
||||
extern int pq_getstring(StringInfo s);
|
||||
extern int pq_getmessage(StringInfo s, int maxlen);
|
||||
extern int pq_getbyte(void);
|
||||
extern int pq_peekbyte(void);
|
||||
extern int pq_getbyte_if_available(unsigned char *c);
|
||||
extern int pq_putbytes(const char *s, size_t len);
|
||||
extern int pq_flush(void);
|
||||
extern int pq_flush_if_writable(void);
|
||||
extern bool pq_is_send_pending(void);
|
||||
extern int pq_putmessage(char msgtype, const char *s, size_t len);
|
||||
extern void pq_putmessage_noblock(char msgtype, const char *s, size_t len);
|
||||
extern void pq_startcopyout(void);
|
||||
extern void pq_endcopyout(bool errorAbort);
|
||||
|
||||
/*
|
||||
* prototypes for functions in be-secure.c
|
||||
*/
|
||||
extern char *ssl_cert_file;
|
||||
extern char *ssl_key_file;
|
||||
extern char *ssl_ca_file;
|
||||
extern char *ssl_crl_file;
|
||||
|
||||
extern int secure_initialize(void);
|
||||
extern bool secure_loaded_verify_locations(void);
|
||||
extern void secure_destroy(void);
|
||||
extern int secure_open_server(Port *port);
|
||||
extern void secure_close(Port *port);
|
||||
extern ssize_t secure_read(Port *port, void *ptr, size_t len);
|
||||
extern ssize_t secure_write(Port *port, void *ptr, size_t len);
|
||||
|
||||
#endif /* LIBPQ_H */
|
||||
30
pg_include/libpq/md5.h
Executable file
30
pg_include/libpq/md5.h
Executable file
@@ -0,0 +1,30 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* md5.h
|
||||
* Interface to libpq/md5.c
|
||||
*
|
||||
* These definitions are needed by both frontend and backend code to work
|
||||
* with MD5-encrypted passwords.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/md5.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PG_MD5_H
|
||||
#define PG_MD5_H
|
||||
|
||||
#define MD5_PASSWD_LEN 35
|
||||
|
||||
#define isMD5(passwd) (strncmp(passwd, "md5", 3) == 0 && \
|
||||
strlen(passwd) == MD5_PASSWD_LEN)
|
||||
|
||||
|
||||
extern bool pg_md5_hash(const void *buff, size_t len, char *hexsum);
|
||||
extern bool pg_md5_binary(const void *buff, size_t len, void *outbuf);
|
||||
extern bool pg_md5_encrypt(const char *passwd, const char *salt,
|
||||
size_t salt_len, char *buf);
|
||||
|
||||
#endif
|
||||
204
pg_include/libpq/pqcomm.h
Executable file
204
pg_include/libpq/pqcomm.h
Executable file
@@ -0,0 +1,204 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pqcomm.h
|
||||
* Definitions common to frontends and backends.
|
||||
*
|
||||
* NOTE: for historical reasons, this does not correspond to pqcomm.c.
|
||||
* pqcomm.c's routines are declared in libpq.h.
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/pqcomm.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PQCOMM_H
|
||||
#define PQCOMM_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
#include <sys/un.h>
|
||||
#endif
|
||||
#include <netinet/in.h>
|
||||
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
|
||||
|
||||
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
|
||||
#define ss_family __ss_family
|
||||
#else
|
||||
#error struct sockaddr_storage does not provide an ss_family member
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
|
||||
#define ss_len __ss_len
|
||||
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
|
||||
#endif
|
||||
#else /* !HAVE_STRUCT_SOCKADDR_STORAGE */
|
||||
|
||||
/* Define a struct sockaddr_storage if we don't have one. */
|
||||
|
||||
struct sockaddr_storage
|
||||
{
|
||||
union
|
||||
{
|
||||
struct sockaddr sa; /* get the system-dependent fields */
|
||||
int64 ss_align; /* ensures struct is properly aligned */
|
||||
char ss_pad[128]; /* ensures struct has desired size */
|
||||
} ss_stuff;
|
||||
};
|
||||
|
||||
#define ss_family ss_stuff.sa.sa_family
|
||||
/* It should have an ss_len field if sockaddr has sa_len. */
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
#define ss_len ss_stuff.sa.sa_len
|
||||
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
|
||||
#endif
|
||||
#endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct sockaddr_storage addr;
|
||||
ACCEPT_TYPE_ARG3 salen;
|
||||
} SockAddr;
|
||||
|
||||
/* Configure the UNIX socket location for the well known port. */
|
||||
|
||||
#define UNIXSOCK_PATH(path, port, sockdir) \
|
||||
snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
|
||||
((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
|
||||
DEFAULT_PGSOCKET_DIR, \
|
||||
(port))
|
||||
|
||||
/*
|
||||
* The maximum workable length of a socket path is what will fit into
|
||||
* struct sockaddr_un. This is usually only 100 or so bytes :-(.
|
||||
*
|
||||
* For consistency, always pass a MAXPGPATH-sized buffer to UNIXSOCK_PATH(),
|
||||
* then complain if the resulting string is >= UNIXSOCK_PATH_BUFLEN bytes.
|
||||
* (Because the standard API for getaddrinfo doesn't allow it to complain in
|
||||
* a useful way when the socket pathname is too long, we have to test for
|
||||
* this explicitly, instead of just letting the subroutine return an error.)
|
||||
*/
|
||||
#define UNIXSOCK_PATH_BUFLEN sizeof(((struct sockaddr_un *) NULL)->sun_path)
|
||||
|
||||
|
||||
/*
|
||||
* 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(1,0)
|
||||
#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,0)
|
||||
|
||||
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
|
||||
|
||||
typedef ProtocolVersion MsgType;
|
||||
|
||||
|
||||
/*
|
||||
* Packet lengths are 4 bytes in network byte order.
|
||||
*
|
||||
* The initial length is omitted from the packet layouts appearing below.
|
||||
*/
|
||||
|
||||
typedef uint32 PacketLen;
|
||||
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#define SM_DATABASE 64
|
||||
#define SM_USER 32
|
||||
/* We append database name if db_user_namespace true. */
|
||||
#define SM_DATABASE_USER (SM_DATABASE+SM_USER+1) /* +1 for @ */
|
||||
#define SM_OPTIONS 64
|
||||
#define SM_UNUSED 64
|
||||
#define SM_TTY 64
|
||||
|
||||
typedef struct StartupPacket
|
||||
{
|
||||
ProtocolVersion protoVersion; /* Protocol version */
|
||||
char database[SM_DATABASE]; /* Database name */
|
||||
/* Db_user_namespace appends dbname */
|
||||
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;
|
||||
|
||||
extern bool Db_user_namespace;
|
||||
|
||||
/*
|
||||
* 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. */
|
||||
|
||||
#define AUTH_REQ_OK 0 /* User is authenticated */
|
||||
#define AUTH_REQ_KRB4 1 /* Kerberos V4. Not supported any more. */
|
||||
#define AUTH_REQ_KRB5 2 /* Kerberos V5 */
|
||||
#define AUTH_REQ_PASSWORD 3 /* Password */
|
||||
#define AUTH_REQ_CRYPT 4 /* crypt password. Not supported any more. */
|
||||
#define AUTH_REQ_MD5 5 /* md5 password */
|
||||
#define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */
|
||||
#define AUTH_REQ_GSS 7 /* GSSAPI without wrap() */
|
||||
#define AUTH_REQ_GSS_CONT 8 /* Continue GSS exchanges */
|
||||
#define AUTH_REQ_SSPI 9 /* SSPI negotiate without wrap() */
|
||||
|
||||
typedef uint32 AuthRequest;
|
||||
|
||||
|
||||
/*
|
||||
* A client can also send a cancel-current-operation request to the postmaster.
|
||||
* This is uglier than sending it directly to the client's backend, but it
|
||||
* avoids depending on out-of-band communication facilities.
|
||||
*
|
||||
* The cancel request code must not match any protocol version number
|
||||
* we're ever likely to use. This random choice should do.
|
||||
*/
|
||||
#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
|
||||
|
||||
typedef struct CancelRequestPacket
|
||||
{
|
||||
/* Note that each field is stored in network byte order! */
|
||||
MsgType cancelRequestCode; /* code to identify a cancel request */
|
||||
uint32 backendPID; /* PID of client's backend */
|
||||
uint32 cancelAuthCode; /* secret key to authorize cancel */
|
||||
} CancelRequestPacket;
|
||||
|
||||
|
||||
/*
|
||||
* A client can also start by sending a SSL negotiation request, to get a
|
||||
* secure channel.
|
||||
*/
|
||||
#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
|
||||
|
||||
#endif /* PQCOMM_H */
|
||||
49
pg_include/libpq/pqformat.h
Executable file
49
pg_include/libpq/pqformat.h
Executable file
@@ -0,0 +1,49 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pqformat.h
|
||||
* Definitions for formatting and parsing frontend/backend messages
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/pqformat.h
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PQFORMAT_H
|
||||
#define PQFORMAT_H
|
||||
|
||||
#include "lib/stringinfo.h"
|
||||
|
||||
extern void pq_beginmessage(StringInfo buf, char msgtype);
|
||||
extern void pq_sendbyte(StringInfo buf, int byt);
|
||||
extern void pq_sendbytes(StringInfo buf, const char *data, int datalen);
|
||||
extern void pq_sendcountedtext(StringInfo buf, const char *str, int slen,
|
||||
bool countincludesself);
|
||||
extern void pq_sendtext(StringInfo buf, const char *str, int slen);
|
||||
extern void pq_sendstring(StringInfo buf, const char *str);
|
||||
extern void pq_send_ascii_string(StringInfo buf, const char *str);
|
||||
extern void pq_sendint(StringInfo buf, int i, int b);
|
||||
extern void pq_sendint64(StringInfo buf, int64 i);
|
||||
extern void pq_sendfloat4(StringInfo buf, float4 f);
|
||||
extern void pq_sendfloat8(StringInfo buf, float8 f);
|
||||
extern void pq_endmessage(StringInfo buf);
|
||||
|
||||
extern void pq_begintypsend(StringInfo buf);
|
||||
extern bytea *pq_endtypsend(StringInfo buf);
|
||||
|
||||
extern void pq_puttextmessage(char msgtype, const char *str);
|
||||
extern void pq_putemptymessage(char msgtype);
|
||||
|
||||
extern int pq_getmsgbyte(StringInfo msg);
|
||||
extern unsigned int pq_getmsgint(StringInfo msg, int b);
|
||||
extern int64 pq_getmsgint64(StringInfo msg);
|
||||
extern float4 pq_getmsgfloat4(StringInfo msg);
|
||||
extern float8 pq_getmsgfloat8(StringInfo msg);
|
||||
extern const char *pq_getmsgbytes(StringInfo msg, int datalen);
|
||||
extern void pq_copymsgbytes(StringInfo msg, char *buf, int datalen);
|
||||
extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes);
|
||||
extern const char *pq_getmsgstring(StringInfo msg);
|
||||
extern void pq_getmsgend(StringInfo msg);
|
||||
|
||||
#endif /* PQFORMAT_H */
|
||||
51
pg_include/libpq/pqsignal.h
Executable file
51
pg_include/libpq/pqsignal.h
Executable file
@@ -0,0 +1,51 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* pqsignal.h
|
||||
* prototypes for the reliable BSD-style signal(2) routine.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* src/include/libpq/pqsignal.h
|
||||
*
|
||||
* NOTES
|
||||
* This shouldn't be in libpq, but the monitor and some other
|
||||
* things need it...
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef PQSIGNAL_H
|
||||
#define PQSIGNAL_H
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef HAVE_SIGPROCMASK
|
||||
extern sigset_t UnBlockSig,
|
||||
BlockSig,
|
||||
StartupBlockSig;
|
||||
|
||||
#define PG_SETMASK(mask) sigprocmask(SIG_SETMASK, mask, NULL)
|
||||
#else /* not HAVE_SIGPROCMASK */
|
||||
extern int UnBlockSig,
|
||||
BlockSig,
|
||||
StartupBlockSig;
|
||||
|
||||
#ifndef WIN32
|
||||
#define PG_SETMASK(mask) sigsetmask(*((int*)(mask)))
|
||||
#else
|
||||
#define PG_SETMASK(mask) pqsigsetmask(*((int*)(mask)))
|
||||
int pqsigsetmask(int mask);
|
||||
#endif
|
||||
|
||||
#define sigaddset(set, signum) (*(set) |= (sigmask(signum)))
|
||||
#define sigdelset(set, signum) (*(set) &= ~(sigmask(signum)))
|
||||
#endif /* not HAVE_SIGPROCMASK */
|
||||
|
||||
typedef void (*pqsigfunc) (int);
|
||||
|
||||
extern void pqinitmask(void);
|
||||
|
||||
extern pqsigfunc pqsignal(int signo, pqsigfunc func);
|
||||
|
||||
#endif /* PQSIGNAL_H */
|
||||
Reference in New Issue
Block a user