Skip to content

Commit

Permalink
Item12468: release UnixUsersContrib version 0.1.2
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/UnixUsersContrib@16648 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
JoenioCosta authored and JoenioCosta committed Apr 8, 2013
1 parent 723f54b commit bf1bc32
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
1 change: 1 addition & 0 deletions data/System/UnixUsersContrib.txt
Expand Up @@ -32,5 +32,6 @@ Settings are in =lib/LocalSite.cfg=. the Foswiki configure script does not curre
| Dependencies: | %$DEPENDENCIES% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 07 Apr 2013 | Bugfix revision |
| 24 May 2012 | Initial version |
| Home: | http://foswiki.org/Extensions/%TOPIC% |
2 changes: 1 addition & 1 deletion lib/Foswiki/Contrib/UnixUsersContrib.pm
Expand Up @@ -16,7 +16,7 @@

package Foswiki::Contrib::UnixUsersContrib;
use vars qw( $VERSION );
$VERSION = '0.1.0';
$VERSION = '0.1.2';
use strict;

sub debug {
Expand Down
57 changes: 33 additions & 24 deletions lib/Foswiki/Users/UnixUserMapping.pm
Expand Up @@ -56,25 +56,6 @@ sub new {
return $this;
}

sub unixUsers {
my $this = shift;
my %users = ();
debug "unixUsers()";
my $pipe = Foswiki::Contrib::UnixUsersContrib::openPipe(qw(/usr/bin/getent passwd));
while (<$pipe>) {
chomp;
if (m/(?<login>[\S]+):x:(?<uid>\d+):(?<gid>\d+):(?<fullname>[^,]+),[^,]*,[^,]*,:[^,]*:[^,]*/) {
my $login = $+{login};
#Make sure we're in 'ok' Wiki word territory
$users{$login}{fullname} = $+{fullname};
(my $wikiname = $+{fullname}) =~ s/[^\w]+(\w)/uc($1)/ge;
$users{$login}{wikiname} = ucfirst($wikiname);
}
}
close $pipe;
return \%users;
}

=pod
---++ ObjectMethod finish()
Expand Down Expand Up @@ -180,7 +161,6 @@ sub getWikiName {
debug "getWikiName($user)";
return $this->{users}{$user}{wikiname} if $this->{users}{$user};
return $user if grep { $user eq $this->{users}{$_}{wikiname} } keys %{$this->{users}};
return $user if $user =~ m/Group$/;
return $user;
}

Expand Down Expand Up @@ -266,8 +246,7 @@ Default is *false*

sub isInGroup {
my ($this, $user, $group) = @_;
debug "isInGroup($user, $group)";
my @users;
$user = $this->getWikiName($user);
my $it = $this->eachGroupMember($group);
while ($it->hasNext()) {
my $u = $this->getWikiName($it->next());
Expand Down Expand Up @@ -342,7 +321,7 @@ sub passwordError {

=pod
---++ ObjectMethod unixGroups() -> @groups
---++ ObjectMethod unixGroups() -> \%groups
Fetch all unix groups that match with "GroupFilter" configuration:
Expand Down Expand Up @@ -371,6 +350,34 @@ sub unixGroups {
return \%groups;
}

=pod
---++ ObjectMethod unixUsers() -> \%users
Fetch all unix users present in Unix Usesr Database (normally /etc/passwd)
=cut

sub unixUsers {
my $this = shift;
my %users = ();
debug "unixUsers()";
my $pipe = Foswiki::Contrib::UnixUsersContrib::openPipe(qw(/usr/bin/getent passwd));
while (<$pipe>) {
chomp;
if (m/(?<login>[\S]+):x:(?<uid>\d+):(?<gid>\d+):(?<fullname>[^,]+),[^,]*,[^,]*,:[^,]*:[^,]*/) {
my $login = $+{login};
#Make sure we're in 'ok' Wiki word territory
$users{$login}{fullname} = $+{fullname};
(my $wikiname = $+{fullname}) =~ s/[^\w]+(\w)/uc($1)/ge;
$users{$login}{wikiname} = ucfirst($wikiname);
}
}
close $pipe;
return \%users;
}


=pod
---++ ObjectMethod getLoginName($cUID) -> login
Expand All @@ -386,10 +393,12 @@ In UnixUserMapping canonical and login are the same!

sub getLoginName {
my ($this, $user) = @_;
foreach (keys %{$this->{users}}) {
return $_ if $user eq $this->{users}{$_}{wikiname};
}
return $user;
}


=pod
---++ ObjectMethod login2cUID($login, $dontcheck) -> cUID
Expand Down

0 comments on commit bf1bc32

Please sign in to comment.