template-migrateTo7 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321
  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. # enable the use of our bundled perldap with our bundled ldapsdk libraries
  42. # all of this nonsense can be omitted if the mozldapsdk and perldap are
  43. # installed in the operating system locations (e.g. /usr/lib /usr/lib/perl5)
  44. BEGIN {
  45. my $sroot = "{{DS-ROOT}}";
  46. push @INC, "$sroot/lib/perl/arch", "$sroot/lib/perl";
  47. if ($ENV{LD_LIBRARY_PATH}) {
  48. $ENV{LD_LIBRARY_PATH} .= ":";
  49. }
  50. $ENV{LD_LIBRARY_PATH} .= "$sroot/shared/lib";
  51. # this is only needed for HP/ux PA-RISC, but it doesn't hurt other platforms
  52. if ($ENV{SHLIB_PATH}) {
  53. $ENV{SHLIB_PATH} .= ":";
  54. }
  55. $ENV{SHLIB_PATH} .= "$sroot/shared/lib";
  56. }
  57. # Migrate a old directory server to a 7.0 directory server
  58. ########################################################################################################
  59. # enable the use of Perldap functions
  60. require DynaLoader;
  61. use Getopt::Std;
  62. use Mozilla::LDAP::Conn;
  63. use Mozilla::LDAP::Entry;
  64. use Mozilla::LDAP::LDIF;
  65. use Mozilla::LDAP::Utils qw(:all);
  66. use Mozilla::LDAP::API qw(:api :ssl :apiv3 :constant); # Direct access to C API
  67. use Time::localtime;
  68. ########################################################################################################
  69. use Class::Struct ; # load struct-building module
  70. struct S_index => {
  71. names => '@' ,
  72. types => '@' ,
  73. oids => '@' ,
  74. specific => '$'
  75. };
  76. struct S_plugin => {
  77. name => '$' ,
  78. type => '$' ,
  79. enable => '$' ,
  80. args => '@'
  81. };
  82. #####################################################################################################
  83. sub usage {
  84. print(STDERR "\nUsage: $0 -D rootdn { -w password | -w - | -j filename } -p port \n");
  85. print(STDERR " -o OldInstancePath -n NewInstancePath [-t tracelevel] [-L logfile]\n");
  86. print(STDERR "************** parameters in brackets are optionals, others are required **************\n");
  87. print(STDERR " Opts: -D rootdn - New Directory Manager\n");
  88. print(STDERR " : -w password - New Directory Manager's password\n");
  89. print(STDERR " : -w - - Prompt for New Directory Manager's password\n");
  90. print(STDERR " : -j filename - Read New Directory Manager's password from file\n");
  91. print(STDERR " : -p port - New Directory Server port\n");
  92. print(STDERR " : -o OldInstancePath - Path of the Old instance to migrate \n");
  93. print(STDERR " : -n NewInstancePath - Path of the new instance\n");
  94. print(STDERR " : [-d dataPath] - Path to directory containing data files to import into new instance\n");
  95. print(STDERR " : [-v oldVersion] - Old version (obtained by running $slapdExecName -v\n");
  96. print(STDERR " : [-t tracelevel] - specify the level of trace (0..3)\n");
  97. print(STDERR " : [-L logfile] - specify the file to log the migration report \n");
  98. }
  99. #############
  100. BEGIN {
  101. require 'uname.lib' ;
  102. $isNT = -d '\\';
  103. $PATHSEP = $isNT ? "\\" : "/";
  104. ${SEP} = $isNT ? ";" : ":" ;
  105. @INC = ( '.', '../../../admin/admin/bin');
  106. grep { s@/@\\@g } @INC if $isNT;
  107. $script_suffix = $isNT ? ".bat" : "";
  108. $exe_suffix = $isNT ? ".exe" : "";
  109. # NT needs quotes around some things unix doesn't
  110. $quote = $isNT ? "\"" : "";
  111. # If this variable is set, all file/directory creation will make sure the mode
  112. # and ownership of the destination is the same as the source
  113. $PRESERVE = 1 if (!$isNT);
  114. $script_suffix = $isNT ? ".bat" : "";
  115. $exe_suffix = $isNT ? ".exe" : "";
  116. if ($isNT) {
  117. $os = "WINNT";
  118. } else {
  119. $os = &uname("-s");
  120. }
  121. if ($isNT) {
  122. # we have to pass batch files directly to the NT command interpreter
  123. $com_spec = $ENV{ComSpec};
  124. if (!$com_spec) {
  125. $com_spec = $ENV{COMSPEC};
  126. }
  127. if (!$com_spec || ! -f $com_spec) {
  128. # find the first available command interpreter
  129. foreach $drive (c..z) {
  130. $com_spec = "$drive:\\winnt\\system32\\cmd.exe";
  131. last if (-f $com_spec);
  132. $com_spec = undef;
  133. }
  134. if (! $com_spec) {
  135. # punt and pray
  136. $com_spec = 'c:\winnt\system32\cmd.exe';
  137. }
  138. }
  139. }
  140. if ( $os eq "AIX" ) {
  141. $dll_suffix = "_shr.a";
  142. }
  143. elsif ( $os eq "HP-UX" ) {
  144. $dll_suffix = ".sl";
  145. }
  146. elsif ( $os eq "WINNT" ) {
  147. $dll_suffix = ".dll";
  148. }
  149. else {
  150. $dll_suffix = ".so";
  151. }
  152. $slapdExecName = $isNT ? 'slapd.exe' : './ns-slapd';
  153. # if this flag is set, we will migrate the old database
  154. # by doing a db2ldif -> ldif2db;
  155. $convertToLDIF = 1;
  156. select STDERR;
  157. $| = 1;
  158. select STDOUT;
  159. $| = 1;
  160. # if the old value for dbcachesize is less than this, make it this
  161. $MIN_DBCACHESIZE = '500000';
  162. }
  163. SWITCH: {
  164. if ($os eq "AIX") {
  165. $LIB_PATH = "LIBPATH" ;
  166. last SWITCH ;
  167. }
  168. if ($os eq "HP-UX") {
  169. $LIB_PATH = "SHLIB_PATH" ;
  170. last SWITCH ;
  171. }
  172. if ($isNT) {
  173. $LIB_PATH = "PATH" ;
  174. last SWITCH ;
  175. }
  176. else {
  177. $LIB_PATH = "LD_LIBRARY_PATH" ;
  178. last SWITCH ;
  179. }
  180. }
  181. # Old parameters
  182. ${oldDir} = "" ;
  183. ${oldname} = "" ;
  184. ${oldHome} = "" ;
  185. ${oldConfDir} = "" ;
  186. ${oldlocaluser} ;
  187. ${olduid} ;
  188. ${oldgid} ;
  189. # New parameters
  190. ${root} = "{{DS-ROOT}}" ;
  191. ${type} = "" ;
  192. ${newname} = "" ;
  193. ${newport} = "" ;
  194. ${rootDN} = "" ;
  195. ${rootpwd} = "" ;
  196. ${localhost} = "" ;
  197. ${LogFileReport} = "" ;
  198. ${newuid} ;
  199. ${localuser} ;
  200. ${newgid} ;
  201. $NO_INPUT_USER = 0 ; # by default user can give inputs during the migration process
  202. ${curdir} = getCwd();
  203. ${slapdExecDir} = "${root}${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server${PATHSEP}";
  204. # specify the level of trace
  205. $TRACELEVEL=1;
  206. $LDAP_SERVER_UNREACHABLE = 81;
  207. # get input users
  208. &getParameters() ;
  209. ${oldDir} = &normalizeDir("${oldDir}");
  210. ${oldHome} = "${oldDir}${PATHSEP}$type-$oldname" ;
  211. ${oldConfDir} = "${oldHome}${PATHSEP}config${PATHSEP}" ;
  212. ${oldSlapdConf} = "${oldConfDir}slapd.conf" ;
  213. ${oldDSEldif} = "${oldConfDir}dse.ldif" ;
  214. ${serverHome} = "${root}${PATHSEP}$type-$newname" ;
  215. ${DSEldif} = "$serverHome${PATHSEP}config${PATHSEP}dse.ldif";
  216. ${ldif_rep} = "${oldConfDir}${PATHSEP}ldif${PATHSEP}" ;
  217. ${oldSlapdExecDir} = "${oldDir}${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server${PATHSEP}";
  218. open(LOGFILE, ">> $LogFileReport");
  219. printTrace("\noldDir: $oldDir, oldHome: $oldHome, \noldConfDir: $oldConfDir, \noldSlapdConf: $oldSlapdConf, \nldif_rep: $ldif_rep, \nrootDN: $rootDN, \nPwd: ******, \nPort: $newport, \nNewname: $newname\n",3);
  220. printTrace("\nLIB_PATH: $LIB_PATH",4);
  221. if (!(-d $serverHome)) {
  222. printMsg("\n$serverHome doesn't exist\n");
  223. exit(1);
  224. }
  225. if (!(-d $oldHome)) {
  226. printMsg("\n$oldHome doesn't exist\n");
  227. exit(1);
  228. }
  229. if ($olddatadir && !(-d $olddatadir)) {
  230. print("\n$olddatadir doesn't exist\n");
  231. exit(1);
  232. }
  233. #define CONFIG_DATABASE_DIRECTIVE "database"
  234. #define CONFIG_DATABASE_ATTRIBUTE "nsslapd-database"
  235. #define CONFIG_PLUGIN_DIRECTIVE "plugin"
  236. #define CONFIG_PLUGIN_ATTRIBUTE "nsslapd-plugin"
  237. #define CONFIG_SIZELIMIT_DIRECTIVE "sizelimit"
  238. #define CONFIG_SIZELIMIT_ATTRIBUTE "nsslapd-sizelimit"
  239. #define CONFIG_ORCAUTO_DIRECTIVE "orcauto"
  240. #define CONFIG_ORCAUTO_ATTRIBUTE "nsslapd-orcauto"
  241. #define CONFIG_TIMELIMIT_DIRECTIVE "timelimit"
  242. #define CONFIG_TIMELIMIT_ATTRIBUTE "nsslapd-timelimit"
  243. #define CONFIG_SUFFIX_DIRECTIVE "suffix"
  244. #define CONFIG_SUFFIX_ATTRIBUTE "nsslapd-suffix"
  245. #define CONFIG_READONLY_DIRECTIVE "readonly"
  246. #define CONFIG_READONLY_ATTRIBUTE "nsslapd-readonly"
  247. #define CONFIG_REFERRAL_DIRECTIVE "referral"
  248. #define CONFIG_REFERRAL_ATTRIBUTE "nsslapd-referral"
  249. #define CONFIG_OBJECTCLASS_DIRECTIVE "objectclass"
  250. #define CONFIG_OBJECTCLASS_ATTRIBUTE "nsslapd-objectclass"
  251. #define CONFIG_ATTRIBUTE_DIRECTIVE "attribute"
  252. #define CONFIG_ATTRIBUTE_ATTRIBUTE "nsslapd-attribute"
  253. #define CONFIG_SCHEMACHECK_DIRECTIVE "schemacheck"
  254. #define CONFIG_SCHEMACHECK_ATTRIBUTE "nsslapd-schemacheck"
  255. #define CONFIG_LOGLEVEL_DIRECTIVE "loglevel"
  256. #define CONFIG_LOGLEVEL_ATTRIBUTE "nsslapd-errorlog-level"
  257. #define CONFIG_ACCESSLOGLEVEL_DIRECTIVE "accessloglevel"
  258. #define CONFIG_ACCESSLOGLEVEL_ATTRIBUTE "nsslapd-accesslog-level"
  259. #define CONFIG_ACCESSLOG_MAXNUMOFLOGSPERDIR_DIRECTIVE "accesslog-maxNumOfLogsPerDir"
  260. #define CONFIG_ACCESSLOG_MAXNUMOFLOGSPERDIR_ATTRIBUTE "nsslapd-accesslog-maxlogsperdir"
  261. #define CONFIG_ERRORLOG_MAXNUMOFLOGSPERDIR_DIRECTIVE "errorlog-maxNumOfLogsPerDir"
  262. #define CONFIG_ERRORLOG_MAXNUMOFLOGSPERDIR_ATTRIBUTE "nsslapd-errorlog-maxlogsperdir"
  263. #define CONFIG_AUDITLOG_MAXNUMOFLOGSPERDIR_DIRECTIVE "auditlog-maxNumOfLogsPerDir"
  264. #define CONFIG_AUDITLOG_MAXNUMOFLOGSPERDIR_ATTRIBUTE "nsslapd-auditlog-maxlogsperdir"
  265. #define CONFIG_ACCESSLOG_MAXLOGSIZE_DIRECTIVE "accesslog-maxlogsize"
  266. #define CONFIG_ACCESSLOG_MAXLOGSIZE_ATTRIBUTE "nsslapd-accesslog-maxlogsize"
  267. #define CONFIG_ERRORLOG_MAXLOGSIZE_DIRECTIVE "errorlog-maxlogsize"
  268. #define CONFIG_ERRORLOG_MAXLOGSIZE_ATTRIBUTE "nsslapd-errorlog-maxlogsize"
  269. #define CONFIG_AUDITLOG_MAXLOGSIZE_DIRECTIVE "auditlog-maxlogsize"
  270. #define CONFIG_AUDITLOG_MAXLOGSIZE_ATTRIBUTE "nsslapd-auditlog-maxlogsize"
  271. #define CONFIG_ACCESSLOG_LOGROTATIONTIME_DIRECTIVE "accesslog-logrotationtime"
  272. #define CONFIG_ACCESSLOG_LOGROTATIONTIME_ATTRIBUTE "nsslapd-accesslog-logrotationtime"
  273. #define CONFIG_ERRORLOG_LOGROTATIONTIME_DIRECTIVE "errorlog-logrotationtime"
  274. #define CONFIG_ERRORLOG_LOGROTATIONTIME_ATTRIBUTE "nsslapd-errorlog-logrotationtime"
  275. #define CONFIG_AUDITLOG_LOGROTATIONTIME_DIRECTIVE "auditlog-logrotationtime"
  276. #define CONFIG_AUDITLOG_LOGROTATIONTIME_ATTRIBUTE "nsslapd-auditlog-logrotationtime"
  277. #define CONFIG_ACCESSLOG_LOGROTATIONTIMEUNIT_DIRECTIVE "accesslog-logrotationtimeunit"
  278. #define CONFIG_ACCESSLOG_LOGROTATIONTIMEUNIT_ATTRIBUTE "nsslapd-accesslog-logrotationtimeunit"
  279. #define CONFIG_ERRORLOG_LOGROTATIONTIMEUNIT_DIRECTIVE "errorlog-logrotationtimeunit"
  280. #define CONFIG_ERRORLOG_LOGROTATIONTIMEUNIT_ATTRIBUTE "nsslapd-errorlog-logrotationtimeunit"
  281. #define CONFIG_AUDITLOG_LOGROTATIONTIMEUNIT_DIRECTIVE "auditlog-logrotationtimeunit"
  282. #define CONFIG_AUDITLOG_LOGROTATIONTIMEUNIT_ATTRIBUTE "nsslapd-auditlog-logrotationtimeunit"
  283. #define CONFIG_ACCESSLOG_MAXLOGDISKSPACE_DIRECTIVE "accesslog-maxlogdiskspace"
  284. #define CONFIG_ACCESSLOG_MAXLOGDISKSPACE_ATTRIBUTE "nsslapd-accesslog-logmaxdiskspace"
  285. #define CONFIG_ERRORLOG_MAXLOGDISKSPACE_DIRECTIVE "errorlog-maxlogdiskspace"
  286. #define CONFIG_ERRORLOG_MAXLOGDISKSPACE_ATTRIBUTE "nsslapd-errorlog-logmaxdiskspace"
  287. #define CONFIG_AUDITLOG_MAXLOGDISKSPACE_DIRECTIVE "auditlog-maxlogdiskspace"
  288. #define CONFIG_AUDITLOG_MAXLOGDISKSPACE_ATTRIBUTE "nsslapd-auditlog-logmaxdiskspace"
  289. #define CONFIG_ACCESSLOG_MINFREEDISKSPACE_DIRECTIVE "accesslog-minfreediskspace"
  290. #define CONFIG_ACCESSLOG_MINFREEDISKSPACE_ATTRIBUTE "nsslapd-accesslog-logminfreediskspace"
  291. #define CONFIG_ERRORLOG_MINFREEDISKSPACE_DIRECTIVE "errorlog-minfreediskspace"
  292. #define CONFIG_ERRORLOG_MINFREEDISKSPACE_ATTRIBUTE "nsslapd-errorlog-logminfreediskspace"
  293. #define CONFIG_AUDITLOG_MINFREEDISKSPACE_DIRECTIVE "auditlog-minfreediskspace"
  294. #define CONFIG_AUDITLOG_MINFREEDISKSPACE_ATTRIBUTE "nsslapd-auditlog-logminfreediskspace"
  295. #define CONFIG_ACCESSLOG_LOGEXPIRATIONTIME_DIRECTIVE "accesslog-logexpirationtime"
  296. #define CONFIG_ACCESSLOG_LOGEXPIRATIONTIME_ATTRIBUTE "nsslapd-accesslog-logexpirationtime"
  297. #define CONFIG_ERRORLOG_LOGEXPIRATIONTIME_DIRECTIVE "errorlog-logexpirationtime"
  298. #define CONFIG_ERRORLOG_LOGEXPIRATIONTIME_ATTRIBUTE "nsslapd-errorlog-logexpirationtime"
  299. #define CONFIG_AUDITLOG_LOGEXPIRATIONTIME_DIRECTIVE "auditlog-logexpirationtime"
  300. #define CONFIG_AUDITLOG_LOGEXPIRATIONTIME_ATTRIBUTE "nsslapd-auditlog-logexpirationtime"
  301. #define CONFIG_ACCESSLOG_LOGEXPIRATIONTIMEUNIT_DIRECTIVE "accesslog-logexpirationtimeunit"
  302. #define CONFIG_ACCESSLOG_LOGEXPIRATIONTIMEUNIT_ATTRIBUTE "nsslapd-accesslog-logexpirationtimeunit"
  303. #define CONFIG_ERRORLOG_LOGEXPIRATIONTIMEUNIT_DIRECTIVE "errorlog-logexpirationtimeunit"
  304. #define CONFIG_ERRORLOG_LOGEXPIRATIONTIMEUNIT_ATTRIBUTE "nsslapd-errorlog-logexpirationtimeunit"
  305. #define CONFIG_AUDITLOG_LOGEXPIRATIONTIMEUNIT_DIRECTIVE "auditlog-logexpirationtimeunit"
  306. #define CONFIG_AUDITLOG_LOGEXPIRATIONTIMEUNIT_ATTRIBUTE "nsslapd-auditlog-logexpirationtimeunit"
  307. #define CONFIG_ACCESSLOG_LOGGING_ENABLED_DIRECTIVE "accesslog-logging-enabled"
  308. #define CONFIG_ACCESSLOG_LOGGING_ENABLED_ATTRIBUTE "nsslapd-accesslog-logging-enabled"
  309. #define CONFIG_ERRORLOG_LOGGING_ENABLED_DIRECTIVE "errorlog-logging-enabled"
  310. #define CONFIG_ERRORLOG_LOGGING_ENABLED_ATTRIBUTE "nsslapd-errorlog-logging-enabled"
  311. #define CONFIG_AUDITLOG_LOGGING_ENABLED_DIRECTIVE "auditlog-logging-enabled"
  312. #define CONFIG_AUDITLOG_LOGGING_ENABLED_ATTRIBUTE "nsslapd-auditlog-logging-enabled"
  313. #define CONFIG_ROOTDN_DIRECTIVE "rootdn"
  314. #define CONFIG_ROOTDN_ATTRIBUTE "nsslapd-rootdn"
  315. #define CONFIG_ROOTPW_DIRECTIVE "rootpw"
  316. #define CONFIG_ROOTPW_ATTRIBUTE "nsslapd-rootpw"
  317. #define CONFIG_ROOTPWSTORAGESCHEME_DIRECTIVE "rootpwstoragescheme"
  318. #define CONFIG_ROOTPWSTORAGESCHEME_ATTRIBUTE "nsslapd-rootpwstoragescheme"
  319. #define CONFIG_UPDATEDN_DIRECTIVE "updatedn"
  320. #define CONFIG_UPDATEDN_ATTRIBUTE "nsslapd-updatedn"
  321. #define CONFIG_UPDATEPW_DIRECTIVE "updatepw"
  322. #define CONFIG_UPDATEPW_ATTRIBUTE "nsslapd-updatepw"
  323. #define CONFIG_UPDATESSLCLIENT_DIRECTIVE "updateSSLclient"
  324. #define CONFIG_UPDATESSLCLIENT_ATTRIBUTE "nsslapd-updateSSLclient"
  325. #define CONFIG_AUDITFILE_DIRECTIVE "auditfile"
  326. #define CONFIG_AUDITFILE_ATTRIBUTE "nsslapd-auditlog"
  327. #define CONFIG_LASTMOD_DIRECTIVE "lastmod"
  328. #define CONFIG_LASTMOD_ATTRIBUTE "nsslapd-lastmod"
  329. #define CONFIG_INCLUDE_DIRECTIVE "include"
  330. #define CONFIG_INCLUDE_ATTRIBUTE "nsslapd-include"
  331. #define CONFIG_DYNAMICCONF_DIRECTIVE "dynamicconf"
  332. #define CONFIG_DYNAMICCONF_ATTRIBUTE "nsslapd-dynamicconf"
  333. #define CONFIG_USEROC_DIRECTIVE "useroc"
  334. #define CONFIG_USEROC_ATTRIBUTE "nsslapd-useroc"
  335. #define CONFIG_USERAT_DIRECTIVE "userat"
  336. #define CONFIG_USERAT_ATTRIBUTE "nsslapd-userat"
  337. #define CONFIG_SVRTAB_DIRECTIVE "svrtab"
  338. #define CONFIG_SVRTAB_ATTRIBUTE "nsslapd-svrtab"
  339. #ifndef _WIN32
  340. #define CONFIG_LOCALUSER_DIRECTIVE "localuser"
  341. #define CONFIG_LOCALUSER_ATTRIBUTE "nsslapd-localuser"
  342. #endif /* !_WIN32 */
  343. #define CONFIG_LOCALHOST_DIRECTIVE "localhost"
  344. #define CONFIG_LOCALHOST_ATTRIBUTE "nsslapd-localhost"
  345. #define CONFIG_PORT_DIRECTIVE "port"
  346. #define CONFIG_PORT_ATTRIBUTE "nsslapd-port"
  347. #define CONFIG_LISTENHOST_DIRECTIVE "listenhost"
  348. #define CONFIG_LISTENHOST_ATTRIBUTE "nsslapd-listenhost"
  349. #define CONFIG_SECURITY_DIRECTIVE "security"
  350. #define CONFIG_SECURITY_ATTRIBUTE "nsslapd-security"
  351. #define CONFIG_SSL3CIPHERS_DIRECTIVE "SSL3ciphers"
  352. #define CONFIG_SSL3CIPHERS_ATTRIBUTE "nsslapd-SSL3ciphers"
  353. #define CONFIG_ACCESSLOG_DIRECTIVE "accesslog"
  354. #define CONFIG_ACCESSLOG_ATTRIBUTE "nsslapd-accesslog"
  355. #define CONFIG_ERRORLOG_DIRECTIVE "errorlog"
  356. #define CONFIG_ERRORLOG_ATTRIBUTE "nsslapd-errorlog"
  357. #define CONFIG_INSTANCEDIR_DIRECTIVE "instancedir"
  358. #define CONFIG_INSTANCEDIR_ATTRIBUTE "nsslapd-instancedir"
  359. #define CONFIG_SECUREPORT_DIRECTIVE "secure-port"
  360. #define CONFIG_SECUREPORT_ATTRIBUTE "nsslapd-securePort"
  361. #define CONFIG_SECURELISTENHOST_DIRECTIVE "secure-listenhost"
  362. #define CONFIG_SECURELISTENHOST_ATTRIBUTE "nsslapd-securelistenhost"
  363. #define CONFIG_THREADNUMBER_DIRECTIVE "threadnumber"
  364. #define CONFIG_THREADNUMBER_ATTRIBUTE "nsslapd-threadnumber"
  365. #define CONFIG_MAXTHREADSPERCONN_DIRECTIVE "maxthreadsperconn"
  366. #define CONFIG_MAXTHREADSPERCONN_ATTRIBUTE "nsslapd-maxthreadsperconn"
  367. #if !defined(_WIN32) && !defined(AIX)
  368. #define CONFIG_MAXDESCRIPTORS_DIRECTIVE "maxdescriptors"
  369. #define CONFIG_MAXDESCRIPTORS_ATTRIBUTE "nsslapd-maxdescriptors"
  370. #endif /* !_WIN32 && ! AIX */
  371. #define CONFIG_RESERVEDESCRIPTORS_DIRECTIVE "reservedescriptors"
  372. #define CONFIG_RESERVEDESCRIPTORS_ATTRIBUTE "nsslapd-reservedescriptors"
  373. #define CONFIG_IDLETIMEOUT_DIRECTIVE "idletimeout"
  374. #define CONFIG_IDLETIMEOUT_ATTRIBUTE "nsslapd-idletimeout"
  375. #define CONFIG_IOBLOCKTIMEOUT_DIRECTIVE "ioblocktimeout"
  376. #define CONFIG_IOBLOCKTIMEOUT_ATTRIBUTE "nsslapd-ioblocktimeout"
  377. #define CONFIG_NTSYNCH_DIRECTIVE "ntsynch"
  378. #define CONFIG_NTSYNCH_ATTRIBUTE "nsslapd-NTSynch"
  379. #define CONFIG_NTSYNCHUSESSL_DIRECTIVE "ntsynchusessl"
  380. #define CONFIG_NTSYNCHUSESSL_ATTRIBUTE "nsslapd-NTSynch-SSL"
  381. #define CONFIG_NTSYNCHPORT_DIRECTIVE "ntsynch-port"
  382. #define CONFIG_NTSYNCHPORT_ATTRIBUTE "nsslapd-NTSynch-port"
  383. #define CONFIG_ACCESSCONTROL_DIRECTIVE "accesscontrol"
  384. #define CONFIG_ACCESSCONTROL_ATTRIBUTE "nsslapd-accesscontrol"
  385. #define CONFIG_GROUPEVALNESTLEVEL_DIRECTIVE "groupevalnestlevel"
  386. #define CONFIG_GROUPEVALNESTLEVEL_ATTRIBUTE "nsslapd-groupevalnestlevel"
  387. #define CONFIG_NAGLE_DIRECTIVE "nagle"
  388. #define CONFIG_NAGLE_ATTRIBUTE "nsslapd-nagle"
  389. #define CONFIG_PW_CHANGE_DIRECTIVE "pw_change"
  390. #define CONFIG_PW_CHANGE_ATTRIBUTE "passwordChange"
  391. #define CONFIG_PW_MUSTCHANGE_DIRECTIVE "pw_must_change"
  392. #define CONFIG_PW_MUSTCHANGE_ATTRIBUTE "passwordMustChange"
  393. #define CONFIG_PW_SYNTAX_DIRECTIVE "pw_syntax"
  394. #define CONFIG_PW_SYNTAX_ATTRIBUTE "passwordCheckSyntax"
  395. #define CONFIG_PW_MINLENGTH_DIRECTIVE "pw_minlength"
  396. #define CONFIG_PW_MINLENGTH_ATTRIBUTE "passwordMinLength"
  397. #define CONFIG_PW_EXP_DIRECTIVE "pw_exp"
  398. #define CONFIG_PW_EXP_ATTRIBUTE "passwordExp"
  399. #define CONFIG_PW_MAXAGE_DIRECTIVE "pw_maxage"
  400. #define CONFIG_PW_MAXAGE_ATTRIBUTE "passwordMaxAge"
  401. #define CONFIG_PW_MINAGE_DIRECTIVE "pw_minage"
  402. #define CONFIG_PW_MINAGE_ATTRIBUTE "passwordMinAge"
  403. #define CONFIG_PW_WARNING_DIRECTIVE "pw_warning"
  404. #define CONFIG_PW_WARNING_ATTRIBUTE "passwordWarning"
  405. #define CONFIG_PW_HISTORY_DIRECTIVE "pw_history"
  406. #define CONFIG_PW_HISTORY_ATTRIBUTE "passwordHistory"
  407. #define CONFIG_PW_INHISTORY_DIRECTIVE "pw_inhistory"
  408. #define CONFIG_PW_INHISTORY_ATTRIBUTE "passwordInHistory"
  409. #define CONFIG_PW_LOCKOUT_DIRECTIVE "pw_lockout"
  410. #define CONFIG_PW_LOCKOUT_ATTRIBUTE "passwordLockout"
  411. #define CONFIG_PW_STORAGESCHEME_DIRECTIVE "pw_storagescheme"
  412. #define CONFIG_PW_STORAGESCHEME_ATTRIBUTE "passwordStorageScheme"
  413. #define CONFIG_PW_MAXFAILURE_DIRECTIVE "pw_maxfailure"
  414. #define CONFIG_PW_MAXFAILURE_ATTRIBUTE "passwordMaxFailure"
  415. #define CONFIG_PW_UNLOCK_DIRECTIVE "pw_unlock"
  416. #define CONFIG_PW_UNLOCK_ATTRIBUTE "passwordUnlock"
  417. #define CONFIG_PW_LOCKDURATION_DIRECTIVE "pw_lockduration"
  418. #define CONFIG_PW_LOCKDURATION_ATTRIBUTE "passwordLockoutDuration"
  419. #define CONFIG_PW_RESETFAILURECOUNT_DIRECTIVE "pw_resetfailurecount"
  420. #define CONFIG_PW_RESETFAILURECOUNT_ATTRIBUTE "passwordResetFailureCount"
  421. #define CONFIG_ACCESSLOG_BUFFERING_DIRECTIVE "logbuffering"
  422. #define CONFIG_ACCESSLOG_BUFFERING_ATTRIBUTE "nsslapd-accesslog-logbuffering"
  423. #define CONFIG_CHANGELOG_DIR_DIRECTIVE "changelogdir"
  424. #define CONFIG_CHANGELOG_DIR_ATTRIBUTE "nsslapd-changelogdir"
  425. #define CONFIG_CHANGELOG_SUFFIX_DIRECTIVE "changelogsuffix"
  426. #define CONFIG_CHANGELOG_SUFFIX_ATTRIBUTE "nsslapd-changelogsuffix"
  427. #define CONFIG_CHANGELOG_MAXENTRIES_DIRECTIVE "changelogmaxextries"
  428. #define CONFIG_CHANGELOG_MAXENTRIES_ATTRIBUTE "nsslapd-changelogmaxentries"
  429. #define CONFIG_CHANGELOG_MAXAGE_DIRECTIVE "changelogmaxage"
  430. #define CONFIG_CHANGELOG_MAXAGE_ATTRIBUTE "nsslapd-changelogmaxage"
  431. #define CONFIG_RETURN_EXACT_CASE_DIRECTIVE "return_exact_case"
  432. #define CONFIG_RESULT_TWEAK_DIRECTIVE "result_tweak"
  433. #define CONFIG_REFERRAL_MODE_DIRECTIVE "referralmode"
  434. #define CONFIG_ATTRIBUTE_NAME_EXCEPTION_DIRECTIVE "attribute_name_exceptions"
  435. #define CONFIG_MAXBERSIZE_DIRECTIVE "maxbersize"
  436. #define CONFIG_VERSIONSTRING_DIRECTIVE "versionstring"
  437. #define CONFIG_ENQUOTE_SUP_OC_DIRECTIVE "enquote_sup_oc"
  438. #define CONFIG_ENQUOTE_SUP_OC_ATTRIBUTE "nsslapd-enquote_sup_oc"
  439. #define CONFIG_BASEDN_DIRECTIVE "certmap-basedn"
  440. #define CONFIG_BASEDN_ATTRIBUTE "nsslapd-certmap-basedn"
  441. %HashParametersName = ();
  442. # The following hash displays only general server parameters to migrate under cn=config
  443. %GeneralSrvParamToMigrate = (
  444. 'accesscontrol' => 'nsslapd-accesscontrol',
  445. 'errorlog-logging-enabled' => 'nsslapd-errorlog-logging-enabled',
  446. 'accesslog-logging-enabled' => 'nsslapd-accesslog-logging-enabled',
  447. 'auditlog-logging-enabled' => 'nsslapd-auditlog-logging-enabled',
  448. 'logbuffering' => 'nsslapd-accesslog-logbuffering',
  449. 'accesslog-logexpirationtime' => 'nsslapd-accesslog-logexpirationtime',
  450. 'accesslog-logexpirationtimeunit' => 'nsslapd-accesslog-logexpirationtimeunit',
  451. 'accesslog-maxlogdiskspace' => 'nsslapd-accesslog-logmaxdiskspace',
  452. 'accesslog-minfreediskspace' => 'nsslapd-accesslog-logminfreediskspace',
  453. 'accesslog-logrotationtime' => 'nsslapd-accesslog-logrotationtime',
  454. 'accesslog-logrotationtimeunit' => 'nsslapd-accesslog-logrotationtimeunit',
  455. 'accesslog-maxlogsize' => 'nsslapd-accesslog-maxlogsize',
  456. 'accesslog-maxnumoflogsperdir' => 'nsslapd-accesslog-maxLogsPerDir',
  457. 'auditlog-logexpirationtime' => 'nsslapd-auditlog-logexpirationtime',
  458. 'auditlog-logexpirationtimeunit' => 'nsslapd-auditlog-logexpirationtimeunit',
  459. 'auditlog-maxlogdiskspace' => 'nsslapd-auditlog-logmaxdiskspace',
  460. 'auditlog-minfreediskspace' => 'nsslapd-auditlog-logminfreediskspace',
  461. 'auditlog-logrotationtime' => 'nsslapd-auditlog-logrotationtime',
  462. 'auditlog-logrotationtimeunit' => 'nsslapd-auditlog-logrotationtimeunit',
  463. 'auditlog-maxlogsize' => 'nsslapd-auditlog-maxlogsize',
  464. 'auditlog-maxnumoflogsperdir' => 'nsslapd-auditlog-maxLogsPerDir',
  465. 'certmap-basedn' => 'nsslapd-certmap-basedn',
  466. 'enquote_sup_oc' => 'nsslapd-enquote-sup-oc',
  467. 'loglevel' => 'nsslapd-errorlog-level',
  468. 'errorlog-logexpirationtime' => 'nsslapd-errorlog-logexpirationtime',
  469. 'errorlog-logexpirationtimeunit' => 'nsslapd-errorlog-logexpirationtimeunit',
  470. 'errorlog-maxlogdiskspace' => 'nsslapd-errorlog-logmaxdiskspace',
  471. 'errorlog-minfreediskspace' => 'nsslapd-errorlog-logminfreediskspace',
  472. 'errorlog-logrotationtime' => 'nsslapd-errorlog-logrotationtime',
  473. 'errorlog-logrotationtimeunit' => 'nsslapd-errorlog-logrotationtimeunit',
  474. 'errorlog-maxlogsize' => 'nsslapd-errorlog-maxlogsize',
  475. 'errorlog-maxnumoflogsperdir' => 'nsslapd-errorlog-maxlogsperdir',
  476. 'idletimeout' => 'nsslapd-idletimeout',
  477. 'ioblocktimeout' => 'nsslapd-ioblocktimeout',
  478. 'lastmod' => 'nsslapd-lastmod',
  479. 'listenhost' => 'nsslapd-listenhost',
  480. 'maxdescriptors' => 'nsslapd-maxdescriptors',
  481. 'referral' => 'nsslapd-referral',
  482. 'reservedescriptors' => 'nsslapd-reservedescriptors',
  483. 'rootpwstoragescheme' => 'nsslapd-rootpwstoragescheme',
  484. 'schemacheck' => 'nsslapd-schemacheck',
  485. 'secure-port' => 'nsslapd-securePort',
  486. 'security' => 'nsslapd-security',
  487. 'sizelimit' => 'nsslapd-sizelimit',
  488. 'SSL3ciphers' => 'nsslapd-SSL3ciphers',
  489. 'timelimit' => 'nsslapd-timelimit',
  490. 'pw_change' => 'passwordChange',
  491. 'pw_syntax' => 'passwordCheckSyntax',
  492. 'pw_exp' => 'passwordExp',
  493. 'pw_history' => 'passwordHistory',
  494. 'pw_inhistory' => 'passwordInHistory',
  495. 'pw_lockout' => 'passwordLockout',
  496. 'pw_lockduration' => 'passwordLockoutDuration',
  497. 'pw_maxage' => 'passwordMaxAge',
  498. 'pw_maxfailure' => 'passwordMaxFailure',
  499. 'pw_minage' => 'passwordMinAge',
  500. 'pw_minlength' => 'passwordMinLength',
  501. 'pw_must_change' => 'passwordMustChange',
  502. 'pw_resetfailurecount' => 'passwordResetFailureCount',
  503. 'pw_storagescheme' => 'passwordStorageScheme',
  504. 'pw_unlock' => 'passwordUnlock',
  505. 'pw_warning' => 'passwordWarning'
  506. );
  507. # the following hash displays global parameters related to database stored under cn=config,cn=ldbm database,cn=plugins,cn=config
  508. %GlobalConfigLDBMparamToMigrate = (
  509. 'allidsthreshold' => 'nsslapd-allidsthreshold',
  510. 'lookthroughlimit' => 'nsslapd-lookthroughlimit',
  511. 'mode' => 'nsslapd-mode',
  512. 'dbcachesize' => 'nsslapd-dbcachesize'
  513. );
  514. # the following hash displays specific parameters to each backends and stored under cn=DBname,cn=ldbm database,cn=plugins,cn=config
  515. %LDBMparamToMigrate = (
  516. 'cachesize' => 'nsslapd-cachesize',
  517. 'readonly' => 'nsslapd-readonly'
  518. );
  519. %stdIncludes = (
  520. "${oldConfDir}slapd.at.conf", "\n",
  521. "${oldConfDir}slapd.oc.conf", "\n",
  522. "${oldConfDir}java-object-schema.conf", "\n",
  523. "${oldConfDir}ns-admin-schema.conf", "\n",
  524. "${oldConfDir}ns-calendar-schema.conf", "\n",
  525. "${oldConfDir}ns-certificate-schema.conf", "\n",
  526. "${oldConfDir}ns-common-schema.conf", "\n",
  527. "${oldConfDir}ns-compass-schema.conf", "\n",
  528. "${oldConfDir}ns-delegated-admin-schema.conf", "\n",
  529. "${oldConfDir}ns-directory-schema.conf", "\n",
  530. "${oldConfDir}ns-legacy-schema.conf", "\n",
  531. "${oldConfDir}ns-mail-schema.conf", "\n",
  532. "${oldConfDir}ns-mcd-browser-schema.conf", "\n",
  533. "${oldConfDir}ns-mcd-config-schema.conf", "\n",
  534. "${oldConfDir}ns-mcd-li-schema.conf", "\n",
  535. "${oldConfDir}ns-mcd-mail-schema.conf", "\n",
  536. "${oldConfDir}ns-media-schema.conf", "\n",
  537. "${oldConfDir}ns-mlm-schema.conf", "\n",
  538. "${oldConfDir}ns-msg-schema.conf", "\n",
  539. "${oldConfDir}ns-netshare-schema.conf", "\n",
  540. "${oldConfDir}ns-news-schema.conf", "\n",
  541. "${oldConfDir}ns-proxy-schema.conf", "\n",
  542. "${oldConfDir}ns-value-schema.conf", "\n",
  543. "${oldConfDir}ns-wcal-schema.conf", "\n",
  544. "${oldConfDir}ns-cos-schema.conf", "\n",
  545. "${oldConfDir}ns-web-schema.conf", "\n"
  546. );
  547. %userDefinedConfigFiles = (
  548. "slapd.conf", "\n",
  549. "slapd.ldbm.conf", "\n",
  550. "slapd.user_at.conf", "\n",
  551. "slapd.user_oc.conf", "\n",
  552. "ns-schema.conf", "\n"
  553. );
  554. $CIS_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.15" ;
  555. $TELEPHONE_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.50" ;
  556. $DN_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.12" ;
  557. $CES_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.26" ;
  558. $INT_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.27" ;
  559. $BIN_SYNTAX_OID = "1.3.6.1.4.1.1466.115.121.1.5" ;
  560. %allowedPlugins = (
  561. "cis", $CIS_SYNTAX_OID,
  562. "tel", $TELEPHONE_SYNTAX_OID,
  563. "dn", $DN_SYNTAX_OID,
  564. "ces", $CES_SYNTAX_OID,
  565. "int", $INT_SYNTAX_OID,
  566. "bin", $BIN_SYNTAX_OID
  567. );
  568. %allowedModifiers = (
  569. "single", "SINGLE-VALUE"
  570. );
  571. # "override" is not supported anymore and "operational" cannot be used in user defined attribute.
  572. @oldSuffixes = () ; # array of old suffixes (with "o=netscaperoot" if presents)
  573. # link beetwen the name of the suffix and its associated DBname
  574. %DBNAMES = () ;
  575. %DBDirectory = () ;
  576. %oldhash = () ;
  577. # list of standard plugin's in version 4
  578. %stdPlugins = (
  579. "7-bit check" => "\n",
  580. "binary syntax" => "\n",
  581. "case exact string syntax" => "\n",
  582. "case ignore string syntax" => "\n",
  583. "distinguished name syntax" => "\n",
  584. "integer syntax" => "\n",
  585. "internationalization plugin" => "\n",
  586. "referential integrity postoperation" => "\n",
  587. "telephone syntax" => "\n",
  588. "uid uniqueness" => "\n"
  589. );
  590. # list of standard indexes configured out of the box in version 4
  591. %stdIndex = (
  592. 'aci', "\n",
  593. 'changenumber', "\n",
  594. 'copiedfrom', "\n",
  595. 'dncomp', "\n",
  596. 'entrydn', "\n",
  597. 'numsubordinates', "\n",
  598. 'objectclass', "\n",
  599. 'parentid', "\n"
  600. );
  601. # list of user added Plugin's. In the new version, they 'll need to be recompiled
  602. @badPlugins = () ;
  603. %newIndex = () ;
  604. %User_oc = () ;
  605. # push objectnames as they are encountered in config files.
  606. @User_oc_names = () ;
  607. %User_at = () ;
  608. #Usage parameters
  609. $USER_OC_FILE_MODIFIED = 0 ; # 0 if user don't want to modify LDIF objectclasses before processing, 1 else
  610. $USER_AT_FILE_MODIFIED = 0 ;
  611. $INDEX_FILE_MODIFIED = 0 ;
  612. # get the version of the DS to migrate
  613. ($oldVersion, $oldMinor) = &getVersion($oldDir, $oldversionstr);
  614. # get the version of the new DS
  615. ($Version, $Minor) = &getVersion($root);
  616. # get old LIB_PATH
  617. $old_libpath = &getLibPath($oldDir, $oldVersion, $oldMinor);
  618. # get new LIB_PATH
  619. $new_libpath = &getLibPath($root, $Version, $Minor);
  620. # Shutdown the legacy Directory instance
  621. printTrace("\nShutdown the legacy Directory Server instance: ${oldHome}",0);
  622. &stopServer($oldDir, 'slapd-'.$oldname);
  623. # compare configuration files with the standard ones
  624. CompareStdConfigFiles() ;
  625. die "\n\n The version of the product you want to migrate is not a 4.x Netscape Directory Server\n" unless ($oldVersion == 4) ;
  626. FillHashParametersName() ;
  627. ############### Connect to the New LDAP Directory Server ######################
  628. $ENV{"$LIB_PATH"} = $new_libpath;
  629. my $LDAPservername = &getLDAPservername();
  630. die "\n Migration aborted. Make sure your Old and New Directory Servers are installed on the same machine \n" if ( $LDAPservername == -1 );
  631. $conn = new Mozilla::LDAP::Conn($LDAPservername,$newport,$rootDN,$rootpwd) or die "\n Can't contact the $Version.$Minor LDAP server: $LDAPservername\n";
  632. # continue if the connection to new LDAP server is successful !
  633. printTrace("\nConnected to $Version.$Minor LDAP server\n",0) ;
  634. # get the uid and gid of the new slapd user
  635. ($localuser, $newuid, $newgid) = getuid_gid();
  636. # get the uid and gid of the old slapd user
  637. ($oldlocaluser, $olduid, $oldgid) = getolduid_gid();
  638. # backup new configuration files in <new_root_server>/slapd-instancename/config
  639. printTrace("\nBackup $serverHome${PATHSEP}config on $serverHome${PATHSEP}config_backup ...",0);
  640. &backupConfigFiles();
  641. # Parse the main configuration file: slapd.conf
  642. printTrace("\nParse the configuration file: $oldSlapdConf...",0);
  643. ParseSlapdConf("< ${oldSlapdConf}");
  644. #migrate key/cert databases
  645. printTrace("\nMigrate key/cert databases...",0);
  646. &MigrateSSL();
  647. # Update parameters : general server parameters, global LDBM parameter, specific backend parameters
  648. printTrace("\nUpdate general server parameters...",0);
  649. $conn = new Mozilla::LDAP::Conn($LDAPservername,$newport,$rootDN,$rootpwd) or die "\n Can't contact the $Version.$Minor LDAP server: $LDAPservername\n";
  650. AddGeneralParameters();
  651. printTrace("\nUpdate global LDBM parameters...",0);
  652. AddGeneralLDBMParameters();
  653. printTrace("\nUpdate specific backend parameters...",0);
  654. AddSpecificLDBMParameters();
  655. ##### FOR TESTING PURPOSE ONLY ########
  656. #
  657. #testIndexUpdating();
  658. #
  659. #######################################
  660. # Migrate some entries contained in the old dse.ldif, and migrate certmap.conf
  661. &MigrateDSE() ;
  662. &MigrateCertmap() ;
  663. # update new attribute definitions
  664. LDAPmodify_User_at();
  665. # update new object classes definitions
  666. LDAPmodify_User_oc();
  667. # add new indexes to each backends
  668. LDAPmodify_Indexes();
  669. # migrate Plug'ins parameters (enable attribute, and arguments)
  670. LDAPmodify_stdPlugin();
  671. ################## Close the connection to new LDAP Server #####################
  672. $conn->close;
  673. ################## stop the new instance and Export/Import the data, restart the server ##################
  674. if (%DBNAMES) {
  675. &stopServer($root,'slapd-'.$newname);
  676. if ($olddatadir) {
  677. printTrace("\nold data directory $olddatadir...",0) ;
  678. $ldif_rep = "$olddatadir${PATHSEP}";
  679. } else {
  680. printTrace("\ndata processing...",0) ;
  681. # migrate data for each suffix: old -> LDIF files
  682. &db2ldif($oldSlapdConf);
  683. }
  684. # migrate LDIF data to the new database: LDIF -> new
  685. &manyLdif2db();
  686. &startServer();
  687. }
  688. else {
  689. printTrace("\nThere no old non-standard suffixes to migrate",0);
  690. }
  691. printMsg("\n\n ****** End of migration ******\n\n");
  692. close(LOGFILE);
  693. ###########################################################################################
  694. # get input users
  695. sub getParameters {
  696. my $exit = 0 ;
  697. my $i = 0;
  698. my $pwdfile= "";
  699. while ($i <= $#ARGV) {
  700. if ( "$ARGV[$i]" eq "-D" ) { # directory manager
  701. if (! $rootDN) {
  702. $rootDN = $ARGV[++$i] ;
  703. }
  704. else {
  705. &usage() ;
  706. exit(1);
  707. }
  708. } elsif ("$ARGV[$i]" eq "-w") { # password
  709. if (! $rootpwd) {
  710. $rootpwd = $ARGV[++$i] ;
  711. }
  712. else {
  713. &usage() ;
  714. exit(1);
  715. }
  716. } elsif ("$ARGV[$i]" eq "-j") { # password file
  717. if (! $pwdfile) {
  718. $pwdfile = $ARGV[++$i] ;
  719. }
  720. else {
  721. &usage() ;
  722. exit(1);
  723. }
  724. } elsif ("$ARGV[$i]" eq "-o") { # old instance path
  725. if (! $oldHome ) {
  726. $oldHome = $ARGV[++$i] ;
  727. grep { s@\\@/@g } $oldHome if $isNT ;
  728. if ($oldHome =~ /[\"]?(.*)?[\"]?/) { $oldHome = $1 ; }
  729. if ($oldHome =~ m@^(.*)/([^-/]*)-([^/]*)[/]?$@) {
  730. $oldDir = $1 ;
  731. $type = $2 ;
  732. $oldname = $3 ;
  733. if ($isNT) {
  734. $oldDir = lc($oldDir) ;
  735. $type = lc($type) ;
  736. $oldname = lc($oldname) ;
  737. $oldHome = lc($oldHome) ;
  738. grep { s@/@\\@g } $oldDir ;
  739. grep { s@/@\\@g } $oldHome ;
  740. }
  741. }
  742. else {
  743. print("\nThe old instance path is not correct. It must be like slapd-instancename");
  744. &usage();
  745. exit(1);
  746. }
  747. }
  748. else {
  749. &usage() ;
  750. exit(1);
  751. }
  752. } elsif ("$ARGV[$i]" eq "-n") { # new instance path
  753. if (! $serverHome ) {
  754. $serverHome = $ARGV[++$i] ;
  755. grep { s@\\@/@g } $root if $isNT ;
  756. grep { s@\\@/@g } $serverHome if $isNT ;
  757. if ($serverHome =~ /[\"]?(.*)?[\"]?/) { $serverHome = $1 ; }
  758. if ($serverHome =~ m@^(.*?)/?([^/-]*)-([^/]*)[/]?$@) {
  759. $root = $1 if ($1);
  760. $type = $2 ;
  761. $newname = $3 ;
  762. if ($isNT) {
  763. $root = lc($root) ;
  764. $type = lc($type) ;
  765. $newname = lc($newname) ;
  766. $serverHome = lc($serverHome) ;
  767. grep { s@/@\\@g } $root ;
  768. grep { s@/@\\@g } $serverHome ;
  769. }
  770. }
  771. else {
  772. print("\nThe new instance path is not correct. It must be like slapd-instancename");
  773. &usage();
  774. exit(1);
  775. }
  776. }
  777. else {
  778. &usage() ;
  779. exit(1);
  780. }
  781. } elsif ("$ARGV[$i]" eq "-p") { # new DS port
  782. if (! $newport ) {
  783. $newport = $ARGV[++$i] ;
  784. }
  785. else {
  786. &usage() ;
  787. exit(1);
  788. }
  789. } elsif ("$ARGV[$i]" eq "-d") { # old instance LDIF data dir
  790. if (! $olddatadir ) {
  791. $olddatadir = $ARGV[++$i] ;
  792. }
  793. else {
  794. &usage() ;
  795. exit(1);
  796. }
  797. } elsif ("$ARGV[$i]" eq "-v") { # old version
  798. if (! $oldversionstr ) {
  799. $oldversionstr = $ARGV[++$i] ;
  800. }
  801. else {
  802. &usage() ;
  803. exit(1);
  804. }
  805. } elsif ("$ARGV[$i]" eq "-t") { # TRACELEVEL
  806. my $value = $ARGV[++$i] ;
  807. if ($value =~ /[0-3]/) {
  808. $TRACELEVEL = $value ;
  809. }
  810. else {
  811. print("\nThe tracelevel must belong to 0..3 interval");
  812. &usage();
  813. exit();
  814. }
  815. } elsif ("$ARGV[$i]" eq "-noinput") { # no user interventions during processing
  816. $NO_INPUT_USER = 1 ;
  817. } elsif ("$ARGV[$i]" eq "-L") { # migration logfile
  818. $LogFileReport = $ARGV[++$i] ;
  819. }
  820. else {
  821. print("\nThe option $ARGV[$i] is not recognized");
  822. &usage() ;
  823. exit(1);
  824. }
  825. $i++;
  826. }
  827. if (! $rootDN) {
  828. print("\nThe rootDN is missing");
  829. $exit = 1;
  830. }
  831. if ($pwdfile ne "") {
  832. # Open file and get the password
  833. unless (open (RPASS, $pwfile)) {
  834. die "Error, cannot open password file $passwdfile\n";
  835. }
  836. $rootpwd = <RPASS>;
  837. chomp($rootpwd);
  838. close(RPASS);
  839. } elsif ($rootpwd eq "-"){
  840. # Read the password from terminal
  841. die "The '-w -' option requires an extension library (Term::ReadKey) which is not\n",
  842. "part of the standard perl distribution. If you want to use it, you must\n",
  843. "download and install the module. You can find it at\n",
  844. "http://www.perl.com/CPAN/CPAN.html\n";
  845. # Remove the previous line and uncomment the following 6 lines once you have installed Term::ReadKey module.
  846. # use Term::ReadKey;
  847. # print "Bind Password: ";
  848. # ReadMode('noecho');
  849. # $rootpwd = ReadLine(0);
  850. # chomp($rootpwd);
  851. # ReadMode('normal');
  852. }
  853. if (! $rootpwd) {
  854. print("\nThe rootpwd is missing");
  855. $exit = 1 ;
  856. }
  857. if (! $newport) {
  858. print("\nThe port is missing");
  859. $exit = 1;
  860. }
  861. if (! $serverHome) {
  862. print("\nThe new instance path is missing");
  863. $exit = 1;
  864. }
  865. if (! $oldHome) {
  866. print("\nThe old instance path is missing");
  867. $exit = 1;
  868. }
  869. if ((! $LogFileReport) && $serverHome) {
  870. ($sec, $min, $hour, $dd, $mm, $yy) = &GetTime();
  871. $LogFileReport = "${serverHome}${PATHSEP}logs${PATHSEP}Migration_${dd}${mm}${yy}_${hour}${min}${sec}.log";
  872. }
  873. if ($exit) {
  874. &usage() ;
  875. exit(1);
  876. }
  877. }
  878. ###############################################################################
  879. # This subroutine is used to parse the slapd.conf configuration file and migrate specific parameters contained in it
  880. sub ParseSlapdConf {
  881. my $oldsrc = shift;
  882. my $NumLine = 0 ;
  883. # read the old conf file into a hash table
  884. open( OLDSRC, $oldsrc ) || die "Can't open $oldsrc: $!: ";
  885. LINE: while ( <OLDSRC> ) {
  886. $NumLine++ ;
  887. printTrace("\nLine: $_",4) ;
  888. if (/^\s*\#/) { # skip comments
  889. printTrace("\n# ",4) ;
  890. next LINE;
  891. }
  892. if (/^\s*$/) { # skip blank lines
  893. printTrace("\nBLANK LINE",4);
  894. next LINE;
  895. } elsif (/^suffix\s+/i) {
  896. chomp($_) ;
  897. CheckSuffix($_);
  898. } elsif (/^plugin/i) {
  899. printTrace("\nPLUGIN",4);
  900. chomp($_);
  901. if (! &isAStandardPlugin($_)) {
  902. push @badPlugins, $_;
  903. }
  904. else {
  905. my $Plugin = $_ ;
  906. if (! &ParsePlugin($_,$NumLine)) {
  907. printMsg("\nLine $NumLine, syntax error of the plugin:\n$Plugin");
  908. }
  909. }
  910. } elsif (/^include\s+[\"]?(.*?)[\"]?\s*$/i) {
  911. # strip leading and trailing "
  912. my $include_file = $1 ;
  913. grep { s@/@\\@g } $include_file if $isNT;
  914. if (! &isAStandardInclude($include_file)) {
  915. printTrace("\nFILE: $1 NOT STANDARD",4) ;
  916. &ParseConfigurationFile($include_file);
  917. printTrace("\nEXIT ParseConfigurationFile: $include_file",4) ;
  918. }
  919. } elsif (/^userat\s+[\"]?(.*?)[\"]?\s*$/i) {
  920. printTrace("\nuserat: $1",4);
  921. my $at_file = $1 ;
  922. grep { s@/@\\@g } $at_file if $isNT;
  923. # Parse user defined attributes
  924. &ParseAttributesFile($at_file);
  925. } elsif (/^useroc\s+[\"]?(.*?)[\"]?\s*$/i) {
  926. printTrace("\nuseroc: $1",4);
  927. my $oc_file = $1 ;
  928. grep { s@/@\\@g } $oc_file if $isNT;
  929. # Parse user defined object classes
  930. &ParseObjectClassesFile($oc_file);
  931. } elsif (/^dynamicconf\s+[\"]?(.*?)[\"]?\s*$/i){
  932. printTrace("\ndynamicconf: $1",4);
  933. my $dynamiconf_file = $1 ;
  934. grep { s@/@\\@g } $dynamiconf_file if $isNT;
  935. # Parse dynamic configuration file (e-g slapd.ldbm.conf)
  936. &ParseConfigurationFile($dynamiconf_file);
  937. } elsif (/^\s*(\S+)\s+[\"]?(.*?)[\"]?\s*$/) {
  938. printTrace("\nParseParameters: $1",4);
  939. # Parse parameters and record the associated value in %oldhash
  940. &ParseParameters($1,$2,$NumLine);
  941. } else {
  942. printTrace("\nUnknown format of configuration data: $_",0); }
  943. }
  944. close(OLDSRC);
  945. }
  946. #############################################################################
  947. # return 1 if the suffix already exists, 0 else
  948. sub existSuffix {
  949. my $suffixname = shift ;
  950. my $nsuffix = normalizeDN($suffixname);
  951. my $entry = $conn->search("cn=mapping tree,cn=config", "one", "(|(cn=\"$suffixname\")(cn=\"$nsuffix\"))");
  952. return 1 if ($entry) ;
  953. my $cpt = 5;
  954. my $errorCode = $conn->getErrorCode();
  955. while (($errorCode eq $LDAP_SERVER_UNREACHABLE) && $cpt && (! $entry)) {
  956. printTrace("\ntry to reconnect to search cn=\"$suffixname\",cn=mapping tree,cn=config", 1);
  957. $conn = new Mozilla::LDAP::Conn($LDAPservername,$newport,$rootDN,$rootpwd) or die "\n Unable to contact the $Version.$Minor LDAP server: $LDAPservername\n";
  958. $entry = $conn->search("cn=mapping tree,cn=config", "one", "(|(cn=\"$suffixname\")(cn=\"$nsuffix\"))");
  959. $errorCode = $conn->getErrorCode();
  960. $cpt--;
  961. }
  962. return 1 if ($entry) ;
  963. return 0 ;
  964. }
  965. # return the name of the backend if it has been successfully created, 0 else
  966. sub createBackend {
  967. my $suffixname = shift ;
  968. my $backend = "MigratedDB_0" ;
  969. my $NbRetry = 1 ;
  970. my $entry = $conn->search("cn=$backend,cn=ldbm database,cn=plugins,cn=config ", "base","objectclass=*") ;
  971. while ($entry) {
  972. # try to find another name for the backend
  973. $backend = "MigratedDB_$NbRetry" ;
  974. $entry = $conn->search("cn=$backend,cn=ldbm database,cn=plugins,cn=config ", "base","objectclass=*") ;
  975. $NbRetry++;
  976. }
  977. # normally I should have a unique name for the backend
  978. my $suffixarg = "nsslapd-suffix" ;
  979. $entry = $conn->newEntry() ;
  980. $entry->setDN("cn=$backend,cn=ldbm database,cn=plugins,cn=config");
  981. $entry->setValues("objectclass", "top", "extensibleObject", "nsBackendInstance" );
  982. $entry->setValues("cn", $backend );
  983. $entry->setValues($suffixarg, $suffixname );
  984. my $res = $conn->add($entry) ;
  985. if ($res) {
  986. return $backend ;
  987. }
  988. else {
  989. return 0 ;
  990. }
  991. }
  992. # return 1, if add the new entry in the mapping tree, else 0
  993. sub AddEntryInMappingTree {
  994. my $backend = shift ;
  995. my $entry = $conn->search("cn=$backend,cn=ldbm database,cn=plugins,cn=config ", "base","objectclass=*") ;
  996. if ($entry) {
  997. printTrace("\nAddEntry in progress ...",4) ;
  998. my $suffixarg = "nsslapd-suffix" ;
  999. my $statearg = "nsslapd-state" ;
  1000. my $backendarg= "nsslapd-backend";
  1001. my $suffixname = $entry->{$suffixarg}[0];
  1002. $entry = $conn->newEntry() ;
  1003. $entry->setDN("cn=\"$suffixname\",cn=mapping tree,cn=config") ;
  1004. $entry->setValues("objectclass", "top", "extensibleObject", "nsMappingTree" );
  1005. $entry->setValues("cn", "\"$suffixname\"");
  1006. $entry->setValues($statearg, "backend");
  1007. $entry->setValues($backendarg, $backend);
  1008. return $conn->add($entry);
  1009. }
  1010. else {
  1011. printTrace("\nNo AddEntry processed for $backend",4);
  1012. return 0 ;
  1013. }
  1014. }
  1015. # Treat the case where the suffix is "o=NetscapeRoot"
  1016. sub CheckSuffix {
  1017. my $suffix = shift ;
  1018. my $suffixname ;
  1019. my $expLdif;
  1020. my $confirm = "No";
  1021. my $dest = "$serverHome${PATHSEP}db_backup" ;
  1022. my $newSlapdExecDir = "$root${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server";
  1023. if (!(/^suffix\s+\"?(.*?)\"?\s*$/i)) {
  1024. printMsg("Syntax error of the suffix: $suffix");
  1025. return 0 ;
  1026. }
  1027. else {
  1028. $suffixname = $1 ;
  1029. }
  1030. if (/^suffix\s+\"?\s*o=netscaperoot\s*\"?\s*$/i) {
  1031. printTrace("\nFor the suffix o=NetscapeRoot, we do nothing",1);
  1032. # treat the case where the suffix is "o=NetscapeRoot"
  1033. }
  1034. else {
  1035. push @oldSuffixes, $_;
  1036. # check if the suffix already exists in the new DS target
  1037. if (! existSuffix($suffixname)) {
  1038. printTrace("\n\nSuffix $suffixname doesn't exist",1) ;
  1039. # create a new backend with the name of the suffix preceded by MigratedDB_
  1040. my $backend = createBackend($suffixname) ;
  1041. if ($backend) {
  1042. printTrace("\nBackend: $backend has been created !!!",1);
  1043. # if the creation of the backend is ok, we add a new entry in the mapping tree
  1044. if (AddEntryInMappingTree($backend)) {
  1045. # We add the association dbname->suffix in the hash %DBNAMES
  1046. $DBNAMES{$suffixname} = $backend ;
  1047. # get the db filename
  1048. $entry = $conn->search("cn=$backend,cn=ldbm database,cn=plugins,cn=config ", "base","objectclass=*") ;
  1049. my $dirarg = "nsslapd-directory";
  1050. $DBDirectory{$backend} = $entry->{$dirarg}[0];
  1051. printTrace("\nThe relation $backend->$suffixname has been added to the mapping tree",2);
  1052. }
  1053. else {
  1054. printMsg("\nCOULD NOT ADD ENTRY: $backend->$suffixname IN MAPPINGTREE");
  1055. }
  1056. }
  1057. else {
  1058. printMsg("\nCOULD NOT CREATE BACKEND: $backend");
  1059. }
  1060. }
  1061. else {
  1062. printMsg("\n\nSuffix: $suffixname already exists");
  1063. # the suffix already exists in the new DS
  1064. printMsg("\nMigration will overwrite existing database");
  1065. printMsg("\nDo you want to continue Yes/No [No] ?") ;
  1066. my $answer = <STDIN> ;
  1067. if ($answer =~ /y|yes/i) {
  1068. my $nsuffix = normalizeDN($suffixname);
  1069. my $my_entry = $conn->search("cn=mapping tree,cn=config", "one", "(|(cn=\"$suffixname\")(cn=\"$nsuffix\"))");
  1070. my $backend = $my_entry->{"nsslapd-backend"}[0];
  1071. my $backend_entry = $conn->search("cn=$backend,cn=ldbm database,cn=plugins,cn=config ", "base","objectclass=*") ;
  1072. printMsg("Do you want to export the existing data Yes/No [Yes] ?");
  1073. my $answer = <STDIN> ;
  1074. if (!($answer =~ /n|no/i)) {
  1075. mkdir $dest, 0700 unless (-d $dest);
  1076. $expLdif = "$dest${PATHSEP}$backend.ldif";
  1077. while (!($confirm =~ /y|yes/i)) {
  1078. printMsg("\nEnter the full pathname of the file [$expLdif]:") ;
  1079. $answer = <STDIN> ;
  1080. chomp($expLdif = $answer) unless ($answer eq "\n");
  1081. printMsg("\nExisting data will be exported under $expLdif");
  1082. printMsg("\nContinue Yes/No [No] ?");
  1083. $confirm = <STDIN>;
  1084. }
  1085. $ENV{"$LIB_PATH"}=$new_libpath;
  1086. chdir($newSlapdExecDir) or die "\nCould not change directory to $newSlapdExecDir: $!\n";
  1087. printTrace("\nNow backing up database $CN in $expLdif\n",0);
  1088. &stopServer($root,'slapd-'.$newname);
  1089. &newinst_db2ldif($expLdif, $suffixname, $serverHome);
  1090. &startServer();
  1091. }
  1092. # We add the association dbname->suffix in the hash %DBNAMES
  1093. $DBNAMES{$suffixname} = $backend ;
  1094. my $dirarg = "nsslapd-directory";
  1095. $DBDirectory{$backend} = $backend_entry->{$dirarg}[0];
  1096. printTrace("\nThe relation $backend->$suffixname has been added to the mapping tree",2);
  1097. }
  1098. }
  1099. return 1 ;
  1100. }
  1101. }
  1102. #############################################################################
  1103. # Usefull to know the standard configuration
  1104. sub isAStandardPlugin {
  1105. my $line = shift;
  1106. chomp($line);
  1107. printTrace("\nStdPlugin?: $line",4);
  1108. if ($line =~ /^plugin\s+(database|extendop|preoperation|postoperation|matchingrule|syntax)\s+(on|off)\s+\"(.*?)\"\s+\"(.*?)\"\s+(\S+)(.*)$/i) {
  1109. # $1 = <type>, $2 = <on|off>, $3 = <name>, $4 = <pathname>, $5 = <init_function>, $6 = [<arg>]*
  1110. printTrace("\nName: $3, pathname: $4, init_function: $5",4);
  1111. my $LC_line = lc($3);
  1112. my $Value = $stdPlugins{$LC_line} ;
  1113. if ($Value) {
  1114. printTrace("\nIS A STANDARD PLUGIN",4);
  1115. }
  1116. else {
  1117. printTrace("\nNOT A STANDARD PLUGIN",4);
  1118. }
  1119. return $stdPlugins{$LC_line} ;
  1120. }
  1121. else {
  1122. printTrace("\nSYNTAX ERROR PLUGIN",4);
  1123. return 0 ;
  1124. }
  1125. }
  1126. sub isAStandardIndex {
  1127. my $line = shift ;
  1128. chomp($line);
  1129. if ($line =~ /^index\s+(\S+).*/i) {
  1130. my $LC_line = lc($1);
  1131. my $Value = $stdIndex{$LC_line} ;
  1132. printTrace("\nInclude: $LC_line \nValue: $Value", 4);
  1133. return $stdIndex{$LC_line};
  1134. }
  1135. else {
  1136. return 0 ;
  1137. }
  1138. }
  1139. sub isAStandardInclude {
  1140. my $line = shift;
  1141. chomp($line);
  1142. if ($isNT){
  1143. return $stdIncludes{lc($line)};
  1144. }
  1145. else {
  1146. return $stdIncludes{$line} ;
  1147. }
  1148. }
  1149. #############################################################################
  1150. #
  1151. # Execute a Perldap command to update plugins definition in the new schema
  1152. sub LDAPmodify_stdPlugin {
  1153. my $Filename = shift ;
  1154. my @pluginames = keys(%stdPlugins);
  1155. if (! $STDPLUGINS_FILE_MODIFIED) {
  1156. printTrace("\nLDAPmodify_plugin",4);
  1157. printTrace("\nMigrate plugin's...",1);
  1158. foreach $pluginame ( @pluginames ) {
  1159. my $update_plugin = 0 ;
  1160. my $ref_plugin = $stdPlugins{$pluginame};
  1161. if ($ref_plugin ne "\n") {
  1162. my $name = $ref_plugin->name ;
  1163. # We have a name change of "uid uniqueness plugin" in DS7.0
  1164. # to "attribute uniqueness"
  1165. $name = "attribute uniqueness" if ($name eq "uid uniqueness");
  1166. my $entry = $conn->search("cn=$name,cn=plugins,cn=config", "base","objectclass=nsSlapdPlugin") ;
  1167. if ($entry) {
  1168. my $pluginenabled="nsslapd-pluginenabled" ;
  1169. if (($entry->{$pluginenabled}[0]) ne $ref_plugin->enable) {
  1170. $update_plugin = 1 ;
  1171. my $enable = $ref_plugin->enable ;
  1172. printTrace("\n$pluginame, plugin-enable: $enable",3) ;
  1173. $entry->setValues($pluginenabled, $enable );
  1174. }
  1175. my $ArgNum = 0 ;
  1176. foreach $ArgValue (@{$ref_plugin->args}) {
  1177. my $Arg="nsslapd-pluginarg$ArgNum";
  1178. printTrace("\n$Arg: $ArgValue",3) ;
  1179. if ($entry->{$Arg}[0] ne $ArgValue) {
  1180. printTrace("\n$pluginame, $Arg: $ArgValue",3) ;
  1181. $update_plugin = 1 ;
  1182. $entry->setValues($Arg, $ArgValue) ;
  1183. }
  1184. $ArgNum++ ;
  1185. }
  1186. if ($update_plugin) {
  1187. printTrace("\n$pluginame is being updated...",2);
  1188. my $res = $conn->update($entry) ;
  1189. if ($res) {
  1190. printTrace("\nupdated !",2);
  1191. }
  1192. else {
  1193. printMsg("\nError during update of plugin: $pluginame") ;
  1194. $MigrationErrors .= "\nError during update of plugin: $pluginame";
  1195. }
  1196. }
  1197. else {
  1198. printTrace("\n$pluginame has not changed",4);
  1199. }
  1200. }
  1201. else {
  1202. printMsg("\ncan't access the plugin: cn=$name,cn=plugins,cn=config");
  1203. }
  1204. }
  1205. else {
  1206. printTrace("\nPLUGIN NOT RECORDED: $pluginame",4) ;
  1207. }
  1208. }
  1209. }
  1210. else {
  1211. # treat the case where the user wants to look at these plugins before processing
  1212. }
  1213. }
  1214. #############################################################################
  1215. # Execute Perldap command to add new indexes to the migrated instances
  1216. sub LDAPmodify_Indexes {
  1217. my $Filename = shift ;
  1218. my @indexnames = keys(%newIndex);
  1219. my @suffixnames = keys(%DBNAMES);
  1220. if ((! $INDEX_FILE_MODIFIED) && (%DBNAMES)) {
  1221. # we update indexes only if there is at least one backend to migrate
  1222. printTrace("\nLDAPmodify_indexes",4);
  1223. printTrace("\nMigrate indexes...",1);
  1224. foreach $indexname ( @indexnames ) {
  1225. printTrace("\nIndexName: $indexname",4);
  1226. printTrace("\nIndexTypes: .@{$newIndex{$indexname}->types}.", 4) ;
  1227. printTrace("\nIndexOIDS: .@{$newIndex{$indexname}->oids}.", 4) ;
  1228. foreach $suffixname ( @suffixnames ) {
  1229. # check if the index already exists !
  1230. printTrace("\nsearch for cn=$indexname,cn=index,cn=$DBNAMES{$suffixname},cn=ldbm database,cn=plugins,cn=config...", 3);
  1231. my $entry = $conn->search("cn=$indexname,cn=index,cn=$DBNAMES{$suffixname},cn=ldbm database,cn=plugins,cn=config","base","objectclass=nsIndex");
  1232. if (! $entry) {
  1233. # create a new index
  1234. printTrace("index $indexname is being created under cn=index,cn=$DBNAMES{$suffixname},cn=ldbm database,cn=plugins,cn=config...",2);
  1235. my $entry = $conn->newEntry();
  1236. $entry->setDN("cn=$indexname,cn=index,cn=$DBNAMES{$suffixname},cn=ldbm database,cn=plugins,cn=config");
  1237. $entry->setValues("objectclass", "top", "nsIndex" ) ;
  1238. $entry->setValues("cn", $indexname) ;
  1239. $entry->setValues("nssystemindex", "false") ;
  1240. my @types = @{$newIndex{$indexname}->types} ;
  1241. my @oids = @{$newIndex{$indexname}->oids} ;
  1242. $entry->setValues("nsindextype", @types) if (@types) ;
  1243. $entry->setValues("nsmatchingrule", @oids ) if (@oids);
  1244. my $res = $conn->add($entry) ;
  1245. if ($res) {
  1246. printTrace("\nAdd index successfully: $indexname for backend: $DBNAMES{$suffixname}",2);
  1247. }
  1248. else {
  1249. printMsg("\n Failed to add the index: $indexname to backend: $DBNAMES{$suffixname}");
  1250. $MigrationErrors .= "\n Failed to add the index: $indexname to backend: $DBNAMES{$suffixname}" ;
  1251. }
  1252. }
  1253. elsif ($entry->{nssystemindex}[0] eq "false") {
  1254. # if the index is not a system index, we update it
  1255. printTrace("\nindex $indexname is being processed under cn=index,cn=$DBNAMES{$suffixname},cn=ldbm database,cn=plugins,cn=config...",2);
  1256. my @types = @{$newIndex{$indexname}->types} ; printTrace("\ntypes: .@types.",2) ;
  1257. my @oids = @{$newIndex{$indexname}->oids} ; printTrace("\noids: .@oids.",2) ;
  1258. my @existing_types = $entry->getValues("nsindextype");
  1259. my @existing_oids = $entry->getValues("nsmatchingrule");
  1260. # get the elements present in @types and not present in @existing_types
  1261. my @typesToAdd = &getDiff(\@types, \@existing_types);
  1262. # same for matchingrules
  1263. my @oidsToAdd = &getDiff(\@oids, \@existing_oids);
  1264. foreach $newtype (@typesToAdd) {
  1265. $entry->addValue("nsindextype", $newtype); printTrace("\nnewtype: $newtype",2);
  1266. }
  1267. foreach $newoid (@oidsToAdd) {
  1268. $entry->addValue("nsmatchingrule", $newoid);
  1269. }
  1270. if (@typesToAdd || @oidsToAdd) {
  1271. my $res = $conn->update($entry) ;
  1272. if ($res) {
  1273. printTrace("\nUpdate index successfully: $indexname for backend: $DBNAMES{$suffixname}",2);
  1274. }
  1275. else {
  1276. printMsg("\n Failed to update the index: $indexname to backend: $DBNAMES{$suffixname}");
  1277. $MigrationErrors .= "\n Failed to update the index: $indexname to backend: $DBNAMES{$suffixname}" ;
  1278. }
  1279. }
  1280. else {
  1281. printTrace("\nNothing to update",2);
  1282. }
  1283. }
  1284. else {
  1285. printTrace("\nThe index: $indexname is a system index. It can't be updated",2);
  1286. }
  1287. }
  1288. }
  1289. }
  1290. else {
  1291. # treat the case where the user wants to look at these indexes before processing
  1292. }
  1293. }
  1294. #############################################################################
  1295. #
  1296. # Execute a Perldap command to add all user defined object classes in the new schema
  1297. sub LDAPmodify_User_oc {
  1298. my $Filename = shift ;
  1299. if (! $USER_OC_FILE_MODIFIED) {
  1300. printTrace("\nLDAPmodify_User_oc",4);
  1301. printTrace("\nMigrate objectclasses...",1);
  1302. foreach $objectname ( @User_oc_names ) {
  1303. my $entry = $conn->search("cn=schema", "base","objectclass=*") ;
  1304. die "\ncan't connect to object: cn=schema\n" unless ($entry);
  1305. printTrace("\nObjectName: $objectname\nValue: $User_oc{$objectname}",3);
  1306. next if ($entry->hasValue("objectclasses",$User_oc{$objectname},1)) ;
  1307. $entry->addValue("objectclasses",$User_oc{$objectname},"1") ;
  1308. my $res = $conn->update($entry) ;
  1309. my $err = $conn->getErrorCode();
  1310. if ($res) {
  1311. printTrace("\nobjectclass: $User_oc{$objectname} added",2);
  1312. } elsif ($err == 20) { # already exists
  1313. printTrace("\nobjectclass: $User_oc{$objectname} already exists",1);
  1314. } else {
  1315. printMsg("\nCan\'t add objectclass to the schema: $User_oc{$objectname}");
  1316. my $msg = $conn->getErrorString();
  1317. printMsg("\nMsg: $msg");
  1318. $MigrationErrors .= "\nCan\'t add objectclass to the schema: $User_oc{$objectname}" ;
  1319. }
  1320. }
  1321. }
  1322. else {
  1323. # treat the case where the user wants to look at these objectclasses before processing
  1324. }
  1325. }
  1326. #############################################################################
  1327. #
  1328. # Execute a Perldap command to add all user defined attributes in the new schema
  1329. sub LDAPmodify_User_at {
  1330. my $Filename = shift ;
  1331. my @attributenames = keys(%User_at);
  1332. if (! $USER_AT_FILE_MODIFIED) {
  1333. printTrace("\nLDAPmodify_User_at",4);
  1334. printTrace("\nMigrate attributes...",1);
  1335. foreach $attributename ( @attributenames ) {
  1336. my $entry = $conn->search("cn=schema", "base","objectclass=*") ;
  1337. printTrace("\nAtributeName: $attributename, Value: $User_at{$attributename}",3);
  1338. die "\nentry not found cn=schema\n" unless $entry ;
  1339. next if ($entry->hasValue("attributetypes",$User_at{$attributename},1) ) ;
  1340. my $res = $entry->addValue("attributetypes",$User_at{$attributename},"1") ;
  1341. if (! $res) {
  1342. printMsg("\nCan\'t add attribute to the schema: $User_at{$attributename}");
  1343. $MigrationErrors .= "\nCan\'t add attribute to the schema: $User_at{$attributename}" ;
  1344. }
  1345. my $res = $conn->update($entry) ;
  1346. my $err = $conn->getErrorCode();
  1347. if ($res) {
  1348. printTrace("\nattribute: $attributename added",2);
  1349. } elsif ($err == 20) { # already exists
  1350. printTrace("\nattribute: $attributename already exists",1);
  1351. }
  1352. else {
  1353. printMsg("\nCan\'t add attribute to the schema: $User_at{$attributename}");
  1354. my $msg = $conn->getErrorString();
  1355. printMsg("\nMsg: $msg");
  1356. $MigrationErrors .= "\nCan\'t add attribute to the schema: $User_at{$attributename}" ;
  1357. }
  1358. }
  1359. }
  1360. else {
  1361. # treat the case where the user wants to look at these attributes before processing
  1362. }
  1363. }
  1364. #############################################################################
  1365. # Add an object class to the user_oc hash and reset the object !!!
  1366. sub AddObjectClass {
  1367. my $ObjectClass = shift ;
  1368. my $ObjectName = $ObjectClass->{'ObjectName'} ;
  1369. my $Object_oid = $ObjectClass->{'Object_oid'} ;
  1370. my $Object_superior = $ObjectClass->{'Object_superior'} ;
  1371. my $Object_requires = $ObjectClass->{'Object_requires'} ;
  1372. my $Object_allows = $ObjectClass->{'Object_allows'} ;
  1373. my $ObjectClassDef = "( $Object_oid NAME \'$ObjectName\' DESC \'\' SUP $Object_superior STRUCTURAL MUST ($Object_requires) MAY ($Object_allows) X-ORIGIN \'user defined\' )";
  1374. if ( (!($ObjectName =~ /^top$/i)) && ( ! $User_oc{$ObjectName} )) {
  1375. $User_oc{$ObjectName} = $ObjectClassDef ;
  1376. push @User_oc_names, $ObjectName ;
  1377. printTrace("ObjectName: $ObjectName \nObject_oid: $Object_oid \nObject_superior:$Object_superior \nObject_requires: $Object_requires \nObject_allows: $Object_allows \nObjectClassDefinition: $User_oc{$ObjectName}\n",4);
  1378. }
  1379. elsif ( ($User_oc{$ObjectName}) && ($User_oc{$ObjectName} ne $ObjectClassDef) ) {
  1380. printMsg("\nAttempt to redifine the objectclass: $ObjectName previously defined in your configuration file. Operation not allowed ");
  1381. }
  1382. else {
  1383. printMsg("\nAttempt to redifine the objectclass: top. Operation not allowed");
  1384. }
  1385. resetObjectClass($ObjectClass);
  1386. }
  1387. #############################################################################
  1388. # Build an LDIF attribute and add it to the user_at hash
  1389. sub AddAttribute {
  1390. my $Attr = shift ;
  1391. my $AttributeName = $Attr->{'AttributeName'};
  1392. my $Attribute_oid = $Attr->{'Attribute_oid'};
  1393. my $Attribute_aliases = $Attr->{'Attribute_aliases'};
  1394. my $Attribute_syntax = $Attr->{'Attribute_syntax'};
  1395. my $Attribute_single = $Attr->{'Attribute_single'};
  1396. my $AttributeDef = "( $Attribute_oid NAME ( \'$AttributeName\' $Attribute_aliases) DESC \'User Defined Attribute\' SYNTAX $Attribute_syntax $Attribute_single X-ORIGIN 'user defined' )" ;
  1397. printTrace("\nAttributeDef: $AttributeDef",4);
  1398. $User_at{$AttributeName} = $AttributeDef ;
  1399. }
  1400. #############################################################################
  1401. # add the index structure to the newIndex hash
  1402. sub AddIndex {
  1403. my $ref_index = shift ;
  1404. my $state = shift ;
  1405. printTrace("\nAddIndex, last state: $state",4) ;
  1406. if ($state == 1) {
  1407. $ref_index->specific("ALL") ;
  1408. return 1 ;
  1409. }
  1410. elsif ($state == 6) {
  1411. $ref_index->specific("NONE") ;
  1412. return 1 ;
  1413. }
  1414. if (($state == 1) || ($state == 3) || ($state == 5) || ($state == 6)) {
  1415. foreach $name (@{$ref_index->names}) {
  1416. $newIndex{$name} = $ref_index ; # record the ref to the index struct in the newIndex hash
  1417. }
  1418. return 1 ;
  1419. }
  1420. else {
  1421. return 0 ;
  1422. }
  1423. }
  1424. #############################################################################
  1425. # add the plugin structure to the stdPlugin hash
  1426. sub AddPlugin {
  1427. my $ref_plugin = shift ;
  1428. printTrace("\nAddPlugin",4) ;
  1429. $stdPlugins{lc($ref_plugin->name)} = $ref_plugin ;
  1430. my $name = $ref_plugin->name ;
  1431. my $type = $ref_plugin->type ;
  1432. my $enable = $ref_plugin->enable ;
  1433. printTrace("\nPluginName: $name",4);
  1434. printTrace("\nPluginType: $type",4);
  1435. printTrace("\nPluginEnable: $enable",4);
  1436. printTrace("\nPluginArgs: @{$ref_plugin->args}",4);
  1437. return 1 ;
  1438. }
  1439. #############################################################################
  1440. # parse a plugin definition and call the addindex
  1441. sub ParsePlugin {
  1442. my $Plugin = shift ;
  1443. my $NumLine = shift ;
  1444. my $state = 0 ;
  1445. my $ErrorMsg = "Syntax error of a plugin definition. \n line parsed:";
  1446. my $ref_plugin = S_plugin->new();
  1447. printTrace("\nParsePlugin: $_",4);
  1448. if (/^plugin\s+(database|extendop|preoperation|postoperation|matchingrule|syntax)\s+(on|off)\s+\"(.*?)\"\s+\"(.*?)\"\s+(\S+)(.*)$/i) {
  1449. # $1 = <type>, $2 = <on|off>, $3 = <name>, $4 = <pathname>, $5 = <init_function>, $6 = [<arg>]*
  1450. $ref_plugin->name($3);
  1451. $ref_plugin->type($1);
  1452. $ref_plugin->enable($2);
  1453. $_ = $6 ;
  1454. my $ArgNb = 0 ;
  1455. my $prec ;
  1456. my $arg ;
  1457. my $Unix_oldDir = $oldDir ;
  1458. my $Unix_root = $root ;
  1459. grep { s@\\@/@g } $Unix_oldDir if $isNT;
  1460. grep { s@\\@/@g } $Unix_root if $isNT;
  1461. while (!(/^\s*$/)) {
  1462. if (/^\s*\".*?\"/) {
  1463. s/^\s*\"(.*?)\"(.*)/$2/i ;
  1464. $arg = $1 ;
  1465. }
  1466. elsif (/^\s*[^\"\s]+/) {
  1467. s/^\s*([^\"\s]+)(.*)/$2/i ;
  1468. $arg = $1 ;
  1469. }
  1470. $prec = $_ ;
  1471. $_ = $arg ;
  1472. s@$Unix_oldDir@$Unix_root@ig ;
  1473. s/$type-$oldname/$type-$newname/ig ;
  1474. @{$ref_plugin->args}[$ArgNb++] = $_ ;
  1475. $_ = $prec ;
  1476. }
  1477. if (/^\s*$/) {
  1478. return AddPlugin($ref_plugin);
  1479. }
  1480. else {
  1481. return 0 ;
  1482. }
  1483. }
  1484. return 0 ;
  1485. }
  1486. #############################################################################
  1487. # parse an index definition and call the addindex
  1488. sub ParseIndex {
  1489. my $index = shift ;
  1490. my $NumLine = shift ;
  1491. my $ref_index = S_index->new() ;
  1492. my $Value ;
  1493. my $state = 0 ;
  1494. my $ErrorMsg = "Syntax error of an index definition.\nline parsed:";
  1495. printTrace("\nParseIndex: $_",4) ;
  1496. s/,/, /g ;
  1497. s/\s+,/,/g ;
  1498. s/^index\s+//i ; # substitute the token index
  1499. while (!(/^\s*$/)) {
  1500. s/^\s*(\S+)(.*)$/$2/ ;
  1501. $Value = $1 ;
  1502. printTrace("\nValue: $Value",4);
  1503. printTrace("\nState: $state",4) ;
  1504. SWITCH: {
  1505. if ($state == 0) {
  1506. if ($Value =~ /[^\.]/) {
  1507. if ($Value =~ /(\S+),$/) {
  1508. push @{$ref_index->names}, $1 ;
  1509. }
  1510. else {
  1511. $state = 1 ;
  1512. push @{$ref_index->names}, $Value ;
  1513. }
  1514. }
  1515. else {
  1516. return 0 ;
  1517. }
  1518. last SWITCH ;
  1519. }
  1520. if ($state == 1) {
  1521. if ($Value =~ /^none$/i) {
  1522. $state = 6 ; # end of the index definition
  1523. }
  1524. elsif ($Value =~ /^\"\"$/) {
  1525. $state = 4 ; # we expect to have at least one OID
  1526. }
  1527. elsif ($Value =~ /(\S+),$/) {
  1528. $state = 2 ;
  1529. push @{$ref_index->types}, $1 ;
  1530. }
  1531. else {
  1532. $state = 3 ;
  1533. push @{$ref_index->types}, $Value ;
  1534. }
  1535. last SWITCH ;
  1536. }
  1537. if ($state == 2) {
  1538. if ($Value =~ /(\S+),$/) {
  1539. push @{$ref_index->types}, $1 ;
  1540. }
  1541. else {
  1542. $state = 3 ;
  1543. push @{$ref_index->types}, $Value ;
  1544. }
  1545. last SWITCH ;
  1546. }
  1547. if ($state == 3) {
  1548. if ($Value =~ /(\S+),$/) {
  1549. $state = 4 ;
  1550. push @{$ref_index->oids}, $1 ;
  1551. }
  1552. else {
  1553. $state = 5 ;
  1554. push @{$ref_index->oids}, $Value ;
  1555. }
  1556. last SWITCH ;
  1557. }
  1558. if ($state == 4) {
  1559. if ($Value =~ /(\S+),$/) {
  1560. push @{$ref_index->oids}, $1 ;
  1561. }
  1562. else {
  1563. $state = 5 ;
  1564. push @{$ref_index->oids}, $Value ;
  1565. }
  1566. last SWITCH ;
  1567. }
  1568. }
  1569. }
  1570. return AddIndex($ref_index,$state) ;
  1571. }
  1572. #############################################################################
  1573. sub ParseAttribute {
  1574. my $Attr = shift ;
  1575. my $NumLine = shift ;
  1576. my $state = 1 ;
  1577. my $ErrorMsg = "Syntax error of an attribute definition.\nline parsed:";
  1578. my %Attribute = (
  1579. 'AttributeName' => "",
  1580. 'Attribute_oid' => "",
  1581. 'Attribute_aliases' => "",
  1582. 'Attribute_syntax' => "",
  1583. 'Attribute_single' => ""
  1584. );
  1585. my $AttributeName = " ";
  1586. printTrace("\nParseAttribute",4);
  1587. while (!(/^\s*$/)) {
  1588. s/^(.*?)(\S+)\s*$/$1/ ;
  1589. printTrace("\nValue: $2",4);
  1590. printTrace("\nState: $state",4) ;
  1591. my $Value = $2 ;
  1592. SWITCH: {
  1593. if ($state == 1) {
  1594. if (isAllowedModifier($Value)) {
  1595. $state = 1 ;
  1596. $modifier = lc($Value);
  1597. $AttrVar = 'Attribute_' . $modifier ;
  1598. $Attribute{$AttrVar} = &getModifierValue($Value) ;
  1599. }
  1600. elsif (&isAllowedPlugin($Value)) {
  1601. $state = 2 ;
  1602. $Attribute{'Attribute_syntax'} = &getSyntaxOid($Value) ;
  1603. }
  1604. else {
  1605. return 0 ;
  1606. }
  1607. last SWITCH ;
  1608. }
  1609. if ($state == 2) {
  1610. if ($Value =~ /[\.]|-oid$/) {
  1611. $Attribute{'Attribute_oid'} = "$Value" ;
  1612. printTrace("\nAttribute-oid: $Attribute{'Attribute_oid'}",3);
  1613. $state = 3 ;
  1614. }
  1615. elsif ($Value =~ /[^\.]/) {
  1616. $AttributeName = $Attribute{'AttributeName'} ;
  1617. if ($AttributeName) { $Attribute{'Attribute_aliases'} .= "\'$AttributeName\' " ;}
  1618. $Attribute{'AttributeName'} = $Value ;
  1619. $state = 4 ;
  1620. }
  1621. else {
  1622. return 0 ;
  1623. }
  1624. last SWITCH ;
  1625. }
  1626. if ($state == 3) {
  1627. if ($Value =~ /[^\.]/) {
  1628. $AttributeName = $Attribute{'AttributeName'} ;
  1629. if ($AttributeName) { $Attribute{'Attribute_aliases'} .= "\'$AttributeName\' " ;}
  1630. $Attribute{'AttributeName'} = $Value ;
  1631. $state = 4 ; }
  1632. else {
  1633. return 0 ;
  1634. }
  1635. last SWITCH ;
  1636. }
  1637. if ($state == 4) {
  1638. if ($Value =~/^attribute$/i){
  1639. $state = 5;
  1640. }
  1641. elsif ($Value =~/[^\.]/i) {
  1642. $AttributeName = $Attribute{'AttributeName'} ;
  1643. if ($AttributeName) { $Attribute{'Attribute_aliases'} .= "\'$AttributeName\' " ;}
  1644. $Attribute{'AttributeName'} = $Value ;
  1645. }
  1646. else {
  1647. return 0 ;
  1648. }
  1649. last SWITCH ;
  1650. }
  1651. if ($state == 5) {
  1652. return 0 ;
  1653. last SWITCH ;
  1654. }
  1655. }
  1656. }
  1657. $Attribute{'Attribute_oid'} = $Attribute{'AttributeName'} . '-oid' unless ($Attribute{'Attribute_oid'}) ;
  1658. return AddAttribute(\%Attribute) ;
  1659. }
  1660. #############################################################################
  1661. # fill in the hash HashParametersName
  1662. sub FillHashParametersName {
  1663. my @paramnames = ( keys(%GeneralSrvParamToMigrate), keys(%GlobalConfigLDBMparamToMigrate), keys(%LDBMparamToMigrate));
  1664. foreach $param (@paramnames) {
  1665. $HashParametersName{$param} = '\n';
  1666. }
  1667. }
  1668. # Parse parameters
  1669. sub ParseParameters {
  1670. my $param = shift ;
  1671. my $value = shift ;
  1672. my $NumLine = shift ;
  1673. my $ErrorMsg = "parameter unknown, or not to be migrated: ";
  1674. if ($HashParametersName{lc($param)} && ($value !~ /^\s*$/)) {
  1675. $HashParametersName{lc($param)} = $value ;
  1676. printTrace("\nParam: $param is present",4);
  1677. }
  1678. else {
  1679. printTrace("\n$NumLine, $ErrorMsg,$param",4);
  1680. }
  1681. }
  1682. # add general server parameters
  1683. sub AddGeneralParameters {
  1684. my @paramnames = keys(%GeneralSrvParamToMigrate);
  1685. my $entry = $conn->search("cn=config","base","objectclass=*");
  1686. die "\ncan't access to object: cn=config. \nMigration stopped\n" unless ($entry);
  1687. printTrace("\nAddGeneralParameters",4);
  1688. foreach $param (@paramnames) {
  1689. my $LDAPparam = $GeneralSrvParamToMigrate{$param} ;
  1690. my $Value = $HashParametersName{$param} ;
  1691. if (($Value ne '\n') && ($entry->{$LDAPparam}[0] ne $Value)) {
  1692. printTrace("\nLDAPparam: $LDAPparam, Value: $Value",4);
  1693. $entry->setValues($LDAPparam, $Value);
  1694. my $res = $conn->update($entry);
  1695. if ($res) {
  1696. printTrace("\nUpdate successfully $LDAPparam ",0);
  1697. }
  1698. else {
  1699. printMsg("\nCan't update parameter: $LDAPparam");
  1700. }
  1701. }
  1702. }
  1703. }
  1704. # add general LDBM parameters
  1705. sub AddGeneralLDBMParameters {
  1706. my @paramnames = keys(%GlobalConfigLDBMparamToMigrate);
  1707. my $entry = $conn->search("cn=config,cn=ldbm database,cn=plugins,cn=config","base","objectclass=*");
  1708. die "\ncan't access to object: cn=config,cn=ldbm database,cn=plugins,cn=config. \nMigration stopped\n" unless ($entry);
  1709. printTrace("\nAddGeneralLDBMParameters",4);
  1710. foreach $param (@paramnames) {
  1711. my $LDAPparam = $GlobalConfigLDBMparamToMigrate{$param} ;
  1712. my $Value = $HashParametersName{$param} ;
  1713. if (($Value ne '\n') && ($entry->{$LDAPparam}[0] ne $Value)) {
  1714. printTrace("\nLDAPparam: $LDAPparam, Value: $Value",4);
  1715. $entry->setValues($LDAPparam, $Value);
  1716. my $res = $conn->update($entry);
  1717. if ($res) {
  1718. printTrace("\nUpdate successfully $LDAPparam ",0);
  1719. }
  1720. else {
  1721. printMsg("\nCan't update parameter: $LDAPparam");
  1722. }
  1723. }
  1724. }
  1725. }
  1726. # add specific LDBM parameters
  1727. sub AddSpecificLDBMParameters {
  1728. my @paramnames = keys(%LDBMparamToMigrate);
  1729. my %REV_DBNAMES = reverse %DBNAMES ;
  1730. my @dbnames = keys(%REV_DBNAMES);
  1731. printTrace("\nAddSpecificLDBMParameters",4);
  1732. foreach $dbname (@dbnames) {
  1733. my $entry = $conn->search("cn=$dbname,cn=ldbm database,cn=plugins,cn=config","base","objectclass=*");
  1734. die "\ncan't access to object: cn=$dbname,cn=ldbm database,cn=plugins,cn=config. \nMigration stopped\n" unless ($entry);
  1735. foreach $param (@paramnames) {
  1736. my $LDAPparam = $LDBMparamToMigrate{$param} ;
  1737. my $Value = $HashParametersName{$param} ;
  1738. if (($Value ne '\n') && ($entry->{$LDAPparam}[0] ne $Value)) {
  1739. printTrace("\nLDAPparam: $LDAPparam, Value: $Value",4);
  1740. $entry->setValues($LDAPparam, $Value);
  1741. my $res = $conn->update($entry);
  1742. if ($res) {
  1743. printTrace("\nUpdate successfully $LDAPparam",2);
  1744. }
  1745. else {
  1746. printMsg("\nCan't update parameter: $LDAPparam");
  1747. }
  1748. }
  1749. }
  1750. }
  1751. }
  1752. #############################################################################
  1753. # Parse a configuration file potentialy tuned by the user (different from slapd.user_oc.conf and slapd.user_at.conf)
  1754. sub ParseConfigurationFile {
  1755. my $FileToParse = shift;
  1756. my $NumLine = 0;
  1757. my $PARSE_OBJECTCLASSES = 0 ; # 1 if there are objectclass definitions in the file
  1758. printTrace("\nParseConfigurationFile: $FileToParse",4) ;
  1759. printTrace("\nParse $FileToParse",2);
  1760. # read each line of the configuration file
  1761. my $CONFIGFILE = "CONFIGFILE.$FileToParse" ;
  1762. open( $CONFIGFILE, $FileToParse ) || die "Can't open $FileToParsec: $!: ";
  1763. LINE: while ( <$CONFIGFILE> ) {
  1764. $NumLine++ ;
  1765. if (/^\s*\#/) { # skip comments
  1766. next LINE;
  1767. }
  1768. if (/^\s*$/) { # skip blank lines
  1769. next LINE;
  1770. } elsif (/^suffix\s+/i) {
  1771. chomp($_) ;
  1772. CheckSuffix($_) ;
  1773. } elsif (/^plugin/i) {
  1774. chomp($_);
  1775. if (! &isAStandardPlugin($_)) {
  1776. push @badPlugins, $_;
  1777. }
  1778. else {
  1779. my $Plugin = $_ ;
  1780. if (! &ParsePlugin($_,$NumLine)) {
  1781. printMsg("\nLine $NumLine, syntax error of the plugin:\n$Plugin");
  1782. }
  1783. }
  1784. } elsif (/^index/i) {
  1785. chomp($_);
  1786. if (! &isAStandardIndex($_)) {
  1787. my $Index = $_ ;
  1788. if (! &ParseIndex($_,$NumLine)) {
  1789. printMsg("\nLine $NumLine, syntax error of index:\n$Index");
  1790. }
  1791. }
  1792. } elsif (/^include\s+[\"]?(.*?)[\"]?\s*$/i) {
  1793. # strip leading and trailing "
  1794. my $include_file = $1 ;
  1795. grep { s@/@\\@g } $include_file if $isNT;
  1796. if (! &isAStandardInclude($include_file)) {
  1797. &ParseConfigurationFile($include_file);
  1798. }
  1799. } elsif (/^attribute\s+\S+/i) {
  1800. chomp($_);
  1801. my $Attrib = $_ ;
  1802. if (! &ParseAttribute($_,$NumLine)) {
  1803. printMsg("\nLine $NumLine, syntax error of attribute:\n$Attrib");
  1804. }
  1805. } elsif (/^objectclass\s+(\S+)\s*$/i) {
  1806. # At least one objectclass is present in the file
  1807. $PARSE_OBJECTCLASSES = 1;
  1808. } elsif (/^\s*(\S+)\s+[\"]?(.*?)[\"]?\s*$/) {
  1809. # Parse parameters and record the associated value in %Oldhash
  1810. &ParseParameters($1,$2,$NumLine);
  1811. }
  1812. }
  1813. close($CONFIGFILE);
  1814. ParseObjectClassesFile($FileToParse) if ($PARSE_OBJECTCLASSES); # parse objectclass definition
  1815. }
  1816. #############################################################################
  1817. # Parse the file specified in the userat attribute
  1818. sub ParseAttributesFile {
  1819. my $userat_file=shift ;
  1820. my $NumLine = 0;
  1821. printTrace("\nParseAttributesFile: $userat_file",4);
  1822. printTrace("\nParse user defined attributes file: $userat_file",2);
  1823. # read each line of the configuration file
  1824. open( ATTRFILE, $userat_file ) || die "Can't open $FileToParsec: $!: ";
  1825. LINE: while ( <ATTRFILE> ) {
  1826. $NumLine++ ;
  1827. if (/^\s*\#/) { # skip comments
  1828. next LINE;
  1829. }
  1830. if (/^\s*$/) { # skip blank lines
  1831. next LINE;
  1832. } elsif (/^attribute\s+\S+/i) {
  1833. chomp($_);
  1834. my $Attrib = $_ ;
  1835. if (! &ParseAttribute($_, $NumLine)) {
  1836. printMsg("\nLine $NumLine, syntax error of attribute:\n$Attrib");
  1837. }
  1838. }
  1839. }
  1840. close(ATTRFILE);
  1841. }
  1842. #############################################################################
  1843. # Parse the file specified in the useroc token
  1844. sub ParseObjectClassesFile {
  1845. my $useroc_file = shift ;
  1846. my %ObjectClass = (
  1847. 'ObjectName' => " ",
  1848. 'Object_oid' => " ",
  1849. 'Object_superior' => "top",
  1850. 'Object_requires' => " ",
  1851. 'Object_allows' => " "
  1852. );
  1853. my $state = 0;
  1854. my $ErrorMsg = "Syntax error of an object class definition.\nline parsed:";
  1855. my $LineNb = 0 ; # Number of the current line parsed in the file
  1856. printTrace("ParseObjectClassesFile: $useroc_file\n",4) ;
  1857. # read each line of the configuration file
  1858. open( OBJCLASSFILE, $useroc_file ) || die "Can't open $FileToParsec: $!: ";
  1859. printTrace("Begin the parsing of the file: $useroc_file",4);
  1860. LINE: while ( <OBJCLASSFILE> ) {
  1861. printTrace("Current Line: $_",4);
  1862. $LineNb++ ;
  1863. if (/^\s*\#/) { # skip comments
  1864. next LINE;
  1865. }
  1866. if (/^\s*$/) { # skip blank lines
  1867. next LINE;
  1868. }
  1869. SWITCH: {
  1870. if ($state == 0) { resetObjectClass(\%ObjectClass);
  1871. if (/^objectclass\s+(\S+)\s*$/i) {
  1872. $ObjectClass{'ObjectName'} = $1;
  1873. $state = 1 ;}
  1874. else {} # printMsg($ErrorMsg,$_,$LineNb);}
  1875. last SWITCH;}
  1876. if ($state == 1) {if (/^\s+oid\s+(\S+)\s*$/i) {
  1877. $ObjectClass{'Object_oid'} = $1;
  1878. $state = 2 ;}
  1879. elsif (/^\s+superior\s+(\S+)\s*$/i) {
  1880. $ObjectClass{'Object_superior'} = $1;
  1881. $state = 3 ;
  1882. }
  1883. elsif (/^\s+requires\s*$/i) {
  1884. $state = 4;
  1885. }
  1886. elsif (/^\s+allows\s*$/i) {
  1887. $state = 5;
  1888. }
  1889. else {$state=0; printMsg($ErrorMsg,$_,$LineNb);}
  1890. last SWITCH;}
  1891. if ($state == 2) {if (/^\s+superior\s+(\S+)\s*$/i) {
  1892. $ObjectClass{'Object_superior'} = $1;
  1893. $state = 3 ;}
  1894. elsif (/^\s+requires\s*$/i) {
  1895. $state = 4;
  1896. }
  1897. elsif (/^\s+allows\s*$/i) {
  1898. $state = 5;
  1899. }
  1900. else { $state=0; printMsg($ErrorMsg,$_,$LineNb);}
  1901. last SWITCH;}
  1902. if ($state == 3) {if (/^\s+requires\s*$/i)
  1903. { $state = 4; }
  1904. elsif (/^objectclass\s+(\S+)\s*$/i) {
  1905. # run an ldap add before to continue
  1906. &AddObjectClass(\%ObjectClass);
  1907. $ObjectClass{'ObjectName'} = $1;
  1908. $state = 1 ;}
  1909. elsif (/^\s+allows\s*$/i)
  1910. { $state = 5; }
  1911. else {$state = 0; printMsg($ErrorMsg,$_,$LineNb);}
  1912. last SWITCH;}
  1913. if ($state == 4) {if (/^\s+([^,\s]+),\s*$/i) {
  1914. $ObjectClass{'Object_requires'}.=$1." \$ "; }
  1915. elsif (/^\s+([^,\s]+)\s*$/i) {
  1916. $ObjectClass{'Object_requires'}.=$1." ";
  1917. $state = 6; }
  1918. else {$state = 0;printMsg($ErrorMsg,$_,$LineNb);}
  1919. last SWITCH;}
  1920. if ($state == 5) {if (/^\s+([^,\s]+),\s*$/i) {
  1921. $ObjectClass{'Object_allows'}.=$1." \$ "; }
  1922. elsif (/^\s+([^,\s]+)\s*$/i) {
  1923. $ObjectClass{'Object_allows'}.=$1." ";
  1924. # run an ldap add before to continue
  1925. &AddObjectClass(\%ObjectClass);
  1926. $state = 0; }
  1927. else {$state = 0; printMsg($ErrorMsg,$_,$LineNb);}
  1928. last SWITCH;}
  1929. if ($state == 6) {if (/^objectclass\s+(\S+)\s*$/i) {
  1930. # run an ldap add before to continue
  1931. &AddObjectClass(\%ObjectClass);
  1932. $ObjectClass{'ObjectName'} = $1;
  1933. $state = 1 ;}
  1934. elsif (/^\s+allows\s*$/i) {
  1935. $state = 5;}
  1936. else {$state = 0; printMsg($ErrorMsg,$_,$LineNb);}
  1937. last SWITCH;}
  1938. }
  1939. }
  1940. close(OBJCLASSFILE);
  1941. if (($state == 3) || ($state == 4) || ($state == 5) || ($state == 6)) {
  1942. &AddObjectClass(\%ObjectClass);
  1943. }
  1944. printTrace("state: $state",4);
  1945. }
  1946. #############################################################################
  1947. # printMsg print message to the user standard output.
  1948. sub printMsg {
  1949. my $TypeMsg = shift ;
  1950. my $Msg = shift ;
  1951. my $LineNb = shift ;
  1952. if ($LineNb) {
  1953. printTrace("Line: $LineNb, $TypeMsg, $Msg");
  1954. }
  1955. else {
  1956. printTrace("$TypeMsg $Msg");
  1957. }
  1958. }
  1959. #############################################################################
  1960. # print message error to the user standard output.
  1961. sub printTrace {
  1962. my $Msg = shift ;
  1963. my $level = shift ;
  1964. if ($level <= $TRACELEVEL) {
  1965. print($Msg);
  1966. print LOGFILE $Msg ;
  1967. }
  1968. }
  1969. #############################################################################
  1970. # reset an objectclass structure
  1971. sub resetObjectClass {
  1972. my $ObjectClass = shift;
  1973. $ObjectClass->{'ObjectName'} = " " ;
  1974. $ObjectClass->{'Object_oid'} = " " ;
  1975. $ObjectClass->{'Object_superior'} = "top" ;
  1976. $ObjectClass->{'Object_requires'} = " " ;
  1977. $ObjectClass->{'Object_allows'} = " " ;
  1978. }
  1979. #############################################################################
  1980. # this subroutine implements a very stupid version of diff
  1981. sub diff {
  1982. my $f1 = shift;
  1983. my $f2 = shift;
  1984. my $lineToBeginWith = shift;
  1985. my $NULL = "" ;
  1986. my $diff_f1 = $NULL ;
  1987. my $diff_f2 = $NULL ;
  1988. my $retval = $NULL ;
  1989. my $ret;
  1990. open(F1, "$f1") or die "Could not open file $f1";
  1991. open(F2, "$f2") or close(F1), die "Could not open file $f2";
  1992. while (defined($l1 = <F1>)) {
  1993. if ($lineToBeginWith){
  1994. $lineToBeginWith -- ;
  1995. next ;
  1996. }
  1997. next if ($l1 =~ /^\#/);
  1998. $ret = defined($l2 = <F2>);
  1999. if ($ret) {
  2000. $ret = defined($l2 = <F2>) while ($ret && ($l2 =~ /^\#/)) ;
  2001. if ($ret) {
  2002. if (!($l1 eq $l2)) {
  2003. # ignore whitespace
  2004. $l1_clean = $l1 ;
  2005. $l2_clean = $l2 ;
  2006. $l1_clean =~ s/\s//g;
  2007. $l2_clean =~ s/\s//g;
  2008. if (!($l1_clean eq $l2_clean)) {
  2009. $diff_f1 .= "${l1}" unless ($l1_clean eq $NULL);
  2010. $diff_f2 .= "${l2}" unless ($l2_clean eq $NULL);
  2011. }
  2012. }
  2013. }
  2014. else {
  2015. next if ($l1 =~ /^\s*$/) ;
  2016. $diff_f1 .= "${l1}";
  2017. }
  2018. }
  2019. else {
  2020. next if ($l1 =~ /^\s*$/) ;
  2021. $diff_f1 .= "${l1}";
  2022. }
  2023. }
  2024. while (defined($l2 = <F2>)) {
  2025. if (($l2 =~ /^\#/) || ($l2 =~ /^\s*$/)) {
  2026. next ;
  2027. }
  2028. else {
  2029. $diff_f2 .= "${l2}" ;
  2030. }
  2031. }
  2032. close(F1);
  2033. close(F2);
  2034. $retval .= "- differences present in your config file but not in standard file:\n\n". "$diff_f1\n" if ($diff_f1) ;
  2035. $retval .= "- differences present in standard file but not in your config file:\n\n" . "$diff_f2" if ($diff_f2) ;
  2036. return $retval ;
  2037. }
  2038. sub CompareStdConfigFiles {
  2039. # Compare each configuration file against its default version. If it has changed,
  2040. # notify the user that the file has changed and will need to be checked by the
  2041. # user. This should be safe to do because there should be no path information
  2042. # stored in these conf files, which are just schema stuff.
  2043. # printTrace("\nCheck if standard configuration files have changed",3);
  2044. my $origFilePath = "$oldDir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}install${PATHSEP}config${PATHSEP}" ;
  2045. my $FilesChanged = "";
  2046. my $AllDiffs = "***********************************************************************";
  2047. my $NoChanges = "" ;
  2048. my $lineToBegin = 0 ;
  2049. printTrace("\nVersion of the old directory server: $oldVersion.$oldMinor",0);
  2050. opendir(CONFDIR, $oldConfDir) or
  2051. die "Error: could not open migrated config dir $oldConfDir: $!";
  2052. foreach $file (readdir(CONFDIR)) {
  2053. $origFile = $origFilePath . $file ;
  2054. $configFile = $oldConfDir . $file ;
  2055. if ((! exists($userDefinedConfigFiles{lc($file)})) && (-f $origFile)) {
  2056. my $lineToBegin = 1 if (lc($file) eq "slapd-collations.conf"); # we ignore the first line of slapd-collations
  2057. $diffs = &diff($configFile, $origFile, $lineToBegin);
  2058. $lineToBegin = 0 if $lineToBegin ;
  2059. if ($diffs) {
  2060. $FilesChanged .= "\n$configFile";
  2061. $AllDiffs .= "\n$configFile is different than the standard configuration file" ;
  2062. $AllDiffs .= "\nYou will need to check this file and make sure its changes are compatible ";
  2063. $AllDiffs .= "with the new directory server\nHere are the differences:\n";
  2064. $AllDiffs .= "$diffs \n\n";
  2065. $AllDiffs .= "***********************************************************************";
  2066. }
  2067. else {
  2068. $NoChanges .= "\n$configFile";
  2069. }
  2070. }
  2071. }
  2072. closedir(CONFDIR);
  2073. if ($FilesChanged) {
  2074. printTrace("\nNo changes to old configuration files:$NoChanges",3) ;
  2075. printTrace("\n***********************************************************************",3) ;
  2076. printMsg("\nThe following standard files have been modified: $FilesChanged");
  2077. if ($NO_INPUT_USER) {
  2078. # do nothing
  2079. }
  2080. else {
  2081. printMsg("\nDo you want to see the differences Yes/No [No] ?") ;
  2082. my $answer = <STDIN> ;
  2083. if ($answer =~ /y|yes/i) {
  2084. printMsg("$AllDiffs");
  2085. }
  2086. printMsg("\nDo you want to continue the migration Yes/No [No] ?");
  2087. $answer = <STDIN> ;
  2088. if (! ($answer =~ /y|yes/i)) {
  2089. exit(1);
  2090. }
  2091. }
  2092. }
  2093. }
  2094. #############################################################################
  2095. sub db2ldif {
  2096. my ($conf, $ldif_dir) = @_;
  2097. $ENV{"$LIB_PATH"}=$old_libpath;
  2098. if (!$conf) {
  2099. $conf = "$oldHome${PATHSEP}config${PATHSEP}slapd.conf";
  2100. }
  2101. if (! $ldif_dir) { $ldif_dir = $ldif_rep ;}
  2102. if (!(-d $ldif_dir)) {
  2103. mkdir($ldif_dir,0777) or die "can't create $ldif_rep to store temporary ldif files";
  2104. }
  2105. my $dir = "$oldDir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server";
  2106. chdir($dir) or
  2107. die "Error: could not change directory to $dir: $!";
  2108. my @suffixnames = keys(%DBNAMES) ;
  2109. foreach $suffixname (@suffixnames) {
  2110. my $ldif_file = $ldif_dir.$DBNAMES{$suffixname}.".ldif" ;
  2111. # If we are on NT, ${quote} is setup to "\"", else it's setup to ""
  2112. # As the suffix can contain some space characters, I write the suffix parameter: "\"$suffixname\"" rather than "${quote}$suffixname${quote}"
  2113. my @cmd =
  2114. ( "${quote}$oldDir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server" .
  2115. "${PATHSEP}$slapdExecName${quote}", "db2ldif", '-n', '-f',
  2116. "${quote}$conf${quote}", '-a', "${quote}$ldif_file${quote}",
  2117. '-d', '1','-s',"\"$suffixname\"" );
  2118. open(DB2LDIF, "${quote}@cmd${quote} 2>&1|") or
  2119. die "Error: could not execute @cmd: $!";
  2120. sleep(1); # allow pipe to fill with data
  2121. $ii = 0; # counter
  2122. while (<DB2LDIF>) {
  2123. ++$ii;
  2124. if (($ii % 250) == 0) {
  2125. printMsg(" Processing...\n");
  2126. }
  2127. }
  2128. close(DB2LDIF);
  2129. # set the ownership of the ldif file; should be the same as the new slapd user id
  2130. if ((! $isNt) && ($oldlocaluser ne $localuser)) {
  2131. if (-f $ldif_file) {
  2132. chown( $newuid, $newgid, $ldif_file) or printMsg("\nUnable to change the ownership of $ldif_file to $localuser") ;
  2133. }
  2134. }
  2135. }
  2136. print " Done.\n";
  2137. chdir($curdir) or die "Could not change directory to $curdir: $!";
  2138. }
  2139. #############################################################################
  2140. # This db2ldif is used to export database of the new instance
  2141. sub newinst_db2ldif {
  2142. my $ldif = shift ;
  2143. my $include_suffix = shift ;
  2144. my $home = shift ;
  2145. my $db2ldif_param = "db2ldif -r -D $home -a $ldif -s \"$include_suffix\"";
  2146. open(DB2LDIF, "${quote}${quote}$slapdExecName${quote} $db2ldif_param${quote} 2>&1 |") or die "Could not run ns-slapd program $ldif2db_exe\n";
  2147. sleep(1); # allow some data to accumulate in the pipe
  2148. my $ii = 0;
  2149. while (<DB2LDIF>) {
  2150. ++$ii;
  2151. if (($ii % 250) == 0) {
  2152. printMsg(" Processing...\n");
  2153. }
  2154. printMsg($_);
  2155. }
  2156. close(DB2LDIF);
  2157. # set the ownership of the ldif file; should be the same as the 5.x slapd user id
  2158. if ((! $isNt) && ($oldlocaluser ne $localuser)) {
  2159. if (-f $ldif) {
  2160. chown( $newuid, $newgid, $ldif) or printMsg("\nUnable to change the ownership of $ldif to $localuser") ;
  2161. }
  2162. }
  2163. }
  2164. #############################################################################
  2165. # this is used to run the system() call, capture exit and signal codes,
  2166. # and die() upon badness; the first argument is a directory to change
  2167. # dir to, if any, and the rest are passed to system()
  2168. sub mySystem {
  2169. my $rc = &mySystemNoDie(@_);
  2170. my ($dir, @args) = @_;
  2171. if ($rc == 0) {
  2172. # success
  2173. } elsif ($rc == 0xff00) {
  2174. die "Error executing @args: error code $rc: $!";
  2175. } elsif ($rc > 0x80) {
  2176. $rc >>= 8;
  2177. die "Error executing @args: error code $rc: $!";
  2178. } else {
  2179. if ($rc & 0x80) {
  2180. $rc &= ~0x80;
  2181. }
  2182. die "Error executing @args: received signal $rc: $!";
  2183. }
  2184. # usually won't get return value
  2185. return $rc;
  2186. }
  2187. # This version does not die but just returns the error code
  2188. sub mySystemNoDie {
  2189. my ($dir, @args) = @_;
  2190. if ($dir && ($dir ne "")) {
  2191. chdir($dir) or die "Could not change directory to $dir: $!";
  2192. }
  2193. my $cmd = $args[0];
  2194. # the system {$cmd} avoids some NT shell quoting problems if the $cmd
  2195. # needs to be quoted e.g. contains spaces; the map puts double quotes
  2196. # around the arguments on NT which are stripped by the command
  2197. # interpreter cmd.exe; but don't quote things which are already quoted
  2198. my @fixargs = map { /^[\"].*[\"]$/ ? $_ : $quote . $_ . $quote } @args;
  2199. my $rc = 0;
  2200. if ($cmd =~ /[.](bat|cmd)$/) {
  2201. # we have to pass batch files directly to the NT command interpreter
  2202. $cmd = $com_spec;
  2203. # print "system $cmd /c \"@fixargs\"\n";
  2204. $rc = 0xffff & system {$cmd} '/c', "\"@fixargs\"";
  2205. } else {
  2206. # print "system $cmd @fixargs\n";
  2207. $rc = 0xffff & system {$cmd} @fixargs;
  2208. }
  2209. chdir(${curdir}) or die "Could not change directory to $curdir: $!";
  2210. return $rc;
  2211. }
  2212. #############################################################################
  2213. sub manyLdif2db {
  2214. my %rev_dbnames = reverse(%DBNAMES);
  2215. @backends = keys(%rev_dbnames);
  2216. $ENV{"$LIB_PATH"}=$new_libpath;
  2217. chdir($slapdExecDir) or die "Could not change directory to $slapdExecDir: $!";
  2218. foreach $backend (@backends) {
  2219. my $ldif = "${ldif_rep}$backend.ldif" ;
  2220. if (! -f $ldif) {
  2221. $ldif = ${ldif_rep}."data.ldif";
  2222. }
  2223. &Ldif2db($ldif, $backend);
  2224. }
  2225. # remove the empty ldif directory
  2226. # but not if using the data dir
  2227. if (!$olddatadir) {
  2228. rmdir($ldif_rep);
  2229. }
  2230. chdir($curdir) or die "Could not change directory to $curdir: $!";
  2231. }
  2232. sub Ldif2db {
  2233. my $ldif = shift ;
  2234. my $backend = shift ;
  2235. my $ldif2db_param = "ldif2db -D $serverHome -n $backend -i $ldif";
  2236. open(LDIF2DB, "${quote}${quote}$slapdExecName${quote} $ldif2db_param${quote} 2>&1 |") or die "Could not run ns-slapd program $ldif2db_exe\n";
  2237. sleep(1); # allow some data to accumulate in the pipe
  2238. while (<LDIF2DB>) {
  2239. printMsg($_);
  2240. }
  2241. close(LDIF2DB);
  2242. # remove the ldif file after the import
  2243. # but not if using the data dir
  2244. if (!$olddatadir) {
  2245. unlink($ldif) ;
  2246. }
  2247. }
  2248. #############################################################################
  2249. #sub copyBak {
  2250. # opendir( OLDBAK, "$oldHome${PATHSEP}bak" ) ||
  2251. # die "Can't open directory $oldHome${PATHSEP}bak: $!: ";
  2252. # local ( @dirs ) = readdir( OLDBAK );
  2253. # closedir ( OLDBAK );
  2254. # for ( @dirs ) {
  2255. # if ( $_ eq "." || $_ eq ".." ) {
  2256. # next;
  2257. # } elsif ( -d "$oldHome${PATHSEP}bak${PATHSEP}$_" ) {
  2258. # $srcDir = "$oldHome${PATHSEP}bak${PATHSEP}$_";
  2259. # $destDir = "$serverHome${PATHSEP}bak${PATHSEP}$_";
  2260. # $srcLDIF = "$oldHome${PATHSEP}ldif${PATHSEP}bak.ldif";
  2261. # $destLDIF = "$serverHome${PATHSEP}ldif${PATHSEP}bak.ldif";
  2262. # mkdir( $destDir , 0755 ) if !( -e $destDir);
  2263. # # Converting database
  2264. # if ( !$isNT && $newuser ) {
  2265. # chown($newuid, $newgid,
  2266. # "$serverHome${PATHSEP}bak", $destDir);
  2267. # }
  2268. # &other_db2ldif($srcDir, $srcLDIF);
  2269. # if ($needAclUpg) {
  2270. # &mySystem("$root${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server",
  2271. # "$root${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server" .
  2272. # "${PATHSEP}aclupg$exe_suffix", '-d', '-i',
  2273. # $srcLDIF, '-o', $destLDIF);
  2274. # } else {
  2275. # &copyBinFile($srcLDIF, $destLDIF);
  2276. # }
  2277. # &other_ldif2db($destLDIF, $destDir);
  2278. # }
  2279. # }
  2280. #}
  2281. #############################################################################
  2282. sub startServer {
  2283. my $instanceDir = ${serverHome} ;
  2284. my $errLog = $instanceDir . $PATHSEP . 'logs' . $PATHSEP . 'errors';
  2285. # emulate tail -f
  2286. # if the last line we see does not contain "slapd started", try again
  2287. my $done = 0;
  2288. my $started = 0;
  2289. my $code = 0;
  2290. my $lastLine = "";
  2291. my $timeout = time + 240; # 4 minutes
  2292. $ENV{"$LIB_PATH"}=$new_libpath;
  2293. my $startCmd = $instanceDir . $PATHSEP . 'start' . $script_suffix;
  2294. if (! -f $startCmd) {
  2295. $startCmd = $instanceDir . $PATHSEP . 'start-slapd' . $script_suffix;
  2296. }
  2297. printTrace("\nInstanceDir: $instanceDir\n",4);
  2298. $code = &mySystem($instanceDir,$startCmd);
  2299. open(IN, $errLog) or die "Could not open error log $errLog: $!";
  2300. my $pos = tell(IN);
  2301. while (($done == 0) && (time < $timeout)) {
  2302. for (; ($done == 0) && ($_ = <IN>); $pos = tell(IN)) {
  2303. $lastLine = $_;
  2304. # print;
  2305. # the server has already been started and shutdown once . . .
  2306. if (/slapd started\./) {
  2307. $started++;
  2308. if ($started == 2) {
  2309. $done = 1;
  2310. }
  2311. # sometimes the server will fail to come up; in that case, restart it
  2312. } elsif (/Initialization Failed/) {
  2313. # print "Server failed to start: $_";
  2314. $code = &mySystem($instanceDir, $startCmd);
  2315. # sometimes the server will fail to come up; in that case, restart it
  2316. } elsif (/exiting\./) {
  2317. # print "Server failed to start: $_";
  2318. #$code = &mySystem($startCmd);
  2319. $code = &mySystem($instanceDir, $startCmd);
  2320. }
  2321. }
  2322. if ($lastLine =~ /PR_Bind/) {
  2323. # server port conflicts with another one, just report and punt
  2324. print $lastLine;
  2325. print "This server cannot be started until the other server on this\n";
  2326. print "port is shutdown.\n";
  2327. $done = 1;
  2328. }
  2329. if ($done == 0) {
  2330. # rest a bit, then . . .
  2331. sleep(2);
  2332. # . . . reset the EOF status of the file desc
  2333. seek(IN, $pos, 0);
  2334. }
  2335. }
  2336. close(IN);
  2337. if ($started < 2) {
  2338. $! = $code;
  2339. # $now = time;
  2340. # if ($now > $timeout) {
  2341. # print "Possible timeout: timeout=$timeout now=$now\n";
  2342. # }
  2343. die "Error: could not start server: $!";
  2344. }
  2345. return 0;
  2346. }
  2347. sub stopServer {
  2348. my $root = shift;
  2349. my $name = shift;
  2350. $maxStopIterations = 5;
  2351. print "\nShutting down server $name . . .\n";
  2352. $ENV{"$LIB_PATH"}=$new_libpath;
  2353. $stopCmd = $quote . $root . $PATHSEP . $name . $PATHSEP . 'stop' . $script_suffix . $quote;
  2354. if (! -f $stopCmd) {
  2355. $stopCmd = $quote . $root . $PATHSEP . $name . $PATHSEP . 'stop-slapd' . $script_suffix . $quote;
  2356. }
  2357. if (! -f $stopCmd) {
  2358. # no stop command, probably a 1.X system; for NT, we'll try net stop
  2359. # for unix, we'll get the pid and kill it
  2360. if ($isNT) {
  2361. $stopCmd = 'net stop ' . $name;
  2362. } else {
  2363. # see if there is a pid file
  2364. $pidfile = $root . $PATHSEP . $name . $PATHSEP . 'logs' .
  2365. $PATHSEP . 'pid';
  2366. if (open(PIDFILE, $pidfile)) {
  2367. chomp($pid = <PIDFILE>);
  2368. close(PIDFILE);
  2369. while ($maxStopIterations-- && !$exitCode) {
  2370. $exitCode = kill(15, $pid);
  2371. }
  2372. $stopCmd = undef;
  2373. }
  2374. }
  2375. }
  2376. # keep looping until the stop cmd returns an error code, which usually
  2377. # means that what ever we want to stop is stopped, or some other error
  2378. # occurred e.g. permission, or no such service
  2379. $exitCode = &runAndIgnoreOutput($stopCmd);
  2380. # print "stopServer: exitCode=$exitCode\n";
  2381. while ($stopCmd && $maxStopIterations-- && $exitCode) {
  2382. $exitCode = &runAndIgnoreOutput($stopCmd);
  2383. # print "stopServer: exitCode=$exitCode\n";
  2384. }
  2385. if (!$maxStopIterations) {
  2386. print "Warning: could not shutdown the server: $!\n";
  2387. }
  2388. sleep(10) ;
  2389. $exitCode = 0;
  2390. }
  2391. sub runAndIgnoreOutput {
  2392. my $cmd = shift;
  2393. printMsg(".");
  2394. open(RUNCMD, "${quote}$cmd${quote} 2>&1 |") or die "Error: could not run $cmd: $!";
  2395. printMsg(".");
  2396. sleep(1); # allow pipe to fill with data
  2397. printMsg(".");
  2398. while (<RUNCMD>) {
  2399. # print;
  2400. }
  2401. my $code = close(RUNCMD);
  2402. # print "runAndIgnore: code=$code status=$?\n";
  2403. return $?;
  2404. }
  2405. #############################################################################
  2406. # migrate some of entries present in the old DSE.ldif like
  2407. # cn=snmp,cn=config
  2408. # cn=encryption,cn=config
  2409. # all the aci's
  2410. sub MigrateDSE {
  2411. printTrace("\nMigrate DSE entries...",1);
  2412. open( DSELDIF, "< $oldDSEldif" ) || die "Can't open $oldDSEldif: $!: ";
  2413. my $in = new Mozilla::LDAP::LDIF(*DSELDIF) ;
  2414. while ($old_entry = readOneEntry $in) {
  2415. my $DN = $old_entry->getDN() ;
  2416. SWITCH: {
  2417. # migrate the entrie: cn=snmp,cn=config
  2418. if ($DN =~ /^cn=SNMP,cn=config$/i) {
  2419. my $entry = $conn->search("$DN","base","objectclass=nsSNMP");
  2420. if ($entry) {
  2421. my $res = $conn->update($old_entry);
  2422. if ($res) {
  2423. printTrace("\n$DN updated !",2);
  2424. }
  2425. else {
  2426. printMsg("\nFailed to update $DN");
  2427. }
  2428. }
  2429. else {
  2430. printMsg("\nUnable to get info under $DN");
  2431. }
  2432. last SWITCH;
  2433. }
  2434. # migrate the entrie: cn=encryption,cn=config
  2435. if ($DN =~ /cn=encryption,cn=config$/i) {
  2436. if ($conn->search("$DN","base","objectclass=*")) {
  2437. if ($old_entry->hasValue("objectClass", "nsEncryptionConfig")) {
  2438. my $certfile = "alias/slapd-" . $newname . "-cert8.db";
  2439. my $keyfile = "alias/slapd-" . $newname. "-key3.db";
  2440. $old_entry->setValues("nsCertfile",$certfile) if ! $old_entry->hasValue("nsCertfile",$certfile);
  2441. $old_entry->setValues("nsKeyfile",$keyfile) if ! $old_entry->hasValue("nsKeyfile",$keyfile);
  2442. }
  2443. my $res = $conn->update($old_entry);
  2444. if ($res) {
  2445. printTrace("\n$DN updated !",2);
  2446. }
  2447. else {
  2448. printMsg("\nFailed to update $DN");
  2449. }
  2450. }
  2451. else {
  2452. my $res = $conn->add($old_entry);
  2453. if ($res) {
  2454. printTrace("\n$DN added !",2);
  2455. }
  2456. else {
  2457. printMsg("\nFailed to add $DN");
  2458. }
  2459. }
  2460. last SWITCH;
  2461. }
  2462. if (@{$old_entry->{aci}} && (! ($DN =~ /^cn=monitor$/i)) && (! ($DN =~ /^cn=schema$/i))) {
  2463. # migrate aci's
  2464. my $entry = $conn->search("$DN","base","objectclass=*");
  2465. if ($entry) {
  2466. my $res = $conn->update($old_entry);
  2467. if ($res) {
  2468. printTrace("\n$DN updated !",2);
  2469. }
  2470. else {
  2471. printMsg("\nFailed to update $DN");
  2472. }
  2473. }
  2474. else {
  2475. my $res = $conn->add($old_entry);
  2476. if ($res) {
  2477. printTrace("\n$DN added !",2);
  2478. }
  2479. else {
  2480. printMsg("\nFailed to add $DN");
  2481. }
  2482. }
  2483. last SWITCH;
  2484. }
  2485. }
  2486. }
  2487. close(DSELDIF);
  2488. }
  2489. #############################################################################
  2490. # migrate SSL info
  2491. sub MigrateSSL {
  2492. my $secPwd = 'bidon' ;
  2493. # copy the SSL directory
  2494. &copyDir("$oldHome${PATHSEP}ssl","$serverHome${PATHSEP}ssl");
  2495. # copy the cert db and key files
  2496. if ( -d "$oldDir${PATHSEP}alias") {
  2497. $aliasDir = "$root${PATHSEP}alias";
  2498. if (! -d $aliasDir) {
  2499. mkdir($aliasDir, 0750);
  2500. }
  2501. &stopServer($root,'slapd-'.$newname);
  2502. my $keydb = "$aliasDir${PATHSEP}slapd-$newname-key3.db" ;
  2503. my $certdb = "$aliasDir${PATHSEP}slapd-$newname-cert8.db" ;
  2504. my $certdb7 = "$aliasDir${PATHSEP}slapd-$newname-cert7.db" ;
  2505. my $old_keydb = "$oldDir${PATHSEP}alias${PATHSEP}slapd-$oldname-key3.db" ;
  2506. my $old_certdb = "$oldDir${PATHSEP}alias${PATHSEP}slapd-$oldname-cert7.db";
  2507. my $keydb_backup = "$aliasDir${PATHSEP}slapd-$newname-key3.db_backup" ;
  2508. my $certdb_backup = "$aliasDir${PATHSEP}slapd-$newname-cert7.db_backup" ;
  2509. if (-f $old_keydb) {
  2510. if (-f $keydb) {
  2511. if ($NO_INPUT_USER) {
  2512. printMsg("\n$keydb already exists. backup in $keydb_backup ...");
  2513. &copyBinFile($keydb,$keydb_backup);
  2514. &copyBinFile($old_keydb,$keydb);
  2515. }
  2516. else {
  2517. print("\n\n$keydb already exists. Do you want to overwrite it ? [no]: ");
  2518. my $answer = <STDIN> ;
  2519. if ($answer =~ /^y|yes$/i) {
  2520. &copyBinFile($old_keydb,$keydb);
  2521. }
  2522. }
  2523. }
  2524. else {
  2525. &copyBinFile($old_keydb,$keydb);
  2526. }
  2527. }
  2528. if (-f $old_certdb) {
  2529. $mode = (stat($old_certdb))[2] if $PRESERVE;
  2530. if (-f $certdb) {
  2531. if ($NO_INPUT_USER) {
  2532. printMsg("\n$certdb already exists. backup in $certdb_backup ...");
  2533. &copyBinFile($certdb,$certdb_backup);
  2534. unlink($certdb) || print "Couldn't delete $certdb : $!\n";
  2535. &copyBinFile($old_certdb,$certdb7);
  2536. }
  2537. else {
  2538. print("\n\n$certdb already exists. Do you want to overwrite it ? [no]: ");
  2539. my $answer = <STDIN> ;
  2540. if ($answer =~ /^y|yes$/i) {
  2541. unlink($certdb) || print "Couldn't delete $certdb : $!\n";
  2542. &copyBinFile($old_certdb,$certdb7);
  2543. }
  2544. }
  2545. }
  2546. else {
  2547. &copyBinFile($old_certdb,$certdb7);
  2548. }
  2549. }
  2550. # copy the old password file
  2551. if (-f "$oldDir${PATHSEP}alias${PATHSEP}$type-$oldname-pin.txt") {
  2552. &copyBinFile(
  2553. "$oldDir${PATHSEP}alias${PATHSEP}$type-$oldname-pin.txt",
  2554. "$aliasDir${PATHSEP}$type-$newname-pin.txt"
  2555. );
  2556. }
  2557. &startServer();
  2558. if ($PRESERVE) {
  2559. chown($newuid,$newgid,$certdb) || print "Failed to set uid $newuid gid $newgid on $certdb : $!\n";
  2560. chmod($mode,$certdb) || print "Failed to set mode $mode on $certdb : $!\n";
  2561. }
  2562. }
  2563. }
  2564. sub DisableSSL {
  2565. my $entry = $conn->search("cn=config","base","objectclass=*");
  2566. my $LDAPparam = "nsslapd-security" ;
  2567. my $Value = "off" ;
  2568. if ($entry->{$LDAPparam}[0] ne $Value) {
  2569. printTrace("\nDisable SSL...",1);
  2570. $entry->setValues($LDAPparam, $Value);
  2571. }
  2572. my $res = $conn->update($entry);
  2573. if ($res) {
  2574. printTrace("\nSSL disabled",2);
  2575. }
  2576. else {
  2577. printMsg("\nCan't disable SSL, the server may have problems starting");
  2578. }
  2579. }
  2580. # enable the migration of client authentication informations
  2581. sub MigrateCertmap {
  2582. # backup the old new certmap.conf and replace it with the old certmap.conf file
  2583. my $oldCertmap = "$oldDir${PATHSEP}shared${PATHSEP}config${PATHSEP}certmap.conf";
  2584. my $newCertmap = "$root${PATHSEP}shared${PATHSEP}config${PATHSEP}certmap.conf" ;
  2585. my $backupCertmap = "$root${PATHSEP}shared${PATHSEP}config${PATHSEP}certmap.conf_backup" ;
  2586. if (&hasChangedoldCertmap($oldCertmap)) {
  2587. if ($NO_INPUT_USER) {
  2588. printMsg("\n$newCertmap has been backup in $backupCertmap");
  2589. &copyBinFile($newCertmap,$backupCertmap);
  2590. &copyBinFile($oldCertmap,$newCertmap);
  2591. }
  2592. else {
  2593. my $Ask = 1 ;
  2594. while ($Ask) {
  2595. printMsg("\n\nWhere do you want to back up the file $newCertmap [$backupCertmap] ?") ;
  2596. my $Answer = <STDIN> ;
  2597. $backupCertmap = $Answer if ($Answer ne "\n");
  2598. chomp($backupCertmap);
  2599. printTrace("\nDest: .$backupCertmap.",4);
  2600. if (-e $backupCertmap) {
  2601. printMsg("\n\n$backupCertmap already exists. Do you want to overwrite it Yes/No [No] ?") ;
  2602. if (<STDIN> =~ /yes|y/i) {
  2603. $Ask = 0 ;
  2604. }
  2605. else {
  2606. $backupCertmap = "$root${PATHSEP}shared${PATHSEP}config${PATHSEP}certmap.conf_backup" ;
  2607. }
  2608. }
  2609. else {
  2610. $Ask = 0 ;
  2611. }
  2612. }
  2613. printTrace("\nBackup file: $newCertmap in $backupCertmap",4);
  2614. &copyBinFile($newCertmap,$backupCertmap);
  2615. &copyBinFile($oldCertmap,$newCertmap);
  2616. }
  2617. }
  2618. else {
  2619. }
  2620. }
  2621. sub hasChangedoldCertmap {
  2622. my $certmapfile = shift ;
  2623. my @reference = ("certmap default default",
  2624. "default:DNComps",
  2625. "default:FilterComps e") ;
  2626. my $cpt = 0 ;
  2627. printTrace("\nhasChangedoldCertmap",3);
  2628. open(CERTMAP,"< $certmapfile");
  2629. while (<CERTMAP>) {
  2630. if ((! /^\s*#/) && (! /^\s*$/)) {
  2631. my $ref = $reference[$cpt] ;
  2632. printTrace("\nValue: $_, ref: $ref",4);
  2633. if (! /^\s*$ref\s*$/) {
  2634. return 1 ;
  2635. }
  2636. else {
  2637. $cpt++ ;
  2638. }
  2639. }
  2640. }
  2641. close (CERTMAP);
  2642. printTrace("\ncpt: $cpt",4);
  2643. if ($cpt < $#reference) {
  2644. return 1 ;
  2645. }
  2646. else {
  2647. return 0 ;
  2648. }
  2649. }
  2650. #############################################################################
  2651. # copy a directory to another
  2652. sub copyDir {
  2653. my $src = shift;
  2654. my $dest = shift;
  2655. my $exclude = shift;
  2656. opendir( SRC, $src ) or die "Can't open directory $src: $!: ";
  2657. my $mode;
  2658. my $uid;
  2659. my $gid;
  2660. mkdir ( $dest , 0755 ) or die "\nCan't create directory $dest. \nPlease check you have enough rights to create it and/or check that your parent directory exists.\n" if !( -e $dest );
  2661. if ($PRESERVE) {
  2662. $mode = (stat($src))[2];
  2663. ($uid, $gid) = (stat(_))[4..5];
  2664. # Make sure files owned by the old user are owned by the
  2665. # new user
  2666. if ($uid == $olduid) {
  2667. $uid = $newuid;
  2668. $gid = $newgid;
  2669. }
  2670. chown $uid, $gid, $dest;
  2671. chmod $mode, $dest;
  2672. }
  2673. local ( @files ) = readdir ( SRC );
  2674. closedir( SRC );
  2675. for ( @files ) {
  2676. if ( $_ eq "." || $_ eq ".." ) {
  2677. next;
  2678. } elsif ( $exclude && /$exclude/ ) {
  2679. next;
  2680. } elsif( -d "$src${PATHSEP}$_") {
  2681. &copyDir ( "$src${PATHSEP}$_", "$dest${PATHSEP}$_" );
  2682. } else {
  2683. &copyBinFile ( "$src${PATHSEP}$_", "$dest${PATHSEP}$_");
  2684. }
  2685. }
  2686. }
  2687. sub copyBinFile {
  2688. my $src = shift;
  2689. my $dest = shift;
  2690. my $buf = "";
  2691. my $bufsize = 8192;
  2692. open( SRC, $src ) || die "Can't open $src: $!\n";
  2693. # if we are given a directory destination instead of a file, extract the
  2694. # filename portion of the source to use as the destination filename
  2695. if (-d $dest) {
  2696. $dest = $dest . $PATHSEP . &basename($src);
  2697. }
  2698. open( DEST, ">$dest" ) || die "Can't create $dest: $!\n";
  2699. binmode SRC;
  2700. binmode DEST;
  2701. if ($PRESERVE) {
  2702. $mode = (stat($src))[2];
  2703. ($uid, $gid) = (stat(_))[4..5];
  2704. # Make sure files owned by the old user are owned by the
  2705. # new user
  2706. if ($uid == $olduid) {
  2707. $uid = $newuid;
  2708. $gid = $newgid;
  2709. }
  2710. chown $uid, $gid, $dest;
  2711. chmod $mode, $dest;
  2712. }
  2713. while (read(SRC, $buf, $bufsize)) {
  2714. print DEST $buf;
  2715. }
  2716. close( SRC );
  2717. close( DEST );
  2718. }
  2719. #############################################################################
  2720. # backup new configuration files
  2721. # backup the directory <new_root_server>/slapd-instance/config in <new_root_server>/slapd-instance/BackupConfig
  2722. sub backupConfigFiles {
  2723. # backup the new config files
  2724. my $src = "$serverHome${PATHSEP}config" ;
  2725. my $dest = "$serverHome${PATHSEP}config_backup" ;
  2726. if ($NO_INPUT_USER) {
  2727. printMsg("\n$src has been backup in $dest");
  2728. &copyDir($src,$dest);
  2729. }
  2730. else {
  2731. my $Ask = 1 ;
  2732. while ($Ask) {
  2733. printMsg("\n\nWhere do you want to back up your configuration directory [$dest] ?") ;
  2734. my $Answer = <STDIN> ;
  2735. $dest = $Answer if ($Answer ne "\n");
  2736. chomp($dest);
  2737. printTrace("\nDest: .$dest.",4);
  2738. if (-e $dest) {
  2739. printMsg("\n\n$dest already exists. Do you want to overwrite it Yes/No [No] ?") ;
  2740. if (<STDIN> =~ /yes|y/i) {
  2741. $Ask = 0 ;
  2742. }
  2743. else {
  2744. $dest = "$serverHome${PATHSEP}config_backup" ;
  2745. }
  2746. }
  2747. else {
  2748. $Ask = 0 ;
  2749. }
  2750. }
  2751. printTrace("\nBackup Directory: $src in $dest",4);
  2752. &copyDir($src,$dest);
  2753. }
  2754. }
  2755. #############################################################################
  2756. sub getLDAPservername {
  2757. my $oldLDAPservername;
  2758. my $LDAPservername;
  2759. open(OLDSLAPDCONF, $oldSlapdConf) or
  2760. die "\nError: could not open old config file $oldSlapdConf \n";
  2761. while(<OLDSLAPDCONF>) {
  2762. chop;
  2763. if (/^localhost\s+/i) {
  2764. ($oldLDAPservername = $') =~ s/^[\"]//;;
  2765. $oldLDAPservername =~ s/[\"]$//;
  2766. printTrace("\nName of the old LDAP server: $oldLDAPservername",3);
  2767. }
  2768. }
  2769. close(OLDSLAPDCONF);
  2770. open( DSELDIF, "< $DSEldif" ) || die "\nCan't open $DSEldif \n";
  2771. my $in = new Mozilla::LDAP::LDIF(*DSELDIF) ;
  2772. while ($entry = readOneEntry $in) {
  2773. my $DN = $entry->getDN() ;
  2774. if ($DN =~ /^cn=config$/i) {
  2775. my $localhost = "nsslapd-localhost";
  2776. my @values = $entry->getValues($localhost);
  2777. if ($#values != -1) {
  2778. $LDAPservername = $values[0];
  2779. }
  2780. break;
  2781. }
  2782. }
  2783. close(DSELDIF);
  2784. # check old and new are installed on the same physical machine.
  2785. if (lc($oldLDAPservername) ne lc($LDAPservername)) {
  2786. # warn the user he tries to migrate a old server installed on a different machine from the new one
  2787. printMsg("\n\nYour old server is on $oldLDAPservername, and your new server is on $LDAPservername. We don't support migration on different machines. Do you want to continue ? Yes/No [No]:") ;
  2788. if (! (<STDIN> =~ /yes|y/i)) {
  2789. return -1;
  2790. }
  2791. }
  2792. return $LDAPservername ;
  2793. }
  2794. #############################################################################
  2795. sub getLibPath {
  2796. my $myDir = shift;
  2797. my $myVersion = shift;
  2798. my $myMinor = shift;
  2799. if ($isNT) {
  2800. return $ENV{"$LIB_PATH"};
  2801. }
  2802. if (($myVersion >= 6) && ($myMinor >= 2)) {
  2803. return
  2804. "$myDir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}lib${SEP}".
  2805. "$myDir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server${SEP}".
  2806. $ENV{"$LIB_PATH"};
  2807. } else {
  2808. return "$myDir${PATHSEP}lib${SEP}".$ENV{"$LIB_PATH"};
  2809. }
  2810. }
  2811. #############################################################################
  2812. sub getVersion {
  2813. my $dir = shift;
  2814. my $versionstr = shift;
  2815. my $version = 0;
  2816. my $minor = 0;
  2817. my $buildNumber = 0;
  2818. my $progDir = "${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server${PATHSEP}";
  2819. my $progDir2 = "${PATHSEP}bin${PATHSEP}slapd${PATHSEP}";
  2820. # find the slapd executable
  2821. if (!$versionstr) { # version not specified on cmd line - find it
  2822. $prog = $dir . $progDir . $slapdExecName;
  2823. if (! -f $prog) {
  2824. $prog = $dir . $progDir2 . $slapdExecName;
  2825. if (-f $prog && $isNT) {
  2826. # if slapd is in bin/slapd and we're on NT, just assume version 1;
  2827. # apparently, slapd.exe doesn't like the -v argument . . .
  2828. return ( '1', $minor );
  2829. }
  2830. else{
  2831. die "Could not run slapd program $prog: $!";
  2832. }
  2833. }
  2834. else {
  2835. chdir($dir . $progDir);
  2836. }
  2837. $cur_libpath=$ENV{"$LIB_PATH"};
  2838. $ENV{"$LIB_PATH"}=
  2839. "$dir${PATHSEP}lib${SEP}".
  2840. "$dir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}lib${SEP}".
  2841. "$dir${PATHSEP}bin${PATHSEP}slapd${PATHSEP}server${SEP}".
  2842. $ENV{"$LIB_PATH"};
  2843. # read the old version from the old slapd program
  2844. open(F, "${quote}${quote}$prog${quote} -v${quote} 2>&1 |") or
  2845. die "Could not run slapd program $prog: $!";
  2846. sleep(1); # allow some data to accumulate in the pipe
  2847. # print "Output from $prog -v:\n";
  2848. while (<F>) {
  2849. if (/^Red Hat-Directory/ || /^Netscape-Directory/ || /^iPlanet-Directory/i) {
  2850. $versionstr = $_;
  2851. last;
  2852. }
  2853. }
  2854. $code = close(F);
  2855. # print "$prog returned code=$code status=$?\n";
  2856. $ENV{"$LIB_PATH"}=$cur_libpath;
  2857. }
  2858. if ($versionstr =~ /^Red Hat-Directory\/(\d+)\.(\d+)(?:b\d)*\s+(\S+)/) {
  2859. $version = $1;
  2860. $minor = $2;
  2861. $buildNumber = $3;
  2862. }
  2863. elsif ($versionstr =~ /^Netscape-Directory\/(\d+)\.(\d+)(?:b\d)*\s+(\S+)/) {
  2864. $version = $1;
  2865. $minor = $2;
  2866. $buildNumber = $3;
  2867. }
  2868. elsif ($versionstr =~ /^Netscape-Directory\(restrict?ed-mode\)\/(\d+)\.(\d+)\s+(\S+)/) { # we can have restricted-mode or restriced-mode ...
  2869. $version = $1;
  2870. $minor = $2;
  2871. $buildNumber = $3;
  2872. }
  2873. elsif ($versionstr =~ /^iPlanet-Directory\/(\d+)\.(\d+)\s+(\S+)/i) {
  2874. $version = $1;
  2875. $minor = $2;
  2876. $buildNumber = $3;
  2877. } elsif ($versionstr =~ /(\d+)\.(\d+)/) {
  2878. $version = $1;
  2879. $minor = $2;
  2880. }
  2881. if ($version == 0) {
  2882. die "\nCould not determine version of the directory server in $dir: \n";
  2883. }
  2884. # distinguish the 4.1 and the 4.11 thanks to the buildNumber
  2885. if (($version == 4) && ($minor == 1)){
  2886. if (! ($buildNumber =~ /^B99\.16/)) {
  2887. # it's not a 4.1 Netscape Directory Server => it's a 4.11
  2888. $minor = 11 ;
  2889. }
  2890. }
  2891. chdir($curdir) or die "Could not change directory to $curdir: $!" ;
  2892. return ( $version, $minor );
  2893. }
  2894. #############################################################################
  2895. sub getDiff {
  2896. # we get references to arrays
  2897. my $elements = shift ;
  2898. my $existing_elements = shift ;
  2899. my %count = () ;
  2900. my %countEE = () ;
  2901. @diff = () ;
  2902. foreach $e (@{$elements}, @{$existing_elements}) { $count{$e}++ ;}
  2903. foreach $e (@{existing_elements}) { $countEE{$e}++ ;}
  2904. foreach $e (@{$elements}) {
  2905. # if $e is only present in @$elements, we push it to the diff array
  2906. if (($count{$e} == 1) && ($countEE{$e} == 0)) {
  2907. push @diff, $e ;
  2908. }
  2909. }
  2910. return @diff ;
  2911. }
  2912. ###############################################################################################
  2913. sub testIndexUpdating {
  2914. #my $entry = $conn->newEntry();
  2915. #$entry->setDN("cn=djeattribute,cn=index,cn=MigratedDB_5,cn=ldbm database,cn=plugins,cn=config");
  2916. my $entry = $conn->search("cn=mail,cn=index,cn=MigratedDB_2,cn=ldbm database,cn=plugins,cn=config","base","objectclass=nsIndex");
  2917. my @types = ("pres", "sub", "eq") ;
  2918. my @existing_types = $entry->getValues("nsindextype");
  2919. my @typesToAdd = &getDiff(\@types, \@existing_types);
  2920. foreach $newtype (@typesToAdd) {
  2921. $entry->addValue("nsindextype", $newtype); printTrace("\nnewtype: $newtype",2);
  2922. }
  2923. my $res = $conn->update($entry) ;
  2924. if ($res) {print("\nUpdate index mail\n");}
  2925. else { print("\ncan't update index mail");}
  2926. $entry = $conn->search("cn=givenName,cn=index,cn=MigratedDB_2,cn=ldbm database,cn=plugins,cn=config","base","objectclass=nsIndex");
  2927. @types = ("pres", "sub", "eq") ;
  2928. @existing_types = $entry->getValues("nsindextype"); print("\ngivenName, existing_types: @existing_types");
  2929. @typesToAdd = &getDiff(\@types, \@existing_types); print("\nTypesToAdd: @typesToAdd");
  2930. foreach $newtype (@typesToAdd) {
  2931. $entry->addValue("nsindextype", $newtype); printTrace("\nnewtype: $newtype",2);
  2932. }
  2933. my $res = $conn->update($entry) ;
  2934. if ($res) {print("\nUpdate index givenName\n");}
  2935. else { print("\ncan't update index givenName");}
  2936. }
  2937. ###############################################################################################
  2938. sub normalizeDir {
  2939. my $dir = shift ;
  2940. my $dir_prec = "" ;
  2941. while ($dir_prec ne $dir) {
  2942. $dir_prec = $dir ;
  2943. if ($isNT) {
  2944. grep { s@\\\\@\\@g } $dir ;
  2945. }
  2946. else {
  2947. grep { s@//@/@g } $dir ;
  2948. }
  2949. }
  2950. return $dir ;
  2951. }
  2952. ###############################################################################################
  2953. # return 1 if the value parameters is
  2954. sub isAllowedPlugin {
  2955. my $Value = lc(shift) ;
  2956. if ($allowedPlugins{$Value}) {
  2957. return 1 ;
  2958. }
  2959. else {
  2960. return 0 ;
  2961. }
  2962. }
  2963. sub getSyntaxOid {
  2964. my $Value = lc(shift) ;
  2965. return $allowedPlugins{$Value} ;
  2966. }
  2967. ###############################################################################################
  2968. # return 1 if the value given in parameters is an allowed modifier
  2969. sub isAllowedModifier {
  2970. my $Value = lc(shift) ;
  2971. if ($allowedModifiers{$Value}) {
  2972. return 1 ;
  2973. }
  2974. else {
  2975. return 0 ;
  2976. }
  2977. }
  2978. sub getModifierValue {
  2979. my $Value = lc(shift) ;
  2980. return $allowedModifiers{$Value} ;
  2981. }
  2982. ###############################################################################################
  2983. sub GetTime {
  2984. my $tm = localtime;
  2985. (my $sec, my $min, my $hour, my $dd, my $mm, my $yy) = ($tm->sec, $tm->min, $tm->hour, $tm->mday, ($tm->mon)+1, ($tm->year)+1900);
  2986. $sec = "0$sec" unless $sec > 9 ;
  2987. $min = "0$min" unless $min > 9 ;
  2988. $hour = "0$hour" unless $hour > 9 ;
  2989. $dd = "0$dd" unless $dd > 9 ;
  2990. $mm = "0$mm" unless $mm > 9 ;
  2991. return ($sec, $min, $hour, $dd, $mm, $yy);
  2992. }
  2993. ###############################################################################################
  2994. # get uid and group id of the new slapd server.
  2995. # The uid is done through the nsslapd-localuser attribute
  2996. sub getuid_gid {
  2997. my $newuid ;
  2998. my $newgid ;
  2999. my $localuser ;
  3000. my $localuser_attr = "nsslapd-localuser" ;
  3001. if (! $isNT) {
  3002. my $entry = $conn->search("cn=config ", "base","objectclass=*", 0, ($localuser_attr)) ;
  3003. # Tests wether we succeed to get the entry cn=config
  3004. die "\nCan't get the entry cn=config \n" unless ($entry);
  3005. my @values = $entry->getValues($localuser_attr);
  3006. if ($#values == -1 || ($values[0] eq "") ) { # tests wether the nsslapd-localuser attribute has a value
  3007. printMsg("\nNo localuser has been found in the configuration of the directory. ");
  3008. if ($NO_INPUT_USER) {
  3009. printMsg("\nWe considered nobody as the localuser");
  3010. $localuser = "nobody" ;
  3011. }
  3012. else {
  3013. my $Ask = 1 ;
  3014. while ($Ask) {
  3015. printMsg("\nUnder what user does your $Version.$Minor directory server run [nobody] ? ") ;
  3016. $localuser = <STDIN> ;
  3017. chomp($localuser);
  3018. $localuser = "nobody" if ($localuser eq "");
  3019. ($newuid, $newgid) = (getpwnam("$localuser"))[2..3] ;
  3020. if ($newuid) {
  3021. $Ask = 0 ;
  3022. }
  3023. else {
  3024. printMsg("\nError: $localuser is unknown from the system ");
  3025. }
  3026. }
  3027. }
  3028. }
  3029. else {
  3030. $localuser = $values[0]; # returns the first value (we should only have one localuser)
  3031. my $size = $#values ;
  3032. }
  3033. ($newuid, $newgid) = (getpwnam("$localuser"))[2..3] ;
  3034. return ($localuser, $newuid, $newgid) ;
  3035. }
  3036. else {
  3037. return () ;
  3038. }
  3039. }
  3040. ###############################################################################################
  3041. # get uid and group id of the old slapd server.
  3042. sub getolduid_gid {
  3043. my $oldlocaluser ;
  3044. if (! $isNT) {
  3045. open(CONF, $oldSlapdConf) or die "\nError: cannot open $oldSlapdConf: $!\n";
  3046. while (<CONF>) {
  3047. if (/^localuser\s+/i) {
  3048. chomp($oldlocaluser = $');
  3049. last;
  3050. }
  3051. }
  3052. close(CONF);
  3053. ($olduid, $oldgid) = (getpwnam("$oldlocaluser"))[2..3] ;
  3054. return ($oldlocaluser, $olduid, $oldgid) ;
  3055. }
  3056. else {
  3057. return ();
  3058. }
  3059. }
  3060. ###############################################################################################
  3061. # get current directory
  3062. sub getCwd {
  3063. my $command = $isNT ? "cd" : "/bin/pwd";
  3064. open(PWDCMD, "$command 2>&1 |") or
  3065. die "Error: could not execute $command: $!";
  3066. # without the following sleep, reading from the pipe will
  3067. # return nothing; I guess it gives the pwd command time
  3068. # to get some data to read . . .
  3069. sleep(1);
  3070. my $currentdir;
  3071. while (<PWDCMD>) {
  3072. if (!$currentdir) {
  3073. chomp($currentdir = $_);
  3074. }
  3075. }
  3076. my $code = close(PWDCMD);
  3077. # if ($code || $?) {
  3078. # print "$command returned code=$code status=$? dir=$curdir\n";
  3079. # }
  3080. # print "getCwd curdir=\[$curdir\]\n";
  3081. return $currentdir;
  3082. }