2012-01-13 14:53:56 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <selinux/selinux.h>
|
2012-05-01 21:02:53 +02:00
|
|
|
#include <selinux/android.h>
|
2012-01-13 14:53:56 +01:00
|
|
|
|
|
|
|
static const char *progname;
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
2014-02-18 17:15:52 +01:00
|
|
|
fprintf(stderr, "usage: %s [-DFnrRv] pathname...\n", progname);
|
2012-01-13 14:53:56 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int restorecon_main(int argc, char **argv)
|
|
|
|
{
|
2014-01-30 16:15:16 +01:00
|
|
|
int ch, i, rc;
|
|
|
|
unsigned int flags = 0;
|
2012-01-13 14:53:56 +01:00
|
|
|
|
|
|
|
progname = argv[0];
|
|
|
|
|
|
|
|
do {
|
2014-02-18 17:15:52 +01:00
|
|
|
ch = getopt(argc, argv, "DFnrRv");
|
2012-01-13 14:53:56 +01:00
|
|
|
if (ch == EOF)
|
|
|
|
break;
|
|
|
|
switch (ch) {
|
2014-02-18 17:15:52 +01:00
|
|
|
case 'D':
|
|
|
|
flags |= SELINUX_ANDROID_RESTORECON_DATADATA;
|
|
|
|
break;
|
2014-01-30 16:15:16 +01:00
|
|
|
case 'F':
|
|
|
|
flags |= SELINUX_ANDROID_RESTORECON_FORCE;
|
|
|
|
break;
|
2012-01-13 14:53:56 +01:00
|
|
|
case 'n':
|
2014-01-30 16:15:16 +01:00
|
|
|
flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
|
2012-01-13 14:53:56 +01:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
2014-01-30 16:15:16 +01:00
|
|
|
flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
|
2012-01-13 14:53:56 +01:00
|
|
|
break;
|
|
|
|
case 'v':
|
2014-01-30 16:15:16 +01:00
|
|
|
flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
|
2012-01-13 14:53:56 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
if (!argc)
|
|
|
|
usage();
|
|
|
|
|
2014-01-30 16:15:16 +01:00
|
|
|
for (i = 0; i < argc; i++) {
|
2014-02-07 15:14:13 +01:00
|
|
|
rc = selinux_android_restorecon(argv[i], flags);
|
2014-01-30 16:15:16 +01:00
|
|
|
if (rc < 0)
|
|
|
|
fprintf(stderr, "Could not restorecon %s: %s\n", argv[i],
|
|
|
|
strerror(errno));
|
2012-01-13 14:53:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|