]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
simplify lookup_user()
authorAndre Noll <maan@systemlinux.org>
Sun, 11 Feb 2007 20:57:49 +0000 (21:57 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 11 Feb 2007 20:57:49 +0000 (21:57 +0100)
It's easier to just pass the name of the user to be looked up. This
fixes a memory leak btw. because u.name was strdupped and never freed.
That leak wasn't serious though as is happened in the child process.

command.c
error.h
user_list.c
user_list.h

index 6f6fad7c4028e0f10833cc30033402e126731d66..ffd660d63c0cdd94cd73d952a8785007873f1a97 100644 (file)
--- a/command.c
+++ b/command.c
@@ -793,7 +793,7 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        int numbytes, ret, argc, use_rc4 = 0;
        char buf[4096];
        unsigned char crypt_buf[MAXLINE];
-       struct user u;
+       struct user *u;
        struct server_command *cmd = NULL;
        long unsigned challenge_nr, chall_response;
        char **argv = NULL;
@@ -825,16 +825,18 @@ int handle_connect(int fd, struct sockaddr_in *addr)
                goto err_out;
 
        if (numbytes < 9 || strncmp(buf, "auth rc4 ", 9))
-               u.name = para_strdup(buf + 5); /* client version < 0.2.6 */
+               p = buf + 5; /* client version < 0.2.6 */
        else {
-               u.name = para_strdup(buf + 9); /* client version >= 0.2.6 */
+               p = buf + 9; /* client version >= 0.2.6 */
                use_rc4 = 1;
        }
        PARA_DEBUG_LOG("received %s request for user %s\n",
-               use_rc4? "rc4" : "auth", u.name);
-       if ((ret = lookup_user(&u)) < 0)
+               use_rc4? "rc4" : "auth", p);
+       ret = -E_BAD_USER;
+       u = lookup_user(p);
+       if (!u)
                goto err_out;
-       ret = para_encrypt_challenge(u.rsa, challenge_nr, crypt_buf);
+       ret = para_encrypt_challenge(u->rsa, challenge_nr, crypt_buf);
        if (ret <= 0)
                goto err_out;
        numbytes = ret;
@@ -855,11 +857,11 @@ int handle_connect(int fd, struct sockaddr_in *addr)
                        || chall_response != challenge_nr)
                goto err_out;
        /* auth successful. Send 'Proceed' message */
-       PARA_INFO_LOG("good auth for %s (%lu)\n", u.name, challenge_nr);
+       PARA_INFO_LOG("good auth for %s (%lu)\n", u->name, challenge_nr);
        sprintf(buf, "%s", PROCEED_MSG);
        if (use_rc4) {
                init_rc4_keys();
-               ret = para_encrypt_buffer(u.rsa, rc4_buf, 2 * RC4_KEY_LEN,
+               ret = para_encrypt_buffer(u->rsa, rc4_buf, 2 * RC4_KEY_LEN,
                        (unsigned char *)buf + PROCEED_MSG_LEN + 1);
                if (ret <= 0)
                        goto err_out;
@@ -891,7 +893,7 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        if (!(cmd = parse_cmd(command)))
                goto err_out;
        /* valid command, check permissions */
-       ret = check_perms(u.perms, cmd);
+       ret = check_perms(u->perms, cmd);
        if (ret < 0)
                goto err_out;
        /* valid command and sufficient perms */
@@ -900,7 +902,7 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        mmd_lock();
        mmd->num_commands++;
        mmd_unlock();
-       PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u.name,
+       PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name,
                inet_ntoa(addr->sin_addr));
        ret = cmd->handler(fd, argc, argv);
        if (ret >= 0) {
diff --git a/error.h b/error.h
index 34b18f193bef5dd4f8a54083cbb4c842ae3ed8be..b970947704dffb401097a5ebe4d88a8624ad423a 100644 (file)
--- a/error.h
+++ b/error.h
@@ -97,7 +97,6 @@ extern const char **para_errlist[];
 
 #define USER_LIST_ERRORS \
        PARA_ERROR(USERLIST, "failed to open user list file"), \
-       PARA_ERROR(BAD_USER, "you don't exist. Go away."), \
 
 
 #define OSX_WRITE_ERRORS \
@@ -203,6 +202,7 @@ extern const char **para_errlist[];
        PARA_ERROR(AUDIOD_SYNTAX, "syntax error"), \
        PARA_ERROR(UCRED_PERM, "permission denied"), \
        PARA_ERROR(INVALID_AUDIOD_CMD, "invalid command"), \
+       PARA_ERROR(BAD_USER, "you don't exist. Go away."), \
 
 
 #define FILTER_CHAIN_ERRORS \
index b7d739c130fc08d5d69c159be3c46d927f894df2..c6d45ca5f4b2846f7f5a6350a8e84b3c551539a7 100644 (file)
@@ -122,19 +122,18 @@ void init_user_list(char *user_list_file)
 /**
  * lookup user in user_list.
  *
- * \param user: must initially contain the name of the user and is filled
- * in by this function on success.
+ * \param name of the user
  *
- * \return 1 on success and < 0 on errors.
+ * \return a pointer to the corresponding user struct if the user was found,
+ *  \p NULL otherwise.
  */
-int lookup_user(struct user *user)
+struct user *lookup_user(const char *name)
 {
        struct user *u;
        list_for_each_entry(u, &user_list, node) {
-               if (strcmp(u->name, user->name))
+               if (strcmp(u->name, name))
                        continue;
-               *user = *u;
-               return 1;
+               return u;
        }
-       return -E_BAD_USER;
+       return NULL;
 }
index 1ee73521fa016406027ece664576f0b5f2401037..ce940376fdc67128e6ae9636281978f7523273ec 100644 (file)
@@ -46,4 +46,4 @@ struct user {
 };
 
 void init_user_list(char *user_list_file);
-int lookup_user(struct user *user);
+struct user *lookup_user(const char *name);