1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#!/usr/bin/perl
##
## Example script og how you could import and smbpasswd file into an LDAP
## directory using the Mozilla PerLDAP module.
##
## wrriten by jerry@samba.org
##
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";
print "Connecting to $LDAPSERVER...";
$conn = new Mozilla::LDAP::Conn ("$LDAPSERVER", "389", $ROOTDN, $rootpw );
die "Unable to connect to LDAP server $LDAPSERVER" unless $conn;
print "connected!\n";
if ("$ARGV[0]") {
open (SMBPASSFILE, "$ARGV[0]") || die $!;
$infile = SMBPASSFILE;
}
else {
$infile = STDIN;
}
while ( $string = <$infile> ) {
chop ($string);
## get the account information
@smbentry = split (/:/, $string);
## scheck for the existence of the posixAccount first
$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";
## Do we need to add the 'objectclass: smbPasswordEntry' attribute?
if (! $result->hasValue("objectclass", "smbPasswordEntry")) {
$result->addValue("objectclass", "smbPasswordEntry");
}
## Set other attribute values
$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";
}
## $result->printLDIF();
}
close ($infile);
$conn->close();
exit 0;
|