makevlvsearch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/usr/bin/env perl
  2. #
  3. # BEGIN COPYRIGHT BLOCK
  4. # This Program is free software; you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation; version 2 of the License.
  7. #
  8. # This Program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  14. # Place, Suite 330, Boston, MA 02111-1307 USA.
  15. #
  16. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  17. # right to link the code of this Program with code not covered under the GNU
  18. # General Public License ("Non-GPL Code") and to distribute linked combinations
  19. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  20. # permitted under this exception must only link to the code of this Program
  21. # through those well defined interfaces identified in the file named EXCEPTION
  22. # found in the source code files (the "Approved Interfaces"). The files of
  23. # Non-GPL Code may instantiate templates or use macros or inline functions from
  24. # the Approved Interfaces without causing the resulting work to be covered by
  25. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  26. # additions to the list of Approved Interfaces. You must obey the GNU General
  27. # Public License in all respects for all of the Program code and other code used
  28. # in conjunction with the Program except the Non-GPL Code covered by this
  29. # exception. If you modify this file, you may extend this exception to your
  30. # version of the file, but you are not obligated to do so. If you do not wish to
  31. # provide this exception without modification, you must delete this exception
  32. # statement from your version and license this file solely under the GPL without
  33. # exception.
  34. #
  35. #
  36. # Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  37. # Copyright (C) 2005 Red Hat, Inc.
  38. # All rights reserved.
  39. # END COPYRIGHT BLOCK
  40. #
  41. # makevlvsearch
  42. sub usage_and_exit
  43. {
  44. print "makevlvsearch [options]\n";
  45. print "\n";
  46. print "May be used to create just a vlvSearch entry, or to create\n";
  47. print "both a vlvSearch and vlvIndex entry.\n";
  48. print "\n";
  49. print "Options:\n";
  50. print "-? - help\n";
  51. print "-D rootdn - Provide a root DN. Default= '$rootdn'\n";
  52. print "-w password - Provide a password for the root DN.\n";
  53. print "-h host - Provide a host name. Default= '$host'\n";
  54. print "-p port - Provide a port. Default= '$port'\n";
  55. print "-b scope - Provide a scope. 1 or 2. Default= '$vlvscope'\n";
  56. print "-f filter - Provide a search filter. Default= '$vlvfilter'\n";
  57. print "-sn search_name - RDN of the vlvSearch parent entry.\n";
  58. print "-in index_name - RDN for the vlvIndex child entry.\n";
  59. print "-s sort - Provide a sort specification. Default='$vlvsort'\n";
  60. exit;
  61. }
  62. # Initialise some things
  63. $vlvsearch_name= "";
  64. $vlvindex_name= "";
  65. $vlvscope= "2";
  66. $vlvfilter= "(objectclass=*)";
  67. $vlvsort= "";
  68. $rootdn= "cn=Directory Manager";
  69. $host= "localhost";
  70. $port= "389";
  71. # Process the command line arguments
  72. while( $arg = shift)
  73. {
  74. if($arg eq "-?")
  75. {
  76. usage_and_exit();
  77. }
  78. elsif($arg eq "-D")
  79. {
  80. $rootdn= shift @ARGV;
  81. }
  82. elsif($arg eq "-w")
  83. {
  84. $rootpw= shift @ARGV;
  85. }
  86. elsif($arg eq "-h")
  87. {
  88. $host= shift @ARGV;
  89. }
  90. elsif($arg eq "-p")
  91. {
  92. $port= shift @ARGV;
  93. }
  94. elsif($arg eq "-b")
  95. {
  96. $vlvscope= shift @ARGV;
  97. }
  98. elsif($arg eq "-f")
  99. {
  100. $vlvfilter= shift @ARGV;
  101. }
  102. elsif($arg eq "-s")
  103. {
  104. $vlvsort= shift @ARGV;
  105. }
  106. elsif($arg eq "-sn")
  107. {
  108. $vlvsearch_name= shift @ARGV;
  109. }
  110. elsif($arg eq "-in")
  111. {
  112. $vlvindex_name= shift @ARGV;
  113. }
  114. else
  115. {
  116. print "$arg: Unknown command line argument.\n";
  117. }
  118. }
  119. $ldapmodify= "ldapmodify -h $host -p $port -D \"$rootdn\" -w $rootpw";
  120. if( $vlvfilter eq "" ||
  121. $vlvscope eq "" ||
  122. $vlvsearch_name eq "" ||
  123. $rootdn eq "" ||
  124. $host eq "" ||
  125. $port eq "")
  126. {
  127. print "Error: Need command line information..\n";
  128. usage_and_exit();
  129. }
  130. if( $rootpw eq "" )
  131. {
  132. print "Warning: No root DN password provided. Won't be able to add VLV Search and Index entries.\n";
  133. }
  134. # Tell the user what we're up to.
  135. print "Adding VLV Search and Index entries.\n";
  136. # Build the vlv search and index entries to be added.
  137. @vlvsearch= (
  138. "dn: cn=$vlvsearch_name, cn=config, cn=ldbm\n",
  139. "objectclass: top\n",
  140. "objectclass: vlvSearch\n",
  141. "cn: $vlvsearch_name\n",
  142. "vlvbase: $dn\n",
  143. "vlvfilter: $vlvfilter\n",
  144. "vlvscope: $vlvscope\n\n" );
  145. @vlvindex= (
  146. "dn: cn=$vlvindex_name, cn=$vlvsearch_name, cn=config, cn=ldbm\n",
  147. "objectclass: top\n",
  148. "objectclass: vlvIndex\n",
  149. "cn: $vlvindex_name\n",
  150. "vlvsort: $vlvsort\n\n" );
  151. open(FD,"| $ldapmodify -a -c");
  152. print FD @vlvsearch;
  153. if( not($vlvindex_name eq "" || $vlvsort eq ""))
  154. {
  155. print FD @vlvindex;
  156. }
  157. close(FD);