libpq-be.h 5.08 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * libpq_be.h
4 5 6 7 8
 *	  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.
9 10
 *
 *
11
 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
12
 * Portions Copyright (c) 1994, Regents of the University of California
13
 *
14
 * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.63 2007/08/02 23:39:45 adunstan Exp $
15 16 17 18 19 20
 *
 *-------------------------------------------------------------------------
 */
#ifndef LIBPQ_BE_H
#define LIBPQ_BE_H

21
#ifdef HAVE_SYS_TIME_H
22
#include <sys/time.h>
23
#endif
24 25 26 27
#ifdef USE_SSL
#include <openssl/ssl.h>
#include <openssl/err.h>
#endif
28 29 30
#ifdef HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
31

32
#ifdef ENABLE_GSS
33 34 35
#if defined(HAVE_GSSAPI_H)
#include <gssapi.h>
#else
36
#include <gssapi/gssapi.h>
37 38 39 40 41 42 43 44
#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
45
#endif
46
#endif /* ENABLE_GSS */
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#ifdef ENABLE_SSPI
#define SECURITY_WIN32
#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 */

64 65
#include "libpq/hba.h"
#include "libpq/pqcomm.h"
66
#include "utils/timestamp.h"
67

68

69 70 71 72 73
typedef enum CAC_state
{
	CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY
} CAC_state;

74 75 76 77

/*
 * GSSAPI specific state information
 */
78
#if defined(ENABLE_GSS) | defined(ENABLE_SSPI)
79 80
typedef struct
{
81 82
	gss_buffer_desc	outbuf;		/* GSSAPI output token buffer */
#ifdef ENABLE_GSS
83 84 85
	gss_cred_id_t	cred;		/* GSSAPI connection cred's */
	gss_ctx_id_t	ctx;		/* GSSAPI connection context */
	gss_name_t		name;		/* GSSAPI client name */
86
#endif
87 88 89
} pg_gssinfo;
#endif

90
/*
91
 * This is used by the postmaster in its communication with frontends.	It
92
 * contains all state information needed during this communication before the
Bruce Momjian's avatar
Bruce Momjian committed
93 94
 * 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
95 96
 * it points to must also be malloc'd, or else palloc'd in TopMemoryContext,
 * so that it survives into PostgresMain execution!
97
 */
98 99 100 101

typedef struct Port
{
	int			sock;			/* File descriptor */
102
	ProtocolVersion proto;		/* FE/BE protocol version */
103 104
	SockAddr	laddr;			/* local addr (postmaster) */
	SockAddr	raddr;			/* remote addr (client) */
Bruce Momjian's avatar
Bruce Momjian committed
105 106
	char	   *remote_host;	/* name (or ip addr) of remote host */
	char	   *remote_port;	/* text rep of remote port */
107
	CAC_state	canAcceptConnections;	/* postmaster connection status */
108 109

	/*
110 111 112
	 * 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.
113
	 */
114 115 116 117
	char	   *database_name;
	char	   *user_name;
	char	   *cmdline_options;
	List	   *guc_options;
118

119 120 121
	/*
	 * Information that needs to be held during the authentication cycle.
	 */
122
	UserAuth	auth_method;
123 124 125
	char	   *auth_arg;
	char		md5Salt[4];		/* Password salt */
	char		cryptSalt[2];	/* Password salt */
126

127
	/*
128 129 130
	 * 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.
131
	 */
Bruce Momjian's avatar
Bruce Momjian committed
132
	TimestampTz SessionStartTime;		/* backend start time */
133

134 135 136
	/*
	 * TCP keepalive settings.
	 *
137 138 139
	 * 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).
140
	 */
141 142 143 144 145 146
	int			default_keepalives_idle;
	int			default_keepalives_interval;
	int			default_keepalives_count;
	int			keepalives_idle;
	int			keepalives_interval;
	int			keepalives_count;
147

148
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
149 150 151 152 153 154 155 156 157 158
	/*
	 * If GSSAPI is supported, store GSSAPI information.
	 * Oterwise, store a NULL pointer to make sure offsets
	 * in the struct remain the same.
	 */
	pg_gssinfo *gss;
#else
	void	   *gss;
#endif

159
	/*
160 161
	 * SSL structures (keep these last so that USE_SSL doesn't affect
	 * locations of other fields)
162 163
	 */
#ifdef USE_SSL
164
	SSL		   *ssl;
165 166 167
	X509	   *peer;
	char		peer_dn[128 + 1];
	char		peer_cn[SM_USER + 1];
168
	unsigned long count;
169
#endif
170
} Port;
171

172

173 174
extern ProtocolVersion FrontendProtocol;

175 176
/* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */

177 178 179
extern int	pq_getkeepalivesidle(Port *port);
extern int	pq_getkeepalivesinterval(Port *port);
extern int	pq_getkeepalivescount(Port *port);
180

181 182 183
extern int	pq_setkeepalivesidle(int idle, Port *port);
extern int	pq_setkeepalivesinterval(int interval, Port *port);
extern int	pq_setkeepalivescount(int count, Port *port);
184

185
#endif   /* LIBPQ_BE_H */