3 ## Example script to export ldap entries into an smbpasswd file format
4 ## using the Mozilla PerLDAP module.
6 ## writen by jerry@samba.org
8 ## ported to Net::LDAP by dkrovich@slackworks.com
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";
19 $LDAPSERVER="localhost";
22 ## end local site variables
23 ######################################################
25 $ldap = Net
::LDAP
->new($LDAPSERVER) or die "Unable to connect to LDAP server $LDAPSERVER";
28 print "## Autogenerated smbpasswd file via ldapsearch\n";
29 print "## from $LDAPSERVER ($DN)\n";
32 ## scheck for the existence of the posixAccount first
33 $result = $ldap->search ( base
=> "$DN",
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";