]> granicus.if.org Git - postgresql/blob - src/include/libpq/libpq-be.h
83628c13f9f2161bfa64e466979e2110f2a563c6
[postgresql] / src / include / libpq / libpq-be.h
1 /*-------------------------------------------------------------------------
2  *
3  * libpq_be.h
4  *        This file contains definitions for structures and externs used
5  *        by the postmaster during client authentication.
6  *
7  *        Note that this is backend-internal and is NOT exported to clients.
8  *        Structs that need to be client-visible are in pqcomm.h.
9  *
10  *
11  * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
12  * Portions Copyright (c) 1994, Regents of the University of California
13  *
14  * src/include/libpq/libpq-be.h
15  *
16  *-------------------------------------------------------------------------
17  */
18 #ifndef LIBPQ_BE_H
19 #define LIBPQ_BE_H
20
21 #ifdef HAVE_SYS_TIME_H
22 #include <sys/time.h>
23 #endif
24 #ifdef USE_SSL
25 #include <openssl/ssl.h>
26 #include <openssl/err.h>
27 #endif
28 #ifdef HAVE_NETINET_TCP_H
29 #include <netinet/tcp.h>
30 #endif
31
32 #ifdef ENABLE_GSS
33 #if defined(HAVE_GSSAPI_H)
34 #include <gssapi.h>
35 #else
36 #include <gssapi/gssapi.h>
37 #endif   /* HAVE_GSSAPI_H */
38 /*
39  * GSSAPI brings in headers that set a lot of things in the global namespace on win32,
40  * that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore,
41  * but also defines a symbol that simply does not exist. Undefine it again.
42  */
43 #ifdef WIN32_ONLY_COMPILER
44 #undef HAVE_GETADDRINFO
45 #endif
46 #endif   /* ENABLE_GSS */
47
48 #ifdef ENABLE_SSPI
49 #define SECURITY_WIN32
50 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
51 #include <ntsecapi.h>
52 #endif
53 #include <security.h>
54 #undef SECURITY_WIN32
55
56 #ifndef ENABLE_GSS
57 /*
58  * Define a fake structure compatible with GSSAPI on Unix.
59  */
60 typedef struct
61 {
62         void       *value;
63         int                     length;
64 } gss_buffer_desc;
65 #endif
66 #endif   /* ENABLE_SSPI */
67
68 #include "libpq/hba.h"
69 #include "libpq/pqcomm.h"
70 #include "utils/timestamp.h"
71
72
73 typedef enum CAC_state
74 {
75         CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
76         CAC_WAITBACKUP
77 } CAC_state;
78
79
80 /*
81  * GSSAPI specific state information
82  */
83 #if defined(ENABLE_GSS) | defined(ENABLE_SSPI)
84 typedef struct
85 {
86         gss_buffer_desc outbuf;         /* GSSAPI output token buffer */
87 #ifdef ENABLE_GSS
88         gss_cred_id_t cred;                     /* GSSAPI connection cred's */
89         gss_ctx_id_t ctx;                       /* GSSAPI connection context */
90         gss_name_t      name;                   /* GSSAPI client name */
91 #endif
92 } pg_gssinfo;
93 #endif
94
95 /*
96  * This is used by the postmaster in its communication with frontends.  It
97  * contains all state information needed during this communication before the
98  * backend is run.      The Port structure is kept in malloc'd memory and is
99  * still available when a backend is running (see MyProcPort).  The data
100  * it points to must also be malloc'd, or else palloc'd in TopMemoryContext,
101  * so that it survives into PostgresMain execution!
102  */
103
104 typedef struct Port
105 {
106         pgsocket        sock;                   /* File descriptor */
107         bool            noblock;                /* is the socket in non-blocking mode? */
108         ProtocolVersion proto;          /* FE/BE protocol version */
109         SockAddr        laddr;                  /* local addr (postmaster) */
110         SockAddr        raddr;                  /* remote addr (client) */
111         char       *remote_host;        /* name (or ip addr) of remote host */
112         char       *remote_port;        /* text rep of remote port */
113         CAC_state       canAcceptConnections;   /* postmaster connection status */
114
115         /*
116          * Information that needs to be saved from the startup packet and passed
117          * into backend execution.      "char *" fields are NULL if not set.
118          * guc_options points to a List of alternating option names and values.
119          */
120         char       *database_name;
121         char       *user_name;
122         char       *cmdline_options;
123         List       *guc_options;
124
125         /*
126          * Information that needs to be held during the authentication cycle.
127          */
128         HbaLine    *hba;
129         char            md5Salt[4];             /* Password salt */
130
131         /*
132          * Information that really has no business at all being in struct Port,
133          * but since it gets used by elog.c in the same way as database_name and
134          * other members of this struct, we may as well keep it here.
135          */
136         TimestampTz SessionStartTime;           /* backend start time */
137
138         /*
139          * TCP keepalive settings.
140          *
141          * default values are 0 if AF_UNIX or not yet known; current values are 0
142          * if AF_UNIX or using the default. Also, -1 in a default value means we
143          * were unable to find out the default (getsockopt failed).
144          */
145         int                     default_keepalives_idle;
146         int                     default_keepalives_interval;
147         int                     default_keepalives_count;
148         int                     keepalives_idle;
149         int                     keepalives_interval;
150         int                     keepalives_count;
151
152 #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
153
154         /*
155          * If GSSAPI is supported, store GSSAPI information. Oterwise, store a
156          * NULL pointer to make sure offsets in the struct remain the same.
157          */
158         pg_gssinfo *gss;
159 #else
160         void       *gss;
161 #endif
162
163         /*
164          * SSL structures (keep these last so that USE_SSL doesn't affect
165          * locations of other fields)
166          */
167 #ifdef USE_SSL
168         SSL                *ssl;
169         X509       *peer;
170         char            peer_dn[128 + 1];
171         char            peer_cn[SM_USER + 1];
172         unsigned long count;
173 #endif
174 } Port;
175
176
177 extern ProtocolVersion FrontendProtocol;
178
179 /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
180
181 extern int      pq_getkeepalivesidle(Port *port);
182 extern int      pq_getkeepalivesinterval(Port *port);
183 extern int      pq_getkeepalivescount(Port *port);
184
185 extern int      pq_setkeepalivesidle(int idle, Port *port);
186 extern int      pq_setkeepalivesinterval(int interval, Port *port);
187 extern int      pq_setkeepalivescount(int count, Port *port);
188
189 #endif   /* LIBPQ_BE_H */