summaryrefslogtreecommitdiffstats
path: root/samba_wizard/Samba.pm
blob: cae13a745b058785b276b7aa428f949f438c8ad0 (plain)
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/usr/bin/perl

# Drakwizard
# Copyright (C) 2002,2005 Mandriva
#
# Authors: Arnaud Desmons <adesmons@mandrakesoft.com>
#          Florent Villard <warly@mandrakesoft.com>
#          antoine Ginies <aginies@mandriva>
#
# 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, 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.

package MDK::Wizard::Samba;
use strict;

use common;
use services;
use MDK::Wizard::Wizcommon;
use Gtk2;

use Libconf::Templates;
use Libconf::Glueconf::Samba::Smb_conf;

my $wiz = new MDK::Wizard::Wizcommon;

my $DOMAINNAME = chomp_(`dnsdomainname`);
my $SHORTHOSTNAME = chomp_(`hostname -s`);
my $wiz_samba_etc = "/etc/sysconfig/wizard_samba";
my @listshare;
my @listprinters;

my $o = {
	 name => 'Samba wizard',
	 var => {
		 wiz_box_list => '',
		 wiz_netbios => '',
		 wiz_all_printers => '',
		 wiz_level => '',
		 wiz_workgroup => '',
		 wiz_banner => '',
		 wiz_log_file => '', wiz_log_level => '', wiz_max_log_size => '',
		 wiz_local_master => '',
		 wiz_os_level => '',
		 wiz_security => '',
		 wiz_domain_logons => '',
		 wiz_domain_master => '',
		 wiz_password_server => '',
		 wiz_passdb_backend => '', wiz_passdb_backend_yn => '',
		 wiz_ldap_admin_dn => '', wiz_ldap_suffix => '', wiz_ldap_root_pw => '', wiz_ldap_root_pw_2 => '',
		 wiz_preferred_master => '',
		 wiz_wins_server => '',
		 wiz_name_resolve_order => '',
		 wiz_dns_proxy => '',
		 wiz_sambatype => '',
		},
	 init => sub {
           test_host_domain($SHORTHOSTNAME, $DOMAINNAME);
         },
	 needed_rpm => [ 'samba-server' ],
	 defaultimage => "/usr/share/wizards/samba_wizard/images/sambasrv.png"
	};

# we ask glueconf to give us the structure representing /etc/samba/smb.conf
if (!-f "/etc/samba/smb.conf") { cp_af("/usr/share/wizards/samba_wizard/scripts/smb.conf.default", "/etc/samba/smb.conf"); }
my $samba = new Libconf::Glueconf::Samba::Smb_conf({ filename => '/etc/samba/smb.conf', show_commented_info => 1 });

#debug
use Data::Dumper;
print Dumper($samba);

my %type = (
	    1 => N('BDC - backup domain controller (need PDC+LDAP)'),
	    2 => N('PDC - primary domain controller'),
	    3 => N('Standalone - standalone server'),
	    #	    4 => N('Member - member of a domain'),
	   );

my @yesorno = qw(yes no); push @yesorno, "";
my @loglevel = qw(0 1 2 3 4 5 6 7 8 9);

$o->{pages} = {
	       welcome => {
			   name => N('Samba server configuration Wizard') . "\n\n" . N('Samba allows your server to behave as a file and print server for workstations running non-Linux systems.'),
			   no_back => 1,
                           pre => sub {
			     if (-f $wiz_samba_etc) {
#			       $::isWizard = 1;
			       $::in->ask_warn(N("Information"), N("It seems you previously setup a Samba server. This wizard will re-read your old configuration, and show you the Samba server type you choose")) and return;
			       my $data = cat_($wiz_samba_etc);
			       # detect old Samba type
			       my ($old_type) = $data =~ /type=(\d)/;
			       $o->{var}{wiz_type} = chomp_($old_type);
			     } else { $o->{var}{wiz_type} = 2 }
			   },
			   post => sub {
                             if ($o->{var}{wiz_type} == 2) {
                               return 'pdc' }
                             elsif ($o->{var}{wiz_type} == 1) {
                               return 'bdc' }
                             elsif ($o->{var}{wiz_type} == 3) {
			       return 'ask_workgroup' }
                             elsif ($o->{var}{wiz_type} == 4) {
			       return 'member' }
                           },
                           data => [
                                   { label => "", val => \$o->{var}{wiz_type}, type => 'list', list => [ keys %type ], format => sub { $type{$_[0]} } },
                                   ],
                          },
	       pdc => {
		       name => N('PDC server: primary domain controller')  . "\n\n" . N('Server configured as a PDC is responsible for Windows authentication throughout the domain.') . "\n" . N('Single server installations may use smbpasswd or tdbsam password backends') . "\n" . N('Domain master = yes, causes the server to register the NetBIOS name <pdc name>1B. This name will be recognized by other servers.'),
		       pre => sub {
			       $o->{var}{wiz_domain_master} = "yes";
			       $o->{var}{wiz_security} = "user";
			       $o->{var}{wiz_domain_logons} = "yes";
			       $o->{var}{wiz_wins_support} ||= $samba->{global}{'wins support'};
			       $o->{var}{wiz_oslevel} = "128";

			       if (exists $samba->{global}{'passdb backend'}) {
				 $o->{var}{wiz_passdb_backend_yn} = "yes";
			       }
			       else {
				 $o->{var}{wiz_passdb_backend_yn} = "no";
			       }
			     },
		       next => 'ask_workgroup',
#		       post => sub {
#			 $o->{var}{wiz_passdb_backend_yn} =~ /yes/ and return 'ldap_conf';
#		       },
		       data => [
				{ label => N('Domain logons:'), fixed_val => \$o->{var}{wiz_domain_logons} },
				{ label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
				{ label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				{ label => N('Wins support:'), val => \$o->{var}{wiz_wins_support}, fixed_list => \@yesorno },
				{ label => N('admin users:'), val => \$o->{var}{wiz_admin_users}, help => N('root @adm') },
				{ label => N('Os level:'), fixed_val => \$o->{var}{wiz_oslevel}, help =>N("The global os level option dictates the operating system level at which Samba will masquerade during a browser election. If you wish to have Samba win an election and become the master browser, you can set the level above that of the operating system on your network with the highest current value. ie: os level = 34") },
#				{ label => N('Use LDAP Passdb backend'), val => \$o->{var}{wiz_passdb_backend_yn}, fixed_list => \@yesorno },
			       ],
		       complete => sub {
				    if (!$o->{var}{wiz_domain_master}) {
				      $::in->ask_warn(N("Error"), N("The domain is wrong."));
				      return 1
				    } else { return 0 };
				   },
		       next => 'ask_workgroup',
		      },
	       bdc => {
		       name => N('BDC server: backup domain controller') . "\n\n" . N('This enables BDCs to carry much of the network logon processing. A BDC on a local segment handles logon requests and authenticates users when the PDC is busy on the local network. When a segment becomes heavily loaded, the reponsibility is offloaded to another segment\'s BDC or to the PDC.'),
		       pre => sub {
			       $o->{var}{wiz_domain_master} = "no";
			       $o->{var}{wiz_security} = "user";
			       $o->{var}{wiz_wins_support} = "";
			       $o->{var}{wiz_oslevel} = "70";
			       $o->{var}{wiz_local_master} = "yes";
			       $o->{var}{wiz_domain_master} = "no";
			       $o->{var}{wiz_preferred_master} = "yes";
			       $o->{var}{wiz_domain_logons} = "yes";
			       $o->{var}{wiz_wins_server} = "";
			       if ($samba->{global}{'name resolve order'}) {
				 $o->{var}{wiz_name_resolve_order} = $samba->{global}{'name resolve order'}
			       } else { $o->{var}{wiz_name_resolve_order} = "lmhosts host wins bcast" }
			       $o->{var}{wiz_dns_proxy} = "no";
			     },
		       data => [
				{ label => N('Wins support:'), val => \$o->{var}{wiz_wins_support}, fixed_list => \@yesorno },
				{ label => N('Wins server:'), val => \$o->{var}{wiz_wins_server}, help => N('This specifies the IP address (or DNS name: IP address for preference) of the WINS server that nmbd(8) should register with. If you have a WINS server on your network then you should set this to the WINS server\'s IP.') },
				{ label => N('Wins name resolve order:'), val => \$o->{var}{wiz_name_resolve_order} },
			       ],
		       complete => sub {
			 if ($o->{var}{wiz_wins_support} =~ /no/ and !$o->{var}{wiz_wins_server} ) {
			   $::in->ask_warn(N("Error"), N("Your server doesn't support Wins. Please provide a Wins server, or leave blank Wins Support entry."));
			   return 1
			 } else { return 0 };
		       },
		       next => 'ask_bdc2',
		      },
	       ask_bdc2 => {
			    name => N('BDC server: needed fixed options'),
			    data => [
				     { label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },
				     { label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				     { label => N('Os level:'), fixed_val => \$o->{var}{wiz_oslevel} },
				     { label => N('Local master:'), fixed_val => \$o->{var}{wiz_local_master} },
				     { label => N('Domain master'), fixed_val => \$o->{var}{wiz_domain_master} },
				     { label => N('Prefered master'), fixed_val => \$o->{var}{wiz_preferred_master} },
				     { label => N('Domain logons'), fixed_val => \$o->{var}{wiz_domain_logons} },
				     { label => N('admin users:'), val => \$o->{var}{wiz_admin_users}, help => N('root @adm') },
				    ],
			    next => 'ldap_conf',
			   },
	       member => {
			  name => N('Member of a domain') . "\n\n" . ('Share data, users home or printers.') . "\n" . N('Please enter the domain you want to join.'),
			  pre => sub {
				  $o->{var}{wiz_security} = "domain";
				  $o->{var}{wiz_domain_master} = "no";
				  $o->{var}{wiz_password_server} ||= $samba->{global}{'password server'};
				  if ($samba->{global}{'passdb backend'}) {
				    $o->{var}{wiz_passdb_backend_yn} = "yes"
				  } else {
				    $o->{var}{wiz_passdb_backend_yn} = "no"
				  }
				},
			  post => sub {
			    $o->{var}{wiz_passdb_backend_yn} =~ /yes/ and return 'ldap_conf';
			  },
			  data => [
				   { label => N('Password server'), hidden => 1, val => \$o->{var}{wiz_password_server} },
				   { label => N('Use LDAP Passdb backend'), val => \$o->{var}{wiz_passdb_backend_yn}, fixed_list => \@yesorno },
				   { label => N('Security:'), fixed_val => \$o->{var}{wiz_security} },
				   { label => N('Domain master:'), fixed_val => \$o->{var}{wiz_domain_master} },

				  ],
			  complete => sub {
				       if (!$o->{var}{wiz_password_server}) {
					 $::in->ask_warn(N("Error"), N("Please provide the password server."));
					 return 1
				       } else { return 0 };
				      },
			  next => 'ask_workgroup',
			 },
	       ldap_conf => {
			     name => N('LDAP configuration for Domain Controlling') . "\n\n" . N('The account (dn) that samba uses to access the LDAP server. This account needs to have write access to the LDAP tree. You will need to give samba the password for this dn.'),
			     pre => sub {
			       $o->{var}{wiz_ldap_passwd_sync} = "yes";
			       if ($samba->{global}{'ldap suffix'}) {
				 $o->{var}{wiz_ldap_suffix} = $samba->{global}{'ldap suffix'};
			       } else { $o->{var}{wiz_ldap_suffix} = "dc=mydomain, dc=com" }
			       if ($samba->{global}{'ldap admin dn'}) {
				 $o->{var}{wiz_ldap_admin_dn} ||= $samba->{global}{'ldap admin dn'}
			       } else { $o->{var}{wiz_ldap_admin_dn} = "cn=Manager,dc=mydomain,dc=com" }
			       if ($samba->{global}{'passdb backend'}) {
				 $o->{var}{wiz_passdb_backend} = $samba->{global}{'passdb backend'}
			       } else { $o->{var}{wiz_passdb_backend} = "ldapsam:ldap://localhost" }
			       if($samba->{global}{'ldap machine suffix'}) {
				 $o->{var}{wiz_ldap_machine_suffix} = $samba->{global}{'ldap machine suffix'} }
			       else { $o->{var}{wiz_ldap_machine_suffix} = "ou=Computers" }
			       if($samba->{global}{'ldap group suffix'}) {
				 $o->{var}{wiz_ldap_group_suffix} = $samba->{global}{'ldap group suffix'} }
			       else { $o->{var}{wiz_ldap_group_suffix} = "ou=Groups" }
			       if($samba->{global}{'ldap user suffix'}) {
			       $o->{var}{wiz_ldap_user_suffix} = $samba->{global}{'ldap user suffix'} }
			       else { $o->{var}{wiz_ldap_user_suffix} = "ou=Users" }
			     },
			     data => [
				      { label => N('Passdb backend'), val => \$o->{var}{wiz_passdb_backend}, help => "ldapsam:ldap://<ldap server name>" },
				      { label => N('LDAP administrator'), val => \$o->{var}{wiz_ldap_admin_dn}, help => N(' The ldap admin dn defines the Distinguished Name (DN) name used by Samba to contact the ldap server when retreiving user account information. ie: cn=Manager,dc=mydomain,dc=com') },
				      { label => N('LDAP suffix'), val => \$o->{var}{wiz_ldap_suffix}, help => N('Specifies where user and machine accounts are added to the tree. Can be overriden by ldap user suffix and ldap machine suffix. It also used as the base dn for all ldap searches. ie: dc=$DOMAINNAME,dc=com') },
				      { label => N('LDAP password'), hidden => 1, val => \$o->{var}{wiz_ldap_root_pw} },
				      { label => N('LDAP password check:'), hidden => 1, val => \$o->{var}{wiz_ldap_root_pw_2} },
				      { label => N('LDAP machine suffix:'), val => \$o->{var}{wiz_ldap_machine_suffix}, help => N('It specifies where machines should be added to the ldap tree. ie: ou=Computers') },
				      { label => N('LDAP user suffix:'), val => \$o->{var}{wiz_ldap_user_suffix}, help => N('This parameter specifies where users are added to the tree. If this parameter is not specified, the value from ldap suffix.') },
				      { label => N('LDAP group suffix:'), val => \$o->{var}{wiz_ldap_group_suffix}, help => N('This parameters specifies the suffix that is  used for groups when these are added to the LDAP directory. ie: ou=Groups') },
				     ],
			     complete => sub {
			       if (!($o->{var}{wiz_ldap_suffix})) {
				 $::in->ask_warn(N('Error'), N('Please provide an LDAP suffix.'));
				 return 1;
			       }
                               if (! ($o->{var}{wiz_ldap_admin_dn})) {
                                 $::in->ask_warn(N('Error'), N('Please enter an LDAP administrator.'));
                                 return 1;
                               }
			       if (! ($o->{var}{wiz_ldap_root_pw})) {
				 $::in->ask_warn(N('Error'), N('Please enter an LDAP password.'));
				 return 1;
			       }
			       if ($o->{var}{wiz_ldap_root_pw} ne $o->{var}{wiz_ldap_root_pw_2}) {
				 $::in->ask_warn(N('Error'), N('Pasword dont match.'));
				 return 1;
			       }
			     },
			     next => 'ask_workgroup',
			    },
	       ask_workgroup => {
				 name => N('Workgroup') . "\n\n" . N('Samba needs to know the Windows Workgroup it will serve.'),
				 pre => sub {
				   $o->{var}{wiz_workgroup} ||= $samba->{global}{workgroup};
				   $o->{var}{wiz_netbios} ||= $samba->{global}{netbios};
				 },
				 data => [
					  { label => N('Workgroup:'), val => \$o->{var}{wiz_workgroup} },
					 ],
				 complete => sub {
				   if (!$o->{var}{wiz_workgroup}) {
                                     $::in->ask_warn(N("Error"), N("The Workgroup is wrong."));
				     return 1
				   } else { return 0 };
				 },
				 next => 'ask_banner',
				},
	       ask_banner => {
			      name => N('Server Banner.') . "\n\n" . N('The banner is the way this server will be described in the Windows workstations.'),
			      pre => sub {
				$o->{var}{wiz_banner} ||= $samba->{global}{'server string'}
			      },
			      data => [
				       { label => N('Banner:'), val => \$o->{var}{wiz_banner}, help => "Samba Server %v" },
				      ],
			      complete => sub {
				if (!$o->{var}{wiz_banner}) {
				  $::in->ask_warn(N("Error"), N("The Server Banner is incorrect."));
				  return 1
				} else { return 0 };
			      },
			      next => 'ask_log',
			     },
	       ask_log => {
			   name => N('Samba Log') . "\n\n" . N('Log file: use file.%m to use a separate log file for each machine that connects') . "\n" . N('Log level: set the log (verbosity) level (0 <= log level <= 10)') . "\n" . N('Max Log size: put a capping on the size of the log files (in Kb).'),
			   pre => sub {
			     $o->{var}{wiz_log_file} ||= $samba->{global}{'log file'};
			     $o->{var}{wiz_log_level} ||= $samba->{global}{'log level'};
			     $o->{var}{wiz_max_log_size} ||= $samba->{global}{'max log size'};
			   },
			   data => [
				    { label => N('Log file:'), val => \$o->{var}{wiz_log_file}, help => "/var/log/samba/log.%m" },
				    { label => N('Max log size:'), val => \$o->{var}{wiz_max_log_size}, help => "50" },
				    { label => N('Log level:'), val => \$o->{var}{wiz_log_level}, fixed_list => \@loglevel },
				   ],
			   next => 'summary',
			  },
	       summary => {
			   name =>  N('Configuring Samba') . "\n\n" . N('The wizard collected the following parameters to configure Samba.') . "\n\n" . N('To accept these values, and configure your server, click the Next button or use the Back button to correct them.') . "\n" . N('If you have previously create some shares, they will appear in this configuration. Run "drakwizard sambashare" to manage your share.'),
			   pre => sub {
			     $o->{var}{wiz_sambatype} = $type{$o->{var}{wiz_type}};
			   },
			   data => [
				    { label => N('Samba type:'), fixed_val => \$o->{var}{wiz_sambatype} },
				    { label => N('Workgroup:'), fixed_val => \$o->{var}{wiz_workgroup} },
				    { label => N('Server banner:'), fixed_val => \$o->{var}{wiz_banner} },
				    { label => N('Log file:'), fixed_val => \$o->{var}{wiz_log_file} },
				   ],
			   post => \&do_it,
			   next => 'end'
			  },
	       end => {
		       name => N('Congratulations') . "\n\n" . N('The wizard successfully configured your Samba server.'),
		       post => sub {
			 store_samba_type($o->{var}{wiz_type});
		       },
		       no_back => 1,
		       end => 1,
		       next => 0
		      },
	       error_end => {
			     name => N("Failed"),
			     data => [ { label => N("Please relaunch drakwizard, and try to change some parameters.") } ],
			     no_back => 1,
			     end => 1,
			     next => 0,
			    },
	      };

sub new {
  my ($class, $conf) = @_;
  bless {
	 o   => $o,
	}, $class;
}

sub check() {
    $> and return 1;
    $wiz->{net}->is_dhcp() and return 2;
    0;
}

sub global_special_options() {
  # set charset
  $samba->{global}{'dos charset'} ||= "850";
  $samba->{global}{'unix charset'} ||= "ISO8859-1";

  # detect Samba type 3 is standalone
  if ($o->{var}{wiz_type} == "3") {
    $samba->{global}{'security'} = "share";
    exists $samba->{global}{'domain_master'} and delete $samba->{global}{'domain_master'};
    exists $samba->{global}{'domain logons'} and delete $samba->{global}{'domain logons'};
    exists $samba->{global}{'wins support'} and delete $samba->{global}{'wins support'};
    exists $samba->{global}{'os level'} and delete $samba->{global}{'os level'};
  } else {
    # so pdc, bdc or member
    $o->{var}{wiz_local_master} and $samba->{global}{'local master'} = $o->{var}{wiz_local_master};
    $o->{var}{wiz_preferred_master} and $samba->{global}{'preferred master'} = $o->{var}{wiz_preferred_master};
    $o->{var}{wiz_wins_server} and $samba->{global}{'wins server'} = $o->{var}{wiz_wins_server};
    $o->{var}{wiz_name_resolve_order} and $samba->{global}{'name resolve order'} = $o->{var}{wiz_name_resolve_order};
    $o->{var}{wiz_dns_proxy} and $samba->{global}{'dns proxy'} = $o->{var}{wiz_dns_proxy};
    $o->{var}{wiz_domain_master} and $samba->{global}{'domain master'} = $o->{var}{wiz_domain_master};
    $o->{var}{wiz_security} and $samba->{global}{security} = $o->{var}{wiz_security};
    $o->{var}{wiz_domain_logons} and $samba->{global}{'domain logons'} = $o->{var}{wiz_domain_logons};
    $o->{var}{wiz_oslevel} and $samba->{global}{'os level'} = $o->{var}{wiz_oslevel};
    $o->{var}{wiz_passdb_backend} and $samba->{global}{'passdb backend'} = $o->{var}{wiz_passdb_backend};
    $o->{var}{wiz_wins_support} and $samba->{global}{'wins support'} = $o->{var}{wiz_wins_support};
    $o->{var}{wiz_password_server} and $samba->{global}{'password server'} = $o->{var}{wiz_password_server};
    $o->{var}{wiz_admin_users} and $samba->{global}{'admin users'} = $o->{var}{wiz_admin_users};
    $samba->{global}{'add machine script'} = "/usr/sbin/useradd -d /dev/null -g machines -c 'Machine Account' -s /bin/false -M '%u'";
    # ldap options if needed
    if ($o->{var}{wiz_passdb_backend_yn} =~ /yes/) {
      $samba->{global}{'ldap passwd sync'} = "yes";
      $samba->{global}{'add machine script'} and delete $samba->{global}{'add machine script'};
      $o->{var}{wiz_ldap_suffix} and $samba->{global}{'ldap suffix'} = $o->{var}{wiz_ldap_suffix};
      $o->{var}{wiz_ldap_admin_dn} and $samba->{global}{'ldap admin dn'} = $o->{var}{wiz_ldap_admin_dn};
      $o->{var}{wiz_passdb_backend} and $samba->{global}{'passdb backend'} = $o->{var}{wiz_passdb_backend};
      $o->{var}{wiz_ldap_machine_suffix} and $samba->{global}{'ldap machine suffix'} = $o->{var}{wiz_ldap_machine_suffix};
      $o->{var}{wiz_ldap_group_suffix} and $samba->{global}{'ldap group suffix'} = $o->{var}{wiz_ldap_group_suffix};
      $o->{var}{wiz_ldap_user_suffix} and $samba->{global}{'ldap user suffix'} = $o->{var}{wiz_ldap_user_suffix};
    } else {
    # delete ldap options if exist
      exists $samba->{global}{'passdb backend'} and delete $samba->{global}{'passdb backend'};
      exists $samba->{global}{'ldap admin dn'} and delete $samba->{global}{'ldap admin_dn'};
      exists $samba->{global}{'ldap suffix'} and delete $samba->{global}{'ldap suffix'};
      exists $samba->{global}{'ldap passwd sync'} and delete$samba->{global}{'ldap passwd sync'};
      exists $samba->{global}{'ldap machine suffix'} and delete $samba->{global}{'ldap machine suffix'};
      exists $samba->{global}{'ldap group suffix'} and delete $samba->{global}{'ldap group suffix'};
      exists $samba->{global}{'ldap user suffix'} and delete $samba->{global}{'ldap user suffix'};
    }
  }
}

sub store_samba_type {
  # write config file to store Samba type
  my ($type) = @_;
  output($wiz_samba_etc, <<EOF);
#  1 = BDC - backup domain controller
#  2 = PDC - primary domain controller
#  3 = Standalone - standalone server
#  4 = Member - member of a domain
EOF

  append_to_file($wiz_samba_etc, "type=$type\n");
}

sub write_conf_restart_smb {
  $samba->write_conf("/etc/samba/smb.conf");
  if (services::is_service_running('smb')) {
    services::restart('smb')
    } else { services::start('smb') }
}

# remember one variable cannot be commented and not in the same file.
sub do_it {
  $::testing and return;
  # display a wait dialog box
  my $in = 'interactive'->vnew('su', 'Samba');
  my $w = $in->wait_message(N("Samba server"), N("Configuring your Samba server..."));
  # global section
  $samba->{global}{workgroup} = $o->{var}{wiz_workgroup};
  $samba->{global}{'server string'} = $o->{var}{wiz_banner};

  # add special global options
  global_special_options;

  # log level in global section
  $o->{var}{wiz_log_file} and $samba->{global}{'log file'} = $o->{var}{wiz_log_file};
  $o->{var}{wiz_log_level} and $samba->{global}{'log level'} = $o->{var}{wiz_log_level};
  $o->{var}{wiz_max_log_size} and $samba->{global}{'max log size'} = $o->{var}{wiz_max_log_size};

  write_conf_restart_smb();
  # remove wait message
  undef $w;
  check_started('smbd');
}
1;