int main(int argc, char **argv)
{
- setuplog("default log_note /dev/tty");
+ setuplog("default:note", "/dev/tty");
if (argc < 2) {
usage_main();
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
#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.");
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)
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);
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);
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);
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\" \
*/
static void register_stuff(void) {
uint port;
- const AFPConfig *config;
+ const AFPObj *obj;
const struct vol *volume;
DSI *dsi;
char name[MAXINSTANCENAMELEN+1];
}
/* 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) {
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,
* 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. */
avahi_entry_group_reset(ctx->group);
} else {
ctx = calloc(1, sizeof(struct context));
- ctx->configs = configs;
+ ctx->obj = obj;
assert(ctx);
}
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 */
{
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) {
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;
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:
#include <atalk/server_child.h>
#include <atalk/globals.h>
+#include <atalk/dsi.h>
-extern AFPConfig *configinit (struct afp_options *);
-extern void configfree (AFPConfig *, const AFPConfig *);
+extern int configinit (AFPObj *);
+extern void configfree (AFPObj *, DSI *);
#endif
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);
}
}
#include <atalk/compat.h>
#include <atalk/globals.h>
#include <atalk/fce_api.h>
+#include <atalk/errchk.h>
#include "status.h"
#include "auth.h"
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)
#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));
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;
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", "");
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))) {
}
#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");
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))) {
if (options->volnamelen > 255)
options->volnamelen = 255; /* AFP3 spec */
- return 0;
+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);
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 ) {
exit( 2 );
}
- return 1;
+ return;
}
/*
* 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");
/*
* 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.
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!" );
*/
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 );
#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;
* all|delete|create
*/
-int fce_set_coalesce(char *opt)
+int fce_set_coalesce(const char *opt)
{
char *e;
char *p;
/* 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;
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;
}
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 :
/* 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;
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);
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;
}
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;
{
if (parent_or_child == 0)
/* Only do this in the parent */
- server_unlock(default_options.pidfile);
+ server_unlock(_PATH_AFPDLOCK);
}
*/
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,
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");
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 :
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)
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);
}
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);
}
/* 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();
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;
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,
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);
}
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,
#include "misc.h"
-
#define MAXMESGSIZE 199
/* this is only used by afpd children, so it's okay. */
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] */
*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));
*/
/* 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 )) ) {
/* ---------------------
*/
-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
*/
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);
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() */
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) {
/* 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;
}
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 */
break;
case UAM_OPTION_SIGNATURE:
- *buf = (void *) (((AFPConfig *)obj->config)->signature);
+ *buf = (void *)obj->dsi->signature;
if (len)
*len = 16;
break;
*len = strlen(obj->options.hostname);
break;
- case UAM_OPTION_PROTOCOL:
- *((int *) option) = obj->proto;
- break;
-
case UAM_OPTION_CLIENTNAME:
{
struct DSI *dsi = obj->dsi;
}
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) );
}
}
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 );
* $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
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;
else if (*(q + 1) != '\0')
q++;
}
- } else if (is_var(p, "$z")) {
- q = obj->Zone;
} else if (is_var(p, "$$")) {
q = "$";
} else
}
/* -------------------- */
-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);
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)
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)
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;
p = strtok(NULL, ",");
}
}
- free(val);
+ free(q);
}
}
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;
/* ----------------------
*/
-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;
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;
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));
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);
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;
}
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");
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);
}
iniparser_freedict(obj->iniconfig);
- obj->iniconfig = iniparser_load(obj->configfile);
+ obj->iniconfig = iniparser_load(obj->options.configfile);
if (obj->username)
pwent = getpwnam(obj->username);
EC_CLEANUP:
if (fd != -1)
(void)close(fd);
- EC_EXIT;
+ return;
}
/* ------------------------------- */
}
/* ------------------------- */
-static int volume_openDB(struct vol *volume)
+static int volume_openDB(const AFPObj *obj, struct vol *volume)
{
int flags = 0;
}
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 */
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;
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);
/*
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
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 )
/* 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);
}
}
/* 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) {
int err = 0;
int debug = 0;
int ret;
- char *loglevel = NULL;
- char *logfile = NULL;
sigset_t set;
struct volinfo *volinfo;
case 's':
dbdpn = strdup(optarg);
break;
- case 'l':
- loglevel = strdup(optarg);
- break;
- case 'f':
- logfile = strdup(optarg);
- break;
default:
err++;
break;
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");
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!");
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 ;
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);
/* 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;
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 */
#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);
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
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;
};
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];
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 *);
#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
#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 */
#include <ctype.h>
#include <ldap.h>
+#include <atalk/globals.h>
#include <atalk/ldapconfig.h>
#include <atalk/logger.h>
#include <atalk/iniparser.h>
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 */
}
} else
LOG(log_info, logtype_afpd,"afp_ldap.conf: not used");
- fclose(f);
return 0;
}
#endif /* HAVE_LDAP */
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
/*
- * $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 <franklahm@googlemail.com>
* All rights reserved. See COPYRIGHT.
*/
#include <stdlib.h>
#include <signal.h>
#include <atalk/dsi.h>
-#include "dsi_private.h"
DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address, const char *port)
{
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) {
return dsi;
}
-
-void dsi_setstatus(DSI *dsi, char *status, const size_t slen)
-{
- dsi->status = status;
- dsi->statuslen = slen;
-}
+++ /dev/null
-/*
- * 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_<proto>.c should
- * include it.
- */
-
-#include <sys/types.h>
-#include <arpa/inet.h>
-
-extern int dsi_tcp_init (DSI *, const char * /*host*/,
- const char * /*address*/,
- const char * /*port*/,
- const int /*proxy*/);
-
-#endif /* _DSI_PRIVATE_H */
#include <atalk/util.h>
#include <atalk/errchk.h>
-#include "dsi_private.h"
-
#define min(a,b) ((a) < (b) ? (a) : (b))
#ifndef DSI_TCPMAXPEND
{
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 */
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;
guess_interface(dsi, hostname, port ? port : "548");
EC_CLEANUP:
- if (address)
- free(address);
+ if (a)
+ free(a);
EC_EXIT;
}
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 ;
This function returns -1 in case of error.
*/
/*--------------------------------------------------------------------------*/
-int iniparser_getnsec(dictionary * d)
+int iniparser_getnsec(const dictionary * d)
{
int i ;
int nsec ;
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 ;
purposes mostly.
*/
/*--------------------------------------------------------------------------*/
-void iniparser_dump(dictionary * d, FILE * f)
+void iniparser_dump(const dictionary * d, FILE * f)
{
int i ;
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 ;
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 ;
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);
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 ;
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 ;
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);
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) {
The returned dictionary must be freed using iniparser_freedict().
*/
/*--------------------------------------------------------------------------*/
-dictionary * iniparser_load(char * ininame)
+dictionary * iniparser_load(const char * ininame)
{
FILE * in ;
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;
ptr++;
c = *ptr;
*ptr = 0;
- setuplog_internal(loglevel, logtype, filename);
+ setuplog_internal(loglevel, logtype, logfile);
*ptr = c;
}