From: Gurusamy Sarathy Date: Sat, 14 Nov 1998 06:09:06 +0000 (+0000) Subject: rework op/groups.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f62c0cf247ab0260b680faf6bc722682ba662635;p=p5sagit%2Fp5-mst-13.2.git rework op/groups.t p4raw-id: //depot/perl@2240 --- diff --git a/t/op/filetest.t b/t/op/filetest.t old mode 100644 new mode 100755 diff --git a/t/op/groups.t b/t/op/groups.t index 6f7f8c4..78a748f 100755 --- a/t/op/groups.t +++ b/t/op/groups.t @@ -1,6 +1,6 @@ #!./perl -$ENV{PATH} = '/usr/xpg4/bin:/bin:/usr/bin:/usr/ucb'; +$ENV{PATH} = '/bin:/usr/bin:/usr/xpg4/bin:/usr/ucb'; # We have to find a command that prints all (effective # and real) group names (not ids). The known commands are: @@ -10,23 +10,44 @@ $ENV{PATH} = '/usr/xpg4/bin:/bin:/usr/bin:/usr/ucb'; # Beware 1: some systems do just 'id -G' even when 'id -Gn' is used. # Beware 2: id -Gn or id -a format might be id(name) or name(id). # Beware 3: the groups= might be anywhere in the id output. +# Beware 4: groups can have spaces ('id -a' being the only defense against this) # # That is, we might meet the following: # -# foo bar zot # accept -# 1 2 3 # reject -# groups=foo(1),bar(2),zot(3) # parse -# groups=1(foo),2(bar),3(zot) # parse +# foo bar zot # accept +# foo 22 42 bar zot # accept +# 1 22 42 2 3 # reject +# groups=(42),foo(1),bar(2),zot me(3) # parse +# groups=22,42,1(foo),2(bar),3(zot me) # parse # # and the groups= might be after, before, or between uid=... and gid=... GROUPS: { - last GROUPS if ($groups = `groups 2>/dev/null`) ne ''; - if ($groups = `id -Gn 2>/dev/null` ne '') { - last GROUPS unless $groups =~ /^(\d+)(\s+\d)*$/; + # prefer 'id' over 'groups' (is this ever wrong anywhere?) + # and 'id -a' over 'id -Gn' (the former is good about spaces in group names) + if (($groups = `id -a 2>/dev/null`) ne '') { + # $groups is of the form: + # uid=39957(gsar) gid=22(users) groups=33536,39181,22(users),0(root),1067(dev) + last GROUPS; + } + if (($groups = `id -Gn 2>/dev/null`) ne '') { + # $groups could be of the form: + # users 33536 39181 root dev + last GROUPS if $groups !~ /^(\d|\s)+$/; } - if ($groups = `id -a 2>/dev/null` ne '') { - # Grok format soon. + if (($groups = `groups 2>/dev/null`) ne '') { + # may not reflect all groups in some places, so do a sanity check + if (-d '/afs') { + print <