39 #ifdef HAVE_SYS_PRCTL_H
40 #include <sys/prctl.h>
56 capng_clear(CAPNG_SELECT_BOTH);
62 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
70 capng_updatev(CAPNG_ADD, CAPNG_EFFECTIVE|CAPNG_PERMITTED,
77 if (capng_change_id(userid, groupid, CAPNG_DROP_SUPP_GRP |
78 CAPNG_CLEAR_BOUNDING) < 0)
84 SCLogInfo(
"dropped the caps for main thread");
90 capng_clear(CAPNG_SELECT_BOTH);
91 capng_apply(CAPNG_SELECT_BOTH);
93 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_IPC_LOCK);
94 capng_apply(CAPNG_SELECT_CAPS);
98 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_ADMIN);
99 capng_apply(CAPNG_SELECT_CAPS);
103 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BIND_SERVICE);
104 capng_apply(CAPNG_SELECT_CAPS);
105 SCLogDebug(
"For thread \"%s\" CAP_NET_BIND_SERVICE has been set",
tv->
name);
108 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BROADCAST);
109 capng_apply(CAPNG_SELECT_CAPS);
113 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_RAW);
114 capng_apply(CAPNG_SELECT_CAPS);
118 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_ADMIN);
119 capng_apply(CAPNG_SELECT_CAPS);
123 capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_RAWIO);
124 capng_apply(CAPNG_SELECT_CAPS);
141 void SCGetUserID(
const char *user_name,
const char *group_name, uint32_t *uid, uint32_t *gid)
144 uint32_t groupid = 0;
147 if (user_name == NULL || strlen(user_name) == 0) {
148 FatalError(
"no user name was provided - ensure it is specified either in the configuration "
149 "file (run-as.user) or in command-line arguments (--user)");
153 if (isdigit((
unsigned char)user_name[0]) != 0) {
155 FatalError(
"invalid user id value: '%s'", user_name);
157 pw = getpwuid(userid);
160 "check if user exist!!");
163 pw = getpwnam(user_name);
166 "check if user exist!!");
172 if (group_name != NULL) {
175 if (isdigit((
unsigned char)group_name[0]) != 0) {
177 FatalError(
"invalid group id: '%s'", group_name);
180 gp = getgrnam(group_name);
183 " ID, check if group exist!!");
185 groupid = gp->gr_gid;
188 groupid = pw->pw_gid;
213 if (group_name == NULL || strlen(group_name) == 0) {
214 FatalError(
"no group name was provided - ensure it is specified either in the "
215 "configuration file (run-as.group) or in command-line arguments (--group)");
219 if (isdigit((
unsigned char)group_name[0]) != 0) {
221 FatalError(
"invalid group id: '%s'", group_name);
224 gp = getgrnam(group_name);
227 " check if group exist!!");
241 int ret = pledge(
"stdio rpath wpath cpath fattr unix dns bpf", NULL);
245 " check permissions!! ret=%i errno=%i",