Skip to content

Commit 7293e32

Browse files
committed
id: add selinux/smack cfg alias
1 parent bbb093c commit 7293e32

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/id/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ path = "src/id.rs"
1919
test = false
2020
doctest = false
2121

22+
[build-dependencies]
23+
cfg_aliases.workspace = true
24+
2225
[dependencies]
2326
clap = { workspace = true }
2427
uucore = { workspace = true, features = ["entries", "process"] }

src/uu/id/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use cfg_aliases::cfg_aliases;
7+
8+
pub fn main() {
9+
cfg_aliases! {
10+
selinux: { all(feature = "selinux", any(target_os = "android", target_os = "linux")) },
11+
smack: { all(feature = "smack", target_os = "linux") },
12+
}
13+
}

src/uu/id/src/id.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ macro_rules! cstr2cow {
6363
}
6464

6565
fn get_context_help_text() -> String {
66-
#[cfg(any(
67-
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
68-
all(feature = "smack", target_os = "linux"),
69-
))]
66+
#[cfg(not(any(selinux, smack)))]
67+
return translate!("id-context-help-disabled");
68+
#[cfg(any(selinux, smack))]
7069
return translate!("id-context-help-enabled");
7170

7271
#[cfg(not(any(
@@ -106,9 +105,9 @@ struct State {
106105
rflag: bool, // --real
107106
zflag: bool, // --zero
108107
cflag: bool, // --context
109-
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
108+
#[cfg(selinux)]
110109
selinux_supported: bool,
111-
#[cfg(all(feature = "smack", target_os = "linux"))]
110+
#[cfg(smack)]
112111
smack_supported: bool,
113112
ids: Option<Ids>,
114113
// The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different.
@@ -147,9 +146,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
147146
rflag: matches.get_flag(options::OPT_REAL_ID),
148147
zflag: matches.get_flag(options::OPT_ZERO),
149148
cflag: matches.get_flag(options::OPT_CONTEXT),
150-
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
149+
#[cfg(selinux)]
151150
selinux_supported: uucore::selinux::is_selinux_enabled(),
152-
#[cfg(all(feature = "smack", target_os = "linux"))]
151+
#[cfg(smack)]
153152
smack_supported: uucore::smack::is_smack_enabled(),
154153
user_specified: !users.is_empty(),
155154
ids: None,
@@ -185,7 +184,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
185184

186185
if state.cflag {
187186
// SELinux context
188-
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
187+
#[cfg(selinux)]
189188
if state.selinux_supported {
190189
if let Ok(context) = selinux::SecurityContext::current(false) {
191190
let bytes = context.as_bytes();
@@ -199,7 +198,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
199198
}
200199

201200
// SMACK label
202-
#[cfg(all(feature = "smack", target_os = "linux"))]
201+
#[cfg(smack)]
203202
if state.smack_supported {
204203
match uucore::smack::get_smack_label_for_self() {
205204
Ok(label) => {
@@ -711,7 +710,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
711710
.join(",")
712711
)?;
713712

714-
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
713+
#[cfg(selinux)]
715714
if state.selinux_supported
716715
&& !state.user_specified
717716
&& std::env::var_os("POSIXLY_CORRECT").is_none()
@@ -723,7 +722,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
723722
}
724723
}
725724

726-
#[cfg(all(feature = "smack", target_os = "linux"))]
725+
#[cfg(smack)]
727726
if state.smack_supported
728727
&& !state.user_specified
729728
&& std::env::var_os("POSIXLY_CORRECT").is_none()

0 commit comments

Comments
 (0)