68 if(amxc_var_type_of(user) == AMXC_VAR_ID_NULL) {
70 }
else if(amxc_var_type_of(user) == AMXC_VAR_ID_CSTRING) {
71 struct passwd* user_info = NULL;
72 user_info = getpwnam(GET_CHAR(user, NULL));
73 when_null_status(user_info, exit, uid = -1);
74 uid = user_info->pw_uid;
76 uid = GET_INT32(user, NULL);
86 if(amxc_var_type_of(group) == AMXC_VAR_ID_NULL) {
88 }
else if(amxc_var_type_of(group) == AMXC_VAR_ID_CSTRING) {
89 struct group* group_info = NULL;
90 group_info = getgrnam(GET_CHAR(group, NULL));
91 when_null_status(group_info, exit, gid = -1);
92 gid = group_info->gr_gid;
94 gid = GET_INT32(group, NULL);
104 amxc_var_t* privileges = GET_ARG(
config,
"privileges");
105 amxc_var_t* caps = GET_ARG(privileges,
"capabilities");
106 amxc_var_t* user = GET_ARG(privileges,
"user");
107 amxc_var_t* group = GET_ARG(privileges,
"group");
109 capng_get_caps_process();
110 when_null_status(privileges, exit, rv = 0);
112 if(!GET_BOOL(privileges,
"keep-all")) {
113 capng_clear(CAPNG_SELECT_BOTH);
115 amxc_var_for_each(cap, caps) {
118 if(amxc_var_type_of(cap) == AMXC_VAR_ID_CSTRING) {
119 const char* cap_name = GET_CHAR(cap, NULL);
120 amxc_string_t str_cap_name;
137 amxc_string_init(&str_cap_name, 0);
138 amxc_string_set(&str_cap_name, cap_name);
139 amxc_string_to_upper(&str_cap_name);
140 offset = strncmp(amxc_string_get(&str_cap_name, 0),
"CAP_", 4) == 0 ? 4 : 0;
141 amxc_string_clean(&str_cap_name);
143 id = capng_name_to_capability(cap_name + offset);
149 id = GET_INT32(cap, NULL);
150 if((
id < 0) || (
id > CAP_LAST_CAP)) {
155 rv = capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED | CAPNG_BOUNDING_SET | CAPNG_INHERITABLE),
id);
163 if((user == NULL) && (group == NULL)) {
165 rv = capng_apply(CAPNG_SELECT_BOTH);
171 rv = capng_change_id(uid, gid, (capng_flags_t) (CAPNG_DROP_SUPP_GRP));
181 capng_print_caps_numeric(CAPNG_PRINT_STDOUT, CAPNG_SELECT_BOTH);
183 printf(
"\nCAPNG_EFFECTIVE:\n");
184 capng_print_caps_text(CAPNG_PRINT_STDOUT, CAPNG_EFFECTIVE);
185 printf(
"\nCAPNG_PERMITTED:\n");
186 capng_print_caps_text(CAPNG_PRINT_STDOUT, CAPNG_PERMITTED);
187 printf(
"\nCAPNG_INHERITABLE:\n");
188 capng_print_caps_text(CAPNG_PRINT_STDOUT, CAPNG_INHERITABLE);
189 printf(
"\nCAPNG_BOUNDING_SET:\n");
190 capng_print_caps_text(CAPNG_PRINT_STDOUT, CAPNG_BOUNDING_SET);
static int32_t amxrt_get_user_id(amxc_var_t *user)
static int32_t amxrt_get_group_id(amxc_var_t *group)
PRIVATE void amxrt_print_message(const char *fmt,...)
PRIVATE int amxrt_dm_create_dir(amxo_parser_t *parser, uid_t uid, gid_t gid)
PRIVATE void amxrt_print_error(const char *fmt,...)
void amxrt_caps_dump(void)
Dumps the capabilities of the process.
int amxrt_caps_apply(void)
Apply the user, group and capabilities as defined in the configuration.
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
amxo_parser_t * amxrt_get_parser(void)
Gets runtime odl parser.