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;
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;
|| 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;
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 */
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) {
#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 \
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 \
/**
* 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;
}