s3-selftest: include addprinter/deleteprinter command.
authorGünther Deschner <gd@samba.org>
Wed, 17 Feb 2010 23:48:58 +0000 (00:48 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 18 Feb 2010 01:27:04 +0000 (02:27 +0100)
Guenther

selftest/target/Samba3.pm
source3/script/tests/printing/modprinter.pl [new file with mode: 0755]
source3/script/tests/selftest.sh

index 0e1602231a4849a1537b40c7f9aa53e016e67514..c3f696a99db214687fda55b6742d2d8ff0fc1511 100644 (file)
@@ -436,6 +436,8 @@ sub provision($$$$$$)
        my $nss_wrapper_passwd = "$privatedir/passwd";
        my $nss_wrapper_group = "$privatedir/group";
 
+       my $mod_printer_pl = "$ENV{PERL} $RealBin/../source3/script/tests/printing/modprinter.pl";
+
        open(CONF, ">$conffile") or die("Unable to open $conffile");
        print CONF "
 [global]
@@ -469,6 +471,9 @@ sub provision($$$$$$)
        delete group script =           $nss_wrapper_pl --group_path  $nss_wrapper_group  --type group  --action delete --name %g
        delete user from group script = $nss_wrapper_pl --passwd_path $nss_wrapper_passwd --type member --action delete --member %u --name %g --group_path $nss_wrapper_group
 
+       addprinter command =            $mod_printer_pl -a -s $conffile --
+       deleteprinter command =         $mod_printer_pl -d -s $conffile --
+
        kernel oplocks = no
        kernel change notify = no
 
diff --git a/source3/script/tests/printing/modprinter.pl b/source3/script/tests/printing/modprinter.pl
new file mode 100755 (executable)
index 0000000..4064841
--- /dev/null
@@ -0,0 +1,128 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Getopt::Long;
+use Cwd qw(abs_path);
+
+my $opt_help = 0;
+my $opt_smb_conf = undef;
+my $opt_add = 0;
+my $opt_delete = 0;
+
+my $result = GetOptions(
+       'help|h|?'      => \$opt_help,
+       'smb_conf|s=s'  => \$opt_smb_conf,
+       'add|a'         => \$opt_add,
+       'delete|d'      => \$opt_delete
+);
+
+sub usage($;$)
+{
+       my ($ret, $msg) = @_;
+
+       print $msg."\n\n" if defined($msg);
+
+       print "usage:
+
+       --help|-h|-?            Show this help.
+
+       --smb_conf|-s <path>    Path of the 'smb.conf' file.
+
+       --add|-a                'add' a printer.
+       --delete|-d             'delete' a printer.
+
+       printer_name share_name port_name driver_name location XX remote_machine
+";
+       exit($ret);
+}
+
+usage(1) if (not $result);
+
+usage(0) if ($opt_help);
+
+if (!$opt_add && !$opt_delete) {
+       usage(1, "invalid: neither --add|-a nor --delete|-d set");
+}
+
+if (!$opt_smb_conf) {
+       usage(1, "invalid: no smb.conf file set");
+}
+
+my @argv = @ARGV;
+
+my $printer_name = shift(@argv);
+my $share_name = shift(@argv);
+my $port_name = shift(@argv);
+my $driver_name = shift(@argv);
+my $location = shift(@argv);
+my $win9x_driver_location = shift(@argv);
+my $remote_machine = shift(@argv);
+
+if (!defined($share_name) || length($share_name) == 0) {
+       $share_name = $printer_name;
+}
+
+if (!defined($share_name)) {
+       die "share name not defined";
+}
+
+my $tmp = $opt_smb_conf.$$;
+
+my $section = undef;
+my $within_section = 0;
+my $found_section = 0;
+
+open(CONFIGFILE_NEW, "+>$tmp") || die "Unable top open conf file $tmp";
+
+open (CONFIGFILE, "+<$opt_smb_conf") || die "Unable to open config file $opt_smb_conf";
+while (<CONFIGFILE>) {
+       my $line = $_;
+       chomp($_);
+       $_ =~ s/^\s*//;
+       $_ =~ s/\s*$//;
+       if (($_ =~ /^#/) || ($_ =~ /^;/)) {
+               print CONFIGFILE_NEW $line;
+               next;
+       }
+       if ($_ =~ /^\[.*\]$/) {
+               $_ = substr($_, 1, length($_)-2);
+               if (length($_)) {
+                       $section = $_;
+               } else {
+                       die "invalid section found";
+               }
+               if ($section eq $share_name) {
+                       $found_section = 1;
+                       if ($opt_add) {
+                               die("share $share_name already exists\n");
+                       }
+                       if ($opt_delete) {
+                               $within_section = 1;
+                               next;
+                       }
+               } else {
+                       print CONFIGFILE_NEW $line;
+                       $within_section = 0;
+               }
+               next;
+       } else {
+               if ($within_section == 1) {
+                       next;
+               }
+               print CONFIGFILE_NEW $line;
+       }
+}
+if ($opt_add) {
+       print CONFIGFILE_NEW "[$share_name]\n\tprintable = yes\n\tpath = /tmp\n";
+}
+close (CONFIGFILE);
+close (CONFIGFILE_NEW);
+
+if ($opt_delete && ($found_section == 0)) {
+       die "share $share_name not found";
+}
+system("cp", "$tmp", "$opt_smb_conf");
+unlink $tmp;
+
+exit 0;
index b9c11b8f50bf1ea57f8cbaf6e64a68d9cd5d57e4..e6e3c2915bb402f3ca0f60e8fbaa21cc6a721bd9 100755 (executable)
@@ -236,6 +236,9 @@ cat >$SERVERCONFFILE<<EOF
        delete group script =           $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type group  --action delete --name %g
        delete user from group script = $PERL $SRCDIR/../lib/nss_wrapper/nss_wrapper.pl --group_path  $NSS_WRAPPER_GROUP  --type member --action delete --name %g --member %u --passwd_path $NSS_WRAPPER_PASSWD
 
+       addprinter command =            $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -a -s $SERVERCONFFILE --
+       deleteprinter command =         $PERL $SRCDIR/../source3/script/tests/printing/modprinter.pl -d -s $SERVERCONFFILE --
+
        kernel oplocks = no
        kernel change notify = no