reverted to 1.24 and manually merged in changes from 2.2
[Samba.git] / examples / LDAP / export2_smbpasswd.pl
blob90f5805e55f1478dd2fba89319b07da1ef6208ed
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 ##
8 ## ported to Net::LDAP by dkrovich@slackworks.com
10 use Net::LDAP;
12 ######################################################
13 ## Set these values to whatever you need for your site
16 $DN="dc=samba,dc=my-domain,dc=com";
17 $ROOTDN="cn=Manager,dc=my-domain,dc=com";
18 $rootpw = "secret";
19 $LDAPSERVER="localhost";
22 ## end local site variables
23 ######################################################
25 $ldap = Net::LDAP->new($LDAPSERVER) or die "Unable to connect to LDAP server $LDAPSERVER";
27 print "##\n";
28 print "## Autogenerated smbpasswd file via ldapsearch\n";
29 print "## from $LDAPSERVER ($DN)\n";
30 print "##\n";
32 ## scheck for the existence of the posixAccount first
33 $result = $ldap->search ( base => "$DN",
34 scope => "sub",
35 filter => "(objectclass=smbpasswordentry)"
40 ## loop over the entries we found
41 while ( $entry = $result->shift_entry() ) {
43 @uid = $entry->get_value("uid");
44 @uidNumber = $entry->get_value("uidNumber");
45 @lm_pw = $entry->get_value("lmpassword");
46 @nt_pw = $entry->get_value("ntpassword");
47 @acct = $entry->get_value("acctFlags");
48 @pwdLastSet = $entry->get_value("pwdLastSet");
50 if (($#uid+1) && ($#uidNumber+1)) {
52 $lm_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#lm_pw+1));
53 $nt_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#nt_pw+1));
54 $acct[0] = "[DU ]" if (! ($#acct+1));
55 $pwdLastSet[0] = "FFFFFFFF" if (! ($#pwdLastSet+1));
57 print "$uid[0]:$uidNumber[0]:$lm_pw[0]:$nt_pw[0]:$acct[0]:LCT-$pwdLastSet[0]\n";
62 $ldap->unbind();
63 exit 0;