]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/afp_options.c
Fix cmdline option handling
[netatalk.git] / etc / afpd / afp_options.c
index 17e1706c5394cbc7f9a97f19f5de1e602ac27943..705652a69d54ac379625c5b8aa09ea2f30ab00b2 100644 (file)
@@ -47,6 +47,8 @@
 /* get rid of any allocated afp_option buffers. */
 void afp_options_free(struct afp_options *opt)
 {
+       if (opt->hostname)
+        free(opt->hostname);
        if (opt->adminauthuser)
         free(opt->adminauthuser);
        if (opt->configfile)
@@ -102,33 +104,10 @@ int afp_config_parse(AFPObj *AFPObj)
     char *q, *r;
     char val[MAXVAL];
 
-    memset(options, 0, sizeof(struct afp_options));
-    options->configfile  = strdup(_PATH_CONFDIR "afp.conf");
+    options->configfile  = AFPObj->cmdlineconfigfile ? strdup(AFPObj->cmdlineconfigfile) : strdup(_PATH_CONFDIR "afp.conf");
     options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf");
     options->uuidconf    = strdup(_PATH_CONFDIR "afp_voluuid.conf");
-    options->flags |= OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF;
-    if (gethostname(val, sizeof(val)) < 0 ) {
-        perror( "gethostname" );
-        return 0;
-    }
-    if (NULL != (q = strchr(val, '.')))
-        *q = '\0';
-    options->hostname = strdup(val);
-
-    while ((c = getopt(AFPObj->argc, AFPObj->argv, "dF:")) != -1) {
-        switch (c) {
-        case 'd':
-            options->flags |= OPTION_DEBUG;
-            break;
-        case 'F':
-            if (options->configfile)
-                free(options->configfile);
-            options->configfile = strdup(optarg);
-            break;
-        default :
-            break;
-        }
-    }
+    options->flags       = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | AFPObj->cmdlineflags;
 
     if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
         return -1;
@@ -157,7 +136,7 @@ int afp_config_parse(AFPObj *AFPObj)
         options->flags &= ~OPTION_ACL2MACCESS;
     if (strstr(val, " keepsessions"))
         options->flags |= OPTION_KEEPSESSIONS;
-    if (strstr(val, " keepsessions"))
+    if (strstr(val, " closevol"))
         options->flags |= OPTION_CLOSEVOL;
     if (strstr(val, " client_polling"))
         options->flags &= ~OPTION_SERVERNOTIF;
@@ -183,7 +162,6 @@ int afp_config_parse(AFPObj *AFPObj)
     options->k5realm        = iniparser_getstrdup(config, INISEC_AFP, "k5realm",        NULL);
     options->authprintdir   = iniparser_getstrdup(config, INISEC_AFP, "authprintdir",   NULL);
     options->listen         = iniparser_getstrdup(config, INISEC_AFP, "listen",         NULL);
-    options->hostname       = iniparser_getstrdup(config, INISEC_AFP, "hostname",       NULL);
     options->ntdomain       = iniparser_getstrdup(config, INISEC_AFP, "ntdomain",       NULL);
     options->ntseparator    = iniparser_getstrdup(config, INISEC_AFP, "ntseparator",    NULL);
     options->mimicmodel     = iniparser_getstrdup(config, INISEC_AFP, "mimicmodel",     NULL);
@@ -202,6 +180,17 @@ int afp_config_parse(AFPObj *AFPObj)
     options->sleep          = iniparser_getint   (config, INISEC_AFP, "sleep",          10) * 60 * 2;
     options->disconnected   = iniparser_getint   (config, INISEC_AFP, "disconnect",     24) * 60 * 2;
 
+    if ((p = iniparser_getstring(config, INISEC_AFP, "hostname", NULL))) {
+        EC_NULL_LOG( options->hostname = strdup(p) );
+    } else {
+        if (gethostname(val, sizeof(val)) < 0 ) {
+            perror( "gethostname" );
+            EC_FAIL;
+        }
+        if ((q = strchr(val, '.')))
+            *q = '\0';
+        options->hostname = strdup(val);
+    }
 
     if ((p = iniparser_getstring(config, INISEC_AFP, "k5keytab", NULL))) {
         EC_NULL_LOG( options->k5keytab = malloc(strlen(p) + 14) );
@@ -224,6 +213,8 @@ int afp_config_parse(AFPObj *AFPObj)
     options->Cnid_srv = strdup(q);
     if (r)
         options->Cnid_port = strdup(r + 1);
+    else
+        options->Cnid_port = strdup("4700");
     LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", options->Cnid_srv, options->Cnid_port);
     if (q)
         free(q);
@@ -243,20 +234,30 @@ int afp_config_parse(AFPObj *AFPObj)
         free(q);
     }
 
-    p = iniparser_getstring(config, INISEC_AFP, "unixcodepage", "LOCALE");
-    if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
+    if (!(p = iniparser_getstring(config, INISEC_AFP, "unixcodepage", NULL))) {
         options->unixcharset = CH_UNIX;
-        LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
+        options->unixcodepage = strdup("LOCALE");
     } else {
-        options->unixcodepage = strdup(p);
+        if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
+            options->unixcharset = CH_UNIX;
+            options->unixcodepage = strdup("LOCALE");
+            LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
+        } else {
+            options->unixcodepage = strdup(p);
+        }
     }
        
-    p = iniparser_getstring(config, INISEC_AFP, "maccodepage", "MAC_ROMAN");
-    if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
+    if (!(p = iniparser_getstring(config, INISEC_AFP, "maccodepage", NULL))) {
         options->maccharset = CH_MAC;
-        LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
+        options->maccodepage = strdup("MAC_ROMAN");
     } else {
-        options->maccodepage = strdup(p);
+        if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
+            options->maccharset = CH_MAC;
+            options->maccodepage = strdup("MAC_ROMAN");
+            LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
+        } else {
+            options->maccodepage = strdup(p);
+        }
     }
 
     if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) {
@@ -433,14 +434,17 @@ static void show_usage(void)
        fprintf( stderr, "\tafpd -h|-v|-V\n");
 }
 
-void afp_options_parse_cmdline(int ac, char **av)
+void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av)
 {
     int c, err = 0;
 
     while (EOF != ( c = getopt( ac, av, "dFvVh" )) ) {
         switch ( c ) {
         case 'd':
+            obj->cmdlineflags |= OPTION_DEBUG;
+            break;
         case 'F':
+            obj->cmdlineconfigfile = strdup(optarg);
             break;
         case 'v':      /* version */
             show_version( ); puts( "" );