From 03ba0b0ab9f1007f4a869c866f17a3fbdc1f134e Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Tue, 14 Feb 2012 15:32:45 +0100 Subject: [PATCH] Fixes --- etc/afpd/afp_avahi.c | 2 +- etc/afpd/afp_config.c | 16 +++++--- etc/afpd/afp_options.c | 73 +++++++++++++++++---------------- etc/afpd/main.c | 2 - etc/afpd/volume.c | 4 +- include/atalk/globals.h | 2 - libatalk/iniparser/dictionary.c | 2 +- 7 files changed, 54 insertions(+), 47 deletions(-) diff --git a/etc/afpd/afp_avahi.c b/etc/afpd/afp_avahi.c index ef7d5293..6a59659a 100644 --- a/etc/afpd/afp_avahi.c +++ b/etc/afpd/afp_avahi.c @@ -92,7 +92,7 @@ static void register_stuff(void) { } /* AFP server */ - for (dsi = obj->dsi; dsi; dsi = dsi->next) { + for (dsi = ctx->obj->dsi; dsi; dsi = dsi->next) { port = getip_port((struct sockaddr *)&dsi->server); if (convert_string(obj->options.unixcharset, diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index 1fafee03..9e1ef0dd 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -72,7 +72,7 @@ int configinit(AFPObj *obj) { EC_INIT; DSI *dsi, **next = &obj->dsi; - char *p, *q = NULL; + char *p = NULL, *q = NULL; LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s", obj->options.hostname, @@ -82,10 +82,12 @@ int configinit(AFPObj *obj) /* obj->options->listen is of the from "IP[:port][,IP:[PORT], ...]" */ /* obj->options->port is the default port to listen (548) */ - EC_NULL( q = p = strdup(obj->options.listen) ); - EC_NULL( p = strtok(p, ",") ); + if (obj->options.listen) { + EC_NULL( q = p = strdup(obj->options.listen) ); + EC_NULL( p = strtok(p, ",") ); + } - while (p) { + while (1) { if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL) break; @@ -97,7 +99,11 @@ int configinit(AFPObj *obj) getip_string((struct sockaddr *)&dsi->server), getip_port((struct sockaddr *)&dsi->server)); - p = strtok(NULL, ","); + if (p) + /* p is NULL if ! obj->options.listen */ + p = strtok(NULL, ","); + if (!p) + break; } if (obj->dsi == NULL) diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index 17e1706c..fa5f6a9a 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -44,9 +44,14 @@ #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) { + if (opt->hostname) + free(opt->hostname); if (opt->adminauthuser) free(opt->adminauthuser); if (opt->configfile) @@ -102,33 +107,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 = configfile ? strdup(configfile) : 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 | flags; if ((config = iniparser_load(AFPObj->options.configfile)) == NULL) return -1; @@ -157,7 +139,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 +165,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 +183,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) ); @@ -243,20 +235,28 @@ 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; + 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; + 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))) { @@ -440,7 +440,10 @@ void afp_options_parse_cmdline(int ac, char **av) while (EOF != ( c = getopt( ac, av, "dFvVh" )) ) { switch ( c ) { case 'd': + flags = OPTION_DEBUG; + break; case 'F': + configfile = strdup(optarg); break; case 'v': /* version */ show_version( ); puts( "" ); diff --git a/etc/afpd/main.c b/etc/afpd/main.c index 8729fc12..13305a1e 100644 --- a/etc/afpd/main.c +++ b/etc/afpd/main.c @@ -221,8 +221,6 @@ int main(int ac, char **av) /* Parse argv args and initialize default options */ afp_options_parse_cmdline(ac, av); - obj.argc = ac; - obj.argv = av; if (afp_config_parse(&obj) != 0) exit(EXITERR_CONF); diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 73904fc4..c7a262f6 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -953,9 +953,11 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p int secnum = iniparser_getnsec(obj->iniconfig); const char *secname; - for (i = 0; i < secnum; secname = iniparser_getsecname(obj->iniconfig, i), i++) { + for (i = 0; i < secnum; i++) { + secname = iniparser_getsecname(obj->iniconfig, i); if (!vol_section(secname)) continue; + if ((p = iniparser_getstrdup(obj->iniconfig, secname, "path", NULL)) == NULL) continue; strlcpy(path, p, MAXPATHLEN); diff --git a/include/atalk/globals.h b/include/atalk/globals.h index f8c353ca..97efb56d 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -102,8 +102,6 @@ struct afp_options { }; typedef struct AFPObj { - int argc; - char **argv; const void *signature; struct DSI *dsi; struct afp_options options; diff --git a/libatalk/iniparser/dictionary.c b/libatalk/iniparser/dictionary.c index 1848b45d..b44796bb 100644 --- a/libatalk/iniparser/dictionary.c +++ b/libatalk/iniparser/dictionary.c @@ -244,7 +244,7 @@ int dictionary_set(dictionary * d, char *section, char * key, char * val) int i ; unsigned hash ; - if (d==NULL || key==NULL) return -1 ; + if (d==NULL || section==NULL) return -1 ; /* Compute hash for this key */ hash = dictionary_hash(makekey(section, key)); -- 2.39.2