monitor.in 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/bin/sh
  2. source @datadir@/@package_name@/data/DSSharedLib
  3. libpath_add "@libdir@/@package_name@/"
  4. libpath_add "@ldapsdk_libdir@"
  5. libpath_add "@libdir@"
  6. libpath_add "@nss_libdir@"
  7. export LD_LIBRARY_PATH
  8. SHLIB_PATH=$LD_LIBRARY_PATH
  9. export SHLIB_PATH
  10. PATH=$PATH:@ldaptool_bindir@:@ldaptool_bindir@:/usr/bin/:/usr/lib64/mozldap
  11. protocol=""
  12. usage ()
  13. {
  14. echo "Usage: monitor [ -Z serverID ] [ -D rootdn ] [ -w password ] [ -b basedn ] [-P protocol] [-h]"
  15. echo "Options:"
  16. echo " -Z serverID - Server instance identifier"
  17. echo " -D rootdn - Directory Manager DN"
  18. echo " -w passwd - Directory Manager password"
  19. echo " -P protocol - STARTTLS, LDAPS, LDAPI, LDAP"
  20. echo " -h - Display usage"
  21. }
  22. while getopts "Z:b:hP:D:w:" flag
  23. do
  24. case $flag in
  25. Z) servid=$OPTARG;;
  26. P) protocol=$OPTARG;;
  27. b) MDN=$OPTARG;;
  28. D) rootdn=$OPTARG;;
  29. w) passwd=$OPTARG;;
  30. h) usage
  31. exit 0;;
  32. ?) usage
  33. exit 1;;
  34. esac
  35. done
  36. initfile=$(get_init_file "@initconfigdir@" $servid)
  37. if [ $? == 1 ]
  38. then
  39. usage
  40. echo "You must supply a valid server instance identifier. Use -Z to specify instance name"
  41. echo "Available instances: $initfile"
  42. exit 1
  43. fi
  44. if [ -z "$MDN" ]
  45. then
  46. MDN="cn=monitor"
  47. fi
  48. . $initfile
  49. process_dse $CONFIG_DIR $$
  50. file="/tmp/DSSharedLib.$$"
  51. port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
  52. host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )
  53. security=$(grep -i 'nsslapd-security' $file | awk '{print $2}' )
  54. secure_port=$(grep -i 'nsslapd-secureport' $file | awk '{print $2}' )
  55. ldapi=$(grep -i 'nsslapd-ldapilisten' $file | awk '{print $2}' )
  56. ldapiURL=$(grep -i 'nsslapd-ldapifilepath' $file | awk '{print $2}' )
  57. certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
  58. autobind=$(grep -i 'nsslapd-ldapiautobind' $file | awk '{print $2}' )
  59. if [ "$rootdn" == "" ]; then
  60. value=$(grep -i 'nsslapd-rootdn' $file)
  61. rootdn=`echo "$value" | sed -e 's/nsslapd-rootdn: //i'`
  62. fi
  63. rm $file
  64. if [ "$passwd" != "" ]; then
  65. dn="-D $rootdn"
  66. passwd="-w$passwd"
  67. fi
  68. if [ "$ldapiURL" != "" ]
  69. then
  70. ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
  71. ldapiURL="ldapi://"$ldapiURL
  72. fi
  73. client_type=`ldapsearch -V 2>&1`;
  74. echo "$client_type" | grep -q "OpenLDAP"
  75. if [ $? -eq 0 ]
  76. then
  77. openldap="yes"
  78. export LDAPTLS_CACERTDIR=$certdir
  79. fi
  80. if [ -z $security ]; then
  81. security="off"
  82. fi
  83. revised_protocol=$(check_protocol $protocol $security $ldapi $openldap)
  84. if [ "$revised_protocol" != "$protocol" ]; then
  85. echo Protocol $protocol requested, but this protocol is not supported
  86. error="yes"
  87. fi
  88. protocol=$revised_protocol
  89. #
  90. # STARTTLS
  91. #
  92. if [ "$security" == "on" ]; then
  93. if [ "$protocol" == "STARTTLS" ] || [ "$protocol" == "" ]; then
  94. if [ "$error" == "yes" ]; then
  95. echo "Using the next most secure protocol(STARTTLS)"
  96. fi
  97. if [ "$openldap" == "yes" ]; then
  98. ldapsearch -x -LLL -ZZ -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
  99. else
  100. ldapsearch -ZZZ -P $certdir -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
  101. fi
  102. exit $?
  103. fi
  104. fi
  105. #
  106. # LDAPS
  107. #
  108. if [ "$security" == "on" ]; then
  109. if [ "$protocol" == "LDAPS" ] || [ "$protocol" == "" ]; then
  110. if [ "$error" == "yes" ]; then
  111. echo "Using the next most secure protocol(LDAPS)"
  112. fi
  113. if [ "$openldap" == "yes" ]; then
  114. ldapsearch -x -LLL -H "ldaps://$host:$secure_port" -b "$MDN" -s base $dn $passwd "objectClass=*"
  115. else
  116. ldapsearch -Z -P $certdir -p $secure_port -b "$MDN" -s base $dn $passwd "objectClass=*"
  117. fi
  118. exit $?
  119. fi
  120. fi
  121. #
  122. # LDAPI
  123. #
  124. if [ "$ldapi" == "on" ] && [ "$openldap" == "yes" ]; then
  125. if [ "$protocol" == "LDAPI" ] || [ "$protocol" == "" ]; then
  126. if [ "$(id -u)" == "0" ] && [ "$autobind" == "on" ]; then
  127. if [ "$error" == "yes" ]; then
  128. echo "Using the next most secure protocol(LDAPI/AUTOBIND)"
  129. fi
  130. ldapsearch -LLL -H "$ldapiURL" -b "$MDN" -s base -Y EXTERNAL "objectClass=*" 2>/dev/null
  131. else
  132. if [ "$error" == "yes" ]; then
  133. echo "Using the next most secure protocol(LDAPI)"
  134. fi
  135. ldapsearch -x -LLL -H "$ldapiURL" -b "$MDN" -s base $dn $passwd "objectClass=*"
  136. fi
  137. exit $?
  138. fi
  139. fi
  140. #
  141. # LDAP
  142. #
  143. if [ "$protocol" == "LDAP" ] || [ "$protocol" == "" ]; then
  144. if [ "$error" == "yes" ]; then
  145. echo "Using the next most secure protocol(LDAP)"
  146. fi
  147. if [ "$openldap" == "yes" ]; then
  148. ldapsearch -x -LLL -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
  149. else
  150. ldapsearch -h $host -p $port -b "$MDN" -s base $dn $passwd "objectClass=*"
  151. fi
  152. exit $?
  153. fi