Skip to content

Commit 02fd684

Browse files
committed
treat invalid user or group as uid or gid if it's an integer
1 parent e96b536 commit 02fd684

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
@@ -405,7 +405,14 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
405405
} else {
406406
match usr2uid(&owner) {
407407
Ok(u) => Some(u),
408-
Err(_) => return Err(InstallError::InvalidUser(owner.clone()).into()),
408+
// When using -o500 option and there's no user with uid 500 on the system
409+
// usr2uid returns an Err value and the whole install operation fails.
410+
// GNU coreutils installs a file with uid 500 in the same situation
411+
// so just return the supplied owner as uid if it's an integer value
412+
Err(_) => match owner.parse::<u32>() {
413+
Ok(u) => Some(u),
414+
Err(_) => return Err(InstallError::InvalidUser(owner.clone()).into()),
415+
},
409416
}
410417
};
411418

@@ -419,7 +426,14 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
419426
} else {
420427
match grp2gid(&group) {
421428
Ok(g) => Some(g),
422-
Err(_) => return Err(InstallError::InvalidGroup(group.clone()).into()),
429+
// When using -g500 option and there's no group with gid 500 on the system
430+
// grp2gid returns an Err value and the whole install operation fails.
431+
// GNU coreutils installs a file with gid 500 in the same situation
432+
// so just return the supplied group as gid if it's an integer value
433+
Err(_) => match group.parse::<u32>() {
434+
Ok(g) => Some(g),
435+
Err(_) => return Err(InstallError::InvalidGroup(group.clone()).into()),
436+
},
423437
}
424438
};
425439

0 commit comments

Comments
 (0)