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

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