9db08715348f2e7df954d5371a106e4b5b347d40
1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file user_list.c User handling for para_server. */
14 #include "user_list.h"
16 static struct list_head user_list
;
19 * Fill the list of users known to para_server.
21 * Populates a linked list of all users in \a user_list_file. Returns on
22 * success, calls exit() on errors.
24 static void populate_user_list(char *user_list_file
)
26 int ret
= -E_USERLIST
;
27 FILE *file_ptr
= fopen(user_list_file
, "r");
34 /* keyword, name, key, perms */
35 char w
[255], n
[255], k
[255], p
[255], tmp
[4][255];
37 struct asymmetric_key
*pubkey
;
39 ret
= para_fgets(line
, sizeof(line
), file_ptr
);
42 if (sscanf(line
,"%200s %200s %200s %200s", w
, n
, k
, p
) < 3)
44 if (strcmp(w
, "user"))
46 PARA_DEBUG_LOG("found entry for user %s\n", n
);
47 ret
= apc_get_pubkey(k
, &pubkey
);
49 PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n
,
54 * In order to encrypt len := APC_CHALLENGE_SIZE + 2 * SESSION_KEY_LEN
55 * bytes using RSA_public_encrypt() with EME-OAEP padding mode,
56 * RSA_size(rsa) must be greater than len + 41. So ignore keys
57 * which are too short. For details see RSA_public_encrypt(3).
59 if (ret
<= APC_CHALLENGE_SIZE
+ 2 * SESSION_KEY_LEN
+ 41) {
60 PARA_WARNING_LOG("public key %s too short (%d)\n",
62 apc_free_pubkey(pubkey
);
65 u
= para_malloc(sizeof(*u
));
66 u
->name
= para_strdup(n
);
69 num
= sscanf(p
, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
70 tmp
[0], tmp
[1], tmp
[2], tmp
[3]);
71 PARA_DEBUG_LOG("found %i perm entries\n", num
);
74 if (!strcmp(tmp
[num
], "VSS_READ"))
76 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
77 u
->perms
|= VSS_WRITE
;
78 else if (!strcmp(tmp
[num
], "AFS_READ"))
80 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
81 u
->perms
|= AFS_WRITE
;
82 else /* unknown permission */
83 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
86 para_list_add(&u
->node
, &user_list
);
92 PARA_EMERG_LOG("%s\n", para_strerror(-ret
));
97 * Initialize the list of users allowed to connect to para_server.
99 * \param user_list_file The file containing access information.
101 * If this function is called for the second time, the contents of the
102 * previous call are discarded, i.e. the user list is reloaded.
104 void init_user_list(char *user_list_file
)
106 struct user
*u
, *tmp
;
107 static int initialized
;
110 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
113 apc_free_pubkey(u
->pubkey
);
117 INIT_LIST_HEAD(&user_list
);
119 populate_user_list(user_list_file
);
123 * Lookup a user in the user list.
125 * \param name The name of the user.
127 * \return A pointer to the corresponding user struct if the user was found, \p
130 struct user
*lookup_user(const char *name
)
133 list_for_each_entry(u
, &user_list
, node
) {
134 if (strcmp(u
->name
, name
))