2 * Copyright (C) 2006-2008 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. */
17 #include "user_list.h"
19 static struct list_head user_list
;
22 * Fill the list of users known to para_server.
24 * Populates a linked list of all users in \a user_list_file. Returns on
25 * success, calls exit() on errors.
27 static void populate_user_list(char *user_list_file
)
29 int ret
= -E_USERLIST
;
30 FILE *file_ptr
= fopen(user_list_file
, "r");
37 /* keyword, name, key, perms */
38 char w
[255], n
[255], k
[255], p
[255], tmp
[4][255];
42 ret
= para_fgets(line
, MAXLINE
, file_ptr
);
45 if (sscanf(line
,"%200s %200s %200s %200s", w
, n
, k
, p
) < 3)
47 if (strcmp(w
, "user"))
49 PARA_DEBUG_LOG("found entry for user %s\n", n
);
50 ret
= get_rsa_key(k
, &rsa
, LOAD_PUBLIC_KEY
);
52 PARA_NOTICE_LOG("skipping entry for user %s: %s\n", n
,
56 u
= para_malloc(sizeof(*u
));
57 u
->name
= para_strdup(n
);
60 num
= sscanf(p
, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
61 tmp
[0], tmp
[1], tmp
[2], tmp
[3]);
62 PARA_DEBUG_LOG("found %i perm entries\n", num
);
65 if (!strcmp(tmp
[num
], "VSS_READ"))
67 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
68 u
->perms
|= VSS_WRITE
;
69 else if (!strcmp(tmp
[num
], "AFS_READ"))
71 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
72 u
->perms
|= AFS_WRITE
;
73 else /* unknown permission */
74 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
77 para_list_add(&u
->node
, &user_list
);
83 PARA_EMERG_LOG("%s\n", para_strerror(-ret
));
88 * Initialize the list of users allowed to connect to to para_server.
90 * \param user_list_file The file containing access information.
92 * If this function is called for the second time, the contents of the
93 * previous call are discarded, i.e. the user list is reloaded.
95 void init_user_list(char *user_list_file
)
98 static int initialized
;
101 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
108 INIT_LIST_HEAD(&user_list
);
110 populate_user_list(user_list_file
);
114 * Lookup a user in the user list.
116 * \param name The name of the user.
118 * \return A pointer to the corresponding user struct if the user was found, \p
121 struct user
*lookup_user(const char *name
)
124 list_for_each_entry(u
, &user_list
, node
) {
125 if (strcmp(u
->name
, name
))