• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <errno.h>
5 #include <selinux/selinux.h>
6 #include <selinux/android.h>
7 
8 static const char *progname;
9 
usage(void)10 static void usage(void)
11 {
12     fprintf(stderr, "usage:  %s [-DFnrRv] pathname...\n", progname);
13     exit(1);
14 }
15 
restorecon_main(int argc,char ** argv)16 int restorecon_main(int argc, char **argv)
17 {
18     int ch, i, rc;
19     unsigned int flags = 0;
20 
21     progname = argv[0];
22 
23     do {
24         ch = getopt(argc, argv, "DFnrRv");
25         if (ch == EOF)
26             break;
27         switch (ch) {
28         case 'D':
29             flags |= SELINUX_ANDROID_RESTORECON_DATADATA;
30             break;
31         case 'F':
32             flags |= SELINUX_ANDROID_RESTORECON_FORCE;
33             break;
34         case 'n':
35             flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
36             break;
37         case 'r':
38         case 'R':
39             flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
40             break;
41         case 'v':
42             flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
43             break;
44         default:
45             usage();
46         }
47     } while (1);
48 
49     argc -= optind;
50     argv += optind;
51     if (!argc)
52         usage();
53 
54     for (i = 0; i < argc; i++) {
55         rc = selinux_android_restorecon(argv[i], flags);
56         if (rc < 0)
57             fprintf(stderr, "Could not restorecon %s:  %s\n", argv[i],
58                     strerror(errno));
59     }
60 
61     return 0;
62 }
63