2008-08-19 19:30:36 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#include <selinux/get_context_list.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *seuser = NULL, *level = NULL;
|
2014-02-19 14:16:17 +00:00
|
|
|
char **contextlist;
|
2021-07-01 17:06:19 +00:00
|
|
|
int rc, n, i;
|
2008-08-19 19:30:36 +00:00
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "usage: %s linuxuser fromcon\n", argv[0]);
|
2021-01-07 20:41:54 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_selinux_enabled()) {
|
|
|
|
fprintf(stderr, "%s may be used only on a SELinux enabled kernel.\n", argv[0]);
|
|
|
|
return 4;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = getseuserbyname(argv[1], &seuser, &level);
|
|
|
|
if (rc) {
|
2021-01-07 20:41:54 +00:00
|
|
|
fprintf(stderr, "getseuserbyname failed: %s\n", strerror(errno));
|
|
|
|
return 2;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
|
|
|
printf("seuser: %s, level %s\n", seuser, level);
|
2021-01-07 20:41:54 +00:00
|
|
|
|
|
|
|
rc = security_check_context(argv[2]);
|
|
|
|
if (rc) {
|
|
|
|
fprintf(stderr, "context '%s' is invalid\n", argv[2]);
|
|
|
|
free(seuser);
|
|
|
|
free(level);
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = get_ordered_context_list_with_level(seuser, level, argv[2], &contextlist);
|
|
|
|
if (n < 0) {
|
|
|
|
fprintf(stderr, "get_ordered_context_list_with_level failed: %s\n", strerror(errno));
|
|
|
|
free(seuser);
|
|
|
|
free(level);
|
|
|
|
return 3;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|
2021-01-07 20:41:54 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
free(seuser);
|
|
|
|
free(level);
|
2021-01-07 20:41:54 +00:00
|
|
|
|
|
|
|
if (n == 0)
|
|
|
|
printf("no valid context found\n");
|
|
|
|
|
2021-07-01 17:06:19 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2008-08-19 19:30:36 +00:00
|
|
|
printf("Context %d\t%s\n", i, contextlist[i]);
|
2021-01-07 20:41:54 +00:00
|
|
|
|
2008-08-19 19:30:36 +00:00
|
|
|
freeconary(contextlist);
|
2021-01-07 20:41:54 +00:00
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
2008-08-19 19:30:36 +00:00
|
|
|
}
|