X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=user_list.c;h=8c54ab7f78cc150a236d7231283d3b5279d9e3fc;hb=7c305178150d5adb4b566e11f1a4bc2e5fe91c8e;hp=525a47dfac7ce6705859836c67998cf3e9358107;hpb=63c513602a6b6a97cdced053beea0b2d07a9f984;p=paraslash.git diff --git a/user_list.c b/user_list.c index 525a47df..8c54ab7f 100644 --- a/user_list.c +++ b/user_list.c @@ -1,15 +1,9 @@ -/* - * Copyright (C) 2006-2009 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. */ #include #include -#include -#include #include "para.h" #include "error.h" @@ -18,9 +12,8 @@ #include "string.h" #include "list.h" #include "user_list.h" -#include "rc4.h" -static struct list_head user_list; +INITIALIZED_LIST_HEAD(user_list); /* * Fill the list of users known to para_server. @@ -28,7 +21,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"); @@ -41,7 +34,7 @@ static void populate_user_list(char *user_list_file) /* keyword, name, key, perms */ char w[255], n[255], k[255], p[255], tmp[4][255]; struct user *u; - RSA *rsa; + struct asymmetric_key *pubkey; ret = para_fgets(line, sizeof(line), file_ptr); if (ret <= 0) @@ -51,27 +44,27 @@ 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_rsa_key(k, &rsa, LOAD_PUBLIC_KEY); + ret = get_public_key(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 * RC4_KEY_LEN + * In order to encrypt len := 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 * RC4_KEY_LEN + 41) { - PARA_WARNING_LOG("rsa key %s too short (%d)\n", + if (ret <= CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) { + PARA_WARNING_LOG("public key %s too short (%d)\n", k, ret); - rsa_free(rsa); + free_public_key(pubkey); continue; } u = para_malloc(sizeof(*u)); u->name = para_strdup(n); - u->rsa = rsa; + u->pubkey = pubkey; u->perms = 0; num = sscanf(p, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]", tmp[0], tmp[1], tmp[2], tmp[3]); @@ -101,29 +94,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); - rsa_free(u->rsa); - 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); } /** @@ -134,9 +122,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;