5
# This script can help you setting up the smbldap_conf.pl file. It will set all
6
# the default values that are defined in the smb.conf configuration file. You
7
# should then start with this configuration file. You will also need the SID
8
# for your samba domain: set up the domain controller before using this script.
10
# This code was developed by IDEALX (http://IDEALX.org/) and
11
# contributors (their names can be found in the CONTRIBUTORS file).
13
# Copyright (C) 2002 IDEALX
15
# This program is free software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
34
# we need to be root to configure the scripts
36
die "Only root can configure the smbldap-tools scripts\n";
39
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
40
smbldap-tools script configuration
41
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
42
Before starting, check
43
. if your samba controller is up and running.
44
. if the domain SID is defined (you can get it with the 'net getlocalsid')
46
. you can leave the configuration using the Ctrl-c key combination
47
. empty value can be set with the \".\" character\n";
48
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n";
50
# we first check if Samba is up and running
51
my $test_smb=`pidof smbd`;
53
die "\nSamba needs to be started first !\n" if ($test_smb eq "" || not defined $test_smb);
55
print "Looking for configuration files...\n\n";
56
my $smb_conf="@SAMBA_SMB_CONF@";
57
print "Samba Configuration File Path [$smb_conf] > ";
58
chomp(my $config_smb=<STDIN>);
59
if ($config_smb ne "") {
60
$smb_conf=$config_smb;
63
my $conf_dir = "@sysconfdir@";
65
print "\nThe default directory in which the smbldap configuration files are stored is shown.\n";
66
print "If you need to change this, enter the full directory path, then press enter to continue.\n";
67
print "Smbldap-tools Configuration Directory Path [$conf_dir] > ";
69
chomp($conf_dir_tmp=<STDIN>);
70
if ($conf_dir_tmp ne "") {
71
$conf_dir=$conf_dir_tmp;
79
my $smbldap_conf="$conf_dir"."/smbldap.conf";
80
my $smbldap_bind_conf="$conf_dir"."/smbldap_bind.conf";
84
# Let's read the smb.conf configuration file
86
open (CONFIGFILE, "$smb_conf") || die "Unable to open $smb_conf for reading !\n";
88
while (<CONFIGFILE>) {
92
## eat leading whitespace
95
## eat trailing whitespace
99
## throw away comments
100
next if (($_=~/^#/) || ($_=~/^;/));
102
## check for a param = value
104
#my ($param, $value) = split (/=/, $_);
105
my ($param, $value) = ($_=~/([^=]*)=(.*)/i);
112
$config{$param} = $value;
113
#print "param=$param\tvalue=$value\n";
120
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
121
print "Let's start configuring the smbldap-tools scripts ...\n\n";
123
# This function need 4 parameters:
124
# . the description of the parameter
125
# . name of the key it is related to in the %config hash (key similar as the name parameter in
126
# smb.conf). You can get all the available keys using this:
127
# foreach my $tmp (keys %config) {
128
# print "key=$tmp\t value=$config{$tmp}\n";
130
# . if no value is found in smb.conf for the keys, this value is proposed
131
# . the 'insist' variable: if set to 1, then the script will always call for a value
132
# for the parameter. In other words, there's no default value, and it can't be set
133
# to an empty string.
137
my $description=shift;
139
my $example_value=shift;
143
$insist=0 if (! defined $insist);
144
if (defined $config{$value} and $config{$value} ne "") {
145
print "$description [$config{$value}] > ";
146
$value_tmp=$config{$value};
148
print "$description [$example_value] > ";
149
$value_tmp="$example_value";
151
chomp(my $get=<STDIN>);
154
} elsif ($get eq ".") {
159
if ($insist == 1 and "$value" eq "") {
160
while ($insist == 1) {
161
print " Warning: You really need to set this parameter...\n";
162
$description=~s/. / /;
163
if (defined $config{$value}) {
164
print "$description [$config{$value}] > ";
165
$value_tmp=$config{$value};
167
print "$description [$value] > ";
170
chomp(my $get=<STDIN>);
173
} elsif ($get eq ".") {
184
print ". workgroup name: name of the domain Samba acts as a PDC for\n";
185
my $workgroup=read_entry(" workgroup name","workgroup","",0);
187
print ". netbios name: netbios name of the samba controller\n";
188
my $netbios_name=read_entry(" netbios name","netbiosname","",0);
190
print ". logon drive: local path to which the home directory will be connected (for NT Workstations). Ex: 'H:'\n";
191
my $logondrive=read_entry(" logon drive","logondrive","",0);
193
print ". logon home: home directory location (for Win95/98 or NT Workstation).\n (use %U as username) Ex:'\\\\$netbios_name\\%U'\n";
194
my $logonhome=read_entry(" logon home (press the \".\" character if you don't want homeDirectory)","logonhome","\\\\$netbios_name\\%U",0);
195
#$logonhome=~s/\\/\\\\/g;
197
print ". logon path: directory where roaming profiles are stored. Ex:'\\\\$netbios_name\\profiles\\\%U'\n";
198
my $logonpath=read_entry(" logon path (press the \".\" character if you don't want roaming profiles)","logonpath","\\\\$netbios_name\\profiles\\\%U",0);
199
#$logonpath=~s/\\/\\\\/g;
201
my $userHome=read_entry(". home directory prefix (use %U as username)","","/home/\%U",0);
203
my $userHomeDirectoryMode=read_entry(". default users' homeDirectory mode","","700",0);
205
my $userScript=read_entry(". default user netlogon script (use %U as username)","logonscript","",0);
207
my $defaultMaxPasswordAge=read_entry(" default password validation time (time in days)","","45",0);
209
#############################
210
# ldap directory parameters #
211
#############################
212
my $ldap_suffix=read_entry(". ldap suffix","ldapsuffix","",0);
213
my $ldap_group_suffix=read_entry(". ldap group suffix","ldapgroupsuffix","",0);
214
$ldap_group_suffix=~s/ou=//;
215
my $ldap_user_suffix=read_entry(". ldap user suffix","ldapusersuffix","",0);
216
$ldap_user_suffix=~s/ou=//;
217
my $ldap_machine_suffix=read_entry(". ldap machine suffix","ldapmachinesuffix","",0);
218
$ldap_machine_suffix=~s/ou=//;
219
my $ldap_idmap_suffix=read_entry(". Idmap suffix","ldapidmapsuffix","ou=Idmap",0);
220
print ". sambaUnixIdPooldn: object where you want to store the next uidNumber\n";
221
print " and gidNumber available for new users and groups\n";
222
my $sambaUnixIdPooldn=read_entry(" sambaUnixIdPooldn object (relative to \${suffix})","","sambaDomainName=$workgroup",0);
224
# parameters for the master ldap server
225
my ($trash1,$server);
226
if (defined $config{passdbbackend}) {
227
($trash1,$server)=($config{passdbbackend}=~m/(.*)ldap:\/\/(.*)/);
229
$server="127.0.0.1" unless defined($server);
231
my $ldapmasterserver;
232
print ". ldap master server: IP address or DNS name of the master (writable) ldap server\n";
233
$ldapmasterserver=read_entry(" ldap master server","",$server,0);
235
if (defined $config{ldapport}) {
236
$ldapmasterport=read_entry(". ldap master port","ldapport","",0);
238
$ldapmasterport=read_entry(". ldap master port","","389",0);
240
my $ldap_master_admin_dn=read_entry(". ldap master bind dn","ldapadmindn","",0);
242
my $ldap_master_bind_password=read_entry(". ldap master bind password","","",1);
246
# parameters for the slave ldap server
247
print ". ldap slave server: IP address or DNS name of the slave ldap server: can also be the master one\n";
248
my $ldap_slave_server=read_entry(" ldap slave server","","$server",0);
250
if (defined $config{ldapport}) {
251
$ldap_slave_port=read_entry(". ldap slave port","ldapport","",0);
253
$ldap_slave_port=read_entry(". ldap slave port","","389",0);
255
my $ldap_slave_admin_dn=read_entry(". ldap slave bind dn","ldapadmindn","",0);
257
my $ldap_slave_bind_password=read_entry(". ldap slave bind password","","",1);
260
my $ldaptls=read_entry(". ldap tls support (1/0)","","0",0);
261
my ($cert_verify,$cert_cafile,$cert_clientcert,$cert_clientkey)=("","","","");
263
$cert_verify=read_entry(". How to verify the server's certificate (none, optional or require)","","require",0);
264
$cert_cafile=read_entry(". CA certificate file","","$conf_dir/ca.pem",0);
265
$cert_clientcert=read_entry(". certificate to use to connect to the ldap server","","$conf_dir/smbldap-tools.pem",0);
266
$cert_clientkey=read_entry(". key certificate to use to connect to the ldap server","","$conf_dir/smbldap-tools.key",0);
269
# let's test if any sid is available
270
# Here is the strategy: If smb.conf has 'domain master = No'
271
# this means we are a BDC and we must obtain the SID from the PDC
272
# using the command 'net rpc getsid -S PDC -Uroot%password' BEFORE
273
# executing this script - that then guarantees the correct SID is available.
274
my $sid_tmp=`net getlocalsid \$netbios_name 2>/dev/null | cut -f2 -d: | sed "s/ //g"`;
276
print ". SID for domain $config{workgroup}: SID of the domain (can be obtained with 'net getlocalsid $netbios_name')\n";
277
my $sid=read_entry(" SID for domain $config{workgroup}","","$sid_tmp",0);
279
print ". unix password encryption: encryption used for unix passwords\n";
280
my $cryp_algo=read_entry(" unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA)","","SSHA",0);
281
my $crypt_salt_format="";
282
if ( $cryp_algo eq "CRYPT" ) {
283
print ". crypt salt format: If hash_encrypt is set to CRYPT, you may set \n";
284
print " a salt format. The default is \"\%s\", but many systems will generate\n";
285
print " MD5 hashed passwords if you use \"\$1\$\%\.8s\"\n";
286
$crypt_salt_format=read_entry(" crypt salt format","","\%s",0);
289
my $default_user_gidnumber=read_entry(". default user gidNumber","","513",0);
291
my $default_computer_gidnumber=read_entry(". default computer gidNumber","","515",0);
293
my $userLoginShell=read_entry(". default login shell","","/bin/bash",0);
295
my $skeletonDir=read_entry(". default skeleton directory","","/etc/skel",0);
297
my $mailDomain=read_entry(". default domain name to append to mail address", "","",0);
299
print "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
300
my $template_smbldap="
301
# smbldap-tools.conf : Q & D configuration file for smbldap-tools
303
# This code was developed by IDEALX (http://IDEALX.org/) and
304
# contributors (their names can be found in the CONTRIBUTORS file).
306
# Copyright (C) 2001-2002 IDEALX
308
# This program is free software; you can redistribute it and/or
309
# modify it under the terms of the GNU General Public License
310
# as published by the Free Software Foundation; either version 2
311
# of the License, or (at your option) any later version.
313
# This program is distributed in the hope that it will be useful,
314
# but WITHOUT ANY WARRANTY; without even the implied warranty of
315
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
316
# GNU General Public License for more details.
318
# You should have received a copy of the GNU General Public License
319
# along with this program; if not, write to the Free Software
320
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
324
# . be the configuration file for all smbldap-tools scripts
326
##############################################################################
328
# General Configuration
330
##############################################################################
332
# Put your own SID. To obtain this number do: \"net getlocalsid\".
333
# If not defined, parameter is taking from \"net getlocalsid\" return
336
# Domain name the Samba server is in charged.
337
# If not defined, parameter is taking from smb.conf configuration file
338
# Ex: sambaDomain=\"IDEALX-NT\"
339
sambaDomain=\"$workgroup\"
341
##############################################################################
345
##############################################################################
347
# Notes: to use to dual ldap servers backend for Samba, you must patch
348
# Samba with the dual-head patch from IDEALX. If not using this patch
349
# just use the same server for slaveLDAP and masterLDAP.
350
# Those two servers declarations can also be used when you have
351
# . one master LDAP server where all writing operations must be done
352
# . one slave LDAP server where all reading operations must be done
353
# (typically a replication directory)
356
# Ex: slaveLDAP=127.0.0.1
357
# If not defined, parameter is set to \"127.0.0.1\"
358
slaveLDAP=\"$ldap_slave_server\"
361
# If not defined, parameter is set to \"389\"
362
slavePort=\"$ldap_slave_port\"
364
# Master LDAP server: needed for write operations
365
# Ex: masterLDAP=127.0.0.1
366
# If not defined, parameter is set to \"127.0.0.1\"
367
masterLDAP=\"$ldapmasterserver\"
370
# If not defined, parameter is set to \"389\"
371
masterPort=\"$ldapmasterport\"
374
# If set to 1, this option will use start_tls for connection
375
# (you should also used the port 389)
376
# If not defined, parameter is set to \"1\"
379
# How to verify the server's certificate (none, optional or require)
380
# see \"man Net::LDAP\" in start_tls section for more details
381
verify=\"$cert_verify\"
384
# see \"man Net::LDAP\" in start_tls section for more details
385
cafile=\"$cert_cafile\"
387
# certificate to use to connect to the ldap server
388
# see \"man Net::LDAP\" in start_tls section for more details
389
clientcert=\"$cert_clientcert\"
391
# key certificate to use to connect to the ldap server
392
# see \"man Net::LDAP\" in start_tls section for more details
393
clientkey=\"$cert_clientkey\"
396
# Ex: suffix=dc=IDEALX,dc=ORG
397
suffix=\"$ldap_suffix\"
399
# Where are stored Users
400
# Ex: usersdn=\"ou=Users,dc=IDEALX,dc=ORG\"
401
# Warning: if 'suffix' is not set here, you must set the full dn for usersdn
402
usersdn=\"ou=$ldap_user_suffix,\${suffix}\"
404
# Where are stored Computers
405
# Ex: computersdn=\"ou=Computers,dc=IDEALX,dc=ORG\"
406
# Warning: if 'suffix' is not set here, you must set the full dn for computersdn
407
computersdn=\"ou=$ldap_machine_suffix,\${suffix}\"
409
# Where are stored Groups
410
# Ex: groupsdn=\"ou=Groups,dc=IDEALX,dc=ORG\"
411
# Warning: if 'suffix' is not set here, you must set the full dn for groupsdn
412
groupsdn=\"ou=$ldap_group_suffix,\${suffix}\"
414
# Where are stored Idmap entries (used if samba is a domain member server)
415
# Ex: groupsdn=\"ou=Idmap,dc=IDEALX,dc=ORG\"
416
# Warning: if 'suffix' is not set here, you must set the full dn for idmapdn
417
idmapdn=\"$ldap_idmap_suffix,\${suffix}\"
419
# Where to store next uidNumber and gidNumber available for new users and groups
420
# If not defined, entries are stored in sambaDomainName object.
421
# Ex: sambaUnixIdPooldn=\"sambaDomainName=\${sambaDomain},\${suffix}\"
422
# Ex: sambaUnixIdPooldn=\"cn=NextFreeUnixId,\${suffix}\"
423
sambaUnixIdPooldn=\"$sambaUnixIdPooldn,\${suffix}\"
428
# Unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA, CLEARTEXT)
429
hash_encrypt=\"$cryp_algo\"
431
# if hash_encrypt is set to CRYPT, you may set a salt format.
432
# default is \"\%s\", but many systems will generate MD5 hashed
433
# passwords if you use \"\$1\$\%\.8s\". This parameter is optional!
434
crypt_salt_format=\"$crypt_salt_format\"
436
##############################################################################
438
# Unix Accounts Configuration
440
##############################################################################
443
# Default Login Shell
444
# Ex: userLoginShell=\"/bin/bash\"
445
userLoginShell=\"$userLoginShell\"
448
# Ex: userHome=\"/home/\%U\"
449
userHome=\"$userHome\"
451
# Default mode used for user homeDirectory
452
userHomeDirectoryMode=\"$userHomeDirectoryMode\"
455
userGecos=\"System User\"
457
# Default User (POSIX and Samba) GID
458
defaultUserGid=\"$default_user_gidnumber\"
460
# Default Computer (Samba) GID
461
defaultComputerGid=\"$default_computer_gidnumber\"
464
skeletonDir=\"$skeletonDir\"
466
# Default password validation time (time in days) Comment the next line if
467
# you don't want password to be enable for defaultMaxPasswordAge days (be
468
# careful to the sambaPwdMustChange attribute's value)
469
defaultMaxPasswordAge=\"$defaultMaxPasswordAge\"
471
##############################################################################
473
# SAMBA Configuration
475
##############################################################################
477
# The UNC path to home drives location (\%U username substitution)
478
# Just set it to a null string if you want to use the smb.conf 'logon home'
479
# directive and/or disable roaming profiles
480
# Ex: userSmbHome=\"\\\\PDC-SMB3\\%U\"
481
userSmbHome=\"$logonhome\"
483
# The UNC path to profiles locations (\%U username substitution)
484
# Just set it to a null string if you want to use the smb.conf 'logon path'
485
# directive and/or disable roaming profiles
486
# Ex: userProfile=\"\\\\PDC-SMB3\\profiles\\\%U\"
487
userProfile=\"$logonpath\"
489
# The default Home Drive Letter mapping
490
# (will be automatically mapped at logon time if home directory exist)
491
# Ex: userHomeDrive=\"H:\"
492
userHomeDrive=\"$logondrive\"
494
# The default user netlogon script name (\%U username substitution)
495
# if not used, will be automatically username.cmd
496
# make sure script file is edited under dos
497
# Ex: userScript=\"startup.cmd\" # make sure script file is edited under dos
498
userScript=\"$userScript\"
500
# Domain appended to the users \"mail\"-attribute
501
# when smbldap-useradd -M is used
502
# Ex: mailDomain=\"idealx.com\"
503
mailDomain=\"$mailDomain\"
505
##############################################################################
507
# SMBLDAP-TOOLS Configuration (default are ok for a RedHat)
509
##############################################################################
511
# Allows not to use smbpasswd (if with_smbpasswd=\"0\" in smbldap.conf) but
512
# prefer Crypt::SmbHash library
514
smbpasswd=\"/usr/bin/smbpasswd\"
516
# Allows not to use slappasswd (if with_slappasswd=\"0\" in smbldap.conf)
517
# but prefer Crypt:: libraries
518
with_slappasswd=\"0\"
519
slappasswd=\"/usr/sbin/slappasswd\"
521
# comment out the following line to get rid of the default banner
525
my $template_smbldap_bind="
526
############################
527
# Credential Configuration #
528
############################
529
# Note: you can specify two different configurations if you use a
530
# master ldap for writing access and a slave ldap server for reading access
531
# By default, we will use the same DN (so it will work for standard Samba
533
slaveDN=\"$ldap_master_admin_dn\"
534
slavePw=\"$ldap_master_bind_password\"
535
masterDN=\"$ldap_slave_admin_dn\"
536
masterPw=\"$ldap_slave_bind_password\"
539
print "backup old configuration files:\n";
540
print " $smbldap_conf->$smbldap_conf.old\n";
541
print " $smbldap_bind_conf->$smbldap_bind_conf.old\n";
542
rename "$smbldap_conf","$smbldap_conf.old";
543
rename "$smbldap_bind_conf","$smbldap_bind_conf.old";
545
print "writing new configuration file:\n";
546
open (SMBLDAP,'>',"$smbldap_conf") || die "Unable to open $smbldap_conf for writing !\n";
547
print SMBLDAP "$template_smbldap";
549
print " $smbldap_conf done.\n";
551
chmod $mode,"$smbldap_conf","$smbldap_conf.old";
553
open (SMBLDAP_BIND,'>',"$smbldap_bind_conf") || die "Unable to open $smbldap_bind_conf for writing !\n";
554
print SMBLDAP_BIND "$template_smbldap_bind";
556
print " $smbldap_bind_conf done.\n";
558
chmod $mode,"$smbldap_bind_conf","$smbldap_bind_conf.old";