Mercurial > hg > toybox
annotate toys/other/chcon.c @ 1776:7bf68329eb3b draft default tip
Repository switched to git at https://github.com/landley/toybox
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Apr 2015 02:28:32 -0500 |
parents | 7f4413a90d45 |
children |
rev | line source |
---|---|
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
1 /* chcon.c - Change file security context |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
2 * |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
3 * Copyright 2014 The Android Open Source Project |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
4 |
1686 | 5 USE_CHCON(NEWTOY(chcon, "<2hvR", TOYFLAG_USR|TOYFLAG_BIN)) |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
6 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
7 config CHCON |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
8 bool "chcon" |
1660
b84024067049
This patch adds a TOYBOX_SELINUX configuration option to control both
Elliott Hughes <enh@google.com>
parents:
1603
diff
changeset
|
9 depends on TOYBOX_SELINUX |
b84024067049
This patch adds a TOYBOX_SELINUX configuration option to control both
Elliott Hughes <enh@google.com>
parents:
1603
diff
changeset
|
10 default y |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
11 help |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
12 usage: chcon [-hRv] CONTEXT FILE... |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
13 |
1686 | 14 Change the SELinux security context of listed file[s]. |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
15 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
16 -h change symlinks instead of what they point to. |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
17 -R recurse into subdirectories. |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
18 -v verbose output. |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
19 */ |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
20 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
21 #define FOR_chcon |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
22 #include "toys.h" |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
23 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
24 int do_chcon(struct dirtree *try) |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
25 { |
1686 | 26 char *path, *con = *toys.optargs; |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
27 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
28 if (!dirtree_notdotdot(try)) return 0; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
29 |
1686 | 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); | |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
34 free(path); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
35 |
1686 | 36 return (toys.optflags & FLAG_R)*DIRTREE_RECURSE; |
1603
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
37 } |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
38 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
39 void chcon_main(void) |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
40 { |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
41 char **file; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
42 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
43 for (file = toys.optargs+1; *file; file++) dirtree_read(*file, do_chcon); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
44 } |