-
Notifications
You must be signed in to change notification settings - Fork 49
Create fifo as RUN_AS_USER, so watchdogs can use fifos #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ | |
| #include <sys/stat.h> // for mkfifo() | ||
| #include <fcntl.h> // for open() | ||
| #include <errno.h> | ||
| #include <grp.h> // for getgrnam() | ||
|
|
||
| /* Change this to the user under which to run */ | ||
| #define RUN_AS_USER "daemon" | ||
|
|
||
| /* this function is to allocate all possible resources before dropping | ||
| * privileges */ | ||
|
|
@@ -30,7 +34,13 @@ allocate_resources(const glb_cnf_t* conf, | |
| int* ctrl_sock, | ||
| int* listen_sock) | ||
| { | ||
| if (mkfifo (conf->fifo_name, S_IRUSR | S_IWUSR)) { | ||
| gid_t gid = getegid(); | ||
| struct group *grp = getgrnam(RUN_AS_USER); | ||
| setegid(grp->gr_gid); | ||
| mode_t um = umask(0); | ||
| if (mkfifo (conf->fifo_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP)) { | ||
| setegid(gid); | ||
| umask(um); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why bother doing |
||
| switch (errno) | ||
| { | ||
| case EEXIST: | ||
|
|
@@ -46,6 +56,10 @@ allocate_resources(const glb_cnf_t* conf, | |
| } | ||
| return 1; | ||
| } | ||
| else { | ||
| setegid(gid); | ||
| umask(um); | ||
| } | ||
|
|
||
| *ctrl_fifo = open (conf->fifo_name, O_RDWR); | ||
| if (*ctrl_fifo < 0) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,7 +174,7 @@ exec_thread (void* arg) | |
| goto init_error; | ||
| } | ||
|
|
||
| char* pargv[4] = { strdup ("sh"), strdup ("-c"), strdup (cmd), NULL }; | ||
| char* pargv[4] = { strdup ("bash"), strdup ("-c"), strdup (cmd), NULL }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that solution for a bug in |
||
|
|
||
| if (!pargv[0] || !pargv[1] || !pargv[2]) { | ||
| ctx->errn = ENOMEM; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have RUN_AS_USER independently defined in two different files. This does not look good.