Blame SOURCES/0006-Ticket-49320-Activating-already-active-role-returns-.patch

058656
From 50d62b6d5ea69e5cad6359dbd1dccb09fcfa1a6b Mon Sep 17 00:00:00 2001
058656
From: Mark Reynolds <mreynolds@redhat.com>
058656
Date: Tue, 3 Oct 2017 09:51:53 -0400
058656
Subject: [PATCH] Ticket 49320 - Activating already active role returns error
058656
 16
058656
058656
Bug Description:  ns-activate.pl returns error 16 when trying to activate an
058656
                  already active role.
058656
058656
Fix Description:  Check for error 16 (no such attr), and return error 100.
058656
                  Also added a "redirect"otion to the ldapmod function to
058656
                  hide any errors printed to STDERR, so that the script can
058656
                  display its own error message.
058656
058656
https://pagure.io/389-ds-base/issue/49320
058656
058656
Reviewed by: firstyear(Thanks!)
058656
058656
(cherry picked from commit 406084847f29aa44ffd81de746770aeff6b67c61)
058656
---
058656
 ldap/admin/src/scripts/DSUtil.pm.in      | 18 +++++++++++-------
058656
 ldap/admin/src/scripts/ns-activate.pl.in |  9 ++++++++-
058656
 2 files changed, 19 insertions(+), 8 deletions(-)
058656
058656
diff --git a/ldap/admin/src/scripts/DSUtil.pm.in b/ldap/admin/src/scripts/DSUtil.pm.in
058656
index 805a9b91d..791464d0a 100644
058656
--- a/ldap/admin/src/scripts/DSUtil.pm.in
058656
+++ b/ldap/admin/src/scripts/DSUtil.pm.in
058656
@@ -1447,6 +1447,10 @@ sub ldapmod {
058656
         close (FILE);
058656
     }
058656
 
058656
+    if ($info{redirect} eq ""){
058656
+        $info{redirect} = "> /dev/null";
058656
+    }
058656
+
058656
     #
058656
     # Check the protocol, and reset it if it's invalid
058656
     #
058656
@@ -1470,9 +1474,9 @@ sub ldapmod {
058656
             print "STARTTLS)\n";
058656
         }
058656
         if($info{openldap} eq "yes"){
058656
-            system "ldapmodify -x -ZZ -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -x -ZZ -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         } else {
058656
-            system "ldapmodify -ZZZ -P \"$info{certdir}\" -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -ZZZ -P \"$info{certdir}\" -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         }
058656
     } elsif (($info{security} eq "on" && $info{protocol} eq "") || ($info{security} eq "on" && $info{protocol} =~ m/LDAPS/i) ){ 
058656
         # 
058656
@@ -1482,9 +1486,9 @@ sub ldapmod {
058656
             print "LDAPS)\n";
058656
         }
058656
         if($info{openldap} eq "yes"){
058656
-            system "ldapmodify -x -H \"ldaps://$info{host}:$info{secure_port}\" -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -x -H \"ldaps://$info{host}:$info{secure_port}\" -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         } else {
058656
-            system "ldapmodify -Z -P \"$info{certdir}\" -p $info{secure_port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -Z -P \"$info{certdir}\" -p $info{secure_port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         }
058656
     } elsif (($info{openldap} eq "yes") && (($info{ldapi} eq "on" && $info{protocol} eq "") || ($info{ldapi} eq "on" && $info{protocol} =~ m/LDAPI/i)) ){  
058656
         #
058656
@@ -1499,7 +1503,7 @@ sub ldapmod {
058656
             if($protocol_error eq "yes"){
058656
                 print "LDAPI)\n";
058656
             }
058656
-            system "ldapmodify -x -H \"$info{ldapiURL}\" -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -x -H \"$info{ldapiURL}\" -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         }
058656
     } else {
058656
         # 
058656
@@ -1509,9 +1513,9 @@ sub ldapmod {
058656
             print "LDAP)\n";
058656
         }
058656
         if($info{openldap} eq "yes"){
058656
-            system "ldapmodify -x -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -x -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         } else {
058656
-            system "ldapmodify -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" > /dev/null";
058656
+            system "ldapmodify -h $info{host} -p $info{port} -D \"$info{rootdn}\" -w $myrootdnpw $info{args} -f \"$file\" $info{redirect}";
058656
         }
058656
     }
058656
     unlink ($file);
058656
diff --git a/ldap/admin/src/scripts/ns-activate.pl.in b/ldap/admin/src/scripts/ns-activate.pl.in
058656
index 5922c9aab..bec19c8e7 100644
058656
--- a/ldap/admin/src/scripts/ns-activate.pl.in
058656
+++ b/ldap/admin/src/scripts/ns-activate.pl.in
058656
@@ -731,11 +731,18 @@ if ( $single == 1 ){
058656
 }
058656
 
058656
 $info{args} = "-c";
058656
+$info{redirect} = "> /dev/null 2>&1";
058656
 DSUtil::ldapmod($record, %info);
058656
 if( $? != 0 ){
058656
     debug("delete, $entry\n");
058656
     $retCode=$?>>8;
058656
-    exit $retCode;
058656
+    if ($retCode == "16") {  # Error 16 (no such attr) - already activated
058656
+        out("$entry already $state.\n");
058656
+        exit 100;
058656
+    } else {
058656
+        out("Failed to activate $entry, error $retCode\n");
058656
+        exit $retCode;
058656
+    }
058656
 }
058656
 
058656
 out("$entry $state.\n");
058656
-- 
058656
2.13.6
058656