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

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