From ca7b6c8d2374f3ee16a0f9ea23bf722a7daa45d7 Mon Sep 17 00:00:00 2001 From: Vicent Guardiola Date: Fri, 20 Aug 2004 10:29:44 +0000 Subject: Remove reading conf_file duplicate with Ldap.pm Clean code --- ldap_wizard/ldapdef.pm | 52 +++++++++++++------------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/ldap_wizard/ldapdef.pm b/ldap_wizard/ldapdef.pm index f7d1d7f2..c2182401 100644 --- a/ldap_wizard/ldapdef.pm +++ b/ldap_wizard/ldapdef.pm @@ -16,57 +16,31 @@ use vars qw(@ISA @EXPORT %cfg %cfgfile $congfile $msg $attrs %ldap $ldap); @EXPORT=qw( %cfg %cfgfile $congfile ldap_connect root_bind $msg anonymous_bind ldap_search get_dn $attrs get_dse %ldap add_user); -my $ldap_suffix=join(',dc=', split(/\./, chomp_(`hostname -f`))); -$ldap_suffix =~ s/[^,]*,//; -my $conf_file = "/etc/sysconfig/ldapwiz"; - -##### Read conf file is exist - -my $hostname = `hostname`; -#my $o = MDK::Wizard::Ldap->new(); -my $o = { var => undef }; -$o->{var}{srv} = $hostname; - -if (-f $conf_file) { - my %conf = getVarsFromSh($conf_file); - $o->{var}{suffix} = $conf{suffix}; - $o->{var}{rootdn} = $conf{rootdn}; - $o->{var}{rootpass} = $conf{rootpass}; - $o->{var}{srv} = $conf{srv}; - $o->{var}{defou} = $conf{users}; - -} else { - my $hostname = chomp_(`hostname`); - $o->{var}{srv} = $hostname; - $o->{var}{suffix} = $ldap_suffix; -} - - - # Connect to Ldap server sub ldap_connect { my ($u) = @_; - print "srv: $u->{var}{srv}\n"; - Net::LDAP->new($u->{var}{srv}) or err_dialog(N("Error!"), N("Unable to connect to %s", $u->{var}{srv})); + my $ldap = Net::LDAP->new($u->{var}{srv}) or err_dialog(N("Error!"), N("Unable to connect to %s", $u->{var}{srv})); + return $ldap; } # bind root sub root_bind { - my ($ldap) = @_; - $ldap->bind(dn => $o->{var}{rootdn},password => $o->{var}{rootpass}); + my ($ldap,$u) = @_; + my $mesg = $ldap->bind(dn => $u->{var}{rootdn},password => $u->{var}{rootpass}); + return $mesg; } sub anonymous_bind { - my ($ds) = @_; - my $mesg=$ds->bind; - return $mesg->code; + my ($ldap) = @_; + my $mesg = $ldap->bind; + return $mesg; } sub ldap_search { - my ($ds, $filter, $basedn) = @_; + my ($ldap, $filter, $basedn) = @_; my $attrs = ['objectClass']; - my $mesg = $ds->search( + my $mesg = $ldap->search( base => $basedn, filter => $filter, scope => "sub", @@ -78,8 +52,8 @@ sub ldap_search { } sub get_dn { - my ($ds, $filter, $basedn, $attrs) = @_; - my $mesg = $ds->search( + my ($ldap, $filter, $basedn, $attrs) = @_; + my $mesg = $ldap->search( base => $basedn, filter => $filter, scope => "sub", @@ -108,7 +82,7 @@ sub get_dse() { sub add_user { my ($u) = @_; my $ldap = ldap_connect($u); - root_bind($ldap); + root_bind($ldap,$u); my $result = $ldap->add( "uid=$u->{var}{uid},$u->{var}{defou},$u->{var}{suffix}", attr => [ -- cgit v1.2.1