diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-09 15:43:59 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-09 15:43:59 +0300 |
commit | a312dfe652e26b7c283241a1d268cf888ab9bec1 (patch) | |
tree | 3039c573e7f9656a37de9b3245b3aa44660f56b1 | |
parent | 9cffcc7e9da8d6190725ff941e4f291a82a2903b (diff) | |
download | smap-a312dfe652e26b7c283241a1d268cf888ab9bec1.tar.gz smap-a312dfe652e26b7c283241a1d268cf888ab9bec1.tar.bz2 |
Bugfixes.
* include/smap/url.h (SMAP_URLE_INVALID): New constant.
* lib/url.c (url_error_string): Add new string for SMAP_URLE_INVALID.
(split_connection): Return SMAP_URLE_INVALID on invalid URLs.
(smap_url_parse): Initialize proto, port and path to NULL.
* modules/mailutils/mailutils.c (checksize): Set res->auth.
(mod_mailutils_init): New options config-verbose and config-verbose.
Set mu_cfg_parser_verbose depending on the flags.
Collect gocs capabilities and call mu_libcfg_init.
* src/Makefile.am (INCLUDES): Add @LTDLINCL@.
* src/smapc.c (read_eval_loop): Handle comments.
* src/smapd.c (cfg_max_children, cfg_global_max_children): Bugfix.
(smap_kwtab): New keyword: trace.
* src/srvman.c: Use tcpwrappers only for AF_INET family.
-rw-r--r-- | include/smap/url.h | 19 | ||||
-rw-r--r-- | lib/url.c | 8 | ||||
-rw-r--r-- | modules/mailutils/mailutils.c | 92 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/smapc.c | 11 | ||||
-rw-r--r-- | src/smapd.c | 5 | ||||
-rw-r--r-- | src/srvman.c | 5 |
7 files changed, 112 insertions, 30 deletions
diff --git a/include/smap/url.h b/include/smap/url.h index f336f9c..8fda1c0 100644 --- a/include/smap/url.h +++ b/include/smap/url.h @@ -15,15 +15,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ #define SMAP_URLE_NOMEM 1 -#define SMAP_URLE_PORT 2 -#define SMAP_URLE_NAME2LONG 3 -#define SMAP_URLE_NOABS 4 -#define SMAP_URLE_NOPORT 5 -#define SMAP_URLE_BADPORT 6 -#define SMAP_URLE_UNKPORT 7 -#define SMAP_URLE_UNKHOST 8 -#define SMAP_URLE_BADFAMILY 9 -#define SMAP_URLE_BADPROTO 10 +#define SMAP_URLE_INVALID 2 +#define SMAP_URLE_PORT 3 +#define SMAP_URLE_NAME2LONG 4 +#define SMAP_URLE_NOABS 5 +#define SMAP_URLE_NOPORT 6 +#define SMAP_URLE_BADPORT 7 +#define SMAP_URLE_UNKPORT 8 +#define SMAP_URLE_UNKHOST 9 +#define SMAP_URLE_BADFAMILY 10 +#define SMAP_URLE_BADPROTO 11 int smap_url_parse(const char *cstr, struct sockaddr **psa, socklen_t *plen); const char *smap_url_strerror(int er); @@ -30,6 +30,7 @@ static char *url_error_string[] = { "no error", "not enough memory", /* SMAP_URLE_NOMEM */ + "malformed URL", /* SMAP_URLE_INVALID */ "port is meaningless for UNIX sockets", /* SMAP_URLE_PORT */ "UNIX socket name too long", /* SMAP_URLE_NAME2LONG */ "UNIX socket name must be absolute", /* SMAP_URLE_NOABS */ @@ -114,7 +115,10 @@ split_connection(const char *cstr, else *pproto = proto; return rc; - } + } else { + free(proto); + return SMAP_URLE_INVALID; + } *pproto = proto; } return 0; @@ -201,7 +205,7 @@ int smap_url_parse(const char *cstr, struct sockaddr **psa, socklen_t *plen) { int rc; - char *proto, *port, *path; + char *proto = NULL, *port = NULL, *path = NULL; rc = split_connection(cstr, &proto, &port, &path); if (rc) diff --git a/modules/mailutils/mailutils.c b/modules/mailutils/mailutils.c index ea0314a..cdd0e7d 100644 --- a/modules/mailutils/mailutils.c +++ b/modules/mailutils/mailutils.c @@ -185,6 +185,7 @@ checksize(struct _mu_smap_db *mdb, smap_ostream_t ostr, char *reply_txt = NULL; auth = mu_get_auth_by_name(user); + res->auth = auth; if (!auth) { res->diag = "user not found"; smap_debug(dbgid, 1, ("%s: user not found", user)); @@ -329,26 +330,94 @@ _smap_debug_printer(void *data, mu_log_level_t level, const char *buf) smap_ostream_printf(str, "%s: %s", mu_program_name, buf); return 0; } + +struct cap_buf { + int err; + char **capa; + size_t numcapa; + size_t maxcapa; +}; +static int +cap_buf_init(struct cap_buf *bp) +{ + bp->err = 0; + bp->numcapa = 0; + bp->maxcapa = 2; + bp->capa = calloc(bp->maxcapa, sizeof bp->capa[0]); + if (!bp->capa) { + mu_error ("%s", mu_strerror(errno)); + bp->err = 1; + return 1; + } + bp->capa[0] = NULL; + return 0; +} + +static int +cap_buf_add(struct cap_buf *bp, char *str) +{ + if (bp->err) + return; + if (bp->numcapa == bp->maxcapa) { + size_t n = bp->maxcapa * 2; + char **p = realloc(bp->capa, n * sizeof bp->capa[0]); + if (!p) { + mu_error("%s", mu_strerror(errno)); + bp->err = 1; + return 1; + } + bp->capa = p; + bp->maxcapa = n; + } + bp->capa[bp->numcapa] = str; + if (str) + bp->numcapa++; + return 0; +} + +static void +cap_buf_free(struct cap_buf *bp) +{ + free(bp->capa); +} + +static int +_reg_action(void *item, void *data) +{ + struct cap_buf *bp = data; + return cap_buf_add(bp, item); +} + int mod_mailutils_init(int argc, char **argv) { int i, rc; mu_debug_t debug; struct mu_cfg_tree *parse_tree = NULL; + struct cap_buf cb; + int cfgflags = MU_PARSE_CONFIG_PLAIN; - static struct smap_option init_option[] = { + struct smap_option init_option[] = { { SMAP_OPTSTR(positive-reply), smap_opt_string, &dfl_positive_reply }, { SMAP_OPTSTR(negative-reply), smap_opt_string, &dfl_negative_reply }, { SMAP_OPTSTR(onerror-reply), smap_opt_string, &dfl_onerror_reply }, + { SMAP_OPTSTR(config-verbose), smap_opt_bitmask, + &cfgflags, { MU_PARSE_CONFIG_VERBOSE } }, + { SMAP_OPTSTR(config-dump), smap_opt_bitmask, + &cfgflags, { MU_PARSE_CONFIG_DUMP } }, { NULL } }; if (smap_parseopt(init_option, argc, argv, 0, NULL)) return 1; + if (cfgflags & MU_PARSE_CONFIG_VERBOSE) + mu_cfg_parser_verbose++; + if (cfgflags & MU_PARSE_CONFIG_DUMP) + mu_cfg_parser_verbose++; mu_set_program_name("smap-mailutils"); /**argv++*/ mu_diag_get_debug(&debug); @@ -360,19 +429,20 @@ mod_mailutils_init(int argc, char **argv) mu_register_all_mbox_formats(); for (i = 0; capa[i]; i++) mu_gocs_register_std(capa[i]); - /* mu_libcfg_init(NULL);*/ + + if (cap_buf_init(&cb) == 0) { + mu_gocs_enumerate(_reg_action, &cb); + cap_buf_add (&cb, NULL); + } + if (cb.err) + return 1; + mu_libcfg_init(cb.capa); + cap_buf_free(&cb); rc = mu_libcfg_parse_config(&parse_tree); - if (rc == 0) { - int cfgflags = MU_PARSE_CONFIG_PLAIN; - - if (mu_cfg_parser_verbose) - cfgflags |= MU_PARSE_CONFIG_VERBOSE; - if (mu_cfg_parser_verbose > 1) - cfgflags |= MU_PARSE_CONFIG_DUMP; + if (rc == 0) rc = mu_cfg_tree_reduce(parse_tree, mu_program_name, - cfg_param, cfgflags, NULL); - } + cfg_param, cfgflags, NULL); mu_gocs_flush(); return !!(rc || mu_cfg_error_count); } diff --git a/src/Makefile.am b/src/Makefile.am index 3378b8b..546f24c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -42,6 +42,6 @@ SUFFIXES=.opt .c BUILT_SOURCES=cmdline.c smapccmd.c EXTRA_DIST=cmdline.opt cmdline.c smapccmd.opt smapccmd.c -INCLUDES = -I$(top_srcdir)/include +INCLUDES = -I$(top_srcdir)/include @LTDLINCL@ AM_CPPFLAGS=-DSYSCONFDIR=\"$(sysconfdir)\"\ -DSMAP_MODDIR=\"$(SMAP_MODDIR)\" diff --git a/src/smapc.c b/src/smapc.c index 28fe71e..d64e1dd 100644 --- a/src/smapc.c +++ b/src/smapc.c @@ -553,9 +553,14 @@ read_eval_loop(FILE *fp) { char *p; char *map; - struct wordsplit ws; - int flags = WRDSF_DEFFLAGS|WRDSF_ENOMEMABRT|WRDSF_SHOWERR; int interactive = isatty(fileno(fp)); + int flags = WRDSF_DEFFLAGS | + WRDSF_COMMENT | + WRDSF_ENOMEMABRT | + WRDSF_SHOWERR; + struct wordsplit ws; + + ws.ws_comment = "#"; #ifdef WITH_READLINE if (interactive) { @@ -583,7 +588,7 @@ read_eval_loop(FILE *fp) if (wordsplit(p + !!cmdprefix, &ws, flags)) break; flags |= WRDSF_REUSE; - if (handle_command(&ws)) + if (ws.ws_wordc && handle_command(&ws)) break; continue; } diff --git a/src/smapd.c b/src/smapd.c index f3ea8f8..a2f919d 100644 --- a/src/smapd.c +++ b/src/smapd.c @@ -436,7 +436,7 @@ cfg_max_children(struct cfg_kw *kw, int wordc, char **wordv, void *data) if (cfg_chkargc(wordc, 2, 2)) return 1; - CFG_GETNUM(wordv[2], n); + CFG_GETNUM(wordv[1], n); smap_server_set_max_children(srv, n); return 0; } @@ -601,7 +601,7 @@ cfg_global_max_children(struct cfg_kw *kw, int wordc, char **wordv, void *data) if (cfg_chkargc(wordc, 2, 2)) return 1; - CFG_GETNUM(wordv[2], n); + CFG_GETNUM(wordv[1], n); srvman_param.max_children = n; return 0; } @@ -641,6 +641,7 @@ static struct cfg_kw smap_kwtab[] = { { "log-facility", KWT_FUN, &log_facility, NULL, NULL, set_syslog_facility }, { "debug", KWT_FUN, NULL, NULL, NULL, cfg_debug }, + { "trace", KWT_BOOL, &smap_trace_option }, /* Global privileges */ { "user", KWT_FUN, NULL, NULL, NULL, cfg_user }, diff --git a/src/srvman.c b/src/srvman.c index b767a87..5f853f3 100644 --- a/src/srvman.c +++ b/src/srvman.c @@ -426,8 +426,9 @@ static void server_run(int connfd, struct smap_server *srv, struct sockaddr *sa, socklen_t salen) { - if (!check_acl(srv->id, connfd) - || !check_acl(log_tag, connfd)) + if (sa->sa_family == AF_INET + && (!check_acl(srv->id, connfd) + || !check_acl(log_tag, connfd))) return; if (srvman_param.single_process |