Skip to content

Commit

Permalink
Merge pull request #281 from mknos/id-root
Browse files Browse the repository at this point in the history
id: uid 0 is valid
  • Loading branch information
briandfoy authored Oct 10, 2023
2 parents 97b398d + 92678da commit ed89d6a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions bin/id
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ my($user,$pw,$uid,$gid,$tp);

if ( @ARGV ) { # user specified
($user,$pw,$uid,$gid) = getpwnam $ARGV[0];
($user,$pw,$uid,$gid) = getpwuid $ARGV[0] unless ( $uid );
die "id: $ARGV[0]: No such user\n" unless ( $uid );
if (!defined($uid) && $ARGV[0] =~ m/\A[0-9]+\Z/) {
($user,$pw,$uid,$gid) = getpwuid $ARGV[0];
}
die "id: $ARGV[0]: No such user\n" unless (defined $uid);
}

if ( $opt_u ) { # print uid
$tp = ($uid)?$uid:($opt_r)?$<:$>;
$tp = defined $uid ? $uid : $opt_r ? $< : $>;
$tp = scalar getpwuid $tp || $tp if ( $opt_n );
}
elsif ( $opt_g ) { # print gid
Expand Down

0 comments on commit ed89d6a

Please sign in to comment.