2 * Copyright (C) 2006-2007 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 */
13 #include "user_list.h"
15 static struct list_head user_list
;
18 * lookup user in user list file. Fills in a user struct containing
19 * filename of the user's public key as well as the permissions of that user.
20 * Returns 1 on success, 0 if user does not exist and < 0 on errors.
22 static void populate_user_list(char *user_list_file
)
24 FILE *file_ptr
= NULL
;
27 /* keyword, user, key, perms */
28 char w
[MAXLINE
], n
[MAXLINE
], k
[MAXLINE
], p
[MAXLINE
], tmp
[4][MAXLINE
];
31 file_ptr
= fopen(user_list_file
, "r");
37 ret
= para_fgets(line
, MAXLINE
, file_ptr
);
39 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret
));
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 %s\n", n
);
47 u
= para_malloc(sizeof(struct user
));
48 u
->name
= para_strdup(n
);
49 ret
= get_rsa_key(k
, &u
->rsa
, LOAD_PUBLIC_KEY
);
53 num
= sscanf(char_ptr
, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
54 tmp
[0], tmp
[1], tmp
[2], tmp
[3]);
55 PARA_DEBUG_LOG("found %i perm entries\n", num
);
59 if (!strcmp(tmp
[num
], "VSS_READ"))
61 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
62 u
->perms
|= VSS_WRITE
;
63 else if (!strcmp(tmp
[num
], "AFS_READ"))
65 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
66 u
->perms
|= AFS_WRITE
;
67 else /* unknown permission */
68 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
71 para_list_add(&u
->node
, &user_list
);
78 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret
));
83 * initialize the list of users allowed to connecto to para_server
85 * \param user_list_file the file containing access information
87 * If this function is called a second time, the contents of the
88 * previous call are discarded.
90 void init_user_list(char *user_list_file
)
93 static int initialized
;
96 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
103 INIT_LIST_HEAD(&user_list
);
105 populate_user_list(user_list_file
);
109 * lookup user in user_list.
111 * \param name of the user
113 * \return a pointer to the corresponding user struct if the user was found,
116 struct user
*lookup_user(const char *name
)
119 list_for_each_entry(u
, &user_list
, node
) {
120 if (strcmp(u
->name
, name
))