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

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