File: getseuser.c

package info (click to toggle)
libselinux 2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, experimental, sid
  • size: 2,080 kB
  • sloc: ansic: 16,057; makefile: 379; sh: 23
file content (40 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#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;
	char **contextlist;
	int rc, n, i;

	if (argc != 3) {
		fprintf(stderr, "usage:  %s linuxuser fromcon\n", argv[0]);
		exit(1);
	}

	rc = getseuserbyname(argv[1], &seuser, &level);
	if (rc) {
		fprintf(stderr, "getseuserbyname failed:  %s\n",
			strerror(errno));
		exit(2);
	}
	printf("seuser:  %s, level %s\n", seuser, level);
	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));
		exit(3);
	}
	free(seuser);
	free(level);
	for (i = 0; i < n; i++)
		printf("Context %d\t%s\n", i, contextlist[i]);
	freeconary(contextlist);
	exit(0);
}