]> granicus.if.org Git - postgresql/blob - src/include/libpq/libpq-be.h
5e15bcdec7330aef9817eae5304b73faa6d6e663
[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-2007, PostgreSQL Global Development Group
12  * Portions Copyright (c) 1994, Regents of the University of California
13  *
14  * $PostgreSQL: pgsql/src/include/libpq/libpq-be.h,v 1.60 2007/07/12 14:36:52 mha Exp $
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
38 #endif
39
40 #include "libpq/hba.h"
41 #include "libpq/pqcomm.h"
42 #include "utils/timestamp.h"
43
44
45 typedef enum CAC_state
46 {
47         CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY
48 } CAC_state;
49
50
51 /*
52  * GSSAPI specific state information
53  */
54 #ifdef ENABLE_GSS
55 typedef struct
56 {
57         gss_cred_id_t   cred;           /* GSSAPI connection cred's */
58         gss_ctx_id_t    ctx;            /* GSSAPI connection context */
59         gss_name_t              name;           /* GSSAPI client name */
60         gss_buffer_desc outbuf;         /* GSSAPI output token buffer */
61 } pg_gssinfo;
62 #endif
63
64 /*
65  * This is used by the postmaster in its communication with frontends.  It
66  * contains all state information needed during this communication before the
67  * backend is run.      The Port structure is kept in malloc'd memory and is
68  * still available when a backend is running (see MyProcPort).  The data
69  * it points to must also be malloc'd, or else palloc'd in TopMemoryContext,
70  * so that it survives into PostgresMain execution!
71  */
72
73 typedef struct Port
74 {
75         int                     sock;                   /* File descriptor */
76         ProtocolVersion proto;          /* FE/BE protocol version */
77         SockAddr        laddr;                  /* local addr (postmaster) */
78         SockAddr        raddr;                  /* remote addr (client) */
79         char       *remote_host;        /* name (or ip addr) of remote host */
80         char       *remote_port;        /* text rep of remote port */
81         CAC_state       canAcceptConnections;   /* postmaster connection status */
82
83         /*
84          * Information that needs to be saved from the startup packet and passed
85          * into backend execution.      "char *" fields are NULL if not set.
86          * guc_options points to a List of alternating option names and values.
87          */
88         char       *database_name;
89         char       *user_name;
90         char       *cmdline_options;
91         List       *guc_options;
92
93         /*
94          * Information that needs to be held during the authentication cycle.
95          */
96         UserAuth        auth_method;
97         char       *auth_arg;
98         char            md5Salt[4];             /* Password salt */
99         char            cryptSalt[2];   /* Password salt */
100
101         /*
102          * Information that really has no business at all being in struct Port,
103          * but since it gets used by elog.c in the same way as database_name and
104          * other members of this struct, we may as well keep it here.
105          */
106         TimestampTz SessionStartTime;           /* backend start time */
107         time_t          session_start;  /* same, in time_t format */
108
109         /*
110          * TCP keepalive settings.
111          *
112          * default values are 0 if AF_UNIX or not yet known; current values are 0
113          * if AF_UNIX or using the default. Also, -1 in a default value means we
114          * were unable to find out the default (getsockopt failed).
115          */
116         int                     default_keepalives_idle;
117         int                     default_keepalives_interval;
118         int                     default_keepalives_count;
119         int                     keepalives_idle;
120         int                     keepalives_interval;
121         int                     keepalives_count;
122
123 #ifdef ENABLE_GSS
124         /*
125          * If GSSAPI is supported, store GSSAPI information.
126          * Oterwise, store a NULL pointer to make sure offsets
127          * in the struct remain the same.
128          */
129         pg_gssinfo *gss;
130 #else
131         void       *gss;
132 #endif
133
134         /*
135          * SSL structures (keep these last so that USE_SSL doesn't affect
136          * locations of other fields)
137          */
138 #ifdef USE_SSL
139         SSL                *ssl;
140         X509       *peer;
141         char            peer_dn[128 + 1];
142         char            peer_cn[SM_USER + 1];
143         unsigned long count;
144 #endif
145 } Port;
146
147
148 extern ProtocolVersion FrontendProtocol;
149
150 /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
151
152 extern int      pq_getkeepalivesidle(Port *port);
153 extern int      pq_getkeepalivesinterval(Port *port);
154 extern int      pq_getkeepalivescount(Port *port);
155
156 extern int      pq_setkeepalivesidle(int idle, Port *port);
157 extern int      pq_setkeepalivesinterval(int interval, Port *port);
158 extern int      pq_setkeepalivescount(int count, Port *port);
159
160 #endif   /* LIBPQ_BE_H */