aboutsummaryrefslogtreecommitdiff
path: root/src/pies.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-11-24 13:38:52 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2009-11-24 14:04:31 +0200
commite6772c4d68849cfdb4547a59bc51cb6dd0acd2c6 (patch)
tree72c0baa79455c9008df3f137a11117772b321a52 /src/pies.c
parent68796f86fe6abae13debf253c0e16b4bac9c1bca (diff)
downloadpies-e6772c4d68849cfdb4547a59bc51cb6dd0acd2c6.tar.gz
pies-e6772c4d68849cfdb4547a59bc51cb6dd0acd2c6.tar.bz2
Implement parsing of inetd.conf files.
* src/Makefile.am (pies_SOURCES): Add inetd.c. * src/inetd.c: New file. * src/pies.c (inetd_mode): New global. (str_to_socket_type): New function. (_cb_socket_type): Use str_to_socket_type. (_cm_include_meta1): Rename to _cb_include_meta1. (_cb_include_inetd): New function. (pies_keywords): New keyword "include-inetd". (options): New option --inetd. (main): Handle inetd mode. * src/pies.h (str_to_socket_type): New proto. (disable_socket, enable_socket): Fix return type. * src/progman.c (redirect_to_file): Avoid coredump on privs.user == NULL. (open_redirector,env_setup) (progman_start,run_command): Remove unneeded variable. (progman_start): Fix diagnostic message. * src/socket.c (disable_socket, enable_socket): Fix return type. Do nothing if fd < 0. * src/userprivs.c (switch_to_privs): Allow to pass uid==0.
Diffstat (limited to 'src/pies.c')
-rw-r--r--src/pies.c108
1 files changed, 78 insertions, 30 deletions
diff --git a/src/pies.c b/src/pies.c
index 2bf127c..fd83e04 100644
--- a/src/pies.c
+++ b/src/pies.c
@@ -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)

Return to:

Send suggestions and report system problems to the System administrator.