X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=user_list.c;h=32a4309d4360fa73a8e7d0bbef622a7928001bb0;hp=dfd8248c7f21940d7a94b9fe79442f02693a070a;hb=cb2bcdde7424805b9f62c152ec6dd2a1c4a68a97;hpb=6a2dbfdb87b3036085ce664a847fc9eb419f65d4 diff --git a/user_list.c b/user_list.c index dfd8248c..32a4309d 100644 --- a/user_list.c +++ b/user_list.c @@ -13,7 +13,7 @@ #include "list.h" #include "user_list.h" -INITIALIZED_LIST_HEAD(user_list); +static INITIALIZED_LIST_HEAD(user_list); /* * Wrapper for fgets(3). @@ -39,25 +39,49 @@ again: goto again; } -/* - * Fill the list of users known to para_server. +/** + * Remove all entries from the user list. + * + * This is called on shutdown and when the user list is reloaded because the + * server received SIGHUP. + */ +void user_list_deplete(void) +{ + struct user *u, *tmpu; + + list_for_each_entry_safe(u, tmpu, &user_list, node) { + list_del(&u->node); + free(u->name); + apc_free_pubkey(u->pubkey); + free(u); + } +} + +/** + * 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. * - * Populates a linked list of all users in \a user_list_file. Returns on - * success, calls exit() on errors. + * This function either succeeds or calls exit(3). */ -static void populate(char *user_list_file) +void user_list_init(const char *user_list_file) { int ret = -E_USERLIST; FILE *file_ptr = fopen(user_list_file, "r"); + struct user *u; if (!file_ptr) goto err; + + user_list_deplete(); for (;;) { int num; char line[255]; /* keyword, name, key, perms */ char w[255], n[255], k[255], p[255], tmp[4][255]; - struct user *u; struct asymmetric_key *pubkey; ret = xfgets(line, sizeof(line), file_ptr); @@ -68,22 +92,22 @@ static void populate(char *user_list_file) if (strcmp(w, "user")) continue; PARA_DEBUG_LOG("found entry for user %s\n", n); - ret = get_public_key(k, &pubkey); + ret = apc_get_pubkey(k, &pubkey); if (ret < 0) { PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n, para_strerror(-ret)); continue; } /* - * In order to encrypt len := CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + * In order to encrypt len := APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN * bytes using RSA_public_encrypt() with EME-OAEP padding mode, * RSA_size(rsa) must be greater than len + 41. So ignore keys * which are too short. For details see RSA_public_encrypt(3). */ - if (ret <= CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) { + if (ret <= APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) { PARA_WARNING_LOG("public key %s too short (%d)\n", k, ret); - free_public_key(pubkey); + apc_free_pubkey(pubkey); continue; } u = para_malloc(sizeof(*u)); @@ -117,27 +141,6 @@ err: exit(EXIT_FAILURE); } -/** - * 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 user_list_init(char *user_list_file) -{ - struct user *u, *tmp; - - 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); -} - /** * Lookup a user in the user list. *