cosmetics
[paraslash.git] / command.c
index ea42ef4..ad3f504 100644 (file)
--- a/command.c
+++ b/command.c
@@ -31,6 +31,7 @@
 #include "net.h"
 #include "daemon.h"
 #include "string.h"
+#include "fd.h"
 
 static RC4_KEY rc4_recv_key;
 static RC4_KEY rc4_send_key;
@@ -603,7 +604,8 @@ static int com_version(int socket_fd, int argc, __a_unused char **argv)
 {
        if (argc != 1)
                return -E_COMMAND_SYNTAX;
-       return send_buffer(socket_fd, "para_server-" VERSION ", \"" CODENAME "\"\n"
+       return send_buffer(socket_fd, "para_server-" PACKAGE_VERSION ", \""
+                       CODENAME "\"\n"
                        COPYRIGHT "\n"
                        "built: " BUILD_DATE "\n"
                        SYSTEM ", " CC_VERSION "\n"
@@ -689,7 +691,9 @@ static int com_stat(int socket_fd, int argc, char **argv)
                ret = 1;
                if (num == 1)
                        goto out;
-               usleep(500000 * 100);
+               sleep(50);
+               if (getppid() == 1)
+                       return -E_SERVER_CRASH;
        }
 out:
        return ret;
@@ -1008,51 +1012,48 @@ static int get_user(struct user *user) {
        char line[MAXLINE];
        /* keyword, user, key, perms */
        char w[MAXLINE], n[MAXLINE], k[MAXLINE], p[MAXLINE], tmp[4][MAXLINE];
-       int num;
+       int num, ret;
 
        file_ptr = open_user_list(user_list);
        if (!file_ptr)
                return -E_USERLIST;
-       while (fgets(line, MAXLINE, file_ptr)) {
-//             PARA_DEBUG_LOG("%s: Read line (%i bytes) "
-//                     "from config file\n", __func__, strlen(line));
+       for (;;) {
+               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") && !strcmp(user->name, n)) {
-                       PARA_DEBUG_LOG("found entry for %s\n", n);
-                       strcpy(user->name, n);
-                       strcpy(user->pubkey_file, k);
-                       user->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);
-                       user->perms = 0;
-                       while (num > 0) {
-                               num--;
-                               //PARA_DEBUG_LOG("%s: tmp[%i]=%s\n", __func__,
-                               //      num, tmp[num]);
-                               if (!strcmp(tmp[num], "AFS_READ"))
-                                       user->perms =
-                                               user->perms | AFS_READ;
-                               else if (!strcmp(tmp[num], "AFS_WRITE"))
-                                       user->perms =
-                                               user->perms | AFS_WRITE;
-                               else if (!strcmp(tmp[num], "DB_READ"))
-                                       user->perms = user->perms | DB_READ;
-                               else if (!strcmp(tmp[num], "DB_WRITE"))
-                                       user->perms = user->perms | DB_WRITE;
-                               else /* unknown permission */
-                                       PARA_WARNING_LOG("unknown permission:"
-                                               "%s\n", tmp[num]);
-                       }
-                       fclose(file_ptr);
-                       return 1;
+               if (strcmp(w, "user") || strcmp(user->name, n))
+                       continue;
+               PARA_DEBUG_LOG("found entry for %s\n", n);
+               strcpy(user->name, n);
+               strcpy(user->pubkey_file, k);
+               user->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);
+               user->perms = 0;
+               while (num > 0) {
+                       num--;
+                       if (!strcmp(tmp[num], "AFS_READ"))
+                               user->perms = user->perms | AFS_READ;
+                       else if (!strcmp(tmp[num], "AFS_WRITE"))
+                               user->perms = user->perms | AFS_WRITE;
+                       else if (!strcmp(tmp[num], "DB_READ"))
+                               user->perms = user->perms | DB_READ;
+                       else if (!strcmp(tmp[num], "DB_WRITE"))
+                               user->perms = user->perms | DB_WRITE;
+                       else /* unknown permission */
+                               PARA_WARNING_LOG("unknown permission: %s\n",
+                                       tmp[num]);
                }
+               break;
        }
        fclose(file_ptr);
-       return 0;
+       return ret;
 }
 
 static void init_rc4_keys(void)
@@ -1100,7 +1101,8 @@ int handle_connect(int fd, struct sockaddr_in *addr)
        in_addr = addr;
        challenge_nr = random();
        /* send Welcome message */
-       ret = send_va_buffer(fd, "This is para_server, version " VERSION  ".\n" );
+       ret = send_va_buffer(fd, "This is para_server, version "
+               PACKAGE_VERSION  ".\n" );
        if (ret < 0)
                goto err_out;
        /* recv auth request line */