~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source3/script/tests/printing/modprinter.pl

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
use strict;
 
4
 
 
5
use Getopt::Long;
 
6
use Cwd qw(abs_path);
 
7
 
 
8
my $opt_help = 0;
 
9
my $opt_smb_conf = undef;
 
10
my $opt_add = 0;
 
11
my $opt_delete = 0;
 
12
 
 
13
my $result = GetOptions(
 
14
        'help|h|?'      => \$opt_help,
 
15
        'smb_conf|s=s'  => \$opt_smb_conf,
 
16
        'add|a'         => \$opt_add,
 
17
        'delete|d'      => \$opt_delete
 
18
);
 
19
 
 
20
sub usage($;$)
 
21
{
 
22
        my ($ret, $msg) = @_;
 
23
 
 
24
        print $msg."\n\n" if defined($msg);
 
25
 
 
26
        print "usage:
 
27
 
 
28
        --help|-h|-?            Show this help.
 
29
 
 
30
        --smb_conf|-s <path>    Path of the 'smb.conf' file.
 
31
 
 
32
        --add|-a                'add' a printer.
 
33
        --delete|-d             'delete' a printer.
 
34
 
 
35
        printer_name share_name port_name driver_name location XX remote_machine
 
36
";
 
37
        exit($ret);
 
38
}
 
39
 
 
40
usage(1) if (not $result);
 
41
 
 
42
usage(0) if ($opt_help);
 
43
 
 
44
if (!$opt_add && !$opt_delete) {
 
45
        usage(1, "invalid: neither --add|-a nor --delete|-d set");
 
46
}
 
47
 
 
48
if (!$opt_smb_conf) {
 
49
        usage(1, "invalid: no smb.conf file set");
 
50
}
 
51
 
 
52
my @argv = @ARGV;
 
53
 
 
54
my $printer_name = shift(@argv);
 
55
my $share_name = shift(@argv);
 
56
my $port_name = shift(@argv);
 
57
my $driver_name = shift(@argv);
 
58
my $location = shift(@argv);
 
59
my $win9x_driver_location = shift(@argv);
 
60
my $remote_machine = shift(@argv);
 
61
 
 
62
if (!defined($share_name) || length($share_name) == 0) {
 
63
        $share_name = $printer_name;
 
64
}
 
65
 
 
66
if (!defined($share_name)) {
 
67
        die "share name not defined";
 
68
}
 
69
 
 
70
my $tmp = $opt_smb_conf.$$;
 
71
 
 
72
my $section = undef;
 
73
my $within_section = 0;
 
74
my $found_section = 0;
 
75
 
 
76
open(CONFIGFILE_NEW, "+>$tmp") || die "Unable top open conf file $tmp";
 
77
 
 
78
open (CONFIGFILE, "+<$opt_smb_conf") || die "Unable to open config file $opt_smb_conf";
 
79
while (<CONFIGFILE>) {
 
80
        my $line = $_;
 
81
        chomp($_);
 
82
        $_ =~ s/^\s*//;
 
83
        $_ =~ s/\s*$//;
 
84
        if (($_ =~ /^#/) || ($_ =~ /^;/)) {
 
85
                print CONFIGFILE_NEW $line;
 
86
                next;
 
87
        }
 
88
        if ($_ =~ /^\[.*\]$/) {
 
89
                $_ = substr($_, 1, length($_)-2);
 
90
                if (length($_)) {
 
91
                        $section = $_;
 
92
                } else {
 
93
                        die "invalid section found";
 
94
                }
 
95
                if ($section eq $share_name) {
 
96
                        $found_section = 1;
 
97
                        if ($opt_add) {
 
98
                                exit 0;
 
99
#                               die("share $share_name already exists\n");
 
100
                        }
 
101
                        if ($opt_delete) {
 
102
                                $within_section = 1;
 
103
                                next;
 
104
                        }
 
105
                } else {
 
106
                        print CONFIGFILE_NEW $line;
 
107
                        $within_section = 0;
 
108
                }
 
109
                next;
 
110
        } else {
 
111
                if ($within_section == 1) {
 
112
                        next;
 
113
                }
 
114
                print CONFIGFILE_NEW $line;
 
115
        }
 
116
}
 
117
if ($opt_add) {
 
118
        print CONFIGFILE_NEW "[$share_name]\n\tprintable = yes\n\tpath = /tmp\n";
 
119
}
 
120
close (CONFIGFILE);
 
121
close (CONFIGFILE_NEW);
 
122
 
 
123
if ($opt_delete && ($found_section == 0)) {
 
124
        die "share $share_name not found";
 
125
}
 
126
system("cp", "$tmp", "$opt_smb_conf");
 
127
unlink $tmp;
 
128
 
 
129
exit 0;