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 */
17 #include "user_list.h"
19 static struct list_head user_list;
22 * lookup user in user list file. Fills in a user struct containing
23 * filename of the user's public key as well as the permissions of that user.
24 * Returns 1 on success, 0 if user does not exist and < 0 on errors.
26 static void populate_user_list(char *user_list_file)
28 FILE *file_ptr = NULL;
31 /* keyword, user, key, perms */
32 char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
35 file_ptr = fopen(user_list_file, "r");
41 ret = para_fgets(line, MAXLINE, file_ptr);
43 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
46 if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
48 if (strcmp(w, "user"))
50 PARA_DEBUG_LOG("found entry for %s\n", n);
51 u = para_malloc(sizeof(struct user));
52 u->name = para_strdup(n);
53 ret = get_rsa_key(k, &u->rsa, LOAD_PUBLIC_KEY);
57 num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
58 tmp[0], tmp[1], tmp[2], tmp[3]);
59 PARA_DEBUG_LOG("found %i perm entries\n", num);
63 if (!strcmp(tmp[num], "VSS_READ"))
65 else if (!strcmp(tmp[num], "VSS_WRITE"))
66 u->perms |= VSS_WRITE;
67 else if (!strcmp(tmp[num], "AFS_READ"))
69 else if (!strcmp(tmp[num], "AFS_WRITE"))
70 u->perms |= AFS_WRITE;
71 else /* unknown permission */
72 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
75 para_list_add(&u->node, &user_list);
82 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
87 * initialize the list of users allowed to connecto to para_server
89 * \param user_list_file the file containing access information
91 * If this function is called a second time, the contents of the
92 * previous call are discarded.
94 void init_user_list(char *user_list_file)
97 static int initialized;
100 list_for_each_entry_safe(u, tmp, &user_list, node) {
107 INIT_LIST_HEAD(&user_list);
109 populate_user_list(user_list_file);
113 * lookup user in user_list.
115 * \param name of the user
117 * \return a pointer to the corresponding user struct if the user was found,
120 struct user *lookup_user(const char *name)
123 list_for_each_entry(u, &user_list, node) {
124 if (strcmp(u->name, name))