2 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file user_list.c user handling for para_server */
14 #include "user_list.h"
16 static struct list_head user_list;
19 * lookup user in user list file. Fills in a user struct containing
20 * filename of the user's public key as well as the permissions of that user.
21 * Returns 1 on success, 0 if user does not exist and < 0 on errors.
23 static void populate_user_list(char *user_list_file)
25 FILE *file_ptr = NULL;
28 /* keyword, user, key, perms */
29 char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
32 file_ptr = fopen(user_list_file, "r");
38 ret = para_fgets(line, MAXLINE, file_ptr);
40 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
43 if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
45 if (strcmp(w, "user"))
47 PARA_DEBUG_LOG("found entry for %s\n", n);
48 u = para_malloc(sizeof(struct user));
49 u->name = para_strdup(n);
50 ret = get_rsa_key(k, &u->rsa, LOAD_PUBLIC_KEY);
54 num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
55 tmp[0], tmp[1], tmp[2], tmp[3]);
56 PARA_DEBUG_LOG("found %i perm entries\n", num);
60 if (!strcmp(tmp[num], "VSS_READ"))
62 else if (!strcmp(tmp[num], "VSS_WRITE"))
63 u->perms |= VSS_WRITE;
64 else if (!strcmp(tmp[num], "AFS_READ"))
66 else if (!strcmp(tmp[num], "AFS_WRITE"))
67 u->perms |= AFS_WRITE;
68 else /* unknown permission */
69 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
72 para_list_add(&u->node, &user_list);
79 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
84 * initialize the list of users allowed to connecto to para_server
86 * \param user_list_file the file containing access information
88 * If this function is called a second time, the contents of the
89 * previous call are discarded.
91 void init_user_list(char *user_list_file)
94 static int initialized;
97 list_for_each_entry_safe(u, tmp, &user_list, node) {
104 INIT_LIST_HEAD(&user_list);
106 populate_user_list(user_list_file);
110 * lookup user in user_list.
112 * \param name of the user
114 * \return a pointer to the corresponding user struct if the user was found,
117 struct user *lookup_user(const char *name)
120 list_for_each_entry(u, &user_list, node) {
121 if (strcmp(u->name, name))