X-Git-Url: http://git.tuebingen.mpg.de/?p=adu.git;a=blobdiff_plain;f=user.c;h=ed16463afed9372426c5c08284a65ec863a19e2e;hp=bde47a7e79b87cc50d5813361d13cfc86746f272;hb=6744ce67f91c410f69de0763fb6faa01a8a53b28;hpb=c3dfa9a0c515bda90248b690e989e611c60f7e20 diff --git a/user.c b/user.c index bde47a7..ed16463 100644 --- a/user.c +++ b/user.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Andre Noll + * Copyright (C) 2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -10,7 +10,6 @@ #include /* readdir() */ #include #include -#include "cmdline.h" /* TODO: This file should be independent of command line options */ #include "user.h" #include "fd.h" #include "string.h" @@ -45,16 +44,13 @@ enum uid_info_flags { * * Even users that are not taken into account because of the --uid * option occupy a slot in this hash table. This allows to find out - * quicky whether a uid is admissible. And yes, this has to be fast. + * quickly whether a uid is admissible. And yes, this has to be fast. */ static struct user_info *uid_hash_table; /** This is always a power of two. It is set in create_hash_table(). */ static uint32_t uid_hash_table_size; -/* Array of indices to the entries of \a uid_hash_table. */ -static int *uid_hash_table_sort_idx; - /** The number of used slots in the hash table. */ static uint32_t num_uids; @@ -270,7 +266,7 @@ static int open_user_table(struct user_info *ui, int create) ui->desc->num_columns = NUM_UT_COLUMNS; ui->desc->flags = 0; ui->desc->column_descriptions = user_table_cols; - ui->desc->dir = adu_strdup(conf.database_dir_arg); + ui->desc->dir = adu_strdup(database_dir); ui->desc->name = make_message("%u", (unsigned)ui->uid); pw = getpwuid(ui->uid); if (pw && pw->pw_name) @@ -325,8 +321,7 @@ int for_each_admissible_user(int (*func)(struct user_info *, void *), assert(uid_hash_table); for (i = 0; i < uid_hash_table_size; i++) { int ret; - struct user_info *ui = uid_hash_table + - uid_hash_table_sort_idx[i]; + struct user_info *ui = uid_hash_table + i; if (!ui_used(ui) || !ui_admissible(ui)) continue; @@ -349,14 +344,9 @@ int for_each_admissible_user(int (*func)(struct user_info *, void *), */ void create_hash_table(unsigned bits) { - int i; - uid_hash_table_size = 1 << bits; uid_hash_table = adu_calloc(uid_hash_table_size * sizeof(struct user_info)); - uid_hash_table_sort_idx = adu_malloc(uid_hash_table_size * sizeof(int)); - for (i = 0; i < uid_hash_table_size; i++) - uid_hash_table_sort_idx[i] = i; } /** @@ -394,8 +384,6 @@ void close_user_tables(void) } free(uid_hash_table); uid_hash_table = NULL; - free(uid_hash_table_sort_idx); - uid_hash_table_sort_idx = NULL; } /* @@ -463,34 +451,8 @@ int create_user_table(uint32_t uid, struct user_info **ui_ptr) static char *get_uid_list_name(void) { - return make_message("%s/uid_list", conf.database_dir_arg); + return make_message("%s/uid_list", database_dir); } - -static int (*hash_table_comparator)(struct user_info *a, struct user_info *b); - -static int comp_wrapper(const void *a, const void *b) -{ - struct user_info *x = uid_hash_table + *(unsigned *)a; - struct user_info *y = uid_hash_table + *(unsigned *)b; - return hash_table_comparator(x, y); -} - -/** - * Sort the hash table according to a given comparator. - * - * \param comp The comparator. - * - * The comparator is a user-defined function which must return 1, 0, or -1. - * - * \sa qsort(3). - */ -void sort_hash_table(int (*comp)(struct user_info *, struct user_info *)) -{ - hash_table_comparator = comp; - qsort(uid_hash_table_sort_idx, uid_hash_table_size, - sizeof(*uid_hash_table_sort_idx), comp_wrapper); -} - /** * Open the osl tables for all admissible uids. * @@ -504,7 +466,7 @@ void sort_hash_table(int (*comp)(struct user_info *, struct user_info *)) * \a admissible_uids. If so, it sets the admissible bit for this slot and * opens the osl table of the uid. * - * \return Stamdard. + * \return Standard. */ int open_admissible_user_tables(struct uid_range *admissible_uids) { @@ -549,7 +511,7 @@ int read_uid_file(void) size_t size; uint32_t n; char *filename = get_uid_list_name(), *map; - int ret = mmap_full_file(filename, O_RDONLY, (void **)&map, &size, NULL); + int ret = mmap_file_ro(filename, (void **)&map, &size); unsigned bits; if (ret < 0) {