diff options
author | David Mitchell <davem@iabyn.com> | 2010-02-20 19:34:05 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2010-02-21 23:39:03 +0000 |
commit | 67d13d020f12d3ee57eba5c0a0265a692cf02e3f (patch) | |
tree | 5ba3405ac2757618569a1f73552d32744902f77f /t/op/groups.t | |
parent | b5ffec61b15547ad2797c1dab817816a248f736a (diff) | |
download | perl-67d13d020f12d3ee57eba5c0a0265a692cf02e3f.tar.gz |
stop op/groups.t skipping on Linux
My linux (with selinux) includes a "context=" field as part of the
output of "id -a". Make the extraction of the "groups=(.+)" entry
of "id -a" more robust in the presence of unpredictable (in name and
ordering) fields, by splitting on fieldname=(.*), then looking for a field
name of 'groups'.
Diffstat (limited to 't/op/groups.t')
-rw-r--r-- | t/op/groups.t | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/t/op/groups.t b/t/op/groups.t index 522701407e..c1cc889975 100644 --- a/t/op/groups.t +++ b/t/op/groups.t @@ -203,6 +203,9 @@ sub _system_groups { # uid=39957(gsar) gid=22(users) groups=33536,39181,22(users),0(root),1067(dev) # FreeBSD since 6.2 has a fake id -a: # uid=1001(tobez) gid=20(staff) groups=20(staff), 0(wheel), 68(dialer) + # + # Linux may also have a context= field + return ( $cmd, $str ); } @@ -243,9 +246,17 @@ sub extract_system_groups { # Remember that group names can contain whitespace, '-', '(parens)', # et cetera. That is: do not \w, do not \S. my @extracted; - if ($groups_string =~ /groups=(.+)( [ug]id=|$)/) { - my $gr = $1; + my @fields = split /\b(\w+=)/, $groups_string; + my $gr; + for my $i (0..@fields-2) { + if ($fields[$i] eq 'groups=') { + $gr = $fields[$i+1]; + $gr =~ s/ $//; + last; + } + } + if (defined $gr) { my @g = split m{, ?}, $gr; # prefer names over numbers for (@g) { |