Mercurial > hg > toybox
annotate toys/pending/chcon.c @ 1639:856b544f8fce draft
strncpy(optptr, hname, strlen(hname)) is really just strcpy().
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 01 Jan 2015 16:49:55 -0600 |
parents | 51b7d1af353b |
children | b84024067049 |
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 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
5 USE_CHCON(NEWTOY(chcon, "hRv", TOYFLAG_USR|TOYFLAG_BIN)) |
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" |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
9 default n |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
10 help |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
11 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
|
12 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
13 Change the SELinux security context of listed file[s] (recursively with -R). |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
14 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
15 -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
|
16 -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
|
17 -v verbose output. |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
18 */ |
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 #define FOR_chcon |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
21 #include "toys.h" |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
22 #include <selinux/selinux.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 GLOBALS( |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
25 char *context; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
26 ) |
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 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
|
29 { |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
30 int ret; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
31 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
32 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
|
33 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
34 char *path = dirtree_path(try, 0); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
35 if (toys.optflags & FLAG_v) |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
36 printf("chcon '%s' to %s\n", path, TT.context); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
37 ret = ((toys.optflags&FLAG_h) ? lsetfilecon : setfilecon)(path, TT.context); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
38 if (ret == -1) |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
39 perror_msg("'%s' to %s", path, TT.context); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
40 free(path); |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
41 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
42 return (toys.optflags & FLAG_R) ? DIRTREE_RECURSE : 0; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
43 } |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
44 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
45 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
|
46 { |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
47 TT.context = *toys.optargs; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
48 char **file; |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
49 |
51b7d1af353b
here's a patch that should let us replace toolbox's chcon.
Elliott Hughes <enh@google.com>
parents:
diff
changeset
|
50 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
|
51 } |