~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/libpq/pqcomm.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * pqcomm.h
 
4
 *              Definitions common to frontends and backends.
 
5
 *
 
6
 * NOTE: for historical reasons, this does not correspond to pqcomm.c.
 
7
 * pqcomm.c's routines are declared in libpq.h.
 
8
 *
 
9
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
10
 * Portions Copyright (c) 1994, Regents of the University of California
 
11
 *
 
12
 * src/include/libpq/pqcomm.h
 
13
 *
 
14
 *-------------------------------------------------------------------------
 
15
 */
 
16
#ifndef PQCOMM_H
 
17
#define PQCOMM_H
 
18
 
 
19
#include <sys/socket.h>
 
20
#include <netdb.h>
 
21
#ifdef HAVE_SYS_UN_H
 
22
#include <sys/un.h>
 
23
#endif
 
24
#include <netinet/in.h>
 
25
 
 
26
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
 
27
 
 
28
#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
 
29
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
 
30
#define ss_family __ss_family
 
31
#else
 
32
#error struct sockaddr_storage does not provide an ss_family member
 
33
#endif
 
34
#endif
 
35
 
 
36
#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
 
37
#define ss_len __ss_len
 
38
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
 
39
#endif
 
40
#else                                                   /* !HAVE_STRUCT_SOCKADDR_STORAGE */
 
41
 
 
42
/* Define a struct sockaddr_storage if we don't have one. */
 
43
 
 
44
struct sockaddr_storage
 
45
{
 
46
        union
 
47
        {
 
48
                struct sockaddr sa;             /* get the system-dependent fields */
 
49
                int64           ss_align;       /* ensures struct is properly aligned */
 
50
                char            ss_pad[128];    /* ensures struct has desired size */
 
51
        }                       ss_stuff;
 
52
};
 
53
 
 
54
#define ss_family       ss_stuff.sa.sa_family
 
55
/* It should have an ss_len field if sockaddr has sa_len. */
 
56
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
 
57
#define ss_len          ss_stuff.sa.sa_len
 
58
#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
 
59
#endif
 
60
#endif   /* HAVE_STRUCT_SOCKADDR_STORAGE */
 
61
 
 
62
typedef struct
 
63
{
 
64
        struct sockaddr_storage addr;
 
65
        ACCEPT_TYPE_ARG3 salen;
 
66
} SockAddr;
 
67
 
 
68
/* Configure the UNIX socket location for the well known port. */
 
69
 
 
70
#define UNIXSOCK_PATH(path, port, sockdir) \
 
71
                snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
 
72
                                ((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
 
73
                                DEFAULT_PGSOCKET_DIR, \
 
74
                                (port))
 
75
 
 
76
/*
 
77
 * These manipulate the frontend/backend protocol version number.
 
78
 *
 
79
 * The major number should be incremented for incompatible changes.  The minor
 
80
 * number should be incremented for compatible changes (eg. additional
 
81
 * functionality).
 
82
 *
 
83
 * If a backend supports version m.n of the protocol it must actually support
 
84
 * versions m.[0..n].  Backend support for version m-1 can be dropped after a
 
85
 * `reasonable' length of time.
 
86
 *
 
87
 * A frontend isn't required to support anything other than the current
 
88
 * version.
 
89
 */
 
90
 
 
91
#define PG_PROTOCOL_MAJOR(v)    ((v) >> 16)
 
92
#define PG_PROTOCOL_MINOR(v)    ((v) & 0x0000ffff)
 
93
#define PG_PROTOCOL(m,n)        (((m) << 16) | (n))
 
94
 
 
95
/* The earliest and latest frontend/backend protocol version supported. */
 
96
 
 
97
#define PG_PROTOCOL_EARLIEST    PG_PROTOCOL(1,0)
 
98
#define PG_PROTOCOL_LATEST              PG_PROTOCOL(3,0)
 
99
 
 
100
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
 
101
 
 
102
typedef ProtocolVersion MsgType;
 
103
 
 
104
 
 
105
/*
 
106
 * Packet lengths are 4 bytes in network byte order.
 
107
 *
 
108
 * The initial length is omitted from the packet layouts appearing below.
 
109
 */
 
110
 
 
111
typedef uint32 PacketLen;
 
112
 
 
113
 
 
114
/*
 
115
 * Old-style startup packet layout with fixed-width fields.  This is used in
 
116
 * protocol 1.0 and 2.0, but not in later versions.  Note that the fields
 
117
 * in this layout are '\0' terminated only if there is room.
 
118
 */
 
119
 
 
120
#define SM_DATABASE             64
 
121
#define SM_USER                 32
 
122
/* We append database name if db_user_namespace true. */
 
123
#define SM_DATABASE_USER (SM_DATABASE+SM_USER+1)                /* +1 for @ */
 
124
#define SM_OPTIONS              64
 
125
#define SM_UNUSED               64
 
126
#define SM_TTY                  64
 
127
 
 
128
typedef struct StartupPacket
 
129
{
 
130
        ProtocolVersion protoVersion;           /* Protocol version */
 
131
        char            database[SM_DATABASE];  /* Database name */
 
132
        /* Db_user_namespace appends dbname */
 
133
        char            user[SM_USER];  /* User name */
 
134
        char            options[SM_OPTIONS];    /* Optional additional args */
 
135
        char            unused[SM_UNUSED];              /* Unused */
 
136
        char            tty[SM_TTY];    /* Tty for debug output */
 
137
} StartupPacket;
 
138
 
 
139
extern bool Db_user_namespace;
 
140
 
 
141
/*
 
142
 * In protocol 3.0 and later, the startup packet length is not fixed, but
 
143
 * we set an arbitrary limit on it anyway.      This is just to prevent simple
 
144
 * denial-of-service attacks via sending enough data to run the server
 
145
 * out of memory.
 
146
 */
 
147
#define MAX_STARTUP_PACKET_LENGTH 10000
 
148
 
 
149
 
 
150
/* These are the authentication request codes sent by the backend. */
 
151
 
 
152
#define AUTH_REQ_OK                     0       /* User is authenticated  */
 
153
#define AUTH_REQ_KRB4           1       /* Kerberos V4. Not supported any more. */
 
154
#define AUTH_REQ_KRB5           2       /* Kerberos V5 */
 
155
#define AUTH_REQ_PASSWORD       3       /* Password */
 
156
#define AUTH_REQ_CRYPT          4       /* crypt password. Not supported any more. */
 
157
#define AUTH_REQ_MD5            5       /* md5 password */
 
158
#define AUTH_REQ_SCM_CREDS      6       /* transfer SCM credentials */
 
159
#define AUTH_REQ_GSS            7       /* GSSAPI without wrap() */
 
160
#define AUTH_REQ_GSS_CONT       8       /* Continue GSS exchanges */
 
161
#define AUTH_REQ_SSPI           9       /* SSPI negotiate without wrap() */
 
162
 
 
163
typedef uint32 AuthRequest;
 
164
 
 
165
 
 
166
/*
 
167
 * A client can also send a cancel-current-operation request to the postmaster.
 
168
 * This is uglier than sending it directly to the client's backend, but it
 
169
 * avoids depending on out-of-band communication facilities.
 
170
 *
 
171
 * The cancel request code must not match any protocol version number
 
172
 * we're ever likely to use.  This random choice should do.
 
173
 */
 
174
#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
 
175
 
 
176
typedef struct CancelRequestPacket
 
177
{
 
178
        /* Note that each field is stored in network byte order! */
 
179
        MsgType         cancelRequestCode;              /* code to identify a cancel request */
 
180
        uint32          backendPID;             /* PID of client's backend */
 
181
        uint32          cancelAuthCode; /* secret key to authorize cancel */
 
182
} CancelRequestPacket;
 
183
 
 
184
 
 
185
/*
 
186
 * A client can also start by sending a SSL negotiation request, to get a
 
187
 * secure channel.
 
188
 */
 
189
#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
 
190
 
 
191
#endif   /* PQCOMM_H */