Parse listenaddr for hostnames
[nbd.git] / nbd-server.c
index 4d01e37..122d2fe 100644 (file)
@@ -344,7 +344,6 @@ void usage() {
               "\t-c|--copy-on-write\tcopy on write\n"
               "\t-C|--config-file\tspecify an alternate configuration file\n"
               "\t-l|--authorize-file\tfile with list of hosts that are allowed to\n\t\t\t\tconnect.\n"
-              "\t-a|--idle-time\t\tmaximum idle seconds; server terminates when\n\t\t\t\tidle time exceeded\n"
               "\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
               "\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n\n"
               "\tif port is set to 0, stdin is used (for running from inetd)\n"
@@ -393,7 +392,6 @@ SERVER* cmdline(int argc, char *argv[]) {
                {"multi-file", no_argument, NULL, 'm'},
                {"copy-on-write", no_argument, NULL, 'c'},
                {"authorize-file", required_argument, NULL, 'l'},
-               {"idle-time", required_argument, NULL, 'a'},
                {"config-file", required_argument, NULL, 'C'},
                {"pid-file", required_argument, NULL, 'p'},
                {"output-config", required_argument, NULL, 'o'},
@@ -413,7 +411,7 @@ SERVER* cmdline(int argc, char *argv[]) {
        serve=g_new0(SERVER, 1);
        serve->authname = g_strdup(default_authname);
        serve->virtstyle=VIRT_IPLIT;
-       while((c=getopt_long(argc, argv, "-a:C:cl:mo:rp:", long_options, &i))>=0) {
+       while((c=getopt_long(argc, argv, "-C:cl:mo:rp:", long_options, &i))>=0) {
                switch (c) {
                case 1:
                        /* non-option argument */
@@ -581,7 +579,7 @@ GArray* parse_cfile(gchar* f, GError** e) {
        retval = g_array_new(FALSE, TRUE, sizeof(SERVER));
        if(!g_key_file_load_from_file(cfile, f, G_KEY_FILE_KEEP_COMMENTS |
                        G_KEY_FILE_KEEP_TRANSLATIONS, &err)) {
-               g_set_error(e, errdomain, CFILE_NOTFOUND, "Could not open config file.", f);
+               g_set_error(e, errdomain, CFILE_NOTFOUND, "Could not open config file %s.", f);
                g_key_file_free(cfile);
                return retval;
        }
@@ -1504,6 +1502,7 @@ void setup_serve(SERVER *serve) {
 #else
        char yes='1';
 #endif /* sun */
+       struct hostent* he;
 
        af = AF_INET;
 #ifdef WITH_SDP
@@ -1538,8 +1537,9 @@ void setup_serve(SERVER *serve) {
        }
 #endif
        addrin.sin_port = htons(serve->port);
-       if(!inet_aton(serve->listenaddr, &(addrin.sin_addr)))
+       if(!(he = gethostbyname(serve->listenaddr)))
                err("could not parse listen address");
+        addrin.sin_addr = he->h_addr_list[0];
        if (bind(serve->socket, (struct sockaddr *) &addrin, addrinlen) < 0)
                err("bind: %m");
        DEBUG("listen, ");
@@ -1626,26 +1626,25 @@ void serve_err(SERVER* serve, const char* msg) {
 void dousers(void) {
        struct passwd *pw;
        struct group *gr;
+       gchar* str;
        if(rungroup) {
                gr=getgrnam(rungroup);
                if(!gr) {
-                       g_message("Invalid group name: %s", rungroup);
-                       exit(EXIT_FAILURE);
+                       str = g_strdup_printf("Invalid group name: %s", rungroup);
+                       err(str);
                }
                if(setgid(gr->gr_gid)<0) {
-                       g_message("Could not set GID: %s", strerror(errno));
-                       exit(EXIT_FAILURE);
+                       err("Could not set GID: %m"); 
                }
        }
        if(runuser) {
                pw=getpwnam(runuser);
                if(!pw) {
-                       g_message("Invalid user name: %s", runuser);
-                       exit(EXIT_FAILURE);
+                       str = g_strdup_printf("Invalid user name: %s", runuser);
+                       err(str);
                }
                if(setuid(pw->pw_uid)<0) {
-                       g_message("Could not set UID: %s", strerror(errno));
-                       exit(EXIT_FAILURE);
+                       err("Could not set UID: %m");
                }
        }
 }
@@ -1674,6 +1673,8 @@ void glib_message_syslog_redirect(const gchar *log_domain,
         break;
       case G_LOG_LEVEL_DEBUG:
         level=LOG_DEBUG;
+      default:
+        level=LOG_ERR;
     }
     syslog(level, message);
 }