-/*
- * lookup user in user_list file. Fills in a user struct containing
- * filename of the user's public key as well as the permissions of that user.
- * Returns 1 on success, 0 if user does not exist and < 0 on errors.
- */
-static void populate_user_list(void) {
- FILE *file_ptr = NULL;
- char *char_ptr;
- char line[MAXLINE];
- /* keyword, user, key, perms */
- char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
- int num, ret;
-
- file_ptr = fopen(user_list, "r");
- ret = -E_USERLIST;
- if (!file_ptr)
- goto out;
- for (;;) {
- struct _user *u;
- ret = para_fgets(line, MAXLINE, file_ptr);
- if (ret < 0)
- PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
- if (ret <= 0)
- break;
- if (sscanf(line,"%200s %200s %200s %200s", w, n, k, p) < 3)
- continue;
- if (strcmp(w, "user"))
- continue;
- PARA_DEBUG_LOG("found entry for %s\n", n);
- u = para_malloc(sizeof(struct _user));
- u->name = para_strdup(n);
- u->rsa = para_malloc(sizeof(RSA));
- ret = get_rsa_key(k, &u->rsa, 0 /* public */);
- if (ret < 0)
- break;
- u->perms = 0;
- char_ptr = p;
- num = sscanf(char_ptr, "%200[A-Z_],%200[A-Z_],%200[A-Z_],%200[A-Z_]",
- tmp[0], tmp[1], tmp[2], tmp[3]);
- PARA_DEBUG_LOG("found %i perm entries\n", num);
- u->perms = 0;
- while (num > 0) {
- num--;
- if (!strcmp(tmp[num], "AFS_READ"))
- u->perms |= AFS_READ;
- else if (!strcmp(tmp[num], "AFS_WRITE"))
- u->perms |= AFS_WRITE;
- else if (!strcmp(tmp[num], "DB_READ"))
- u->perms |= DB_READ;
- else if (!strcmp(tmp[num], "DB_WRITE"))
- u->perms |= DB_WRITE;
- else /* unknown permission */
- PARA_WARNING_LOG("unknown permission: %s\n",
- tmp[num]);