2 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file user_list.c user handling for para_server */
25 #include "user_list.h"
27 static struct list_head user_list;
30 * lookup user in user list file. Fills in a user struct containing
31 * filename of the user's public key as well as the permissions of that user.
32 * Returns 1 on success, 0 if user does not exist and < 0 on errors.
34 static void populate_user_list(char *user_list_file)
36 FILE *file_ptr = NULL;
39 /* keyword, user, key, perms */
40 char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
43 file_ptr = fopen(user_list_file, "r");
49 ret = para_fgets(line, MAXLINE, file_ptr);
51 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
54 if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
56 if (strcmp(w, "user"))
58 PARA_DEBUG_LOG("found entry for %s\n", n);
59 u = para_malloc(sizeof(struct user));
60 u->name = para_strdup(n);
61 u->rsa = para_malloc(sizeof(RSA));
62 ret = get_rsa_key(k, &u->rsa, LOAD_PUBLIC_KEY);
67 num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
68 tmp[0], tmp[1], tmp[2], tmp[3]);
69 PARA_DEBUG_LOG("found %i perm entries\n", num);
73 if (!strcmp(tmp[num], "VSS_READ"))
75 else if (!strcmp(tmp[num], "VSS_WRITE"))
76 u->perms |= VSS_WRITE;
77 else if (!strcmp(tmp[num], "DB_READ"))
79 else if (!strcmp(tmp[num], "DB_WRITE"))
81 else /* unknown permission */
82 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
85 para_list_add(&u->node, &user_list);
92 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
96 void init_user_list(char *user_list_file)
99 static int initialized;
102 list_for_each_entry_safe(u, tmp, &user_list, node) {
109 INIT_LIST_HEAD(&user_list);
111 populate_user_list(user_list_file);
115 * lookup user in user_list.
117 * \param user: must initially contain the name of the user and is filled
118 * in by this function on success.
120 * \return 1 on success and < 0 on errors.
122 int lookup_user(struct user *user)
125 list_for_each_entry(u, &user_list, node) {
126 if (strcmp(u->name, user->name))