Changeset 1383
Set CAP_NET_ADMIN after setuid() to allow setting
all TOS bits (needed for DiffServ).
Committed by:
armin
Date:
Feb 14 2006 * 18:32 (over 2 years ago)
Affected files:
openpbx/trunk/corelib/openpbx.c (unified diff)
| r1379 | r1383 | |
|---|---|---|
| 79 | 79 | #include <netdb.h> |
| 80 | 80 | #endif |
| 81 | 81 | |
| 82 | #undef _POSIX_SOURCE | |
| 83 | #include <sys/capability.h> | |
| 84 | ||
| 82 | 85 | #include "openpbx.h" |
| 83 | 86 | |
| 84 | 87 | OPENPBX_FILE_VERSION("$HeadURL$", "$Revision$") |
| --- | --- | |
| 2058 | 2061 | if (!is_child_of_nonroot) { |
| 2059 | 2062 | struct group *gr; |
| 2060 | 2063 | struct passwd *pw; |
| 2064 | cap_user_header_t cap_header; | |
| 2065 | cap_user_data_t cap_data; | |
| 2061 | 2066 | |
| 2067 | cap_header = alloca(sizeof(*cap_header)); | |
| 2068 | cap_data = alloca(sizeof(*cap_data)); | |
| 2069 | if (cap_header != NULL) { | |
| 2070 | cap_header->version = _LINUX_CAPABILITY_VERSION; | |
| 2071 | cap_header->pid = 0; | |
| 2072 | } | |
| 2073 | /* inherit our capabilities */ | |
| 2074 | if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) == -1) { | |
| 2075 | opbx_log(LOG_WARNING, "Unable to keep capabilities: %s\n", strerror(errno)); | |
| 2076 | } | |
| 2077 | ||
| 2062 | 2078 | gr = getgrnam(rungroup); |
| 2063 | 2079 | if (!gr) { |
| 2064 | 2080 | opbx_log(LOG_ERROR, "No such group '%s'!\n", rungroup); |
| --- | --- | |
| 2124 | 2140 | opbx_verbose("Now running as user '' (%d)\n", getegid()); |
| 2125 | 2141 | } |
| 2126 | 2142 | } |
| 2143 | if ((cap_header != NULL) && (cap_data != NULL)) { | |
| 2144 | /* get current capabilities */ | |
| 2145 | if (capget(cap_header, cap_data) == -1) { | |
| 2146 | opbx_log(LOG_WARNING, "Unable to get capabilities\n"); | |
| 2147 | } | |
| 2148 | cap_data->effective = 1 << CAP_NET_ADMIN; | |
| 2149 | /* set capabilities including NET_ADMIN */ | |
| 2150 | /* this allows us to e.g. set all TOS bits */ | |
| 2151 | if (capset(cap_header, cap_data) == -1) { | |
| 2152 | opbx_log(LOG_WARNING, "Unable to set new capabilities (CAP_NET_ADMIN)\n"); | |
| 2153 | } | |
| 2154 | } | |
| 2127 | 2155 | } |
| 2128 | 2156 | |
| 2129 | 2157 | /* Check if we're root */ |
![Home changeset 1383 [home]](/images/logo.png?1180520111)
RSS Feeds