summaryrefslogtreecommitdiffstats
path: root/samba_wizard/scripts
diff options
context:
space:
mode:
authorArnaud Desmons <adesmons@mandriva.com>2002-09-05 07:37:06 +0000
committerArnaud Desmons <adesmons@mandriva.com>2002-09-05 07:37:06 +0000
commitf7cca6ea32444a7764d54989bf360530d07d6092 (patch)
tree779049ed3b297fa40354f497a5e0d6ca86505096 /samba_wizard/scripts
parent52d4a220029dac288c8b86c3271ce9ab5fbdc6c2 (diff)
downloaddrakwizard-f7cca6ea32444a7764d54989bf360530d07d6092.tar
drakwizard-f7cca6ea32444a7764d54989bf360530d07d6092.tar.gz
drakwizard-f7cca6ea32444a7764d54989bf360530d07d6092.tar.bz2
drakwizard-f7cca6ea32444a7764d54989bf360530d07d6092.tar.xz
drakwizard-f7cca6ea32444a7764d54989bf360530d07d6092.zip
untouched
Diffstat (limited to 'samba_wizard/scripts')
-rwxr-xr-xsamba_wizard/scripts/check_banner.sh39
-rwxr-xr-xsamba_wizard/scripts/check_services.sh44
-rwxr-xr-xsamba_wizard/scripts/check_workgroup.sh38
-rwxr-xr-xsamba_wizard/scripts/do_it_samba.sh80
-rwxr-xr-xsamba_wizard/scripts/smbconfig.pl232
5 files changed, 433 insertions, 0 deletions
diff --git a/samba_wizard/scripts/check_banner.sh b/samba_wizard/scripts/check_banner.sh
new file mode 100755
index 00000000..42aed456
--- /dev/null
+++ b/samba_wizard/scripts/check_banner.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+#
+# Wizard
+#
+# Copyright (C) 2000 Mandrakesoft.
+#
+# 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.
+# See file LICENSE for further informations on licensing terms.
+#
+# 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.
+#
+# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
+# icons: Helene Durosini <ln@mandrakesoft.com>
+# <corporate@mandrakesoft.com> http://www.mandrakesoft.com
+
+# script for wizard samba configuration
+#
+# checking if the provided server banner is correct :
+
+
+if [ -z "${wiz_banner}" ] ;then
+ echo_debug "wiz_banner is empty, should not."
+ exit 1
+fi
+
+
+# all seems to be ok
+exit 10
+
diff --git a/samba_wizard/scripts/check_services.sh b/samba_wizard/scripts/check_services.sh
new file mode 100755
index 00000000..802bc320
--- /dev/null
+++ b/samba_wizard/scripts/check_services.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+#
+# Wizard
+#
+# Copyright (C) 2000 Mandrakesoft.
+#
+# 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.
+# See file LICENSE for further informations on licensing terms.
+#
+# 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.
+#
+# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
+# icons: Helene Durosini <ln@mandrakesoft.com>
+# <corporate@mandrakesoft.com> http://www.mandrakesoft.com
+
+# script for wizard samba configuration
+#
+# checking if the provided services are correct :
+
+
+if [ -z "${wiz_do_file_sharing}" ] ;then
+ echo_debug "wiz_do_file_sharing is empty, should not."
+ exit 1
+fi
+
+if [ -z "${wiz_do_printer_sharing}" ] ;then
+ echo_debug "wiz_do_file_sharing is empty, should not."
+ exit 1
+fi
+
+
+# all seems to be ok
+exit 10
+
diff --git a/samba_wizard/scripts/check_workgroup.sh b/samba_wizard/scripts/check_workgroup.sh
new file mode 100755
index 00000000..db70ec8b
--- /dev/null
+++ b/samba_wizard/scripts/check_workgroup.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+#
+# Wizard
+#
+# Copyright (C) 2000 Mandrakesoft.
+#
+# 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.
+# See file LICENSE for further informations on licensing terms.
+#
+# 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.
+#
+# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
+# icons: Helene Durosini <ln@mandrakesoft.com>
+# <corporate@mandrakesoft.com> http://www.mandrakesoft.com
+
+# script for wizard samba configuration
+#
+# checking if the provided server workgroup is correct :
+
+
+if [ -z "${wiz_workgroup}" ] ;then
+ echo_debug "wiz_banner is empty, should not."
+ exit 1
+fi
+
+
+# all seems to be ok
+exit 10
diff --git a/samba_wizard/scripts/do_it_samba.sh b/samba_wizard/scripts/do_it_samba.sh
new file mode 100755
index 00000000..2f3fc0be
--- /dev/null
+++ b/samba_wizard/scripts/do_it_samba.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+# Wizard
+#
+# Copyright (C) 2000 Mandrakesoft.
+#
+# 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.
+# See file LICENSE for further informations on licensing terms.
+#
+# 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.
+#
+# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
+# icons: Helene Durosini <ln@mandrakesoft.com>
+# <corporate@mandrakesoft.com> http://www.mandrakesoft.com
+
+#
+# set up the config for samba
+# assuming all dependencies are ok
+
+file=/etc/sysconfig/mdk_serv
+
+# store the variables
+
+chg_val ${file} wiz_banner ${wiz_banner} s
+chg_val ${file} wiz_workgroup ${wiz_workgroup} s
+chg_val ${file} wiz_do_printer_sharing ${wiz_do_printer_sharing} s
+chg_val ${file} wiz_do_file_sharing ${wiz_do_file_sharing} s
+
+
+ip=`get_var wiz_ip_net`
+
+
+echo_debug "printer ${wiz_do_printer_sharing}"
+echo_debug "file share ${wiz_do_file_sharing}"
+echo_debug "banner ${wiz_banner}"
+echo_debug "workgr ${wiz_workgroup}"
+
+
+# samba configuration file
+config="/etc/samba/smb.conf"
+if [ ! -f ${config} ]; then
+ echo_debug "no smb.conf configuration file found ! exiting."
+ exit 2
+fi
+
+bck_file ${config}
+
+cat ${CWD}/scripts/smb.conf.default > ${config}
+
+${CWD}/scripts/smbconfig.pl --set-hosts-allow="${ip%.*}. 127." \
+--set-workgroup="${wiz_workgroup}" --set-banner="${wiz_banner}"
+
+if [ "${wiz_do_file_sharing}" == "true" ]; then
+ echo_debug "enabling file sharing"
+ ${CWD}/scripts/smbconfig.pl --remove-homes --enable-public --set-security-share
+fi
+
+if [ "${wiz_do_printer_sharing}" == "enabled" ]; then
+ echo_debug "enabling printer access"
+ ${CWD}/scripts/smbconfig.pl --enable-printer-access
+fi
+
+
+echo_debug "restarting service smb"
+# restarting service
+#/etc/rc.d/init.d/smb restart >/dev/null 2>&1
+
+
+# exiting ok
+exit 1
diff --git a/samba_wizard/scripts/smbconfig.pl b/samba_wizard/scripts/smbconfig.pl
new file mode 100755
index 00000000..bee6d7a8
--- /dev/null
+++ b/samba_wizard/scripts/smbconfig.pl
@@ -0,0 +1,232 @@
+#!/usr/bin/perl -w
+#
+# smbconfig by Guillaume Cottenceau <gc@mandrakesoft.com>
+#
+# Copyright (c) 2000 by Mandrakesoft
+#
+# Permission to use, copy, modify, and distribute this software and its
+# documentation under the terms of the GNU General Public License is hereby
+# granted. No representations are made about the suitability of this software
+# for any purpose. It is provided "as is" without express or implied warranty.
+# See the GNU General Public License for more details.
+
+$program_name = "smbconfig";
+$version = "0.1.3";
+
+$debug_printings = 0;
+
+
+sub debug_print
+{
+ $debug_printings && print "[DEBUG] ".$_[0];
+}
+
+sub debug_print2
+{
+ $debug_printings && print $_[0];
+}
+
+
+sub fail
+{
+ die "Exiting on failure.\n";
+}
+
+
+sub fail_with_message
+{
+ print $_[0];
+ fail();
+}
+
+
+@options = ( [ "--debug", "\t\tadditional debug printings", \$debug_printings ] );
+
+@modes = ( [ "--help", "\t\tthis help screen", \&show_options ],
+ [ "--set-security-share", "setup security = share, very useful because we would need otherwise smbpasswd", \&set_security_share ],
+ [ "--set-hosts-allow=<..>", "setup which hosts are allowed to access; for example \"192.168.1. 127.\"", \&set_hosts_allow ],
+ [ "--set-workgroup=<name>", "setup workgroup name", \&set_workgroup ],
+ [ "--set-banner=<name>", "setup the \"server string\" banner of this smb server", \&set_banner ],
+ [ "--remove-homes", "\tremove the default [homes] share (which needs the security=user)", \&remove_homes ],
+ [ "--enable-public", "\tenable read-write share \"public\" at /home/local/samba-public", \&enable_corpo_public ],
+ [ "--enable-printer-access", "setup access to printers of this machine", \&set_printer_access ] );
+
+
+
+sub read_conf
+{
+ open(FH, "+< /etc/samba/smb.conf") or fail_with_message("Could not open /etc/samba/smb.conf\n");
+ @conf = <FH> or fail_with_message("Could not read /etc/samba/smb.conf\n");
+ debug_print("/etc/samba/smb.conf read, #lines=".$#conf."\n");
+}
+
+sub write_conf
+{
+ debug_print("Will write /etc/samba/smb.conf, #lines=".$#conf."\n");
+ seek(FH, 0, 0) or fail_with_message("Could not seek in /etc/samba/smb.conf\n");
+ print FH @conf or fail_with_message("Could not write /etc/samba/smb.conf\n");
+ truncate(FH, tell(FH)) or fail_with_message("Could not truncate /etc/samba/smb.conf\n");
+ close(FH) or fail_with_message("Could not close /etc/samba/smb.conf\n");
+}
+
+# set_parameter: section param value
+sub set_parameter
+{
+ my $section = $_[0]; my $param = $_[1]; my $value = $_[2];
+ debug_print("Attempt to find section \"$section\", parameter \"$param\", and setup to \"$value\"\n");
+ my $i = 0;
+ ($i++ && (lc($_) =~ /^\s*\[$section\]/) && last) foreach (@conf);
+ while (1)
+ {
+ ($i < $#conf) or ($conf[$i] = "$conf[$i]\n\n\t$param = $value") and last;
+ ($conf[$i] =~ /^\s*\[\S+\]/) && ($conf[$i] = "\t$param = $value\n\n$conf[$i]") && last;
+ ($conf[$i] =~ /^\s*$param\s*=/) && ($conf[$i] = "\t$param = $value\n") && last;
+ $i++;
+ }
+}
+
+sub enable_corpo_public
+{
+ system("mkdir -p /home/local/samba-public") && fail_with_message("Could not create public dir. Probably run as non-root..\n");
+ system("chown nobody /home/local/samba-public") && fail_with_message("Could not chown public dir to nobody. Requests admin help.\n");
+ my $i = 0;
+ ($i++ && (lc($_) =~ /^\s*\[public\]/) && fail_with_message("An active [public] section has been found in /etc/samba/smb.conf at line $i\n")) foreach (@conf);
+ push(@conf, ( "$banner"."[public]\n\tcomment = Public space with read-write access\n\tpath = /home/local/samba-public\n\tguest ok = yes\n\twriteable = yes\n" ));
+ $did_something = 1;
+}
+
+
+sub set_workgroup
+{
+ set_parameter("global", "workgroup", $_[0]);
+ $did_something = 1;
+}
+
+sub set_banner
+{
+ set_parameter("global", "server string", $_[0]);
+ $did_something = 1;
+}
+
+sub set_security_share
+{
+ set_parameter("global", "security", "share");
+ $did_something = 1;
+}
+
+sub set_hosts_allow
+{
+ set_parameter("global", "hosts allow", $_[0]);
+ $did_something = 1;
+}
+
+
+sub set_printer_access
+{
+ my $i = 0; my $found = 0;
+ # look for default section "printers"
+ ($i++ && (lc($_) =~ /^\s*\[printers\]/) && ($found = 1) && last) foreach (@conf);
+ ($found) && debug_print("Printer section found at line $i\n");
+ if ($found == 1)
+ {
+ $conf[$i-1] = ";".$conf[$i-1];
+ while ($i <= $#conf)
+ {
+ (($conf[$i] =~ /^\s*\[\S+\]/) && last) || ($conf[$i] = ";".$conf[$i]);
+ $i++;
+ }
+ debug_print("End of printer section at line $i\n");
+ }
+ push(@conf, ( "$banner"."[printers]\n\tcomment = All Printers\n\tpath = /var/spool/samba\n\tbrowseable = no\n\tguest ok = yes\n\twritable = no\n\tprintable = yes\n" ));
+ $did_something = 1;
+}
+
+sub remove_homes
+{
+ my $i = 0; my $found = 0;
+ # look for default section "printers"
+ ($i++ && (lc($_) =~ /^\s*\[homes\]/) && ($found = 1) && last) foreach (@conf);
+ ($found) && debug_print("[homes] section found at line $i\n");
+ if ($found == 1)
+ {
+ $conf[$i-1] = ";".$conf[$i-1];
+ while ($i <= $#conf)
+ {
+ (($conf[$i] =~ /^\s*\[\S+\]/) && last) || ($conf[$i] = ";".$conf[$i]);
+ $i++;
+ }
+ debug_print("End of [homes] section at line $i\n");
+ }
+ $did_something = 1;
+}
+
+
+sub show_options
+{
+ print "$program_name v$version helps auto-config of Samba.\n\n";
+
+ print "mode:\n";
+ print "\t".$_->[0]."\t\t".$_->[1]."\n" foreach (@modes);
+ print "options:\n";
+ print "\t".$_->[0]."\t\t".$_->[1]."\n" foreach (@options);
+ print "\n";
+ $did_something = 1;
+}
+
+
+sub arg_without_value
+{
+ $_[0] =~ /([^=]*)/;
+ return $1;
+}
+
+sub arg_value
+{
+ $_[0] =~ /([^=]*)=(.*)/;
+ return $2;
+}
+
+# Disable file buffering [to display strings on the tty even when no trailing \n is added]
+$| = 1;
+
+$date = `date`; chop $date;
+$host = `hostname`; chop $host;
+$banner = "\n### Autogenerated by $program_name at $date on host $host\n";
+
+$did_something = 0;
+
+
+foreach $arg (@ARGV)
+{
+ (($arg eq $_->[0]) && (${$_->[2]} = 1)) foreach (@options)
+}
+
+
+read_conf();
+
+foreach $arg (@ARGV)
+{
+ ((arg_without_value($arg) eq arg_without_value($_->[0])) && &{$_->[2]}(arg_value($arg))) foreach (@modes)
+}
+
+
+($did_something && write_conf()) || show_options();
+
+
+
+# Changelog
+#
+# 0.1.3
+# remove smb.conf end of file bug
+#
+# 0.1.2
+# added parameter support: hosts allow
+#
+# 0.1.1
+# added parameter support: server string
+# support multiple parameter sets at same time
+# added parameter support: security = share
+# added remove homes
+#
+# 0.1.0
+# first version with configure for printers, public, workgroup