mirror of
https://github.com/SELinuxProject/selinux
synced 2024-12-24 06:52:12 +00:00
9eb9c93275
In attempting to enable building various part of Android with -Wall -Werror, we found that the const security_context_t declarations in libselinux are incorrect; const char * was intended, but const security_context_t translates to char * const and triggers warnings on passing const char * from the caller. Easiest fix is to replace them all with const char *. And while we are at it, just get rid of all usage of security_context_t itself as it adds no value - there is no true encapsulation of the security context strings and callers already directly use string functions on them. typedef left to permit building legacy users until such a time as all are updated. This is a port of Change-Id I2f9df7bb9f575f76024c3e5f5b660345da2931a7 from Android, augmented to deal with all of the other code in upstream libselinux and updating the man pages too. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: Eric Paris <eparis@redhat.com>
41 lines
897 B
C
41 lines
897 B
C
#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);
|
|
}
|