27a93650c0
libselinux selinux_android_restorecon API is changing to the more general interface with flags and dropping the older variants. Also get rid of the old, no longer used selinux_android_setfilecon API and rename selinux_android_setfilecon2 to it as it is the only API in use. Change-Id: I1e71ec398ccdc24cac4ec76f1b858d0f680f4925 Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
59 lines
1.3 KiB
C
59 lines
1.3 KiB
C
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <selinux/selinux.h>
|
|
#include <selinux/android.h>
|
|
|
|
static const char *progname;
|
|
|
|
static void usage(void)
|
|
{
|
|
fprintf(stderr, "usage: %s [-FnrRv] pathname...\n", progname);
|
|
exit(1);
|
|
}
|
|
|
|
int restorecon_main(int argc, char **argv)
|
|
{
|
|
int ch, i, rc;
|
|
unsigned int flags = 0;
|
|
|
|
progname = argv[0];
|
|
|
|
do {
|
|
ch = getopt(argc, argv, "FnrRv");
|
|
if (ch == EOF)
|
|
break;
|
|
switch (ch) {
|
|
case 'F':
|
|
flags |= SELINUX_ANDROID_RESTORECON_FORCE;
|
|
break;
|
|
case 'n':
|
|
flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
|
|
break;
|
|
case 'r':
|
|
case 'R':
|
|
flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
|
|
break;
|
|
case 'v':
|
|
flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
|
|
break;
|
|
default:
|
|
usage();
|
|
}
|
|
} while (1);
|
|
|
|
argc -= optind;
|
|
argv += optind;
|
|
if (!argc)
|
|
usage();
|
|
|
|
for (i = 0; i < argc; i++) {
|
|
rc = selinux_android_restorecon(argv[i], flags);
|
|
if (rc < 0)
|
|
fprintf(stderr, "Could not restorecon %s: %s\n", argv[i],
|
|
strerror(errno));
|
|
}
|
|
|
|
return 0;
|
|
}
|