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

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/ns-activate.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
$ENV{'PATH'} = "@ldaptool_bindir@:/usr/bin:/usr/lib64/mozldap/";
 
48
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
 
49
 
 
50
$single = 0;
 
51
$role = 0;
 
52
 
 
53
###############################
 
54
# SUB-ROUTINES
 
55
###############################
 
56
 
 
57
sub usage
 
58
{
 
59
    print (STDERR "ns-activate.pl [-Z serverID] [-D rootdn] { -w password | -w - | -j filename } \n");
 
60
    print (STDERR "               [-p port] [-h host] [-P protocol] -I DN-to-$operation\n\n");
 
61
    print (STDERR "May be used to $operation a user or a domain of users\n\n");
 
62
    print (STDERR "Arguments:\n");
 
63
    print (STDERR "        -?                   - Display usage\n");
 
64
    print (STDERR "        -D rootdn            - Provide a Directory Manager DN\n");
 
65
    print (STDERR "        -w password          - Provide a password for the Directory Manager DN\n");
 
66
    print (STDERR "        -w -                 - Prompt for the Directory Manager's password\n");
 
67
    print (STDERR "        -Z serverID          - Server instance identifier\n");
 
68
    print (STDERR "        -j filename          - Read the Directory Manager's password from file\n");
 
69
    print (STDERR "        -p port              - Provide a port\n");
 
70
    print (STDERR "        -h host              - Provide a host name'\n");
 
71
    print (STDERR "        -P protocol          - STARTTLS, LDAPS, LDAPI, LDAP (default: uses most secure protocol available)\n");
 
72
    print (STDERR "        -I DN-to-$operation  - Single entry DN or role DN to $operation\n");
 
73
}
 
74
 
 
75
sub debug
 
76
{
 
77
#    print " ==> @_";
 
78
}
 
79
 
 
80
sub out
 
81
{
 
82
    print "@_";
 
83
}
 
84
 
 
85
# --------------------------
 
86
# Check if the entry is part of a locked role:
 
87
# i.e.: for each role member (nsroledn) of nsdisabledrole, check if
 
88
#     * it is the same as the entry
 
89
#     * the entry is member of role (==has nsroledn attributes), compare each of
 
90
#        them with the nsroledn of nsdisabledrole
 
91
#    * if nsroledn of nsdisabledrole are complex, go through each of them
 
92
# argv[0] is the local file handler
 
93
# argv[1] is the entry (may be a single entry DN or a role DN)
 
94
# argv[2] is the base for the search
 
95
# --------------------------
 
96
 
 
97
$throughRole="";
 
98
 
 
99
sub indirectLock
 
100
{
 
101
    # For recursivity, file handler must be local
 
102
    my $L_filehandle=$_[0];
 
103
    $L_filehandle++;
 
104
 
 
105
    my $L_entry=$_[1];
 
106
    # Remove useless space
 
107
    my @L_intern=split /([,])/,$L_entry;
 
108
    my $L_result="";
 
109
    foreach $L_part (@L_intern){
 
110
        $L_part=~s/^ +//;
 
111
        $L_part=~ tr/A-Z/a-z/;
 
112
        $L_result="$L_result$L_part";
 
113
    }
 
114
    $L_entry=$L_result;
 
115
 
 
116
    my $L_base=$_[2];
 
117
    my $L_search;
 
118
    my $L_currentrole;
 
119
    my $L_retCode;
 
120
    my $L_local;
 
121
 
 
122
    $info{base} = $L_base;
 
123
    $info{filter} = "(|(objectclass=*)(objectclass=ldapsubentry))";
 
124
    $info{scope} = "base";
 
125
    $info{attrs} = "nsroledn";
 
126
    $info{redirect} = ">> /dev/null 2>&1";
 
127
    DSUtil::ldapsrch_ext(%info);
 
128
    $info{redirect} = "";
 
129
    $retCode=$?;
 
130
    if ( $retCode != 0 ){
 
131
        $retCode=$?>>8;
 
132
        return 1;
 
133
    }
 
134
 
 
135
    # Check if the role is a nested role
 
136
    $info{filter} = "(|(objectclass=nsNestedRoleDefinition)(objectclass=ldapsubentry))";
 
137
    $info{attrs} = "";
 
138
    @L_Nested=DSUtil::ldapsrch(%info);
 
139
    # L_isNested == 1 means that we are going through a nested role, so for each member of that
 
140
    # nested role, check that the member is below the scope of the nested
 
141
    $L_isNested=@L_Nested;
 
142
 
 
143
    # Not Direct Lock, Go through roles if any
 
144
    $info{attrs} = "nsroledn";
 
145
    $info{filter} = "(|(objectclass=*)(objectclass=ldapsubentry))";
 
146
    $L_search=DSUtil::ldapsrch(%info);
 
147
 
 
148
    debug("\t-->indirectLock: check if $L_entry is part of a locked role from base $L_base\n\n");
 
149
 
 
150
    unless (open ($L_filehandle, "$L_search |")){
 
151
        out("Can't open file $L_filehandle\n");
 
152
        exit;
 
153
    }
 
154
    while (<$L_filehandle>) {
 
155
        s/\n //g;
 
156
        if (/^nsroledn: (.*)\n/) {
 
157
            $L_currentrole = $1;
 
158
 
 
159
            # Remove useless space
 
160
            my @L_intern=split /([,])/,$L_currentrole;
 
161
            my $L_result="";
 
162
            foreach $L_part (@L_intern){
 
163
                $L_part=~s/^ +//;
 
164
                $L_part=~ tr/A-Z/a-z/;
 
165
                $L_result="$L_result$L_part";
 
166
            }
 
167
            $L_currentrole=$L_result;
 
168
 
 
169
            debug("\t-- indirectLock loop: current nsroledn $L_currentrole of base $L_base\n");
 
170
            if ( $L_isNested == 1 ){
 
171
                if ( checkScope($L_currentrole, $L_base) == 0 ){
 
172
                    # Scope problem probably a bad conf, skip the currentrole
 
173
                    next;    
 
174
                }
 
175
            }
 
176
 
 
177
            if ( $L_currentrole eq $L_entry ){
 
178
                # the entry is a role that is directly locked
 
179
                # i.e, nsroledn of nsdisabledrole contains the entry
 
180
                $throughRole=$L_base;
 
181
                $throughRole=~ tr/A-Z/a-z/;
 
182
 
 
183
                # skipDisabled means that we've just found that the entry (which is a role)
 
184
                # is locked directly (==its DN is part of nsroledn attributes)
 
185
                # we just want to know now, if it is locked through another role
 
186
                # at least, one
 
187
                if ( $skipDisabled == 1 ){
 
188
                    # direct inactivation
 
189
                    $directLocked=1;
 
190
                    # just go through that test once
 
191
                    $skipDisabled=0;
 
192
                    next;
 
193
                }
 
194
                debug("\t-- 1 indirectLock: $L_currentrole locked throughRole == $throughRole\n");
 
195
                return 0;
 
196
            }
 
197
 
 
198
            $L_retCode=memberOf($L_currentrole, $L_entry);
 
199
            if ( $L_retCode == 0 && $single == 1 ){
 
200
                $throughRole=$L_currentrole;
 
201
                $throughRole=~ tr/A-Z/a-z/;
 
202
                if ( $skipManaged == 1 ){
 
203
                    if ( $L_currentrole eq $nsManagedDisabledRole){
 
204
                        # Try next nsroledn
 
205
                        $directLocked=1;
 
206
                        $skipManaged=0;
 
207
                        next;
 
208
                    }
 
209
                } 
 
210
                debug("\t-- 2 indirectLock: $L_currentrole locked throughRole == $throughRole\n");
 
211
                return 0;
 
212
            }
 
213
 
 
214
            # Only for the first iteration
 
215
            # the first iteration is with nsdisabledrole as base, other
 
216
            # loops are deeper
 
217
            $L_local=$skipDisabled;
 
218
            $skipDisabled=0;
 
219
    
 
220
            # the current nsroledn may be a complex role, just go through
 
221
            # its won nsroledn
 
222
            $L_retCode=indirectLock($L_filehandle,$L_entry, $L_currentrole);
 
223
 
 
224
            # Because of recursivity, to keep the initial value for the first level
 
225
            $skipDisabled=$L_local;
 
226
 
 
227
            if ( $L_retCode == 0 ){
 
228
                $throughRole=$L_currentrole;
 
229
                $throughRole=~ tr/A-Z/a-z/;
 
230
                debug("\t-- 3 indirectLock: $L_entry locked throughRole == $throughRole\n");
 
231
                return 0;
 
232
            }
 
233
        }
 
234
    }
 
235
 
 
236
    close($L_filehandle);
 
237
 
 
238
    debug("\t<--indirectLock: no more nsroledn to process\n");
 
239
    return 1;
 
240
}
 
241
 
 
242
# --------------------------
 
243
# Check if nsroledn is part of the entry attributes
 
244
# argv[0] is a role DN (nsroledn attribute)
 
245
# argv[1] is the entry
 
246
# --------------------------
 
247
sub memberOf
 
248
{
 
249
    my $L_nsroledn=$_[0];
 
250
    $L_nsroledn=~ tr/A-Z/a-z/;
 
251
    my $L_entry=$_[1];
 
252
    my $L_search;
 
253
    my $L_currentrole;
 
254
 
 
255
    $info{base} = $L_entry;
 
256
    $info{filter} = "(|(objectclass=*)(objectclass=ldapsubentry))";
 
257
    $info{scope} = "base";
 
258
    $info{attrs} = "nsrole";
 
259
    $L_search = DSUtil::ldapsrch(%info);
 
260
 
 
261
    debug("\t\t-->memberOf: $L_search: check if $L_entry has $L_nsroledn as nsroledn attribute\n");
 
262
 
 
263
    open (LDAP2, "$L_search |");
 
264
    while (<LDAP2>) {
 
265
        s/\n //g;
 
266
        if (/^nsrole: (.*)\n/) {
 
267
            $L_currentrole = $1;
 
268
            $L_currentrole=~ tr/A-Z/a-z/;
 
269
            if ( $L_currentrole eq $L_nsroledn ){
 
270
                # the parm is part of the $L_entry nsroledn
 
271
                debug("\t\t<--memberOf: $L_entry locked through $L_nsroledn\n");
 
272
                return 0;
 
273
            }
 
274
        }
 
275
    }
 
276
    close(LDAP2);
 
277
 
 
278
    # the parm is not part of the $L_entry nsroledn
 
279
    debug("\t\t<--memberOf: $L_entry not locked through $L_nsroledn\n");
 
280
    return 1;
 
281
}
 
282
 
 
283
 
 
284
# --------------------------
 
285
# Remove the rdn of a DN
 
286
# argv[0] is a DN
 
287
# --------------------------
 
288
sub removeRdn
 
289
{
 
290
    $L_entry=$_[0];
 
291
 
 
292
    @L_entryToTest=split /([,])/,$L_entry;
 
293
    debug("removeRdn: entry to split: $L_entry**@L_entryToTest\n");
 
294
 
 
295
    $newDN="";
 
296
    $removeRDN=1;
 
297
    foreach $part (@L_entryToTest){
 
298
        $part=~ s/^ +//;
 
299
        $part=~ tr/A-Z/a-z/;
 
300
        if ( $removeRDN <= 2 ){
 
301
            $removeRDN=$removeRDN+1;
 
302
        } else {
 
303
            $newDN="$newDN$part";
 
304
        }
 
305
    }
 
306
 
 
307
    debug("removeRdn: new DN **$newDN**\n");
 
308
}
 
309
 
 
310
# --------------------------
 
311
# Check if L_current is below the scope of 
 
312
# L_nestedRole
 
313
# argv[0] is a role
 
314
# argv[1] is the nested role
 
315
# --------------------------
 
316
sub checkScope
 
317
{
 
318
    $L_current=$_[0];
 
319
    $L_nestedRole=$_[1];
 
320
 
 
321
    debug("checkScope: check if $L_current is below $L_nestedRole\n");
 
322
 
 
323
    removeRdn($L_nestedRole);
 
324
    $L_nestedRoleSuffix=$newDN;
 
325
    debug("checkScope: nested role based:  $L_nestedRoleSuffix\n");
 
326
 
 
327
    $cont=1;
 
328
    while ( ($cont == 1) && ($L_current ne "") ){
 
329
        removeRdn($L_current);
 
330
        $currentDn=$newDN;
 
331
        debug("checkScope: current DN to check: $currentDn\n");
 
332
 
 
333
        if ( $currentDn eq $L_nestedRoleSuffix ){
 
334
            debug("checkScope: DN match!!!\n");
 
335
            $cont = 0;
 
336
        } else {
 
337
            $L_current=$currentDn;
 
338
        }
 
339
    }
 
340
 
 
341
    if ( $cont == 1 ){
 
342
        debug("checkScope: $_[0] and $_[1] are not compatible\n");
 
343
        return 0;
 
344
    } else {
 
345
        debug("checkScope: $_[0] and $_[1] are compatible\n");
 
346
        return 1;
 
347
    }
 
348
}
 
349
 
 
350
 
 
351
###############################
 
352
# MAIN ROUTINE
 
353
###############################
 
354
 
 
355
# Generated variable
 
356
 
 
357
# Determine which command we are running
 
358
if ( $0 =~ /ns-inactivate(.pl)?$/ ){
 
359
    $cmd="ns-inactivate.pl";
 
360
    $operation="inactivate";
 
361
    $state="inactivated";
 
362
    $modrole="add";
 
363
    $already="already";
 
364
} elsif ( $0 =~ /ns-activate(.pl)?$/ ){
 
365
    $cmd="ns-activate.pl";
 
366
    $operation="activate";
 
367
    $state="activated";
 
368
    $modrole="delete";
 
369
    $already="already";
 
370
} elsif ( $0 =~ /ns-accountstatus(.pl)?$/ ){
 
371
    $cmd="ns-accountstatus.pl";
 
372
    $operation="get status of";
 
373
    $state="activated";
 
374
    # no need for $modrole as no operation is performed
 
375
    $already="";
 
376
 
 
377
} else {
 
378
    out("$0: unknown command\n");
 
379
    exit 100;
 
380
}
 
381
 
 
382
debug("Running ** $cmd ** $operation\n");
 
383
 
 
384
# Process the command line arguments
 
385
while( $arg = shift)
 
386
{
 
387
    if($arg eq "-?"){
 
388
        usage();
 
389
        exit(0);
 
390
    } elsif($arg eq "-D"){
 
391
        $rootdn = shift @ARGV;
 
392
    } elsif($arg eq "-w"){
 
393
        $rootpw = shift @ARGV;
 
394
    } elsif($arg eq "-j"){
 
395
        $pwfile = shift @ARGV;
 
396
    } elsif($arg eq "-p"){
 
397
        $port = shift @ARGV;
 
398
    } elsif($arg eq "-h"){
 
399
        $host = shift @ARGV;
 
400
    } elsif($arg eq "-I"){
 
401
        $entry = shift @ARGV;
 
402
    } elsif($arg eq "-Z"){
 
403
        $servid = shift @ARGV;
 
404
    } elsif ($arg eq "-P") { 
 
405
        $protocol = shift @ARGV;
 
406
    } else {
 
407
        print "$arg: Unknown command line argument.\n";
 
408
        usage();
 
409
        exit(1);
 
410
    }
 
411
}
 
412
 
 
413
#
 
414
# Gather all our config settings
 
415
#
 
416
($servid, $confdir) = DSUtil::get_server_id($servid, "@initconfigdir@");
 
417
%info = DSUtil::get_info($confdir, $host, $port, $rootdn);
 
418
$info{rootdnpw} = DSUtil::get_password_from_file($rootpw, $pwfile);
 
419
$info{protocol} = $protocol;
 
420
$info{args} = "-c";
 
421
if($entry eq ""){
 
422
    usage();
 
423
    exit 1;
 
424
}
 
425
 
 
426
#
 
427
# Check the actual existence of the entry to inactivate/activate
 
428
# and at the same time, validate the various parm: port, host, rootdn, rootpw
 
429
#
 
430
$info{base} = $entry;
 
431
$info{filter} = "(objectclass=*)";
 
432
$info{scope} = "base";
 
433
$info{attrs} = "dn";
 
434
@exist=DSUtil::ldapsrch_ext(%info);
 
435
$retCode1=$?;
 
436
if ( $retCode1 != 0 ){
 
437
    $retCode1=$?>>8;
 
438
    exit $retCode1;
 
439
}
 
440
 
 
441
$info{filter} = "(&(objectclass=LDAPsubentry)(objectclass=nsRoleDefinition))";
 
442
@isRole = DSUtil::ldapsrch_ext(%info);
 
443
$nbLineRole=@isRole;
 
444
$retCode2=$?;
 
445
if ( $retCode2 != 0 ){
 
446
    $retCode2=$?>>8;
 
447
    exit $retCode2;
 
448
}
 
449
 
 
450
if ( $nbLineRole > 0 ){
 
451
    debug("Groups of users\n");
 
452
    $role=1;
 
453
} else {
 
454
    debug("Single user\n");
 
455
    $single=1;
 
456
}
 
457
 
 
458
#
 
459
# First of all, check the existence of the nsaccountlock attribute in the entry
 
460
#
 
461
$isLocked=0;
 
462
if ( $single == 1 ){
 
463
    $info{filter} = "(objectclass=*)";
 
464
    $info{attrs} = "nsaccountlock";
 
465
    $searchAccountLock= DSUtil::ldapsrch(%info);
 
466
    open (LDAP1, "$searchAccountLock |");
 
467
    while (<LDAP1>) {
 
468
        s/\n //g;
 
469
        if (/^nsaccountlock: (.*)\n/) {
 
470
            $L_currentvalue = $1;
 
471
            $L_currentvalue=~ tr/A-Z/a-z/;
 
472
            if ( $L_currentvalue eq "true"){
 
473
                $isLocked=1;
 
474
            } elsif ( $L_currentvalue eq "false" ){
 
475
                $isLocked=0;
 
476
            }
 
477
        }
 
478
    }
 
479
    close(LDAP1);
 
480
}
 
481
debug("Is the entry already locked? ==> $isLocked\n");
 
482
 
 
483
#
 
484
# Get the suffix name of that entry
 
485
#
 
486
 
 
487
# Remove the space at the beginning (just in case...)
 
488
#    -I "uid=jvedder , ou=People , o=sun.com"
 
489
@suffix=split /([,])/,$entry;
 
490
$result="";
 
491
foreach $part (@suffix){
 
492
    $part=~s/^ +//;
 
493
    $part=~ tr/A-Z/a-z/;
 
494
    $result="$result$part";
 
495
}
 
496
@suffixN=$result;
 
497
 
 
498
debug("Entry to $operation: #@suffix#\n");
 
499
debug("Entry to $operation: #@suffixN#\n");
 
500
 
 
501
# Get the suffix
 
502
$cont=0;
 
503
while ($cont == 0){
 
504
    # Look if suffix is the suffix of the entry
 
505
    #    ldapsearch -s one -b "cn=mapping tree,cn=config" "cn=\"uid=jvedder,ou=People,o=sun.com\""
 
506
    #
 
507
    debug("\tSuffix from the entry: #@suffixN#\n");
 
508
    $info{base} = "cn=mapping tree, cn=config";
 
509
    $info{filter} = "cn=\"@suffixN\"";
 
510
    $info{scope} = "one";
 
511
    $info{attrs} = "cn";
 
512
    @mapping = DSUtil::ldapsrch_ext(%info);
 
513
    $retCode=$?;
 
514
    if ( $retCode != 0 ){
 
515
        $retCode=$?>>8;
 
516
        exit $retCode;
 
517
    }
 
518
 
 
519
    # If we get a result, remove the dn:
 
520
    #    dn: cn="o=sun.com",cn=mapping tree,cn=config
 
521
    #    cn: "o=sun.com"
 
522
    #
 
523
    shift @mapping;
 
524
 
 
525
    foreach $res (@mapping){
 
526
        # Break the string cn: "o=sun.com" into pieces
 
527
        @cn= split(/ /,$res);
 
528
 
 
529
        # And remove the cn: part
 
530
        shift @cn;
 
531
 
 
532
        # Now compare the suffix we extract from the mapping tree 
 
533
        # with the suffix derived from the entry
 
534
        debug("\tSuffix from mapping tree: #@cn#\n");
 
535
        if ( @cn eq @suffixN ) {
 
536
            debug("Found matching suffix\n");
 
537
            $cont=1;
 
538
        }
 
539
    }
 
540
 
 
541
    if ( $cont == 0 ){
 
542
        # Remove the current rdn to try another suffix
 
543
        shift @suffix;
 
544
 
 
545
        $result="";
 
546
        foreach $part (@suffix){
 
547
            $part=~ s/^ +//;
 
548
            $part=~ tr/A-Z/a-z/;
 
549
            $result="$result$part";
 
550
        }
 
551
        @suffixN=$result;
 
552
 
 
553
        debug("\t\tNothing found => go up one level in rdn #@suffix#\n");
 
554
        $len=@suffix;
 
555
        if ( $len == 0 ){
 
556
            debug("Can not find suffix. Problem\n");
 
557
            $cont=2;
 
558
        }
 
559
    }
 
560
}
 
561
if ( $cont == 2){
 
562
    out("Can not find suffix for entry $entry\n");
 
563
    exit 100;
 
564
}
 
565
 
 
566
if ( $operation eq "inactivate" ){
 
567
    #
 
568
    # Now that we have the suffix and we know if we deal with a single entry or
 
569
    # a role, just try to create the COS and roles associated.
 
570
    #
 
571
    $role1="dn: cn=nsManagedDisabledRole,@suffixN\n" .
 
572
           "objectclass: LDAPsubentry\n" .
 
573
           "objectclass: nsRoleDefinition\n" .
 
574
           "objectclass: nsSimpleRoleDefinition\n" .
 
575
           "objectclass: nsManagedRoleDefinition\n" .
 
576
           "cn: nsManagedDisabledRole\n\n";
 
577
    $role2="dn: cn=nsDisabledRole,@suffixN\n" .
 
578
           "objectclass: top\n" .
 
579
           "objectclass: LDAPsubentry\n" .
 
580
           "objectclass: nsRoleDefinition\n" .
 
581
           "objectclass: nsComplexRoleDefinition\n" .
 
582
           "objectclass: nsNestedRoleDefinition\n" .
 
583
           "nsRoleDN: cn=nsManagedDisabledRole,@suffixN\n" .
 
584
           "cn: nsDisabledRole\n\n";
 
585
    $cos1="dn: cn=nsAccountInactivationTmp,@suffixN\n" .
 
586
          "objectclass: top\n" .
 
587
          "objectclass: nsContainer\n\n";
 
588
    $cos2="dn: cn=\"cn=nsDisabledRole,@suffixN\",cn=nsAccountInactivationTmp,@suffixN\n" .
 
589
          "objectclass: top\n" .
 
590
          "objectclass: extensibleObject\n" .
 
591
          "objectclass: costemplate\n" .
 
592
            "objectclass: ldapsubentry\n" .
 
593
            "cosPriority: 1\n" .
 
594
          "nsAccountLock: true\n\n";
 
595
    $cos3="dn: cn=nsAccountInactivation_cos,@suffixN\n" .
 
596
          "objectclass: top\n" .
 
597
          "objectclass: LDAPsubentry\n" .
 
598
          "objectclass: cosSuperDefinition\n" .
 
599
          "objectclass: cosClassicDefinition\n" .
 
600
          "cosTemplateDn: cn=nsAccountInactivationTmp,@suffixN\n" .
 
601
          "cosSpecifier: nsRole\n" .
 
602
          "cosAttribute: nsAccountLock operational\n\n";
 
603
    $all=$role1 . $role2 . $cos1 . $cos2 . $cos3;
 
604
 
 
605
    $info{args} = "-c -a";
 
606
    DSUtil::ldapmod($all[$i], %info);
 
607
    if ( $? != 0 ){
 
608
        $retCode=$?>>8;
 
609
        if ( $retCode == 68 ){
 
610
            debug("Entry already exists, ignore error\n");
 
611
        } else {
 
612
            # Probably a more serious problem.
 
613
            # Exit with LDAP error
 
614
            exit $retCode;
 
615
        }
 
616
    } else {
 
617
        debug("Role/cos entries created\n");
 
618
    }
 
619
}
 
620
 
 
621
$skipManaged=0;
 
622
$skipDisabled=0;
 
623
$directLocked=0;
 
624
 
 
625
$nsDisabledRole="cn=nsDisabledRole,@suffixN";
 
626
$nsDisabledRole=~ tr/A-Z/a-z/;
 
627
 
 
628
$nsManagedDisabledRole="cn=nsManagedDisabledRole,@suffixN";
 
629
$nsManagedDisabledRole=~ tr/A-Z/a-z/;
 
630
 
 
631
if ( $operation eq "inactivate" ){
 
632
    # Go through all the roles part of nsdisabledrole to check if the entry
 
633
    # is a member of one of those roles
 
634
    $ret=indirectLock("LDAP00", $entry, $nsDisabledRole);
 
635
    if ( $ret == 0 ){
 
636
        if ( $throughRole ne $nsDisabledRole && $throughRole ne $nsManagedDisabledRole ){
 
637
            # indirect lock
 
638
            out("$entry already $state through $throughRole.\n");
 
639
        } else {
 
640
            # direct lock
 
641
            out("$entry already $state.\n");
 
642
        }
 
643
        exit 100;
 
644
    } elsif ( $isLocked == 1 ){
 
645
        # the entry is not locked through a role, may be nsaccountlock is "hardcoded" ?
 
646
        out("$entry already $state (probably directly).\n");
 
647
        exit 103;
 
648
    }
 
649
} elsif ( $operation eq "activate" || $operation eq "get status of" ){
 
650
    $skipManaged=$single;
 
651
    $skipDisabled=$role;
 
652
 
 
653
    $ret=indirectLock("LDAP00",$entry, $nsDisabledRole);
 
654
 
 
655
    if ( $ret == 0 ){
 
656
        # undirectly locked
 
657
        if ( $throughRole ne $nsDisabledRole && $throughRole ne $nsManagedDisabledRole ){
 
658
            if ( $operation eq "activate" ){
 
659
                out("$entry inactivated through $throughRole. Can not activate it individually.\n");
 
660
                exit 100;
 
661
            } else {
 
662
                out("$entry inactivated through $throughRole.\n");
 
663
                exit 104;
 
664
            }
 
665
        }
 
666
        debug("$entry locked individually\n");
 
667
 
 
668
        if ( $operation ne "activate" ){
 
669
            out("$entry inactivated.\n");
 
670
            exit 103;
 
671
        }
 
672
    } elsif ( $directLocked == 0 ){
 
673
        if ( $operation eq "activate" && $isLocked != 1 ){
 
674
            out("$entry $already $state.\n");
 
675
            exit 100;
 
676
        } elsif ( $isLocked != 1 ) {
 
677
            out("$entry $already $state.\n");
 
678
            exit 102;
 
679
        } else {
 
680
            # not locked using our schema, but nsaccountlock is probably present
 
681
            out("$entry inactivated (probably directly).\n");
 
682
            exit 103;
 
683
        }
 
684
    } elsif ( $operation ne "activate" ){
 
685
        out("$entry inactivated.\n");
 
686
        exit 103;
 
687
    }
 
688
    # else Locked directly, juste unlock it!
 
689
    debug("$entry locked individually\n");
 
690
}
 
691
 
 
692
#
 
693
# Inactivate/activate the entry
 
694
#
 
695
if ( $single == 1 ){
 
696
    $record = "dn: $entry\n" . "changetype: modify\n" . "$modrole: nsRoleDN\n" . "nsRoleDN: cn=nsManagedDisabledRole,@suffixN\n";
 
697
} else {
 
698
    $record = "dn: cn=nsDisabledRole,@suffixN\n" . "changetype: modify\n" . "$modrole: nsRoleDN\n" . "nsRoleDN: $entry\n";
 
699
}
 
700
 
 
701
$info{args} = "-c";
 
702
DSUtil::ldapmod($record, %info);
 
703
if( $? != 0 ){
 
704
    debug("$modrole, $entry\n");
 
705
    $retCode=$?>>8;
 
706
    exit $retCode;
 
707
}
 
708
 
 
709
out("$entry $state.\n");
 
710
exit 0;