1 | Also setgroups before setting gid/pid/home |
---|
2 | |
---|
3 | Author: Mario Limonciello <superm1@ubuntu.com> |
---|
4 | |
---|
5 | Bug: <url in upstream bugtracker> |
---|
6 | --- mythtv-0.23.0~trunk23567.orig/programs/mythbackend/main.cpp |
---|
7 | +++ mythtv-0.23.0~trunk23567/programs/mythbackend/main.cpp |
---|
8 | @@ -7,6 +7,7 @@ |
---|
9 | #include <libgen.h> |
---|
10 | #include <signal.h> |
---|
11 | #include <pwd.h> |
---|
12 | +#include <grp.h> |
---|
13 | |
---|
14 | #include "mythconfig.h" |
---|
15 | #if CONFIG_DARWIN |
---|
16 | @@ -878,6 +879,33 @@ int main(int argc, char **argv) |
---|
17 | } |
---|
18 | else if (!user_id && user_info) |
---|
19 | { |
---|
20 | + int ngroups = 1; |
---|
21 | + gid_t *groups; |
---|
22 | + groups = (gid_t*) malloc(ngroups * sizeof (gid_t)); |
---|
23 | + if (groups == NULL) |
---|
24 | + { |
---|
25 | + VERBOSE(VB_IMPORTANT, |
---|
26 | + QString("Error allocating memory for %1 groups.").arg(ngroups)); |
---|
27 | + return BACKEND_EXIT_PERMISSIONS_ERROR; |
---|
28 | + } |
---|
29 | + if (getgrouplist(user_info->pw_name, user_info->pw_gid, groups, &ngroups) == -1) |
---|
30 | + { |
---|
31 | + free(groups); |
---|
32 | + groups = (gid_t*) malloc(ngroups * sizeof (gid_t)); |
---|
33 | + if (groups == NULL) |
---|
34 | + { |
---|
35 | + VERBOSE(VB_IMPORTANT, |
---|
36 | + QString("Error allocating memory for %1 groups.").arg(ngroups)); |
---|
37 | + return BACKEND_EXIT_PERMISSIONS_ERROR; |
---|
38 | + } |
---|
39 | + getgrouplist(user_info->pw_name, user_info->pw_gid, groups, &ngroups); |
---|
40 | + } |
---|
41 | + free(groups); |
---|
42 | + if (setgroups(sizeof(groups), groups) == -1) |
---|
43 | + { |
---|
44 | + VERBOSE(VB_IMPORTANT, "Error setting groups."); |
---|
45 | + return BACKEND_EXIT_PERMISSIONS_ERROR; |
---|
46 | + } |
---|
47 | if (setenv("HOME", user_info->pw_dir,1) == -1) |
---|
48 | { |
---|
49 | VERBOSE(VB_IMPORTANT, "Error setting home directory."); |
---|