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-E<gt>B<get_config> (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-E<gt>B<set_config> (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-E<gt>B<read_config> ([I<@files>])
+
+Read the config from the files given or F</etc/licom/licom.conf> and
+F<~/.licomrc> if no files were given.
+
+=cut
+
+sub read_config
+{
my @files = ('/etc/licom/licom.conf');
if (@_)
return ($config);
}
+
+=back
+
+=head1 AUTHOR
+
+Florian octo Forster E<lt>octo at verplant.orgE<gt>
+
+=cut
use strict;
use warnings;
+use LiCoM::Config (qw(get_config));
use LiCoM::Connection (qw($Ldap));
use Net::LDAP;
use Net::LDAP::Filter;
{
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)))"
);
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 ();
my $mesg = $Ldap->search
(
- base => $Config{'base_dn'},
+ base => get_config ('base_dn'),
filter => "(objectClass=groupOfNames)"
);
}
}
-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>-E<gt>B<name> ([I<$name>])
Sets the name if given. Returns the (new) 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);
}
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