6 # create single or continuously numbered domain
7 # users/groups/aliases via rpc
9 # Copyright (C) Michael Adam <obnox@samba.org> 2007
11 # This program is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by the Free
13 # Software Foundation; either version 3 of the License, or (at your option)
16 # This program is distributed in the hope that it will be useful, but WITHOUT
17 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 # You should have received a copy of the GNU General Public License along with
22 # this program; if not, see <http://www.gnu.org/licenses/>.
26 # WARNING: This script is still rather crude.
33 my $target_type = "group"; # what type of object to create
34 my $rpc_cmd = "createdom".$target_type;
35 my $rpccli_cmd = "rpcclient";
41 my $startnum; # if empty, don't add numbers to prefix
42 my $prefix; # name-prefix
43 my $path; # path to rpcclient command
44 my $rpccli_path = $rpccli_cmd;
48 print "USAGE: $0 [-h] -S server -U user\%pass [-p prefix] \\\n"
49 . "\t[-t {alias|group|user}] [-s startnum] [-n numobjs] [-P path] \n";
55 getopts
("U:t:S:s:n:p:P:h", \
%options);
57 if (exists($options{h
})) {
62 if (exists($options{t
})) {
63 $target_type = $options{t
};
64 if ($target_type !~ /^(alias|user|group)$/) {
65 print "ERROR: invalid target type given\n";
69 $rpc_cmd = "createdom".$target_type;
72 if (exists($options{U
})) {
73 $creds = "-U $options{U}";
75 print "ERROR: you need to specify credentials in the form -U user\%pass\n";
81 print "ERROR: mandatory argument '-U' missing\n";
86 if (exists($options{S
})) {
87 $server = $options{S
};
90 print "ERROR: madatory argument '-S' missing\n";
95 if (exists($options{s
})) {
96 $startnum = $options{s
};
99 if (exists($options{n
})) {
100 $num_targets = $options{n
};
103 if (exists($options{p
})) {
104 $prefix = $options{p
};
106 $prefix = $target_type;
109 if (exists($options{P
})) {
111 $rpccli_path = "$path/$rpccli_cmd";
115 print "ERROR: junk on the command line ('" . join(" ", @ARGV) . "')...\n";
123 print "opening rpc pipe\n";
124 open(IPC
, "| $rpccli_cmd $server $creds -d0") or
125 die "error opening rpc pipe.";
129 print "closing rpc pipe\n";
134 my $target_name = shift;
135 print "creating $target_type $target_name\n";
136 print IPC
"$rpc_cmd $target_name\n";
143 if ("x$startnum" eq "x") {
147 for (my $num = 1; $num <= $num_targets; ++$num) {
148 do_create
(sprintf "%s%.05d", $prefix, $startnum + $num - 1);
149 if (($num) % 500 == 0) {
150 printf("500 ".$target_type."s created\n");