2 * Copyright (C) 2006-2007 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file user_list.c user handling for para_server */
25 #include "user_list.h"
27 static struct list_head user_list
;
30 * lookup user in user list file. Fills in a user struct containing
31 * filename of the user's public key as well as the permissions of that user.
32 * Returns 1 on success, 0 if user does not exist and < 0 on errors.
34 static void populate_user_list(char *user_list_file
)
36 FILE *file_ptr
= NULL
;
39 /* keyword, user, key, perms */
40 char w
[MAXLINE
], n
[MAXLINE
], k
[MAXLINE
], p
[MAXLINE
], tmp
[4][MAXLINE
];
43 file_ptr
= fopen(user_list_file
, "r");
49 ret
= para_fgets(line
, MAXLINE
, file_ptr
);
51 PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret
));
54 if (sscanf(line
,"%200s %200s %200s %200s", w
, n
, k
, p
) < 3)
56 if (strcmp(w
, "user"))
58 PARA_DEBUG_LOG("found entry for %s\n", n
);
59 u
= para_malloc(sizeof(struct user
));
60 u
->name
= para_strdup(n
);
61 ret
= get_rsa_key(k
, &u
->rsa
, LOAD_PUBLIC_KEY
);
65 num
= sscanf(char_ptr
, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
66 tmp
[0], tmp
[1], tmp
[2], tmp
[3]);
67 PARA_DEBUG_LOG("found %i perm entries\n", num
);
71 if (!strcmp(tmp
[num
], "VSS_READ"))
73 else if (!strcmp(tmp
[num
], "VSS_WRITE"))
74 u
->perms
|= VSS_WRITE
;
75 else if (!strcmp(tmp
[num
], "AFS_READ"))
77 else if (!strcmp(tmp
[num
], "AFS_WRITE"))
78 u
->perms
|= AFS_WRITE
;
79 else /* unknown permission */
80 PARA_WARNING_LOG("ignoring unknown permission: %s\n",
83 para_list_add(&u
->node
, &user_list
);
90 PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret
));
95 * initialize the list of users allowed to connecto to para_server
97 * \param user_list_file the file containing access information
99 * If this function is called a second time, the contents of the
100 * previous call are discarded.
102 void init_user_list(char *user_list_file
)
104 struct user
*u
, *tmp
;
105 static int initialized
;
108 list_for_each_entry_safe(u
, tmp
, &user_list
, node
) {
115 INIT_LIST_HEAD(&user_list
);
117 populate_user_list(user_list_file
);
121 * lookup user in user_list.
123 * \param name of the user
125 * \return a pointer to the corresponding user struct if the user was found,
128 struct user
*lookup_user(const char *name
)
131 list_for_each_entry(u
, &user_list
, node
) {
132 if (strcmp(u
->name
, name
))