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

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/template-usn-tombstone-cleanup.pl.in

  • Committer: Package Import Robot
  • Author(s): Krzysztof Klimonda
  • Date: 2012-03-27 14:26:16 UTC
  • Revision ID: package-import@ubuntu.com-20120327142616-xt24t6nffm3f7ybz
Tags: upstream-1.2.11.7
ImportĀ upstreamĀ versionĀ 1.2.11.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#{{PERL-EXEC}}
 
2
#
 
3
# BEGIN COPYRIGHT BLOCK
 
4
# This Program is free software; you can redistribute it and/or modify it under
 
5
# the terms of the GNU General Public License as published by the Free Software
 
6
# Foundation; version 2 of the License.
 
7
 
8
# This Program is distributed in the hope that it will be useful, but WITHOUT
 
9
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
10
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 
11
 
12
# You should have received a copy of the GNU General Public License along with
 
13
# this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
14
# Place, Suite 330, Boston, MA 02111-1307 USA.
 
15
 
16
# In addition, as a special exception, Red Hat, Inc. gives You the additional
 
17
# right to link the code of this Program with code not covered under the GNU
 
18
# General Public License ("Non-GPL Code") and to distribute linked combinations
 
19
# including the two, subject to the limitations in this paragraph. Non-GPL Code
 
20
# permitted under this exception must only link to the code of this Program
 
21
# through those well defined interfaces identified in the file named EXCEPTION
 
22
# found in the source code files (the "Approved Interfaces"). The files of
 
23
# Non-GPL Code may instantiate templates or use macros or inline functions from
 
24
# the Approved Interfaces without causing the resulting work to be covered by
 
25
# the GNU General Public License. Only Red Hat, Inc. may make changes or
 
26
# additions to the list of Approved Interfaces. You must obey the GNU General
 
27
# Public License in all respects for all of the Program code and other code used
 
28
# in conjunction with the Program except the Non-GPL Code covered by this
 
29
# exception. If you modify this file, you may extend this exception to your
 
30
# version of the file, but you are not obligated to do so. If you do not wish to
 
31
# provide this exception without modification, you must delete this exception
 
32
# statement from your version and license this file solely under the GPL without
 
33
# exception. 
 
34
 
35
 
36
# Copyright (C) 2009 Red Hat, Inc.
 
37
# All rights reserved.
 
38
# END COPYRIGHT BLOCK
 
39
#
 
40
 
 
41
sub usage {
 
42
    print(STDERR "Usage: $0 [-v] -D rootdn { -w password | -w - | -j filename } -s suffix | -n backend [ -m maxusn_to_delete ]\n");
 
43
    print(STDERR " Opts: -D rootdn           - Directory Manager\n");
 
44
    print(STDERR "     : -w password         - Directory Manager's password\n");
 
45
    print(STDERR "     : -w -                - Prompt for Directory Manager's password\n");
 
46
    print(STDERR "     : -j filename         - Read Directory Manager's password from file\n");
 
47
    print(STDERR "     : -s suffix           - Suffix where USN tombstone entries are cleaned up\n");
 
48
    print(STDERR "     : -n backend          - Backend instance in which USN tombstone entries \n");
 
49
        print(STDERR "                             are cleaned up (alternative to suffix)\n");
 
50
    print(STDERR "     : -m maxusn_to_delete - USN tombstone entries are deleted up to \n");
 
51
    print(STDERR "                             the entry with maxusn_to_delete\n");
 
52
    print(STDERR "     : -v                  - verbose\n");
 
53
}
 
54
 
 
55
$rootdn = "";
 
56
$passwd = "";
 
57
$passwdfile = "";
 
58
$args = "";
 
59
$suffix_arg = "";
 
60
$backend_arg = "";
 
61
$maxusn_arg = "";
 
62
$verbose = 0;
 
63
 
 
64
$prefix = "{{DS-ROOT}}";
 
65
 
 
66
$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
 
67
 
 
68
libpath_add("$prefix@nss_libdir@");
 
69
libpath_add("$prefix/usr/lib");
 
70
libpath_add("@nss_libdir@");
 
71
libpath_add("/usr/lib");
 
72
 
 
73
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
74
 
 
75
$i = 0;
 
76
while ($i <= $#ARGV) 
 
77
{
 
78
    if ("$ARGV[$i]" eq "-s")
 
79
    {
 
80
        # suffix
 
81
        $i++; $suffix_arg = $ARGV[$i];
 
82
    }
 
83
    elsif ("$ARGV[$i]" eq "-n")
 
84
    {
 
85
        # backend
 
86
        $i++; $backend_arg = $ARGV[$i];
 
87
    }
 
88
    elsif ("$ARGV[$i]" eq "-m")
 
89
    {
 
90
        # max usn
 
91
        $i++; $maxusn_arg = $ARGV[$i];
 
92
    }
 
93
    elsif ("$ARGV[$i]" eq "-D") 
 
94
    {    
 
95
        # Directory Manager
 
96
        $i++; $rootdn = $ARGV[$i];
 
97
    }
 
98
    elsif ("$ARGV[$i]" eq "-w") 
 
99
    {    
 
100
        # Directory Manager's password
 
101
        $i++; $passwd = $ARGV[$i];
 
102
    } 
 
103
    elsif ("$ARGV[$i]" eq "-j")
 
104
    {
 
105
         # Read Directory Manager's password from a file
 
106
        $i++; $passwdfile = $ARGV[$i];
 
107
    }
 
108
    elsif ("$ARGV[$i]" eq "-v") 
 
109
    {    
 
110
        # verbose
 
111
        $verbose = 1;
 
112
    }
 
113
    else
 
114
    {
 
115
        &usage; exit(1);
 
116
    }
 
117
    $i++;
 
118
}
 
119
 
 
120
if ($passwdfile ne ""){
 
121
# Open file and get the password
 
122
    unless (open (RPASS, $passwdfile)) {
 
123
        die "Error, cannot open password file $passwdfile\n";
 
124
    }
 
125
    $passwd = <RPASS>;
 
126
    chomp($passwd);
 
127
    close(RPASS);
 
128
} elsif ($passwd eq "-"){
 
129
# Read the password from terminal
 
130
        print "Bind Password: ";
 
131
        # Disable console echo
 
132
        system("@sttyexec@ -echo") if -t STDIN;
 
133
        # read the answer
 
134
        $passwd = <STDIN>;
 
135
        # Enable console echo
 
136
        system("@sttyexec@ echo") if -t STDIN;
 
137
        print "\n";
 
138
        chop($passwd); # trim trailing newline
 
139
}
 
140
 
 
141
if ( $rootdn eq "" || $passwd eq "" )
 
142
 
143
    &usage; 
 
144
    exit(1); 
 
145
}
 
146
 
 
147
$vstr = "";
 
148
if ($verbose != 0) 
 
149
 
150
    $vstr = "-v"; 
 
151
}
 
152
 
 
153
# Use a timestamp as part of the task entry name
 
154
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 
155
$mn++; $yr += 1900;
 
156
$taskname = "usn_cleanup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
 
157
 
 
158
# Build the task entry to add
 
159
$dn = "dn: cn=$taskname, cn=USN tombstone cleanup task, cn=tasks, cn=config\n";
 
160
$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
 
161
$cn =  "cn: $taskname\n";
 
162
 
 
163
if ( $suffix_arg eq "" && $backend_arg eq "" )
 
164
{
 
165
    &usage; 
 
166
    exit(1); 
 
167
}
 
168
elsif ( $suffix_arg ne "" )
 
169
{
 
170
    $args = "suffix: $suffix_arg\n";
 
171
}
 
172
else
 
173
{
 
174
    $args = "backend: $backend_arg\n";
 
175
}
 
176
 
 
177
if ( $maxusn_arg ne "" )
 
178
{
 
179
    $args = $args . "maxusn_to_delete: $maxusn_arg\n";
 
180
}
 
181
 
 
182
$entry = "${dn}${misc}${cn}${basedn}${args}";
 
183
open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
 
184
print(FOO "$entry");
 
185
close(FOO);
 
186
 
 
187
sub libpath_add {
 
188
    my $libpath = shift;
 
189
 
 
190
    if ($libpath) {
 
191
        if ($ENV{'LD_LIBRARY_PATH'}) {
 
192
            $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
 
193
        } else {
 
194
            $ENV{'LD_LIBRARY_PATH'} = "$libpath";
 
195
        }
 
196
    }
 
197
}