5
5
* wherein you authenticate a user by seeing what IP address the system
6
6
* says he comes from and possibly using ident).
7
7
*
8
- * $Id: hba.c,v 1.47 1999/07/17 20:17:02 momjian Exp $
8
+ * $Id: hba.c,v 1.48 1999/09/27 03:12:59 momjian Exp $
9
9
*
10
10
*-------------------------------------------------------------------------
11
11
*/
@@ -146,9 +146,7 @@ read_hba_entry2(FILE *file, UserAuth *userauth_p, char *auth_arg,
146
146
147
147
148
148
static void
149
- process_hba_record (FILE * file , SockAddr * raddr , const char * user ,
150
- const char * database , bool * matches_p , bool * error_p ,
151
- UserAuth * userauth_p , char * auth_arg )
149
+ process_hba_record (FILE * file , hbaPort * port , bool * matches_p , bool * error_p )
152
150
{
153
151
/*---------------------------------------------------------------------------
154
152
Process the non-comment record in the config file that is next on the file.
@@ -182,16 +180,16 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
182
180
183
181
/* Read the rest of the line. */
184
182
185
- read_hba_entry2 (file , userauth_p , auth_arg , error_p );
183
+ read_hba_entry2 (file , & port -> auth_method , port -> auth_arg , error_p );
186
184
187
185
/*
188
186
* For now, disallow methods that need AF_INET sockets to work.
189
187
*/
190
188
191
189
if (!* error_p &&
192
- (* userauth_p == uaIdent ||
193
- * userauth_p == uaKrb4 ||
194
- * userauth_p == uaKrb5 ))
190
+ (port -> auth_method == uaIdent ||
191
+ port -> auth_method == uaKrb4 ||
192
+ port -> auth_method == uaKrb5 ))
195
193
* error_p = true;
196
194
197
195
if (* error_p )
@@ -202,15 +200,33 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
202
200
* sort of connection, ignore it.
203
201
*/
204
202
205
- if ((strcmp (db , database ) != 0 && strcmp (db , "all" ) != 0 &&
206
- (strcmp (db , "sameuser" ) != 0 || strcmp (database , user ) != 0 )) ||
207
- raddr -> sa .sa_family != AF_UNIX )
203
+ if ((strcmp (db , port -> database ) != 0 && strcmp (db , "all" ) != 0 &&
204
+ (strcmp (db , "sameuser" ) != 0 || strcmp (port -> database , port -> user ) != 0 )) ||
205
+ port -> raddr . sa .sa_family != AF_UNIX )
208
206
return ;
209
207
}
210
- else if (strcmp (buf , "host" ) == 0 )
208
+ else if (strcmp (buf , "host" ) == 0 || strcmp ( buf , "hostssl" ) == 0 )
211
209
{
212
210
struct in_addr file_ip_addr ,
213
211
mask ;
212
+ bool discard = 0 ; /* Discard this entry */
213
+
214
+ #ifdef USE_SSL
215
+ /* If SSL, then check that we are on SSL */
216
+ if (strcmp (buf , "hostssl" ) == 0 ) {
217
+ if (!port -> ssl )
218
+ discard = 1 ;
219
+
220
+ /* Placeholder to require specific SSL level, perhaps? */
221
+ /* Or a client certificate */
222
+
223
+ /* Since we were on SSL, proceed as with normal 'host' mode */
224
+ }
225
+ #else
226
+ /* If not SSL, we don't support this */
227
+ if (strcmp (buf ,"hostssl" ) == 0 )
228
+ goto syntax ;
229
+ #endif
214
230
215
231
/* Get the database. */
216
232
@@ -252,20 +268,27 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
252
268
* info from it.
253
269
*/
254
270
255
- read_hba_entry2 (file , userauth_p , auth_arg , error_p );
271
+ read_hba_entry2 (file , & port -> auth_method , port -> auth_arg , error_p );
256
272
257
273
if (* error_p )
258
274
goto syntax ;
259
275
276
+ /*
277
+ * If told to discard earlier. Moved down here so we don't get
278
+ * "out of sync" with the file.
279
+ */
280
+ if (discard )
281
+ return ;
282
+
260
283
/*
261
284
* If this record isn't for our database, or this is the wrong
262
285
* sort of connection, ignore it.
263
286
*/
264
287
265
- if ((strcmp (db , database ) != 0 && strcmp (db , "all" ) != 0 &&
266
- (strcmp (db , "sameuser" ) != 0 || strcmp (database , user ) != 0 )) ||
267
- raddr -> sa .sa_family != AF_INET ||
268
- ((file_ip_addr .s_addr ^ raddr -> in .sin_addr .s_addr ) & mask .s_addr ) != 0x0000 )
288
+ if ((strcmp (db , port -> database ) != 0 && strcmp (db , "all" ) != 0 &&
289
+ (strcmp (db , "sameuser" ) != 0 || strcmp (port -> database , port -> user ) != 0 )) ||
290
+ port -> raddr . sa .sa_family != AF_INET ||
291
+ ((file_ip_addr .s_addr ^ port -> raddr . in .sin_addr .s_addr ) & mask .s_addr ) != 0x0000 )
269
292
return ;
270
293
}
271
294
else
@@ -291,9 +314,7 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
291
314
292
315
293
316
static void
294
- process_open_config_file (FILE * file , SockAddr * raddr , const char * user ,
295
- const char * database , bool * hba_ok_p ,
296
- UserAuth * userauth_p , char * auth_arg )
317
+ process_open_config_file (FILE * file , hbaPort * port , bool * hba_ok_p )
297
318
{
298
319
/*---------------------------------------------------------------------------
299
320
This function does the same thing as find_hba_entry, only with
@@ -316,8 +337,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
316
337
if (c == '#' )
317
338
read_through_eol (file );
318
339
else
319
- process_hba_record (file , raddr , user , database ,
320
- & found_entry , & error , userauth_p , auth_arg );
340
+ process_hba_record (file , port , & found_entry , & error );
321
341
}
322
342
}
323
343
@@ -326,7 +346,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
326
346
/* If no matching entry was found, synthesize 'reject' entry. */
327
347
328
348
if (!found_entry )
329
- * userauth_p = uaReject ;
349
+ port -> auth_method = uaReject ;
330
350
331
351
* hba_ok_p = true;
332
352
}
@@ -335,8 +355,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
335
355
336
356
337
357
static void
338
- find_hba_entry (SockAddr * raddr , const char * user , const char * database ,
339
- bool * hba_ok_p , UserAuth * userauth_p , char * auth_arg )
358
+ find_hba_entry (hbaPort * port , bool * hba_ok_p )
340
359
{
341
360
/*
342
361
* Read the config file and find an entry that allows connection from
@@ -412,8 +431,7 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
412
431
}
413
432
else
414
433
{
415
- process_open_config_file (file , raddr , user , database , hba_ok_p ,
416
- userauth_p , auth_arg );
434
+ process_open_config_file (file , port , hba_ok_p );
417
435
FreeFile (file );
418
436
}
419
437
pfree (conf_file );
@@ -1057,8 +1075,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
1057
1075
#endif
1058
1076
1059
1077
int
1060
- hba_getauthmethod (SockAddr * raddr , char * user , char * database ,
1061
- char * auth_arg , UserAuth * auth_method )
1078
+ hba_getauthmethod (hbaPort * port )
1062
1079
{
1063
1080
/*---------------------------------------------------------------------------
1064
1081
Determine what authentication method should be used when accessing database
@@ -1070,7 +1087,7 @@ hba_getauthmethod(SockAddr *raddr, char *user, char *database,
1070
1087
----------------------------------------------------------------------------*/
1071
1088
bool hba_ok = false;
1072
1089
1073
- find_hba_entry (raddr , user , database , & hba_ok , auth_method , auth_arg );
1090
+ find_hba_entry (port , & hba_ok );
1074
1091
1075
1092
return hba_ok ? STATUS_OK : STATUS_ERROR ;
1076
1093
}
0 commit comments