]> arthur.barton.de Git - netatalk.git/commitdiff
Fix cmdline option handling
authorFrank Lahm <franklahm@googlemail.com>
Tue, 14 Feb 2012 15:22:45 +0000 (16:22 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 14 Feb 2012 15:22:45 +0000 (16:22 +0100)
etc/afpd/afp_options.c
etc/afpd/main.c
include/atalk/globals.h

index fa5f6a9a1b842e5cf98cacbbedd88ef22df92d51..705652a69d54ac379625c5b8aa09ea2f30ab00b2 100644 (file)
@@ -44,9 +44,6 @@
 
 #define LENGTH 512
 
-static const char *configfile;
-static int flags;
-
 /* get rid of any allocated afp_option buffers. */
 void afp_options_free(struct afp_options *opt)
 {
@@ -107,10 +104,10 @@ int afp_config_parse(AFPObj *AFPObj)
     char *q, *r;
     char val[MAXVAL];
 
-    options->configfile  = configfile ? strdup(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 | flags;
+    options->flags       = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | AFPObj->cmdlineflags;
 
     if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
         return -1;
@@ -216,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);
@@ -241,6 +240,7 @@ int afp_config_parse(AFPObj *AFPObj)
     } else {
         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);
@@ -253,6 +253,7 @@ int afp_config_parse(AFPObj *AFPObj)
     } else {
         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);
@@ -433,17 +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':
-            flags = OPTION_DEBUG;
+            obj->cmdlineflags |= OPTION_DEBUG;
             break;
         case 'F':
-            configfile = strdup(optarg);
+            obj->cmdlineconfigfile = strdup(optarg);
             break;
         case 'v':      /* version */
             show_version( ); puts( "" );
index 13305a1efa58f4182d8c8f4b3b93e89489fc011a..f49daf6f140bc65e428d7ed444e3b23f66540723 100644 (file)
@@ -220,9 +220,7 @@ int main(int ac, char **av)
     int                 ret;
 
     /* Parse argv args and initialize default options */
-    afp_options_parse_cmdline(ac, av);
-    if (afp_config_parse(&obj) != 0)
-        exit(EXITERR_CONF);
+    afp_options_parse_cmdline(&obj, ac, av);
 
     if (check_lockfile("afpd", _PATH_AFPDLOCK) != 0)
         exit(EXITERR_SYS);
@@ -237,6 +235,9 @@ int main(int ac, char **av)
     fault_setup(NULL);
     atexit(afp_exit);
 
+    if (afp_config_parse(&obj) != 0)
+        exit(EXITERR_CONF);
+
     /* Save the user's current umask */
     obj.options.save_mask = umask(obj.options.umask);
 
index 97efb56d27b8e66abfe485e339fac576f7742345..5607b3294c6c45f136c61af2e7c59b9dd39d7477 100644 (file)
@@ -46,7 +46,7 @@
  * Ini config sections
  **********************************************************************************************/
 
-#define INISEC_GLOBAL "General"
+#define INISEC_GLOBAL "Global"
 #define INISEC_AFP    "AFP"
 #define INISEC_CNID   "CNID"
 
@@ -102,6 +102,8 @@ struct afp_options {
 };
 
 typedef struct AFPObj {
+    const char *cmdlineconfigfile;
+    int cmdlineflags;
     const void *signature;
     struct DSI *dsi;
     struct afp_options options;
@@ -136,7 +138,7 @@ extern const char         *Cnid_port;
 
 extern int  get_afp_errno   (const int param);
 extern void afp_options_init (struct afp_options *);
-extern void afp_options_parse_cmdline(int ac, char **av);
+extern void afp_options_parse_cmdline(AFPObj *obj, int ac, char **av);
 extern int  afp_config_parse(AFPObj *AFPObj);
 extern void afp_options_free(struct afp_options *);
 extern void setmessage (const char *);