1 /* chcon.c - Change file security context
3 * Copyright 2014 The Android Open Source Project
5 USE_CHCON(NEWTOY(chcon, "<2hvR", TOYFLAG_USR|TOYFLAG_BIN))
9 depends on TOYBOX_SELINUX
12 usage: chcon [-hRv] CONTEXT FILE...
14 Change the SELinux security context of listed file[s].
16 -h change symlinks instead of what they point to.
17 -R recurse into subdirectories.
24 static int do_chcon(struct dirtree *try)
26 char *path, *con = *toys.optargs;
28 if (!dirtree_notdotdot(try)) return 0;
30 path = dirtree_path(try, 0);
31 if (toys.optflags & FLAG_v) printf("chcon '%s' to %s\n", path, con);
32 if (-1 == ((toys.optflags & FLAG_h) ? lsetfilecon : setfilecon)(path, con))
33 perror_msg("'%s' to %s", path, con);
36 return (toys.optflags & FLAG_R)*DIRTREE_RECURSE;
43 for (file = toys.optargs+1; *file; file++) dirtree_read(*file, do_chcon);