From: octo Date: Fri, 6 May 2005 12:55:25 +0000 (+0000) Subject: Removed moved functions/methods from LiCoM::Person X-Git-Tag: Release-0.3~9 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=58514068dafe37b69bca7d34e5d4bc2e6e234c9a;p=licom.git Removed moved functions/methods from LiCoM::Person Removed group functionality from LiCoM::Person --- diff --git a/lib/LiCoM/Group.pm b/lib/LiCoM/Group.pm index e948926..e828115 100644 --- a/lib/LiCoM/Group.pm +++ b/lib/LiCoM/Group.pm @@ -34,7 +34,8 @@ sub new =item LiCoM::Group-EB (I<$cn>) -Loads and returns the group named I<$cn> or with a member named I<$cn>. +Loads and returns the group named I<$cn> or all groups with a member named +I<$cn>. =cut @@ -69,7 +70,7 @@ sub load =item LiCoM::Group-EB (I<$name>, I<$description>, I<@members>) Creates and returns a new group. At least one member has to be given to meet -LDAP requirements. +LDAP requirements. I<@members> is an array of B-objects. =cut diff --git a/lib/LiCoM/Person.pm b/lib/LiCoM/Person.pm index e9b3063..b5c2fdf 100644 --- a/lib/LiCoM/Person.pm +++ b/lib/LiCoM/Person.pm @@ -3,6 +3,8 @@ package LiCoM::Person; use strict; use warnings; +use LiCoM::Config (qw(get_config)); + use Net::LDAP; use Net::LDAP::Filter; @@ -12,11 +14,6 @@ Person - High level interface for address books using an LDAP-backend. =cut -our %Config = -( - base_dn => undef -); - our %ValidFields = ( telephoneNumber => 1, @@ -29,7 +26,6 @@ our %ValidFields = labeledURI => 1, mail => 1, mobile => 1, - o => 1, userPassword => 0 ); @@ -45,7 +41,6 @@ our %ExternalNames = uri => 'labeledURI', mail => 'mail', cellphone => 'mobile', - group => 'o', password => 'userPassword' ); @@ -53,81 +48,11 @@ our $Ldap; return (1); -=head1 METHODS +=head1 STATIC FUNCTIONS =over 4 -=item Person-EB (I<$server>, I<$bind_dn>, I<$password>, I<$base_dn>, [I<$port>]) - -Connects to the LDAP-Server given. - -=cut - -sub connect -{ - my $pkg = shift; - my %opts = @_; - - my $bind_dn = $opts{'bind_dn'}; - my $base_dn = $opts{'base_dn'}; - my $uri = $opts{'uri'}; - my $passwd = $opts{'password'}; - - my $msg; - - die unless ($bind_dn and $base_dn and $uri and defined ($passwd)); - - $Ldap = Net::LDAP->new ($uri); - - $msg = $Ldap->bind ($bind_dn, password => $passwd); - if ($msg->is_error ()) - { - warn ('LDAP bind failed: ' . $msg->error_text ()); - return (0); - } - - $Config{'base_dn'} = $base_dn; - - return (1); -} - -=item Person-EB () - -Disconnect from the LDAP-Server. - -=cut - -sub disconnect -{ - $Ldap->unbind (); - $Ldap = undef; -} - -=item Person-EB (I<$ldap_entry>) - -Created a new I-object from the passed I-object. - -=cut - -sub new -{ - my $pkg = shift; - my $entry = shift; - my $obj = {}; - - $obj->{'dn'} = $entry->dn (); - $obj->{'ldap'} = $entry; - - for (keys %ValidFields) - { - my $key = $_; - $obj->{$key} = $entry->get_value ($key, asref => $ValidFields{$key}); - } - - return (bless ($obj, $pkg)); -} - -=item Person-EB (I<$cn>) +=item LiCoM::Person-EB (I<$cn>) Loads the given CN and returns the B-object. @@ -149,7 +74,7 @@ sub load return ($retval); } -=item Person-EB (B =E I<$lastname>, B =E I<$firstname>, ...) +=item LiCoM::Person-EB (B =E I<$lastname>, B =E I<$firstname>, ...) Create a new I-object and return it's corresponding I-object. @@ -163,7 +88,6 @@ sub create my %hash = @_; my $entry = Net::LDAP::Entry->new (); my $dn; - my $ou; $entry->add (objectClass => [qw(top organizationalUnit person organizationalPerson inetOrgPerson)]); @@ -223,16 +147,11 @@ sub create return (undef); } - $dn = "cn=$sn $gn," . $Config{'base_dn'}; - ($ou) = $Config{'base_dn'} =~ m/\bou\s*=\s*([^,]+)/i; + $dn = "cn=$sn $gn," . get_config ('base_dn'); - $entry->add (cn => "$sn $gn", ou => $ou); + $entry->add (cn => "$sn $gn"); $entry->dn ($dn); - print "\n"; - $entry->changetype ('add'); my $mesg = $entry->update ($Ldap); @@ -245,7 +164,7 @@ sub create return (new ($pkg, $entry)); } -=item Person-EB (B =E I<"Flor*">) +=item LiCoM::Person-EB (B =E I<"Flor*">) Search for the given patterns. Returns a list of I-objects. @@ -317,11 +236,9 @@ sub search $filter = '(objectclass=inetOrgPerson)'; } - #print STDERR "Debug: using filter: $filter"; - $mesg = $Ldap->search ( - base => $Config{'base_dn'}, + base => get_config ('base_dn'), filter => $filter ); @@ -342,6 +259,57 @@ sub search return (@retval); } +=item LiCoM::Person-EB (I<$dn>) + +Returns the cn and, if defined, the user-id of this dn. + +=cut + +sub get_user +{ + my $pkg = shift; + my $dn = shift; + my ($search) = $dn =~ m/cn\s*=\s*([^,]+)/i; + + die unless ($search); + + my $cn = ''; + my $id = ''; + + my $mesg = $Ldap->search + ( + base => get_config ('base_dn'), + filter => "(cn=$search)" + ); + + if ($mesg->is_error ()) + { + warn ("Error while querying LDAP server: " . $mesg->error_text ()); + return (''); + } + + for ($mesg->entries ()) + { + my $e = $_; + my ($t_cn) = $e->get_value ('cn', asref => 0); + my ($t_id) = $e->get_value ('uid', asref => 0); + + if (!$id or $t_id) + { + $cn = $t_cn; + $id = $t_id; + } + } + + return ($cn, $id); +} + +=back + +=head1 METHODS + +=over 4 + =item I<$obj>-EB () Deletes the record. @@ -373,7 +341,7 @@ sub _update_dn my $sn = $obj->{'sn'}; my $gn = $obj->{'givenName'}; my $cn = "$sn $gn"; - my $dn = "cn=$cn," . $Config{'base_dn'}; + my $dn = "cn=$cn," . get_config ('base_dn'); $obj->{'cn'} = $cn; @@ -539,89 +507,6 @@ sub set } } -sub get_user -{ - my $pkg = shift; - my $dn = shift; - my ($search) = $dn =~ m/cn\s*=\s*([^,]+)/i; - - die unless ($search); - - my $cn = ''; - my $id = ''; - - my $mesg = $Ldap->search - ( - base => $Config{'base_dn'}, - filter => "(cn=$search)" - ); - - if ($mesg->is_error ()) - { - warn ("Error while querying LDAP server: " . $mesg->error_text ()); - return (''); - } - - for ($mesg->entries ()) - { - my $e = $_; - my ($t_cn) = $e->get_value ('cn', asref => 0); - my ($t_id) = $e->get_value ('uid', asref => 0); - - if (!$id or $t_id) - { - $cn = $t_cn; - $id = $t_id; - } - } - - return ($cn, $id); -} - -=item LiCoM::Person-EB () - -Returns all defined groups. In scalar context returns a hash-ref with the -group-names as keys and the number of group members as values. In list context -returns a sorted list of group names. - -=cut - -sub all_groups -{ - my $pkg = shift; - my %retval = (); - - my $mesg = $Ldap->search - ( - base => $Config{'base_dn'}, - filter => "(objectClass=groupOfNames)" - ); - - if ($mesg->is_error ()) - { - warn ("Error while querying LDAP server: " . $mesg->error_text ()); - return (qw()); - } - - for ($mesg->entries ()) - { - my $entry = $_; - my ($name) = $entry->get_value ('cn', asref => 0); - my @members = $entry->get_value ('member', asref => 0); - - $retval{$name} = scalar (@members); - } - - if (wantarray ()) - { - return (sort (keys %retval)); - } - else - { - return (\%retval); - } -} - =back =head1 AUTHOR