From 90c690eac43c4037d8c9ecc470cf36424992df71 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 4 May 2001 16:33:11 +0000 Subject: [PATCH] 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" --- examples/misc/modify_samba_config.pl | 47 ++++++++++++++++++++++++++++-------- 1 file 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 +## + +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 () { ## 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"; } -- 2.11.4.GIT