From: Frank Lahm Date: Tue, 14 Feb 2012 11:17:33 +0000 (+0100) Subject: Fix build X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=260c314546ffcfdbef47f2c7de82d5310b26df0a Fix build --- diff --git a/bin/ad/ad.c b/bin/ad/ad.c index 38fd62bb..2287ee6a 100644 --- a/bin/ad/ad.c +++ b/bin/ad/ad.c @@ -46,7 +46,7 @@ static void show_version(void) int main(int argc, char **argv) { - setuplog("default log_note /dev/tty"); + setuplog("default:note", "/dev/tty"); if (argc < 2) { usage_main(); diff --git a/bin/misc/Makefile.am b/bin/misc/Makefile.am index 426dc317..b8ec7040 100644 --- a/bin/misc/Makefile.am +++ b/bin/misc/Makefile.am @@ -17,6 +17,6 @@ fce_CFLAGS = -I$(top_srcdir)/include bin_PROGRAMS += afpldaptest afpldaptest_SOURCES = uuidtest.c -afpldaptest_CFLAGS = -D_PATH_ACL_LDAPCONF=\"$(pkgconfdir)/afp_ldap.conf\" +afpldaptest_CFLAGS = -D_PATH_CONFDIR=\"$(pkgconfdir)\" afpldaptest_LDADD = $(top_builddir)/libatalk/libatalk.la diff --git a/bin/misc/logger_test.c b/bin/misc/logger_test.c index b3ab7b53..585c1583 100644 --- a/bin/misc/logger_test.c +++ b/bin/misc/logger_test.c @@ -25,11 +25,11 @@ int main(int argc, char *argv[]) #endif /* filelog testing */ - setuplog("DSI log_maxdebug test.log"); + setuplog("DSI:maxdebug", "test.log"); LOG(log_info, logtype_dsi, "This should log."); LOG(log_error, logtype_default, "This should not log."); - setuplog("Default log_debug test.log"); + setuplog("Default:debug", "test.log"); LOG(log_debug, logtype_default, "This should log."); LOG(log_maxdebug, logtype_default, "This should not log."); diff --git a/bin/misc/uuidtest.c b/bin/misc/uuidtest.c index 0efc3318..81d11736 100644 --- a/bin/misc/uuidtest.c +++ b/bin/misc/uuidtest.c @@ -41,12 +41,14 @@ static void usage() static void parse_ldapconf() { static int inited = 0; + dictionary *iniconfig; if (! inited) { #ifdef HAVE_LDAP /* Parse afp_ldap.conf */ printf("Start parsing afp_ldap.conf\n"); - acl_ldap_readconfig(_PATH_ACL_LDAPCONF); + iniconfig = iniparser_load(_PATH_CONFDIR "afp.conf"); + acl_ldap_readconfig(iniconfig); printf("Finished parsing afp_ldap.conf\n"); if (ldap_config_valid) { if (ldap_auth_method == LDAP_AUTH_NONE) @@ -83,14 +85,14 @@ int main( int argc, char **argv) case 'v': if (! verbose) { verbose = 1; - setuplog("default log_maxdebug /dev/tty"); + setuplog("default:maxdebug", "/dev/tty"); logsetup = 1; } break; case 'u': if (! logsetup) - setuplog("default log_info /dev/tty"); + setuplog("default:info", "/dev/tty"); parse_ldapconf(); printf("Searching user: %s\n", optarg); ret = getuuidfromname( optarg, UUID_USER, uuid); @@ -103,7 +105,7 @@ int main( int argc, char **argv) case 'g': if (! logsetup) - setuplog("default log_info /dev/tty"); + setuplog("default:info", "/dev/tty"); parse_ldapconf(); printf("Searching group: %s\n", optarg); ret = getuuidfromname( optarg, UUID_GROUP, uuid); @@ -116,7 +118,7 @@ int main( int argc, char **argv) case 'i': if (! logsetup) - setuplog("default log_info /dev/tty"); + setuplog("default:info", "/dev/tty"); parse_ldapconf(); printf("Searching uuid: %s\n", optarg); uuid_string2bin(optarg, uuid); diff --git a/etc/afpd/Makefile.am b/etc/afpd/Makefile.am index 544c5843..747d84f5 100644 --- a/etc/afpd/Makefile.am +++ b/etc/afpd/Makefile.am @@ -45,14 +45,14 @@ afpd_SOURCES = \ afpd_LDADD = \ $(top_builddir)/libatalk/cnid/libcnid.la \ $(top_builddir)/libatalk/libatalk.la \ - @LIBGCRYPT_LIBS@ @QUOTA_LIBS@ @SLP_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @ZEROCONF_LIBS@ @PTHREAD_LIBS@ + @LIBGCRYPT_LIBS@ @QUOTA_LIBS@ @WRAP_LIBS@ @LIBADD_DL@ @ACL_LIBS@ @ZEROCONF_LIBS@ @PTHREAD_LIBS@ afpd_LDFLAGS = -export-dynamic afpd_CFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/sys \ - @SLP_CFLAGS@ @ZEROCONF_CFLAGS@ \ + @ZEROCONF_CFLAGS@ \ -DAPPLCNAME \ -DSERVERTEXT=\"$(SERVERTEXT)/\" \ -D_PATH_AFPDPWFILE=\"$(pkgconfdir)/afppasswd\" \ diff --git a/etc/afpd/afp_avahi.c b/etc/afpd/afp_avahi.c index 89ff95fd..ef7d5293 100644 --- a/etc/afpd/afp_avahi.c +++ b/etc/afpd/afp_avahi.c @@ -44,7 +44,7 @@ static void publish_reply(AvahiEntryGroup *g, */ static void register_stuff(void) { uint port; - const AFPConfig *config; + const AFPObj *obj; const struct vol *volume; DSI *dsi; char name[MAXINSTANCENAMELEN+1]; @@ -92,16 +92,12 @@ static void register_stuff(void) { } /* AFP server */ - for (config = ctx->configs; config; config = config->next) { - - dsi = (DSI *)config->obj.dsi; + for (dsi = obj->dsi; dsi; dsi = dsi->next) { port = getip_port((struct sockaddr *)&dsi->server); - if (convert_string(config->obj.options.unixcharset, + if (convert_string(obj->options.unixcharset, CH_UTF8, - config->obj.options.server ? - config->obj.options.server : - config->obj.options.hostname, + obj->options.hostname, -1, name, MAXINSTANCENAMELEN) <= 0) { @@ -146,8 +142,8 @@ static void register_stuff(void) { goto fail; } /* if */ - if (config->obj.options.mimicmodel) { - strlist2 = avahi_string_list_add_printf(strlist2, "model=%s", config->obj.options.mimicmodel); + if (obj->options.mimicmodel) { + strlist2 = avahi_string_list_add_printf(strlist2, "model=%s", obj->options.mimicmodel); if (avahi_entry_group_add_service_strlst(ctx->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, @@ -278,7 +274,7 @@ static void client_callback(AvahiClient *client, * Tries to setup the Zeroconf thread and any * neccessary config setting. */ -void av_zeroconf_register(const AFPConfig *configs) { +void av_zeroconf_register(const AFPObj *obj) { int error; /* initialize the struct that holds our config settings. */ @@ -287,7 +283,7 @@ void av_zeroconf_register(const AFPConfig *configs) { avahi_entry_group_reset(ctx->group); } else { ctx = calloc(1, sizeof(struct context)); - ctx->configs = configs; + ctx->obj = obj; assert(ctx); } diff --git a/etc/afpd/afp_avahi.h b/etc/afpd/afp_avahi.h index e516408c..f7d0473d 100644 --- a/etc/afpd/afp_avahi.h +++ b/etc/afpd/afp_avahi.h @@ -37,11 +37,11 @@ struct context { AvahiClient *client; AvahiEntryGroup *group; /* Netatalk stuff */ - const AFPConfig *configs; + const AFPObj *obj; }; /* prototype definitions */ -void av_zeroconf_register(const AFPConfig *configs); +void av_zeroconf_register(const AFPObj *obj); int av_zeroconf_unregister(void); #endif /* AFPD_AVAHI_H */ diff --git a/etc/afpd/afp_config.c b/etc/afpd/afp_config.c index f8596379..1fafee03 100644 --- a/etc/afpd/afp_config.c +++ b/etc/afpd/afp_config.c @@ -48,14 +48,13 @@ void configfree(AFPObj *obj, DSI *dsi) { DSI *p, *q; - afp_options_free(obj->options); + afp_options_free(&obj->options); for (p = obj->dsi; p; p = q) { q = p->next; if (p == dsi) continue; close(p->socket); - free(p->dsi); free(p); } if (dsi) { @@ -76,20 +75,21 @@ int configinit(AFPObj *obj) char *p, *q = NULL; LOG(log_debug, logtype_afpd, "DSIConfigInit: hostname: %s, listen: %s, port: %s", - obj->options->hostname, - obj->options->listen ? obj->options->listen : "(default: hostname)", - obj->options->port); + obj->options.hostname, + obj->options.listen ? obj->options.listen : "(default: hostname)", + obj->options.port); /* 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, ',') ); + EC_NULL( q = p = strdup(obj->options.listen) ); + EC_NULL( p = strtok(p, ",") ); while (p) { - if ((dsi = dsi_init(obj, obj->options->hostname, p, obj->options->port)) == NULL) + if ((dsi = dsi_init(obj, obj->options.hostname, p, obj->options.port)) == NULL) break; + status_init(obj, dsi); *next = dsi; next = &dsi->next; @@ -97,25 +97,24 @@ int configinit(AFPObj *obj) getip_string((struct sockaddr *)&dsi->server), getip_port((struct sockaddr *)&dsi->server)); - p = strtok(NULL, ','); + p = strtok(NULL, ","); } if (obj->dsi == NULL) EC_FAIL; - auth_load(obj->options->uampath, obj->options->uamlist); - status_init(obj); - set_signature(obj->options); + auth_load(obj->options.uampath, obj->options.uamlist); + set_signature(&obj->options); #ifdef HAVE_LDAP /* Parse afp_ldap.conf */ - acl_ldap_readconfig(AFPObj->iniconfig); + acl_ldap_readconfig(obj->iniconfig); #endif /* HAVE_LDAP */ /* Now register with zeroconf, we also need the volumes for that */ - if (! (AFPObj->options.flags & OPTION_NOZEROCONF)) { - load_volumes(AFPObj); - zeroconf_register(AFPObj); + if (! (obj->options.flags & OPTION_NOZEROCONF)) { + load_volumes(obj); + zeroconf_register(obj); } EC_CLEANUP: diff --git a/etc/afpd/afp_config.h b/etc/afpd/afp_config.h index 09cad9bb..bfa93c73 100644 --- a/etc/afpd/afp_config.h +++ b/etc/afpd/afp_config.h @@ -3,8 +3,9 @@ #include #include +#include -extern AFPConfig *configinit (struct afp_options *); -extern void configfree (AFPConfig *, const AFPConfig *); +extern int configinit (AFPObj *); +extern void configfree (AFPObj *, DSI *); #endif diff --git a/etc/afpd/afp_dsi.c b/etc/afpd/afp_dsi.c index 47dd4e46..2869722e 100644 --- a/etc/afpd/afp_dsi.c +++ b/etc/afpd/afp_dsi.c @@ -541,15 +541,15 @@ void afp_over_dsi(AFPObj *obj) if (debugging) { if (obj->options.logconfig) - setuplog(obj->options.logconfig); + setuplog(obj->options.logconfig, obj->options.logfile); else - setuplog("default log_note"); + setuplog("default:note", NULL); debugging = 0; } else { char logstr[50]; debugging = 1; - sprintf(logstr, "default log_maxdebug /tmp/afpd.%u.XXXXXX", getpid()); - setuplog(logstr); + sprintf(logstr, "/tmp/afpd.%u.XXXXXX", getpid()); + setuplog("default:maxdebug", logstr); } } diff --git a/etc/afpd/afp_options.c b/etc/afpd/afp_options.c index e39bf3f7..b4e2306d 100644 --- a/etc/afpd/afp_options.c +++ b/etc/afpd/afp_options.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "status.h" #include "auth.h" @@ -54,8 +55,8 @@ void afp_options_free(struct afp_options *opt) 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) @@ -64,6 +65,8 @@ void afp_options_free(struct afp_options *opt) free(opt->k5service); if (opt->logconfig) free(opt->logconfig); + if (opt->logfile) + free(opt->logfile); if (opt->loginmesg) free(opt->loginmesg); if (opt->maccodepage) @@ -78,8 +81,6 @@ void afp_options_free(struct afp_options *opt) free(opt->passwdfile); if (opt->port) free(opt->port); - if (opt->server) - free(opt->server); if (opt->signatureopt) free(opt->signatureopt); if (opt->uamlist) @@ -93,10 +94,12 @@ void afp_options_free(struct afp_options *opt) #define MAXVAL 1024 int afp_config_parse(AFPObj *AFPObj) { + 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]; memset(options, 0, sizeof(struct afp_options)); @@ -104,9 +107,16 @@ int afp_config_parse(AFPObj *AFPObj) 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 (EOF != (p = getopt(AFPObj->argc, AFPObj->argv, "dF:"))) { - switch (p) { + while ((c = getopt(AFPObj->argc, AFPObj->argv, "dF:")) != -1) { + switch (c) { case 'd': options->flags |= OPTION_DEBUG; break; @@ -125,10 +135,10 @@ int afp_config_parse(AFPObj *AFPObj) AFPObj->iniconfig = config; /* [Global] */ - options->logconfig = iniparser_getstring(config, INISEC_GLOBAL, "loglevel", "default:note"); - options->logfile = iniparser_getstring(config, INISEC_GLOBAL, "logfile", NULL); + options->logconfig = iniparser_getstrdup(config, INISEC_GLOBAL, "loglevel", "default:note"); + options->logfile = iniparser_getstrdup(config, INISEC_GLOBAL, "logfile", NULL); set_processname("afpd"); - setuplog(logconfig, logfile); + setuplog(options->logconfig, options->logfile); /* [AFP] "options" options wo values */ p = iniparser_getstring(config, INISEC_AFP, "options", ""); @@ -190,7 +200,7 @@ int afp_config_parse(AFPObj *AFPObj) 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->disconnected = iniparser_getint (config, INISEC_AFP, "disconnect", 24) * 60 * 2; if ((p = iniparser_getstring(config, INISEC_AFP, "k5keytab", NULL))) { @@ -207,29 +217,30 @@ int afp_config_parse(AFPObj *AFPObj) } #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); 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"); @@ -245,7 +256,7 @@ int afp_config_parse(AFPObj *AFPObj) options->maccharset = CH_MAC; LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p); } else { - options->maccharset = strdup(p); + options->maccodepage = strdup(p); } if ((p = iniparser_getstring(config, INISEC_AFP, "fcelistener", NULL))) { @@ -275,7 +286,8 @@ int afp_config_parse(AFPObj *AFPObj) if (options->volnamelen > 255) options->volnamelen = 255; /* AFP3 spec */ - return 0; +EC_CLEANUP: + EC_EXIT; } /* @@ -404,16 +416,9 @@ static void show_version_extended(void ) */ 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); @@ -430,20 +435,11 @@ static void show_usage( char *name ) fprintf( stderr, "\t%s -h|-v|-V\n", name ); } -int afp_options_parse_cmdline(int ac, char **av) +void afp_options_parse_cmdline(int ac, char **av) { 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, "vVh" )) ) { switch ( c ) { @@ -470,5 +466,5 @@ int afp_options_parse_cmdline(int ac, char **av) exit( 2 ); } - return 1; + return; } diff --git a/etc/afpd/afp_zeroconf.c b/etc/afpd/afp_zeroconf.c index d6fa6577..64347be3 100644 --- a/etc/afpd/afp_zeroconf.c +++ b/etc/afpd/afp_zeroconf.c @@ -22,7 +22,7 @@ /* * Functions (actually they are just facades) */ -void zeroconf_register(const AFPConfig *configs) +void zeroconf_register(const AFPObj *configs) { #if defined (HAVE_AVAHI) LOG(log_debug, logtype_afpd, "Attempting to register with mDNS using Avahi"); diff --git a/etc/afpd/afp_zeroconf.h b/etc/afpd/afp_zeroconf.h index e2711afb..5058cc60 100644 --- a/etc/afpd/afp_zeroconf.h +++ b/etc/afpd/afp_zeroconf.h @@ -19,7 +19,7 @@ /* * registers service with a particular Zerconf implemenation. */ -void zeroconf_register(const AFPConfig *configs); +void zeroconf_register(const AFPObj *obj); /* * de-registers the ntpd service with a particular Zerconf implemenation. diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index d6382c84..aff77956 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -655,9 +655,6 @@ static int get_version(AFPObj *obj, char *ibuf, size_t ibuflen, size_t len) if ( i == num ) /* An inappropo version */ return AFPERR_BADVERS ; - if (afp_version >= 30 && obj->proto != AFPPROTO_DSI) - return AFPERR_BADVERS ; - /* FIXME Hack */ if (afp_version >= 30 && sizeof(off_t) != 8) { LOG(log_error, logtype_afpd, "get_version: no LARGE_FILE support recompile!" ); diff --git a/etc/afpd/desktop.c b/etc/afpd/desktop.c index c03f0769..258f3e5f 100644 --- a/etc/afpd/desktop.c +++ b/etc/afpd/desktop.c @@ -204,42 +204,34 @@ int afp_addicon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t */ addicon_err: if ( cc < 0 ) { - if (obj->proto == AFPPROTO_DSI) { - dsi_writeinit(obj->dsi, rbuf, buflen); - dsi_writeflush(obj->dsi); - } + dsi_writeinit(obj->dsi, rbuf, buflen); + dsi_writeflush(obj->dsi); return cc; } - switch (obj->proto) { - case AFPPROTO_DSI: - { - DSI *dsi = obj->dsi; + DSI *dsi = obj->dsi; - iovcnt = dsi_writeinit(dsi, rbuf, buflen); + iovcnt = dsi_writeinit(dsi, rbuf, buflen); - /* add headers at end of file */ - if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } + /* add headers at end of file */ + if ((cc == 0) && (write(si.sdt_fd, imh, sizeof(imh)) < 0)) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; + } - while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { - if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { - LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); - dsi_writeflush(dsi); - return AFPERR_PARAM; - } - } + while ((iovcnt = dsi_write(dsi, rbuf, buflen))) { + if ((cc = write(si.sdt_fd, rbuf, iovcnt)) < 0) { + LOG(log_error, logtype_afpd, "afp_addicon(%s): write: %s", icon_dtfile(vol, fcreator), strerror(errno)); + dsi_writeflush(dsi); + return AFPERR_PARAM; } - break; } close( si.sdt_fd ); @@ -441,7 +433,7 @@ int afp_geticon(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t #define min(a,b) ((a)<(b)?(a):(b)) rc = min( bsize, rsize ); - if ((obj->proto == AFPPROTO_DSI) && (buflen < rc)) { + if (buflen < rc) { DSI *dsi = obj->dsi; struct stat st; off_t size; diff --git a/etc/afpd/fce_util.c b/etc/afpd/fce_util.c index 672adac8..75bc3f4b 100644 --- a/etc/afpd/fce_util.c +++ b/etc/afpd/fce_util.c @@ -172,7 +172,7 @@ bool fce_handle_coalescation( char *path, int is_dir, int mode ) * all|delete|create */ -int fce_set_coalesce(char *opt) +int fce_set_coalesce(const char *opt) { char *e; char *p; diff --git a/etc/afpd/file.c b/etc/afpd/file.c index 06ba8c19..c8101048 100644 --- a/etc/afpd/file.c +++ b/etc/afpd/file.c @@ -76,22 +76,16 @@ static int default_type(void *finder) /* FIXME path : unix or mac name ? (for now it's unix name ) */ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *adp, void *data, int islink) { - struct extmap *em; void *ad_finder = NULL; int chk_ext = 0; - - if (adp) + ad_finder = ad_entry(adp, ADEID_FINDERI); if (ad_finder) { memcpy(data, ad_finder, ADEDLEN_FINDERI); - /* default type ? */ - if (default_type(ad_finder)) - chk_ext = 1; } else { memcpy(data, ufinderi, ADEDLEN_FINDERI); - chk_ext = 1; if (vol_inv_dots(vol) && *upath == '.') { /* make it invisible */ uint16_t ashort; @@ -107,14 +101,8 @@ void *get_finderinfo(const struct vol *vol, const char *upath, struct adouble *a memcpy((char *)data + FINDERINFO_FRFLAGOFF, &linkflag, 2); memcpy((char *)data + FINDERINFO_FRTYPEOFF,"slnk",4); memcpy((char *)data + FINDERINFO_FRCREATOFF,"rhap",4); - chk_ext = 0; } - /** Only enter if no appledouble information and no finder information found. */ - if (chk_ext && (em = getextmap( upath ))) { - memcpy(data, em->em_type, sizeof( em->em_type )); - memcpy((char *)data + 4, em->em_creator, sizeof(em->em_creator)); - } return data; } @@ -1004,17 +992,6 @@ int setfilparams(struct vol *vol, ad_setdate(adp, AD_DATE_BACKUP, bdate); break; case FILPBIT_FINFO : - if (default_type( ad_entry( adp, ADEID_FINDERI )) - && ( - ((em = getextmap( path->m_name )) && - !memcmp(finder_buf, em->em_type, sizeof( em->em_type )) && - !memcmp(finder_buf + 4, em->em_creator,sizeof( em->em_creator))) - || ((em = getdefextmap()) && - !memcmp(finder_buf, em->em_type, sizeof( em->em_type )) && - !memcmp(finder_buf + 4, em->em_creator,sizeof( em->em_creator))) - )) { - memcpy(finder_buf, ufinderi, 8 ); - } memcpy(ad_entry( adp, ADEID_FINDERI ), finder_buf, 32 ); break; case FILPBIT_UNIXPR : diff --git a/etc/afpd/fork.c b/etc/afpd/fork.c index 8e0ba732..89f15e18 100644 --- a/etc/afpd/fork.c +++ b/etc/afpd/fork.c @@ -851,7 +851,7 @@ static int read_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, si /* dsi can stream requests. we can only do this if we're not checking * for an end-of-line character. oh well. */ - if ((obj->proto == AFPPROTO_DSI) && (*rbuflen < reqcount) && !nlmask) { + if ((*rbuflen < reqcount) && !nlmask) { DSI *dsi = obj->dsi; off_t size; @@ -1191,63 +1191,56 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s goto afp_write_err; } - /* this is yucky, but dsi can stream i/o and asp can't */ - switch (obj->proto) { - case AFPPROTO_DSI: - { - DSI *dsi = obj->dsi; - /* find out what we have already and write it out. */ - cc = dsi_writeinit(dsi, rbuf, *rbuflen); + DSI *dsi = obj->dsi; + /* find out what we have already and write it out. */ + cc = dsi_writeinit(dsi, rbuf, *rbuflen); - if (!cc || (cc = write_file(ofork, eid, offset, rbuf, cc)) < 0) { + if (!cc || (cc = write_file(ofork, eid, offset, rbuf, cc)) < 0) { + dsi_writeflush(dsi); + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum); + return cc; + } + + offset += cc; + +#if 0 /*def HAVE_SENDFILE_WRITE*/ + if (!(obj->options.flags & OPTION_DEBUG)) { + if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket, + offset, dsi->datasize)) < 0) { + switch (errno) { + case EDQUOT : + case EFBIG : + case ENOSPC : + cc = AFPERR_DFULL; + break; + default : + LOG(log_error, logtype_afpd, "afp_write: ad_writefile: %s", strerror(errno) ); + goto afp_write_loop; + } dsi_writeflush(dsi); *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum); + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, + reqcount, ofork->of_refnum); return cc; } offset += cc; - -#if 0 /*def HAVE_SENDFILE_WRITE*/ - if (!(obj->options.flags & OPTION_DEBUG)) { - if ((cc = ad_writefile(ofork->of_ad, eid, dsi->socket, - offset, dsi->datasize)) < 0) { - switch (errno) { - case EDQUOT : - case EFBIG : - case ENOSPC : - cc = AFPERR_DFULL; - break; - default : - LOG(log_error, logtype_afpd, "afp_write: ad_writefile: %s", strerror(errno) ); - goto afp_write_loop; - } - dsi_writeflush(dsi); - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, - reqcount, ofork->of_refnum); - return cc; - } - - offset += cc; - goto afp_write_done; - } + goto afp_write_done; + } #endif /* 0, was HAVE_SENDFILE_WRITE */ - /* loop until everything gets written. currently - * dsi_write handles the end case by itself. */ - while ((cc = dsi_write(dsi, rbuf, *rbuflen))) { - if ((cc = write_file(ofork, eid, offset, rbuf, cc)) < 0) { - dsi_writeflush(dsi); - *rbuflen = 0; - ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, - reqcount, ofork->of_refnum); - return cc; - } - offset += cc; + /* loop until everything gets written. currently + * dsi_write handles the end case by itself. */ + while ((cc = dsi_write(dsi, rbuf, *rbuflen))) { + if ((cc = write_file(ofork, eid, offset, rbuf, cc)) < 0) { + dsi_writeflush(dsi); + *rbuflen = 0; + ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, + reqcount, ofork->of_refnum); + return cc; } - } - break; + offset += cc; } ad_tmplock(ofork->of_ad, eid, ADLOCK_CLR, saveoff, reqcount, ofork->of_refnum); @@ -1264,10 +1257,9 @@ static int write_fork(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, s return( AFP_OK ); afp_write_err: - if (obj->proto == AFPPROTO_DSI) { - dsi_writeinit(obj->dsi, rbuf, *rbuflen); - dsi_writeflush(obj->dsi); - } + dsi_writeinit(obj->dsi, rbuf, *rbuflen); + dsi_writeflush(obj->dsi); + if (err != AFP_OK) { *rbuflen = 0; } diff --git a/etc/afpd/main.c b/etc/afpd/main.c index d96d52db..8729fc12 100644 --- a/etc/afpd/main.c +++ b/etc/afpd/main.c @@ -43,7 +43,7 @@ unsigned char nologin = 0; -static AFPObj AFPObj; +static AFPObj obj; static server_child *server_children; static sig_atomic_t reloadconfig = 0; static sig_atomic_t gotsigchld = 0; @@ -62,7 +62,7 @@ static void afp_exit(void) { if (parent_or_child == 0) /* Only do this in the parent */ - server_unlock(default_options.pidfile); + server_unlock(_PATH_AFPDLOCK); } @@ -71,7 +71,7 @@ static void afp_exit(void) */ static void fd_set_listening_sockets(const AFPObj *config) { - const DSI *dsi; + DSI *dsi; for (dsi = config->dsi; dsi; dsi = dsi->next) { fdset_add_fd(config->options.connections + AFP_LISTENERS + FDSET_SAFETY, @@ -119,7 +119,7 @@ static void afp_goaway(int sig) LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGTERM"); break; case SIGQUIT: - if (default_options.flags & OPTION_KEEPSESSIONS) { + if (obj.options.flags & OPTION_KEEPSESSIONS) { LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGQUIT, NOT disconnecting clients"); } else { LOG(log_note, logtype_afpd, "AFP Server shutting down on SIGQUIT"); @@ -130,8 +130,8 @@ static void afp_goaway(int sig) if (server_children) server_child_kill(server_children, CHILD_DSIFORK, sig); - server_unlock(AFPObj->options.pidfile); - exit(0); + server_unlock(_PATH_AFPDLOCK); + _exit(0); break; case SIGUSR1 : @@ -220,15 +220,16 @@ int main(int ac, char **av) int ret; /* Parse argv args and initialize default options */ - AFPObj.argc = ac; - AFPObj.argv = av; - if (afp_config_parse(&AFPObj) != 0) + afp_options_parse_cmdline(ac, av); + obj.argc = ac; + obj.argv = av; + if (afp_config_parse(&obj) != 0) exit(EXITERR_CONF); if (check_lockfile("afpd", _PATH_AFPDLOCK) != 0) exit(EXITERR_SYS); - if (!(AFPObj.options.flags & OPTION_DEBUG) && (daemonize(0, 0) != 0)) + if (!(obj.options.flags & OPTION_DEBUG) && (daemonize(0, 0) != 0)) exit(EXITERR_SYS); if (create_lockfile("afpd", _PATH_AFPDLOCK) != 0) @@ -239,13 +240,12 @@ int main(int ac, char **av) atexit(afp_exit); /* Save the user's current umask */ - AFPObj.options.save_mask = umask(AFPObj.options.umask); + obj.options.save_mask = umask(obj.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(AFPObj.options.connections, - CHILD_NFORKS))) { + if (!(server_children = server_child_alloc(obj.options.connections, CHILD_NFORKS))) { LOG(log_error, logtype_afpd, "main: server_child alloc: %s", strerror(errno) ); exit(EXITERR_SYS); } @@ -343,7 +343,7 @@ int main(int ac, char **av) sigaddset(&sigs, SIGCHLD); pthread_sigmask(SIG_BLOCK, &sigs, NULL); - if (configinit(&AFPObj) != 0) { + if (configinit(&obj) != 0) { LOG(log_error, logtype_afpd, "main: no servers configured"); exit(EXITERR_CONF); } @@ -354,12 +354,12 @@ int main(int ac, char **av) /* watch atp, dsi sockets and ipc parent/child file descriptor. */ - if (AFPObj.options.flags & OPTION_KEEPSESSIONS) { + if (obj.options.flags & OPTION_KEEPSESSIONS) { LOG(log_note, logtype_afpd, "Activating continous service"); disasociated_ipc_fd = ipc_server_uds(_PATH_AFP_IPC); } - fd_set_listening_sockets(&AFPObj); + fd_set_listening_sockets(&obj); /* set limits */ (void)setlimits(); @@ -391,17 +391,17 @@ int main(int ac, char **av) if (reloadconfig) { nologin++; auth_unload(); - fd_reset_listening_sockets(&AFPObj); + fd_reset_listening_sockets(&obj); LOG(log_info, logtype_afpd, "re-reading configuration file"); - configfree(&AFPObj, NULL); - if (configinit(&AFPObj) != 0) { + configfree(&obj, NULL); + if (configinit(&obj) != 0) { LOG(log_error, logtype_afpd, "config re-read: no servers configured"); exit(EXITERR_CONF); } - fd_set_listening_sockets(&AFPObj); + fd_set_listening_sockets(&obj); nologin = 0; reloadconfig = 0; @@ -424,9 +424,9 @@ int main(int ac, char **av) switch (polldata[i].fdtype) { case LISTEN_FD: - if (child = dsi_start(AFPObj, (DSI *)polldata[i].data, server_children)) { + if (child = dsi_start(&obj, (DSI *)polldata[i].data, server_children)) { /* Add IPC fd to select fd set */ - fdset_add_fd(AFPObj.options.connections + AFP_LISTENERS + FDSET_SAFETY, + fdset_add_fd(obj.options.connections + AFP_LISTENERS + FDSET_SAFETY, &fdset, &polldata, &fdset_used, @@ -445,7 +445,7 @@ int main(int ac, char **av) fdset_del_fd(&fdset, &polldata, &fdset_used, &fdset_size, child->ipc_fds[0]); close(child->ipc_fds[0]); child->ipc_fds[0] = -1; - if ((AFPObj.options.flags & OPTION_KEEPSESSIONS) && child->disasociated) { + if ((obj.options.flags & OPTION_KEEPSESSIONS) && child->disasociated) { LOG(log_note, logtype_afpd, "main: removing reattached child[%u]", child->pid); server_child_remove(server_children, CHILD_DSIFORK, child->pid); } @@ -470,7 +470,7 @@ int main(int ac, char **av) break; } child->disasociated = 1; - fdset_add_fd(AFPObj.options.connections + AFP_LISTENERS + FDSET_SAFETY, + fdset_add_fd(obj.options.connections + AFP_LISTENERS + FDSET_SAFETY, &fdset, &polldata, &fdset_used, diff --git a/etc/afpd/messages.c b/etc/afpd/messages.c index cd3f32f7..e2dd1535 100644 --- a/etc/afpd/messages.c +++ b/etc/afpd/messages.c @@ -20,7 +20,6 @@ #include "misc.h" - #define MAXMESGSIZE 199 /* this is only used by afpd children, so it's okay. */ @@ -44,7 +43,7 @@ void readmessage(AFPObj *obj) uid_t euid; uint32_t maxmsgsize; - maxmsgsize = (obj->proto == AFPPROTO_DSI)?MIN(MAX(((DSI*)obj->dsi)->attn_quantum, MAXMESGSIZE),MAXPATHLEN):MAXMESGSIZE; + maxmsgsize = MIN(MAX(obj->dsi->attn_quantum, MAXMESGSIZE), MAXPATHLEN); i=0; /* Construct file name SERVERTEXT/message.[pid] */ @@ -121,7 +120,7 @@ int afp_getsrvrmesg(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, siz *rbuflen = 0; - msgsize = (obj->proto == AFPPROTO_DSI)?MAX(((DSI*)obj->dsi)->attn_quantum, MAXMESGSIZE):MAXMESGSIZE; + msgsize = MAX(obj->dsi->attn_quantum, MAXMESGSIZE); memcpy(&type, ibuf + 2, sizeof(type)); memcpy(&bitmap, ibuf + 4, sizeof(bitmap)); diff --git a/etc/afpd/status.c b/etc/afpd/status.c index 4aa134e9..0f45ce45 100644 --- a/etc/afpd/status.c +++ b/etc/afpd/status.c @@ -364,7 +364,7 @@ static size_t status_utf8servername(char *data, int *nameoffset, */ /* extract the obj part of the server */ - Obj = (char *) (options->server ? options->server : options->hostname); + Obj = options->hostname; if ((size_t) -1 == (len = convert_string ( options->unixcharset, CH_UTF8_MAC, Obj, -1, data+sizeof(namelen), maxstatuslen-offset )) ) { @@ -413,36 +413,27 @@ static void status_icon(char *data, const unsigned char *icondata, /* --------------------- */ -void status_init(AFPConfig *dsiconfig, - const struct afp_options *options) +void status_init(AFPObj *obj, DSI *dsi) { - DSI *dsi; - char *status = NULL; + char *status = dsi->status; size_t statuslen; - int c, sigoff, ipok; - - if (!dsiconfig || !options) - return; - - ipok = 0; - if (dsiconfig) { - status = dsiconfig->status; - maxstatuslen=sizeof(dsiconfig->status); - dsi = dsiconfig->obj.dsi; - if (dsi->server.ss_family == AF_INET) { /* IPv4 */ - const struct sockaddr_in *sa4 = (struct sockaddr_in *)&dsi->server; - ipok = sa4->sin_addr.s_addr ? 1 : 0; - } else { /* IPv6 */ - const struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&dsi->server; - for (int i=0; i<16; i++) { - if (sa6->sin6_addr.s6_addr[i]) { - ipok = 1; - break; - } + int c, sigoff, ipok = 0; + const struct afp_options *options = &obj->options; + + maxstatuslen = sizeof(dsi->status); + + if (dsi->server.ss_family == AF_INET) { /* IPv4 */ + const struct sockaddr_in *sa4 = (struct sockaddr_in *)&dsi->server; + ipok = sa4->sin_addr.s_addr ? 1 : 0; + } else { /* IPv6 */ + const struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&dsi->server; + for (int i=0; i<16; i++) { + if (sa6->sin6_addr.s6_addr[i]) { + ipok = 1; + break; } } - } else - dsi = NULL; + } /* * These routines must be called in order -- earlier calls @@ -465,14 +456,13 @@ void status_init(AFPConfig *dsiconfig, */ status_flags(status, - options->server_notif, + options->flags & OPTION_SERVERNOTIF, (options->fqdn || ipok), options->passwdbits, (options->k5service && options->k5realm && options->fqdn), options->flags); /* returns offset to signature offset */ - c = status_server(status, options->server ? options->server : - options->hostname, options); + c = status_server(status, options->hostname, options); status_machine(status); status_versions(status, dsi); status_uams(status, options->uamlist); @@ -493,14 +483,12 @@ void status_init(AFPConfig *dsiconfig, if ( statuslen < maxstatuslen) statuslen = status_utf8servername(status, &c, dsi, options); - if (dsiconfig) { - if ((options->flags & OPTION_CUSTOMICON) == 0) { - status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0); - } - dsi_setstatus(dsi, status, statuslen); - dsiconfig->signature = status + sigoff; - dsiconfig->statuslen = statuslen; + if ((options->flags & OPTION_CUSTOMICON) == 0) { + status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0); } + + dsi->signature = status + sigoff; + dsi->statuslen = statuslen; } /* set_signature() */ @@ -522,7 +510,7 @@ void set_signature(struct afp_options *options) { size_t len; char *server_tmp; - server_tmp = (options->server ? options->server : options->hostname); + server_tmp = options->hostname; if (strcmp(options->signatureopt, "auto") == 0) { goto server_signature_auto; /* default */ } else if (strcmp(options->signatureopt, "host") == 0) { @@ -682,9 +670,8 @@ server_signature_done: /* this is the same as asp/dsi_getstatus */ int afp_getsrvrinfo(AFPObj *obj, char *ibuf _U_, size_t ibuflen _U_, char *rbuf, size_t *rbuflen) { - AFPConfig *config = obj->config; + memcpy(rbuf, obj->dsi->status, obj->dsi->statuslen); + *rbuflen = obj->dsi->statuslen; - memcpy(rbuf, config->status, config->statuslen); - *rbuflen = config->statuslen; return AFP_OK; } diff --git a/etc/afpd/status.h b/etc/afpd/status.h index 1a1365e3..3057b759 100644 --- a/etc/afpd/status.h +++ b/etc/afpd/status.h @@ -41,7 +41,7 @@ extern void status_versions (char * /*status*/, const DSI *); extern void status_uams (char * /*status*/, const char * /*authlist*/); -extern void status_init (AFPConfig *, const struct afp_options *); +extern void status_init (AFPObj *, DSI *dsi); extern void set_signature(struct afp_options *); /* FP functions */ diff --git a/etc/afpd/uam.c b/etc/afpd/uam.c index 8adfb3bb..0d7b6b2b 100644 --- a/etc/afpd/uam.c +++ b/etc/afpd/uam.c @@ -372,7 +372,7 @@ int uam_afpserver_option(void *private, const int what, void *option, break; case UAM_OPTION_SIGNATURE: - *buf = (void *) (((AFPConfig *)obj->config)->signature); + *buf = (void *)obj->dsi->signature; if (len) *len = 16; break; @@ -390,10 +390,6 @@ int uam_afpserver_option(void *private, const int what, void *option, *len = strlen(obj->options.hostname); break; - case UAM_OPTION_PROTOCOL: - *((int *) option) = obj->proto; - break; - case UAM_OPTION_CLIENTNAME: { struct DSI *dsi = obj->dsi; diff --git a/etc/afpd/unix.c b/etc/afpd/unix.c index 1688c9ab..21602ab1 100644 --- a/etc/afpd/unix.c +++ b/etc/afpd/unix.c @@ -266,17 +266,17 @@ int setdeskmode(const mode_t mode) } if (S_ISDIR(st.st_mode)) { - if ( chmod_acl( modbuf, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( modbuf, (DIRBITS | mode)) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) ); } - } else if ( chmod_acl( modbuf, mode & ~(default_options.umask | EXEC_MODE) ) < 0 && errno != EPERM ) { + } else if ( chmod_acl( modbuf, mode & ~EXEC_MODE ) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(modbuf), strerror(errno) ); } } closedir( sub ); /* XXX: need to preserve special modes */ - if ( chmod_acl( deskp->d_name, (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( deskp->d_name, (DIRBITS | mode)) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s",fullpathname(deskp->d_name), strerror(errno) ); } } @@ -286,7 +286,7 @@ int setdeskmode(const mode_t mode) return -1; } /* XXX: need to preserve special modes */ - if ( chmod_acl( ".AppleDesktop", (DIRBITS | mode) & ~default_options.umask ) < 0 && errno != EPERM ) { + if ( chmod_acl( ".AppleDesktop", (DIRBITS | mode)) < 0 && errno != EPERM ) { LOG(log_error, logtype_afpd, "setdeskmode: chmod %s: %s", fullpathname(".AppleDesktop"),strerror(errno) ); } return( 0 ); diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index f09381b3..73904fc4 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -152,7 +152,6 @@ static void volfree(struct vol_option *options, const struct vol_option *save) * $s -> server name (hostname if it doesn't exist) * $u -> username (guest is usually nobody) * $v -> volume name or basename if null - * $z -> zone (may not exist) * $$ -> $ * * This get's called from readvolfile with @@ -253,12 +252,7 @@ static char *volxlate(AFPObj *obj, DSI *dsi = obj->dsi; q = getip_string((struct sockaddr *)&dsi->client); } else if (is_var(p, "$s")) { - if (obj->Obj) - q = obj->Obj; - else if (obj->options.server) { - q = obj->options.server; - } else - q = obj->options.hostname; + q = obj->options.hostname; } else if (obj->username && is_var(p, "$u")) { if (afpmaster && xlatevolname) return NULL; @@ -279,8 +273,6 @@ static char *volxlate(AFPObj *obj, else if (*(q + 1) != '\0') q++; } - } else if (is_var(p, "$z")) { - q = obj->Zone; } else if (is_var(p, "$$")) { q = "$"; } else @@ -309,7 +301,7 @@ static char *volxlate(AFPObj *obj, } /* -------------------- */ -static void setoption(struct vol_option *options, struct vol_option *save, int opt, const char *val) +static void setoption(struct vol_option *options, const struct vol_option *save, int opt, const char *val) { if (options[opt].c_value && (!save || options[opt].c_value != save[opt].c_value)) free(options[opt].c_value); @@ -320,72 +312,72 @@ static void setoption(struct vol_option *options, struct vol_option *save, int o static void volset(const dictionary *conf, const char *vol, struct vol_option *options, const struct vol_option *save) { const char *val; - const char *p; + char *p, *q; - if (val = iniparser_getstring(conf, vol, "allow")) + if (val = iniparser_getstring(conf, vol, "allow", NULL)) setoption(options, save, VOLOPT_ALLOW, val); - if (val = iniparser_getstring(conf, vol, "deny")) + if (val = iniparser_getstring(conf, vol, "deny", NULL)) setoption(options, save, VOLOPT_DENY, val); - if (val = iniparser_getstring(conf, vol, "rwlist")) + if (val = iniparser_getstring(conf, vol, "rwlist", NULL)) setoption(options, save, VOLOPT_RWLIST, val); - if (val = iniparser_getstring(conf, vol, "rolist")) + if (val = iniparser_getstring(conf, vol, "rolist", NULL)) setoption(options, save, VOLOPT_ROLIST, val); - if (val = iniparser_getstring(conf, vol, "volcharset")) + if (val = iniparser_getstring(conf, vol, "volcharset", NULL)) setoption(options, save, VOLOPT_ENCODING, val); - if (val = iniparser_getstring(conf, vol, "maccharset")) + if (val = iniparser_getstring(conf, vol, "maccharset", NULL)) setoption(options, save, VOLOPT_MACCHARSET, val); - if (val = iniparser_getstring(conf, vol, "veto")) + if (val = iniparser_getstring(conf, vol, "veto", NULL)) setoption(options, save, VOLOPT_VETO, val); - if (val = iniparser_getstring(conf, vol, "cnidscheme")) + if (val = iniparser_getstring(conf, vol, "cnidscheme", NULL)) setoption(options, save, VOLOPT_CNIDSCHEME, val); - if (val = iniparser_getstring(conf, vol, "dbpath")) + if (val = iniparser_getstring(conf, vol, "dbpath", NULL)) setoption(options, save, VOLOPT_DBPATH, val); - if (val = iniparser_getstring(conf, vol, "password")) + if (val = iniparser_getstring(conf, vol, "password", NULL)) setoption(options, save, VOLOPT_PASSWORD, val); - if (val = iniparser_getstring(conf, vol, "root_preexec")) + if (val = iniparser_getstring(conf, vol, "root_preexec", NULL)) setoption(options, save, VOLOPT_ROOTPREEXEC, val); - if (val = iniparser_getstring(conf, vol, "preexec")) + if (val = iniparser_getstring(conf, vol, "preexec", NULL)) setoption(options, save, VOLOPT_PREEXEC, val); - if (val = iniparser_getstring(conf, vol, "root_postexec")) + if (val = iniparser_getstring(conf, vol, "root_postexec", NULL)) setoption(options, save, VOLOPT_ROOTPOSTEXEC, val); - if (val = iniparser_getstring(conf, vol, "postexec")) + if (val = iniparser_getstring(conf, vol, "postexec", NULL)) setoption(options, save, VOLOPT_POSTEXEC, val); - if (val = iniparser_getstring(conf, vol, "allowed_hosts")) + if (val = iniparser_getstring(conf, vol, "allowed_hosts", NULL)) setoption(options, save, VOLOPT_ALLOWED_HOSTS, val); - if (val = iniparser_getstring(conf, vol, "denied_hosts")) + if (val = iniparser_getstring(conf, vol, "denied_hosts", NULL)) setoption(options, save, VOLOPT_DENIED_HOSTS, val); - if (val = iniparser_getstring(conf, vol, "umask")) + if (val = iniparser_getstring(conf, vol, "umask", NULL)) options[VOLOPT_UMASK].i_value = (int)strtol(val, NULL, 8); - if (val = iniparser_getstring(conf, vol, "dperm")) + if (val = iniparser_getstring(conf, vol, "dperm", NULL)) options[VOLOPT_DPERM].i_value = (int)strtol(val, NULL, 8); - if (val = iniparser_getstring(conf, vol, "fperm")) + if (val = iniparser_getstring(conf, vol, "fperm", NULL)) options[VOLOPT_FPERM].i_value = (int)strtol(val, NULL, 8); - if (val = iniparser_getstring(conf, vol, "perm")) + if (val = iniparser_getstring(conf, vol, "perm", NULL)) options[VOLOPT_DFLTPERM].i_value = (int)strtol(val, NULL, 8); - if (val = iniparser_getstring(conf, vol, "volsizelimit")) + if (val = iniparser_getstring(conf, vol, "volsizelimit", NULL)) options[VOLOPT_LIMITSIZE].i_value = (uint32_t)strtoul(val, NULL, 10); - if (val = iniparser_getstring(conf, vol, "casefold")) { + if (val = iniparser_getstring(conf, vol, "casefold", NULL)) { if (strcasecmp(val, "tolower") == 0) options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER; else if (strcasecmp(val, "toupper") == 0) @@ -396,14 +388,14 @@ static void volset(const dictionary *conf, const char *vol, struct vol_option *o options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER; } - if (val = iniparser_getstring(conf, vol, "adouble")) { + if (val = iniparser_getstring(conf, vol, "adouble", NULL)) { if (strcasecmp(val, "v2") == 0) options[VOLOPT_ADOUBLE].i_value = AD_VERSION2; else if (strcasecmp(val, "ea") == 0) options[VOLOPT_ADOUBLE].i_value = AD_VERSION_EA; } - if (val = iniparser_getstring(conf, vol, "ea")) { + if (val = iniparser_getstring(conf, vol, "ea", NULL)) { if (strcasecmp(val, "ad") == 0) options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_AD; else if (strcasecmp(val, "sys") == 0) @@ -412,19 +404,19 @@ static void volset(const dictionary *conf, const char *vol, struct vol_option *o options[VOLOPT_EA_VFS].i_value = AFPVOL_EA_NONE; } - if (val = iniparser_getstrdup(conf, vol, "cnidserver")) { - if (p = strrchr(val, ':')) { - *p = 0; - setoption(options, save, VOLOPT_CNIDPORT, p + 1); + if (p = iniparser_getstrdup(conf, vol, "cnidserver", NULL)) { + if (q = strrchr(val, ':')) { + *q = 0; + setoption(options, save, VOLOPT_CNIDPORT, q + 1); } - setoption(options, save, VOLOPT_CNIDSERVER, val); + setoption(options, save, VOLOPT_CNIDSERVER, p); LOG(log_debug, logtype_afpd, "CNID Server for volume '%s': %s:%s", - volname, val, p ? p + 1 : Cnid_port); - free(val); + vol, p, q ? q + 1 : "4700"); + free(p); } - if (val = iniparser_getstrdup(conf, vol, "options")) { - if (p = strtok(val, ",")) { + if (q = iniparser_getstrdup(conf, vol, "options", NULL)) { + if (p = strtok(q, ",")) { while (p) { if (strcasecmp(p, "ro") == 0) options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; @@ -461,7 +453,7 @@ static void volset(const dictionary *conf, const char *vol, struct vol_option *o p = strtok(NULL, ","); } } - free(val); + free(q); } } @@ -850,9 +842,6 @@ static int hostaccessvol(int type, const char *volname, const char *args, const if ((p = strtok_r(buf, ",", &b)) == NULL) /* nothing, return okay */ return -1; - if (obj->proto != AFPPROTO_DSI) - return -1; - while (p) { int ret; char *ipaddr, *mask_char; @@ -906,18 +895,12 @@ static int hostaccessvol(int type, const char *volname, const char *args, const /* ---------------------- */ -static int volfile_changed(struct afp_volume_name *p) +static int volfile_changed(struct afp_options *p) { struct stat st; - char *name; - if (p->full_name) - name = p->full_name; - else - name = p->name; - - if (!stat( name, &st) && st.st_mtime > p->mtime) { - p->mtime = st.st_mtime; + if (!stat(p->configfile, &st) && st.st_mtime > p->volfile.mtime) { + p->volfile.mtime = st.st_mtime; return 1; } return 0; @@ -944,7 +927,8 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p char path[MAXPATHLEN + 1]; char volname[AFPVOL_U8MNAMELEN + 1]; char tmp[MAXPATHLEN + 1]; - char *u, *p; + char *u; + const char *p; int fd; int i; struct passwd *pw; @@ -952,10 +936,8 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p struct vol_option default_options[VOLOPT_NUM]; struct vol_option options[VOLOPT_NUM]; - LOG(log_debug, logtype_afpd, "readvolfile(\"%s\"): BEGIN", p1->name); + LOG(log_debug, logtype_afpd, "readvolfile: BEGIN"); - if (!p1->name) - return -1; p1->mtime = 0; memset(default_options, 0, sizeof(default_options)); @@ -974,7 +956,7 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p for (i = 0; i < secnum; secname = iniparser_getsecname(obj->iniconfig, i), i++) { if (!vol_section(secname)) continue; - if ((p = iniparser_getstring(obj->iniconfig, secname, "path")) == NULL) + if ((p = iniparser_getstrdup(obj->iniconfig, secname, "path", NULL)) == NULL) continue; strlcpy(path, p, MAXPATHLEN); strcpy(tmp, path); @@ -1012,7 +994,7 @@ static int readvolfile(AFPObj *obj, struct afp_volume_name *p1, struct passwd *p options[VOLOPT_FLAGS].i_value |= AFPVOL_RO; /* do variable substitution for volname */ - if (volxlate(obj, tmp, sizeof(tmp) - 1, secname, pwent, path, NULL) == NULL) { + if (volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path, NULL) == NULL) { volfree(options, default_options); continue; } @@ -1583,6 +1565,7 @@ void load_volumes(AFPObj *obj) int fd = -1; struct passwd *pwent; struct stat st; + int retries = 0; if (parent_or_child == 0) { LOG(log_debug, logtype_afpd, "load_volumes: AFP MASTER"); @@ -1590,19 +1573,22 @@ void load_volumes(AFPObj *obj) LOG(log_debug, logtype_afpd, "load_volumes: user: %s", obj->username); } - if (Volumes && volfile_changed(&obj->options.volfile)) + if (Volumes) { + if (!volfile_changed(&obj->options)) + return; free_volumes(); + } /* try putting a read lock on the volume file twice, sleep 1 second if first attempt fails */ - int retries = 2; - fd = open(p1->name, O_RDWR); - if (fd != -1 && fstat(fd, &st) == 0) - p1->mtime = st.st_mtime; - while (1) { + + fd = open(obj->options.configfile, O_RDWR); + + while (retries < 2) { if ((read_lock(fd, 0, SEEK_SET, 0)) != 0) { - retries--; + retries++; if (!retries) { - LOG(log_error, logtype_afpd, "readvolfile: can't lock volume file \"%s\"", path); + LOG(log_error, logtype_afpd, "readvolfile: can't lock configfile \"%s\"", + obj->options.configfile); EC_FAIL; } sleep(1); @@ -1612,7 +1598,7 @@ void load_volumes(AFPObj *obj) } iniparser_freedict(obj->iniconfig); - obj->iniconfig = iniparser_load(obj->configfile); + obj->iniconfig = iniparser_load(obj->options.configfile); if (obj->username) pwent = getpwnam(obj->username); @@ -1635,7 +1621,7 @@ void load_volumes(AFPObj *obj) EC_CLEANUP: if (fd != -1) (void)close(fd); - EC_EXIT; + return; } /* ------------------------------- */ @@ -1742,7 +1728,7 @@ static int volume_codepage(AFPObj *obj, struct vol *volume) } /* ------------------------- */ -static int volume_openDB(struct vol *volume) +static int volume_openDB(const AFPObj *obj, struct vol *volume) { int flags = 0; @@ -1757,37 +1743,15 @@ static int volume_openDB(struct vol *volume) } LOG(log_info, logtype_afpd, "CNID server: %s:%s", - volume->v_cnidserver ? volume->v_cnidserver : Cnid_srv, - volume->v_cnidport ? volume->v_cnidport : Cnid_port); - -#if 0 -/* Found this in branch dir-rewrite, maybe we want to use it sometimes */ - - /* Legacy pre 2.1 way of sharing eg CD-ROM */ - if (strcmp(volume->v_cnidscheme, "last") == 0) { - /* "last" is gone. We support it by switching to in-memory "tdb" */ - volume->v_cnidscheme = strdup("tdb"); - flags |= CNID_FLAG_MEMORY; - } - - /* New way of sharing CD-ROM */ - if (volume->v_flags & AFPVOL_CDROM) { - flags |= CNID_FLAG_MEMORY; - if (strcmp(volume->v_cnidscheme, "tdb") != 0) { - free(volume->v_cnidscheme); - volume->v_cnidscheme = strdup("tdb"); - LOG(log_info, logtype_afpd, "Volume %s is ejectable, switching to scheme %s.", - volume->v_path, volume->v_cnidscheme); - } - } -#endif + volume->v_cnidserver ? volume->v_cnidserver : obj->options.Cnid_srv, + volume->v_cnidport ? volume->v_cnidport : obj->options.Cnid_port); volume->v_cdb = cnid_open(volume->v_path, volume->v_umask, volume->v_cnidscheme, flags, - volume->v_cnidserver ? volume->v_cnidserver : Cnid_srv, - volume->v_cnidport ? volume->v_cnidport : Cnid_port); + volume->v_cnidserver ? volume->v_cnidserver : obj->options.Cnid_srv, + volume->v_cnidport ? volume->v_cnidport : obj->options.Cnid_port); if ( ! volume->v_cdb && ! (flags & CNID_FLAG_MEMORY)) { /* The first attempt failed and it wasn't yet an attempt to open in-memory */ @@ -2028,7 +1992,7 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t volume->v_root = dir; curdir = dir; - if (volume_openDB(volume) < 0) { + if (volume_openDB(obj, volume) < 0) { LOG(log_error, logtype_afpd, "Fatal error: cannot open CNID or invalid CNID backend for %s: %s", volume->v_path, volume->v_cnidscheme); ret = AFPERR_MISC; @@ -2040,8 +2004,8 @@ int afp_openvol(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t if (ret == AFP_OK) { handle_special_folders(volume); savevolinfo(volume, - volume->v_cnidserver ? volume->v_cnidserver : Cnid_srv, - volume->v_cnidport ? volume->v_cnidport : Cnid_port); + volume->v_cnidserver ? volume->v_cnidserver : obj->options.Cnid_srv, + volume->v_cnidport ? volume->v_cnidport : obj->options.Cnid_port); /* @@ -2184,39 +2148,6 @@ struct vol *getvolbyvid(const uint16_t vid ) return( vol ); } -/* ------------------------ */ -static int ext_cmp_key(const void *key, const void *obj) -{ - const char *p = key; - const struct extmap *em = obj; - return strdiacasecmp(p, em->em_ext); -} -struct extmap *getextmap(const char *path) -{ - char *p; - struct extmap *em; - - if (!Extmap_cnt || NULL == ( p = strrchr( path, '.' )) ) { - return( Defextmap ); - } - p++; - if (!*p) { - return( Defextmap ); - } - em = bsearch(p, Extmap, Extmap_cnt, sizeof(struct extmap), ext_cmp_key); - if (em) { - return( em ); - } else { - return( Defextmap ); - } -} - -/* ------------------------- */ -struct extmap *getdefextmap(void) -{ - return( Defextmap ); -} - /* -------------------------- poll if a volume is changed by other processes. return @@ -2236,7 +2167,7 @@ int pollvoltime(AFPObj *obj) struct timeval tv; struct stat st; - if (!(afp_version > 21 && obj->options.server_notif)) + if (!(afp_version > 21 && obj->options.flags & OPTION_SERVERNOTIF)) return 0; if ( gettimeofday( &tv, NULL ) < 0 ) @@ -2276,7 +2207,7 @@ void setvoltime(AFPObj *obj, struct vol *vol) /* or finder doesn't update free space * AFP 3.2 and above clients seem to be ok without so many notification */ - if (afp_version < 32 && obj->options.server_notif) { + if (afp_version < 32 && obj->options.flags & OPTION_SERVERNOTIF) { obj->attention(obj->dsi, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED); } } diff --git a/etc/cnid_dbd/cmd_dbd.c b/etc/cnid_dbd/cmd_dbd.c index a9993d4c..ad0e22b4 100644 --- a/etc/cnid_dbd/cmd_dbd.c +++ b/etc/cnid_dbd/cmd_dbd.c @@ -262,9 +262,9 @@ int main(int argc, char **argv) /* Setup logging. Should be portable among *NIXes */ if (!verbose) - setuplog("default log_info /dev/tty"); + setuplog("default:info", "/dev/tty"); else - setuplog("default log_debug /dev/tty"); + setuplog("default:debug", "/dev/tty"); /* Load .volinfo file */ if (loadvolinfo(volpath, &volinfo) == -1) { diff --git a/etc/cnid_dbd/cnid_metad.c b/etc/cnid_dbd/cnid_metad.c index 2a3bc6b9..580c36cd 100644 --- a/etc/cnid_dbd/cnid_metad.c +++ b/etc/cnid_dbd/cnid_metad.c @@ -444,8 +444,6 @@ int main(int argc, char *argv[]) int err = 0; int debug = 0; int ret; - char *loglevel = NULL; - char *logfile = NULL; sigset_t set; struct volinfo *volinfo; @@ -483,12 +481,6 @@ int main(int argc, char *argv[]) case 's': dbdpn = strdup(optarg); break; - case 'l': - loglevel = strdup(optarg); - break; - case 'f': - logfile = strdup(optarg); - break; default: err++; break; @@ -506,16 +498,7 @@ int main(int argc, char *argv[]) if (create_lockfile("cnid_metad", _PATH_CNID_METAD_LOCK)) return -1; - if (loglevel) { - strlcpy(logconfig + 8, loglevel, 13); - free(loglevel); - strcat(logconfig, " "); - } - if (logfile) { - strlcat(logconfig, logfile, MAXPATHLEN); - free(logfile); - } - setuplog(logconfig); + setuplog("default:note", NULL); if (err) { LOG(log_error, logtype_cnid, "main: bad arguments"); diff --git a/etc/cnid_dbd/main.c b/etc/cnid_dbd/main.c index 55bbcddb..000abbf0 100644 --- a/etc/cnid_dbd/main.c +++ b/etc/cnid_dbd/main.c @@ -313,8 +313,8 @@ int main(int argc, char *argv[]) ctrlfd = atoi(argv[optind + 1]); clntfd = atoi(argv[optind + 2]); - logconfig = strdup(argv[optind + 3]); - setuplog(logconfig); + + setuplog("default:note", NULL); if (vol_load_charsets(&volinfo) == -1) { LOG(log_error, logtype_cnid, "Error loading charsets!"); diff --git a/include/atalk/dictionary.h b/include/atalk/dictionary.h index 0d6eb677..7a910524 100644 --- a/include/atalk/dictionary.h +++ b/include/atalk/dictionary.h @@ -50,8 +50,8 @@ typedef struct _dictionary_ { int n ; /** Number of entries in dictionary */ int size ; /** Storage size */ - char ** val ; /** List of string values */ - char ** key ; /** List of string keys */ + char ** val ; /** List of string values */ + char ** key ; /** List of string keys */ unsigned * hash ; /** List of hash values for keys */ } dictionary ; @@ -63,7 +63,7 @@ typedef struct _dictionary_ { unsigned dictionary_hash (char * key); dictionary *dictionary_new (int size); void dictionary_del (dictionary * vd); -char *dictionary_get (dictionary * d, char *section, char * key, char * def); +const char *dictionary_get (const dictionary * d, const char *section, const char * key, const char * def); int dictionary_set (dictionary * vd, char *section, char * key, char * val); void dictionary_unset (dictionary * d, char *section, char * key); void dictionary_dump (dictionary * d, FILE * out); diff --git a/include/atalk/dsi.h b/include/atalk/dsi.h index f520c209..5af4cac5 100644 --- a/include/atalk/dsi.h +++ b/include/atalk/dsi.h @@ -56,8 +56,11 @@ struct dsi_block { /* child and parent processes might interpret a couple of these * differently. */ typedef struct DSI { - DSI *next; /* multiple listening addresses */ + struct DSI *next; /* multiple listening addresses */ AFPObj *AFPobj; + int statuslen; + char status[1400]; + char *signature; struct dsi_block header; struct sockaddr_storage server, client; struct itimerval timer; @@ -69,9 +72,7 @@ typedef struct DSI { uint32_t attn_quantum, datasize, server_quantum; uint16_t serverID, clientID; - char *status; uint8_t commands[DSI_CMDSIZ], data[DSI_DATASIZ]; - size_t statuslen; size_t datalen, cmdlen; off_t read_count, write_count; uint32_t flags; /* DSI flags like DSI_SLEEPING, DSI_DISCONNECTED */ @@ -155,12 +156,9 @@ typedef struct DSI { #endif /* basic initialization: dsi_init.c */ -extern DSI *dsi_init (const dsi_proto /*protocol*/, - const char * /*program*/, - const char * /*host*/, const char * /*address*/, - const char * /*port*/, const int /*proxy*/, - const uint32_t /* server quantum */); +extern DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address, const char *port); extern void dsi_setstatus (DSI *, char *, const size_t); +extern int dsi_tcp_init(DSI *dsi, const char *hostname, const char *address, const char *port); /* in dsi_getsess.c */ extern afp_child_t *dsi_getsession (DSI *, server_child *, const int); diff --git a/include/atalk/fce_api.h b/include/atalk/fce_api.h index 9175afe9..aebb56ad 100755 --- a/include/atalk/fce_api.h +++ b/include/atalk/fce_api.h @@ -54,7 +54,7 @@ int fce_register_file_modification( struct ofork *ofork ); int fce_register_tm_size(const char *vol, size_t used); int fce_add_udp_socket(const char *target ); // IP or IP:Port -int fce_set_coalesce( char *coalesce_opt ); // all|delete|create +int fce_set_coalesce(const char *coalesce_opt ); // all|delete|create int fce_set_events(const char *events); /* fmod,fdel,ddel,fcre,dcre,tmsz (default is all except tmsz) */ #define FCE_DEFAULT_PORT 12250 diff --git a/include/atalk/globals.h b/include/atalk/globals.h index 83fd3a1e..f8c353ca 100644 --- a/include/atalk/globals.h +++ b/include/atalk/globals.h @@ -53,12 +53,8 @@ struct DSI; #define AFPOBJ_TMPSIZ (MAXPATHLEN) -/* a couple of these options could get stuck in unions to save - * space. */ struct afp_volume_name { time_t mtime; - char *name; - char *full_name; int loaded; }; @@ -108,12 +104,10 @@ struct afp_options { typedef struct AFPObj { int argc; char **argv; - int statuslen; - char status[1400]; const void *signature; struct DSI *dsi; struct afp_options options; - const dictionary *iniconfig; + dictionary *iniconfig; char username[MAXUSERLEN]; /* to prevent confusion, only use these in afp_* calls */ char oldtmp[AFPOBJ_TMPSIZ + 1], newtmp[AFPOBJ_TMPSIZ + 1]; @@ -144,7 +138,7 @@ extern const char *Cnid_port; extern int get_afp_errno (const int param); extern void afp_options_init (struct afp_options *); -extern int afp_options_parse_cmdline (int ac, char **av); +extern void afp_options_parse_cmdline(int ac, char **av); extern int afp_config_parse(AFPObj *AFPObj); extern void afp_options_free(struct afp_options *); extern void setmessage (const char *); diff --git a/include/atalk/iniparser.h b/include/atalk/iniparser.h index 6466358c..0eefa4cb 100644 --- a/include/atalk/iniparser.h +++ b/include/atalk/iniparser.h @@ -34,19 +34,19 @@ #include "dictionary.h" -int iniparser_getnsec(dictionary * d); -char *iniparser_getsecname(dictionary * d, int n); -void iniparser_dump_ini(dictionary * d, FILE * f); -void iniparser_dump(dictionary * d, FILE * f); -char *iniparser_getstring(dictionary * d, char *section, char * key, char * def); -char *iniparser_getstrdup(dictionary * d, char *section, char * key, char * def); -int iniparser_getint(dictionary * d, char *section, char * key, int notfound); -double iniparser_getdouble(dictionary * d, char *section, char * key, double notfound); -int iniparser_getboolean(dictionary * d, char *section, char * key, int notfound); +int iniparser_getnsec(const dictionary * d); +const char *iniparser_getsecname(const dictionary * d, int n); +void iniparser_dump_ini(const dictionary * d, FILE * f); +void iniparser_dump(const dictionary * d, FILE * f); +const char *iniparser_getstring(const dictionary * d, const char *section, const char * key, const char * def); +char *iniparser_getstrdup(const dictionary * d, const char *section, const char * key, const char * def); +int iniparser_getint(const dictionary * d, const char *section, const char * key, int notfound); +double iniparser_getdouble(const dictionary * d, const char *section, const char * key, double notfound); +int iniparser_getboolean(const dictionary * d, const char *section, const char * key, int notfound); int iniparser_set(dictionary * ini, char *section, char * key, char * val); void iniparser_unset(dictionary * ini, char *section, char * key); -int iniparser_find_entry(dictionary * ini, char * entry) ; -dictionary *iniparser_load(char * ininame); +int iniparser_find_entry(const dictionary * ini, const char * entry) ; +dictionary *iniparser_load(const char * ininame); void iniparser_freedict(dictionary * d); #endif diff --git a/include/atalk/uam.h b/include/atalk/uam.h index 72207f1f..dcb32e99 100644 --- a/include/atalk/uam.h +++ b/include/atalk/uam.h @@ -39,7 +39,6 @@ #define UAM_OPTION_RANDNUM (1 << 4) /* request a random number */ #define UAM_OPTION_HOSTNAME (1 << 5) /* get host name */ #define UAM_OPTION_COOKIE (1 << 6) /* cookie handle */ -#define UAM_OPTION_PROTOCOL (1 << 7) /* DSI or ASP */ #define UAM_OPTION_CLIENTNAME (1 << 8) /* get client IP address */ #define UAM_OPTION_KRB5SERVICE (1 << 9) /* service name for krb5 principal */ #define UAM_OPTION_MACCHARSET (1 << 10) /* mac charset handle */ diff --git a/libatalk/acl/ldap_config.c b/libatalk/acl/ldap_config.c index d719cafd..bbba8b66 100644 --- a/libatalk/acl/ldap_config.c +++ b/libatalk/acl/ldap_config.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -37,9 +38,7 @@ int acl_ldap_readconfig(dictionary *iniconfig) i = 0; /* now see if its a correct pref */ for (i = 0; ldap_prefs[i].name != NULL; i++) { - if ((val = iniparser_getstring(ldap_prefs[i].name)) != NULL) { - /* ok, found a valid pref */ - + if ((val = iniparser_getstring(iniconfig, INISEC_AFP, ldap_prefs[i].name, NULL))) { /* check if we have pre-defined values */ if (ldap_prefs[i].intfromarray == 0) { /* no, its just a string */ @@ -89,7 +88,6 @@ int acl_ldap_readconfig(dictionary *iniconfig) } } else LOG(log_info, logtype_afpd,"afp_ldap.conf: not used"); - fclose(f); return 0; } #endif /* HAVE_LDAP */ diff --git a/libatalk/dsi/Makefile.am b/libatalk/dsi/Makefile.am index d64cbed6..34fa76e5 100644 --- a/libatalk/dsi/Makefile.am +++ b/libatalk/dsi/Makefile.am @@ -7,5 +7,3 @@ LIBS = @LIBS@ noinst_LTLIBRARIES = libdsi.la libdsi_la_SOURCES = dsi_attn.c dsi_close.c dsi_cmdreply.c dsi_getsess.c dsi_getstat.c dsi_init.c dsi_opensess.c dsi_read.c dsi_tcp.c dsi_tickle.c dsi_write.c dsi_stream.c - -noinst_HEADERS = dsi_private.h diff --git a/libatalk/dsi/dsi_init.c b/libatalk/dsi/dsi_init.c index 568f9ffd..824d31f3 100644 --- a/libatalk/dsi/dsi_init.c +++ b/libatalk/dsi/dsi_init.c @@ -1,7 +1,5 @@ /* - * $Id: dsi_init.c,v 1.10 2009-11-05 14:38:08 franklahm Exp $ - * - * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) + * Copyright (c) 2012, Frank Lahm * All rights reserved. See COPYRIGHT. */ @@ -13,7 +11,6 @@ #include #include #include -#include "dsi_private.h" DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address, const char *port) { @@ -24,7 +21,7 @@ DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address, const char dsi->attn_quantum = DSI_DEFQUANT; dsi->server_quantum = obj->options.server_quantum; - dsi->dsireadbuf = obj->options->dsireadbuf; + dsi->dsireadbuf = obj->options.dsireadbuf; /* currently the only transport protocol that exists for dsi */ if (dsi_tcp_init(dsi, hostname, address, port) != 0) { @@ -34,9 +31,3 @@ DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address, const char return dsi; } - -void dsi_setstatus(DSI *dsi, char *status, const size_t slen) -{ - dsi->status = status; - dsi->statuslen = slen; -} diff --git a/libatalk/dsi/dsi_private.h b/libatalk/dsi/dsi_private.h deleted file mode 100644 index c953afdc..00000000 --- a/libatalk/dsi/dsi_private.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu) - * All rights reserved. See COPYRIGHT. - */ - -#ifndef _DSI_PRIVATE_H -#define _DSI_PRIVATE_H 1 - -/* this header handles interactions between protocol-specific code and - * dsi initialization. only dsi_init.c and dsi_.c should - * include it. - */ - -#include -#include - -extern int dsi_tcp_init (DSI *, const char * /*host*/, - const char * /*address*/, - const char * /*port*/, - const int /*proxy*/); - -#endif /* _DSI_PRIVATE_H */ diff --git a/libatalk/dsi/dsi_tcp.c b/libatalk/dsi/dsi_tcp.c index f11eca51..01aca6f7 100644 --- a/libatalk/dsi/dsi_tcp.c +++ b/libatalk/dsi/dsi_tcp.c @@ -53,8 +53,6 @@ int deny_severity = log_warning; #include #include -#include "dsi_private.h" - #define min(a,b) ((a) < (b) ? (a) : (b)) #ifndef DSI_TCPMAXPEND @@ -273,17 +271,19 @@ int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const ch { EC_INIT; int flag; - char *p, *address = NULL; + char *a = NULL, *b; + const char *address; + const char *port; struct addrinfo hints, *servinfo, *p; /* Check whether address is of the from IP:PORT and split */ address = inaddress; port = inport; if (address && strchr(address, ':')) { - EC_NULL_LOG( address = strdup(inaddress) ); - p = strchr(address, ':'); - *p = 0; - port = p + 1; + EC_NULL_LOG( address = a = strdup(address) ); + b = strchr(a, ':'); + *b = 0; + port = b + 1; } /* Prepare hint for getaddrinfo */ @@ -310,64 +310,59 @@ int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const ch EC_FAIL; } - /* create a socket */ - if (proxy) - dsi->serversock = -1; - else { - /* loop through all the results and bind to the first we can */ - for (p = servinfo; p != NULL; p = p->ai_next) { - if ((dsi->serversock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { - LOG(log_info, logtype_dsi, "dsi_tcp_init: socket: %s", strerror(errno)); - continue; - } + /* loop through all the results and bind to the first we can */ + for (p = servinfo; p != NULL; p = p->ai_next) { + if ((dsi->serversock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { + LOG(log_info, logtype_dsi, "dsi_tcp_init: socket: %s", strerror(errno)); + continue; + } - /* - * Set some socket options: - * SO_REUSEADDR deals w/ quick close/opens - * TCP_NODELAY diables Nagle - */ + /* + * Set some socket options: + * SO_REUSEADDR deals w/ quick close/opens + * TCP_NODELAY diables Nagle + */ #ifdef SO_REUSEADDR - flag = 1; - setsockopt(dsi->serversock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); + flag = 1; + setsockopt(dsi->serversock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); #endif #if defined(FREEBSD) && defined(IPV6_BINDV6ONLY) - int on = 0; - setsockopt(dsi->serversock, IPPROTO_IPV6, IPV6_BINDV6ONLY, (char *)&on, sizeof (on)); + int on = 0; + setsockopt(dsi->serversock, IPPROTO_IPV6, IPV6_BINDV6ONLY, (char *)&on, sizeof (on)); #endif #ifdef USE_TCP_NODELAY #ifndef SOL_TCP #define SOL_TCP IPPROTO_TCP #endif - flag = 1; - setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag)); + flag = 1; + setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag)); #endif /* USE_TCP_NODELAY */ - if (bind(dsi->serversock, p->ai_addr, p->ai_addrlen) == -1) { - close(dsi->serversock); - LOG(log_info, logtype_dsi, "dsi_tcp_init: bind: %s\n", strerror(errno)); - continue; - } - - if (listen(dsi->serversock, DSI_TCPMAXPEND) < 0) { - close(dsi->serversock); - LOG(log_info, logtype_dsi, "dsi_tcp_init: listen: %s\n", strerror(errno)); - continue; - } - - break; + if (bind(dsi->serversock, p->ai_addr, p->ai_addrlen) == -1) { + close(dsi->serversock); + LOG(log_info, logtype_dsi, "dsi_tcp_init: bind: %s\n", strerror(errno)); + continue; } - if (p == NULL) { - LOG(log_error, logtype_dsi, "dsi_tcp_init: no suitable network config for TCP socket"); - freeaddrinfo(servinfo); - EC_FAIL; + if (listen(dsi->serversock, DSI_TCPMAXPEND) < 0) { + close(dsi->serversock); + LOG(log_info, logtype_dsi, "dsi_tcp_init: listen: %s\n", strerror(errno)); + continue; } + + break; + } - /* Copy struct sockaddr to struct sockaddr_storage */ - memcpy(&dsi->server, p->ai_addr, p->ai_addrlen); + if (p == NULL) { + LOG(log_error, logtype_dsi, "dsi_tcp_init: no suitable network config for TCP socket"); freeaddrinfo(servinfo); - } /* if (proxy) */ + EC_FAIL; + } + + /* Copy struct sockaddr to struct sockaddr_storage */ + memcpy(&dsi->server, p->ai_addr, p->ai_addrlen); + freeaddrinfo(servinfo); /* Point protocol specific functions to tcp versions */ dsi->proto_open = dsi_tcp_open; @@ -416,8 +411,8 @@ interfaces: guess_interface(dsi, hostname, port ? port : "548"); EC_CLEANUP: - if (address) - free(address); + if (a) + free(a); EC_EXIT; } diff --git a/libatalk/iniparser/dictionary.c b/libatalk/iniparser/dictionary.c index 6ba08358..1848b45d 100644 --- a/libatalk/iniparser/dictionary.c +++ b/libatalk/iniparser/dictionary.c @@ -193,7 +193,7 @@ void dictionary_del(dictionary * d) dictionary object, you should not try to free it or modify it. */ /*--------------------------------------------------------------------------*/ -char * dictionary_get(dictionary * d, char *section, char * key, char * def) +const char * dictionary_get(const dictionary * d, const char *section, const char * key, const char * def) { unsigned hash ; int i ; diff --git a/libatalk/iniparser/iniparser.c b/libatalk/iniparser/iniparser.c index 0308ed2c..761b9303 100644 --- a/libatalk/iniparser/iniparser.c +++ b/libatalk/iniparser/iniparser.c @@ -88,7 +88,7 @@ static char * strstrip(char * s) This function returns -1 in case of error. */ /*--------------------------------------------------------------------------*/ -int iniparser_getnsec(dictionary * d) +int iniparser_getnsec(const dictionary * d) { int i ; int nsec ; @@ -119,7 +119,7 @@ int iniparser_getnsec(dictionary * d) This function returns NULL in case of error. */ /*--------------------------------------------------------------------------*/ -char * iniparser_getsecname(dictionary * d, int n) +const char * iniparser_getsecname(const dictionary * d, int n) { int i ; int foundsec ; @@ -154,7 +154,7 @@ char * iniparser_getsecname(dictionary * d, int n) purposes mostly. */ /*--------------------------------------------------------------------------*/ -void iniparser_dump(dictionary * d, FILE * f) +void iniparser_dump(const dictionary * d, FILE * f) { int i ; @@ -182,12 +182,12 @@ void iniparser_dump(dictionary * d, FILE * f) It is Ok to specify @c stderr or @c stdout as output files. */ /*--------------------------------------------------------------------------*/ -void iniparser_dump_ini(dictionary * d, FILE * f) +void iniparser_dump_ini(const dictionary * d, FILE * f) { int i, j ; char keym[ASCIILINESZ+1]; int nsec ; - char * secname ; + const char * secname ; int seclen ; if (d==NULL || f==NULL) return ; @@ -238,9 +238,9 @@ void iniparser_dump_ini(dictionary * d, FILE * f) the dictionary, do not free or modify it. */ /*--------------------------------------------------------------------------*/ -char * iniparser_getstring(dictionary * d, char *section, char * key, char * def) +const char * iniparser_getstring(const dictionary * d, const char *section, const char * key, const char * def) { - char * sval ; + const char * sval ; if (d==NULL || key==NULL) return def ; @@ -264,12 +264,12 @@ char * iniparser_getstring(dictionary * d, char *section, char * key, char * def The returned char pointer a strdup'ed allocated string, so the caller must free it. */ /*--------------------------------------------------------------------------*/ -char * iniparser_getstrdup(dictionary * d, char *section, char * key, char * def) +char * iniparser_getstrdup(const dictionary * d, const char *section, const char * key, const char * def) { - char * sval ; + const char * sval ; if (d==NULL || key==NULL) - return def ; + return NULL; if ((sval = dictionary_get(d, section, key, def))) return strdup(sval); @@ -304,9 +304,9 @@ char * iniparser_getstrdup(dictionary * d, char *section, char * key, char * def Credits: Thanks to A. Becker for suggesting strtol() */ /*--------------------------------------------------------------------------*/ -int iniparser_getint(dictionary * d, char *section, char * key, int notfound) +int iniparser_getint(const dictionary * d, const char *section, const char * key, int notfound) { - char * str ; + const char * str ; str = iniparser_getstring(d, section, key, INI_INVALID_KEY); if (str==INI_INVALID_KEY) return notfound ; @@ -327,9 +327,9 @@ int iniparser_getint(dictionary * d, char *section, char * key, int notfound) the notfound value is returned. */ /*--------------------------------------------------------------------------*/ -double iniparser_getdouble(dictionary * d, char *section, char * key, double notfound) +double iniparser_getdouble(const dictionary * d, const char *section, const char * key, double notfound) { - char * str ; + const char * str ; str = iniparser_getstring(d, section, key, INI_INVALID_KEY); if (str==INI_INVALID_KEY) return notfound ; @@ -369,9 +369,9 @@ double iniparser_getdouble(dictionary * d, char *section, char * key, double not necessarily have to be 0 or 1. */ /*--------------------------------------------------------------------------*/ -int iniparser_getboolean(dictionary * d, char *section, char * key, int notfound) +int iniparser_getboolean(const dictionary * d, const char *section, const char * key, int notfound) { - char * c ; + const char * c ; int ret ; c = iniparser_getstring(d, section, key, INI_INVALID_KEY); @@ -398,7 +398,7 @@ int iniparser_getboolean(dictionary * d, char *section, char * key, int notfound of querying for the presence of sections in a dictionary. */ /*--------------------------------------------------------------------------*/ -int iniparser_find_entry(dictionary *ini, char *entry) +int iniparser_find_entry(const dictionary *ini, const char *entry) { int found=0 ; if (iniparser_getstring(ini, entry, NULL, INI_INVALID_KEY)!=INI_INVALID_KEY) { @@ -526,7 +526,7 @@ static line_status iniparser_line( The returned dictionary must be freed using iniparser_freedict(). */ /*--------------------------------------------------------------------------*/ -dictionary * iniparser_load(char * ininame) +dictionary * iniparser_load(const char * ininame) { FILE * in ; diff --git a/libatalk/util/logger.c b/libatalk/util/logger.c index c1e981dd..b96b2181 100644 --- a/libatalk/util/logger.c +++ b/libatalk/util/logger.c @@ -90,16 +90,20 @@ UAM_MODULE_EXPORT logtype_conf_t type_configs[logtype_end_of_list_marker] = { DEFAULT_LOG_CONFIG /* logtype_uams */ }; +static void syslog_setup(int loglevel, enum logtypes logtype, int display_options, int facility); + /* We use this in order to track the last n log messages in order to prevent flooding */ #define LOG_FLOODING_MINCOUNT 5 /* this controls after how many consecutive messages must be detected before we start to hide them */ #define LOG_FLOODING_MAXCOUNT 1000 /* this controls after how many consecutive messages we force a "repeated x times" message */ #define LOG_FLOODING_ARRAY_SIZE 3 /* this contols how many messages in flow we track */ + struct log_flood_entry { int count; unsigned int hash; }; + static struct log_flood_entry log_flood_array[LOG_FLOODING_ARRAY_SIZE]; static int log_flood_entries; @@ -639,7 +643,7 @@ void setuplog(const char *logstr, const char *logfile) ptr++; c = *ptr; *ptr = 0; - setuplog_internal(loglevel, logtype, filename); + setuplog_internal(loglevel, logtype, logfile); *ptr = c; }