From: octo Date: Fri, 6 May 2005 11:28:51 +0000 (+0000) Subject: Changed config handling. More fixes needed.. X-Git-Tag: Release-0.3~10 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6880416f9ad06412359f31a5438a785b37b4bbf4;p=licom.git Changed config handling. More fixes needed.. --- diff --git a/lib/LiCoM/Config.pm b/lib/LiCoM/Config.pm index c631a4b..f62c7d4 100644 --- a/lib/LiCoM/Config.pm +++ b/lib/LiCoM/Config.pm @@ -5,13 +5,60 @@ use warnings; use Exporter; -@LiCoM::Config::EXPORT_OK = ('get_config'); +@LiCoM::Config::EXPORT_OK = ('get_config read_config'); @LiCoM::Config::ISA = ('Exporter'); +our $Config = {}; + return (1); +=head1 STATIC FUNCTIONS + +=over 4 + +=item LiCoM::Config-EB (I<$key>) + +Returns the value for I<$key> or undef if it's unknown. + +=cut + sub get_config { + my $pkg = shift; + my $key = shift; + + if (!%$Config) + { + read_config (); + } + + return ($Config->{$key}); +} + +=item LiCoM::Config-EB (I<$key>, I<$value>) + +Sets the value of I<$key> to I<$value>. + +=cut + +sub set_config +{ + my $pkg = shift; + my $key = shift; + my $val = shift; + + $Config->{$key} = $val; +} + +=item LiCoM::Config-EB ([I<@files>]) + +Read the config from the files given or F and +F<~/.licomrc> if no files were given. + +=cut + +sub read_config +{ my @files = ('/etc/licom/licom.conf'); if (@_) @@ -59,3 +106,11 @@ sub read_file return ($config); } + +=back + +=head1 AUTHOR + +Florian octo Forster Eocto at verplant.orgE + +=cut diff --git a/lib/LiCoM/Group.pm b/lib/LiCoM/Group.pm index f7bd00d..e948926 100644 --- a/lib/LiCoM/Group.pm +++ b/lib/LiCoM/Group.pm @@ -3,6 +3,7 @@ package LiCoM::Group; use strict; use warnings; +use LiCoM::Config (qw(get_config)); use LiCoM::Connection (qw($Ldap)); use Net::LDAP; use Net::LDAP::Filter; @@ -41,12 +42,12 @@ sub load { my $pkg = shift; my $name = shift; - my $member_dn = 'cn=' . $name . ',' . $Config{'base_dn'}; + my $member_dn = _cn_to_dn ($name); my @retval = (); my $mesg = $Ldap->search ( - base => $Config{'base_dn'}, + base => get_config ('base_dn'), filter => "(&(objectClass=groupOfNames)(|(cn=$name)(member=$member_dn)))" ); @@ -78,7 +79,7 @@ sub create ($$$@) my $name = shift; my $desc = shift; my @members = @_; - my $dn = "cn=$name," . $Config{'base_dn'}; + my $dn = _cn_to_dn ($name); my $entry = Net::LDAP::Entry->new (); @@ -113,7 +114,7 @@ sub all my $mesg = $Ldap->search ( - base => $Config{'base_dn'}, + base => get_config ('base_dn'), filter => "(objectClass=groupOfNames)" ); @@ -222,17 +223,6 @@ sub del_members } } -sub _update_members -{ - my $obj = shift; - my $entry = $obj->{'ldap'}; - my @tmp = map { 'cn=' . $_ . ',' . $Config{'base_dn'} } (@{$obj->{'members'}}); - - $entry->changetype ('modify'); - $entry->replace (member => \@tmp); - $entry->update ($Ldap); -} - =item I<$obj>-EB ([I<$name>]) Sets the name if given. Returns the (new) name. @@ -251,7 +241,7 @@ sub name $entry->changetype ('modify'); $entry->replace (cn => $obj->{'name'}); $entry->update ($Ldap); - $entry->dn ('cn=' . $obj->{'name'} . ',' . $Config{'base_dn'}); + $entry->dn (_cn_to_dn ($obj->{'name'})); $entry->update ($Ldap); } @@ -281,6 +271,24 @@ sub description return ($obj->{'description'}); } +sub _cn_to_dn +{ + my $cn = shift; + my $base_dn = get_config ('base_dn') or die; + + return ('cn=' . $cn . ',' . $base_dn); +} + +sub _update_members +{ + my $obj = shift; + my $entry = $obj->{'ldap'}; + my @tmp = map { _cn_to_dn ($_); } (@{$obj->{'members'}}); + + $entry->changetype ('modify'); + $entry->replace (member => \@tmp); + $entry->update ($Ldap); +} =back