summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2001-05-04 16:33:11 +0000
committerGerald Carter <jerry@samba.org>2001-05-04 16:33:11 +0000
commit90c690eac43c4037d8c9ecc470cf36424992df71 (patch)
tree583ed0461d1f8f57a54df7615c91412420486bdc /examples
parentc6b7455764f5b5f9491bc22a6f70f794f2668fd5 (diff)
downloadsamba-90c690eac43c4037d8c9ecc470cf36424992df71.tar.gz
samba-90c690eac43c4037d8c9ecc470cf36424992df71.tar.xz
samba-90c690eac43c4037d8c9ecc470cf36424992df71.zip
this now works as a add|delete share command :-)
It rewrites smb.conf and all the spaces have been stripped from the parameter names. I can fix this using a table lookup, but I don;t have time to put all the smb.conf parameters in to a table right now. It is "proof of concept"
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/misc/modify_samba_config.pl47
1 files changed, 37 insertions, 10 deletions
diff --git a/examples/misc/modify_samba_config.pl b/examples/misc/modify_samba_config.pl
index df03ee52741..c9f2c33b480 100755
--- a/examples/misc/modify_samba_config.pl
+++ b/examples/misc/modify_samba_config.pl
@@ -1,10 +1,21 @@
#!/usr/bin/perl
##
+## Simple example of how to implement a '[add|delete] share command' for
+## use with the Windows NT Server Manager. See smb.conf(5) for details
+## on the '[add|delete] share command'
+##
+## Author : Gerald (Jerry) Carter <jerry@samba.org>
+##
+
+use POSIX qw(tmpnam);
+
+##
## local variables
##
my $delete_mode = undef;
my $add_mode = undef;
+my $tmp_file_name = undef;
## check for correct parameters
@@ -66,6 +77,7 @@ while (<CONFIGFILE>) {
## should have a hash of hashes indexed by section name
}
+close (CONFIGFILE);
##
## We have the smb.conf in our hash of hashes now.
@@ -82,7 +94,21 @@ elsif ($delete_mode) {
##
## Print the resulting configuration
##
-PrintConfigFile();
+#do {
+# $tmp_file_name = tmpnam();
+# print "Using temporary file - $tmp_file_name\n";
+#} while (!sysopen(TMP, $tmp_file_name, O_RDWR|O_CREAT|O_EXCL));
+$tmp_file_name = tmpnam();
+open (TMP, ">$tmp_file_name") || die "Unable to open temporary file for writing!\n";
+
+PrintConfigFile(TMP);
+
+## now overwrite the original config file
+close (TMP);
+system ("cp -pf $ARGV[0] $ARGV[0].bak");
+system ("cp -pf $tmp_file_name $ARGV[0]");
+unlink $tmp_file_name;
+
exit 0;
@@ -94,33 +120,34 @@ exit 0;
## PrintConfigFile()
##
sub PrintConfigFile {
+ my ($output) = @_;
## print the file back out, beginning with the global section
- print "#\n# Generated by $0\n#\n";
+ print $output "#\n# Generated by $0\n#\n";
- PrintSection ('global', $config{'global'});
+ PrintSection ($output, 'global', $config{'global'});
foreach $section (keys %config) {
if ("$section" ne "global") {
- print "## Section - [$section]\n";
- PrintSection ($section, $config{$section});
+ print $output "## Section - [$section]\n";
+ PrintSection ($output, $section, $config{$section});
}
}
- print "#\n# end of generated smb.conf\n#\n";
+ print $output "#\n# end of generated smb.conf\n#\n";
}
#######################################################################################
## PrintSection()
##
sub PrintSection {
- my ($name, $section) = @_;
+ my ($outfile, $name, $section) = @_;
- print "[$name]\n";
+ print $outfile "[$name]\n";
foreach $param (keys %$section) {
- print "\t$param".' 'x(25-length($param)). " = $$section{$param}\n";
+ print $outfile "\t$param".' 'x(25-length($param)). " = $$section{$param}\n";
}
- print "\n";
+ print $outfile "\n";
}