X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=user_list.c;h=dfd8248c7f21940d7a94b9fe79442f02693a070a;hp=9c751244339c34197d52229b75b4d55e5a58a43f;hb=6a2dbfdb87b3036085ce664a847fc9eb419f65d4;hpb=642445e95fea1c548c79f80ad3b5d6f30ba572f3 diff --git a/user_list.c b/user_list.c index 9c751244..dfd8248c 100644 --- a/user_list.c +++ b/user_list.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2006 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2006 Andre Noll , see file COPYING. */ /** \file user_list.c User handling for para_server. */ @@ -17,7 +13,31 @@ #include "list.h" #include "user_list.h" -static struct list_head user_list; +INITIALIZED_LIST_HEAD(user_list); + +/* + * Wrapper for fgets(3). + * + * Unlike fgets(3), an integer value is returned. On success, this function + * returns 1. On errors, -E_FGETS is returned. A zero return value indicates an + * end of file condition. + */ +static int xfgets(char *line, int size, FILE *f) +{ +again: + if (fgets(line, size, f)) + return 1; + if (feof(f)) + return 0; + if (!ferror(f)) + return -E_FGETS; + if (errno != EINTR) { + PARA_ERROR_LOG("%s\n", strerror(errno)); + return -E_FGETS; + } + clearerr(f); + goto again; +} /* * Fill the list of users known to para_server. @@ -25,7 +45,7 @@ static struct list_head user_list; * Populates a linked list of all users in \a user_list_file. Returns on * success, calls exit() on errors. */ -static void populate_user_list(char *user_list_file) +static void populate(char *user_list_file) { int ret = -E_USERLIST; FILE *file_ptr = fopen(user_list_file, "r"); @@ -40,7 +60,7 @@ static void populate_user_list(char *user_list_file) struct user *u; struct asymmetric_key *pubkey; - ret = para_fgets(line, sizeof(line), file_ptr); + ret = xfgets(line, sizeof(line), file_ptr); if (ret <= 0) break; if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3) @@ -48,7 +68,7 @@ static void populate_user_list(char *user_list_file) if (strcmp(w, "user")) continue; PARA_DEBUG_LOG("found entry for user %s\n", n); - ret = get_asymmetric_key(k, LOAD_PUBLIC_KEY, &pubkey); + ret = get_public_key(k, &pubkey); if (ret < 0) { PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n, para_strerror(-ret)); @@ -63,7 +83,7 @@ static void populate_user_list(char *user_list_file) if (ret <= CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) { PARA_WARNING_LOG("public key %s too short (%d)\n", k, ret); - free_asymmetric_key(pubkey); + free_public_key(pubkey); continue; } u = para_malloc(sizeof(*u)); @@ -98,29 +118,24 @@ err: } /** - * Initialize the list of users allowed to connect to to para_server. + * Initialize the list of users allowed to connect to para_server. * * \param user_list_file The file containing access information. * * If this function is called for the second time, the contents of the * previous call are discarded, i.e. the user list is reloaded. */ -void init_user_list(char *user_list_file) +void user_list_init(char *user_list_file) { struct user *u, *tmp; - static int initialized; - if (initialized) { - list_for_each_entry_safe(u, tmp, &user_list, node) { - list_del(&u->node); - free(u->name); - free_asymmetric_key(u->pubkey); - free(u); - } - } else - INIT_LIST_HEAD(&user_list); - initialized = 1; - populate_user_list(user_list_file); + list_for_each_entry_safe(u, tmp, &user_list, node) { + list_del(&u->node); + free(u->name); + free_public_key(u->pubkey); + free(u); + } + populate(user_list_file); } /** @@ -131,9 +146,9 @@ void init_user_list(char *user_list_file) * \return A pointer to the corresponding user struct if the user was found, \p * NULL otherwise. */ -struct user *lookup_user(const char *name) +const struct user *user_list_lookup(const char *name) { - struct user *u; + const struct user *u; list_for_each_entry(u, &user_list, node) { if (strcmp(u->name, name)) continue;