From: Frank Lahm Date: Tue, 14 Feb 2012 15:22:45 +0000 (+0100) Subject: Fix cmdline option handling X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=7db833b1021f3daa8e30966e6f025b2a894348dc Fix cmdline option handling --- diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index fa5f6a9a..705652a6 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -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( "" ); diff --git a/etc/afpd/main.c b/etc/afpd/main.c index 13305a1e..f49daf6f 100644 --- a/etc/afpd/main.c +++ b/etc/afpd/main.c @@ -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); diff --git a/include/atalk/globals.h b/include/atalk/globals.h index 97efb56d..5607b329 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -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 *);