| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include "test-expander-users.h" |
| 24 |
|
| 25 |
#include <sepol/policydb/policydb.h> |
| 26 |
#include <CUnit/Basic.h> |
| 27 |
#include <stdlib.h> |
| 28 |
|
| 29 |
extern policydb_t user_expanded; |
| 30 |
|
| 31 |
static void check_user_roles(policydb_t * p, const char *user_name, const char **role_names, int num_roles) |
| 32 |
{ |
| 33 |
user_datum_t *user; |
| 34 |
ebitmap_node_t *tnode; |
| 35 |
unsigned int i; |
| 36 |
int j; |
| 37 |
unsigned char *found; |
| 38 |
int extra = 0; |
| 39 |
|
| 40 |
user = (user_datum_t *) hashtab_search(p->p_users.table, user_name); |
| 41 |
if (!user) { |
| 42 |
printf("%s not found\n", user_name); |
| 43 |
CU_FAIL("user not found"); |
| 44 |
return; |
| 45 |
} |
| 46 |
found = calloc(num_roles, sizeof(unsigned char)); |
| 47 |
CU_ASSERT_FATAL(found != NULL); |
| 48 |
ebitmap_for_each_bit(&user->roles.roles, tnode, i) { |
| 49 |
if (ebitmap_node_get_bit(tnode, i)) { |
| 50 |
extra++; |
| 51 |
for (j = 0; j < num_roles; j++) { |
| 52 |
if (strcmp(role_names[j], p->p_role_val_to_name[i]) == 0) { |
| 53 |
extra--; |
| 54 |
found[j] += 1; |
| 55 |
break; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
for (j = 0; j < num_roles; j++) { |
| 61 |
if (found[j] != 1) { |
| 62 |
printf("role %s associated with user %s %d times\n", role_names[j], user_name, found[j]); |
| 63 |
CU_FAIL("user mapping failure\n"); |
| 64 |
} |
| 65 |
} |
| 66 |
free(found); |
| 67 |
CU_ASSERT_EQUAL(extra, 0); |
| 68 |
} |
| 69 |
|
| 70 |
void test_expander_user_mapping(void) |
| 71 |
{ |
| 72 |
const char *roles1[] = { "user_check_1_1_r", "user_check_1_2_r" }; |
| 73 |
|
| 74 |
check_user_roles(&user_expanded, "user_check_1", roles1, 2); |
| 75 |
} |