]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
server: Combine user_list_init() and populate().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 13 Aug 2017 20:07:57 +0000 (22:07 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Mar 2018 02:28:56 +0000 (03:28 +0100)
The latter is only called by the former, and both are short enough.

user_list.c

index dfd8248c7f21940d7a94b9fe79442f02693a070a..a2b494936f3e8f4138b98c26e181d24638a29b04 100644 (file)
@@ -39,25 +39,36 @@ again:
        goto again;
 }
 
        goto again;
 }
 
-/*
- * Fill the list of users known to para_server.
+/**
+ * Initialize the list of users allowed to connect to para_server.
+ *
+ * \param user_list_file The file containing access information.
  *
  *
- * Populates a linked list of all users in \a user_list_file.  Returns on
- * success, calls exit() on errors.
+ * If this function is called for the second time, the contents of the
+ * previous call are discarded, i.e. the user list is reloaded.
+ *
+ * This function either succeeds or calls exit(3).
  */
  */
-static void populate(char *user_list_file)
+void user_list_init(char *user_list_file)
 {
        int ret = -E_USERLIST;
        FILE *file_ptr = fopen(user_list_file, "r");
 {
        int ret = -E_USERLIST;
        FILE *file_ptr = fopen(user_list_file, "r");
+       struct user *u, *tmpu;
 
        if (!file_ptr)
                goto err;
 
        if (!file_ptr)
                goto err;
+
+       list_for_each_entry_safe(u, tmpu, &user_list, node) {
+               list_del(&u->node);
+               free(u->name);
+               free_public_key(u->pubkey);
+               free(u);
+       }
        for (;;) {
                int num;
                char line[255];
                /* keyword, name, key, perms */
                char w[255], n[255], k[255], p[255], tmp[4][255];
        for (;;) {
                int num;
                char line[255];
                /* keyword, name, key, perms */
                char w[255], n[255], k[255], p[255], tmp[4][255];
-               struct user *u;
                struct asymmetric_key *pubkey;
 
                ret = xfgets(line, sizeof(line), file_ptr);
                struct asymmetric_key *pubkey;
 
                ret = xfgets(line, sizeof(line), file_ptr);
@@ -117,27 +128,6 @@ err:
        exit(EXIT_FAILURE);
 }
 
        exit(EXIT_FAILURE);
 }
 
-/**
- * Initialize the list of users allowed to connect to para_server.
- *
- * \param user_list_file The file containing access information.
- *
- * If this function is called for the second time, the contents of the
- * previous call are discarded, i.e. the user list is reloaded.
- */
-void user_list_init(char *user_list_file)
-{
-       struct user *u, *tmp;
-
-       list_for_each_entry_safe(u, tmp, &user_list, node) {
-               list_del(&u->node);
-               free(u->name);
-               free_public_key(u->pubkey);
-               free(u);
-       }
-       populate(user_list_file);
-}
-
 /**
  * Lookup a user in the user list.
  *
 /**
  * Lookup a user in the user list.
  *