projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rrdtool plugin: Wait for the `queue thread' to exit..
[collectd.git]
/
src
/
exec.c
diff --git
a/src/exec.c
b/src/exec.c
index
e416c8f
..
d9f2d8c
100644
(file)
--- a/
src/exec.c
+++ b/
src/exec.c
@@
-118,6
+118,7
@@
static void exec_child (program_list_t *pl)
int status;
int uid;
int gid;
int status;
int uid;
int gid;
+ int egid;
char *arg0;
struct passwd *sp_ptr;
char *arg0;
struct passwd *sp_ptr;
@@
-140,20
+141,16
@@
static void exec_child (program_list_t *pl)
}
uid = sp.pw_uid;
}
uid = sp.pw_uid;
+ gid = sp.pw_gid;
if (uid == 0)
{
ERROR ("exec plugin: Cowardly refusing to exec program as root.");
exit (-1);
}
if (uid == 0)
{
ERROR ("exec plugin: Cowardly refusing to exec program as root.");
exit (-1);
}
- status = setuid (uid);
- if (status != 0)
- {
- ERROR ("exec plugin: setuid failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- exit (-1);
- }
-
+ /* The group configured in the configfile is set as effective group, because
+ * this way the forked process can (re-)gain the user's primary group. */
+ egid = -1;
if (NULL != pl->group)
{
if ('\0' != *pl->group) {
if (NULL != pl->group)
{
if ('\0' != *pl->group) {
@@
-173,22
+170,41
@@
static void exec_child (program_list_t *pl)
exit (-1);
}
exit (-1);
}
- gid = gr.gr_gid;
+
e
gid = gr.gr_gid;
}
else
{
}
else
{
-
gid = sp.pw_
gid;
+
egid =
gid;
}
}
+ } /* if (pl->group == NULL) */
- status = setgid (gid);
- if (0 != status)
+ status = setgid (gid);
+ if (status != 0)
+ {
+ ERROR ("exec plugin: setgid (%i) failed: %s",
+ gid, sstrerror (errno, errbuf, sizeof (errbuf)));
+ exit (-1);
+ }
+
+ if (egid != -1)
+ {
+ status = setegid (egid);
+ if (status != 0)
{
{
- ERROR ("exec plugin: set
gid
failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
+ ERROR ("exec plugin: set
egid (%i)
failed: %s",
+
egid,
sstrerror (errno, errbuf, sizeof (errbuf)));
exit (-1);
}
}
exit (-1);
}
}
+ status = setuid (uid);
+ if (status != 0)
+ {
+ ERROR ("exec plugin: setuid (%i) failed: %s",
+ uid, sstrerror (errno, errbuf, sizeof (errbuf)));
+ exit (-1);
+ }
+
arg0 = strrchr (pl->exec, '/');
if (arg0 != NULL)
arg0++;
arg0 = strrchr (pl->exec, '/');
if (arg0 != NULL)
arg0++;