summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 12c1e32)
raw | patch | inline | side by side (parent: 12c1e32)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 28 Aug 2007 16:54:53 +0000 (18:54 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Tue, 28 Aug 2007 22:37:46 +0000 (00:37 +0200) |
Now, the user and group as which the process should be executed can be
specified as the first argument to the "Exec" config option. The syntax is
identical to the one used by GNU's chown(1).
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@leeloo.lan.home.verplant.org>
specified as the first argument to the "Exec" config option. The syntax is
identical to the one used by GNU's chown(1).
Signed-off-by: Sebastian Harl <sh@tokkee.org>
Signed-off-by: Florian Forster <octo@leeloo.lan.home.verplant.org>
src/exec.c | patch | blob | history |
diff --git a/src/exec.c b/src/exec.c
index 058e7c4d30acf9bc8ad5f3a8e9b1122d987b5a79..21ac7c7320e7d520610b3a0e4ef2ab57514f0d1e 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
#include <sys/types.h>
#include <pwd.h>
+#include <grp.h>
#include <signal.h>
#include <pthread.h>
struct program_list_s
{
char *user;
+ char *group;
char *exec;
int pid;
program_list_t *next;
pl->next = pl_head;
pl_head = pl;
+
+ pl->group = strchr (pl->user, ':');
+ if (NULL != pl->group) {
+ *pl->group = '\0';
+ pl->group++;
+ }
}
else
{
{
int status;
int uid;
+ int gid;
char *arg0;
struct passwd *sp_ptr;
struct passwd sp;
- char pwnambuf[2048];
+ char nambuf[2048];
char errbuf[1024];
sp_ptr = NULL;
- status = getpwnam_r (pl->user, &sp, pwnambuf, sizeof (pwnambuf), &sp_ptr);
+ status = getpwnam_r (pl->user, &sp, nambuf, sizeof (nambuf), &sp_ptr);
if (status != 0)
{
ERROR ("exec plugin: getpwnam_r failed: %s",
exit (-1);
}
+ if (NULL != pl->group)
+ {
+ if ('\0' != *pl->group) {
+ struct group *gr_ptr = NULL;
+ struct group gr;
+
+ status = getgrnam_r (pl->group, &gr, nambuf, sizeof (nambuf), &gr_ptr);
+ if (0 != status)
+ {
+ ERROR ("exec plugin: getgrnam_r failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ exit (-1);
+ }
+ if (NULL == gr_ptr)
+ {
+ ERROR ("exec plugin: No such group: `%s'", pl->group);
+ exit (-1);
+ }
+
+ gid = gr.gr_gid;
+ }
+ else
+ {
+ gid = sp.pw_gid;
+ }
+
+ status = setgid (gid);
+ if (0 != status)
+ {
+ ERROR ("exec plugin: setgid failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ exit (-1);
+ }
+ }
+
arg0 = strrchr (pl->exec, '/');
if (arg0 != NULL)
arg0++;