summaryrefslogtreecommitdiffstats
path: root/ldap_wizard
diff options
context:
space:
mode:
Diffstat (limited to 'ldap_wizard')
-rw-r--r--ldap_wizard/fcldap.pm142
1 files changed, 142 insertions, 0 deletions
diff --git a/ldap_wizard/fcldap.pm b/ldap_wizard/fcldap.pm
new file mode 100644
index 00000000..4af1f62a
--- /dev/null
+++ b/ldap_wizard/fcldap.pm
@@ -0,0 +1,142 @@
+# 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;
+use Net::LDAP::LDIF;
+use MDK::Common;
+use vars qw(@ISA @EXPORT);
+use Exporter;
+
+
+@ISA = qw(Exporter);
+@EXPORT = qw(cnx_ldap_ano
+ cnx_ldap_user
+ find_user_posix
+ add_user_posix
+ create_rootdse
+ create_rootdse_file
+ );
+
+sub cnx_ldap_ano {
+ my $srv = shift;
+ my $ldap = Net::LDAP->new($srv) or die $@;
+ my $mesg = $ldap->bind;
+ 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,
+ );
+ return $ldap;
+}
+
+sub create_rootdse_file {
+ my ($u) = @_;
+ output('/tmp/rootdse.ldif', <<EOF);
+dn: dc=mdkconsulting,dc=com
+objectclass: dcObject
+objectclass: organization
+o: Example Company
+dc: example
+
+dn: cn=manager,dc=mdkconsulting,dc=com
+objectclass: organizationalRole
+cn: Manager
+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;
+ }
+}
+
+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})",
+ );
+ foreach my $entry ($mesg->all_entries) {
+ my $dn = $entry->dn;
+ print "$dn \n";
+ }
+}
+
+sub add_user_posix
+{
+ my ($u) = @_;
+ my $user = $u->{var}{uid};
+ print " $user \n";
+
+ my $ldap=Net::LDAP->new('loki') or die $@;
+ my $mesg = $ldap->bind('cn=manager,$u->{var}{basedn}',
+ password => 'secret'
+ );
+ #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",
+ ]
+ );
+
+ $result->code && warn "failed to add entry: ", $result->error ;
+ $mesg = $ldap->unbind; # take down session
+}
+1;