~ubuntu-branches/ubuntu/utopic/389-ds-base/utopic-proposed

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/fixup-memberof.pl.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2014-02-03 11:08:50 UTC
  • mfrom: (0.2.1)
  • Revision ID: package-import@ubuntu.com-20140203110850-tjzx85elnke9fiu3
Tags: 1.3.2.9-1
* New upstream release.
  - fixes CVE-2013-0336 (Closes: #704077)
  - fixes CVE-2013-1897 (Closes: #704421)
  - fixes CVE-2013-2219 (Closes: #718325)
  - fixes CVE-2013-4283 (Closes: #721222)
  - fixes CVE-2013-4485 (Closes: #730115)
* Drop fix-CVE-2013-0312.diff, upstream.
* rules: Add new scripts to rename.
* fix-sasl-path.diff: Use a triplet path to find libsasl2. (LP:
  #1088822)
* admin_scripts.diff: Add patch from upstream #47511 to fix bashisms.
* control: Add ldap-utils to -base depends.
* rules, rename-online-scripts.diff: Some scripts with .pl suffix are
  meant for an online server, so instead of overwriting the offline
  scripts use -online suffix.
* rules: Enable parallel build, but limit the jobs to 1 for
  dh_auto_install.
* control: Bump policy to 3.9.5, no changes.
* rules: Add get-orig-source target.
* lintian-overrides: Drop obsolete entries, add comments for the rest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!@perlexec@
 
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) 2001 Sun Microsystems, Inc. Used by permission.
 
37
# Copyright (C) 2013 Red Hat, Inc.
 
38
# All rights reserved.
 
39
# END COPYRIGHT BLOCK
 
40
#
 
41
 
 
42
use lib qw(@perlpath@);
 
43
use DSUtil;
 
44
 
 
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'}";
 
50
 
 
51
$i = 0;
 
52
 
 
53
sub usage {
 
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");
 
69
}
 
70
 
 
71
while ($i <= $#ARGV) 
 
72
{
 
73
    if ("$ARGV[$i]" eq "-b"){
 
74
        # base DN
 
75
        $i++; $basedn_arg = $ARGV[$i];
 
76
    } elsif ("$ARGV[$i]" eq "-f"){    
 
77
        # filter 
 
78
        $i++; $filter_arg = $ARGV[$i];
 
79
    } elsif ("$ARGV[$i]" eq "-D"){    
 
80
        # Directory Manager
 
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"){ 
 
92
        # protocol preference
 
93
        $i++; $protocol = $ARGV[$i];
 
94
    } elsif ("$ARGV[$i]" eq "-h"){ 
 
95
        # help
 
96
        &usage; exit(0);
 
97
    } elsif ("$ARGV[$i]" eq "-v"){    
 
98
        # verbose
 
99
        $verbose = 1;
 
100
    } else {
 
101
        &usage; exit(1);
 
102
    }
 
103
    $i++;
 
104
}
 
105
 
 
106
#
 
107
# Gather all our config settings
 
108
#
 
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;
 
113
if ($verbose == 1){
 
114
    $info{args} = "-v -a";
 
115
} else {
 
116
    $info{args} = "-a";
 
117
}
 
118
if ( $basedn_arg eq "" ){ 
 
119
    &usage; 
 
120
    exit(1); 
 
121
}
 
122
 
 
123
 
124
# Construct the task entry
 
125
#
 
126
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
 
127
$mn++; $yr += 1900;
 
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 "" )
 
134
{
 
135
    $filter = "filter: $filter_arg\n";
 
136
}
 
137
 
 
138
$entry = "${dn}${misc}${cn}${basedn}${filter}";
 
139
$rc = DSUtil::ldapmod($entry, %info);
 
140
 
 
141
$dn =~ s/^dn: //;
 
142
$dn =~ s/\n//;
 
143
if($rc == 0){
 
144
    print "Successfully added task entry \"$dn\"\n";
 
145
} else {
 
146
    print "Failed to add task entry \"$dn\" error ($rc)\n";
 
147
}
 
148
 
 
149
exit($rc);