From ab3292308a65af8a46469202addd92b407e6ec4a Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 5 Nov 2009 01:01:49 +0100 Subject: [PATCH] Girocco::User: Introduce load_by_uid() --- Girocco/User.pm | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Girocco/User.pm b/Girocco/User.pm index 6c6a04b..2811873 100644 --- a/Girocco/User.pm +++ b/Girocco/User.pm @@ -81,7 +81,7 @@ sub load { open F, jailed_file("/etc/passwd") or die "user load failed: $!"; while () { chomp; - @_ = split /:+/; + @_ = split /:/; next unless (shift eq $name); my $self = $class->_new($name); @@ -95,6 +95,28 @@ sub load { undef; } +# public constructor #2 +sub load_by_uid { + my $class = shift; + my ($uid) = @_; + + open F, jailed_file("/etc/passwd") or die "user load failed: $!"; + while () { + chomp; + @_ = split /:/; + next unless ($_[2] eq $uid); + + my $self = $class->_new($_[0]); + + (undef, undef, $self->{uid}, undef, $self->{email}) = @_; + ($self->{keys}, $self->{auth}) = $self->_sshkey_load; + + return $self; + } + close F; + undef; +} + # $user may not be in sane state if this returns false! sub cgi_fill { my $self = shift; -- 2.11.4.GIT