aboutsummaryrefslogtreecommitdiff
path: root/selinux
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 16:38:18 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-08 17:09:40 +0200
commit036585a911a5fe6c2cd77b808dd9150500f37272 (patch)
treeaa7c65b4d09c74642f622a1ef5da982d6ed4940a /selinux
parent00677b5e35dd97f415f0b0bef25b55865f55ab33 (diff)
downloadbusybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.tar.gz
busybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.tar.bz2
busybox-w32-036585a911a5fe6c2cd77b808dd9150500f37272.zip
getopt32: remove applet_long_options
FEATURE_GETOPT_LONG made dependent on LONG_OPTS. The folloving options are removed, now LONG_OPTS enables long options for affected applets: FEATURE_ENV_LONG_OPTIONS FEATURE_EXPAND_LONG_OPTIONS FEATURE_UNEXPAND_LONG_OPTIONS FEATURE_MKDIR_LONG_OPTIONS FEATURE_MV_LONG_OPTIONS FEATURE_RMDIR_LONG_OPTIONS FEATURE_ADDGROUP_LONG_OPTIONS FEATURE_ADDUSER_LONG_OPTIONS FEATURE_HWCLOCK_LONG_OPTIONS FEATURE_NSENTER_LONG_OPTS FEATURE_CHCON_LONG_OPTIONS FEATURE_RUNCON_LONG_OPTIONS They either had a small number of long options, or their long options are essential. Example: upstream addgroup and adduser have ONLY longopts, we should probably go further and get rid of non-standard short options. To this end, make addgroup and adduser "select LONG_OPTS". We had this breakage caused by us even in our own package! #if ENABLE_LONG_OPTS || !ENABLE_ADDGROUP /* We try to use --gid, not -g, because "standard" addgroup * has no short option -g, it has only long --gid. */ argv[1] = (char*)"--gid"; #else /* Breaks if system in fact does NOT use busybox addgroup */ argv[1] = (char*)"-g"; #endif xargs: its lone longopt no longer depends on DESKTOP, only on LONG_OPTS. hwclock TODO: get rid of incompatible -t, -l aliases to --systz, --localtime Shorten help texts by omitting long option when short opt alternative exists. Reduction of size comes from the fact that store of an immediate (an address of longopts) to a fixed address (global variable) is a longer insn than pushing that immediate or passing it in a register. This effect is CPU-agnostic. function old new delta getopt32 1350 22 -1328 vgetopt32 - 1318 +1318 getopt32long - 24 +24 tftpd_main 562 567 +5 scan_recursive 376 380 +4 collect_cpu 545 546 +1 date_main 1096 1095 -1 hostname_main 262 259 -3 uname_main 259 255 -4 setpriv_main 362 358 -4 rmdir_main 191 187 -4 mv_main 562 558 -4 ipcalc_main 548 544 -4 ifenslave_main 641 637 -4 gzip_main 192 188 -4 gunzip_main 77 73 -4 fsfreeze_main 81 77 -4 flock_main 318 314 -4 deluser_main 337 333 -4 cp_main 374 370 -4 chown_main 175 171 -4 applet_long_options 4 - -4 xargs_main 894 889 -5 wget_main 2540 2535 -5 udhcpc_main 2767 2762 -5 touch_main 436 431 -5 tar_main 1014 1009 -5 start_stop_daemon_main 1033 1028 -5 sed_main 682 677 -5 script_main 1082 1077 -5 run_parts_main 330 325 -5 rtcwake_main 459 454 -5 od_main 2169 2164 -5 nl_main 201 196 -5 modprobe_main 773 768 -5 mkdir_main 160 155 -5 ls_main 568 563 -5 install_main 773 768 -5 hwclock_main 411 406 -5 getopt_main 622 617 -5 fstrim_main 256 251 -5 env_main 198 193 -5 dumpleases_main 635 630 -5 dpkg_main 3991 3986 -5 diff_main 1355 1350 -5 cryptpw_main 233 228 -5 cpio_main 593 588 -5 conspy_main 1135 1130 -5 chpasswd_main 313 308 -5 adduser_main 887 882 -5 addgroup_main 416 411 -5 ftpgetput_main 351 345 -6 get_terminal_width_height 242 234 -8 expand_main 690 680 -10 static.expand_longopts 18 - -18 static.unexpand_longopts 27 - -27 mkdir_longopts 28 - -28 env_longopts 30 - -30 static.ifenslave_longopts 34 - -34 mv_longopts 46 - -46 static.rmdir_longopts 48 - -48 packed_usage 31739 31687 -52 ------------------------------------------------------------------------------ (add/remove: 2/8 grow/shrink: 3/49 up/down: 1352/-1840) Total: -488 bytes text data bss dec hex filename 915681 485 6880 923046 e15a6 busybox_old 915428 485 6876 922789 e14a5 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'selinux')
-rw-r--r--selinux/chcon.c41
-rw-r--r--selinux/runcon.c22
2 files changed, 14 insertions, 49 deletions
diff --git a/selinux/chcon.c b/selinux/chcon.c
index ae87fb554..3cf9e928a 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,22 @@
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(
30//usage: "\n chcon [OPTIONS] --reference=RFILE FILE..." 24//usage: "\n chcon [OPTIONS] --reference=RFILE FILE..."
31//usage: ) 25//usage:
32//usage:#define chcon_full_usage "\n\n" 26//usage:#define chcon_full_usage "\n\n"
33//usage: "Change the security context of each FILE to CONTEXT\n" 27//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" 28//usage: "\n -v Verbose"
48//usage: "\n -c Report changes made" 29//usage: "\n -c Report changes made"
49//usage: "\n -h Affect symlinks instead of their targets" 30//usage: "\n -h Affect symlinks instead of their targets"
50//usage: "\n -f Suppress most error messages" 31//usage: "\n -f Suppress most error messages"
32//usage: IF_LONG_OPTS(
33//usage: "\n --reference RFILE Use RFILE's group instead of using a CONTEXT value"
34//usage: )
51//usage: "\n -u USER Set user/role/type/range in the target security context" 35//usage: "\n -u USER Set user/role/type/range in the target security context"
52//usage: "\n -r ROLE" 36//usage: "\n -r ROLE"
53//usage: "\n -t TYPE" 37//usage: "\n -t TYPE"
54//usage: "\n -l RNG" 38//usage: "\n -l RNG"
55//usage: "\n -R Recurse" 39//usage: "\n -R Recurse"
56//usage: )
57 40
58#include <selinux/context.h> 41#include <selinux/context.h>
59 42
@@ -68,7 +51,7 @@
68#define OPT_TYPE (1<<6) /* 't' */ 51#define OPT_TYPE (1<<6) /* 't' */
69#define OPT_RANGE (1<<7) /* 'l' */ 52#define OPT_RANGE (1<<7) /* 'l' */
70#define OPT_VERBOSE (1<<8) /* 'v' */ 53#define OPT_VERBOSE (1<<8) /* 'v' */
71#define OPT_REFERENCE ((1<<9) * ENABLE_FEATURE_CHCON_LONG_OPTIONS) 54#define OPT_REFERENCE ((1<<9) * ENABLE_LONG_OPTS)
72#define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE) 55#define OPT_COMPONENT_SPECIFIED (OPT_USER | OPT_ROLE | OPT_TYPE | OPT_RANGE)
73 56
74static char *user = NULL; 57static char *user = NULL;
@@ -157,7 +140,7 @@ skip:
157 return rc; 140 return rc;
158} 141}
159 142
160#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 143#if ENABLE_LONG_OPTS
161static const char chcon_longopts[] ALIGN1 = 144static const char chcon_longopts[] ALIGN1 =
162 "recursive\0" No_argument "R" 145 "recursive\0" No_argument "R"
163 "changes\0" No_argument "c" 146 "changes\0" No_argument "c"
@@ -180,20 +163,18 @@ int chcon_main(int argc UNUSED_PARAM, char **argv)
180 char *fname; 163 char *fname;
181 int i, errors = 0; 164 int i, errors = 0;
182 165
183#if ENABLE_FEATURE_CHCON_LONG_OPTIONS
184 applet_long_options = chcon_longopts;
185#endif
186 opt_complementary = "-1" /* at least 1 param */ 166 opt_complementary = "-1" /* at least 1 param */
187 ":?" /* error if exclusivity constraints are violated */ 167 ":?" /* error if exclusivity constraints are violated */
188#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 168#if ENABLE_LONG_OPTS
189 ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff" 169 ":\xff--urtl:u--\xff:r--\xff:t--\xff:l--\xff"
190#endif 170#endif
191 ":f--v:v--f"; /* 'verbose' and 'quiet' are exclusive */ 171 ":f--v:v--f"; /* 'verbose' and 'quiet' are exclusive */
192 getopt32(argv, "Rchfu:r:t:l:v", 172 getopt32long(argv, "Rchfu:r:t:l:v", chcon_longopts,
193 &user, &role, &type, &range, &reference_file); 173 &user, &role, &type, &range, &reference_file
174 );
194 argv += optind; 175 argv += optind;
195 176
196#if ENABLE_FEATURE_CHCON_LONG_OPTIONS 177#if ENABLE_LONG_OPTS
197 if (option_mask32 & OPT_REFERENCE) { 178 if (option_mask32 & OPT_REFERENCE) {
198 /* FIXME: lgetfilecon() should be used when '-h' is specified. 179 /* FIXME: lgetfilecon() should be used when '-h' is specified.
199 * But current implementation follows the original one. */ 180 * But current implementation follows the original one. */
diff --git a/selinux/runcon.c b/selinux/runcon.c
index 09082d6c2..199da25c6 100644
--- a/selinux/runcon.c
+++ b/selinux/runcon.c
@@ -34,11 +34,6 @@
34//config: depends on SELINUX 34//config: depends on SELINUX
35//config: help 35//config: help
36//config: Enable support to run command in specified security context. 36//config: Enable support to run command in specified security context.
37//config:
38//config:config FEATURE_RUNCON_LONG_OPTIONS
39//config: bool "Enable long options"
40//config: default y
41//config: depends on RUNCON && LONG_OPTS
42 37
43//applet:IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP)) 38//applet:IF_RUNCON(APPLET(runcon, BB_DIR_USR_BIN, BB_SUID_DROP))
44 39
@@ -50,20 +45,11 @@
50//usage:#define runcon_full_usage "\n\n" 45//usage:#define runcon_full_usage "\n\n"
51//usage: "Run PROG in a different security context\n" 46//usage: "Run PROG in a different security context\n"
52//usage: "\n CONTEXT Complete security context\n" 47//usage: "\n CONTEXT Complete security context\n"
53//usage: IF_FEATURE_RUNCON_LONG_OPTIONS(
54//usage: "\n -c,--compute Compute process transition context before modifying"
55//usage: "\n -t,--type TYPE Type (for same role as parent)"
56//usage: "\n -u,--user USER User identity"
57//usage: "\n -r,--role ROLE Role"
58//usage: "\n -l,--range RNG Levelrange"
59//usage: )
60//usage: IF_NOT_FEATURE_RUNCON_LONG_OPTIONS(
61//usage: "\n -c Compute process transition context before modifying" 48//usage: "\n -c Compute process transition context before modifying"
62//usage: "\n -t TYPE Type (for same role as parent)" 49//usage: "\n -t TYPE Type (for same role as parent)"
63//usage: "\n -u USER User identity" 50//usage: "\n -u USER User identity"
64//usage: "\n -r ROLE Role" 51//usage: "\n -r ROLE Role"
65//usage: "\n -l RNG Levelrange" 52//usage: "\n -l RNG Levelrange"
66//usage: )
67 53
68#include <selinux/context.h> 54#include <selinux/context.h>
69/* from deprecated <selinux/flask.h>: */ 55/* from deprecated <selinux/flask.h>: */
@@ -108,7 +94,7 @@ static context_t runcon_compute_new_context(char *user, char *role, char *type,
108 return con; 94 return con;
109} 95}
110 96
111#if ENABLE_FEATURE_RUNCON_LONG_OPTIONS 97#if ENABLE_LONG_OPTS
112static const char runcon_longopts[] ALIGN1 = 98static const char runcon_longopts[] ALIGN1 =
113 "user\0" Required_argument "u" 99 "user\0" Required_argument "u"
114 "role\0" Required_argument "r" 100 "role\0" Required_argument "r"
@@ -140,11 +126,9 @@ int runcon_main(int argc UNUSED_PARAM, char **argv)
140 126
141 selinux_or_die(); 127 selinux_or_die();
142 128
143#if ENABLE_FEATURE_RUNCON_LONG_OPTIONS
144 applet_long_options = runcon_longopts;
145#endif
146 opt_complementary = "-1"; 129 opt_complementary = "-1";
147 opts = getopt32(argv, "r:t:u:l:ch", &role, &type, &user, &range); 130 opts = getopt32long(argv, "r:t:u:l:ch", runcon_longopts,
131 &role, &type, &user, &range);
148 argv += optind; 132 argv += optind;
149 133
150 if (!(opts & OPTS_CONTEXT_COMPONENT)) { 134 if (!(opts & OPTS_CONTEXT_COMPONENT)) {