diff options
Diffstat (limited to 'examples/LDAP/export_smbpasswd.pl')
-rw-r--r-- | examples/LDAP/export_smbpasswd.pl | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/examples/LDAP/export_smbpasswd.pl b/examples/LDAP/export_smbpasswd.pl index 3f67dc6242..e4f120bf02 100644 --- a/examples/LDAP/export_smbpasswd.pl +++ b/examples/LDAP/export_smbpasswd.pl @@ -5,16 +5,16 @@ ## ## writen by jerry@samba.org ## +## ported to Net::LDAP by dkrovich@slackworks.com -use Mozilla::LDAP::Conn; -use Mozilla::LDAP::Entry; +use Net::LDAP; ###################################################### ## Set these values to whatever you need for your site ## -$DN="ou=people,dc=plainjoe,dc=org"; -$ROOTDN="cn=Manager,dc=plainjoe,dc=org"; +$DN="dc=samba,dc=my-domain,dc=com"; +$ROOTDN="cn=Manager,dc=my-domain,dc=com"; $rootpw = "secret"; $LDAPSERVER="localhost"; @@ -22,9 +22,7 @@ $LDAPSERVER="localhost"; ## end local site variables ###################################################### - -$conn = new Mozilla::LDAP::Conn ("$LDAPSERVER", "389", $ROOTDN, $rootpw ); -die "Unable to connect to LDAP server $LDAPSERVER" unless $conn; +$ldap = Net::LDAP->new($LDAPSERVER) or die "Unable to connect to LDAP server $LDAPSERVER"; print "##\n"; print "## Autogenerated smbpasswd file via ldapsearch\n"; @@ -32,32 +30,35 @@ print "## from $LDAPSERVER ($DN)\n"; print "##\n"; ## scheck for the existence of the posixAccount first -$result = $conn->search ("$DN", "sub", "(objectclass=smbPasswordEntry)"); - - +$result = $ldap->search ( base => "$DN", + scope => "sub", + filter => "(objectclass=sambaAccount)" + ); + + + ## loop over the entries we found -while ($result) { - - @uid = $result->getValue("uid"); - @uidNumber = $result->getValue("uidNumber"); - @lm_pw = $result->getValue("lmpassword"); - @nt_pw = $result->getValue("ntpassword"); - @acct = $result->getValue("acctFlags"); - @pwdLastSet = $result->getValue("pwdLastSet"); - +while ( $entry = $result->shift_entry() ) { + + @uid = $entry->get_value("uid"); + @uidNumber = $entry->get_value("uidNumber"); + @lm_pw = $entry->get_value("lmpassword"); + @nt_pw = $entry->get_value("ntpassword"); + @acct = $entry->get_value("acctFlags"); + @pwdLastSet = $entry->get_value("pwdLastSet"); + if (($#uid+1) && ($#uidNumber+1)) { - + $lm_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#lm_pw+1)); $nt_pw[0] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" if (! ($#nt_pw+1)); $acct[0] = "[DU ]" if (! ($#acct+1)); $pwdLastSet[0] = "FFFFFFFF" if (! ($#pwdLastSet+1)); - + print "$uid[0]:$uidNumber[0]:$lm_pw[0]:$nt_pw[0]:$acct[0]:LCT-$pwdLastSet[0]\n"; } - - $result = $conn->nextEntry(); - + } -$conn->close(); +$ldap->unbind(); exit 0; + |