import_smbpasswd.pl [plain text]
use Mozilla::LDAP::Conn;
use Mozilla::LDAP::Entry;
$DN="ou=people,dc=plainjoe,dc=org";
$ROOTDN="cn=Manager,dc=plainjoe,dc=org";
$rootpw = "secret";
$LDAPSERVER="localhost";
$conn = new Mozilla::LDAP::Conn ("$LDAPSERVER", "389", $ROOTDN, $rootpw );
die "Unable to connect to LDAP server $LDAPSERVER" unless $conn;
while ( $string = <STDIN> ) {
chop ($string);
@smbentry = split (/:/, $string);
$result = $conn->search ("$DN", "sub", "(&(uid=$smbentry[0])(objectclass=posixAccount))");
if ( ! $result ) {
print STDERR "uid=$smbentry[0] does not have a posixAccount entry in the directory!\n";
next;
}
print "Updating [" . $result->getDN() . "]\n";
if (! $result->hasValue("objectclass", "smbPasswordEntry")) {
$result->addValue("objectclass", "smbPasswordEntry");
}
$result->setValues ("lmPassword", $smbentry[2]);
$result->setValues ("ntPassword", $smbentry[3]);
$result->setValues ("acctFlags", $smbentry[4]);
$result->setValues ("pwdLastSet", substr($smbentry[5],4));
if (! $conn->update($result)) {
print "Error updating!\n";
}
}
$conn->close();
exit 0;