Skip to content

Commit 2c31110

Browse files
squellbjorn3
authored andcommitted
clarify the surprising use of pointers
1 parent ee50e3a commit 2c31110

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/sudoers/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,17 @@ fn group_cmd_specs_per_runas<'a>(
212212
let mut last_runas = None;
213213
let mut collected_specs = vec![];
214214

215+
// `distribute_tags` will have given every spec a reference to the "runas specification"
216+
// that applies to it. The output of sudo --list splits the CmndSpec list based on that:
217+
// every line only has a single "runas" specifier. So we need to combine them for that.
218+
//
219+
// But sudo --list also outputs lines that are from different lines in the sudoers file on
220+
// different lines in the output of sudo --list, so we cannot compare "by value". Luckily,
221+
// once a RunAs is parsed, it will have a unique identifier in the form of its address.
222+
let origin = |runas: Option<&RunAs>| runas.map(|r| r as *const _);
223+
215224
for (runas, (tag, spec)) in cmnd_specs {
216-
if runas.map(|r| r as *const _) != last_runas.map(|r| r as *const _) {
225+
if origin(runas) != origin(last_runas) {
217226
if !collected_specs.is_empty() {
218227
entries.push(Entry::new(
219228
last_runas,

0 commit comments

Comments
 (0)