#include <atalk/compat.h>
#include <atalk/globals.h>
#include <atalk/fce_api.h>
+#include <atalk/errchk.h>
#include "status.h"
#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)
{
+ if (opt->hostname)
+ free(opt->hostname);
if (opt->adminauthuser)
free(opt->adminauthuser);
if (opt->configfile)
free(opt->fqdn);
if (opt->guest)
free(opt->guest);
- if (opt->ipaddr)
- free(opt->ipaddr);
+ if (opt->listen)
+ free(opt->listen);
if (opt->k5realm)
free(opt->k5realm);
if (opt->k5keytab)
free(opt->k5service);
if (opt->logconfig)
free(opt->logconfig);
+ if (opt->logfile)
+ free(opt->logfile);
if (opt->loginmesg)
free(opt->loginmesg);
if (opt->maccodepage)
free(opt->passwdfile);
if (opt->port)
free(opt->port);
- if (opt->server)
- free(opt->server);
if (opt->signatureopt)
free(opt->signatureopt);
if (opt->uamlist)
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;
+ EC_INIT;
+ dictionary *config;
struct afp_options *options = &AFPObj->options;
- int i;
+ int i, c;
const char *p, *tmp;
+ char *q, *r;
char val[MAXVAL];
- /* [Global] */
+ 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 | AFPObj->cmdlineflags;
- options->logconfig = iniparser_getstring(config, INISEC_GLOBAL, "loglevel", "default:note");
- options->logfile = iniparser_getstring(config, INISEC_GLOBAL, "logfile", NULL);
- setuplog(logconfig, logfile);
+ if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
+ return -1;
+ AFPObj->iniconfig = config;
- /* [AFP] "options" options wo values */
- options->flags |= OPTION_ACL2MACCESS | OPTION_UUID;
+ /* [Global] */
+ options->logconfig = iniparser_getstrdup(config, INISEC_GLOBAL, "loglevel", "default:note");
+ options->logfile = iniparser_getstrdup(config, INISEC_GLOBAL, "logfile", NULL);
+ set_processname("afpd");
+ setuplog(options->logconfig, options->logfile);
+ /* [AFP] "options" options wo values */
p = iniparser_getstring(config, INISEC_AFP, "options", "");
strcpy(val, " ");
strlcat(val, p, MAXVAL);
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;
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 */
- options->loginmesg = iniparser_getstring(config, INISEC_AFP, "loginmesg", "");
- options->guest = iniparser_getstring(config, INISEC_AFP, "guestname", "nobody");
- options->passwdfile = iniparser_getstring(config, INISEC_AFP, "passwdfile", _PATH_AFPDPWFILE);
- options->uampath = iniparser_getstring(config, INISEC_AFP, "uampath", _PATH_AFPDUAMPATH);
- options->uamlist = iniparser_getstring(config, INISEC_AFP, "uamlist", "uams_dhx.so,uams_dhx2.so");
- options->port = iniparser_getstring(config, INISEC_AFP, "port", "548");
- options->signatureopt = iniparser_getstring(config, INISEC_AFP, "signature", "auto");
-
+ options->loginmesg = iniparser_getstrdup(config, INISEC_AFP, "loginmesg", "");
+ options->guest = iniparser_getstrdup(config, INISEC_AFP, "guestname", "nobody");
+ options->passwdfile = iniparser_getstrdup(config, INISEC_AFP, "passwdfile", _PATH_AFPDPWFILE);
+ options->uampath = iniparser_getstrdup(config, INISEC_AFP, "uampath", _PATH_AFPDUAMPATH);
+ options->uamlist = iniparser_getstrdup(config, INISEC_AFP, "uamlist", "uams_dhx.so,uams_dhx2.so");
+ options->port = iniparser_getstrdup(config, INISEC_AFP, "port", "548");
+ options->signatureopt = iniparser_getstrdup(config, INISEC_AFP, "signature", "auto");
+ options->k5service = iniparser_getstrdup(config, INISEC_AFP, "k5service", NULL);
+ 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->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);
+ options->adminauthuser = iniparser_getstrdup(config, INISEC_AFP, "adminauthuser", NULL);
options->connections = iniparser_getint (config, INISEC_AFP, "maxcon", 200);
options->passwdminlen = iniparser_getint (config, INISEC_AFP, "passwdminlen", 0);
options->tickleval = iniparser_getint (config, INISEC_AFP, "tickleval", 30);
options->tcp_rcvbuf = iniparser_getint (config, INISEC_AFP, "tcprcvbuf", 0);
options->fce_fmodwait = iniparser_getint (config, INISEC_AFP, "fceholdfmod", 60);
options->sleep = iniparser_getint (config, INISEC_AFP, "sleep", 10) * 60 * 2;
- options->disconnect = iniparser_getint (config, INISEC_AFP, "disconnect" 24) * 60 * 2;
-
- options->k5service = iniparser_getstringdup(config, INISEC_AFP, "k5service", NULL);
- options->k5realm = iniparser_getstringdup(config, INISEC_AFP, "k5realm", NULL);
- options->authprintdir = iniparser_getstringdup(config, INISEC_AFP, "authprintdir", NULL);
- options->ipaddr = iniparser_getstringdup(config, INISEC_AFP, "ipaddr", NULL);
- options->hostname = iniparser_getstringdup(config, INISEC_AFP, "hostname", NULL);
- options->ntdomain = iniparser_getstringdup(config, INISEC_AFP, "ntdomain", NULL);
- options->ntseparator = iniparser_getstringdup(config, INISEC_AFP, "ntseparator", NULL);
- options->mimicmodel = iniparser_getstringdup(config, INISEC_AFP, "mimicmodel", NULL);
- options->adminauthuser = iniparser_getstringdup(config, INISEC_AFP, "adminauthuser", NULL);
+ 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) );
}
#endif /* ADMIN_GRP */
- p = iniparser_getstring(config, INISEC_AFP, "cnidserver", "localhost:4700");
- tmp = strrchr(p, ':');
- if (tmp)
- *t = 0;
- options->Cnid_srv = strdup(p);
- if (tmp)
- options->Cnid_port = strdup(tmp + 1);
+ q = iniparser_getstrdup(config, INISEC_AFP, "cnidserver", "localhost:4700");
+ r = strrchr(q, ':');
+ if (r)
+ *r = 0;
+ 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);
-
- if ((p = iniparser_getstring(config, INISEC_AFP, "fqdn", NULL))) {
+ if ((q = iniparser_getstrdup(config, INISEC_AFP, "fqdn", NULL))) {
/* do a little checking for the domain name. */
- tmp = strchr(c, ':');
- if (tmp)
- *tmp = '\0';
- if (gethostbyname(p)) {
- if (tmp)
- *tmp = ':';
- if ((opt = strdup(p)))
- options->fqdn = opt;
+ r = strchr(q, ':');
+ if (r)
+ *r = '\0';
+ if (gethostbyname(q)) {
+ if (r)
+ *r = ':';
+ EC_NULL_LOG( options->fqdn = strdup(q) );
} else {
LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
}
+ 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;
+ options->unixcodepage = strdup("LOCALE");
+ 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->maccharset = strdup(p);
+ 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);
+ }
}
if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) {
if (options->volnamelen > 255)
options->volnamelen = 255; /* AFP3 spec */
- return 1;
+EC_CLEANUP:
+ EC_EXIT;
}
/*
*/
static void show_paths( void )
{
- printf( " afpd.conf:\t%s\n", _PATH_AFPDCONF );
- printf( " AppleVolumes.system:\t%s\n", _PATH_AFPDSYSVOL );
- printf( " AppleVolumes.default:\t%s\n", _PATH_AFPDDEFVOL );
- printf( " afp_signature.conf:\t%s\n", _PATH_AFPDSIGCONF );
- printf( " afp_voluuid.conf:\t%s\n", _PATH_AFPDUUIDCONF );
-#ifdef HAVE_LDAP
- printf( " afp_ldap.conf:\t%s\n", _PATH_ACL_LDAPCONF );
-#else
- printf( " afp_ldap.conf:\tnot supported\n");
-#endif
+ printf( " afp.conf:\t%s\n", _PATH_CONFDIR "afp.conf");
+ printf( " afp_signature.conf:\t%s\n", _PATH_CONFDIR "afp_signature.conf");
+ printf( " afp_voluuid.conf:\t%s\n", _PATH_CONFDIR "afp_voluuid.conf");
printf( " UAM search path:\t%s\n", _PATH_AFPDUAMPATH );
printf( " Server messages path:\t%s\n", SERVERTEXT);
printf( " lockfile:\t%s\n", _PATH_AFPDLOCK);
/*
* Display usage information about afpd.
*/
-static void show_usage( char *name )
+static void show_usage(void)
{
- fprintf( stderr, "Usage:\t%s [-duptDTI] [-n nbpname]\n", name );
- fprintf( stderr, "\t [-c maxconnections] [-g guest] [-P pidfile] [-S port] [-L message]\n" );
- fprintf( stderr, "\t [-F configfile] [-U uams] [-m umask]\n" );
- fprintf( stderr, "\t%s -h|-v|-V\n", name );
+ fprintf( stderr, "Usage:\tafpd [-d] [-F configfile]\n");
+ fprintf( stderr, "\tafpd -h|-v|-V\n");
}
-int afp_options_parse_cmdline(int ac, char **av, struct afp_options *options)
+void afp_options_parse_cmdline(AFPObj *obj, 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;
- char buf[1024];
-
- if (gethostname(buf, sizeof(buf)) < 0 ) {
- perror( "gethostname" );
- return 0;
- }
- if (NULL != (p = strchr(buf, '.')))
- *p = '\0';
- options->hostname = strdup(buf);
- while (EOF != ( c = getopt( ac, av, OPTIONS )) ) {
+ while (EOF != ( c = getopt( ac, av, "dFvVh" )) ) {
switch ( c ) {
- case 'd' :
- options->flags |= OPTION_DEBUG;
+ case 'd':
+ obj->cmdlineflags |= OPTION_DEBUG;
break;
case 'F':
- options->configfile = optarg;
+ obj->cmdlineconfigfile = strdup(optarg);
break;
case 'v': /* version */
show_version( ); puts( "" );
exit( 0 );
break;
case 'h': /* usage */
- show_usage( p );
+ show_usage();
exit( 0 );
break;
default :
}
}
if ( err || optind != ac ) {
- show_usage( p );
+ show_usage();
exit( 2 );
}
- return 1;
+ return;
}