]> arthur.barton.de Git - netatalk.git/commitdiff
Fixes
authorFrank Lahm <franklahm@googlemail.com>
Tue, 14 Feb 2012 14:32:45 +0000 (15:32 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 14 Feb 2012 14:32:45 +0000 (15:32 +0100)
etc/afpd/afp_avahi.c
etc/afpd/afp_config.c
etc/afpd/afp_options.c
etc/afpd/main.c
etc/afpd/volume.c
include/atalk/globals.h
libatalk/iniparser/dictionary.c

index ef7d529336b7dab60cbaa237b283f1a32ef99f2e..6a59659ad08da9f738ed18bdc4b7f6ecb1a39cf7 100644 (file)
@@ -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,
index 1fafee03a04641623c898de1a6af916260911ac7..9e1ef0ddd55508d96d426da8c7aa230a2b686884 100644 (file)
@@ -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)
index 17e1706c5394cbc7f9a97f19f5de1e602ac27943..fa5f6a9a1b842e5cf98cacbbedd88ef22df92d51 100644 (file)
 
 #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( "" );
index 8729fc12466134ab0875576df3dd4bf42b3c191a..13305a1efa58f4182d8c8f4b3b93e89489fc011a 100644 (file)
@@ -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);
 
index 73904fc4c3b083891f6c9d82607e0387e542bee4..c7a262f6ea8821bfdacfee18005ad53932b8c3d7 100644 (file)
@@ -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);
index f8c353cac0a2e8356ccfc27348d200a9c93146d9..97efb56d27b8e66abfe485e339fac576f7742345 100644 (file)
@@ -102,8 +102,6 @@ struct afp_options {
 };
 
 typedef struct AFPObj {
-    int argc;
-    char **argv;
     const void *signature;
     struct DSI *dsi;
     struct afp_options options;
index 1848b45db15c036ada509e72ccbb1af74dd7875c..b44796bb24e30394d70cfd84c81784255b9068e5 100644 (file)
@@ -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));