PageRenderTime 39ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/389-ds-base-1.2.11.7/ldap/admin/src/scripts/template-ldif2db.pl.in

#
Autoconf | 241 lines | 190 code | 6 blank | 45 comment | 36 complexity | 10efe505e7c661f1026c0a495811cb96 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  1. #{{PERL-EXEC}}
  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. sub usage {
  42. print(STDERR "Usage: $0 [-v] -D rootdn { -w password | -w - | -j filename } \n");
  43. print(STDERR " -n instance | {-s include}* [{-x exclude}*] [-O] [-c]\n");
  44. print(STDERR " [-g [string]] [-G namespace_id] {-i filename}*\n");
  45. print(STDERR " Opts: -D rootdn - Directory Manager\n");
  46. print(STDERR " : -w password - Directory Manager's password\n");
  47. print(STDERR " : -w - - Prompt for Directory Manager's password\n");
  48. print(STDERR " : -j filename - Read Directory Manager's password from file\n");
  49. print(STDERR " : -n instance - instance to be imported to\n");
  50. print(STDERR " : -i filename - input ldif file(s)\n");
  51. print(STDERR " : -s include - included suffix\n");
  52. print(STDERR " : -x exclude - excluded suffix(es)\n");
  53. print(STDERR " : -O - only create core db, no attr indexes\n");
  54. print(STDERR " : -c size - merge chunk size\n");
  55. print(STDERR " : -g [string] - string is \"none\" or \"deterministic\"\n");
  56. print(STDERR " : none - unique id is not generated\n");
  57. print(STDERR " : deterministic - generate name based unique id (-G name)\n");
  58. print(STDERR " : by default - generate time based unique id\n");
  59. print(STDERR " : -G name - namespace id for name based uniqueid (-g deterministic)\n");
  60. print(STDERR " : -E - Encrypt data when importing\n");
  61. print(STDERR " : -v - verbose\n");
  62. }
  63. @ldiffiles = (
  64. "", "", "", "", "", "", "", "", "", "",
  65. "", "", "", "", "", "", "", "", "", "",
  66. "", "", "", "", "", "", "", "", "", "",
  67. "", "", "", "", "", "", "", "", "", "",
  68. "", "", "", "", "", "", "", "", "", "",
  69. ""
  70. );
  71. @included = (
  72. "", "", "", "", "", "", "", "", "", "",
  73. "", "", "", "", "", "", "", "", "", "",
  74. "", "", "", "", "", "", "", "", "", "",
  75. "", "", "", "", "", "", "", "", "", "",
  76. "", "", "", "", "", "", "", "", "", "",
  77. ""
  78. );
  79. @excluded = (
  80. "", "", "", "", "", "", "", "", "", "",
  81. "", "", "", "", "", "", "", "", "", "",
  82. "", "", "", "", "", "", "", "", "", "",
  83. "", "", "", "", "", "", "", "", "", "",
  84. "", "", "", "", "", "", "", "", "", "",
  85. ""
  86. );
  87. $maxidx = 50;
  88. $instance = "";
  89. $noattrindexes = 0;
  90. $mergechunksiz = 0;
  91. $genuniqid = "time";
  92. $uniqidname = "";
  93. $taskname = "";
  94. $prefix = "{{DS-ROOT}}";
  95. $verbose = 0;
  96. $rootdn = "";
  97. $passwd = "";
  98. $passwdfile = "";
  99. $i = 0;
  100. $ldifi = 0;
  101. $incli = 0;
  102. $excli = 0;
  103. $encrypt_on_import = 0;
  104. while ($i <= $#ARGV) {
  105. if ( "$ARGV[$i]" eq "-i" ) { # ldiffiles
  106. $i++;
  107. if ($ldifi < $maxidx) {
  108. $ldiffiles[$ldifi] = $ARGV[$i]; $ldifi++;
  109. } else {
  110. &usage; exit(1);
  111. }
  112. } elsif ("$ARGV[$i]" eq "-s") { # included suffix
  113. $i++;
  114. if ($incli < $maxidx) {
  115. $included[$incli] = $ARGV[$i]; $incli++;
  116. } else {
  117. &usage; exit(1);
  118. }
  119. } elsif ("$ARGV[$i]" eq "-x") { # excluded suffix
  120. $i++;
  121. if ($excli < $maxidx) {
  122. $excluded[$excli] = $ARGV[$i]; $excli++;
  123. } else {
  124. &usage; exit(1);
  125. }
  126. } elsif ("$ARGV[$i]" eq "-n") { # instance
  127. $i++; $instance = $ARGV[$i];
  128. } elsif ("$ARGV[$i]" eq "-D") { # Directory Manager
  129. $i++; $rootdn = $ARGV[$i];
  130. } elsif ("$ARGV[$i]" eq "-w") { # Directory Manager's password
  131. $i++; $passwd = $ARGV[$i];
  132. } elsif ("$ARGV[$i]" eq "-j") { # Read Directory Manager's password from a file
  133. $i++; $passwdfile = $ARGV[$i];
  134. } elsif ("$ARGV[$i]" eq "-O") { # no attr indexes
  135. $noattrindexes = 1;
  136. } elsif ("$ARGV[$i]" eq "-c") { # merge chunk size
  137. $i++; $mergechunksiz = $ARGV[$i];
  138. } elsif ("$ARGV[$i]" eq "-g") { # generate uniqueid
  139. if (("$ARGV[$i+1]" ne "") && !("$ARGV[$i+1]" =~ /^-/)) {
  140. $i++;
  141. if ("$ARGV[$i]" eq "none") {
  142. $genuniqid = $ARGV[$i];
  143. } elsif ("$ARGV[$i]" eq "deterministic") {
  144. $genuniqid = $ARGV[$i];
  145. }
  146. }
  147. } elsif ("$ARGV[$i]" eq "-G") { # namespace id
  148. $i++; $uniqidname = $ARGV[$i];
  149. } elsif ("$ARGV[$i]" eq "-v") { # verbose
  150. $verbose = 1;
  151. } elsif ("$ARGV[$i]" eq "-E") { # encrypt on import
  152. $encrypt_on_import = 1;
  153. } else {
  154. &usage; exit(1);
  155. }
  156. $i++;
  157. }
  158. if ($passwdfile ne ""){
  159. # Open file and get the password
  160. unless (open (RPASS, $passwdfile)) {
  161. die "Error, cannot open password file $passwdfile\n";
  162. }
  163. $passwd = <RPASS>;
  164. chomp($passwd);
  165. close(RPASS);
  166. } elsif ($passwd eq "-"){
  167. # Read the password from terminal
  168. print "Bind Password: ";
  169. # Disable console echo
  170. system("@sttyexec@ -echo") if -t STDIN;
  171. # read the answer
  172. $passwd = <STDIN>;
  173. # Enable console echo
  174. system("@sttyexec@ echo") if -t STDIN;
  175. print "\n";
  176. chop($passwd); # trim trailing newline
  177. }
  178. if (($instance eq "" && $included[0] eq "") || $ldiffiles[0] eq "" || $rootdn eq "" || $passwd eq "") { &usage; exit(1); }
  179. ($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
  180. $mn++; $yr += 1900;
  181. $taskname = "import_${yr}_${mn}_${dy}_${h}_${m}_${s}";
  182. $dn = "dn: cn=$taskname, cn=import, cn=tasks, cn=config\n";
  183. $misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
  184. $cn = "cn: $taskname\n";
  185. if ($instance ne "") {
  186. $nsinstance = "nsInstance: ${instance}\n";
  187. }
  188. $i = 0;
  189. $nsldiffiles = "";
  190. while ("" ne "$ldiffiles[$i]") {
  191. $nsldiffiles = "${nsldiffiles}nsFilename: $ldiffiles[$i]\n";
  192. $i++;
  193. }
  194. $i = 0;
  195. $nsincluded = "";
  196. while ("" ne "$included[$i]") {
  197. $nsincluded = "${nsincluded}nsIncludeSuffix: $included[$i]\n";
  198. $i++;
  199. }
  200. $i = 0;
  201. $nsexcluded = "";
  202. while ("" ne "$excluded[$i]") {
  203. $nsexcluded = "${nsexcluded}nsExcludeSuffix: $excluded[$i]\n";
  204. $i++;
  205. }
  206. $nsnoattrindexes = "";
  207. if ($noattrindexes != 0) { $nsnoattrindexes = "nsImportIndexAttrs: false\n"; }
  208. $nsimportencrypt = "";
  209. if ($encrypt_on_import != 0) { $nsimportencrypt = "nsImportEncrypt: true\n"; }
  210. $nsmergechunksiz = "nsImportChunkSize: ${mergechunksiz}\n";
  211. $nsgenuniqid = "nsUniqueIdGenerator: ${genuniqid}\n";
  212. $nsuniqidname = "";
  213. if ($uniqidname ne "") { $nsuniqidname = "nsUniqueIdGeneratorNamespace: ${uniqidname}\n"; }
  214. $entry = "${dn}${misc}${cn}${nsinstance}${nsincluded}${nsexcluded}${nsldiffiles}${nsnoattrindexes}${nsimportencrypt}${nsmergechunksiz}${nsgenuniqid}${nsuniqidname}";
  215. $vstr = "";
  216. if ($verbose != 0) { $vstr = "-v"; }
  217. $ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
  218. libpath_add("$prefix@nss_libdir@");
  219. libpath_add("$prefix/usr/lib");
  220. libpath_add("@nss_libdir@");
  221. libpath_add("/usr/lib");
  222. $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
  223. open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
  224. print(FOO "$entry");
  225. close(FOO);
  226. sub libpath_add {
  227. my $libpath = shift;
  228. if ($libpath) {
  229. if ($ENV{'LD_LIBRARY_PATH'}) {
  230. $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
  231. } else {
  232. $ENV{'LD_LIBRARY_PATH'} = "$libpath";
  233. }
  234. }
  235. }