diff options
-rw-r--r-- | ldap_wizard/Ldap.pm | 36 | ||||
-rw-r--r-- | ldap_wizard/ldapdef.pm | 142 |
2 files changed, 84 insertions, 94 deletions
diff --git a/ldap_wizard/Ldap.pm b/ldap_wizard/Ldap.pm index 1d43e3cd..295b56d4 100644 --- a/ldap_wizard/Ldap.pm +++ b/ldap_wizard/Ldap.pm @@ -5,7 +5,7 @@ package MDK::Wizard::Ldap; use lib qw(/usr/lib/libDrakX); -use ugtk2; +use ugtk2 qw(:create); use strict; use ldapdef; use common; @@ -16,6 +16,8 @@ use Expect; require Net::LDAP; use Net::LDAP::Util qw(ldap_error_text); + + #unless ($> == 0) { # die "You are not root Exiting\n"; #} @@ -103,10 +105,9 @@ $o->{pages} = { sav_old_conf => { name => N("Save an existing configuration"), - post => \&sav_conf, - next => 'set_srv' + post => \&sav_conf, + next => 'set_srv' }, - add_userposix => { name => N("LDAP User Add") . "\n\n" . N("User Create in: ") . $o->{var}{defou} . ", " . $o->{var}{suffix}, data => [ @@ -157,8 +158,7 @@ $o->{pages} = { { label => N("LDAP Password (again):"), hidden => 1, val => \$o->{var}{rootpass2}, help => N("aide p") }, ], complete => sub { - - if (!$o->{var}{suffix} || $o->{var}{suffix} !~ /dc/ ) { + if (!$o->{var}{suffix} || $o->{var}{suffix} !~ /dc/) { $::in->ask_warn(N("Error"), N("You must enter a suffix for LDAP.")); return 1; } @@ -226,7 +226,6 @@ $o->{pages} = { }; sub do_it_setldap { - return if $::testing; if (!-f $LDAPCONF) { die "no $LDAPCONF found"; @@ -244,12 +243,12 @@ sub do_it_setldap { } else { append_to_file($LDAPCONF, qq(suffix\t"$o->{var}{suffix}")); } - - # s/example/$dcall + + # s/example/$dcall substInFile { s/example/$o->{var}{suffix}/g; } $LDAPCONF; - + # set rootdn if (any { /^rootdn/ } cat_($LDAPCONF)) { substInFile { @@ -292,14 +291,14 @@ EOF sub init_ldap { my $_root_cn = (split('=', (split(/,/, $o->{var}{rootdn}))[0]))[1]; my $ldap_dc = (split('=', (split(/,/, $o->{var}{suffix}))[0]))[1]; - + $o->{var}{rootdn} =~ /cn=(\w+),/ and my $cnadmin = $1; - + print "$o->{var}{rootdn}\n"; print "$o->{var}{rootpass}\n"; my $LDAP; open($LDAP, "| ldapadd -x -h $o->{var}{srv} -D '$o->{var}{rootdn}' -w $o->{var}{rootpass}"); - + print $LDAP <<RootLdif; dn: $o->{var}{suffix} dc: $ldap_dc @@ -335,18 +334,15 @@ RootLdif close($LDAP) } - - - sub do_it_user_add { return if $::testing; - my $_mesg = add_user($o); + add_user($o); } sub sav_conf { - system("slapcat -l /root/ldap-sav.ldiff"); - system("cp /etc/openldap/slapd.conf /root/"); - system("rm -fr /var/lib/ldap/*") + system("slapcat -l /root/ldap-sav.ldiff"); + system("cp /etc/openldap/slapd.conf /root/"); + system("rm -fr /var/lib/ldap/*") } sub new { diff --git a/ldap_wizard/ldapdef.pm b/ldap_wizard/ldapdef.pm index 7a1a6e9e..59134c0c 100644 --- a/ldap_wizard/ldapdef.pm +++ b/ldap_wizard/ldapdef.pm @@ -5,6 +5,9 @@ use MDK::Wizard::Ldap; use Net::LDAP; use Net::LDAP::Util qw(ldap_error_text); use MDK::Common; +use standalone; +use common; +use ugtk2 qw(:dialogs :create); require Exporter; @@ -23,11 +26,9 @@ my $hostname = `hostname`; #my $o = MDK::Wizard::Ldap->new(); my $o = { var => undef }; $o->{var}{srv} = $hostname; -print "tot"; if (-f $conf_file) { - - my %conf = getVarsFromSh($conf_file); + my %conf = getVarsFromSh($conf_file); $o->{var}{suffix} = $conf{suffix}; $o->{var}{rootdn} = $conf{rootdn}; $o->{var}{rootpass} = $conf{rootpass}; @@ -42,97 +43,90 @@ if (-f $conf_file) { -# Connect to Ldap server +# Connect to Ldap server sub ldap_connect { - my ($u) = @_; - print $u; - print " $u->{var}{srv}\n"; - Net::LDAP->new($o->{var}{srv}) or die "Impossible de se connecter au server"; - + 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})); } # bind root sub root_bind { - my ($ldap) = @_; - $ldap->bind(dn => $o->{var}{rootdn},password => $o->{var}{rootpass}); + my ($ldap) = @_; + $ldap->bind(dn => $o->{var}{rootdn},password => $o->{var}{rootpass}); } sub anonymous_bind { - my ($ds) = @_; - my $mesg=$ds->bind; - return $mesg->code; + my ($ds) = @_; + my $mesg=$ds->bind; + return $mesg->code; } sub ldap_search { - my ($ds, $filter, $basedn) = @_; - my $attrs = ['objectClass']; - my $mesg = $ds->search( - base => $basedn, - filter => $filter, - scope => "sub", - attrs => $attrs - ); - my $href = $mesg->as_struct; - print("Résultats de la recherchei\n"); - print $href; + my ($ds, $filter, $basedn) = @_; + my $attrs = ['objectClass']; + my $mesg = $ds->search( + base => $basedn, + filter => $filter, + scope => "sub", + attrs => $attrs + ); + my $href = $mesg->as_struct; + print("Search results\n"); + print $href; } sub get_dn { - my ($ds, $filter, $basedn, $attrs) = @_; - my $mesg = $ds->search( - base => $basedn, - filter => $filter, - scope => "sub", - #attrs => $attrs - ); - #my $entry = ""; - #foreach $entry ($mesg->entries) { - #print "show DN ".$entry->dn."\n"; - #} - return $mesg + my ($ds, $filter, $basedn, $attrs) = @_; + my $mesg = $ds->search( + base => $basedn, + filter => $filter, + scope => "sub", + #attrs => $attrs + ); + #my $entry = ""; + #foreach $entry ($mesg->entries) { + #print "show DN ".$entry->dn."\n"; + #} + return $mesg } sub get_dse() { - - my $ldap = ldap_connect(); - my $result = get_dn($ldap, "(objectclass=organization)", $cfg{base}); - my @arrayOfDNs = $result->entries; - #my %ldap = (); - foreach my $dn_value (@arrayOfDNs) + my $ldap = ldap_connect(); + my $result = get_dn($ldap, "(objectclass=organization)", $cfg{base}); + my @arrayOfDNs = $result->entries; + #my %ldap = (); + foreach my $dn_value (@arrayOfDNs) { - my $orga = $dn_value->dn; - $ldap{orga} = $orga; + my $orga = $dn_value->dn; + $ldap{orga} = $orga; } - return %ldap; + return %ldap; } sub add_user { - my ($u) = @_; - my $ldap = ldap_connect(); - root_bind($ldap); - my $result = $ldap->add( - "uid=$u->{var}{uid},$u->{var}{defou},$u->{var}{suffix}", - attr => [ - objectclass => ["top", "posixAccount", "inetOrgPerson", "shadowAccount"], - sn => $u->{var}{sn}, - uid => $u->{var}{uid}, - cn => $u->{var}{cn}, - userPassword => $u->{var}{uidpass}, - loginShell => $u->{var}{lshell}, - uidNumber => $u->{var}{uidnb}, - gidNumber => $u->{var}{gidnb}, - homeDirectory => $u->{var}{home} . $u->{var}{uid}, - shadowMin => '-1', - shadowMax => '999999', - shadowWarning => '7', - shadowInactive => '-1', - shadowExpire => '-1', - ] - ); - print ldap_error_text($result->code); -# return $result->code; - use lib qw(/usr/lib/libDrakX); - use standalone; - use ugtk2 qw(:ask :helpers :wrappers :create :dialogs); - create_dialog("Add user in OpenLDAP server", ldap_error_text($result->code)) } + my ($u) = @_; + my $ldap = ldap_connect(); + root_bind($ldap); + my $result = $ldap->add( + "uid=$u->{var}{uid},$u->{var}{defou},$u->{var}{suffix}", + attr => [ + objectclass => ["top", "posixAccount", "inetOrgPerson", "shadowAccount"], + sn => $u->{var}{sn}, + uid => $u->{var}{uid}, + cn => $u->{var}{cn}, + userPassword => $u->{var}{uidpass}, + loginShell => $u->{var}{lshell}, + uidNumber => $u->{var}{uidnb}, + gidNumber => $u->{var}{gidnb}, + homeDirectory => $u->{var}{home} . $u->{var}{uid}, + shadowMin => '-1', + shadowMax => '999999', + shadowWarning => '7', + shadowInactive => '-1', + shadowExpire => '-1', + ] + ); + create_dialog("", ldap_error_text($result->code)); +} |