]> git.8kb.co.uk Git - pgpool-ii/pgpool-ii_2.2.5/blob - pool_type.h
Attempt to send a proper failure message to frontend when authentication
[pgpool-ii/pgpool-ii_2.2.5] / pool_type.h
1 /* -*-pgsql-c-*- */
2 /*
3  *
4  * $Header: /cvsroot/pgpool/pgpool-II/pool_type.h,v 1.9 2008/12/30 00:59:35 t-ishii Exp $
5  *
6  * pgpool: a language independent connection pool server for PostgreSQL 
7  * written by Tatsuo Ishii
8  *
9  * Copyright (c) 2003-2008      PgPool Global Development Group
10  *
11  * Permission to use, copy, modify, and distribute this software and
12  * its documentation for any purpose and without fee is hereby
13  * granted, provided that the above copyright notice appear in all
14  * copies and that both that copyright notice and this permission
15  * notice appear in supporting documentation, and that the name of the
16  * author not be used in advertising or publicity pertaining to
17  * distribution of the software without specific, written prior
18  * permission. The author makes no representations about the
19  * suitability of this software for any purpose.  It is provided "as
20  * is" without express or implied warranty.
21  *
22  * pool_type.h.: type definition header file
23  *
24  */
25
26 #ifndef POOL_TYPE_H
27 #define POOL_TYPE_H
28
29 #include "config.h"
30 #include <sys/types.h>
31 #include <sys/socket.h>
32
33 /* Define common boolean type. C++ and BEOS already has it so exclude them. */
34 #ifdef c_plusplus
35 #ifndef __cplusplus
36 #define __cplusplus
37 #endif /* __cplusplus */
38 #endif /* c_plusplus */
39
40 #ifndef __BEOS__
41 #ifndef __cplusplus
42 #ifndef bool
43 typedef char bool;
44 #endif
45 #ifndef true
46 #define true ((bool) 1)
47 #endif
48 #ifndef TRUE
49 #define TRUE ((bool) 1)
50 #endif
51 #ifndef false
52 #define false ((bool) 0)
53 #endif
54 #ifndef FALSE
55 #define FALSE ((bool) 0)
56 #endif
57 #endif /* not C++ */
58 #endif /* __BEOS__ */
59
60 /*
61  * startup packet definitions (v2) stolen from PostgreSQL
62  */
63 #define SM_DATABASE             64
64 #define SM_USER                 32
65 #define SM_OPTIONS              64
66 #define SM_UNUSED               64
67 #define SM_TTY                  64
68
69 #define MAX_NUM_BACKENDS 128
70 #define MAX_CONNECTION_SLOTS 128
71 #define MAX_DB_HOST_NAMELEN      128
72 #define MAX_PATH_LENGTH 256
73
74 typedef enum {
75         CON_UNUSED,             /* unused slot */
76     CON_CONNECT_WAIT,           /* waiting for connection starting */
77         CON_UP, /* up and running */
78         CON_DOWN                /* down, disconnected */
79 } BACKEND_STATUS;
80
81 typedef enum {
82         LOAD_UNSELECTED = 0,
83         LOAD_SELECTED
84 } LOAD_BALANCE_STATUS;
85
86 /*
87  * PostgreSQL backend descriptor. Placed on shared memory area.
88  */
89 typedef struct {
90         char backend_hostname[MAX_DB_HOST_NAMELEN];     /* backend host name */
91         int backend_port;       /* backend port numbers */
92         BACKEND_STATUS backend_status;  /* backend status */
93         double backend_weight;  /* normalized backend load balance ratio */
94         double unnormalized_weight; /* descripted parameter */
95         char backend_data_directory[MAX_PATH_LENGTH];
96 } BackendInfo;
97
98 typedef struct {
99         int num_backends;               /* number of used PostgreSQL backends */
100         BackendInfo backend_info[MAX_NUM_BACKENDS];
101 } BackendDesc;
102
103 /*
104  * Connection pool information. Placed on shared memory area.
105  */
106 typedef struct {
107         char            database[SM_DATABASE];  /* Database name */
108         char            user[SM_USER];  /* User name */
109         int                     major;  /* protocol major version */
110         int                     minor;  /* protocol minor version */
111         int                     pid;    /* backend process id */
112         int                     key;    /* cancel key */
113         int                     counter; /* used counter */
114         time_t          create_time; /* connection creation time */
115         int load_balancing_node; /* load balancing node */
116 } ConnectionInfo;
117
118
119 /*
120  * process information
121  * This object put on shared memory.
122  */
123 typedef struct {
124         pid_t pid; /* OS's process id */
125         time_t start_time; /* fork() time */
126         ConnectionInfo *connection_info; /* head of the connection info for this process */
127 } ProcessInfo;
128
129 /*
130  * 
131  * system db structure
132  */
133 typedef struct {
134         char *dbname;                   /* database name */
135         char *schema_name;              /* schema name */
136         char *table_name;               /* table name */
137         char *dist_key_col_name;/* column name for dist key */
138         int  dist_key_col_id;   /* column index id for dist key */
139         int  col_num;                   /* number of clumn*/
140         char **col_list;                /* column list */
141         char **type_list;               /* type list */
142         char *dist_def_func;    /* function name of distribution rule */
143         char *prepare_name;             /* prepared statement name */
144         int is_created_prepare; /* is prepare statement created? */
145 } DistDefInfo;
146
147 typedef struct {
148         char *dbname;     /* database name */
149         char *schema_name;    /* schema name */
150         char *table_name;   /* table name */
151         int  col_num;     /* number of clumn*/
152         char **col_list;    /* column list */
153         char **type_list;   /* type list */
154         char *prepare_name;   /* prepared statement name */
155         int is_created_prepare; /* is prepare statement created? */
156 } RepliDefInfo;
157
158 typedef struct {
159         int has_prepared_statement;     /* true if the current session has prepared statement created */
160         char *register_prepared_statement; /* prepared statement name for cache register */
161 } QueryCacheTableInfo;
162
163 typedef struct {
164         char *hostname;     /* host name */
165         int port;       /* port number */
166         char *user;       /* login user name */
167         char *password;     /* login password */
168         char *schema_name;    /* schema name */
169         char *database_name;  /* database name */
170         int repli_def_num;    /* number of replication table */
171         int dist_def_num;   /* number of distribution table */
172         RepliDefInfo *repli_def_slot; /* replication rule list */
173         DistDefInfo *dist_def_slot; /* distribution rule list */
174         QueryCacheTableInfo query_cache_table_info; /* query cache db session info */
175         BACKEND_STATUS system_db_status;
176 } SystemDBInfo;
177
178 /*
179  *  It seems that sockaddr_storage is now commonly used in place of sockaddr.
180  *  So, define it if it is not define yet, and create new SockAddr structure
181  *  that uses sockaddr_storage.
182  */
183 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE
184
185 #ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
186 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
187 #define ss_family __ss_family
188 #else
189 #error struct sockaddr_storage does not provide an ss_family member
190 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY */
191 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY */
192
193 #ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
194 #define ss_len __ss_len
195 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
196 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */
197
198 #else /* !HAVE_STRUCT_SOCKADDR_STORAGE */
199
200 /* Define a struct sockaddr_storage if we don't have one. */
201 struct sockaddr_storage
202 {
203         union
204         {
205                 struct sockaddr sa;             /* get the system-dependent fields */
206                 long int ss_align; /* ensures struct is properly aligned. original uses int64 */
207                 char ss_pad[128];               /* ensures struct has desired size */
208         }
209         ss_stuff;
210 };
211
212 #define ss_family   ss_stuff.sa.sa_family
213 /* It should have an ss_len field if sockaddr has sa_len. */
214 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
215 #define ss_len      ss_stuff.sa.sa_len
216 #define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
217 #endif
218 #endif /* HAVE_STRUCT_SOCKADDR_STORAGE */
219
220 typedef struct
221 {
222         struct sockaddr_storage addr;
223         /* ACCEPT_TYPE_ARG3 - Third argument type of accept().
224          * It is defined in ac_func_accept_argtypes.m4
225          */
226         ACCEPT_TYPE_ARG3 salen;
227 }
228 SockAddr;
229
230 /* UserAuth type used for HBA which indicates the authentication method */
231 typedef enum UserAuth
232 {
233         uaReject,
234         /*  uaKrb4, */
235         /*  uaKrb5, */
236         uaTrust
237         /*  uaIdent, */
238         /*  uaPassword, */
239         /*  uaCrypt, */
240         /*  uaMD5 */
241 #ifdef USE_PAM
242         ,uaPAM
243 #endif /* USE_PAM */
244 }
245 UserAuth;
246
247 #define AUTH_REQ_OK         0   /* User is authenticated  */
248 #define AUTH_REQ_KRB4       1   /* Kerberos V4 */
249 #define AUTH_REQ_KRB5       2   /* Kerberos V5 */
250 #define AUTH_REQ_PASSWORD   3   /* Password */
251 #define AUTH_REQ_CRYPT      4   /* crypt password */
252 #define AUTH_REQ_MD5        5   /* md5 password */
253 #define AUTH_REQ_SCM_CREDS  6   /* transfer SCM credentials */
254
255 typedef unsigned int AuthRequest;
256
257 #endif /* POOL_TYPE_H */