1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | # Populate a LDAP base for Samba-LDAP usage
|
---|
4 | #
|
---|
5 | # $Id: smbldap-populate,v 1.27 2005/10/31 15:05:22 jtournier Exp $
|
---|
6 |
|
---|
7 | # This code was developped by IDEALX (http://IDEALX.org/) and
|
---|
8 | # contributors (their names can be found in the CONTRIBUTORS file).
|
---|
9 | #
|
---|
10 | # Copyright (C) 2001-2002 IDEALX
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation; either version 2
|
---|
15 | # of the License, or (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
---|
25 | # USA.
|
---|
26 |
|
---|
27 | # Purpose :
|
---|
28 | # . Create an initial LDAP database suitable for Samba 2.2
|
---|
29 | # . For lazy people, replace ldapadd (with only an ldif parameter)
|
---|
30 |
|
---|
31 | use strict;
|
---|
32 | use FindBin;
|
---|
33 | use FindBin qw($RealBin);
|
---|
34 | use lib "$RealBin/";
|
---|
35 | use smbldap_tools;
|
---|
36 | use Getopt::Std;
|
---|
37 | use Net::LDAP::LDIF;
|
---|
38 |
|
---|
39 | use vars qw(%oc);
|
---|
40 |
|
---|
41 | # objectclass of the suffix
|
---|
42 | %oc = (
|
---|
43 | "ou" => "organizationalUnit",
|
---|
44 | "o" => "organization",
|
---|
45 | "dc" => "dcObject",
|
---|
46 | );
|
---|
47 |
|
---|
48 |
|
---|
49 | my %Options;
|
---|
50 |
|
---|
51 | my $ok = getopts('a:b:e:i:k:l:m:u:g:?', \%Options);
|
---|
52 | if ( (!$ok) || ($Options{'?'}) ) {
|
---|
53 | print_banner;
|
---|
54 | print "Usage: $0 [-abeiklug?] [ldif]\n";
|
---|
55 | print " -u uidNumber first uidNumber to allocate (default: 1000)\n";
|
---|
56 | print " -g gidNumber first uidNumber to allocate (default: 1000)\n";
|
---|
57 | print " -a user administrator login name (default: root)\n";
|
---|
58 | print " -b user guest login name (default: nobody)\n";
|
---|
59 | print " -k uidNumber administrator's uidNumber (default: 0)\n";
|
---|
60 | print " -l uidNumber guest's uidNumber (default: 999)\n";
|
---|
61 | print " -m gidNumber administrator's gidNumber (default: 0)\n";
|
---|
62 | print " -e file export ldif file\n";
|
---|
63 | print " -i file import ldif file\n";
|
---|
64 | print " -? show this help message\n";
|
---|
65 |
|
---|
66 | exit (1);
|
---|
67 | }
|
---|
68 |
|
---|
69 | # sanity checks
|
---|
70 | my $domain = $config{sambaDomain};
|
---|
71 | if (! defined $domain) {
|
---|
72 | print STDERR "error: domain name not found !\n";
|
---|
73 | print STDERR "possible reasons are:\n";
|
---|
74 | print STDERR ". incorrect 'sambaDomain' parameter in smbldap.conf\n";
|
---|
75 | print STDERR ". incorrect 'samba_conf' definition in smbldap_tools.pm\n";
|
---|
76 | die;
|
---|
77 | }
|
---|
78 |
|
---|
79 | #$config{sambaUnixIdPooldn}="sambaDomainName=$domain,$config{suffix}";
|
---|
80 |
|
---|
81 | my $firstuidNumber=$Options{'u'};
|
---|
82 | if (!defined($firstuidNumber)) {
|
---|
83 | $firstuidNumber=1000;
|
---|
84 | }
|
---|
85 |
|
---|
86 | my $firstgidNumber=$Options{'g'};
|
---|
87 | if (!defined($firstgidNumber)) {
|
---|
88 | $firstgidNumber=1000;
|
---|
89 | }
|
---|
90 |
|
---|
91 | my $tmp_ldif_file=$Options{'e'};
|
---|
92 | if (!defined($tmp_ldif_file)) {
|
---|
93 | $tmp_ldif_file="/tmp/$$.ldif";
|
---|
94 | }
|
---|
95 |
|
---|
96 | my $adminName = $Options{'a'};
|
---|
97 | if (!defined($adminName)) {
|
---|
98 | $adminName = "root";
|
---|
99 | }
|
---|
100 |
|
---|
101 | my $guestName = $Options{'b'};
|
---|
102 | if (!defined($guestName)) {
|
---|
103 | $guestName = "nobody";
|
---|
104 | }
|
---|
105 |
|
---|
106 | my $adminUidNumber=$Options{'k'};
|
---|
107 | my $adminrid;
|
---|
108 | if (!defined($adminUidNumber)) {
|
---|
109 | $adminUidNumber = "0";
|
---|
110 | $adminrid= "500";
|
---|
111 | } else {
|
---|
112 | $adminrid=(2*$adminUidNumber+ 1000)
|
---|
113 | }
|
---|
114 |
|
---|
115 | my $guestUidNumber=$Options{'l'};
|
---|
116 | if (!defined($guestUidNumber)) {
|
---|
117 | $guestUidNumber = "999";
|
---|
118 | }
|
---|
119 |
|
---|
120 | my $adminGidNumber=$Options{'m'};
|
---|
121 | if (!defined($adminGidNumber)) {
|
---|
122 | $adminGidNumber = "0";
|
---|
123 | }
|
---|
124 |
|
---|
125 | my $_ldifName = $Options{'i'};
|
---|
126 |
|
---|
127 | my $exportFile = $Options{'e'};
|
---|
128 | if (!defined($exportFile)) {
|
---|
129 | $exportFile = "base.ldif";
|
---|
130 | }
|
---|
131 |
|
---|
132 | print "Populating LDAP directory for domain $domain ($config{SID})\n";
|
---|
133 | if (!defined($_ldifName)) {
|
---|
134 | my $attr;
|
---|
135 | my $val;
|
---|
136 | my $objcl;
|
---|
137 |
|
---|
138 | print "(using builtin directory structure)\n\n";
|
---|
139 | if ($config{suffix} =~ m/([^=]+)=([^,]+)/) {
|
---|
140 | $attr = $1;
|
---|
141 | $val = $2;
|
---|
142 | $objcl = $oc{$attr} if (exists $oc{$attr});
|
---|
143 | if (!defined($objcl)) {
|
---|
144 | $objcl = "myhardcodedobjectclass";
|
---|
145 | }
|
---|
146 | } else {
|
---|
147 | die "can't extract first attr and value from suffix $config{suffix}";
|
---|
148 | }
|
---|
149 | #print "$attr=$val\n";
|
---|
150 | my ($type,$ou_users,$ou_groups,$ou_computers,$ou_idmap,$cnsambaUnixIdPool);
|
---|
151 | ($type,$ou_users)=($config{usersdn}=~/(.*)=(.*),$config{suffix}/);
|
---|
152 | ($type,$ou_groups)=($config{groupsdn}=~/(.*)=(.*),$config{suffix}/);
|
---|
153 | ($type,$ou_computers)=($config{computersdn}=~/(.*)=(.*),$config{suffix}/);
|
---|
154 | if (defined $config{idmapdn}) {
|
---|
155 | ($type,$ou_idmap)=($config{idmapdn}=~/(.*)=(.*),$config{suffix}/);
|
---|
156 | }
|
---|
157 | ($type,$cnsambaUnixIdPool)=($config{sambaUnixIdPooldn}=~/(.*)=(.*),$config{suffix}/);
|
---|
158 | my $org;
|
---|
159 | my ($organisation,$ext);
|
---|
160 | if ($config{suffix} =~ m/dc=([^=]+),dc=(.*)$/) {
|
---|
161 | ($organisation,$ext) = ($config{suffix} =~ m/dc=([^=]+),dc=(.*)$/);
|
---|
162 | } elsif ($config{suffix} =~ m/dc=(.*)$/) {
|
---|
163 | $organisation=$1;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if ($organisation ne '') {
|
---|
167 | $org = "\nobjectclass: organization\no: $organisation";
|
---|
168 | }
|
---|
169 | #my $FILE="|cat";
|
---|
170 |
|
---|
171 | my $entries="dn: $config{suffix}
|
---|
172 | objectClass: $objcl$org
|
---|
173 | $attr: $val
|
---|
174 |
|
---|
175 | dn: $config{usersdn}
|
---|
176 | objectClass: top
|
---|
177 | objectClass: organizationalUnit
|
---|
178 | ou: $ou_users
|
---|
179 |
|
---|
180 | dn: $config{groupsdn}
|
---|
181 | objectClass: top
|
---|
182 | objectClass: organizationalUnit
|
---|
183 | ou: $ou_groups
|
---|
184 |
|
---|
185 | dn: $config{computersdn}
|
---|
186 | objectClass: top
|
---|
187 | objectClass: organizationalUnit
|
---|
188 | ou: $ou_computers\n";
|
---|
189 |
|
---|
190 | if (defined $config{idmapdn}) {
|
---|
191 | $entries.="\ndn: $config{idmapdn}
|
---|
192 | objectClass: top
|
---|
193 | objectClass: organizationalUnit
|
---|
194 | ou: $ou_idmap\n";
|
---|
195 | }
|
---|
196 |
|
---|
197 | $entries.="\ndn: uid=$adminName,$config{usersdn}
|
---|
198 | cn: $adminName
|
---|
199 | sn: $adminName
|
---|
200 | objectClass: top
|
---|
201 | objectClass: person
|
---|
202 | objectClass: organizationalPerson
|
---|
203 | objectClass: inetOrgPerson
|
---|
204 | objectClass: sambaSAMAccount
|
---|
205 | objectClass: posixAccount
|
---|
206 | objectClass: shadowAccount
|
---|
207 | gidNumber: $adminGidNumber
|
---|
208 | uid: $adminName
|
---|
209 | uidNumber: $adminUidNumber\n";
|
---|
210 | if (defined $config{userHome} and $config{userHome} ne "") {
|
---|
211 | my $userHome=$config{userHome};
|
---|
212 | $userHome=~s/\%U/$adminName/;
|
---|
213 | $entries.="homeDirectory: $userHome\n";
|
---|
214 | } else {
|
---|
215 | $entries.="homeDirectory: /dev/null\n";
|
---|
216 | }
|
---|
217 | $entries.="sambaPwdLastSet: 0
|
---|
218 | sambaLogonTime: 0
|
---|
219 | sambaLogoffTime: 2147483647
|
---|
220 | sambaKickoffTime: 2147483647
|
---|
221 | sambaPwdCanChange: 0
|
---|
222 | sambaPwdMustChange: 2147483647\n";
|
---|
223 | if (defined $config{userSmbHome} and $config{userSmbHome} ne "") {
|
---|
224 | my $userSmbHome=$config{userSmbHome};
|
---|
225 | $userSmbHome=~s/\%U/$adminName/;
|
---|
226 | $entries.="sambaHomePath: $userSmbHome\n";
|
---|
227 | }
|
---|
228 | if (defined $config{userHomeDrive} and $config{userHomeDrive} ne "") {
|
---|
229 | $entries.="sambaHomeDrive: $config{userHomeDrive}\n";
|
---|
230 | }
|
---|
231 | if (defined $config{userProfile} and $config{userProfile} ne "") {
|
---|
232 | my $userProfile=$config{userProfile};
|
---|
233 | $userProfile=~s/\%U/$adminName/;
|
---|
234 | $entries.="sambaProfilePath: $userProfile\n";
|
---|
235 | }
|
---|
236 | $entries.="sambaPrimaryGroupSID: $config{SID}-512
|
---|
237 | sambaLMPassword: XXX
|
---|
238 | sambaNTPassword: XXX
|
---|
239 | sambaAcctFlags: [U ]
|
---|
240 | sambaSID: $config{SID}-$adminrid
|
---|
241 | loginShell: /bin/false
|
---|
242 | gecos: Netbios Domain Administrator
|
---|
243 |
|
---|
244 | dn: uid=$guestName,$config{usersdn}
|
---|
245 | cn: $guestName
|
---|
246 | sn: $guestName
|
---|
247 | objectClass: top
|
---|
248 | objectClass: person
|
---|
249 | objectClass: organizationalPerson
|
---|
250 | objectClass: inetOrgPerson
|
---|
251 | objectClass: sambaSAMAccount
|
---|
252 | objectClass: posixAccount
|
---|
253 | objectClass: shadowAccount
|
---|
254 | gidNumber: 514
|
---|
255 | uid: $guestName
|
---|
256 | uidNumber: $guestUidNumber
|
---|
257 | homeDirectory: /dev/null
|
---|
258 | sambaPwdLastSet: 0
|
---|
259 | sambaLogonTime: 0
|
---|
260 | sambaLogoffTime: 2147483647
|
---|
261 | sambaKickoffTime: 2147483647
|
---|
262 | sambaPwdCanChange: 0
|
---|
263 | sambaPwdMustChange: 2147483647\n";
|
---|
264 | if (defined $config{userSmbHome} and $config{userSmbHome} ne "") {
|
---|
265 | my $userSmbHome=$config{userSmbHome};
|
---|
266 | $userSmbHome=~s/\%U/$guestName/;
|
---|
267 | $entries.="sambaHomePath: $userSmbHome\n";
|
---|
268 | }
|
---|
269 | if (defined $config{userHomeDrive} and $config{userHomeDrive} ne "") {
|
---|
270 | $entries.="sambaHomeDrive: $config{userHomeDrive}\n";
|
---|
271 | }
|
---|
272 | if (defined $config{userProfile} and $config{userProfile} ne "") {
|
---|
273 | my $userProfile=$config{userProfile};
|
---|
274 | $userProfile=~s/\%U/$guestName/;
|
---|
275 | $entries.="sambaProfilePath: $userProfile\n";
|
---|
276 | }
|
---|
277 | $entries.="sambaPrimaryGroupSID: $config{SID}-514
|
---|
278 | sambaLMPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
|
---|
279 | sambaNTPassword: NO PASSWORDXXXXXXXXXXXXXXXXXXXXX
|
---|
280 | # account disabled by default
|
---|
281 | sambaAcctFlags: [NUD ]
|
---|
282 | sambaSID: $config{SID}-2998
|
---|
283 | loginShell: /bin/false
|
---|
284 |
|
---|
285 | dn: cn=Domain Admins,$config{groupsdn}
|
---|
286 | objectClass: top
|
---|
287 | objectClass: posixGroup
|
---|
288 | objectClass: sambaGroupMapping
|
---|
289 | gidNumber: 512
|
---|
290 | cn: Domain Admins
|
---|
291 | memberUid: $adminName
|
---|
292 | description: Netbios Domain Administrators
|
---|
293 | sambaSID: $config{SID}-512
|
---|
294 | sambaGroupType: 2
|
---|
295 | displayName: Domain Admins
|
---|
296 |
|
---|
297 | dn: cn=Domain Users,$config{groupsdn}
|
---|
298 | objectClass: top
|
---|
299 | objectClass: posixGroup
|
---|
300 | objectClass: sambaGroupMapping
|
---|
301 | gidNumber: 513
|
---|
302 | cn: Domain Users
|
---|
303 | description: Netbios Domain Users
|
---|
304 | sambaSID: $config{SID}-513
|
---|
305 | sambaGroupType: 2
|
---|
306 | displayName: Domain Users
|
---|
307 |
|
---|
308 | dn: cn=Domain Guests,$config{groupsdn}
|
---|
309 | objectClass: top
|
---|
310 | objectClass: posixGroup
|
---|
311 | objectClass: sambaGroupMapping
|
---|
312 | gidNumber: 514
|
---|
313 | cn: Domain Guests
|
---|
314 | description: Netbios Domain Guests Users
|
---|
315 | sambaSID: $config{SID}-514
|
---|
316 | sambaGroupType: 2
|
---|
317 | displayName: Domain Guests
|
---|
318 |
|
---|
319 | dn: cn=Domain Computers,$config{groupsdn}
|
---|
320 | objectClass: top
|
---|
321 | objectClass: posixGroup
|
---|
322 | objectClass: sambaGroupMapping
|
---|
323 | gidNumber: 515
|
---|
324 | cn: Domain Computers
|
---|
325 | description: Netbios Domain Computers accounts
|
---|
326 | sambaSID: $config{SID}-515
|
---|
327 | sambaGroupType: 2
|
---|
328 | displayName: Domain Computers
|
---|
329 |
|
---|
330 | dn: cn=Administrators,$config{groupsdn}
|
---|
331 | objectClass: top
|
---|
332 | objectClass: posixGroup
|
---|
333 | objectClass: sambaGroupMapping
|
---|
334 | gidNumber: 544
|
---|
335 | cn: Administrators
|
---|
336 | description: Netbios Domain Members can fully administer the computer/sambaDomainName
|
---|
337 | sambaSID: S-1-5-32-544
|
---|
338 | sambaGroupType: 5
|
---|
339 | displayName: Administrators
|
---|
340 |
|
---|
341 | #dn: cn=Users,$config{groupsdn}
|
---|
342 | #objectClass: top
|
---|
343 | #objectClass: posixGroup
|
---|
344 | #objectClass: sambaGroupMapping
|
---|
345 | #gidNumber: 545
|
---|
346 | #cn: Users
|
---|
347 | #description: Netbios Domain Ordinary users
|
---|
348 | #sambaSID: S-1-5-32-545
|
---|
349 | #sambaGroupType: 5
|
---|
350 | #displayName: users
|
---|
351 |
|
---|
352 | #dn: cn=Guests,$config{groupsdn}
|
---|
353 | #objectClass: top
|
---|
354 | #objectClass: posixGroup
|
---|
355 | #objectClass: sambaGroupMapping
|
---|
356 | #gidNumber: 546
|
---|
357 | #cn: Guests
|
---|
358 | #memberUid: $guestName
|
---|
359 | #description: Netbios Domain Users granted guest access to the computer/sambaDomainName
|
---|
360 | #sambaSID: S-1-5-32-546
|
---|
361 | #sambaGroupType: 5
|
---|
362 | #displayName: Guests
|
---|
363 |
|
---|
364 | #dn: cn=Power Users,$config{groupsdn}
|
---|
365 | #objectClass: top
|
---|
366 | #objectClass: posixGroup
|
---|
367 | #objectClass: sambaGroupMapping
|
---|
368 | #gidNumber: 547
|
---|
369 | #cn: Power Users
|
---|
370 | #description: Netbios Domain Members can share directories and printers
|
---|
371 | #sambaSID: S-1-5-32-547
|
---|
372 | #sambaGroupType: 5
|
---|
373 | #displayName: Power Users
|
---|
374 |
|
---|
375 | dn: cn=Account Operators,$config{groupsdn}
|
---|
376 | objectClass: top
|
---|
377 | objectClass: posixGroup
|
---|
378 | objectClass: sambaGroupMapping
|
---|
379 | gidNumber: 548
|
---|
380 | cn: Account Operators
|
---|
381 | description: Netbios Domain Users to manipulate users accounts
|
---|
382 | sambaSID: S-1-5-32-548
|
---|
383 | sambaGroupType: 5
|
---|
384 | displayName: Account Operators
|
---|
385 |
|
---|
386 | #dn: cn=System Operators,$config{groupsdn}
|
---|
387 | #objectClass: top
|
---|
388 | #objectClass: posixGroup
|
---|
389 | #objectClass: sambaGroupMapping
|
---|
390 | #gidNumber: 549
|
---|
391 | #cn: System Operators
|
---|
392 | #description: Netbios Domain System Operators
|
---|
393 | #sambaSID: S-1-5-32-549
|
---|
394 | #sambaGroupType: 5
|
---|
395 | #displayName: System Operators
|
---|
396 |
|
---|
397 | dn: cn=Print Operators,$config{groupsdn}
|
---|
398 | objectClass: top
|
---|
399 | objectClass: posixGroup
|
---|
400 | objectClass: sambaGroupMapping
|
---|
401 | gidNumber: 550
|
---|
402 | cn: Print Operators
|
---|
403 | description: Netbios Domain Print Operators
|
---|
404 | sambaSID: S-1-5-32-550
|
---|
405 | sambaGroupType: 5
|
---|
406 | displayName: Print Operators
|
---|
407 |
|
---|
408 | dn: cn=Backup Operators,$config{groupsdn}
|
---|
409 | objectClass: top
|
---|
410 | objectClass: posixGroup
|
---|
411 | objectClass: sambaGroupMapping
|
---|
412 | gidNumber: 551
|
---|
413 | cn: Backup Operators
|
---|
414 | description: Netbios Domain Members can bypass file security to back up files
|
---|
415 | sambaSID: S-1-5-32-551
|
---|
416 | sambaGroupType: 5
|
---|
417 | displayName: Backup Operators
|
---|
418 |
|
---|
419 | dn: cn=Replicators,$config{groupsdn}
|
---|
420 | objectClass: top
|
---|
421 | objectClass: posixGroup
|
---|
422 | objectClass: sambaGroupMapping
|
---|
423 | gidNumber: 552
|
---|
424 | cn: Replicators
|
---|
425 | description: Netbios Domain Supports file replication in a sambaDomainName
|
---|
426 | sambaSID: S-1-5-32-552
|
---|
427 | sambaGroupType: 5
|
---|
428 | displayName: Replicators
|
---|
429 |
|
---|
430 | ";
|
---|
431 | if ("sambaDomainName=$domain,$config{suffix}" eq $config{sambaUnixIdPooldn}) {
|
---|
432 | $entries.="dn: sambaDomainName=$domain,$config{suffix}
|
---|
433 | objectClass: top
|
---|
434 | objectClass: sambaDomain
|
---|
435 | objectClass: sambaUnixIdPool
|
---|
436 | sambaDomainName: $domain
|
---|
437 | sambaSID: $config{SID}
|
---|
438 | uidNumber: $firstuidNumber
|
---|
439 | gidNumber: $firstgidNumber";
|
---|
440 | } else {
|
---|
441 | $entries.="dn: $config{sambaUnixIdPooldn}
|
---|
442 | objectClass: inetOrgPerson
|
---|
443 | objectClass: sambaUnixIdPool
|
---|
444 | uidNumber: $firstuidNumber
|
---|
445 | gidNumber: $firstgidNumber
|
---|
446 | cn: $cnsambaUnixIdPool
|
---|
447 | sn: $cnsambaUnixIdPool";
|
---|
448 | }
|
---|
449 | open (FILE, ">$tmp_ldif_file") || die "Can't open file $tmp_ldif_file: $!\n";
|
---|
450 |
|
---|
451 | print FILE <<EOF;
|
---|
452 | $entries
|
---|
453 | EOF
|
---|
454 | close FILE;
|
---|
455 | } else {
|
---|
456 | $tmp_ldif_file=$_ldifName;
|
---|
457 | }
|
---|
458 |
|
---|
459 | if (!defined $Options{'e'}) {
|
---|
460 | my $ldap_master=connect_ldap_master();
|
---|
461 | my $ldif = Net::LDAP::LDIF->new($tmp_ldif_file, "r", onerror => 'undef' );
|
---|
462 | while ( not $ldif->eof() ) {
|
---|
463 | my $entry = $ldif->read_entry();
|
---|
464 | if ( $ldif->error() ) {
|
---|
465 | print "Error msg: ",$ldif->error(),"\n";
|
---|
466 | print "Error lines:\n",$ldif->error_lines(),"\n";
|
---|
467 | } else {
|
---|
468 | my $dn = $entry->dn;
|
---|
469 | # we first check if the entry exist
|
---|
470 | my $mesg = $ldap_master->search (
|
---|
471 | base => "$dn",
|
---|
472 | scope => "base",
|
---|
473 | filter => "objectclass=*"
|
---|
474 | );
|
---|
475 | $mesg->code;
|
---|
476 | my $nb=$mesg->count;
|
---|
477 | if ($nb == 1 ) {
|
---|
478 | print "entry $dn already exist. ";
|
---|
479 | if ($dn eq $config{sambaUnixIdPooldn}) {
|
---|
480 | print "Updating it...\n";
|
---|
481 | my @mods;
|
---|
482 | foreach my $attr_tmp ($entry->attributes) {
|
---|
483 | push(@mods,$attr_tmp=>[$entry->get_value("$attr_tmp")]);
|
---|
484 | }
|
---|
485 | my $modify = $ldap_master->modify ( "$dn",
|
---|
486 | 'replace' => { @mods },
|
---|
487 | );
|
---|
488 | $modify->code && warn "failed to modify entry: ", $modify->error ;
|
---|
489 | } else {
|
---|
490 | print "\n";
|
---|
491 | }
|
---|
492 | } else {
|
---|
493 | print "adding new entry: $dn\n";
|
---|
494 | my $result=$ldap_master->add($entry);
|
---|
495 | $result->code && warn "failed to add entry: ", $result->error ;
|
---|
496 | }
|
---|
497 | }
|
---|
498 | }
|
---|
499 | $ldap_master->unbind;
|
---|
500 | if (!defined $Options{'i'}) {
|
---|
501 | system "rm -f $tmp_ldif_file";
|
---|
502 | }
|
---|
503 |
|
---|
504 | # secure the admin account
|
---|
505 | print "\nPlease provide a password for the domain $adminName: \n";
|
---|
506 | system("$RealBin/smbldap-passwd $adminName");
|
---|
507 |
|
---|
508 |
|
---|
509 |
|
---|
510 | } else {
|
---|
511 | print "exported ldif file: $tmp_ldif_file\n";
|
---|
512 | }
|
---|
513 | exit(0);
|
---|
514 |
|
---|
515 |
|
---|
516 | ########################################
|
---|
517 |
|
---|
518 | =head1 NAME
|
---|
519 |
|
---|
520 | smbldap-populate - Populate your LDAP database
|
---|
521 |
|
---|
522 | =head1 SYNOPSIS
|
---|
523 |
|
---|
524 | smbldap-populate [ldif-file]
|
---|
525 |
|
---|
526 | =head1 DESCRIPTION
|
---|
527 |
|
---|
528 | The smbldap-populate 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).
|
---|
529 |
|
---|
530 | -a name
|
---|
531 | Your local administrator login name (default: Administrator)
|
---|
532 |
|
---|
533 | -b name
|
---|
534 | Your local guest login name (default: nobody)
|
---|
535 |
|
---|
536 | -e file
|
---|
537 | export an ldif file
|
---|
538 |
|
---|
539 | -i file
|
---|
540 | import an ldif file (Options -a and -b will be ignored)
|
---|
541 |
|
---|
542 | =head1 FILES
|
---|
543 |
|
---|
544 | /etc/opt/IDEALX/smbldap-tools/smbldap.conf : main configuration
|
---|
545 | /etc/opt/IDEALX/smbldap-tools/smbldap_bind.conf : credentials for binding to the directory
|
---|
546 |
|
---|
547 | =head1 SEE ALSO
|
---|
548 |
|
---|
549 | smb.conf(5)
|
---|
550 |
|
---|
551 | =cut
|
---|
552 |
|
---|
553 | #'
|
---|
554 |
|
---|
555 |
|
---|
556 |
|
---|
557 | # - The End
|
---|