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.
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.
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.
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
36
# Copyright (C) 2009 Red Hat, Inc.
37
# All rights reserved.
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");
64
$prefix = "{{DS-ROOT}}";
66
$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
68
libpath_add("$prefix@nss_libdir@");
69
libpath_add("$prefix/usr/lib");
70
libpath_add("@nss_libdir@");
71
libpath_add("/usr/lib");
73
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
78
if ("$ARGV[$i]" eq "-s")
81
$i++; $suffix_arg = $ARGV[$i];
83
elsif ("$ARGV[$i]" eq "-n")
86
$i++; $backend_arg = $ARGV[$i];
88
elsif ("$ARGV[$i]" eq "-m")
91
$i++; $maxusn_arg = $ARGV[$i];
93
elsif ("$ARGV[$i]" eq "-D")
96
$i++; $rootdn = $ARGV[$i];
98
elsif ("$ARGV[$i]" eq "-w")
100
# Directory Manager's password
101
$i++; $passwd = $ARGV[$i];
103
elsif ("$ARGV[$i]" eq "-j")
105
# Read Directory Manager's password from a file
106
$i++; $passwdfile = $ARGV[$i];
108
elsif ("$ARGV[$i]" eq "-v")
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";
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;
135
# Enable console echo
136
system("@sttyexec@ echo") if -t STDIN;
138
chop($passwd); # trim trailing newline
141
if ( $rootdn eq "" || $passwd eq "" )
153
# Use a timestamp as part of the task entry name
154
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
156
$taskname = "usn_cleanup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
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";
163
if ( $suffix_arg eq "" && $backend_arg eq "" )
168
elsif ( $suffix_arg ne "" )
170
$args = "suffix: $suffix_arg\n";
174
$args = "backend: $backend_arg\n";
177
if ( $maxusn_arg ne "" )
179
$args = $args . "maxusn_to_delete: $maxusn_arg\n";
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" );
191
if ($ENV{'LD_LIBRARY_PATH'}) {
192
$ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
194
$ENV{'LD_LIBRARY_PATH'} = "$libpath";