diff options
Diffstat (limited to 'selinux/chcon.c')
-rw-r--r-- | selinux/chcon.c | 50 |
1 files changed, 18 insertions, 32 deletions
diff --git a/selinux/chcon.c b/selinux/chcon.c index ae87fb554..3ddb2dd46 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c | |||
@@ -13,11 +13,6 @@ | |||
13 | //config: depends on SELINUX | 13 | //config: depends on SELINUX |
14 | //config: help | 14 | //config: help |
15 | //config: Enable support to change the security context of file. | 15 | //config: Enable support to change the security context of file. |
16 | //config: | ||
17 | //config:config FEATURE_CHCON_LONG_OPTIONS | ||
18 | //config: bool "Enable long options" | ||
19 | //config: default y | ||
20 | //config: depends on CHCON && LONG_OPTS | ||
21 | 16 | ||
22 | //applet:IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) | 17 | //applet:IF_CHCON(APPLET(chcon, BB_DIR_USR_BIN, BB_SUID_DROP)) |
23 | 18 | ||
@@ -26,34 +21,24 @@ | |||
26 | //usage:#define chcon_trivial_usage | 21 | //usage:#define chcon_trivial_usage |
27 | //usage: "[OPTIONS] CONTEXT FILE..." | 22 | //usage: "[OPTIONS] CONTEXT FILE..." |
28 | //usage: "\n chcon [OPTIONS] [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE..." | 23 | //usage: "\n chcon [OPTIONS] [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE..." |
29 | //usage: IF_FEATURE_CHCON_LONG_OPTIONS( | 24 | //usage: IF_LONG_OPTS( |
30 | //usage: "\n chcon [OPTIONS] --reference=RFILE FILE..." | 25 | //usage: "\n chcon [OPTIONS] --reference=RFILE FILE..." |
31 | //usage: ) | 26 | //usage: ) |
27 | //usage: | ||
32 | //usage:#define chcon_full_usage "\n\n" | 28 | //usage:#define chcon_full_usage "\n\n" |
33 | //usage: "Change the security context of each FILE to CONTEXT\n" | 29 | //usage: "Change the security context of each FILE to CONTEXT\n" |
34 | //usage: IF_FEATURE_CHCON_LONG_OPTIONS( | ||
35 | //usage: "\n -v,--verbose Verbose" | ||
36 | //usage: "\n -c,--changes Report changes made" | ||
37 | //usage: "\n -h,--no-dereference Affect symlinks instead of their targets" | ||
38 | //usage: "\n -f,--silent,--quiet Suppress most error messages" | ||
39 | //usage: "\n --reference RFILE Use RFILE's group instead of using a CONTEXT value" | ||
40 | //usage: "\n -u,--user USER Set user/role/type/range in the target" | ||
41 | //usage: "\n -r,--role ROLE security context" | ||
42 | //usage: "\n -t,--type TYPE" | ||
43 | //usage: "\n -l,--range RANGE" | ||
44 | //usage: "\n -R,--recursive Recurse" | ||
45 | //usage: ) | ||
46 | //usage: IF_NOT_FEATURE_CHCON_LONG_OPTIONS( | ||
47 | //usage: "\n -v Verbose" | 30 | //usage: "\n -v Verbose" |
48 | //usage: "\n -c Report changes made" | 31 | //usage: "\n -c Report changes made" |
49 | //usage: "\n -h Affect symlinks instead of their targets" | 32 | //usage: "\n -h Affect symlinks instead of their targets" |
50 | //usage: "\n -f Suppress most error messages" | 33 | //usage: "\n -f Suppress most error messages" |
34 | //usage: IF_LONG_OPTS( | ||
35 | //usage: "\n --reference RFILE Use RFILE's group instead of using a CONTEXT value" | ||
36 | //usage: ) | ||
51 | //usage: "\n -u USER Set user/role/type/range in the target security context" | 37 | //usage: "\n -u USER Set user/role/type/range in the target security context" |
52 | //usage: "\n -r ROLE" | 38 | //usage: "\n -r ROLE" |
53 | //usage: "\n -t TYPE" | 39 | //usage: "\n -t TYPE" |
54 | //usage: "\n -l RNG" | 40 | //usage: "\n -l RNG" |
55 | //usage: "\n -R Recurse" | 41 | //usage: "\n -R Recurse" |
56 | //usage: ) | ||
57 | 42 | ||
58 | #include <selinux/context.h> | 43 | #include <selinux/context.h> |
59 | 44 | ||
@@ -68,7 +53,7 @@ | |||
68 | #define OPT_TYPE (1<<6) /* 't' */ | 53 | #define OPT_TYPE (1<<6) /* 't' */ |
69 | #define OPT_RANGE (1<<7) /* 'l' */ | 54 | #define OPT_RANGE (1<<7) /* 'l' */ |
70 | #define OPT_VERBOSE (1<<8) /* 'v' */ | 55 | #define OPT_VERBOSE (1<<8) /* 'v' */ |
71 | #define OPT_REFERENCE ((1<<9) * ENABLE_FEATURE_CHCON_LONG_OPTIONS) | 56 | #define OPT_REFERENCE ((1<<9) * ENABLE_LONG_OPTS) |
72 | #define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE) | 57 | #define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE) |
73 | 58 | ||
74 | static char *user = NULL; | 59 | static char *user = NULL; |
@@ -157,7 +142,7 @@ skip: | |||
157 | return rc; | 142 | return rc; |
158 | } | 143 | } |
159 | 144 | ||
160 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 145 | #if ENABLE_LONG_OPTS |
161 | static const char chcon_longopts[] ALIGN1 = | 146 | static const char chcon_longopts[] ALIGN1 = |
162 | "recursive\0" No_argument "R" | 147 | "recursive\0" No_argument "R" |
163 | "changes\0" No_argument "c" | 148 | "changes\0" No_argument "c" |
@@ -180,20 +165,21 @@ int chcon_main(int argc UNUSED_PARAM, char **argv) | |||
180 | char *fname; | 165 | char *fname; |
181 | int i, errors = 0; | 166 | int i, errors = 0; |
182 | 167 | ||
183 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 168 | getopt32long(argv, "^" |
184 | applet_long_options = chcon_longopts; | 169 | "Rchfu:r:t:l:v" |
185 | #endif | 170 | "\0" |
186 | opt_complementary = "-1" /* at least 1 param */ | 171 | "-1" /* at least 1 arg */ |
187 | ":?" /* error if exclusivity constraints are violated */ | 172 | ":?" /* error if exclusivity constraints are violated */ |
188 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 173 | #if ENABLE_LONG_OPTS |
189 | ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff" | 174 | ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff" |
190 | #endif | 175 | #endif |
191 | ":f--v:v--f"; /* 'verbose' and 'quiet' are exclusive */ | 176 | ":f--v:v--f" /* 'verbose' and 'quiet' are exclusive */ |
192 | getopt32(argv, "Rchfu:r:t:l:v", | 177 | , chcon_longopts, |
193 | &user, &role, &type, &range, &reference_file); | 178 | &user, &role, &type, &range, &reference_file |
179 | ); | ||
194 | argv += optind; | 180 | argv += optind; |
195 | 181 | ||
196 | #if ENABLE_FEATURE_CHCON_LONG_OPTIONS | 182 | #if ENABLE_LONG_OPTS |
197 | if (option_mask32 & OPT_REFERENCE) { | 183 | if (option_mask32 & OPT_REFERENCE) { |
198 | /* FIXME: lgetfilecon() should be used when '-h' is specified. | 184 | /* FIXME: lgetfilecon() should be used when '-h' is specified. |
199 | * But current implementation follows the original one. */ | 185 | * But current implementation follows the original one. */ |