1010 *
1111 *
1212 * IDENTIFICATION
13- * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.95 2003/03/20 03:34:55 momjian Exp $
13+ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.96 2003/04/03 21:25:02 tgl Exp $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -387,7 +387,7 @@ get_group_line(const char *group)
387387/*
388388 * Lookup a user name in the pg_shadow file
389389 */
390- List * *
390+ List * *
391391get_user_line (const char * user )
392392{
393393return (List * * )bsearch ((void * )user ,
@@ -401,7 +401,7 @@ get_user_line(const char *user)
401401/*
402402 * Check group for a specific user.
403403 */
404- static int
404+ static bool
405405check_group (char * group ,char * user )
406406{
407407List * * line ,
@@ -411,16 +411,16 @@ check_group(char *group, char *user)
411411{
412412foreach (l ,lnext (lnext (* line )))
413413if (strcmp (lfirst (l ),user )== 0 )
414- return 1 ;
414+ return true ;
415415}
416416
417- return 0 ;
417+ return false ;
418418}
419419
420420/*
421421 * Check comma user list for a specific user, handle group names.
422422 */
423- static int
423+ static bool
424424check_user (char * user ,char * param_str )
425425{
426426char * tok ;
@@ -430,42 +430,42 @@ check_user(char *user, char *param_str)
430430if (tok [0 ]== '+' )
431431{
432432if (check_group (tok + 1 ,user ))
433- return 1 ;
433+ return true ;
434434}
435435else if (strcmp (tok ,user )== 0 ||
436436strcmp (tok ,"all" )== 0 )
437- return 1 ;
437+ return true ;
438438}
439439
440- return 0 ;
440+ return false ;
441441}
442442
443443/*
444444 * Check to see if db/user combination matches param string.
445445 */
446- static int
446+ static bool
447447check_db (char * dbname ,char * user ,char * param_str )
448448{
449449char * tok ;
450450
451451for (tok = strtok (param_str ,MULTI_VALUE_SEP );tok != NULL ;tok = strtok (NULL ,MULTI_VALUE_SEP ))
452452{
453453if (strcmp (tok ,"all" )== 0 )
454- return 1 ;
454+ return true ;
455455else if (strcmp (tok ,"sameuser" )== 0 )
456456{
457457if (strcmp (dbname ,user )== 0 )
458- return 1 ;
458+ return true ;
459459}
460460else if (strcmp (tok ,"samegroup" )== 0 )
461461{
462462if (check_group (dbname ,user ))
463- return 1 ;
463+ return true ;
464464}
465465else if (strcmp (tok ,dbname )== 0 )
466- return 1 ;
466+ return true ;
467467}
468- return 0 ;
468+ return false ;
469469}
470470
471471
@@ -752,13 +752,18 @@ user_openfile(void)
752752 * Load group/user name mapping file
753753 */
754754void
755- load_group ()
755+ load_group (void )
756756{
757757FILE * group_file ;
758758List * line ;
759759
760+ /* Discard any old data */
760761if (group_lines )
761762free_lines (& group_lines );
763+ if (group_sorted )
764+ pfree (group_sorted );
765+ group_sorted = NULL ;
766+ group_length = 0 ;
762767
763768group_file = group_openfile ();
764769if (!group_file )
@@ -767,8 +772,6 @@ load_group()
767772FreeFile (group_file );
768773
769774/* create sorted lines for binary searching */
770- if (group_sorted )
771- pfree (group_sorted );
772775group_length = length (group_lines );
773776if (group_length )
774777{
@@ -779,24 +782,30 @@ load_group()
779782foreach (line ,group_lines )
780783group_sorted [i ++ ]= lfirst (line );
781784
782- qsort ((void * )group_sorted ,group_length ,sizeof (List * ),user_group_qsort_cmp );
785+ qsort ((void * )group_sorted ,
786+ group_length ,
787+ sizeof (List * ),
788+ user_group_qsort_cmp );
783789}
784- else
785- group_sorted = NULL ;
786790}
787791
788792
789793/*
790794 * Load user/password mapping file
791795 */
792796void
793- load_user ()
797+ load_user (void )
794798{
795799FILE * user_file ;
796800List * line ;
797801
802+ /* Discard any old data */
798803if (user_lines )
799804free_lines (& user_lines );
805+ if (user_sorted )
806+ pfree (user_sorted );
807+ user_sorted = NULL ;
808+ user_length = 0 ;
800809
801810user_file = user_openfile ();
802811if (!user_file )
@@ -805,8 +814,6 @@ load_user()
805814FreeFile (user_file );
806815
807816/* create sorted lines for binary searching */
808- if (user_sorted )
809- pfree (user_sorted );
810817user_length = length (user_lines );
811818if (user_length )
812819{
@@ -817,10 +824,11 @@ load_user()
817824foreach (line ,user_lines )
818825user_sorted [i ++ ]= lfirst (line );
819826
820- qsort ((void * )user_sorted ,user_length ,sizeof (List * ),user_group_qsort_cmp );
827+ qsort ((void * )user_sorted ,
828+ user_length ,
829+ sizeof (List * ),
830+ user_group_qsort_cmp );
821831}
822- else
823- user_sorted = NULL ;
824832}
825833
826834
@@ -848,11 +856,9 @@ load_hba(void)
848856
849857file = AllocateFile (conf_file ,"r" );
850858if (file == NULL )
851- {
852859elog (FATAL ,
853860"load_hba: Unable to open authentication config file \"%s\": %m" ,
854861conf_file );
855- }
856862
857863hba_lines = tokenize_file (file );
858864FreeFile (file );