#47962 Wrong exit values returned by DS scripts (1.2.11 only)
Closed: wontfix None Opened 8 years ago by nkinder.

Ticket was cloned from Red Hat Bugzilla (product Red Hat Enterprise Linux 6): Bug 1159124

# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)


ns-newpwpolicy.pl [ -D rootdn ] [ -w password | -j filename ] [ -p port ] [ -h
host ] -U userDN -S suffixDN [ -v ] [ -? ]


The script itself does not exit properly even if the commands within it
obviously have failed.

Description of the problem:

Even with a non-existent user, the  script continues and exits with 0 as return
code. This is incorrect, right?
This script should exist with non-zero exit code (preferably same as what is
reported by the directory server).

# ./ns-newpwpolicy.pl -D cn=Manager -w Manager -U
No such object (32)
adding new entry "cn=nsPwPolicyContainer,cn=config"
ldap_add: Already exists (68)

Entry cn=nsPwPolicyContainer,cn=config already exists. Please ignore the error

adding new entry "cn=cn\=nsPwPolicyEntry\,cn\=system_credential_access\,cn\=con
ldap_add: Already exists (68)

Entry cn=cn\=nsPwPolicyEntry\,cn\=system_credential_access\,cn\=config,cn=nsPwP
olicyContainer,cn=config already exists. Please ignore the error

modifying entry "cn=system_credential_access,cn=config"
ldap_modify: No such object (32)

Error 8192 while modifing cn=system_credential_access,cn=config. Exiting.
#echo $?

The problem here is that the Perl exit() function does not expect an exit code larger than 255. If the value is larger (such as 8192 above), it ends up being 0. We are ending up with these odd exit codes due to some missing shift operations. For example, we have correct and incorrect exit value processing in ns-newpwpolicy.pl:


open(FD,"| $ldapadd");
print FD @{$all[$i]};
    if ( $? != 0 ) {
        if ( $retCode == 68 ) {


open(FD,"| $modifyCfg ");
print(FD $modConfig);
    $retcode = $?;
    if ( $retcode != 0 ) {
        print( STDERR "1 Error $retcode while modifing \"cn=config\". Exiting.\n" );
        exit ($retcode);

We need to shift the value from $? to the right by 8 to get the actual exit value of the command that is being run as desribed in the Perl system() function documentation:


Do we need to do this for all of our .pl scripts?

Replying to [comment:5 rmeggins]:

Do we need to do this for all of our .pl scripts?

Yeah, must of them do need to be adjusted. Attaching new patch...

322d7d0..d8e7912 389-ds-base-1.2.11 -> 389-ds-base-1.2.11
commit d8e7912
Author: Mark Reynolds mreynolds@redhat.com
Date: Wed Dec 17 11:56:42 2014 -0500

Metadata Update from @mreynolds:
- Issue assigned to mreynolds
- Issue set to the milestone:

5 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/389ds/389-ds-base/issues/1293

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Metadata Update from @spichugi:
- Issue close_status updated to: wontfix (was: Fixed)

2 years ago

Login to comment on this ticket.