testsuite: Introduce a new test for para_server.
[paraslash.git] / command.c
index ece87e168a7e42b406526a9638ef5bf7126cd45c..b6861b88bbcb36621109f6d9ac7fe80546a42b35 100644 (file)
--- a/command.c
+++ b/command.c
@@ -10,7 +10,6 @@
 #include <signal.h>
 #include <sys/time.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <osl.h>
 #include <stdbool.h>
 
@@ -35,6 +34,7 @@
 #include "afs_command_list.h"
 #include "sched.h"
 #include "signal.h"
+#include "version.h"
 
 /** Commands including options must be shorter than this. */
 #define MAX_COMMAND_LEN 32768
@@ -108,7 +108,8 @@ static char *get_status(struct misc_meta_data *nmmd, int parser_friendly)
 {
        char mtime[30] = "";
        char *status, *flags; /* vss status info */
-       char *ut = uptime_str();
+       /* nobody updates our version of "now" */
+       char *ut = get_server_uptime_str(NULL);
        long offset = (nmmd->offset + 500) / 1000;
        struct timeval current_time;
        struct tm mtime_tm;
@@ -122,16 +123,22 @@ static char *get_status(struct misc_meta_data *nmmd, int parser_friendly)
                strftime(mtime, 29, "%b %d %Y", &mtime_tm);
        }
        gettimeofday(&current_time, NULL);
-       WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
-       WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
-       WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
-       WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
-       WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
-       WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
-       WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
+       /*
+        * The calls to WRITE_STATUS_ITEM() below never fail because
+        * b->max_size is zero (unlimited), see para_printf(). However, clang
+        * is not smart enough to prove this and complains nevertheless.
+        * Casting the return value to void silences solves this.
+        */
+       (void)WRITE_STATUS_ITEM(&b, SI_FILE_SIZE, "%zu\n", nmmd->size / 1024);
+       (void)WRITE_STATUS_ITEM(&b, SI_MTIME, "%s\n", mtime);
+       (void)WRITE_STATUS_ITEM(&b, SI_STATUS, "%s\n", status);
+       (void)WRITE_STATUS_ITEM(&b, SI_STATUS_FLAGS, "%s\n", flags);
+       (void)WRITE_STATUS_ITEM(&b, SI_OFFSET, "%li\n", offset);
+       (void)WRITE_STATUS_ITEM(&b, SI_AFS_MODE, "%s\n", mmd->afs_mode_string);
+       (void)WRITE_STATUS_ITEM(&b, SI_STREAM_START, "%lu.%lu\n",
                (long unsigned)nmmd->stream_start.tv_sec,
                (long unsigned)nmmd->stream_start.tv_usec);
-       WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
+       (void)WRITE_STATUS_ITEM(&b, SI_CURRENT_TIME, "%lu.%lu\n",
                (long unsigned)current_time.tv_sec,
                (long unsigned)current_time.tv_usec);
        free(flags);
@@ -252,7 +259,7 @@ int com_si(struct stream_cipher_context *scc, int argc, __a_unused char * const
                sender_info = para_strcat(sender_info, info);
                free(info);
        }
-       ut = uptime_str();
+       ut = get_server_uptime_str(now);
        ret = sc_send_va_buffer(scc, "version: " GIT_VERSION "\n"
                "up: %s\nplayed: %u\n"
                "server_pid: %d\n"
@@ -730,7 +737,7 @@ __noreturn void handle_connect(int fd, const char *peername)
        int ret, argc;
        char buf[4096];
        unsigned char rand_buf[CHALLENGE_SIZE + 2 * SESSION_KEY_LEN];
-       unsigned char challenge_sha1[HASH_SIZE];
+       unsigned char challenge_hash[HASH_SIZE];
        struct user *u;
        struct server_command *cmd = NULL;
        char **argv = NULL;
@@ -756,13 +763,11 @@ __noreturn void handle_connect(int fd, const char *peername)
                ret = -E_AUTH_REQUEST;
                goto net_err;
        }
-       numbytes = ret;
        ret = -E_AUTH_REQUEST;
        if (strncmp(buf, AUTH_REQUEST_MSG, strlen(AUTH_REQUEST_MSG)))
                goto net_err;
        p = buf + strlen(AUTH_REQUEST_MSG);
        PARA_DEBUG_LOG("received auth request for user %s\n", p);
-       ret = -E_BAD_USER;
        u = lookup_user(p);
        if (u) {
                get_random_bytes_or_die(rand_buf, sizeof(rand_buf));
@@ -795,14 +800,14 @@ __noreturn void handle_connect(int fd, const char *peername)
        if (!u)
                goto net_err;
        /*
-        * The correct response is the sha1 of the first CHALLENGE_SIZE bytes
+        * The correct response is the hash of the first CHALLENGE_SIZE bytes
         * of the random data.
         */
        ret = -E_BAD_AUTH;
        if (numbytes != HASH_SIZE)
                goto net_err;
-       sha1_hash((char *)rand_buf, CHALLENGE_SIZE, challenge_sha1);
-       if (memcmp(challenge_sha1, buf, HASH_SIZE))
+       hash_function((char *)rand_buf, CHALLENGE_SIZE, challenge_hash);
+       if (memcmp(challenge_hash, buf, HASH_SIZE))
                goto net_err;
        /* auth successful */
        alarm(0);