summaryrefslogtreecommitdiffstats
path: root/ldap_wizard
diff options
context:
space:
mode:
Diffstat (limited to 'ldap_wizard')
-rw-r--r--ldap_wizard/fcldap.pm136
1 files changed, 65 insertions, 71 deletions
diff --git a/ldap_wizard/fcldap.pm b/ldap_wizard/fcldap.pm
index 12834028..4fc6911a 100644
--- a/ldap_wizard/fcldap.pm
+++ b/ldap_wizard/fcldap.pm
@@ -1,4 +1,5 @@
package fcldap;
+
use strict;
use Net::LDAP;
use Net::LDAP::LDIF;
@@ -15,30 +16,30 @@ use Exporter;
create_rootdse
create_rootdse_file
add_ou
- tutu
+ toto
);
sub cnx_ldap_ano {
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 ($u) = @_;
- print "cnx_ldap_user not connect\n";
+ 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}",
- );
-
- print "$ldap \n";
- return ($ldap);
+ 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},
+ );
+ print "$ldap \n";
+ return $ldap;
}
sub create_rootdse_file {
@@ -66,88 +67,81 @@ EOF
sub create_rootdse {
my ($u) = @_;
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);
-
+ return $mesg;
}
sub find_user_posix {
my ($u) = @_;
my $dn;
my $ldap = cnx_ldap_ano('loki');
- my $mesg = $ldap->search (base => "$u->{var}{basedn}",
- scope => $u->{var}{scope},
- filter => "(&(objectclass=posixAccount)(uid=$u->{var}{uid})",
- );
+ my $mesg = $ldap->search(base => $u->{var}{basedn},
+ scope => $u->{var}{scope},
+ filter => "(&(objectclass=posixAccount)(uid=$u->{var}{uid})",
+ );
foreach my $entry ($mesg->all_entries) {
- my $dn = $entry->dn;
- print "$dn \n";
+ my $dn = $entry->dn;
+ print "$dn \n";
}
}
-sub add_ou
-{
+sub add_ou {
my ($u) = @_;
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 $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
}
+sub add_user_posix {
+ my ($u) = @_;
+ $u->{var}{defou} = "users,ou=$u->{var}{defou}";
+ $u->{var}{rootdse} = "dc=mdkc,dc=com";
+ my $srvhost = "localhost";
-
-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=$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
+output('/tmp/addusr.ldif', <<EOF);
+dn: uid=$u->{var}{uid},ou=$u->{var}{defou},$u->{var}{rootdse}
+objectClass: top
+objectClass: posixAccount
+objectClass: shadowAccount
+objectClass: inetOrgPerson
+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}{guidnb}
+homeDirectory:$u->{var}{home}
+shadowMin: -1
+shadowMax: 999999
+shadowWarning: 7
+shadowInactive: -1
+shadowExpire: -1
+EOF
+
+
+ my $mesg = system("ldapadd -x -h $srvhost -D 'cn=$u->{var}{rootdn},$u->{var}{rootdse}' -f /tmp/addusr.ldif -w $u->{var}{rootpass}");
+ return $mesg;
+
+
+ #$result->code && warn "failed to add entry: ", $result->error;
+ #$mesg = $ldap->unbind; # take down session
}