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 2 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, write to the Free Software Foundation, Inc., 675
23 # Mass Ave, Cambridge, MA 02139, USA.
27 # WARNING: This script is still rather crude.
34 my $target_type = "group"; # what type of object to create
35 my $rpc_cmd = "createdom".$target_type;
36 my $rpccli_cmd = "rpcclient";
42 my $startnum; # if empty, don't add numbers to prefix
43 my $prefix = $target_type; # name-prefix
44 my $path; # path to rpcclient command
45 my $rpccli_path = $rpccli_cmd;
49 print "USAGE: $0 [-h] -S server -U user\%pass [-p prefix] \\\n"
50 . "\t[-t {alias|group|user}] [-s startnum] [-n numobjs] [-P path] \n";
56 getopts("U:t:S:s:n:p:P:h", \%options);
58 if (exists($options{h})) {
63 if (exists($options{t})) {
64 $target_type = $options{t};
65 if ($target_type !~ /^(alias|user|group)$/) {
66 print "ERROR: invalid target type given\n";
70 $rpc_cmd = "createdom".$target_type;
73 if (exists($options{U})) {
74 $creds = "-U $options{U}";
76 print "ERROR: you need to specify credentials in the form -U user\%pass\n";
82 print "ERROR: mandatory argument '-U' missing\n";
87 if (exists($options{S})) {
88 $server = $options{S};
91 print "ERROR: madatory argument '-S' missing\n";
96 if (exists($options{s})) {
97 $startnum = $options{s};
100 if (exists($options{n})) {
101 $num_targets = $options{n};
104 if (exists($options{p})) {
105 $prefix = $options{p};
108 if (exists($options{P})) {
110 $rpccli_path = "$path/$rpccli_cmd";
114 print "ERROR: junk on the command line ('" . join(" ", @ARGV) . "')...\n";
122 print "opening rpc pipe\n";
123 open(IPC, "| $rpccli_cmd $server $creds -d0") or
124 die "error opening rpc pipe.";
128 print "closing rpc pipe\n";
133 my $target_name = shift;
134 print "creating $target_type $target_name\n";
135 print IPC "$rpc_cmd $target_name\n";
142 if ("x$startnum" eq "x") {
146 for (my $num = 1; $num <= $num_targets; ++$num) {
147 do_create(sprintf "%s%.05d", $prefix, $startnum + $num - 1);
148 if (($num) % 500 == 0) {
149 printf("500 ".$target_type."s created\n");