aboutsummaryrefslogtreecommitdiff
path: root/pies/pies.c
diff options
context:
space:
mode:
Diffstat (limited to 'pies/pies.c')
-rw-r--r--pies/pies.c100
1 files changed, 8 insertions, 92 deletions
diff --git a/pies/pies.c b/pies/pies.c
index 7f1ed35..8c39cfa 100644
--- a/pies/pies.c
+++ b/pies/pies.c
@@ -21,7 +21,7 @@ int log_to_stderr; /* Use stderr for logging */
char *log_tag; /* override mu_log_tag */
mu_log_level_t debug_level;
mu_debug_t pies_debug;
-struct pies_privs_data pies_user;
+struct mf_privs pies_privs;
int foreground;
int command;
char *pidfile = STATEDIR "/pies.pid";
@@ -314,48 +314,6 @@ return_code_cfg_init ()
mu_cfg_section_add_params (section, return_code_cfg_param);
}
-
-static int
-_cb_group (mu_debug_t debug, void *data, mu_config_value_t *arg)
-{
- int argc, i;
- char **argv;
- mu_list_t *plist = data, list;
- int rc;
-
- if (mu_cfg_assert_value_type (arg, MU_CFG_STRING, debug))
- return 1;
- rc = mu_argcv_get_np (arg->v.string, strlen (arg->v.string),
- ",", NULL, 0, &argc, &argv, NULL);
- if (rc)
- {
- mu_cfg_format_error (debug, MU_DEBUG_ERROR,
- "mu_argcv_get: %s", mu_strerror (rc));
- return 1;
- }
- if (*plist)
- list = *plist;
- else
- {
- mu_list_create (&list);
- *plist = list;
- }
- for (i = 0; i < argc; i++)
- {
- struct group *group = getgrnam (argv[i]);
- if (!group)
- {
- mu_cfg_format_error (debug, MU_DEBUG_ERROR, _("Unknown group: %s"),
- argv[i]);
- continue;
- }
- mu_list_append (list, (void*)group->gr_gid);
- }
- mu_argcv_free (argc, argv);
- return 0;
-}
-
-
static int
_cb_command (mu_debug_t debug, void *data, mu_config_value_t *val)
{
@@ -677,8 +635,8 @@ struct mu_cfg_param component_cfg_param[] = {
{ "user", mu_cfg_string, NULL,
mu_offsetof (struct component, privs.user), NULL,
N_("Run with this user privileges.") },
- { "group", mu_cfg_callback, NULL,
- mu_offsetof (struct component, privs.groups), _cb_group,
+ { "group", MU_CFG_LIST_OF(mu_cfg_string), NULL,
+ mu_offsetof (struct component, privs.groups), NULL,
N_("Retain supplementary group.") },
{ "allgroups", mu_cfg_bool, NULL,
mu_offsetof (struct component, privs.allgroups), NULL,
@@ -886,11 +844,11 @@ struct mu_cfg_param pies_cfg_param[] = {
N_("Set location of the control file.") },
{ "stat-file", mu_cfg_string, &statfile, 0, NULL,
N_("Set location of the statistics output file.") },
- { "user", mu_cfg_string, &pies_user.user, 0, NULL,
+ { "user", mu_cfg_string, &pies_privs.user, 0, NULL,
N_("Run with this user privileges.") },
- { "group", mu_cfg_callback, &pies_user.groups, 0, _cb_group,
+ { "group", MU_CFG_LIST_OF(mu_cfg_string), &pies_privs.groups, 0, NULL,
N_("Retain supplementary group.") },
- { "allgroups", mu_cfg_bool, &pies_user.allgroups, 0, NULL,
+ { "allgroups", mu_cfg_bool, &pies_privs.allgroups, 0, NULL,
N_("Retain all supplementary groups of which user is a member.") },
{ "umask", mu_cfg_callback, &pies_umask, 0, _cb_umask,
N_("Force this umask."),
@@ -1047,48 +1005,6 @@ version (FILE *stream, struct argp_state *state)
}
-static void
-pies_add_allgroups (mu_list_t *pgrouplist, const char *user)
-{
- struct group *gr;
- mu_list_t list;
- if (!*pgrouplist)
- mu_list_create (pgrouplist);
- list = *pgrouplist;
- setgrent ();
- while (gr = getgrent ())
- {
- char **p;
- for (p = gr->gr_mem; *p; p++)
- if (strcmp (*p, user) == 0)
- {
- /* FIXME: Avoid duplicating gids */
- mu_list_append (list, (void*)gr->gr_gid);
- break;
- }
- }
- endgrent ();
-}
-
-void
-priv_setup (struct pies_privs_data *pr)
-{
- if (pr->user)
- {
- struct passwd *pw = getpwnam (pr->user);
- if (!pw)
- {
- mu_error (_("No such user: %s"), pr->user);
- exit (EX_CONFIG);
- }
- if (pr->allgroups)
- pies_add_allgroups (&pr->groups, pr->user);
- if (pw && switch_to_privs (pw->pw_uid, pw->pw_gid, pr->groups))
- exit (EX_SOFTWARE);
- }
-}
-
-
#define ACTION_CONT 0
#define ACTION_STOP 1
#define ACTION_RESTART 2
@@ -1377,7 +1293,7 @@ main (int argc, char **argv)
switch (command)
{
case OPT_RESTART:
- priv_setup (&pies_user);
+ mf_priv_setup (&pies_privs);
if (pies_umask)
umask (pies_umask);
exit (request_restart_components (argv + index));
@@ -1392,7 +1308,7 @@ main (int argc, char **argv)
exit (pies_stop ());
default:
- priv_setup (&pies_user);
+ mf_priv_setup (&pies_privs);
if (pies_umask)
umask (pies_umask);
}

Return to:

Send suggestions and report system problems to the System administrator.