Skip to content

Commit 8d60ea1

Browse files
authored
install: -o0 and -g0 ignored (#984)
* Include options -o and -g in the empty-string validation previously added for option -m * Generally uid 0 means "root user" on unix, and -o 0 could be given to explicitly install files as this user * The call to chown() was being ignored %perl mkdir d0 # after patch, as non-root user %perl install -o0 file d0 install: chown 0.1000 d0/file: Operation not permitted %perl install -g0 ar d0 install: chown 1000.0 d0/ar: Operation not permitted
1 parent 8fc4b57 commit 8d60ea1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bin/install

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ if ($opt{d} and grep($_, @opt{qw/ C c D p /}) > 0) {
5454
warn "$Program: -d not allowed with -[CcDp]\n";
5555
usage();
5656
}
57-
if (defined $opt{'m'} && length($opt{'m'}) == 0) {
58-
warn "$Program: invalid file mode: ''\n";
59-
exit 1;
57+
foreach my $x (qw(g m o)) {
58+
if (defined $opt{$x} && length($opt{$x}) == 0) {
59+
warn "$Program: invalid argument for option -$x\n";
60+
exit 1;
61+
}
6062
}
6163

6264
$opt{C}++ if $opt{p};
@@ -103,10 +105,12 @@ sub modify_file {
103105
}
104106
}
105107

106-
if ($opt{o} || $opt{g}) {
108+
if (defined $opt{'o'} || defined $opt{'g'}) {
107109
my @st = stat $path;
108-
my $uid = $opt{o} || $st[4];
109-
my $gid = $opt{g} || $st[5];
110+
my $uid = $opt{'o'};
111+
$uid = $st[4] unless defined $uid;
112+
my $gid = $opt{'g'};
113+
$gid = $st[5] unless defined $gid;
110114

111115
unless (chown $uid, $gid => $path) {
112116
warn "$Program: chown $uid.$gid $path: $!\n";

0 commit comments

Comments
 (0)