#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <setjmp.h>
#include <stdarg.h>
#include <cmocka.h>
#include <cap-ng.h>
#include <pwd.h>
#include <grp.h>
#include "test_amxrt_caps.h"
Go to the source code of this file.
◆ __real_capng_get_caps_process()
int __real_capng_get_caps_process |
( |
void |
| ) |
|
◆ __wrap_capng_apply() [1/2]
int __wrap_capng_apply |
( |
capng_select_t |
set | ) |
|
◆ __wrap_capng_apply() [2/2]
int __wrap_capng_apply |
( |
UNUSED capng_select_t |
set | ) |
|
◆ __wrap_capng_change_id() [1/2]
int __wrap_capng_change_id |
( |
int |
uid, |
|
|
int |
gid, |
|
|
capng_flags_t |
flag |
|
) |
| |
◆ __wrap_capng_change_id() [2/2]
int __wrap_capng_change_id |
( |
UNUSED int |
uid, |
|
|
UNUSED int |
gid, |
|
|
UNUSED capng_flags_t |
flag |
|
) |
| |
◆ __wrap_capng_clear() [1/2]
void __wrap_capng_clear |
( |
capng_select_t |
set | ) |
|
◆ __wrap_capng_clear() [2/2]
void __wrap_capng_clear |
( |
UNUSED capng_select_t |
set | ) |
|
◆ __wrap_capng_get_caps_process()
int __wrap_capng_get_caps_process |
( |
void |
| ) |
|
◆ __wrap_capng_update() [1/2]
int __wrap_capng_update |
( |
capng_act_t |
action, |
|
|
capng_type_t |
type, |
|
|
unsigned int |
capability |
|
) |
| |
◆ __wrap_capng_update() [2/2]
int __wrap_capng_update |
( |
UNUSED capng_act_t |
action, |
|
|
UNUSED capng_type_t |
type, |
|
|
UNUSED unsigned int |
capability |
|
) |
| |
◆ __wrap_getgrnam()
struct group * __wrap_getgrnam |
( |
const char * |
__name | ) |
|
Definition at line 108 of file test_amxrt_caps.c.
109 static struct group grp;
112 check_expected(name);
114 if(strcmp(name,
"webui") == 0) {
◆ __wrap_getpwnam()
struct passwd * __wrap_getpwnam |
( |
const char * |
__name | ) |
|
Definition at line 95 of file test_amxrt_caps.c.
96 static struct passwd pwd;
101 if(strcmp(name,
"webadmin") == 0) {
◆ test_caps_apply_can_fail()
void test_caps_apply_can_fail |
( |
UNUSED void ** |
state | ) |
|
Definition at line 277 of file test_amxrt_caps.c.
279 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
280 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
282 amxc_var_add(cstring_t, capabilities,
"CAP_CHOWN");
283 amxc_var_add(cstring_t, capabilities,
"CAP_KILL");
290 amxc_var_delete(&privileges);
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.
int __wrap_capng_update(capng_act_t action, capng_type_t type, unsigned int capability)
int __wrap_capng_apply(capng_select_t set)
◆ test_caps_can_dump_capabilities()
void test_caps_can_dump_capabilities |
( |
UNUSED void ** |
state | ) |
|
Definition at line 293 of file test_amxrt_caps.c.
void amxrt_caps_dump(void)
Dumps the capabilities of the process.
int __real_capng_get_caps_process(void)
◆ test_caps_can_keep_capabilities()
void test_caps_can_keep_capabilities |
( |
UNUSED void ** |
state | ) |
|
Definition at line 190 of file test_amxrt_caps.c.
192 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
193 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
195 amxc_var_add(cstring_t, capabilities,
"CAP_CHOWN");
196 amxc_var_add(cstring_t, capabilities,
"CAP_KILL");
203 amxc_var_set_type(capabilities, AMXC_VAR_ID_LIST);
204 amxc_var_add(cstring_t, capabilities,
"chown");
205 amxc_var_add(cstring_t, capabilities,
"KILL");
209 amxc_var_delete(&privileges);
◆ test_caps_can_use_capability_ids()
void test_caps_can_use_capability_ids |
( |
UNUSED void ** |
state | ) |
|
Definition at line 229 of file test_amxrt_caps.c.
231 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
232 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
234 amxc_var_add(uint32_t, capabilities, 0);
235 amxc_var_add(uint32_t, capabilities, 10);
243 amxc_var_delete(&privileges);
◆ test_caps_invalid_capability_ids_are_ignored()
void test_caps_invalid_capability_ids_are_ignored |
( |
UNUSED void ** |
state | ) |
|
Definition at line 246 of file test_amxrt_caps.c.
248 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
249 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
251 amxc_var_add(int32_t, capabilities, -1);
252 amxc_var_add(int32_t, capabilities, 25000);
258 amxc_var_delete(&privileges);
◆ test_caps_setup()
int test_caps_setup |
( |
UNUSED void ** |
state | ) |
|
◆ test_caps_switch_user_group()
void test_caps_switch_user_group |
( |
UNUSED void ** |
state | ) |
|
Definition at line 131 of file test_amxrt_caps.c.
133 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
135 amxc_var_add_key(cstring_t, privileges,
"user",
"webadmin");
136 amxc_var_add_key(cstring_t, privileges,
"group",
"webui");
143 amxc_var_delete(&privileges);
struct passwd * __wrap_getpwnam(const char *__name)
struct group * __wrap_getgrnam(const char *__name)
◆ test_caps_teardown()
int test_caps_teardown |
( |
UNUSED void ** |
state | ) |
|
◆ test_caps_unknown_capabilities_are_ignored()
void test_caps_unknown_capabilities_are_ignored |
( |
UNUSED void ** |
state | ) |
|
Definition at line 212 of file test_amxrt_caps.c.
214 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
215 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
217 amxc_var_add(cstring_t, capabilities,
"CAP_DUMMY");
219 amxc_var_set_type(capabilities, AMXC_VAR_ID_LIST);
220 amxc_var_add(cstring_t, capabilities,
"dummy");
226 amxc_var_delete(&privileges);
◆ test_caps_update_capability_can_fail()
void test_caps_update_capability_can_fail |
( |
UNUSED void ** |
state | ) |
|
Definition at line 261 of file test_amxrt_caps.c.
263 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
264 amxc_var_t* capabilities = amxc_var_add_key(amxc_llist_t, privileges,
"capabilities", NULL);
266 amxc_var_add(cstring_t, capabilities,
"CAP_KILL");
274 amxc_var_delete(&privileges);
◆ test_caps_use_non_existing_user_group()
void test_caps_use_non_existing_user_group |
( |
UNUSED void ** |
state | ) |
|
Definition at line 163 of file test_amxrt_caps.c.
165 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
167 amxc_var_add_key(cstring_t, privileges,
"user",
"non-existing");
168 amxc_var_add_key(cstring_t, privileges,
"group",
"fake-group");
175 amxc_var_delete(&privileges);
◆ test_caps_use_null_user_group()
void test_caps_use_null_user_group |
( |
UNUSED void ** |
state | ) |
|
Definition at line 146 of file test_amxrt_caps.c.
148 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
149 amxc_var_t* group = amxc_var_add_new_key(privileges,
"group");
151 amxc_var_add_new_key(privileges,
"user");
155 amxc_var_set(cstring_t, group,
"webui");
160 amxc_var_delete(&privileges);
◆ test_caps_use_user_and_group_id()
void test_caps_use_user_and_group_id |
( |
UNUSED void ** |
state | ) |
|
Definition at line 178 of file test_amxrt_caps.c.
180 amxc_var_t* privileges = amxc_var_add_key(amxc_htable_t,
config,
"privileges", NULL);
182 amxc_var_add_key(uint32_t, privileges,
"user", 100);
183 amxc_var_add_key(uint32_t, privileges,
"group", 100);
187 amxc_var_delete(&privileges);