Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/uu/id/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ macro_rules! cstr2cow {
}

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

#[cfg(not(any(
all(feature = "selinux", any(target_os = "android", target_os = "linux")),
all(feature = "smack", target_os = "linux"),
)))]
return translate!("id-context-help-disabled");
}

mod options {
Expand Down Expand Up @@ -99,9 +106,9 @@ struct State {
rflag: bool, // --real
zflag: bool, // --zero
cflag: bool, // --context
#[cfg(feature = "selinux")]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
selinux_supported: bool,
#[cfg(feature = "smack")]
#[cfg(all(feature = "smack", target_os = "linux"))]
smack_supported: bool,
ids: Option<Ids>,
// The behavior for calling GNU's `id` and calling GNU's `id $USER` is similar but different.
Expand Down Expand Up @@ -140,10 +147,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
rflag: matches.get_flag(options::OPT_REAL_ID),
zflag: matches.get_flag(options::OPT_ZERO),
cflag: matches.get_flag(options::OPT_CONTEXT),

#[cfg(feature = "selinux")]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
selinux_supported: uucore::selinux::is_selinux_enabled(),
#[cfg(feature = "smack")]
#[cfg(all(feature = "smack", target_os = "linux"))]
smack_supported: uucore::smack::is_smack_enabled(),
user_specified: !users.is_empty(),
ids: None,
Expand Down Expand Up @@ -179,7 +185,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

if state.cflag {
// SELinux context
#[cfg(feature = "selinux")]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
if state.selinux_supported {
if let Ok(context) = selinux::SecurityContext::current(false) {
let bytes = context.as_bytes();
Expand All @@ -193,7 +199,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
}

// SMACK label
#[cfg(feature = "smack")]
#[cfg(all(feature = "smack", target_os = "linux"))]
if state.smack_supported {
match uucore::smack::get_smack_label_for_self() {
Ok(label) => {
Expand Down Expand Up @@ -705,7 +711,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
.join(",")
)?;

#[cfg(feature = "selinux")]
#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
if state.selinux_supported
&& !state.user_specified
&& std::env::var_os("POSIXLY_CORRECT").is_none()
Expand All @@ -717,7 +723,7 @@ fn id_print(state: &State, groups: &[u32]) -> io::Result<()> {
}
}

#[cfg(feature = "smack")]
#[cfg(all(feature = "smack", target_os = "linux"))]
if state.smack_supported
&& !state.user_specified
&& std::env::var_os("POSIXLY_CORRECT").is_none()
Expand Down
Loading