Blame SOURCES/0007-Issue-49065-dbmon.sh-fails-if-you-have-nsslapd-requi.patch

61f723
From edf3d210e9ba9006f87e0597b052fa925c68ddc2 Mon Sep 17 00:00:00 2001
61f723
From: Mark Reynolds <mreynolds@redhat.com>
61f723
Date: Mon, 20 Mar 2017 17:35:10 -0400
61f723
Subject: [PATCH] Issue 49065 - dbmon.sh fails if you have
61f723
 nsslapd-require-secure-binds enabled
61f723
61f723
Description:  Add the ability to detect if security is enabled, if so connect using
61f723
              start TLS.  Added a new param SERVID for specifying which instance
61f723
              you want to look at.
61f723
61f723
https://pagure.io/389-ds-base/issue/49065
61f723
61f723
Reviewed by: firstyear(Thanks!)
61f723
---
61f723
 Makefile.am                                      |  2 +-
61f723
 ldap/admin/src/scripts/{dbmon.sh => dbmon.sh.in} | 62 ++++++++++++++++++++++--
61f723
 man/man8/dbmon.sh.8                              | 14 +++---
61f723
 3 files changed, 65 insertions(+), 13 deletions(-)
61f723
 rename ldap/admin/src/scripts/{dbmon.sh => dbmon.sh.in} (81%)
61f723
 mode change 100755 => 100644
61f723
61f723
diff --git a/Makefile.am b/Makefile.am
61f723
index 9aebb6b..4a4b2d3 100644
61f723
--- a/Makefile.am
61f723
+++ b/Makefile.am
61f723
@@ -235,7 +235,7 @@ CLEANFILES =  dberrstrs.h ns-slapd.properties \
61f723
 	ldap/admin/src/scripts/usn-tombstone-cleanup.pl ldap/admin/src/scripts/verify-db.pl \
61f723
 	ldap/admin/src/scripts/ds_selinux_port_query ldap/admin/src/scripts/ds_selinux_enabled \
61f723
 	ldap/admin/src/scripts/dbverify ldap/admin/src/scripts/readnsstate \
61f723
-	doxyfile.stamp \
61f723
+	doxyfile.stamp ldap/admin/src/scripts/dbmon.sh \
61f723
 	$(NULL)
61f723
 
61f723
 clean-local:
61f723
diff --git a/ldap/admin/src/scripts/dbmon.sh b/ldap/admin/src/scripts/dbmon.sh.in
61f723
old mode 100755
61f723
new mode 100644
61f723
similarity index 81%
61f723
rename from ldap/admin/src/scripts/dbmon.sh
61f723
rename to ldap/admin/src/scripts/dbmon.sh.in
61f723
index 3b8b4d1..4ee6adc
61f723
--- a/ldap/admin/src/scripts/dbmon.sh
61f723
+++ b/ldap/admin/src/scripts/dbmon.sh.in
61f723
@@ -8,10 +8,11 @@
61f723
 # END COPYRIGHT BLOCK
61f723
 #
61f723
 
61f723
+. @datadir@/@package_name@/data/DSSharedLib
61f723
+
61f723
 DURATION=${DURATION:-0}
61f723
 INCR=${INCR:-1}
61f723
-HOST=${HOST:-localhost}
61f723
-PORT=${PORT:-389}
61f723
+SERVID=${SERVID}
61f723
 BINDDN=${BINDDN:-"cn=directory manager"}
61f723
 BINDPW=${BINDPW:-"secret"}
61f723
 DBLIST=${DBLIST:-all}
61f723
@@ -180,10 +181,63 @@ parseldif() {
61f723
 }
61f723
 
61f723
 dodbmon() {
61f723
+    initfile=$(get_init_file "@initconfigdir@" $SERVID)
61f723
+    if [ $? -eq 1 ]
61f723
+    then
61f723
+        echo "You must supply a valid server instance identifier (via SERVID)."
61f723
+        echo "Available instances: $initfile"
61f723
+        exit 1
61f723
+    fi
61f723
+
61f723
+    . $initfile
61f723
+
61f723
+    process_dse $CONFIG_DIR $$
61f723
+    file="/tmp/DSSharedLib.$$"
61f723
+    port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
61f723
+    host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )
61f723
+    security=$(grep -i 'nsslapd-security' $file | awk '{print $2}' )
61f723
+    certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
61f723
+    rm $file
61f723
+
61f723
+    if [ -n "$ldapiURL" ]
61f723
+    then
61f723
+        ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
61f723
+        ldapiURL="ldapi://"$ldapiURL
61f723
+    fi
61f723
+
61f723
+    client_type=`ldapsearch -V 2>&1;;
61f723
+    echo "$client_type" | grep -q "OpenLDAP"
61f723
+    if  [ $? -eq 0 ]
61f723
+    then
61f723
+        openldap="yes"
61f723
+        export LDAPTLS_CACERTDIR=$certdir
61f723
+    fi
61f723
+
61f723
+    if [ -z $security ]; then
61f723
+        security="off"
61f723
+    fi
61f723
+
61f723
     while [ 1 ] ; do
61f723
         date
61f723
-        ldapsearch -xLLL -h $HOST -p $PORT -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
61f723
-        | parseldif
61f723
+        if [ "$security" = "on" ]; then
61f723
+            # STARTTLS
61f723
+	    if [ "$openldap" = "yes" ]; then
61f723
+	        ldapsearch -x -LLL -ZZ -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
61f723
+                | parseldif
61f723
+	    else
61f723
+	        ldapsearch -ZZZ -P $certdir  -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
61f723
+                | parseldif
61f723
+	    fi
61f723
+        else
61f723
+            # LDAP
61f723
+            if [ "$openldap" = "yes" ]; then
61f723
+	        ldapsearch -x -LLL -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
61f723
+                | parseldif
61f723
+            else
61f723
+	        ldapsearch -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
61f723
+                | parseldif
61f723
+            fi
61f723
+        fi
61f723
         echo ""
61f723
         sleep $INCR
61f723
     done
61f723
diff --git a/man/man8/dbmon.sh.8 b/man/man8/dbmon.sh.8
61f723
index 49e61d0..ad318a1 100644
61f723
--- a/man/man8/dbmon.sh.8
61f723
+++ b/man/man8/dbmon.sh.8
61f723
@@ -2,7 +2,7 @@
61f723
 .\" First parameter, NAME, should be all caps
61f723
 .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
61f723
 .\" other parameters are allowed: see man(7), man(1)
61f723
-.TH DBMON.SH 8 "Jul 25, 2014"
61f723
+.TH DBMON.SH 8 "Mar 20, 2017"
61f723
 .\" Please adjust this date whenever revising the manpage.
61f723
 .\"
61f723
 .\" Some roff macros, for reference:
61f723
@@ -18,7 +18,7 @@
61f723
 .SH NAME 
61f723
 dbmon.sh - Directory Server script for monitoring database and entry cache usage
61f723
 .SH SYNOPSIS
61f723
-[INCR=num] [HOST=hostname] [PORT=num] [BINDDN=binddn] [BINDPW=password] [DBLIST=databases] [INDEXLIST=indexes] [VERBOSE=num] dbmon.sh
61f723
+[INCR=num] [SERVID=server_id][BINDDN=binddn] [BINDPW=password] [DBLIST=databases] [INDEXLIST=indexes] [VERBOSE=num] dbmon.sh
61f723
 .SH DESCRIPTION
61f723
 dbmon.sh is a tool used to monitor database and entry cache usage. It is especially useful for database cache and entry/dn cache tuning - how much space is left, is the cache full, how much space on average do I need per entry/dn.
61f723
 .SH OPTIONS
61f723
@@ -31,9 +31,7 @@ All arguments are optional, but you will most likely have to provide BINDPW
61f723
 .TP
61f723
 .B \fBINCR\fR - show results every INCR seconds - default is 1 second
61f723
 .TP
61f723
-.B \fBHOST\fR - name of host or IP address - default is "localhost"
61f723
-.TP
61f723
-.B \fBPORT\fR - port number (LDAP not LDAPS) - default is 389
61f723
+.B \fBSERVID\fR - Name of the server instance
61f723
 .TP
61f723
 .B \fBBINDDN\fR - DN to use to bind - must have permission to read everything under cn=config - default is cn=Directory Manager
61f723
 .TP
61f723
@@ -46,11 +44,11 @@ All arguments are optional, but you will most likely have to provide BINDPW
61f723
 .B \fBVERBOSE\fR - output level - 0 == suitable for parsing by a script - 1 == has column headings - 2 == provides detailed descriptions of the data - default is 0
61f723
 
61f723
 .SH EXAMPLE
61f723
-INCR=1 HOST=ldap.example.com BINDDN="cn=directory manager" BINDPW="secret" VERBOSE=2 dbmon.sh
61f723
+INCR=1 SERVID=slapd-localhost BINDDN="cn=directory manager" BINDPW="secret" VERBOSE=2 dbmon.sh
61f723
 
61f723
 .SH AUTHOR
61f723
 dbmon.sh was written by the 389 Project.
61f723
 .SH "REPORTING BUGS"
61f723
-Report bugs to https://fedorahosted.org/389/newticket.
61f723
+Report bugs to https://pagure.io/389-ds-base/new_issue
61f723
 .SH COPYRIGHT
61f723
-Copyright \(co 2014 Red Hat, Inc.
61f723
+Copyright \(co 2017 Red Hat, Inc.
61f723
-- 
61f723
2.9.3
61f723