Header And Logo

PostgreSQL
| The world's most advanced open source database.

libpq-be.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * libpq_be.h
00004  *    This file contains definitions for structures and externs used
00005  *    by the postmaster during client authentication.
00006  *
00007  *    Note that this is backend-internal and is NOT exported to clients.
00008  *    Structs that need to be client-visible are in pqcomm.h.
00009  *
00010  *
00011  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00012  * Portions Copyright (c) 1994, Regents of the University of California
00013  *
00014  * src/include/libpq/libpq-be.h
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef LIBPQ_BE_H
00019 #define LIBPQ_BE_H
00020 
00021 #ifdef HAVE_SYS_TIME_H
00022 #include <sys/time.h>
00023 #endif
00024 #ifdef USE_SSL
00025 #include <openssl/ssl.h>
00026 #include <openssl/err.h>
00027 #endif
00028 #ifdef HAVE_NETINET_TCP_H
00029 #include <netinet/tcp.h>
00030 #endif
00031 
00032 #ifdef ENABLE_GSS
00033 #if defined(HAVE_GSSAPI_H)
00034 #include <gssapi.h>
00035 #else
00036 #include <gssapi/gssapi.h>
00037 #endif   /* HAVE_GSSAPI_H */
00038 /*
00039  * GSSAPI brings in headers that set a lot of things in the global namespace on win32,
00040  * that doesn't match the msvc build. It gives a bunch of compiler warnings that we ignore,
00041  * but also defines a symbol that simply does not exist. Undefine it again.
00042  */
00043 #ifdef WIN32_ONLY_COMPILER
00044 #undef HAVE_GETADDRINFO
00045 #endif
00046 #endif   /* ENABLE_GSS */
00047 
00048 #ifdef ENABLE_SSPI
00049 #define SECURITY_WIN32
00050 #if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
00051 #include <ntsecapi.h>
00052 #endif
00053 #include <security.h>
00054 #undef SECURITY_WIN32
00055 
00056 #ifndef ENABLE_GSS
00057 /*
00058  * Define a fake structure compatible with GSSAPI on Unix.
00059  */
00060 typedef struct
00061 {
00062     void       *value;
00063     int         length;
00064 } gss_buffer_desc;
00065 #endif
00066 #endif   /* ENABLE_SSPI */
00067 
00068 #include "datatype/timestamp.h"
00069 #include "libpq/hba.h"
00070 #include "libpq/pqcomm.h"
00071 
00072 
00073 typedef enum CAC_state
00074 {
00075     CAC_OK, CAC_STARTUP, CAC_SHUTDOWN, CAC_RECOVERY, CAC_TOOMANY,
00076     CAC_WAITBACKUP
00077 } CAC_state;
00078 
00079 
00080 /*
00081  * GSSAPI specific state information
00082  */
00083 #if defined(ENABLE_GSS) | defined(ENABLE_SSPI)
00084 typedef struct
00085 {
00086     gss_buffer_desc outbuf;     /* GSSAPI output token buffer */
00087 #ifdef ENABLE_GSS
00088     gss_cred_id_t cred;         /* GSSAPI connection cred's */
00089     gss_ctx_id_t ctx;           /* GSSAPI connection context */
00090     gss_name_t  name;           /* GSSAPI client name */
00091 #endif
00092 } pg_gssinfo;
00093 #endif
00094 
00095 /*
00096  * This is used by the postmaster in its communication with frontends.  It
00097  * contains all state information needed during this communication before the
00098  * backend is run.  The Port structure is kept in malloc'd memory and is
00099  * still available when a backend is running (see MyProcPort).  The data
00100  * it points to must also be malloc'd, or else palloc'd in TopMemoryContext,
00101  * so that it survives into PostgresMain execution!
00102  */
00103 
00104 typedef struct Port
00105 {
00106     pgsocket    sock;           /* File descriptor */
00107     bool        noblock;        /* is the socket in non-blocking mode? */
00108     ProtocolVersion proto;      /* FE/BE protocol version */
00109     SockAddr    laddr;          /* local addr (postmaster) */
00110     SockAddr    raddr;          /* remote addr (client) */
00111     char       *remote_host;    /* name (or ip addr) of remote host */
00112     char       *remote_hostname;/* name (not ip addr) of remote host, if
00113                                  * available */
00114     int         remote_hostname_resolv; /* +1 = remote_hostname is known to
00115                                          * resolve to client's IP address; -1
00116                                          * = remote_hostname is known NOT to
00117                                          * resolve to client's IP address; 0 =
00118                                          * we have not done the forward DNS
00119                                          * lookup yet */
00120     char       *remote_port;    /* text rep of remote port */
00121     CAC_state   canAcceptConnections;   /* postmaster connection status */
00122 
00123     /*
00124      * Information that needs to be saved from the startup packet and passed
00125      * into backend execution.  "char *" fields are NULL if not set.
00126      * guc_options points to a List of alternating option names and values.
00127      */
00128     char       *database_name;
00129     char       *user_name;
00130     char       *cmdline_options;
00131     List       *guc_options;
00132 
00133     /*
00134      * Information that needs to be held during the authentication cycle.
00135      */
00136     HbaLine    *hba;
00137     char        md5Salt[4];     /* Password salt */
00138 
00139     /*
00140      * Information that really has no business at all being in struct Port,
00141      * but since it gets used by elog.c in the same way as database_name and
00142      * other members of this struct, we may as well keep it here.
00143      */
00144     TimestampTz SessionStartTime;       /* backend start time */
00145 
00146     /*
00147      * TCP keepalive settings.
00148      *
00149      * default values are 0 if AF_UNIX or not yet known; current values are 0
00150      * if AF_UNIX or using the default. Also, -1 in a default value means we
00151      * were unable to find out the default (getsockopt failed).
00152      */
00153     int         default_keepalives_idle;
00154     int         default_keepalives_interval;
00155     int         default_keepalives_count;
00156     int         keepalives_idle;
00157     int         keepalives_interval;
00158     int         keepalives_count;
00159 
00160 #if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
00161 
00162     /*
00163      * If GSSAPI is supported, store GSSAPI information. Otherwise, store a
00164      * NULL pointer to make sure offsets in the struct remain the same.
00165      */
00166     pg_gssinfo *gss;
00167 #else
00168     void       *gss;
00169 #endif
00170 
00171     /*
00172      * SSL structures (keep these last so that USE_SSL doesn't affect
00173      * locations of other fields)
00174      */
00175 #ifdef USE_SSL
00176     SSL        *ssl;
00177     X509       *peer;
00178     char       *peer_cn;
00179     unsigned long count;
00180 #endif
00181 } Port;
00182 
00183 
00184 extern ProtocolVersion FrontendProtocol;
00185 
00186 /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
00187 
00188 extern int  pq_getkeepalivesidle(Port *port);
00189 extern int  pq_getkeepalivesinterval(Port *port);
00190 extern int  pq_getkeepalivescount(Port *port);
00191 
00192 extern int  pq_setkeepalivesidle(int idle, Port *port);
00193 extern int  pq_setkeepalivesinterval(int interval, Port *port);
00194 extern int  pq_setkeepalivescount(int count, Port *port);
00195 
00196 #endif   /* LIBPQ_BE_H */