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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
#!/usr/bin/perl -w
# Populate a LDAP base for Samba-LDAP usage
#
# $Id: smbldap-populate.pl,v 1.1.6.4 2003/12/04 21:59:19 jerry Exp $
# This code was developped by IDEALX (http://IDEALX.org/) and
# contributors (their names can be found in the CONTRIBUTORS file).
#
# Copyright (C) 2001-2002 IDEALX
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
# USA.
# Purpose :
# . Create an initial LDAP database suitable for Samba 2.2
# . For lazy people, replace ldapadd (with only an ldif parameter)
use strict;
use FindBin;
use FindBin qw($RealBin);
use lib "$RealBin/";
use smbldap_tools;
use smbldap_conf;
use Getopt::Std;
use Net::LDAP::LDIF;
use vars qw(%oc);
# objectclass of the suffix
%oc = (
"ou" => "organizationalUnit",
"o" => "organization",
"dc" => "dcObject",
);
my %Options;
my $ok = getopts('a:b:?', \%Options);
if ( (!$ok) || ($Options{'?'}) ) {
print "Usage: $0 [-ab?] [ldif]\n";
print " -a administrator login name (default: Administrator)\n";
print " -b guest login name (default: nobody)\n";
print " -? show this help message\n";
print " ldif file to add to ldap (default: suffix, Groups,";
print " Users, Computers and builtin users )\n";
exit (1);
}
my $_ldifName;
my $tmp_ldif_file="/tmp/$$.ldif";
if (@ARGV >= 1) {
$_ldifName = $ARGV[0];
}
my $adminName = $Options{'a'};
if (!defined($adminName)) {
$adminName = "Administrator";
}
my $guestName = $Options{'b'};
if (!defined($guestName)) {
$guestName = "nobody";
}
if (!defined($_ldifName)) {
my $attr;
my $val;
my $objcl;
print "Using builtin directory structure\n";
if ($suffix =~ m/([^=]+)=([^,]+)/) {
$attr = $1;
$val = $2;
$objcl = $oc{$attr} if (exists $oc{$attr});
if (!defined($objcl)) {
$objcl = "myhardcodedobjectclass";
}
} else {
die "can't extract first attr and value from suffix $suffix";
}
#print "$attr=$val\n";
my ($organisation,$ext) = ($suffix =~ m/dc=(.*),dc=(.*)$/);
#my $FILE="|cat";
my $FILE=$tmp_ldif_file;
open (FILE, ">$FILE") || die "Can't open file $FILE: $!\n";
print FILE <<EOF;
dn: $suffix
objectClass: $objcl
objectclass: organization
$attr: $val
o: $organisation
dn: $usersdn
objectClass: organizationalUnit
ou: $usersou
dn: $groupsdn
objectClass: organizationalUnit
ou: $groupsou
dn: $computersdn
objectClass: organizationalUnit
ou: $computersou
dn: uid=$adminName,$usersdn
cn: $adminName
sn: $adminName
objectClass: inetOrgPerson
objectClass: sambaSAMAccount
objectClass: posixAccount
gidNumber: 512
uid: $adminName
uidNumber: 998
homeDirectory: $_userHomePrefix
sambaPwdLastSet: 0
sambaLogonTime: 0
sambaLogoffTime: 2147483647
sambaKickoffTime: 2147483647
sambaPwdCanChange: 0
sambaPwdMustChange: 2147483647
sambaHomePath: $_userSmbHome
sambaHomeDrive: $_userHomeDrive
sambaProfilePath: $_userProfile
sambaPrimaryGroupSID: $SID-512
sambaLMPassword: XXX
sambaNTPassword: XXX
sambaAcctFlags: [U ]
sambaSID: $SID-2996
loginShell: /bin/false
gecos: Netbios Domain Administrator
dn: uid=$guestName,$usersdn
cn: $guestName
sn: $guestName
objectClass: inetOrgPerson
objectClass: sambaSAMAccount
objectClass: posixAccount
gidNumber: 514
uid: $guestName
uidNumber: 999
homeDirectory: /dev/null
sambaPwdLastSet: 0
sambaLogonTime: 0
sambaLogoffTime: 2147483647
sambaKickoffTime: 2147483647
sambaPwdCanChange: 0
sambaPwdMustChange: 2147483647
sambaHomePath: $_userSmbHome
sambaHomeDrive: $_userHomeDrive
sambaProfilePath: $_userProfile
sambaPrimaryGroupSID: $SID-514
sambaLMPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
sambaNTPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
sambaAcctFlags: [NU ]
sambaSID: $SID-2998
loginShell: /bin/false
dn: cn=Domain Admins,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 512
cn: Domain Admins
memberUid: $adminName
description: Netbios Domain Administrators
sambaSID: $SID-512
sambaGroupType: 2
displayName: Domain Admins
dn: cn=Domain Users,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 513
cn: Domain Users
description: Netbios Domain Users
sambaSID: $SID-513
sambaGroupType: 2
displayName: Domain Users
dn: cn=Domain Guests,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 514
cn: Domain Guests
description: Netbios Domain Guests Users
sambaSID: $SID-514
sambaGroupType: 2
displayName: Domain Guests
dn: cn=Administrators,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 544
cn: Administrators
description: Netbios Domain Members can fully administer the computer/sambaDomainName
sambaSID: $SID-544
sambaGroupType: 2
displayName: Administrators
dn: cn=Users,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 545
cn: Users
description: Netbios Domain Ordinary users
sambaSID: $SID-545
sambaGroupType: 2
displayName: users
dn: cn=Guests,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 546
cn: Guests
memberUid: $guestName
description: Netbios Domain Users granted guest access to the computer/sambaDomainName
sambaSID: $SID-546
sambaGroupType: 2
displayName: Guests
dn: cn=Power Users,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 547
cn: Power Users
description: Netbios Domain Members can share directories and printers
sambaSID: $SID-547
sambaGroupType: 2
displayName: Power Users
dn: cn=Account Operators,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 548
cn: Account Operators
description: Netbios Domain Users to manipulate users accounts
sambaSID: $SID-548
sambaGroupType: 2
displayName: Account Operators
dn: cn=Server Operators,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 549
cn: Server Operators
description: Netbios Domain Server Operators
sambaSID: $SID-549
sambaGroupType: 2
displayName: Server Operators
dn: cn=Print Operators,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 550
cn: Print Operators
description: Netbios Domain Print Operators
sambaSID: $SID-550
sambaGroupType: 2
displayName: Print Operators
dn: cn=Backup Operators,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 551
cn: Backup Operators
description: Netbios Domain Members can bypass file security to back up files
sambaSID: $SID-551
sambaGroupType: 2
displayName: Backup Operators
dn: cn=Replicator,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 552
cn: Replicator
description: Netbios Domain Supports file replication in a sambaDomainName
sambaSID: $SID-552
sambaGroupType: 2
displayName: Replicator
dn: cn=Domain Computers,$groupsdn
objectClass: posixGroup
objectClass: sambaGroupMapping
gidNumber: 553
cn: Domain Computers
description: Netbios Domain Computers accounts
sambaSID: $SID-553
sambaGroupType: 2
displayName: Domain Computers
EOF
close FILE;
} else {
$tmp_ldif_file=$_ldifName;
}
my $ldap_master=connect_ldap_master();
my $ldif = Net::LDAP::LDIF->new($tmp_ldif_file, "r", onerror => 'undef' );
while( not $ldif->eof() ) {
my $entry = $ldif->read_entry();
if ( $ldif->error() ) {
print "Error msg: ",$ldif->error(),"\n";
print "Error lines:\n",$ldif->error_lines(),"\n";
} else {
my $dn = $entry->dn;
print "adding new entry: $dn\n";
my $result=$ldap_master->add($entry);
$result->code && warn "failed to add entry: ", $result->error ;
}
}
$ldap_master->unbind;
system "rm -f $tmp_ldif_file";
exit(0);
########################################
=head1 NAME
smbldap-populate.pl - Populate your LDAP database
=head1 SYNOPSIS
smbldap-populate.pl [ldif-file]
=head1 DESCRIPTION
The smbldap-populate.pl command helps to populate an LDAP server
by adding the necessary entries : base suffix (doesn't abort
if already there), organizational units for users, groups and
computers, builtin users : Administrator and guest, builtin
groups (though posixAccount only, no SambaTNG support).
-a name Your local administrator login name (default: Administrator)
-b name Your local guest login name (default: nobody)
If you give an extra parameter, it is assumed to be the ldif
file to use instead of the builtin one. Options -a and -b
will be ignored.
=head1 FILES
/usr/lib/perl5/site-perl/smbldap_conf.pm : Global parameters.
=head1 SEE ALSO
smp(1)
=cut
#'
# - The End
|