summaryrefslogtreecommitdiff
path: root/source3/script
diff options
context:
space:
mode:
Diffstat (limited to 'source3/script')
-rwxr-xr-xsource3/script/tests/printing/modprinter.pl128
-rwxr-xr-xsource3/script/tests/selftest.sh3
2 files changed, 131 insertions, 0 deletions
diff --git a/source3/script/tests/printing/modprinter.pl b/source3/script/tests/printing/modprinter.pl
new file mode 100755
index 0000000000..406484188d
--- /dev/null
+++ b/source3/script/tests/printing/modprinter.pl
@@ -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;
diff --git a/source3/script/tests/selftest.sh b/source3/script/tests/selftest.sh
index b9c11b8f50..e6e3c2915b 100755
--- a/source3/script/tests/selftest.sh
+++ b/source3/script/tests/selftest.sh
@@ -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