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) 2001 Sun Microsystems, Inc. Used by permission.
37
# Copyright (C) 2013 Red Hat, Inc.
38
# All rights reserved.
42
use lib qw(@perlpath@);
45
DSUtil::libpath_add("@nss_libdir@");
46
DSUtil::libpath_add("/usr/lib");
47
DSUtil::libpath_add("/usr/lib64");
48
$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:/usr/lib64/mozldap/";
49
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
54
print(STDERR "Usage: fixup-memberof.pl [-Z serverID] [-D rootdn] { -w password | -w - | -j filename }\n");
55
print(STDERR " [-P protocol] -b baseDN [-f filter] [-v] [-h]\n");
56
print(STDERR "Options:\n");
57
print(STDERR " -D rootdn - Directory Manager\n");
58
print(STDERR " -w password - Directory Manager's password\n");
59
print(STDERR " -w - - Prompt for Directory Manager's password\n");
60
print(STDERR " -Z serverID - Server instance identifier\n");
61
print(STDERR " -j filename - Read Directory Manager's password from file\n");
62
print(STDERR " -b baseDN - Base DN that contains entries to fix up.\n");
63
print(STDERR " -f filter - Filter for entries to fix up\n");
64
print(STDERR " If omitted, all entries with objectclass inetuser/inetadmin under the\n");
65
print(STDERR " specified base will have their memberOf attribute regenerated.\n");
66
print(STDERR " -P protocol - STARTTLS, LDAPS, LDAPI, LDAP (default: uses most secure protocol available)\n");
67
print(STDERR " -v - Verbose output\n");
68
print(STDERR " -h - Display usage\n");
73
if ("$ARGV[$i]" eq "-b"){
75
$i++; $basedn_arg = $ARGV[$i];
76
} elsif ("$ARGV[$i]" eq "-f"){
78
$i++; $filter_arg = $ARGV[$i];
79
} elsif ("$ARGV[$i]" eq "-D"){
81
$i++; $rootdn = $ARGV[$i];
82
} elsif ("$ARGV[$i]" eq "-w"){
83
# Directory Manager's password
84
$i++; $passwd = $ARGV[$i];
85
} elsif ("$ARGV[$i]" eq "-j"){
86
# Read Directory Manager's password from a file
87
$i++; $passwdfile = $ARGV[$i];
88
} elsif ("$ARGV[$i]" eq "-Z"){
89
# server instance identifier
90
$i++; $servid = $ARGV[$i];
91
} elsif ("$ARGV[$i]" eq "-P"){
93
$i++; $protocol = $ARGV[$i];
94
} elsif ("$ARGV[$i]" eq "-h"){
97
} elsif ("$ARGV[$i]" eq "-v"){
107
# Gather all our config settings
109
($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
110
%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
111
$info{rootdnpw} = DSUtil::get_password_from_file($passwd, $passwdfile);
112
$info[9] = $protocol;
114
$info{args} = "-v -a";
118
if ( $basedn_arg eq "" ){
124
# Construct the task entry
126
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
128
$taskname = "memberOf_fixup_${yr}_${mn}_${dy}_${h}_${m}_${s}";
129
$dn = "dn: cn=$taskname, cn=memberOf task, cn=tasks, cn=config\n";
130
$misc = "objectclass: top\nobjectclass: extensibleObject\n";
131
$cn = "cn: $taskname\n";
132
$basedn = "basedn: $basedn_arg\n";
133
if ( $filter_arg ne "" )
135
$filter = "filter: $filter_arg\n";
138
$entry = "${dn}${misc}${cn}${basedn}${filter}";
139
$rc = DSUtil::ldapmod($entry, %info);
144
print "Successfully added task entry \"$dn\"\n";
146
print "Failed to add task entry \"$dn\" error ($rc)\n";