diff options
author | Vicent Guardiola <vguardiola@mandriva.com> | 2004-01-20 15:36:36 +0000 |
---|---|---|
committer | Vicent Guardiola <vguardiola@mandriva.com> | 2004-01-20 15:36:36 +0000 |
commit | cb66ec60c32e120748c5699911e725a28cfb9943 (patch) | |
tree | f35afa41cabfd4a70b4b1674e19b9adf28a479d2 /ldap_wizard | |
parent | 2c420e97e1ffc3047e294f5185168cb8d9d39b66 (diff) | |
download | drakwizard-cb66ec60c32e120748c5699911e725a28cfb9943.tar drakwizard-cb66ec60c32e120748c5699911e725a28cfb9943.tar.gz drakwizard-cb66ec60c32e120748c5699911e725a28cfb9943.tar.bz2 drakwizard-cb66ec60c32e120748c5699911e725a28cfb9943.tar.xz drakwizard-cb66ec60c32e120748c5699911e725a28cfb9943.zip |
Function for Wizard LDAP
Diffstat (limited to 'ldap_wizard')
-rw-r--r-- | ldap_wizard/fcldap.pm | 172 |
1 files changed, 92 insertions, 80 deletions
diff --git a/ldap_wizard/fcldap.pm b/ldap_wizard/fcldap.pm index 4af1f62a..12834028 100644 --- a/ldap_wizard/fcldap.pm +++ b/ldap_wizard/fcldap.pm @@ -1,23 +1,3 @@ -# version 0.1 -# -# Copyright (C) 2002,2003 Mandrakesoft -# -# Author: vguardiola _at_ mandrakesoft.com -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - package fcldap; use strict; use Net::LDAP; @@ -34,69 +14,76 @@ use Exporter; add_user_posix create_rootdse create_rootdse_file + add_ou + tutu ); sub cnx_ldap_ano { - my $srv = shift; - my $ldap = Net::LDAP->new($srv) or die $@; + my ($u) = @_; + my $ldap = Net::LDAP->new($u->{var}{srv}) or die $@; my $mesg = $ldap->bind; - return $ldap; + return ($ldap); } sub cnx_ldap_user { - my ($srv, $rootdn, $pass) = @_; - my $ldap = Net::LDAP->new($srv) or die $@; - my $mesg = $ldap->bind(cn => $rootdn, - password => $pass, + my ($u) = @_; + print "cnx_ldap_user not connect\n"; + my $ldap = Net::LDAP->new($u->{var}{srv}) or die $@; + print "cnx_ldap_user \n"; + print "$u->{var}{rootdn} \n"; + print "$u->{var}{rootdse} \n"; + print "$u->{var}{rootpass} \n"; + my $mesg = $ldap->bind( "$u->{var}{rootdn},$u->{var}{rootdse}", + password => "$u->{var}{rootpass}", ); - return $ldap; + + print "$ldap \n"; + return ($ldap); } sub create_rootdse_file { my ($u) = @_; output('/tmp/rootdse.ldif', <<EOF); -dn: dc=mdkconsulting,dc=com +dn: $u->{var}{rootdse} objectclass: dcObject objectclass: organization o: Example Company -dc: example +dc: $u->{var}{dom} -dn: cn=manager,dc=mdkconsulting,dc=com +dn: cn=$u->{var}{rootdn},$u->{var}{rootdse} objectclass: organizationalRole -cn: Manager +cn: $u->{var}{rootdn} + + +dn: ou=$u->{var}{defou},$u->{var}{rootdse} +objectClass: top +objectClass: organizationalUnit +ou: $u->{var}{defou} +description: $u->{var}{defou} EOF } sub create_rootdse { my ($u) = @_; - my $ldap=Net::LDAP->new('loki') or die $@; - my $mesg = $ldap->bind('cn=manager,dc=mdkconsulting,dc=com', - password => 'secret' - ); - create_rootdse_file(); - my $ldif = Net::LDAP::LDIF->new("/tmp/rootdse.ldif", "r", onerror => 'undef'); - while (!$ldif->eof) { - my $entry = $ldif->read_entry; - if ($ldif->error) { - print "Error msg: ", $ldif->error, "\n"; - print "Error lines:\n", $ldif->error_lines, "\n"; - } else { - my $res = $entry->update($ldap); - if ($res->code) { - print "Error inserting entry: ", $res->error, "\n"; - last; - # do stuff - } - } - $ldif->done; - } + create_rootdse_file($u); + + print "$u->{var}{rootdse}\n"; + print "$u->{var}{rootdn}\n"; + print "$u->{var}{rootpass}\n"; + print "$u->{var}{defou}\n"; + print "$u->{var}{dom}\n"; + + my $mesg = system("ldapadd -x -D 'cn=$u->{var}{rootdn},$u->{var}{rootdse}' -f /tmp/rootdse.ldif -w $u->{var}{rootpass}"); + + return($mesg); + } sub find_user_posix { my ($u) = @_; my $dn; my $ldap = cnx_ldap_ano('loki'); - my $mesg = $ldap->search( base => $u->{var}{basedn}, + my $mesg = $ldap->search (base => "$u->{var}{basedn}", scope => $u->{var}{scope}, filter => "(&(objectclass=posixAccount)(uid=$u->{var}{uid})", ); @@ -106,37 +93,62 @@ sub find_user_posix { } } -sub add_user_posix +sub add_ou { my ($u) = @_; - my $user = $u->{var}{uid}; - print " $user \n"; + print "add_ou \n"; + my $ldap = cnx_ldap_user($u); + print "add_ou \n"; + my $result = $ldap->add( "ou=$u->{var}{defou},$u->{var}{rootdse} ", + attr => [ + objectclass => ["top","organizationalUnit"], + ou => $u->{var}{defou}, + description => $u->{var}{defou}, + ] + ); + + print "Create Default OU=$u->{var}{defou} \n"; + $result->code && warn "failed to add entry: ", $result->error ; + my $mesg = $ldap->unbind; # take down session +} + - my $ldap=Net::LDAP->new('loki') or die $@; - my $mesg = $ldap->bind('cn=manager,$u->{var}{basedn}', - password => 'secret' - ); + +sub add_user_posix +{ + my ($u) = @_; + my $uid = $u->{var}{uid}; + my $ldap=Net::LDAP->new('127.0.0.1') or die "$@"; + my $mesg = $ldap->bind( "cn=$u->{var}{rootdn},$u->{var}{rootdse}", + password => "$u->{var}{rootpass}" + ); + + my $shell = "/bin/zsh"; + my $uid = "vincent" ; #my $ldap = cnx_ldap_user('loki','manager','secret'); - my $result = $ldap->add("uid=$u->{var}{uid}, ou=$u->{var}{ou}, $u->{var}{basedn}", - attr => [ - objectClass => ["top","account","posixAccount","shadowAccount"], - uid => $u->{var}{uid}, - cn => $u->{var}{cn}, - sn => $u->{var}{sn}, - userPassword => $u->{var}{userPassword}, - loginShell => $u->{var}{loginShell}, - uidNumber =>$u->{var}{uidNumber}, - gidNumber => $u->{var}{gidNumber}, - homeDirectory => $u->{var}{homeDirectory}, - shadowMin => "-1", - shadowMax => "999999", - shadowWarning => "7", - shadowInactive => "-1", - shadowExpire => "-1", - ] - ); + my $result = $ldap->add( "uid=$uid,ou=$u->{var}{defou},$u->{var}{rootdse}", + attr => [ + objectClass => ["top","account","posixAccount","shadowAccount"], + uid => $uid, + cn => 'toto', + userPassword => 'test', + userPassword => 'pass', + loginShell => '/bin/bash', + #loginShell => $u->{var}{lshell}, + uidNumber => '501', + gidNumber => '501', + homeDirectory => '/home/toto', + shadowMin => "-1", + shadowMax => "999999", + shadowWarning => "7", + shadowInactive => "-1", + shadowExpire => "-1", + ] + ); $result->code && warn "failed to add entry: ", $result->error ; - $mesg = $ldap->unbind; # take down session + $mesg = $ldap->unbind; # take down session + } + 1; |