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 INITIALIZED_LIST_HEAD(user_list);
19 * Wrapper for fgets(3).
21 * Unlike fgets(3), an integer value is returned. On success, this function
22 * returns 1. On errors, -E_FGETS is returned. A zero return value indicates an
23 * end of file condition.
25 static int xfgets(char *line, int size, FILE *f)
28 if (fgets(line, size, f))
35 PARA_ERROR_LOG("%s\n", strerror(errno));
43 * Initialize the list of users allowed to connect to para_server.
45 * \param user_list_file The file containing access information.
47 * If this function is called for the second time, the contents of the
48 * previous call are discarded, i.e. the user list is reloaded.
50 * This function either succeeds or calls exit(3).
52 void user_list_init(char *user_list_file)
54 int ret = -E_USERLIST;
55 FILE *file_ptr = fopen(user_list_file, "r");
56 struct user *u, *tmpu;
61 list_for_each_entry_safe(u, tmpu, &user_list, node) {
64 free_public_key(u->pubkey);
70 /* keyword, name, key, perms */
71 char w[255], n[255], k[255], p[255], tmp[4][255];
72 struct asymmetric_key *pubkey;
74 ret = xfgets(line, sizeof(line), file_ptr);
77 if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
79 if (strcmp(w, "user"))
81 PARA_DEBUG_LOG("found entry for user %s\n", n);
82 ret = get_public_key(k, &pubkey);
84 PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n,
89 * In order to encrypt len := CHALLENGE_SIZE + 2 * SESSION_KEY_LEN
90 * bytes using RSA_public_encrypt() with EME-OAEP padding mode,
91 * RSA_size(rsa) must be greater than len + 41. So ignore keys
92 * which are too short. For details see RSA_public_encrypt(3).
94 if (ret <= CHALLENGE_SIZE + 2 * SESSION_KEY_LEN + 41) {
95 PARA_WARNING_LOG("public key %s too short (%d)\n",
97 free_public_key(pubkey);
100 u = para_malloc(sizeof(*u));
101 u->name = para_strdup(n);
104 num = sscanf(p, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
105 tmp[0], tmp[1], tmp[2], tmp[3]);
106 PARA_DEBUG_LOG("found %i perm entries\n", num);
109 if (!strcmp(tmp[num], "VSS_READ"))
110 u->perms |= VSS_READ;
111 else if (!strcmp(tmp[num], "VSS_WRITE"))
112 u->perms |= VSS_WRITE;
113 else if (!strcmp(tmp[num], "AFS_READ"))
114 u->perms |= AFS_READ;
115 else if (!strcmp(tmp[num], "AFS_WRITE"))
116 u->perms |= AFS_WRITE;
117 else /* unknown permission */
118 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
121 para_list_add(&u->node, &user_list);
127 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
132 * Lookup a user in the user list.
134 * \param name The name of the user.
136 * \return A pointer to the corresponding user struct if the user was found, \p
139 const struct user *user_list_lookup(const char *name)
141 const struct user *u;
142 list_for_each_entry(u, &user_list, node) {
143 if (strcmp(u->name, name))