Commit ea43fec2 authored by Bruce Momjian's avatar Bruce Momjian

Fix problem with new pg_hba.conf code where the same comparison function

was incorrectly used for both qsort and bsearch.
parent 6c598869
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.82 2002/04/25 00:56:36 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.83 2002/04/28 22:49:07 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -335,21 +335,36 @@ tokenize_file(FILE *file) ...@@ -335,21 +335,36 @@ tokenize_file(FILE *file)
/* /*
* Compare two password-file lines on the basis of their user names. * Compare two lines based on their user/group names.
* *
* Used for qsort() sorting and bsearch() lookup. * Used for qsort() sorting.
*/ */
static int static int
user_group_cmp(const void *user, const void *list) user_group_qsort_cmp(const void *list1, const void *list2)
{ {
/* first node is line number */ /* first node is line number */
char *user1 = (char *)user; char *user1 = lfirst(lnext(*(List **)list1));
char *user2 = lfirst(lnext(*(List **)list)); char *user2 = lfirst(lnext(*(List **)list2));
return strcmp(user1, user2); return strcmp(user1, user2);
} }
/*
* Compare two lines based on their user/group names.
*
* Used for bsearch() lookup.
*/
static int
user_group_bsearch_cmp(const void *user, const void *list)
{
/* first node is line number */
char *user2 = lfirst(lnext(*(List **)list));
return strcmp(user, user2);
}
/* /*
* Lookup a group name in the pg_group file * Lookup a group name in the pg_group file
*/ */
...@@ -360,7 +375,7 @@ get_group_line(const char *group) ...@@ -360,7 +375,7 @@ get_group_line(const char *group)
(void *) group_sorted, (void *) group_sorted,
group_length, group_length,
sizeof(List *), sizeof(List *),
user_group_cmp); user_group_bsearch_cmp);
} }
...@@ -374,7 +389,7 @@ get_user_line(const char *user) ...@@ -374,7 +389,7 @@ get_user_line(const char *user)
(void *) user_sorted, (void *) user_sorted,
user_length, user_length,
sizeof(List *), sizeof(List *),
user_group_cmp); user_group_bsearch_cmp);
} }
...@@ -754,7 +769,7 @@ load_group() ...@@ -754,7 +769,7 @@ load_group()
foreach(line, group_lines) foreach(line, group_lines)
group_sorted[i++] = lfirst(line); group_sorted[i++] = lfirst(line);
qsort((void *) group_sorted, group_length, sizeof(List *), user_group_cmp); qsort((void *) group_sorted, group_length, sizeof(List *), user_group_qsort_cmp);
} }
else else
group_sorted = NULL; group_sorted = NULL;
...@@ -792,7 +807,7 @@ load_user() ...@@ -792,7 +807,7 @@ load_user()
foreach(line, user_lines) foreach(line, user_lines)
user_sorted[i++] = lfirst(line); user_sorted[i++] = lfirst(line);
qsort((void *) user_sorted, user_length, sizeof(List *), user_group_cmp); qsort((void *) user_sorted, user_length, sizeof(List *), user_group_qsort_cmp);
} }
else else
user_sorted = NULL; user_sorted = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment