|
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.39 1999/02/13 23:15:43 momjian Exp $ |
| 8 | + * $Id: hba.c,v 1.40 1999/04/16 04:59:03 tgl Exp $ |
9 | 9 | * |
10 | 10 | *------------------------------------------------------------------------- |
11 | 11 | */ |
@@ -298,81 +298,66 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user, |
298 | 298 |
|
299 | 299 | staticvoid |
300 | 300 | process_open_config_file(FILE*file,SockAddr*raddr,constchar*user, |
301 | | -constchar*database,bool*host_ok_p, |
| 301 | +constchar*database,bool*hba_ok_p, |
302 | 302 | UserAuth*userauth_p,char*auth_arg) |
303 | 303 | { |
304 | 304 | /*--------------------------------------------------------------------------- |
305 | 305 | This function does the same thing as find_hba_entry, only with |
306 | 306 | the config file already open on stream descriptor "file". |
307 | 307 | ----------------------------------------------------------------------------*/ |
308 | | -boolfound_entry; |
| 308 | +boolfound_entry= false;/* found an applicable entry? */ |
| 309 | +boolerror= false;/* found an erroneous entry? */ |
| 310 | +booleof= false;/* end of hba file */ |
309 | 311 |
|
310 | | -/* We've processed a record that applies to our connection */ |
311 | | -boolerror; |
312 | | - |
313 | | -/* Said record has invalid syntax. */ |
314 | | -booleof;/* We've reached the end of the file we're |
315 | | - * reading */ |
316 | | - |
317 | | -found_entry= false;/* initial value */ |
318 | | -error= false;/* initial value */ |
319 | | -eof= false;/* initial value */ |
320 | 312 | while (!eof&& !found_entry&& !error) |
321 | 313 | { |
322 | 314 | /* Process a line from the config file */ |
323 | | - |
324 | | -intc;/* a character read from the file */ |
325 | | - |
326 | | -c=getc(file); |
327 | | -ungetc(c,file); |
| 315 | +intc=getc(file); |
328 | 316 | if (c==EOF) |
329 | 317 | eof= true; |
330 | 318 | else |
331 | 319 | { |
| 320 | +ungetc(c,file); |
332 | 321 | if (c=='#') |
333 | 322 | read_through_eol(file); |
334 | 323 | else |
335 | | -{ |
336 | 324 | process_hba_record(file,raddr,user,database, |
337 | 325 | &found_entry,&error,userauth_p,auth_arg); |
338 | | -} |
339 | 326 | } |
340 | 327 | } |
341 | 328 |
|
342 | 329 | if (!error) |
343 | 330 | { |
344 | | -/* If no entry was found then force a rejection. */ |
| 331 | +/* If nomatchingentry was found, synthesize 'reject' entry. */ |
345 | 332 |
|
346 | 333 | if (!found_entry) |
347 | 334 | *userauth_p=uaReject; |
348 | 335 |
|
349 | | -*host_ok_p= true; |
| 336 | +*hba_ok_p= true; |
350 | 337 | } |
351 | 338 | } |
352 | 339 |
|
353 | 340 |
|
354 | 341 |
|
355 | 342 | staticvoid |
356 | 343 | find_hba_entry(SockAddr*raddr,constchar*user,constchar*database, |
357 | | -bool*host_ok_p,UserAuth*userauth_p,char*auth_arg) |
| 344 | +bool*hba_ok_p,UserAuth*userauth_p,char*auth_arg) |
358 | 345 | { |
359 | 346 | /* |
360 | 347 | * Read the config file and find an entry that allows connection from |
361 | | - * host "*raddr" to database "database". If found, return *host_ok_p == true |
362 | | - * and *userauth_p and *auth_arg representing the contents of that entry. |
363 | | - * |
364 | | - * When a record has invalid syntax, we either ignore it or reject the |
365 | | - * connection (depending on where it's invalid). No message or anything. |
366 | | - * We need to fix that some day. |
| 348 | + * host "raddr", user "user", to database "database". If found, |
| 349 | + * return *hba_ok_p = true and *userauth_p and *auth_arg representing |
| 350 | + * the contents of that entry. If there is no matching entry, we |
| 351 | + * set *hba_ok_p = true, *userauth_p = uaReject. |
367 | 352 | * |
368 | | - * If we don't find or can't access the config file, we issue an error |
369 | | - * message and deny the connection. |
| 353 | + * If the config file is unreadable or contains invalid syntax, we |
| 354 | + * issue a diagnostic message to stderr (ie, the postmaster log file) |
| 355 | + * and return without changing *hba_ok_p. |
370 | 356 | * |
371 | 357 | * If we find a file by the old name of the config file (pg_hba), we issue |
372 | 358 | * an error message because it probably needs to be converted. He didn't |
373 | 359 | * follow directions and just installed his old hba file in the new database |
374 | 360 | * system. |
375 | | - * |
376 | 361 | */ |
377 | 362 |
|
378 | 363 | intfd, |
@@ -431,14 +416,13 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database, |
431 | 416 | } |
432 | 417 | else |
433 | 418 | { |
434 | | -process_open_config_file(file,raddr,user,database,host_ok_p, |
| 419 | +process_open_config_file(file,raddr,user,database,hba_ok_p, |
435 | 420 | userauth_p,auth_arg); |
436 | 421 | FreeFile(file); |
437 | 422 | } |
438 | 423 | pfree(conf_file); |
439 | 424 | } |
440 | 425 | pfree(old_conf_file); |
441 | | -return; |
442 | 426 | } |
443 | 427 |
|
444 | 428 |
|
@@ -1079,20 +1063,21 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir) |
1079 | 1063 |
|
1080 | 1064 | #endif |
1081 | 1065 |
|
1082 | | -externint |
| 1066 | +int |
1083 | 1067 | hba_getauthmethod(SockAddr*raddr,char*user,char*database, |
1084 | 1068 | char*auth_arg,UserAuth*auth_method) |
1085 | 1069 | { |
1086 | 1070 | /*--------------------------------------------------------------------------- |
1087 | 1071 | Determine what authentication method should be used when accessing database |
1088 | | - "database" from frontend "raddr". Return the method, an optional argument, |
1089 | | - and STATUS_OK. |
| 1072 | + "database" from frontend "raddr", user "user". Return the method, |
| 1073 | + an optional argument, and STATUS_OK. |
| 1074 | + Note that STATUS_ERROR indicates a problem with the hba config file. |
| 1075 | + If the file is OK but does not contain any entry matching the request, |
| 1076 | + we return STATUS_OK and method = uaReject. |
1090 | 1077 | ----------------------------------------------------------------------------*/ |
1091 | | -boolhost_ok; |
1092 | | - |
1093 | | -host_ok= false; |
| 1078 | +boolhba_ok= false; |
1094 | 1079 |
|
1095 | | -find_hba_entry(raddr,user,database,&host_ok,auth_method,auth_arg); |
| 1080 | +find_hba_entry(raddr,user,database,&hba_ok,auth_method,auth_arg); |
1096 | 1081 |
|
1097 | | -returnhost_ok ?STATUS_OK :STATUS_ERROR; |
| 1082 | +returnhba_ok ?STATUS_OK :STATUS_ERROR; |
1098 | 1083 | } |