~ubuntu-branches/ubuntu/trusty/389-ds-base/trusty

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/template-cleanallruv.pl.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-08-30 00:31:55 UTC
  • mfrom: (1.2.1)
  • Revision ID: package-import@ubuntu.com-20130830003155-oimuzdqopkvp2cd0
Tags: 1.3.1.7-0ubuntu1
Sync from unreleased debian git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
35
35
36
36
# Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
37
 
# Copyright (C) 2012 Red Hat, Inc.
 
37
# Copyright (C) 2013 Red Hat, Inc.
38
38
# All rights reserved.
39
39
# END COPYRIGHT BLOCK
40
40
#
41
41
 
42
 
sub usage {
43
 
    print(STDERR "Usage: $0 [-v] -D rootdn { -w password | -w - | -j filename } \n");
44
 
    print(STDERR "        [-b basedn | -r rid | -A]\n");
45
 
    print(STDERR " Opts: -D rootdn           - Directory Manager\n");
46
 
    print(STDERR "     : -w password         - Directory Manager's password\n");
47
 
    print(STDERR "     : -w -                - Prompt for Directory Manager's password\n");
48
 
    print(STDERR "     : -j filename         - Read Directory Manager's password from file\n");
49
 
    print(STDERR "     : -b basedn           - DN of the replica root you want to clean\n");
50
 
    print(STDERR "     : -r rid              - The replica id that you want to clean\n");
51
 
    print(STDERR "     : -A                  - Abort an existing cleanallruv task(must use with -b and -r args\n");
52
 
    print(STDERR "     : -v                  - verbose\n");
53
 
}
54
 
 
55
 
$rootdn = "";
56
 
$passwd = "";
57
 
$passwdfile = "";
58
 
$basedn = "";
59
 
$rid = "";
60
 
$abort = "";
61
 
$verbose = 0;
62
 
 
63
 
$prefix = "{{DS-ROOT}}";
64
 
 
65
 
$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
66
 
 
67
 
libpath_add("$prefix@nss_libdir@");
68
 
libpath_add("$prefix/usr/lib");
69
 
libpath_add("@nss_libdir@");
70
 
libpath_add("/usr/lib");
71
 
 
72
 
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
73
 
 
74
 
$i = 0;
75
 
while ($i <= $#ARGV) 
76
 
{
77
 
    if ("$ARGV[$i]" eq "-b")
78
 
    {
79
 
        # Base DN
80
 
        $i++; $basedn = $ARGV[$i];
81
 
    }
82
 
    elsif ("$ARGV[$i]" eq "-r")
83
 
    {
84
 
        # rid
85
 
        $i++; $rid = $ARGV[$i];
86
 
    }
87
 
    elsif ("$ARGV[$i]" eq "-A")
88
 
    {
89
 
        # abort
90
 
        $abort = "yes";
91
 
    }
92
 
    elsif ("$ARGV[$i]" eq "-D") 
93
 
    {    
94
 
        # Directory Manager
95
 
        $i++; $rootdn = $ARGV[$i];
96
 
    }
97
 
    elsif ("$ARGV[$i]" eq "-w") 
98
 
    {    
99
 
        # Directory Manager's password
100
 
        $i++; $passwd = $ARGV[$i];
101
 
    } 
102
 
    elsif ("$ARGV[$i]" eq "-j")
103
 
    {
104
 
         # Read Directory Manager's password from a file
105
 
        $i++; $passwdfile = $ARGV[$i];
106
 
    }
107
 
    elsif ("$ARGV[$i]" eq "-v") 
108
 
    {    
109
 
        # verbose
110
 
        $verbose = 1;
111
 
    }
112
 
    else
113
 
    {
114
 
        &usage; exit(1);
115
 
    }
116
 
    $i++;
117
 
}
118
 
 
119
 
if ($passwdfile ne ""){
120
 
# Open file and get the password
121
 
    unless (open (RPASS, $passwdfile)) {
122
 
        die "Error, cannot open password file $passwdfile\n";
123
 
    }
124
 
    $passwd = <RPASS>;
125
 
    chomp($passwd);
126
 
    close(RPASS);
127
 
} elsif ($passwd eq "-"){
128
 
# Read the password from terminal
129
 
    print "Bind Password: ";
130
 
    # Disable console echo
131
 
    system("@sttyexec@ -echo") if -t STDIN;
132
 
    # read the answer
133
 
    $passwd = <STDIN>;
134
 
    # Enable console echo
135
 
    system("@sttyexec@ echo") if -t STDIN;
136
 
    print "\n";
137
 
    chop($passwd); # trim trailing newline
138
 
}
139
 
 
140
 
if ( $rootdn eq "" || $passwd eq "" || $basedn eq "" || $rid eq "") 
141
 
142
 
    &usage; 
143
 
    exit(1); 
144
 
}
145
 
 
146
 
$vstr = "";
147
 
if ($verbose != 0) 
148
 
149
 
    $vstr = "-v"; 
150
 
}
151
 
 
152
 
# Use a timestamp as part of the task entry name
153
 
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
154
 
$mn++; $yr += 1900;
155
 
 
156
 
if($abort eq ""){
157
 
    # Build the task entry to add
158
 
    $taskname = "cleanallruv_${yr}_${mn}_${dy}_${h}_${m}_${s}";
159
 
    $dn = "dn: cn=$taskname, cn=cleanallruv, cn=tasks, cn=config\n";
160
 
} else {
161
 
    $taskname = "abort_cleanallruv_${yr}_${mn}_${dy}_${h}_${m}_${s}";
162
 
    $dn = "dn: cn=$taskname, cn=abort cleanallruv, cn=tasks, cn=config\n";
163
 
}    
164
 
$misc =   "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
165
 
$cn =     "cn: $taskname\n";
166
 
$basedn = "replica-base-dn: $basedn\n";
167
 
$rid =    "replica-id: $rid\n";
168
 
 
169
 
 
170
 
$entry = "${dn}${misc}${cn}${basedn}${rid}";
171
 
open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
172
 
print(FOO "$entry");
173
 
close(FOO);
174
 
 
175
 
sub libpath_add {
176
 
    my $libpath = shift;
177
 
 
178
 
    if ($libpath) {
179
 
        if ($ENV{'LD_LIBRARY_PATH'}) {
180
 
            $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
 
42
# We lose args that are quoted when passing ARGV to a wrapper
 
43
while ($i <= $#ARGV) {
 
44
        if($ARGV[$i] =~ /^-/){
 
45
                $wrapperArgs[$i] = $ARGV[$i];
181
46
        } else {
182
 
            $ENV{'LD_LIBRARY_PATH'} = "$libpath";
 
47
                $wrapperArgs[$i] = "\"$ARGV[$i]\"";
183
48
        }
184
 
    }
 
49
        $i++;
185
50
}
186
51
 
 
52
exec "{{SERVERBIN-DIR}}/cleanallruv.pl @wrapperArgs -Z {{SERV-ID}}"
 
53
 
 
54
exit ($?);
 
 
b'\\ No newline at end of file'