From 85eb0fd28ff87289d2f49a0230c07e7a7c56e101 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Sat, 11 Feb 2012 15:40:03 +0100 Subject: [PATCH] Fixes --- etc/afpd/Makefile.am | 3 -- etc/afpd/afp_config.c | 17 +------- etc/afpd/afp_options.c | 87 ++++++++++++++++------------------------- etc/afpd/main.c | 31 ++++++--------- include/atalk/globals.h | 5 ++- libatalk/util/logger.c | 24 ++++++------ 6 files changed, 63 insertions(+), 104 deletions(-) diff --git a/etc/afpd/Makefile.am b/etc/afpd/Makefile.am index 1a2dd95c..544c5843 100644 --- a/etc/afpd/Makefile.am +++ b/etc/afpd/Makefile.am @@ -56,10 +56,7 @@ afpd_CFLAGS = \ -DAPPLCNAME \ -DSERVERTEXT=\"$(SERVERTEXT)/\" \ -D_PATH_AFPDPWFILE=\"$(pkgconfdir)/afppasswd\" \ - -D_PATH_AFPDCONF=\"$(pkgconfdir)/afpd.conf\" \ - -D_PATH_AFPDSIGCONF=\"$(pkgconfdir)/afp_signature.conf\" \ -D_PATH_AFPDUAMPATH=\"$(UAMS_PATH)/\" \ - -D_PATH_AFPDUUIDCONF=\"$(pkgconfdir)/afp_voluuid.conf\" \ -D_PATH_CONFDIR=\"$(pkgconfdir)\" if HAVE_ACLS diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index cd332a94..c07b2e92 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -171,21 +171,10 @@ static AFPConfig *AFPConfigInit(struct afp_options *options, } /*! - * Parse configfile and build AFPObj + * Get everything running */ -int configinit(AFPObj *AFPObj, const struct afp_options *defoptions) +int configinit(AFPObj *AFPObj) { - int have_option = 0; - - afp_options_duplicate(&AFPObj->options, defoptions); - - if ((AFPObj->iniconfig = iniparser_load(AFPObj->options.configfile)) == NULL) - /* if config file doesn't exist, load defaults */ - return AFPConfigInit(AFPObj); - - if (afp_options_parse(AFPObj) != 0) - return -1; - AFPConfigInit(AFPObj); #ifdef HAVE_LDAP @@ -193,8 +182,6 @@ int configinit(AFPObj *AFPObj, const struct afp_options *defoptions) acl_ldap_readconfig(AFPObj->iniconfig); #endif /* HAVE_LDAP */ - LOG(log_debug, logtype_afpd, "Finished parsing Config File"); - /* Now register with zeroconf, we also need the volumes for that */ if (! (AFPObj->options.flags & OPTION_NOZEROCONF)) { load_volumes(AFPObj); diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index 65710c10..79b4df07 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -41,22 +41,8 @@ #include "auth.h" #include "dircache.h" -#define OPTIONS "dn:uc:g:P:ptS:L:F:U:hIvVm:" #define LENGTH 512 -/* initialize options */ -void afp_options_init(struct afp_options *options) -{ - memset(options, 0, sizeof(struct afp_options)); - - options->pidfile = _PATH_AFPDLOCK; - options->configfile = D_PATH_CONFDIR "afp.conf"; - options->sigconffile = _PATH_AFPDSIGCONF; - options->uuidconf = _PATH_AFPDUUIDCONF; - options->server_notif = 1; - options->dsireadbuf = 12; -} - /* get rid of any allocated afp_option buffers. */ void afp_options_free(struct afp_options *opt) { @@ -104,27 +90,8 @@ void afp_options_free(struct afp_options *opt) free(opt->unixcodepage); } -void afp_options_duplicate(struct afp_options *options, const struct afp_options *soptions) -{ - memcpy(options, soptions, sizeof(struct afp_options)); - - options->pidfile = NULL; - options->uuidconf = NULL; - - options->configfile = strdup(options->configfile); - options->guest = strdup(options->guest); - options->loginmesg = strdup(options->loginmesg); - options->maccodepage = strdup(options->maccodepage); - options->passwdfile = strdup(options->passwdfile); - options->sigconffile = strdup(options->sigconffile); - options->signatureopt = strdup(options->signatureopt); - options->uamlist = strdup(options->uamlist); - options->uampath = strdup(options->uampath); - options->unixcodepage = strdup(options->unixcodepage); -} - -#define MAXVAL -int afp_options_parse(AFPObj *AFPObj) +#define MAXVAL 1024 +int afp_config_parse(AFPObj *AFPObj) { dictionary *config = AFPObj->iniconfig; struct afp_options *options = &AFPObj->options; @@ -132,15 +99,38 @@ int afp_options_parse(AFPObj *AFPObj) const char *p, *tmp; char val[MAXVAL]; - /* [Global] */ + memset(options, 0, sizeof(struct afp_options)); + options->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; + + while (EOF != (p = getopt(AFPObj->argc, AFPObj->argv, "dF:"))) { + switch (p) { + case 'd': + options->flags |= OPTION_DEBUG; + break; + case 'F': + if (options->configfile) + free(options->configfile); + options->configfile = optarg; + break; + default : + break; + } + } - options->logconfig = iniparser_getstring(config, INISEC_GLOBAL, "loglevel", "default:note"); - options->logfile = iniparser_getstring(config, INISEC_GLOBAL, "logfile", NULL); + if ((config = iniparser_load(AFPObj->options.configfile)) == NULL) + return -1; + AFPObj->iniconfig = config; + + /* [Global] */ + options->logconfig = iniparser_getstring(config, INISEC_GLOBAL, "loglevel", "default:note"); + options->logfile = iniparser_getstring(config, INISEC_GLOBAL, "logfile", NULL); + set_processname("afpd"); setuplog(logconfig, logfile); /* [AFP] "options" options wo values */ - options->flags |= OPTION_ACL2MACCESS | OPTION_UUID; - p = iniparser_getstring(config, INISEC_AFP, "options", ""); strcpy(val, " "); strlcat(val, p, MAXVAL); @@ -159,6 +149,8 @@ int afp_options_parse(AFPObj *AFPObj) options->flags |= OPTION_KEEPSESSIONS; if (strstr(val, " keepsessions")) options->flags |= OPTION_CLOSEVOL; + if (strstr(val, " client_polling")) + options->flags &= ~OPTION_SERVERNOTIF; if (strstr(val, " nosavepassword")) options->passwdbits |= PASSWD_NOSAVE; if (strstr(val, " savepassword")) @@ -167,8 +159,6 @@ int afp_options_parse(AFPObj *AFPObj) options->passwdbits &= ~PASSWD_SET; if (strstr(val, " setpassword")) options->passwdbits |= PASSWD_SET; - if (strstr(val, " client_polling")) - options->server_notif = 0; /* figure out options w values */ @@ -441,11 +431,8 @@ static void show_usage( char *name ) fprintf( stderr, "\t%s -h|-v|-V\n", name ); } -int afp_options_parse_cmdline(int ac, char **av, struct afp_options *options) +int afp_options_parse_cmdline(int ac, char **av) { - extern char *optarg; - extern int optind; - char *p; char *tmp; /* Used for error checking the result of strtol */ int c, err = 0; @@ -459,14 +446,8 @@ int afp_options_parse_cmdline(int ac, char **av, struct afp_options *options) *p = '\0'; options->hostname = strdup(buf); - while (EOF != ( c = getopt( ac, av, OPTIONS )) ) { + while (EOF != ( c = getopt( ac, av, "vVh" )) ) { switch ( c ) { - case 'd' : - options->flags |= OPTION_DEBUG; - break; - case 'F': - options->configfile = optarg; - break; case 'v': /* version */ show_version( ); puts( "" ); show_paths( ); puts( "" ); diff --git a/etc/afpd/main.c b/etc/afpd/main.c index 43b8d080..80b475b1 100644 --- a/etc/afpd/main.c +++ b/etc/afpd/main.c @@ -217,39 +217,34 @@ int main(int ac, char **av) struct sigaction sv; sigset_t sigs; int ret; - struct afp_options default_options = {0}; /* Parse argv args and initialize default options */ - afp_options_init(&default_options); - if (!afp_options_parse_cmdline(ac, av, &default_options)) + AFPObj.argc = ac; + AFPObj.argv = av; + if (!afp_config_parse(&AFPObj)) exit(EXITERR_CONF); - if (check_lockfile("afpd", default_options.pidfile) != 0) + if (check_lockfile("afpd", _PATH_AFPDLOCK) != 0) exit(EXITERR_SYS); - if (!(default_options.flags & OPTION_DEBUG) && (daemonize(0, 0) != 0)) + if (!(AFPObj.options.flags & OPTION_DEBUG) && (daemonize(0, 0) != 0)) exit(EXITERR_SYS); - if (create_lockfile("afpd", default_options.pidfile) != 0) + if (create_lockfile("afpd", _PATH_AFPDLOCK) != 0) exit(EXITERR_SYS); /* Log SIGBUS/SIGSEGV SBT */ fault_setup(NULL); - - /* Default log setup: log to syslog */ - set_processname("afpd"); - setuplog("default log_note"); + atexit(afp_exit); /* Save the user's current umask */ - default_options.save_mask = umask( default_options.umask ); - - atexit(afp_exit); + AFPObj.options.save_mask = umask(AFPObj.options.umask); /* install child handler for asp and dsi. we do this before afp_goaway * as afp_goaway references stuff from here. * XXX: this should really be setup after the initial connections. */ - if (!(server_children = server_child_alloc(default_options.connections, - CHILD_NFORKS))) { + if (!(server_children = server_child_alloc(AFPObj.options.connections, + CHILD_NFORKS))) { LOG(log_error, logtype_afpd, "main: server_child alloc: %s", strerror(errno) ); exit(EXITERR_SYS); } @@ -304,7 +299,6 @@ int main(int ac, char **av) exit(EXITERR_SYS); } - sigemptyset( &sv.sa_mask ); sigaddset(&sv.sa_mask, SIGALRM); sigaddset(&sv.sa_mask, SIGHUP); @@ -348,7 +342,7 @@ int main(int ac, char **av) sigaddset(&sigs, SIGCHLD); pthread_sigmask(SIG_BLOCK, &sigs, NULL); - if (!(AFPObj = configinit(&default_options))) { + if (configinit(&AFPObj) != 0) { LOG(log_error, logtype_afpd, "main: no servers configured"); exit(EXITERR_CONF); } @@ -399,12 +393,11 @@ int main(int ac, char **av) fd_reset_listening_sockets(&AFPObj); LOG(log_info, logtype_afpd, "re-reading configuration file"); - dsi_cleanup(&AFPObj); /* configfree close atp socket used for DDP tickle, there's an issue * with atp tid. */ configfree(&AFPObj); - if (!(AFPObj = configinit(&default_options))) { + if (configinit(&AFPObj) != 0) { LOG(log_error, logtype_afpd, "config re-read: no servers configured"); exit(EXITERR_CONF); } diff --git a/include/atalk/globals.h b/include/atalk/globals.h index 62e754a4..716c6038 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -34,6 +34,7 @@ #define OPTION_DEBUG (1 << 0) #define OPTION_CLOSEVOL (1 << 1) +#define OPTION_SERVERNOTIF (1 << 2) #define OPTION_CUSTOMICON (1 << 4) #define OPTION_ANNOUNCESSH (1 << 6) #define OPTION_UUID (1 << 7) @@ -61,10 +62,11 @@ struct afp_volume_name { }; struct afp_options { + int argc; + char **argv; int connections; /* Maximum number of possible AFP connections */ int tickleval; int timeout; - int server_notif; int flags; int dircachesize; int sleep; /* Maximum time allowed to sleep (in tickles) */ @@ -79,7 +81,6 @@ struct afp_options { char *Cnid_srv, *Cnid_port; char *configfile; char *uampath, *fqdn; - char *pidfile; char *sigconffile; char *uuidconf; char *guest, *loginmesg, *keyfile, *passwdfile; diff --git a/libatalk/util/logger.c b/libatalk/util/logger.c index 3f26c457..c1e981dd 100644 --- a/libatalk/util/logger.c +++ b/libatalk/util/logger.c @@ -39,18 +39,18 @@ Netatalk 2001 (c) #define MAXLOGSIZE 512 #define LOGLEVEL_STRING_IDENTIFIERS { \ - "LOG_NOTHING", \ - "LOG_SEVERE", \ - "LOG_ERROR", \ - "LOG_WARN", \ - "LOG_NOTE", \ - "LOG_INFO", \ - "LOG_DEBUG", \ - "LOG_DEBUG6", \ - "LOG_DEBUG7", \ - "LOG_DEBUG8", \ - "LOG_DEBUG9", \ - "LOG_MAXDEBUG"} + "NOTHING", \ + "SEVERE", \ + "ERROR", \ + "WARN", \ + "NOTE", \ + "INFO", \ + "DEBUG", \ + "DEBUG6", \ + "DEBUG7", \ + "DEBUG8", \ + "DEBUG9", \ + "MAXDEBUG"} /* these are the string identifiers corresponding to each logtype */ #define LOGTYPE_STRING_IDENTIFIERS { \ -- 2.39.2