#include "includes.h"
#include "sec_ctx_utils.h"
#define NUM_TESTS 10000
int main (int argc, char **argv)
{
int seed, level = 0, num_tests = 0;
init_sec_ctx();
if (argc == 1) {
seed = time(NULL);
} else {
seed = atoi(argv[1]);
}
printf("seed = %d\n", seed);
while(num_tests < NUM_TESTS) {
switch (random() % 2) {
case 0:
if (level < MAX_SEC_CTX_DEPTH) {
int ngroups;
gid_t *groups;
if (!push_sec_ctx()) {
printf("FAIL: push random ctx\n");
return 1;
}
get_random_grouplist(&ngroups, &groups);
set_sec_ctx(random() % 32767,
random() % 32767,
ngroups, groups);
if (!verify_current_groups(ngroups,
groups)) {
printf("FAIL: groups did not stick\n");
return 1;
}
printf("pushed (%d, %d) eff=(%d, %d)\n",
getuid(), getgid(), geteuid(),
getegid());
level++;
num_tests++;
free(groups);
}
break;
case 1:
if (level > 0) {
if (!pop_sec_ctx()) {
printf("FAIL: pop random ctx\n");
return 1;
}
printf("popped (%d, %d) eff=(%d, %d)\n",
getuid(), getgid(), geteuid(),
getegid());
level--;
num_tests++;
}
break;
}
}
printf("PASS\n");
return 0;
}