aboutsummaryrefslogtreecommitdiff
path: root/selinux
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
committerRon Yorston <rmy@pobox.com>2017-08-22 14:56:12 +0100
commitce9af1cc5ea23f754587448cf35b5120c77bfeef (patch)
tree69e5eaba5e75ab909ed92d5045393471b8ff3c13 /selinux
parentc170026700eabb10147dd848c45c06995b43a32e (diff)
parente837a0dbbebf4229306df98fe9ee3b9bb30630c4 (diff)
downloadbusybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.gz
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.tar.bz2
busybox-w32-ce9af1cc5ea23f754587448cf35b5120c77bfeef.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'selinux')
-rw-r--r--selinux/chcon.c50
-rw-r--r--selinux/matchpathcon.c10
-rw-r--r--selinux/runcon.c27
-rw-r--r--selinux/sestatus.c3
-rw-r--r--selinux/setfiles.c22
5 files changed, 47 insertions, 65 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
74static char *user = NULL; 59static 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
161static const char chcon_longopts[] ALIGN1 = 146static 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. */
diff --git a/selinux/matchpathcon.c b/selinux/matchpathcon.c
index 3388d0857..e57120d3b 100644
--- a/selinux/matchpathcon.c
+++ b/selinux/matchpathcon.c
@@ -58,9 +58,13 @@ int matchpathcon_main(int argc UNUSED_PARAM, char **argv)
58 unsigned opts; 58 unsigned opts;
59 char *fcontext, *prefix, *path; 59 char *fcontext, *prefix, *path;
60 60
61 opt_complementary = "-1" /* at least one param reqd */ 61 opts = getopt32(argv, "^"
62 ":?:f--p:p--f"; /* mutually exclusive */ 62 "nNf:p:V"
63 opts = getopt32(argv, "nNf:p:V", &fcontext, &prefix); 63 "\0"
64 "-1" /* at least one param reqd */
65 ":?:f--p:p--f" /* mutually exclusive */
66 , &fcontext, &prefix
67 );
64 argv += optind; 68 argv += optind;
65 69
66 if (opts & OPT_NOT_TRANS) { 70 if (opts & OPT_NOT_TRANS) {
diff --git a/selinux/runcon.c b/selinux/runcon.c
index 09082d6c2..a5a394427 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,12 @@ 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 129 opts = getopt32long(argv, "^"
144 applet_long_options = runcon_longopts; 130 "r:t:u:l:ch"
145#endif 131 "\0" "-1",
146 opt_complementary = "-1"; 132 runcon_longopts,
147 opts = getopt32(argv, "r:t:u:l:ch", &role, &type, &user, &range); 133 &role, &type, &user, &range
134 );
148 argv += optind; 135 argv += optind;
149 136
150 if (!(opts & OPTS_CONTEXT_COMPONENT)) { 137 if (!(opts & OPTS_CONTEXT_COMPONENT)) {
diff --git a/selinux/sestatus.c b/selinux/sestatus.c
index daf4b223b..6954aca70 100644
--- a/selinux/sestatus.c
+++ b/selinux/sestatus.c
@@ -167,8 +167,7 @@ int sestatus_main(int argc UNUSED_PARAM, char **argv)
167 const char *pol_path; 167 const char *pol_path;
168 int rc; 168 int rc;
169 169
170 opt_complementary = "?0"; /* no arguments are required. */ 170 opts = getopt32(argv, "^" "vb" "\0" "=0"/*no arguments*/);
171 opts = getopt32(argv, "vb");
172 171
173 /* SELinux status: line */ 172 /* SELinux status: line */
174 rc = is_selinux_enabled(); 173 rc = is_selinux_enabled();
diff --git a/selinux/setfiles.c b/selinux/setfiles.c
index 01106bd67..8da47d274 100644
--- a/selinux/setfiles.c
+++ b/selinux/setfiles.c
@@ -610,17 +610,23 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv)
610 610
611 set_matchpathcon_flags(matchpathcon_flags); 611 set_matchpathcon_flags(matchpathcon_flags);
612 612
613 opt_complementary = "vv:v--p:p--v:v--q:q--v";
614 /* Option order must match OPT_x definitions! */ 613 /* Option order must match OPT_x definitions! */
615 if (applet_name[0] == 'r') { /* restorecon */ 614 if (applet_name[0] == 'r') { /* restorecon */
616 flags = getopt32(argv, "de:*f:ilnpqrsvo:FWR", 615 flags = getopt32(argv, "^"
617 &exclude_dir, &input_filename, &out_filename, &verbose); 616 "de:*f:ilnpqrsvo:FWR",
617 "\0" "vv:v--p:p--v:v--q:q--v";
618 &exclude_dir, &input_filename, &out_filename,
619 &verbose
620 );
618 } else { /* setfiles */ 621 } else { /* setfiles */
619 flags = getopt32(argv, "de:*f:ilnpqr:svo:FW" 622 flags = getopt32(argv, "^"
620 IF_FEATURE_SETFILES_CHECK_OPTION("c:"), 623 "de:*f:ilnpqr:svo:FW"
624 IF_FEATURE_SETFILES_CHECK_OPTION("c:"),
625 "\0" "vv:v--p:p--v:v--q:q--v";
621 &exclude_dir, &input_filename, &rootpath, &out_filename, 626 &exclude_dir, &input_filename, &rootpath, &out_filename,
622 IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,) 627 IF_FEATURE_SETFILES_CHECK_OPTION(&policyfile,)
623 &verbose); 628 &verbose
629 );
624 } 630 }
625 argv += optind; 631 argv += optind;
626 632
@@ -673,7 +679,7 @@ int setfiles_main(int argc UNUSED_PARAM, char **argv)
673 bb_show_usage(); 679 bb_show_usage();
674 xstat(argv[0], &sb); 680 xstat(argv[0], &sb);
675 if (!S_ISREG(sb.st_mode)) { 681 if (!S_ISREG(sb.st_mode)) {
676 bb_error_msg_and_die("spec file %s is not a regular file", argv[0]); 682 bb_error_msg_and_die("'%s' is not a regular file", argv[0]);
677 } 683 }
678 /* Load the file contexts configuration and check it. */ 684 /* Load the file contexts configuration and check it. */
679 rc = matchpathcon_init(argv[0]); 685 rc = matchpathcon_init(argv[0]);