2 * Copyright (C) 2006-2009 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. */
11 #include <openssl/rc4.h>
19 #include "user_list.h"
21 static struct list_head user_list
;
24 * Fill the list of users known to para_server.
26 * Populates a linked list of all users in \a user_list_file. Returns on
27 * success, calls exit() on errors.
29 static void populate_user_list(char *user_list_file
)
31 int ret
= -E_USERLIST
;
32 FILE *file_ptr
= fopen(user_list_file
, "r");
39 /* keyword, name, key, perms */
40 char w
[255], n
[255], k
[255], p
[255], tmp
[4][255];
44 ret
= para_fgets(line
, MAXLINE
, file_ptr
);
47 if (sscanf(line
,"%200s %200s %200s %200s", w
, n
, k
, p
) < 3)
49 if (strcmp(w
, "user"))
51 PARA_DEBUG_LOG("found entry for user %s\n", n
);
52 ret
= get_rsa_key(k
, &rsa
, LOAD_PUBLIC_KEY
);
54 PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n
,
58 if (ret
< CHALLENGE_SIZE
+ 2 * CHALLENGE_SIZE
+ 41) {
59 PARA_WARNING_LOG("rsa key for %s too small\n", n
);
63 u
= para_malloc(sizeof(*u
));
64 u
->name
= para_strdup(n
);
67 num
= sscanf(p
, "%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
);
72 if (!strcmp(tmp
[num
], "VSS_READ"))
74 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
75 u
->perms
|= VSS_WRITE
;
76 else if (!strcmp(tmp
[num
], "AFS_READ"))
78 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
79 u
->perms
|= AFS_WRITE
;
80 else /* unknown permission */
81 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
84 para_list_add(&u
->node
, &user_list
);
90 PARA_EMERG_LOG("%s\n", para_strerror(-ret
));
95 * Initialize the list of users allowed to connect to to para_server.
97 * \param user_list_file The file containing access information.
99 * If this function is called for the second time, the contents of the
100 * previous call are discarded, i.e. the user list is reloaded.
102 void init_user_list(char *user_list_file
)
104 struct user
*u
, *tmp
;
105 static int initialized
;
108 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
115 INIT_LIST_HEAD(&user_list
);
117 populate_user_list(user_list_file
);
121 * Lookup a user in the user list.
123 * \param name The name of the user.
125 * \return A pointer to the corresponding user struct if the user was found, \p
128 struct user
*lookup_user(const char *name
)
131 list_for_each_entry(u
, &user_list
, node
) {
132 if (strcmp(u
->name
, name
))