#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)
{
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;
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);
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"))
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 */
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;
*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( "" );
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);
}
exit(EXITERR_SYS);
}
-
sigemptyset( &sv.sa_mask );
sigaddset(&sv.sa_mask, SIGALRM);
sigaddset(&sv.sa_mask, SIGHUP);
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);
}
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);
}