diff options
Diffstat (limited to 'src/pies.c')
-rw-r--r-- | src/pies.c | 108 |
1 files changed, 78 insertions, 30 deletions
@@ -28,6 +28,7 @@ char *log_tag; struct pies_privs pies_privs; int foreground; int command; +int inetd_mode; char *pidfile = LOCALSTATEDIR "/pies.pid"; char *ctlfile = LOCALSTATEDIR "/pies.ctl"; char *statfile = LOCALSTATEDIR "/pies.stat"; @@ -712,33 +713,35 @@ _cb_url (enum grecs_callback_command cmd, return 0; } +int +str_to_socket_type (const char *str, int *pret) +{ + if (strcmp (str, "stream") == 0) + *pret = SOCK_STREAM; + else if (strcmp (str, "dgram") == 0) + *pret = SOCK_DGRAM; + else if (strcmp (str, "rdm") == 0) + *pret = SOCK_RDM; + else if (strcmp (str, "seqpacket") == 0) + *pret = SOCK_SEQPACKET; + else if (strcmp (str, "raw") == 0) + *pret = SOCK_RAW; + else + return 1; + return 0; +} + static int _cb_socket_type (enum grecs_callback_command cmd, grecs_locus_t *locus, void *varptr, grecs_value_t *value, void *cb_data) { - int t; - if (assert_scalar_stmt (locus, cmd) || assert_grecs_value_type (locus, value, GRECS_TYPE_STRING)) return 1; - if (strcmp (value->v.string, "stream") == 0) - t = SOCK_STREAM; - else if (strcmp (value->v.string, "dgram") == 0) - t = SOCK_DGRAM; - else if (strcmp (value->v.string, "rdm") == 0) - t = SOCK_RDM; - else if (strcmp (value->v.string, "seqpacket") == 0) - t = SOCK_SEQPACKET; - else if (strcmp (value->v.string, "raw") == 0) - t = SOCK_RAW; - else - { - grecs_error (locus, 0, _("bad socket type")); - return 0; - } - *(int*)varptr = t; + if (str_to_socket_type (value->v.string, varptr)) + grecs_error (locus, 0, _("bad socket type")); return 0; } @@ -1207,7 +1210,7 @@ static struct grecs_keyword syslog_kw[] = { struct component default_component; static int -_cm_include_meta1 (enum grecs_callback_command cmd, +_cb_include_meta1 (enum grecs_callback_command cmd, grecs_locus_t *locus, void *varptr, grecs_value_t *value, void *cb_data) { @@ -1217,6 +1220,16 @@ _cm_include_meta1 (enum grecs_callback_command cmd, return 0; } +static int +_cb_include_inetd (enum grecs_callback_command cmd, + grecs_locus_t *locus, + void *varptr, grecs_value_t *value, void *cb_data) +{ + if (assert_grecs_value_type (locus, value, GRECS_TYPE_STRING)) + return 1; + return inetd_parse_conf (value->v.string); +} + struct grecs_keyword pies_keywords[] = { {"component", N_("<tag: string>"), @@ -1303,11 +1316,16 @@ struct grecs_keyword pies_keywords[] = { N_("Define an ACL."), grecs_type_section, NULL, 0, defacl_section_parser, NULL, acl_keywords}, + {"include-inetd", + N_("file-or-dir: string"), + N_("Include inetd configuration file or directory"), + grecs_type_string, NULL, 0, + _cb_include_inetd }, {"include-meta1", N_("file: string"), N_("Include components from the specified MeTA1 configuration file."), grecs_type_string, NULL, 0, - _cm_include_meta1, + _cb_include_meta1, }, {"meta1-queue-dir", NULL, @@ -1391,6 +1409,8 @@ static struct argp_option options[] = { N_("parse configuration file and exit"), GRP + 1}, {NULL, 'E', NULL, 0, N_("preprocess config and exit"), GRP + 1}, + {"inetd", 'i', NULL, 0, + N_("run in inetd mode"), GRP + 1}, {"config-file", 'c', N_("FILE"), 0, N_("use FILE instead of the default configuration"), GRP + 1}, {"config-help", OPT_CONFIG_HELP, NULL, 0, @@ -1453,6 +1473,10 @@ parse_opt (int key, char *arg, struct argp_state *state) preprocess_only = 1; break; + case 'i': + inetd_mode = 1; + break; + case 't': log_to_stderr_only = 1; lint_mode = 1; @@ -1938,20 +1962,44 @@ main (int argc, char **argv) if (argp_parse (&argp, argc, argv, 0, &index, NULL)) exit (EX_USAGE); - if (!DEFAULT_PREPROCESSOR) - grecs_preprocessor = NULL; - else + if (inetd_mode) { - grecs_preprocessor = obstack_finish (&pp_stk); - free (pp_qopt); + if (index == argc) + { + if (inetd_parse_conf (SYSCONFDIR "/inetd.conf")) + exit (EX_CONFIG); + } + else + { + int i; + + for (i = index; i < argc; i++) + { + if (inetd_parse_conf (argv[i])) + exit (EX_CONFIG); + } + } + + index = argc; } + else + { + if (!DEFAULT_PREPROCESSOR) + grecs_preprocessor = NULL; + else + { + grecs_preprocessor = obstack_finish (&pp_stk); + free (pp_qopt); + } - if (preprocess_only) - exit (grecs_preproc_run (conffile, grecs_preprocessor) ? EX_CONFIG : 0); - - if (grecs_parse (conffile)) - exit (EX_CONFIG); + if (preprocess_only) + exit (grecs_preproc_run (conffile, grecs_preprocessor) + ? EX_CONFIG : 0); + if (grecs_parse (conffile)) + exit (EX_CONFIG); + } + set_mailer_argcv (); if (lint_mode) |