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. */
10 #include <sys/types.h>
12 #include <openssl/rc4.h>
20 #include "user_list.h"
23 static struct list_head user_list
;
26 * Fill the list of users known to para_server.
28 * Populates a linked list of all users in \a user_list_file. Returns on
29 * success, calls exit() on errors.
31 static void populate_user_list(char *user_list_file
)
33 int ret
= -E_USERLIST
;
34 FILE *file_ptr
= fopen(user_list_file
, "r");
41 /* keyword, name, key, perms */
42 char w
[255], n
[255], k
[255], p
[255], tmp
[4][255];
46 ret
= para_fgets(line
, MAXLINE
, file_ptr
);
49 if (sscanf(line
,"%200s %200s %200s %200s", w
, n
, k
, p
) < 3)
51 if (strcmp(w
, "user"))
53 PARA_DEBUG_LOG("found entry for user %s\n", n
);
54 ret
= get_rsa_key(k
, &rsa
, LOAD_PUBLIC_KEY
);
56 PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n
,
61 * In order to encrypt len := CHALLENGE_SIZE + 2 * RC4_KEY_LEN
62 * bytes using RSA_public_encrypt() with EME-OAEP padding mode,
63 * RSA_size(rsa) must be greater than len + 41. So ignore keys
64 * which are too short. For details see RSA_public_encrypt(3).
66 if (ret
<= CHALLENGE_SIZE
+ 2 * RC4_KEY_LEN
+ 41) {
67 PARA_WARNING_LOG("rsa key %s too short (%d)\n",
72 u
= para_malloc(sizeof(*u
));
73 u
->name
= para_strdup(n
);
76 num
= sscanf(p
, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
77 tmp
[0], tmp
[1], tmp
[2], tmp
[3]);
78 PARA_DEBUG_LOG("found %i perm entries\n", num
);
81 if (!strcmp(tmp
[num
], "VSS_READ"))
83 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
84 u
->perms
|= VSS_WRITE
;
85 else if (!strcmp(tmp
[num
], "AFS_READ"))
87 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
88 u
->perms
|= AFS_WRITE
;
89 else /* unknown permission */
90 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
93 para_list_add(&u
->node
, &user_list
);
99 PARA_EMERG_LOG("%s\n", para_strerror(-ret
));
104 * Initialize the list of users allowed to connect to to para_server.
106 * \param user_list_file The file containing access information.
108 * If this function is called for the second time, the contents of the
109 * previous call are discarded, i.e. the user list is reloaded.
111 void init_user_list(char *user_list_file
)
113 struct user
*u
, *tmp
;
114 static int initialized
;
117 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
124 INIT_LIST_HEAD(&user_list
);
126 populate_user_list(user_list_file
);
130 * Lookup a user in the user list.
132 * \param name The name of the user.
134 * \return A pointer to the corresponding user struct if the user was found, \p
137 struct user
*lookup_user(const char *name
)
140 list_for_each_entry(u
, &user_list
, node
) {
141 if (strcmp(u
->name
, name
))