Skip to content

Commit 845d80d

Browse files
committed
treat invalid user or group as uid or gid if it's an integer
1 parent 415d01c commit 845d80d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/uu/install/src/install.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,14 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
396396
} else {
397397
match usr2uid(&owner) {
398398
Ok(u) => Some(u),
399-
Err(_) => return Err(InstallError::InvalidUser(owner.clone()).into()),
399+
// When using -o500 option and there's no user with uid 500 on the system
400+
// usr2uid returns an Err value and the whole install operation fails.
401+
// GNU coreutils installs a file with uid 500 in the same situation
402+
// so just return the supplied owner as uid if it's an integer value
403+
Err(_) => match owner.parse::<u32>() {
404+
Ok(u) => Some(u),
405+
Err(_) => return Err(InstallError::InvalidUser(owner.clone()).into()),
406+
},
400407
}
401408
};
402409

@@ -410,7 +417,14 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
410417
} else {
411418
match grp2gid(&group) {
412419
Ok(g) => Some(g),
413-
Err(_) => return Err(InstallError::InvalidGroup(group.clone()).into()),
420+
// When using -g500 option and there's no group with gid 500 on the system
421+
// grp2gid returns an Err value and the whole install operation fails.
422+
// GNU coreutils installs a file with gid 500 in the same situation
423+
// so just return the supplied group as gid if it's an integer value
424+
Err(_) => match group.parse::<u32>() {
425+
Ok(g) => Some(g),
426+
Err(_) => return Err(InstallError::InvalidGroup(group.clone()).into()),
427+
},
414428
}
415429
};
416430

0 commit comments

Comments
 (0)