Home | History | Annotate | Download | only in android
      1 /* restorecon.c - Restore default security contexts for files
      2  *
      3  * Copyright 2015 The Android Open Source Project
      4 
      5 USE_RESTORECON(NEWTOY(restorecon, "<1DFnRrv", TOYFLAG_USR|TOYFLAG_SBIN))
      6 
      7 config RESTORECON
      8   bool "restorecon"
      9   depends on TOYBOX_SELINUX
     10   default y
     11   help
     12     usage: restorecon [-D] [-F] [-R] [-n] [-v] FILE...
     13 
     14     Restores the default security contexts for the given files.
     15 
     16     -D	apply to /data/data too
     17     -F	force reset
     18     -R	recurse into directories
     19     -n	don't make any changes; useful with -v to see what would change
     20     -v	verbose: show any changes
     21 */
     22 
     23 #define FOR_restorecon
     24 #include "toys.h"
     25 
     26 #if defined(__ANDROID__)
     27 #include <selinux/android.h>
     28 #endif
     29 
     30 void restorecon_main(void)
     31 {
     32 #if defined(__ANDROID__)
     33   char **s;
     34   int flags = 0;
     35 
     36   if (toys.optflags & FLAG_D) flags |= SELINUX_ANDROID_RESTORECON_DATADATA;
     37   if (toys.optflags & FLAG_F) flags |= SELINUX_ANDROID_RESTORECON_FORCE;
     38   if (toys.optflags & (FLAG_R|FLAG_r))
     39     flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
     40   if (toys.optflags & FLAG_n) flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
     41   if (toys.optflags & FLAG_v) flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
     42 
     43   for (s = toys.optargs; *s; s++)
     44     if (selinux_android_restorecon(*s, flags) < 0)
     45       perror_msg("restorecon failed: %s", *s);
     46 #endif
     47 }
     48