reverted to 1.24 and manually merged in changes from 2.2
[Samba.git] / examples / LDAP / export_smbpasswd.pl
blob3f67dc62427b21363f721555a0786f720cd3736b
1 #!/usr/bin/perl
2 ##
3 ## Example script to export ldap entries into an smbpasswd file format
4 ## using the Mozilla PerLDAP module.
5 ##
6 ## writen by jerry@samba.org
7 ##
9 use Mozilla::LDAP::Conn;
10 use Mozilla::LDAP::Entry;
12 ######################################################
13 ## Set these values to whatever you need for your site
16 $DN="ou=people,dc=plainjoe,dc=org";
17 $ROOTDN="cn=Manager,dc=plainjoe,dc=org";
18 $rootpw = "secret";
19 $LDAPSERVER="localhost";
22 ## end local site variables
23 ######################################################
26 $conn = new Mozilla::LDAP::Conn ("$LDAPSERVER", "389", $ROOTDN, $rootpw );
27 die "Unable to connect to LDAP server $LDAPSERVER" unless $conn;
29 print "##\n";
30 print "## Autogenerated smbpasswd file via ldapsearch\n";
31 print "## from $LDAPSERVER ($DN)\n";
32 print "##\n";
34 ## scheck for the existence of the posixAccount first
35 $result = $conn->search ("$DN", "sub", "(objectclass=smbPasswordEntry)");
38 ## loop over the entries we found
39 while ($result) {
41 @uid = $result->getValue("uid");
42 @uidNumber = $result->getValue("uidNumber");
43 @lm_pw = $result->getValue("lmpassword");
44 @nt_pw = $result->getValue("ntpassword");
45 @acct = $result->getValue("acctFlags");
46 @pwdLastSet = $result->getValue("pwdLastSet");
48 if (($#uid+1) && ($#uidNumber+1)) {
50 $lm_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#lm_pw+1));
51 $nt_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#nt_pw+1));
52 $acct[0] = "[DU ]" if (! ($#acct+1));
53 $pwdLastSet[0] = "FFFFFFFF" if (! ($#pwdLastSet+1));
55 print "$uid[0]:$uidNumber[0]:$lm_pw[0]:$nt_pw[0]:$acct[0]:LCT-$pwdLastSet[0]\n";
58 $result = $conn->nextEntry();
62 $conn->close();
63 exit 0;