ux-dialog.cc 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /*********************************************************************
  39. **
  40. ** NAME:
  41. ** ux-dialog.cc
  42. **
  43. ** DESCRIPTION:
  44. ** Netscape Directory Server Pre-installation Program
  45. ** Definitions for UI dialogs.
  46. **
  47. ** NOTES:
  48. **
  49. **
  50. *********************************************************************/
  51. #if !defined(HPUX) || defined(_HP_NAMESPACE_STD)
  52. #include <iostream>
  53. #include <strstream>
  54. #include <fstream>
  55. using namespace std;
  56. using std::ostrstream;
  57. #else
  58. /* older HP-UX compiler, using libstd 1 (no -AA) */
  59. #include <iostream.h> /* use old name on older systems */
  60. #include <strstream.h>
  61. #include <fstream.h>
  62. #endif
  63. #include <errno.h>
  64. #include <stdio.h>
  65. #include <unistd.h>
  66. #include <ctype.h>
  67. #include <string.h>
  68. #include <strings.h>
  69. #include "utf8.h"
  70. #include "ux-util.h"
  71. #include "dialog.h"
  72. #include "ux-dialog.h"
  73. #include "ux-config.h"
  74. #include "install_keywords.h"
  75. extern "C" {
  76. #include "dsalib.h"
  77. #include "nspr.h"
  78. #include "plstr.h"
  79. }
  80. static const char *DEFAULT_SLAPDUSER = "cn=Directory Manager";
  81. // #define DEBUG 2
  82. /*
  83. ** Forward References
  84. */
  85. static DialogAction askSlapdPortSetup (Dialog *me);
  86. static DialogAction askSlapdPortNext(Dialog *me);
  87. static DialogAction askSlapdServerIDSetup (Dialog *me);
  88. static DialogAction askSlapdServerIDNext(Dialog *me);
  89. static DialogAction askSlapdRootDNSetup(Dialog *me);
  90. static DialogAction askSlapdRootDNNext (Dialog *me);
  91. static DialogAction askMCAdminIDSetup (Dialog *me);
  92. static DialogAction askMCAdminIDNext (Dialog *me);
  93. static DialogAction askReconfigMCAdminPwdSetup (Dialog *me);
  94. static DialogAction askReconfigMCAdminPwdNext (Dialog *me);
  95. static DialogAction askSlapdSuffixSetup (Dialog *me);
  96. static DialogAction askSlapdSuffixNext (Dialog *me);
  97. static DialogAction askSampleSetup (Dialog *me);
  98. static DialogAction askSampleNext (Dialog *me);
  99. static DialogAction askPopulateSetup (Dialog *me);
  100. static DialogAction askPopulateNext (Dialog *me);
  101. static DialogAction askOrgSizeSetup (Dialog *me);
  102. static DialogAction askOrgSizeNext (Dialog *me);
  103. static DialogAction askCIRSetup(Dialog *me);
  104. static DialogAction askCIRNext(Dialog *me);
  105. static DialogAction askCIRHostSetup(Dialog *me);
  106. static DialogAction askCIRHostNext(Dialog *me);
  107. static DialogAction askCIRPortSetup(Dialog *me);
  108. static DialogAction askCIRPortNext(Dialog *me);
  109. static DialogAction askCIRDNSetup(Dialog *me);
  110. static DialogAction askCIRDNNext(Dialog *me);
  111. static DialogAction askCIRSuffixSetup(Dialog *me);
  112. static DialogAction askCIRSuffixNext(Dialog *me);
  113. static DialogAction askCIRSSLSetup(Dialog *me);
  114. static DialogAction askCIRSSLNext(Dialog *me);
  115. static DialogAction askCIRIntervalSetup(Dialog *me);
  116. static DialogAction askCIRIntervalNext(Dialog *me);
  117. static DialogAction askCIRDaysSetup(Dialog *me);
  118. static DialogAction askCIRDaysNext(Dialog *me);
  119. static DialogAction askCIRTimesSetup(Dialog *me);
  120. static DialogAction askCIRTimesNext(Dialog *me);
  121. static DialogAction askSIRSetup(Dialog *me);
  122. static DialogAction askSIRNext(Dialog *me);
  123. static DialogAction askChangeLogSuffixSetup(Dialog *me);
  124. static DialogAction askChangeLogSuffixNext(Dialog *me);
  125. static DialogAction askChangeLogDirSetup(Dialog *me);
  126. static DialogAction askChangeLogDirNext(Dialog *me);
  127. static DialogAction askReplicationDNSetup(Dialog *me);
  128. static DialogAction askReplicationDNNext(Dialog *me);
  129. static DialogAction askReplicationSetup(Dialog *me);
  130. static DialogAction askReplicationNext(Dialog *me);
  131. static DialogAction askConsumerDNSetup(Dialog *me);
  132. static DialogAction askConsumerDNNext(Dialog *me);
  133. static DialogAction askSIRHostSetup(Dialog *me);
  134. static DialogAction askSIRHostNext(Dialog *me);
  135. static DialogAction askSIRPortSetup(Dialog *me);
  136. static DialogAction askSIRPortNext(Dialog *me);
  137. static DialogAction askSIRDNSetup(Dialog *me);
  138. static DialogAction askSIRDNNext(Dialog *me);
  139. static DialogAction askSIRSuffixSetup(Dialog *me);
  140. static DialogAction askSIRSuffixNext(Dialog *me);
  141. static DialogAction askSIRSSLSetup(Dialog *me);
  142. static DialogAction askSIRSSLNext(Dialog *me);
  143. static DialogAction askSIRDaysSetup(Dialog *me);
  144. static DialogAction askSIRDaysNext(Dialog *me);
  145. static DialogAction askSIRTimesSetup(Dialog *me);
  146. static DialogAction askSIRTimesNext(Dialog *me);
  147. static DialogAction askUseExistingMCSetup(Dialog *me);
  148. static DialogAction askUseExistingMCNext(Dialog *me);
  149. static DialogAction askMCHostSetup(Dialog *me);
  150. static DialogAction askMCHostNext(Dialog *me);
  151. static DialogAction askMCPortSetup(Dialog *me);
  152. static DialogAction askMCPortNext(Dialog *me);
  153. static DialogAction askMCDNSetup(Dialog *me);
  154. static DialogAction askMCDNNext(Dialog *me);
  155. static DialogAction askDisableSchemaCheckingSetup(Dialog *me);
  156. static DialogAction askDisableSchemaCheckingNext(Dialog *me);
  157. static DialogAction askMCAdminDomainSetup(Dialog *me);
  158. static DialogAction askMCAdminDomainNext(Dialog *me);
  159. static DialogAction askAdminDomainSetup(Dialog *me);
  160. static DialogAction askAdminDomainNext(Dialog *me);
  161. static DialogAction askUseExistingUGSetup(Dialog *me);
  162. static DialogAction askUseExistingUGNext(Dialog *me);
  163. static DialogAction askUGHostSetup(Dialog *me);
  164. static DialogAction askUGHostNext(Dialog *me);
  165. static DialogAction askUGPortSetup(Dialog *me);
  166. static DialogAction askUGPortNext(Dialog *me);
  167. static DialogAction askUGDNSetup(Dialog *me);
  168. static DialogAction askUGDNNext(Dialog *me);
  169. static DialogAction askUGSuffixSetup(Dialog *me);
  170. static DialogAction askUGSuffixNext(Dialog *me);
  171. static int
  172. isAValidDN(const char *dn_to_test)
  173. {
  174. int ret = 1;
  175. if (!dn_to_test || !*dn_to_test)
  176. {
  177. ret = 0;
  178. }
  179. else
  180. {
  181. char **rdnList = ldap_explode_dn(dn_to_test, 0);
  182. char **rdnNoTypes = ldap_explode_dn(dn_to_test, 1);
  183. if (!rdnList || !rdnList[0] || !rdnNoTypes || !rdnNoTypes[0] ||
  184. !*rdnNoTypes[0] || !strcasecmp(rdnList[0], rdnNoTypes[0]))
  185. {
  186. ret = 0;
  187. }
  188. if (rdnList)
  189. ldap_value_free(rdnList);
  190. if (rdnNoTypes)
  191. ldap_value_free(rdnNoTypes);
  192. }
  193. if ((ret == 1) && ds_dn_uses_LDAPv2_quoting(dn_to_test))
  194. {
  195. char *newdn = strdup(dn_to_test);
  196. dn_normalize_convert(newdn);
  197. char *oldlocaldn = UTF8ToLocal(dn_to_test);
  198. char *newlocaldn = UTF8ToLocal(newdn);
  199. free(newdn);
  200. NSString msg = NSString(
  201. "The given value [") + oldlocaldn + "] is quoted in the deprecated LDAPv2 style\n" +
  202. "quoting format. It will be automatically converted to use the\n" +
  203. "LDAPv3 style escaped format [" + newlocaldn + "].";
  204. DialogManagerType::showAlert(msg);
  205. nsSetupFree(oldlocaldn);
  206. nsSetupFree(newlocaldn);
  207. }
  208. return ret;
  209. }
  210. static int
  211. contains8BitChars(const char *s)
  212. {
  213. int ret = 0;
  214. if (s && *s)
  215. {
  216. for (; !ret && *s; ++s)
  217. {
  218. ret = (*s & 0x80);
  219. }
  220. }
  221. return ret;
  222. }
  223. static int
  224. rootDNPwdIsValid(const char *pwd)
  225. {
  226. if (!pwd || !*pwd || (strlen(pwd) < 8))
  227. return 0;
  228. return !contains8BitChars(pwd);
  229. }
  230. static int
  231. isValid(const char *s)
  232. {
  233. if (!s)
  234. return 1; // null is a valid response (means to accept default)
  235. int ret = 1;
  236. char *ncs = (char *)s; // cast away const-ness for ldaputf8 stuff
  237. // trim spaces from the beginning of the string
  238. while (*ncs && ldap_utf8isspace(ncs))
  239. LDAP_UTF8INC(ncs);
  240. if (!*ncs) // empty string or all spaces
  241. ret = 0;
  242. return ret;
  243. }
  244. static int
  245. isValidServerID(const char *s)
  246. {
  247. if (!s || !*s)
  248. return 0;
  249. if (!isValid(s))
  250. return 0;
  251. if (contains8BitChars(s))
  252. return 0;
  253. // server ID should contain alphanum, _, -, . since it will
  254. // be used for both a filename and a DN component
  255. const char *badChars = "`~!@#$%^&*()[]|\\\"\':;,+=/<>?";
  256. const char *p = s;
  257. for (; *p && !strchr(badChars, *p); ++p)
  258. ;
  259. if (!*p) // the string contains all valid chars
  260. return 1;
  261. return 0;
  262. }
  263. static int
  264. isValidYesNo(const char *s)
  265. {
  266. if (!s)
  267. return 1; // null means accept default
  268. const char *msg = 0;
  269. if (isValid(s))
  270. {
  271. int len = strlen(s);
  272. if (strncasecmp(s, "yes", len) && strncasecmp(s, "no", len))
  273. {
  274. msg = "Please type yes or no.";
  275. }
  276. }
  277. else
  278. {
  279. msg = "Please specify a valid string.";
  280. }
  281. if (msg)
  282. {
  283. DialogManagerType::showAlert(msg);
  284. return 0;
  285. }
  286. return 1;
  287. }
  288. static int
  289. dialogSetup (Dialog *me, const char *which, const char *defaultAns)
  290. {
  291. const char *ans = getManager(me)->getDefaultScript()->get(which);
  292. if (!ans)
  293. ans = getManager(me)->getAdminScript()->get(which);
  294. if (!ans)
  295. ans = getManager(me)->getBaseScript()->get(which);
  296. int status;
  297. if (ans == NULL)
  298. status = 0;
  299. else
  300. status = 1;
  301. /*
  302. int status = (int)ans; // 0 - there was already a value in the script
  303. // not zero - no value already in script
  304. */
  305. if (ans)
  306. me->setDefaultAns(ans);
  307. else if (defaultAns)
  308. me->setDefaultAns(defaultAns);
  309. return status;
  310. }
  311. DialogInput askSlapdPort(
  312. "The standard directory server network port number is 389. However, if\n"
  313. "you are not logged as the superuser, or port 389 is in use, the\n"
  314. "default value will be a random unused port number greater than 1024.\n"
  315. "If you want to use port 389, make sure that you are logged in as the\n"
  316. "superuser, that port 389 is not in use, and that you run the admin\n"
  317. "server as the superuser.\n",
  318. "Directory server network port",
  319. NULL,
  320. askSlapdPortSetup,
  321. askSlapdPortNext
  322. );
  323. static DialogAction
  324. askSlapdPortSetup(Dialog *me)
  325. {
  326. #if DEBUG > 1
  327. cerr << "Entering askSlapdPortSetup" << endl;
  328. #endif
  329. char tmp[10];
  330. int port = 389;
  331. const char *defPort =
  332. getManager(me)->getDefaultScript()->get(SLAPD_KEY_SERVER_PORT);
  333. if (defPort && *defPort && atoi(defPort) > 0)
  334. {
  335. PL_strncpyz(tmp, defPort, sizeof(tmp));
  336. port = atoi(defPort);
  337. }
  338. else
  339. PR_snprintf(tmp, sizeof(tmp), "%d", port);
  340. // see if default port is available
  341. if (InstUtil::portAvailable(port) == False)
  342. {
  343. // start with a random port number, and keep going until we find
  344. // an available port
  345. int origport = port = InstUtil::guessPort();
  346. while (InstUtil::portAvailable(port) == False)
  347. {
  348. ++port;
  349. if (port > MAXPORT)
  350. port = MINPORT;
  351. if (port == origport)
  352. {
  353. port = -1; // NO AVAILABLE PORTS!!!!!!!
  354. break;
  355. }
  356. }
  357. }
  358. if (port == -1) // NO AVAILABLE PORTS!!!!!!!
  359. {
  360. #if DEBUG > 1
  361. cerr << "Leaving askSlapdPortSetup DIALOG_ERROR" << endl;
  362. #endif
  363. return DIALOG_ERROR;
  364. }
  365. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SERVER_PORT, (long)port);
  366. dialogSetup(me, SLAPD_KEY_SERVER_PORT, tmp);
  367. long setupval = 0;
  368. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  369. setupval == SETUP_ONLY)
  370. {
  371. #if DEBUG > 1
  372. cerr << "Leaving askSlapdPortSetup DIALOG_NEXT" << endl;
  373. #endif
  374. return DIALOG_NEXT;
  375. }
  376. #if DEBUG > 1
  377. cerr << "Leaving askSlapdPortSetup DIALOG_SAME" << endl;
  378. #endif
  379. return DIALOG_SAME;
  380. }
  381. static DialogAction
  382. askSlapdPortNext(Dialog *me)
  383. {
  384. #if DEBUG > 1
  385. cerr << "Entering askSlapdPortNext" << endl;
  386. #endif
  387. const char *buf = me->input();
  388. const char *tmp;
  389. char testbuf[1024];
  390. int port, err = 0;
  391. if (buf[0] == 0)
  392. {
  393. tmp = me->defaultAns();
  394. }
  395. else
  396. {
  397. tmp = buf;
  398. }
  399. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SERVER_PORT, tmp);
  400. port = atoi(tmp);
  401. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  402. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  403. {
  404. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  405. "Please choose another port between 1 and %d.\n\n",
  406. port, MAXPORT);
  407. err = -1;
  408. }
  409. else if (InstUtil::portAvailable(port) == False)
  410. {
  411. PR_snprintf(testbuf, sizeof(testbuf), "ERROR: Unable to bind to port %d\n"
  412. "Please choose another port.\n\n", port);
  413. err = -1;
  414. }
  415. if (err)
  416. {
  417. DialogManagerType::showAlert(testbuf);
  418. return DIALOG_SAME;
  419. }
  420. #if DEBUG > 1
  421. cerr << "Leaving askSlapdPortNext" << endl;
  422. #endif
  423. return DIALOG_NEXT;
  424. }
  425. DialogInput askSlapdServerID(
  426. "Each instance of a directory server requires a unique identifier.\n"
  427. "Press Enter to accept the default, or type in another name and press\n"
  428. "Enter.\n",
  429. "Directory server identifier",
  430. NULL,
  431. askSlapdServerIDSetup,
  432. askSlapdServerIDNext
  433. );
  434. static DialogAction
  435. askSlapdServerIDSetup(Dialog *me)
  436. {
  437. #if DEBUG > 1
  438. cerr << "Entering askSlapdServerIDSetup" << endl;
  439. #endif
  440. // extract the hostname part of the FQDN
  441. const char *tmp = 0;
  442. char *basehost = 0;
  443. if ((tmp = getManager(me)->getBaseScript()->get(SLAPD_KEY_FULL_MACHINE_NAME))) {
  444. basehost = strdup(tmp);
  445. } else {
  446. basehost = strdup(InstUtil::guessHostname());
  447. }
  448. if (!basehost)
  449. return DIALOG_ERROR;
  450. char *ptr = strchr(basehost, '.');
  451. if (ptr)
  452. {
  453. *ptr = 0;
  454. }
  455. else
  456. {
  457. free(basehost);
  458. basehost = 0;
  459. }
  460. const char *ans =
  461. getManager(me)->getDefaultScript()->get(SLAPD_KEY_SERVER_IDENTIFIER);
  462. if (!ans && basehost)
  463. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SERVER_IDENTIFIER,
  464. basehost);
  465. else if (!ans && !basehost)
  466. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SERVER_IDENTIFIER,
  467. InstUtil::guessHostname());
  468. if (ans)
  469. {
  470. me->setDefaultAns(ans);
  471. }
  472. else if (basehost)
  473. {
  474. me->setDefaultAns(basehost);
  475. }
  476. else
  477. {
  478. me->setDefaultAns(InstUtil::guessHostname());
  479. }
  480. if (basehost)
  481. free(basehost);
  482. long setupval = 0;
  483. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  484. setupval == SETUP_ONLY)
  485. {
  486. #if DEBUG > 1
  487. cerr << "Leaving askSlapdServerIDSetup DIALOG_SAME" << endl;
  488. #endif
  489. return DIALOG_NEXT;
  490. }
  491. #if DEBUG > 1
  492. cerr << "Leaving askSlapdServerIDSetup DIALOG_SAME" << endl;
  493. #endif
  494. return DIALOG_SAME;
  495. }
  496. static DialogAction
  497. askSlapdServerIDNext(Dialog *me)
  498. {
  499. const char *buf = me->input();
  500. const char *tmp;
  501. char testbuf[1024];
  502. int err = 0;
  503. if (buf[0] == 0)
  504. {
  505. tmp = me->defaultAns();
  506. }
  507. else
  508. {
  509. tmp = buf;
  510. }
  511. if (!tmp)
  512. {
  513. err = -1;
  514. PR_snprintf(testbuf, sizeof(testbuf), "The name must not be empty");
  515. }
  516. else if (!isValid(tmp))
  517. {
  518. err = -1;
  519. PR_snprintf(testbuf, sizeof(testbuf), "Please specify a valid value for the name.");
  520. }
  521. else if (contains8BitChars(tmp))
  522. {
  523. err = -1;
  524. PR_snprintf(testbuf, sizeof(testbuf), "The server ID must contain 7 bit ascii only.");
  525. }
  526. else if (!isValidServerID(tmp))
  527. {
  528. err = -1;
  529. PR_snprintf(testbuf, sizeof(testbuf), "The server ID must be a valid filename and DN component.");
  530. }
  531. if (!err)
  532. {
  533. // see if an instance by the same name already exists
  534. NSString instanceDir = NSString(
  535. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ROOT)
  536. ) + "/slapd-" + tmp;
  537. if (InstUtil::fileExists(instanceDir))
  538. {
  539. PR_snprintf(testbuf, sizeof(testbuf), "ERROR: a server instance named [%s] already exists."
  540. " Please choose a unique name.\n", tmp);
  541. err = -1;
  542. }
  543. }
  544. if (tmp)
  545. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SERVER_IDENTIFIER, tmp);
  546. if (err)
  547. {
  548. DialogManagerType::showAlert(testbuf);
  549. return DIALOG_SAME;
  550. }
  551. return DIALOG_NEXT;
  552. }
  553. DialogInput askMCAdminID(
  554. "Please enter the administrator ID for the Fedora configuration\n"
  555. "directory server. This is the ID typically used to log in to the\n"
  556. "console. You will also be prompted for the password.\n",
  557. "Fedora configuration directory server\nadministrator ID",
  558. "admin",
  559. askMCAdminIDSetup,
  560. askMCAdminIDNext
  561. );
  562. static DialogAction
  563. askMCAdminIDSetup(Dialog *me)
  564. {
  565. #if DEBUG > 1
  566. cerr << "Entering askMCAdminIDSetup" << endl;
  567. #endif
  568. if (getManager(me)->getAdminScript() &&
  569. getManager(me)->getAdminScript()->get(SLAPD_KEY_ADMIN_SERVER_ID) &&
  570. getManager(me)->getAdminScript()->get(SLAPD_KEY_ADMIN_SERVER_PWD))
  571. {
  572. // see if the MC Admin ID has been provided
  573. if (getManager(me)->getBaseScript() &&
  574. !(getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID) &&
  575. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_PWD)))
  576. {
  577. getManager(me)->getBaseScript()->set(
  578. SLAPD_KEY_SERVER_ADMIN_ID,
  579. getManager(me)->getAdminScript()->get(SLAPD_KEY_ADMIN_SERVER_ID)
  580. );
  581. getManager(me)->getBaseScript()->set(
  582. SLAPD_KEY_SERVER_ADMIN_PWD,
  583. getManager(me)->getAdminScript()->get(SLAPD_KEY_ADMIN_SERVER_PWD)
  584. );
  585. }
  586. }
  587. dialogSetup(me, SLAPD_KEY_SERVER_ADMIN_ID, "admin");
  588. long setupval = 0;
  589. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  590. setupval == SETUP_ONLY)
  591. {
  592. #if DEBUG > 1
  593. cerr << "Leaving askMCAdminIDSetup setup DIALOG_NEXT" << endl;
  594. #endif
  595. return DIALOG_NEXT;
  596. }
  597. // this dialog is only used for creating the MC Admin; don't use it if
  598. // we will be using an existing MC i.e. we are not creating the MC host
  599. DialogAction action = DIALOG_NEXT;
  600. long actionval = 0;
  601. me->getUserData(ACTION, actionval);
  602. action = (DialogAction)actionval;
  603. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  604. {
  605. #if DEBUG > 1
  606. cerr << "Leaving askMCAdminIDSetup DIALOG_NEXT" << endl;
  607. #endif
  608. return action;
  609. }
  610. #if DEBUG > 1
  611. cerr << "Leaving askMCAdminIDSetup DIALOG_SAME" << endl;
  612. #endif
  613. return DIALOG_SAME;
  614. }
  615. static DialogAction
  616. askMCAdminIDNext(Dialog *me)
  617. {
  618. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  619. return DIALOG_NEXT;
  620. long setupval = 0;
  621. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  622. setupval == SETUP_ONLY)
  623. {
  624. #if DEBUG > 1
  625. cerr << "Leaving askMCAdminIDNext setup DIALOG_NEXT" << endl;
  626. #endif
  627. return DIALOG_NEXT;
  628. }
  629. const char *adminUser;
  630. const char *adminPwd;
  631. const char *buf;
  632. buf = me->input();
  633. if (buf[0] == 0)
  634. {
  635. adminUser = me->defaultAns();
  636. }
  637. else
  638. {
  639. adminUser = buf;
  640. }
  641. if (!isValid(adminUser))
  642. {
  643. DialogManagerType::showAlert("Please enter a valid ID.");
  644. return DIALOG_SAME;
  645. }
  646. else if (!isAValidDN(adminUser) && contains8BitChars(adminUser))
  647. {
  648. DialogManagerType::showAlert("The user ID value must be 7 bit ASCII only.");
  649. return DIALOG_SAME;
  650. }
  651. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_ID, adminUser);
  652. while (1)
  653. {
  654. // cerr << "before password in askMCAdminIDNext" << endl;
  655. me->showString("Password: ");
  656. // cerr << "after password in askMCAdminIDNext" << endl;
  657. if (me->getPassword () == 0)
  658. {
  659. return DIALOG_PREV;
  660. }
  661. else
  662. {
  663. char *inp = strdup(me->input());
  664. if (inp[0] == 0)
  665. {
  666. continue;
  667. }
  668. else if (contains8BitChars(inp))
  669. {
  670. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  671. return DIALOG_SAME;
  672. }
  673. else if (!isValid(inp))
  674. {
  675. DialogManagerType::showAlert("Please enter a valid password.");
  676. return DIALOG_SAME;
  677. }
  678. else
  679. {
  680. me->showString("Password (again): ");
  681. if (me->getPassword() == 0)
  682. {
  683. return DIALOG_PREV;
  684. }
  685. else
  686. {
  687. adminPwd = me->input();
  688. if (strcmp(inp,adminPwd))
  689. {
  690. DialogManagerType::showAlert("Passwords don't match.");
  691. return DIALOG_SAME;
  692. }
  693. break;
  694. }
  695. }
  696. free(inp);
  697. }
  698. }
  699. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_PWD, adminPwd);
  700. return DIALOG_NEXT;
  701. }
  702. DialogInput askSlapdSuffix(
  703. "The suffix is the root of your directory tree. You may have more than\n"
  704. "one suffix.\n",
  705. "Suffix",
  706. NULL,
  707. askSlapdSuffixSetup,
  708. askSlapdSuffixNext
  709. );
  710. static DialogAction
  711. askSlapdSuffixSetup(Dialog *me)
  712. {
  713. DialogAction action = DIALOG_NEXT;
  714. long actionval = 0;
  715. me->getUserData(ACTION, actionval);
  716. action = (DialogAction)actionval;
  717. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  718. return action;
  719. if (!getManager(me)->getDefaultScript()->get(SLAPD_KEY_SUFFIX)) {
  720. getManager(me)->getDefaultScript()->set(
  721. SLAPD_KEY_SUFFIX, getManager(me)->getDefaultSuffix());
  722. }
  723. dialogSetup(me, SLAPD_KEY_SUFFIX, getManager(me)->getDefaultSuffix());
  724. long setupval = 0;
  725. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  726. setupval == SETUP_ONLY)
  727. return DIALOG_NEXT;
  728. return DIALOG_SAME;
  729. }
  730. static DialogAction
  731. askSlapdSuffixNext(Dialog *me)
  732. {
  733. const char *buf;
  734. NSString val;
  735. buf = me->input();
  736. if (buf[0] == 0)
  737. val = me->defaultAns();
  738. else
  739. val = buf;
  740. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SUFFIX, val);
  741. // check the value to see if it is a valid DN
  742. if (!isAValidDN(val))
  743. {
  744. DialogManagerType::showAlert("A suffix must be a valid DN.");
  745. return DIALOG_SAME;
  746. }
  747. else if (!isValid(val))
  748. {
  749. DialogManagerType::showAlert("Please enter a valid string.");
  750. return DIALOG_SAME;
  751. }
  752. return DIALOG_NEXT;
  753. }
  754. DialogInput askSlapdRootDN(
  755. "Certain directory server operations require an administrative user.\n"
  756. "This user is referred to as the Directory Manager and typically has a\n"
  757. "bind Distinguished Name (DN) of cn=Directory Manager. Press Enter to\n"
  758. "accept the default value, or enter another DN. In either case, you\n"
  759. "will be prompted for the password for this user. The password must\n"
  760. "be at least 8 characters long.\n",
  761. "Directory Manager DN",
  762. DEFAULT_SLAPDUSER,
  763. askSlapdRootDNSetup,
  764. askSlapdRootDNNext
  765. );
  766. static DialogAction
  767. askSlapdRootDNSetup(Dialog *me)
  768. {
  769. if (!getManager(me)->getDefaultScript()->get(SLAPD_KEY_ROOTDN))
  770. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ROOTDN,
  771. DEFAULT_SLAPDUSER);
  772. dialogSetup(me, SLAPD_KEY_ROOTDN, DEFAULT_SLAPDUSER);
  773. long setupval = 0;
  774. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  775. setupval == SETUP_ONLY)
  776. return DIALOG_NEXT;
  777. return DIALOG_SAME;
  778. }
  779. static DialogAction
  780. askSlapdRootDNNext(Dialog *me)
  781. {
  782. long setupval = 0;
  783. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  784. setupval == SETUP_ONLY)
  785. {
  786. #if DEBUG > 1
  787. cerr << "Leaving askSlapdRootDNNext setup DIALOG_NEXT" << endl;
  788. #endif
  789. return DIALOG_NEXT;
  790. }
  791. const char *slapdUser;
  792. const char *slapdPwd;
  793. const char *buf;
  794. buf = me->input();
  795. if (buf[0] == 0)
  796. {
  797. slapdUser = me->defaultAns();
  798. }
  799. else
  800. {
  801. slapdUser = buf;
  802. }
  803. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ROOTDN, slapdUser);
  804. // check the value to see if it is a valid DN
  805. if (!isAValidDN(slapdUser))
  806. {
  807. DialogManagerType::showAlert("The Directory Manager must be a valid DN.");
  808. return DIALOG_SAME;
  809. }
  810. else if (!isValid(slapdUser))
  811. {
  812. DialogManagerType::showAlert("Please enter a valid string.");
  813. return DIALOG_SAME;
  814. }
  815. while (1)
  816. {
  817. // cerr << "before password in askSlapdRootDNNext" << endl;
  818. me->showString("Password: ");
  819. // cerr << "after password in askSlapdRootDNNext" << endl;
  820. if (me->getPassword () == 0)
  821. {
  822. return DIALOG_PREV;
  823. }
  824. else
  825. {
  826. char *inp = strdup(me->input());
  827. if (inp[0] == 0)
  828. {
  829. continue;
  830. }
  831. else if (contains8BitChars(inp))
  832. {
  833. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  834. return DIALOG_SAME;
  835. }
  836. else if (!isValid(inp))
  837. {
  838. DialogManagerType::showAlert("Please enter a valid password.");
  839. return DIALOG_SAME;
  840. }
  841. else
  842. {
  843. me->showString("Password (again): ");
  844. if (me->getPassword() == 0)
  845. {
  846. return DIALOG_PREV;
  847. }
  848. else
  849. {
  850. slapdPwd = me->input();
  851. if (strcmp(inp,slapdPwd))
  852. {
  853. DialogManagerType::showAlert("Passwords don't match.");
  854. return DIALOG_SAME;
  855. }
  856. else if (!rootDNPwdIsValid(inp))
  857. {
  858. DialogManagerType::showAlert("Password must be at least 8 characters long");
  859. return DIALOG_SAME;
  860. }
  861. break;
  862. }
  863. }
  864. free(inp);
  865. }
  866. }
  867. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ROOTDNPWD, slapdPwd);
  868. return DIALOG_NEXT;
  869. }
  870. DialogYesNo askSample(
  871. "You may install some sample entries in this directory instance. These\n"
  872. "entries will be installed in a separate suffix and will not interfere\n"
  873. "with the normal operation of the directory server.\n",
  874. "Do you want to install the sample entries?",
  875. "No",
  876. askSampleSetup,
  877. askSampleNext
  878. );
  879. static DialogAction
  880. askSampleSetup(Dialog *me)
  881. {
  882. DialogAction action = DIALOG_NEXT;
  883. long actionval = 0;
  884. me->getUserData(ACTION, actionval);
  885. action = (DialogAction)actionval;
  886. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  887. return action;
  888. long setupval = 0;
  889. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  890. setupval == SETUP_ONLY)
  891. return DIALOG_NEXT;
  892. return DIALOG_SAME;
  893. }
  894. static DialogAction
  895. askSampleNext(Dialog *me)
  896. {
  897. const char *buf = me->input();
  898. if (!buf || !*buf)
  899. {
  900. buf = me->defaultAns();
  901. if (!buf || !*buf)
  902. buf = "No";
  903. }
  904. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_SAMPLE_ENTRIES, buf);
  905. if (!isValidYesNo(buf))
  906. return DIALOG_SAME;
  907. return DIALOG_NEXT;
  908. }
  909. DialogInput askPopulate(
  910. "You may wish to populate your new directory instance with some data.\n"
  911. "You may already have a file in LDIF format to use or some suggested\n"
  912. "entries can be added. If you want to import entries from an LDIF\n"
  913. "file, you may type in the full path and filename at the prompt. If\n"
  914. "you want the install program to add the suggested entries, type the\n"
  915. "word suggest at the prompt. The suggested entries are common\n"
  916. "container entries under your specified suffix, such as ou=People and\n"
  917. "ou=Groups, which are commonly used to hold the entries for the persons\n"
  918. "and groups in your organization. If you do not want to add any of\n"
  919. "these entries, type the word none at the prompt.\n",
  920. "Type the full path and filename, the word suggest, or the word none\n",
  921. "none",
  922. askPopulateSetup,
  923. askPopulateNext
  924. );
  925. static DialogAction
  926. askPopulateSetup(Dialog *me)
  927. {
  928. DialogAction action = DIALOG_NEXT;
  929. long actionval = 0;
  930. me->getUserData(ACTION, actionval);
  931. action = (DialogAction)actionval;
  932. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  933. return action;
  934. // if setting up a UG host, by default setup the suggested entries
  935. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  936. {
  937. getManager(me)->getDefaultScript()->set(SLAPD_KEY_INSTALL_LDIF_FILE,
  938. "suggest");
  939. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_ORG_ENTRIES,
  940. "Yes");
  941. }
  942. dialogSetup(me, SLAPD_KEY_INSTALL_LDIF_FILE, "none");
  943. // max input buffer size is sizeof(Dialog::_buf)-1
  944. // Dialog::_buf is defined as char[MED_BUF]
  945. me->setInputLen(MED_BUF-1); // it seems to get reset somewhere . . .
  946. long setupval = 0;
  947. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  948. setupval == SETUP_ONLY)
  949. return DIALOG_NEXT;
  950. return DIALOG_SAME;
  951. }
  952. static DialogAction
  953. askPopulateNext(Dialog *me)
  954. {
  955. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  956. return DIALOG_NEXT;
  957. const char *buf = me->input();
  958. if (!buf || !*buf)
  959. {
  960. buf = me->defaultAns();
  961. if (!buf || !*buf)
  962. buf = "No";
  963. }
  964. if (buf && !strncasecmp(buf, "none", strlen(buf)))
  965. {
  966. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_ORG_ENTRIES, "No");
  967. getManager(me)->getDefaultScript()->
  968. set(SLAPD_KEY_INSTALL_LDIF_FILE, "none");
  969. }
  970. else if (buf && !strncasecmp(buf, "suggest", strlen(buf)))
  971. {
  972. getManager(me)->getDefaultScript()->
  973. set(SLAPD_KEY_INSTALL_LDIF_FILE, "suggest");
  974. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_ORG_ENTRIES, "Yes");
  975. } else {
  976. getManager(me)->getDefaultScript()->set(SLAPD_KEY_INSTALL_LDIF_FILE, buf);
  977. if (!InstUtil::fileExists(buf))
  978. {
  979. NSString msg = NSString("The specified filename ") + buf + "\n" +
  980. "does not exist. Please try again.\n";
  981. DialogManagerType::showAlert(msg);
  982. return DIALOG_SAME;
  983. }
  984. else
  985. {
  986. getManager(me)->getDefaultScript()->
  987. set(SLAPD_KEY_ADD_ORG_ENTRIES, "Yes");
  988. getManager(me)->getDefaultScript()->
  989. set(SLAPD_KEY_INSTALL_LDIF_FILE, buf);
  990. }
  991. }
  992. return DIALOG_NEXT;
  993. }
  994. DialogInput askOrgSize(
  995. "Your directory will be populated with entries based on the size of\n"
  996. "your organization. The choices are small or large. Please specify 1\n"
  997. "for small and 2 for large.\n",
  998. "Organization size (1 or 2)",
  999. "1",
  1000. askOrgSizeSetup,
  1001. askOrgSizeNext
  1002. );
  1003. static DialogAction
  1004. askOrgSizeSetup(Dialog *me)
  1005. {
  1006. DialogAction action = DIALOG_NEXT;
  1007. long actionval = 0;
  1008. me->getUserData(ACTION, actionval);
  1009. action = (DialogAction)actionval;
  1010. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  1011. return action;
  1012. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_ADD_ORG_ENTRIES))
  1013. return action;
  1014. else if (dialogSetup(me, SLAPD_KEY_ORG_SIZE, "1") &&
  1015. getManager(me)->installMode() == Silent)
  1016. return DIALOG_ERROR;
  1017. long setupval = 0;
  1018. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1019. setupval == SETUP_ONLY)
  1020. return DIALOG_NEXT;
  1021. return DIALOG_SAME;
  1022. }
  1023. static DialogAction
  1024. askOrgSizeNext(Dialog *me)
  1025. {
  1026. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  1027. return DIALOG_NEXT;
  1028. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_ADD_ORG_ENTRIES))
  1029. return DIALOG_NEXT;
  1030. const char *buf = me->input();
  1031. const char *tmp;
  1032. char testbuf[1024];
  1033. int num, err = 0;
  1034. if (buf[0] == 0)
  1035. {
  1036. tmp = me->defaultAns();
  1037. }
  1038. else
  1039. {
  1040. tmp = buf;
  1041. }
  1042. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ORG_SIZE, tmp);
  1043. num = atoi(tmp);
  1044. if (num != 1 && num != 2)
  1045. {
  1046. PR_snprintf(testbuf, sizeof(testbuf), "Please enter a 1 or a 2\n\n");
  1047. err = -1;
  1048. }
  1049. if (err)
  1050. {
  1051. DialogManagerType::showAlert(testbuf);
  1052. return DIALOG_SAME;
  1053. }
  1054. return DIALOG_NEXT;
  1055. }
  1056. DialogYesNo askReplication(
  1057. "Replication is used to duplicate all or part of a directory server to\n"
  1058. "another directory server. This can be used for failsafe purposes, to\n"
  1059. "ensure that the directory data is always online and up-to-date in case\n"
  1060. "one server goes down. It is also useful for distributing directory\n"
  1061. "data from a central main repository to remote directory servers.\n",
  1062. "Do you want to configure this directory server\nto use replication?",
  1063. "No",
  1064. askReplicationSetup,
  1065. askReplicationNext
  1066. );
  1067. static DialogAction
  1068. askReplicationSetup(Dialog *me)
  1069. {
  1070. me = me;
  1071. long setupval = 0;
  1072. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1073. setupval == SETUP_ONLY)
  1074. return DIALOG_NEXT;
  1075. return DIALOG_SAME;
  1076. }
  1077. static DialogAction
  1078. askReplicationNext(Dialog *me)
  1079. {
  1080. const char *buf = me->input();
  1081. if (!buf || !*buf)
  1082. {
  1083. buf = me->defaultAns();
  1084. if (!buf || !*buf)
  1085. buf = "No";
  1086. }
  1087. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_REPLICATION, buf);
  1088. if (!isValidYesNo(buf))
  1089. return DIALOG_SAME;
  1090. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1091. {
  1092. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_SUPPLIER, "No");
  1093. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_CONSUMER, "No");
  1094. }
  1095. return DIALOG_NEXT;
  1096. }
  1097. DialogYesNo askCIR(
  1098. "You may want to set up your directory server as a consumer server to\n"
  1099. "receive replicated entries from another directory server. The first\n"
  1100. "two of the following methods configure this server as a consumer:\n\n"
  1101. "1) The supplier server will push its entries to this server (SIR)\n"
  1102. "2) This server will pull the entries from the supplier (CIR)\n"
  1103. "3) This server will not be a consumer for replication (NONE)\n",
  1104. "Do you want to set up this server as a consumer\n"
  1105. "for replication? (1, 2, or 3)",
  1106. "3",
  1107. askCIRSetup,
  1108. askCIRNext
  1109. );
  1110. static DialogAction
  1111. askCIRSetup(Dialog *me)
  1112. {
  1113. DialogAction action = DIALOG_NEXT;
  1114. long actionval = 0;
  1115. me->getUserData(ACTION, actionval);
  1116. action = (DialogAction)actionval;
  1117. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1118. return action;
  1119. long setupval = 0;
  1120. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1121. setupval == SETUP_ONLY)
  1122. return DIALOG_NEXT;
  1123. return DIALOG_SAME;
  1124. }
  1125. static DialogAction
  1126. askCIRNext(Dialog *me)
  1127. {
  1128. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1129. return DIALOG_NEXT;
  1130. const char *buf = me->input();
  1131. if (!buf || !*buf)
  1132. {
  1133. buf = me->defaultAns();
  1134. if (!buf || !*buf)
  1135. buf = "3";
  1136. }
  1137. int val = atoi(buf);
  1138. if (!val || val < 1 || val > 3)
  1139. {
  1140. DialogManagerType::showAlert("Please enter a 1, 2, or 3.");
  1141. return DIALOG_SAME;
  1142. }
  1143. else if (val == 3)
  1144. {
  1145. buf = "No";
  1146. }
  1147. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_CONSUMER, buf);
  1148. return DIALOG_NEXT;
  1149. }
  1150. DialogYesNo askSIR(
  1151. "You may want to set up your directory server as a supplier server to\n"
  1152. "replicate its entries to another directory server. The first two of\n"
  1153. "the following methods configure this server as a supplier:\n\n"
  1154. "1) This server will push its entries to another one (SIR)\n"
  1155. "2) Another server will pull entries from this one (CIR)\n"
  1156. "3) This server will not be a supplier for replication (NONE)\n",
  1157. "Do you want to set up this server as a supplier\n"
  1158. "for replication? (1, 2, or 3)",
  1159. "3",
  1160. askSIRSetup,
  1161. askSIRNext
  1162. );
  1163. static DialogAction
  1164. askSIRSetup(Dialog *me)
  1165. {
  1166. DialogAction action = DIALOG_NEXT;
  1167. long actionval = 0;
  1168. me->getUserData(ACTION, actionval);
  1169. action = (DialogAction)actionval;
  1170. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1171. return action;
  1172. long setupval = 0;
  1173. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1174. setupval == SETUP_ONLY)
  1175. return DIALOG_NEXT;
  1176. return DIALOG_SAME;
  1177. }
  1178. static DialogAction
  1179. askSIRNext(Dialog *me)
  1180. {
  1181. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1182. return DIALOG_NEXT;
  1183. const char *buf = me->input();
  1184. if (!buf || !*buf)
  1185. {
  1186. buf = me->defaultAns();
  1187. if (!buf || !*buf)
  1188. buf = "3";
  1189. }
  1190. int val = atoi(buf);
  1191. if (!val || val < 1 || val > 3)
  1192. {
  1193. DialogManagerType::showAlert("Please enter a 1, 2, or 3.");
  1194. return DIALOG_SAME;
  1195. }
  1196. else if (val == 3)
  1197. {
  1198. buf = "No";
  1199. }
  1200. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_SUPPLIER, buf);
  1201. return DIALOG_NEXT;
  1202. }
  1203. DialogInput askCIRHost(
  1204. "Please specify the host name of the server from which the replicated\n"
  1205. "entries will be copied.\n",
  1206. "Supplier host name",
  1207. 0,
  1208. askCIRHostSetup,
  1209. askCIRHostNext
  1210. );
  1211. static DialogAction
  1212. askCIRHostSetup(Dialog *me)
  1213. {
  1214. DialogAction action = DIALOG_NEXT;
  1215. long actionval = 0;
  1216. me->getUserData(ACTION, actionval);
  1217. action = (DialogAction)actionval;
  1218. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1219. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1220. return action;
  1221. else if (dialogSetup(me, SLAPD_KEY_CIR_HOST, 0) &&
  1222. getManager(me)->installMode() == Silent)
  1223. return DIALOG_ERROR;
  1224. long setupval = 0;
  1225. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1226. setupval == SETUP_ONLY)
  1227. return DIALOG_NEXT;
  1228. return DIALOG_SAME;
  1229. }
  1230. static DialogAction
  1231. askCIRHostNext(Dialog *me)
  1232. {
  1233. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1234. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1235. return DIALOG_NEXT;
  1236. const char *buf = me->input();
  1237. const char *tmp;
  1238. if (buf[0] == 0)
  1239. {
  1240. tmp = me->defaultAns();
  1241. }
  1242. else
  1243. {
  1244. tmp = buf;
  1245. }
  1246. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_HOST, tmp);
  1247. if (!tmp || !isValid(tmp))
  1248. {
  1249. DialogManagerType::showAlert("Please enter a valid hostname");
  1250. return DIALOG_SAME;
  1251. }
  1252. return DIALOG_NEXT;
  1253. }
  1254. DialogInput askCIRPort(
  1255. "Please specify the port of the server from which the replicated\n"
  1256. "entries will be copied.\n",
  1257. "Supplier port",
  1258. "389",
  1259. askCIRPortSetup,
  1260. askCIRPortNext
  1261. );
  1262. static DialogAction
  1263. askCIRPortSetup(Dialog *me)
  1264. {
  1265. DialogAction action = DIALOG_NEXT;
  1266. long actionval = 0;
  1267. me->getUserData(ACTION, actionval);
  1268. action = (DialogAction)actionval;
  1269. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1270. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1271. return action;
  1272. const char *defaultPort = "389";
  1273. if (getManager(me)->featureIsEnabled(SLAPD_KEY_CIR_SECURITY_ON))
  1274. defaultPort = "636";
  1275. if (dialogSetup(me, SLAPD_KEY_CIR_PORT, defaultPort) &&
  1276. getManager(me)->installMode() == Silent)
  1277. return DIALOG_ERROR;
  1278. long setupval = 0;
  1279. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1280. setupval == SETUP_ONLY)
  1281. return DIALOG_NEXT;
  1282. return DIALOG_SAME;
  1283. }
  1284. static DialogAction
  1285. askCIRPortNext(Dialog *me)
  1286. {
  1287. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1288. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1289. return DIALOG_NEXT;
  1290. const char *buf = me->input();
  1291. const char *tmp;
  1292. char testbuf[1024];
  1293. int port, err = 0;
  1294. if (buf[0] == 0)
  1295. {
  1296. tmp = me->defaultAns();
  1297. }
  1298. else
  1299. {
  1300. tmp = buf;
  1301. }
  1302. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_PORT, tmp);
  1303. port = atoi(tmp);
  1304. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  1305. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  1306. {
  1307. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  1308. "Please choose another port between 1 and %d.\n\n",
  1309. port, MAXPORT);
  1310. err = -1;
  1311. }
  1312. if (err)
  1313. {
  1314. DialogManagerType::showAlert(testbuf);
  1315. return DIALOG_SAME;
  1316. }
  1317. return DIALOG_NEXT;
  1318. }
  1319. DialogInput askCIRDN(
  1320. "Replication requires that this consumer has access to the portion of\n"
  1321. "the remote directory to be replicated. This requires a bind DN and\n"
  1322. "password for access to the supplier. You will first be asked for the\n"
  1323. "bind DN, then the password.\n",
  1324. "Replication DN",
  1325. NULL,
  1326. askCIRDNSetup,
  1327. askCIRDNNext
  1328. );
  1329. static DialogAction
  1330. askCIRDNSetup(Dialog *me)
  1331. {
  1332. DialogAction action = DIALOG_NEXT;
  1333. long actionval = 0;
  1334. me->getUserData(ACTION, actionval);
  1335. action = (DialogAction)actionval;
  1336. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1337. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1338. return action;
  1339. if (dialogSetup(me, SLAPD_KEY_CIR_BINDDN, getManager(me)->getConsumerDN()) &&
  1340. getManager(me)->installMode() == Silent)
  1341. return DIALOG_ERROR;
  1342. long setupval = 0;
  1343. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1344. setupval == SETUP_ONLY)
  1345. return DIALOG_NEXT;
  1346. return DIALOG_SAME;
  1347. }
  1348. static DialogAction
  1349. askCIRDNNext(Dialog *me)
  1350. {
  1351. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1352. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1353. return DIALOG_NEXT;
  1354. const char *slapdUser;
  1355. char *slapdPwd = 0;
  1356. const char *buf;
  1357. buf = me->input();
  1358. if (buf[0] == 0)
  1359. {
  1360. slapdUser = me->defaultAns();
  1361. }
  1362. else
  1363. {
  1364. slapdUser = buf;
  1365. }
  1366. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_BINDDN, slapdUser);
  1367. // check to see if it is a valid DN
  1368. if (!isAValidDN(slapdUser))
  1369. {
  1370. DialogManagerType::showAlert("The consumer must be a valid DN.");
  1371. return DIALOG_SAME;
  1372. }
  1373. else if (!isValid(slapdUser))
  1374. {
  1375. DialogManagerType::showAlert("Please enter a valid string.");
  1376. return DIALOG_SAME;
  1377. }
  1378. while (1)
  1379. {
  1380. me->showString("Password: ");
  1381. if (me->getPassword () == 0)
  1382. {
  1383. return DIALOG_PREV;
  1384. }
  1385. else
  1386. {
  1387. char *inp = strdup(me->input());
  1388. if (inp[0] == 0)
  1389. {
  1390. free(inp);
  1391. continue;
  1392. }
  1393. else
  1394. {
  1395. slapdPwd = inp;
  1396. break;
  1397. }
  1398. }
  1399. }
  1400. if (slapdPwd)
  1401. {
  1402. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_BINDDNPWD, slapdPwd);
  1403. free(slapdPwd);
  1404. }
  1405. return DIALOG_NEXT;
  1406. }
  1407. DialogInput askCIRSuffix(
  1408. "Please enter the full DN of the part of the tree to replicate,\n"
  1409. "including the suffix (e.g. ou=People, o=company.com).\n",
  1410. "Enter the directory path",
  1411. NULL,
  1412. askCIRSuffixSetup,
  1413. askCIRSuffixNext
  1414. );
  1415. static DialogAction
  1416. askCIRSuffixSetup(Dialog *me)
  1417. {
  1418. DialogAction action = DIALOG_NEXT;
  1419. long actionval = 0;
  1420. me->getUserData(ACTION, actionval);
  1421. action = (DialogAction)actionval;
  1422. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1423. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1424. return action;
  1425. if (dialogSetup(me, SLAPD_KEY_CIR_SUFFIX, getManager(me)->getDefaultSuffix()) &&
  1426. getManager(me)->installMode() == Silent)
  1427. return DIALOG_ERROR;
  1428. long setupval = 0;
  1429. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1430. setupval == SETUP_ONLY)
  1431. return DIALOG_NEXT;
  1432. return DIALOG_SAME;
  1433. }
  1434. static DialogAction
  1435. askCIRSuffixNext(Dialog *me)
  1436. {
  1437. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1438. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1439. return DIALOG_NEXT;
  1440. const char *buf;
  1441. NSString val;
  1442. buf = me->input();
  1443. if (buf[0] == 0)
  1444. val = me->defaultAns();
  1445. else
  1446. val = buf;
  1447. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_SUFFIX, val);
  1448. // check val to see if it is a valid DN
  1449. if (!isAValidDN(val))
  1450. {
  1451. DialogManagerType::showAlert("The suffix must be a valid DN.");
  1452. return DIALOG_SAME;
  1453. }
  1454. if (!isValid(val))
  1455. {
  1456. DialogManagerType::showAlert("Please enter a valid string.");
  1457. return DIALOG_SAME;
  1458. }
  1459. int status;
  1460. if ((status = getManager(me)->verifyRemoteLdap(
  1461. SLAPD_KEY_CIR_HOST,
  1462. SLAPD_KEY_CIR_PORT,
  1463. SLAPD_KEY_CIR_SUFFIX,
  1464. SLAPD_KEY_CIR_BINDDN,
  1465. SLAPD_KEY_CIR_BINDDNPWD
  1466. ))
  1467. )
  1468. {
  1469. ostrstream msg;
  1470. msg << "Could not connect to ldap://"
  1471. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_HOST)
  1472. << ":"
  1473. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_PORT)
  1474. << "/"
  1475. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_SUFFIX)
  1476. << endl << "for bind DN "
  1477. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_BINDDN)
  1478. << " status = " << status << endl
  1479. << "Please check your typing. If you have mis-typed, you can backup"
  1480. << endl
  1481. << "and retype. Otherwise, the remote server may be down at this time."
  1482. << endl
  1483. << "The replication agreement will be created anyway. Proceeding..."
  1484. << endl << ends;
  1485. DialogManagerType::showAlert(msg.str());
  1486. delete [] msg.str();
  1487. return DIALOG_NEXT;
  1488. }
  1489. return DIALOG_NEXT;
  1490. }
  1491. DialogYesNo askCIRSSL(
  1492. "You may use SSL authentication for replication if you have enabled it\n"
  1493. "on the remote server.\n",
  1494. "Do you want to use SSL?",
  1495. "No",
  1496. askCIRSSLSetup,
  1497. askCIRSSLNext
  1498. );
  1499. static DialogAction
  1500. askCIRSSLSetup(Dialog *me)
  1501. {
  1502. DialogAction action = DIALOG_NEXT;
  1503. long actionval = 0;
  1504. me->getUserData(ACTION, actionval);
  1505. action = (DialogAction)actionval;
  1506. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1507. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1508. return action;
  1509. long setupval = 0;
  1510. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1511. setupval == SETUP_ONLY)
  1512. return DIALOG_NEXT;
  1513. return DIALOG_SAME;
  1514. }
  1515. static DialogAction
  1516. askCIRSSLNext(Dialog *me)
  1517. {
  1518. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1519. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1520. return DIALOG_NEXT;
  1521. const char *buf = me->input();
  1522. if (!buf || !*buf)
  1523. {
  1524. buf = me->defaultAns();
  1525. if (!buf || !*buf)
  1526. buf = "No";
  1527. }
  1528. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_SECURITY_ON, buf);
  1529. if (!isValidYesNo(buf))
  1530. return DIALOG_SAME;
  1531. return DIALOG_NEXT;
  1532. }
  1533. DialogInput askCIRInterval(
  1534. "Please specify the time interval to check the remote server for new\n"
  1535. "entries to be replicated. Use the directory server console to set up\n"
  1536. "more fine-grained control. Specify the time in minutes. Use a 0\n"
  1537. "(zero) to indicate that changes should be propagated immediately all\n"
  1538. "the time.\n",
  1539. "Replication Sync Interval (in minutes)",
  1540. "10",
  1541. askCIRIntervalSetup,
  1542. askCIRIntervalNext
  1543. );
  1544. static DialogAction
  1545. askCIRIntervalSetup(Dialog *me)
  1546. {
  1547. DialogAction action = DIALOG_NEXT;
  1548. long actionval = 0;
  1549. me->getUserData(ACTION, actionval);
  1550. action = (DialogAction)actionval;
  1551. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1552. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1553. return action;
  1554. if (dialogSetup(me, SLAPD_KEY_CIR_INTERVAL, "10") &&
  1555. getManager(me)->installMode() == Silent)
  1556. return DIALOG_ERROR;
  1557. long setupval = 0;
  1558. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1559. setupval == SETUP_ONLY)
  1560. return DIALOG_NEXT;
  1561. return DIALOG_SAME;
  1562. }
  1563. static DialogAction
  1564. askCIRIntervalNext(Dialog *me)
  1565. {
  1566. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1567. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1568. return DIALOG_NEXT;
  1569. const char *buf = me->input();
  1570. const char *tmp;
  1571. char testbuf[1024];
  1572. int interval, err = 0;
  1573. if (buf[0] == 0)
  1574. {
  1575. tmp = me->defaultAns();
  1576. }
  1577. else
  1578. {
  1579. tmp = buf;
  1580. }
  1581. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_INTERVAL, tmp);
  1582. interval = atoi(tmp);
  1583. if (!isdigit((*tmp)) || interval < 0)
  1584. {
  1585. PR_snprintf(testbuf, sizeof(testbuf), "Please specify an integer greater than or equal to 0");
  1586. err = -1;
  1587. }
  1588. if (err)
  1589. {
  1590. DialogManagerType::showAlert(testbuf);
  1591. return DIALOG_SAME;
  1592. }
  1593. return DIALOG_NEXT;
  1594. }
  1595. DialogInput askChangeLogSuffix(
  1596. "Changes to the database will be kept under a separate suffix in the\n"
  1597. "directory tree. These changes are used to replicate changes to other\n"
  1598. "directory servers.\n",
  1599. "Changelog suffix",
  1600. "cn=changelog",
  1601. askChangeLogSuffixSetup,
  1602. askChangeLogSuffixNext
  1603. );
  1604. static DialogAction
  1605. askChangeLogSuffixSetup(Dialog *me)
  1606. {
  1607. DialogAction action = DIALOG_NEXT;
  1608. long actionval = 0;
  1609. me->getUserData(ACTION, actionval);
  1610. action = (DialogAction)actionval;
  1611. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1612. return action;
  1613. if (dialogSetup(me, SLAPD_KEY_CHANGELOGSUFFIX, "cn=changelog") &&
  1614. getManager(me)->installMode() == Silent)
  1615. return DIALOG_ERROR;
  1616. long setupval = 0;
  1617. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1618. setupval == SETUP_ONLY)
  1619. return DIALOG_NEXT;
  1620. return DIALOG_SAME;
  1621. }
  1622. static DialogAction
  1623. askChangeLogSuffixNext(Dialog *me)
  1624. {
  1625. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1626. return DIALOG_NEXT;
  1627. const char *buf;
  1628. NSString val;
  1629. buf = me->input();
  1630. if (buf[0] == 0)
  1631. val = me->defaultAns();
  1632. else
  1633. val = buf;
  1634. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CHANGELOGSUFFIX, val);
  1635. // check to see if val is a valid DN
  1636. if (!isAValidDN(val))
  1637. {
  1638. DialogManagerType::showAlert("The ChangeLog suffix must be a valid DN");
  1639. return DIALOG_SAME;
  1640. }
  1641. else if (!isValid(val))
  1642. {
  1643. DialogManagerType::showAlert("Please enter a valid string.");
  1644. return DIALOG_SAME;
  1645. }
  1646. return DIALOG_NEXT;
  1647. }
  1648. DialogInput askChangeLogDir(
  1649. "Changes to the main database will be kept in a separate database\n"
  1650. "stored in a separate directory path, usually under your server\n"
  1651. "instance directory.\n",
  1652. "Changelog database\n"
  1653. "directory",
  1654. NULL,
  1655. askChangeLogDirSetup,
  1656. askChangeLogDirNext
  1657. );
  1658. static DialogAction
  1659. askChangeLogDirSetup(Dialog *me)
  1660. {
  1661. DialogAction action = DIALOG_NEXT;
  1662. long actionval = 0;
  1663. me->getUserData(ACTION, actionval);
  1664. action = (DialogAction)actionval;
  1665. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1666. return action;
  1667. NSString dir = NSString(
  1668. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ROOT)
  1669. ) + "/slapd-" +
  1670. getManager(me)->getDefaultScript()->get(SLAPD_KEY_SERVER_IDENTIFIER) +
  1671. "/logs/changelogdb";
  1672. if (dialogSetup(me, SLAPD_KEY_CHANGELOGDIR, dir) &&
  1673. getManager(me)->installMode() == Silent)
  1674. return DIALOG_ERROR;
  1675. long setupval = 0;
  1676. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1677. setupval == SETUP_ONLY)
  1678. return DIALOG_NEXT;
  1679. return DIALOG_SAME;
  1680. }
  1681. static DialogAction
  1682. askChangeLogDirNext(Dialog *me)
  1683. {
  1684. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1685. return DIALOG_NEXT;
  1686. const char *buf;
  1687. NSString val;
  1688. buf = me->input();
  1689. if (buf[0] == 0)
  1690. val = me->defaultAns();
  1691. else
  1692. val = buf;
  1693. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CHANGELOGDIR, val);
  1694. if (InstUtil::dirExists(val) && !InstUtil::dirWritable(val))
  1695. {
  1696. DialogManagerType::showAlert("You do not have access to that directory. Please try again.");
  1697. return DIALOG_SAME;
  1698. }
  1699. return DIALOG_NEXT;
  1700. }
  1701. DialogInput askReplicationDN(
  1702. "In order to allow remote servers to replicate new entries to this\n"
  1703. "server, the remote server must have the ability to bind to this server\n"
  1704. "as some entity with permission to do so. The Supplier DN is the DN of\n"
  1705. "the entity the remote server will use to connect to this server to\n"
  1706. "supply updates. The Supplier DN also requires a password which you\n"
  1707. "will be prompted for after the DN.\n",
  1708. "Supplier Bind DN",
  1709. "cn=supplier",
  1710. askReplicationDNSetup,
  1711. askReplicationDNNext
  1712. );
  1713. static DialogAction
  1714. askReplicationDNSetup(Dialog *me)
  1715. {
  1716. DialogAction action = DIALOG_NEXT;
  1717. long actionval = 0;
  1718. me->getUserData(ACTION, actionval);
  1719. action = (DialogAction)actionval;
  1720. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1721. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "1"))
  1722. return action;
  1723. if (dialogSetup(me, SLAPD_KEY_REPLICATIONDN, "cn=supplier") &&
  1724. getManager(me)->installMode() == Silent)
  1725. return DIALOG_ERROR;
  1726. long setupval = 0;
  1727. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1728. setupval == SETUP_ONLY)
  1729. return DIALOG_NEXT;
  1730. return DIALOG_SAME;
  1731. }
  1732. static DialogAction
  1733. askReplicationDNNext(Dialog *me)
  1734. {
  1735. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1736. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "1"))
  1737. return DIALOG_NEXT;
  1738. const char *replicationdn;
  1739. const char *replicationpw;
  1740. const char *buf;
  1741. buf = me->input();
  1742. if (buf[0] == 0)
  1743. {
  1744. replicationdn = me->defaultAns();
  1745. }
  1746. else
  1747. {
  1748. replicationdn = buf;
  1749. }
  1750. getManager(me)->getDefaultScript()->set(SLAPD_KEY_REPLICATIONDN, replicationdn);
  1751. // check to see if it is a valid DN
  1752. if (!isAValidDN(replicationdn))
  1753. {
  1754. DialogManagerType::showAlert("The Supplier Bind DN must be a valid DN");
  1755. return DIALOG_SAME;
  1756. }
  1757. if (!isValid(replicationdn))
  1758. {
  1759. DialogManagerType::showAlert("Please enter a valid string.");
  1760. return DIALOG_SAME;
  1761. }
  1762. while (1)
  1763. {
  1764. me->showString("Password: ");
  1765. if (me->getPassword () == 0)
  1766. {
  1767. return DIALOG_PREV;
  1768. }
  1769. else
  1770. {
  1771. char *inp = strdup(me->input());
  1772. if (inp[0] == 0)
  1773. {
  1774. continue;
  1775. }
  1776. else if (contains8BitChars(inp))
  1777. {
  1778. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  1779. return DIALOG_SAME;
  1780. }
  1781. else if (!isValid(inp))
  1782. {
  1783. DialogManagerType::showAlert("Please enter a valid password.");
  1784. return DIALOG_SAME;
  1785. }
  1786. else
  1787. {
  1788. me->showString("Password (again): ");
  1789. if (me->getPassword() == 0)
  1790. {
  1791. return DIALOG_PREV;
  1792. }
  1793. else
  1794. {
  1795. replicationpw = me->input();
  1796. if (strcmp(inp,replicationpw))
  1797. {
  1798. DialogManagerType::showAlert("Passwords don't match.");
  1799. return DIALOG_SAME;
  1800. }
  1801. break;
  1802. }
  1803. }
  1804. free(inp);
  1805. }
  1806. }
  1807. getManager(me)->getDefaultScript()->set(SLAPD_KEY_REPLICATIONPWD, replicationpw);
  1808. return DIALOG_NEXT;
  1809. }
  1810. DialogInput askConsumerDN(
  1811. "In order to allow remote servers to replicate new entries from this\n"
  1812. "server, the remote server must have the ability to bind to this server\n"
  1813. "as some entity with permission to do so. The Consumer DN is the DN of\n"
  1814. "the entity the remote server will use to connect to this server to\n"
  1815. "pull the new entries. This entity will have access to the entire\n"
  1816. "database as well as the changelog entries. The Consumer DN also\n"
  1817. "requires a password which you will be prompted for after the DN. If\n"
  1818. "you leave this entry blank, no consumer bind DN will be created. The\n"
  1819. "default is no consumer bind DN.\n",
  1820. "Consumer Bind DN",
  1821. NULL,
  1822. askConsumerDNSetup,
  1823. askConsumerDNNext
  1824. );
  1825. static DialogAction
  1826. askConsumerDNSetup(Dialog *me)
  1827. {
  1828. DialogAction action = DIALOG_NEXT;
  1829. long actionval = 0;
  1830. me->getUserData(ACTION, actionval);
  1831. action = (DialogAction)actionval;
  1832. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1833. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "2"))
  1834. return action;
  1835. if (dialogSetup(me, SLAPD_KEY_CONSUMERDN, 0) &&
  1836. getManager(me)->installMode() == Silent)
  1837. return DIALOG_ERROR;
  1838. long setupval = 0;
  1839. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1840. setupval == SETUP_ONLY)
  1841. return DIALOG_NEXT;
  1842. return DIALOG_SAME;
  1843. }
  1844. static DialogAction
  1845. askConsumerDNNext(Dialog *me)
  1846. {
  1847. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1848. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "2"))
  1849. return DIALOG_NEXT;
  1850. const char *consumerdn;
  1851. const char *consumerpw;
  1852. const char *buf;
  1853. buf = me->input();
  1854. if (buf[0] == 0)
  1855. {
  1856. consumerdn = me->defaultAns();
  1857. }
  1858. else
  1859. {
  1860. consumerdn = buf;
  1861. }
  1862. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CONSUMERDN, consumerdn);
  1863. if (!consumerdn || !*consumerdn ||
  1864. !strncasecmp(consumerdn, "none", strlen(consumerdn)))
  1865. {
  1866. getManager(me)->getDefaultScript()->remove(SLAPD_KEY_CONSUMERDN);
  1867. return DIALOG_NEXT;
  1868. }
  1869. // check to see if it is a valid dn
  1870. if (!isAValidDN(consumerdn))
  1871. {
  1872. DialogManagerType::showAlert("The Consumer Bind DN must be a valid DN");
  1873. return DIALOG_SAME;
  1874. }
  1875. else if (!isValid(consumerdn))
  1876. {
  1877. DialogManagerType::showAlert("Please enter a valid string.");
  1878. return DIALOG_SAME;
  1879. }
  1880. while (1)
  1881. {
  1882. me->showString("Password: ");
  1883. if (me->getPassword () == 0)
  1884. {
  1885. return DIALOG_PREV;
  1886. }
  1887. else
  1888. {
  1889. char *inp = strdup(me->input());
  1890. if (inp[0] == 0)
  1891. {
  1892. continue;
  1893. }
  1894. else if (contains8BitChars(inp))
  1895. {
  1896. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  1897. return DIALOG_SAME;
  1898. }
  1899. else if (!isValid(inp))
  1900. {
  1901. DialogManagerType::showAlert("Please enter a valid password.");
  1902. return DIALOG_SAME;
  1903. }
  1904. else
  1905. {
  1906. me->showString("Password (again): ");
  1907. if (me->getPassword() == 0)
  1908. {
  1909. return DIALOG_PREV;
  1910. }
  1911. else
  1912. {
  1913. consumerpw = me->input();
  1914. if (strcmp(inp,consumerpw))
  1915. {
  1916. DialogManagerType::showAlert("Passwords don't match.");
  1917. return DIALOG_SAME;
  1918. }
  1919. break;
  1920. }
  1921. }
  1922. free(inp);
  1923. }
  1924. }
  1925. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CONSUMERPWD, consumerpw);
  1926. return DIALOG_NEXT;
  1927. }
  1928. DialogInput askSIRHost(
  1929. "Please specify the host name of the server to which the replicated\n"
  1930. "entries will be pushed.\n",
  1931. "Consumer host name",
  1932. 0,
  1933. askSIRHostSetup,
  1934. askSIRHostNext
  1935. );
  1936. static DialogAction
  1937. askSIRHostSetup(Dialog *me)
  1938. {
  1939. DialogAction action = DIALOG_NEXT;
  1940. long actionval = 0;
  1941. me->getUserData(ACTION, actionval);
  1942. action = (DialogAction)actionval;
  1943. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1944. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1945. return action;
  1946. else if (dialogSetup(me, SLAPD_KEY_SIR_HOST, 0) &&
  1947. getManager(me)->installMode() == Silent)
  1948. return DIALOG_ERROR;
  1949. long setupval = 0;
  1950. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1951. setupval == SETUP_ONLY)
  1952. return DIALOG_NEXT;
  1953. return DIALOG_SAME;
  1954. }
  1955. static DialogAction
  1956. askSIRHostNext(Dialog *me)
  1957. {
  1958. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1959. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1960. return DIALOG_NEXT;
  1961. const char *buf = me->input();
  1962. const char *tmp;
  1963. if (buf[0] == 0)
  1964. {
  1965. tmp = me->defaultAns();
  1966. }
  1967. else
  1968. {
  1969. tmp = buf;
  1970. }
  1971. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_HOST, tmp);
  1972. if (!tmp || !isValid(tmp))
  1973. {
  1974. DialogManagerType::showAlert("Please enter a valid hostname");
  1975. return DIALOG_SAME;
  1976. }
  1977. return DIALOG_NEXT;
  1978. }
  1979. DialogInput askSIRPort(
  1980. "Please specify the port of the server to which the replicated entries\n"
  1981. "will be pushed.\n",
  1982. "Consumer port",
  1983. "389",
  1984. askSIRPortSetup,
  1985. askSIRPortNext
  1986. );
  1987. static DialogAction
  1988. askSIRPortSetup(Dialog *me)
  1989. {
  1990. DialogAction action = DIALOG_NEXT;
  1991. long actionval = 0;
  1992. me->getUserData(ACTION, actionval);
  1993. action = (DialogAction)actionval;
  1994. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1995. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1996. return action;
  1997. const char *defaultPort = "389";
  1998. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SIR_SECURITY_ON))
  1999. defaultPort = "636";
  2000. if (dialogSetup(me, SLAPD_KEY_SIR_PORT, defaultPort) &&
  2001. getManager(me)->installMode() == Silent)
  2002. return DIALOG_ERROR;
  2003. long setupval = 0;
  2004. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2005. setupval == SETUP_ONLY)
  2006. return DIALOG_NEXT;
  2007. return DIALOG_SAME;
  2008. }
  2009. static DialogAction
  2010. askSIRPortNext(Dialog *me)
  2011. {
  2012. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2013. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2014. return DIALOG_NEXT;
  2015. const char *buf = me->input();
  2016. const char *tmp;
  2017. char testbuf[1024];
  2018. int port, err = 0;
  2019. if (buf[0] == 0)
  2020. {
  2021. tmp = me->defaultAns();
  2022. }
  2023. else
  2024. {
  2025. tmp = buf;
  2026. }
  2027. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_PORT, tmp);
  2028. port = atoi(tmp);
  2029. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  2030. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  2031. {
  2032. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  2033. "Please choose another port between 1 and %d.\n\n",
  2034. port, MAXPORT);
  2035. err = -1;
  2036. }
  2037. if (err)
  2038. {
  2039. DialogManagerType::showAlert(testbuf);
  2040. return DIALOG_SAME;
  2041. }
  2042. return DIALOG_NEXT;
  2043. }
  2044. DialogInput askSIRDN(
  2045. "Replication requires that this supplier has access to the portion of\n"
  2046. "the remote directory to be replicated. This requires a bind DN and\n"
  2047. "password for access to the consumer. You will first be asked for the\n"
  2048. "bind DN, then the password. This is the same as the Supplier DN on\n"
  2049. "the consumer.\n",
  2050. "Replication DN on the Consumer",
  2051. "cn=supplier",
  2052. askSIRDNSetup,
  2053. askSIRDNNext
  2054. );
  2055. static DialogAction
  2056. askSIRDNSetup(Dialog *me)
  2057. {
  2058. DialogAction action = DIALOG_NEXT;
  2059. long actionval = 0;
  2060. me->getUserData(ACTION, actionval);
  2061. action = (DialogAction)actionval;
  2062. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2063. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2064. return action;
  2065. if (dialogSetup(me, SLAPD_KEY_SIR_BINDDN, "cn=supplier") &&
  2066. getManager(me)->installMode() == Silent)
  2067. return DIALOG_ERROR;
  2068. long setupval = 0;
  2069. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2070. setupval == SETUP_ONLY)
  2071. return DIALOG_NEXT;
  2072. return DIALOG_SAME;
  2073. }
  2074. static DialogAction
  2075. askSIRDNNext(Dialog *me)
  2076. {
  2077. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2078. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2079. return DIALOG_NEXT;
  2080. const char *slapdUser;
  2081. char *slapdPwd = 0;
  2082. const char *buf;
  2083. buf = me->input();
  2084. if (buf[0] == 0)
  2085. {
  2086. slapdUser = me->defaultAns();
  2087. }
  2088. else
  2089. {
  2090. slapdUser = buf;
  2091. }
  2092. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_BINDDN, slapdUser);
  2093. // check to see if it is a valid dn
  2094. if (!isAValidDN(slapdUser))
  2095. {
  2096. DialogManagerType::showAlert("The Consumer Replication DN must be a valid DN");
  2097. return DIALOG_SAME;
  2098. }
  2099. else if (!isValid(slapdUser))
  2100. {
  2101. DialogManagerType::showAlert("Please enter a valid string.");
  2102. return DIALOG_SAME;
  2103. }
  2104. while (1)
  2105. {
  2106. me->showString("Password: ");
  2107. if (me->getPassword () == 0)
  2108. {
  2109. return DIALOG_PREV;
  2110. }
  2111. else
  2112. {
  2113. char *inp = strdup(me->input());
  2114. if (inp[0] == 0)
  2115. {
  2116. free(inp);
  2117. continue;
  2118. }
  2119. else
  2120. {
  2121. slapdPwd = inp;
  2122. break;
  2123. }
  2124. }
  2125. }
  2126. if (slapdPwd)
  2127. {
  2128. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_BINDDNPWD, slapdPwd);
  2129. free(slapdPwd);
  2130. }
  2131. return DIALOG_NEXT;
  2132. }
  2133. DialogInput askSIRSuffix(
  2134. "Please enter the full DN of the part of the tree to replicate,\n"
  2135. "including the suffix (e.g. ou=People, o=company.com).\n",
  2136. "Directory path (DN)",
  2137. NULL,
  2138. askSIRSuffixSetup,
  2139. askSIRSuffixNext
  2140. );
  2141. static DialogAction
  2142. askSIRSuffixSetup(Dialog *me)
  2143. {
  2144. DialogAction action = DIALOG_NEXT;
  2145. long actionval = 0;
  2146. me->getUserData(ACTION, actionval);
  2147. action = (DialogAction)actionval;
  2148. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2149. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2150. return action;
  2151. if (dialogSetup(me, SLAPD_KEY_SIR_SUFFIX, getManager(me)->getDefaultSuffix()) &&
  2152. getManager(me)->installMode() == Silent)
  2153. return DIALOG_ERROR;
  2154. long setupval = 0;
  2155. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2156. setupval == SETUP_ONLY)
  2157. return DIALOG_NEXT;
  2158. return DIALOG_SAME;
  2159. }
  2160. static DialogAction
  2161. askSIRSuffixNext(Dialog *me)
  2162. {
  2163. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2164. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2165. return DIALOG_NEXT;
  2166. const char *buf;
  2167. NSString val;
  2168. buf = me->input();
  2169. if (buf[0] == 0)
  2170. val = me->defaultAns();
  2171. else
  2172. val = buf;
  2173. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_SUFFIX, val);
  2174. // check to see if it is a valid dn
  2175. if (!isAValidDN(val))
  2176. {
  2177. DialogManagerType::showAlert("The suffix must be a valid DN");
  2178. return DIALOG_SAME;
  2179. }
  2180. else if (!isValid(val))
  2181. {
  2182. DialogManagerType::showAlert("Please enter a valid string.");
  2183. return DIALOG_SAME;
  2184. }
  2185. int status;
  2186. if ((status = getManager(me)->verifyRemoteLdap(
  2187. SLAPD_KEY_SIR_HOST,
  2188. SLAPD_KEY_SIR_PORT,
  2189. SLAPD_KEY_SIR_SUFFIX,
  2190. SLAPD_KEY_SIR_BINDDN,
  2191. SLAPD_KEY_SIR_BINDDNPWD
  2192. ))
  2193. )
  2194. {
  2195. ostrstream msg;
  2196. msg << "Could not connect to ldap://"
  2197. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_HOST)
  2198. << ":"
  2199. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_PORT)
  2200. << "/"
  2201. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_SUFFIX)
  2202. << endl << "for bind DN "
  2203. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_BINDDN)
  2204. << " status = " << status << endl
  2205. << "Please check your typing. If you have mis-typed, you can backup"
  2206. << endl
  2207. << "and retype. Otherwise, the remote server may be down at this time."
  2208. << endl
  2209. << "The replication agreement will be created anyway. Proceeding..."
  2210. << endl << ends;
  2211. DialogManagerType::showAlert(msg.str());
  2212. delete [] msg.str();
  2213. return DIALOG_NEXT;
  2214. }
  2215. return DIALOG_NEXT;
  2216. }
  2217. DialogYesNo askSIRSSL(
  2218. "You may use SSL authentication for replication if you have enabled it\n"
  2219. "on the remote server.\n",
  2220. "Do you want to use SSL?",
  2221. "No",
  2222. askSIRSSLSetup,
  2223. askSIRSSLNext
  2224. );
  2225. static DialogAction
  2226. askSIRSSLSetup(Dialog *me)
  2227. {
  2228. DialogAction action = DIALOG_NEXT;
  2229. long actionval = 0;
  2230. me->getUserData(ACTION, actionval);
  2231. action = (DialogAction)actionval;
  2232. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2233. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2234. return action;
  2235. long setupval = 0;
  2236. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2237. setupval == SETUP_ONLY)
  2238. return DIALOG_NEXT;
  2239. return DIALOG_SAME;
  2240. }
  2241. static DialogAction
  2242. askSIRSSLNext(Dialog *me)
  2243. {
  2244. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2245. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2246. return DIALOG_NEXT;
  2247. const char *buf = me->input();
  2248. if (!buf || !*buf)
  2249. {
  2250. buf = me->defaultAns();
  2251. if (!buf || !*buf)
  2252. buf = "No";
  2253. }
  2254. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_SECURITY_ON, buf);
  2255. if (!isValidYesNo(buf))
  2256. return DIALOG_SAME;
  2257. return DIALOG_NEXT;
  2258. }
  2259. DialogInput askCIRDays(
  2260. "Please enter the days of the week on which you would like replication\n"
  2261. "to occur. The days are specified by a number. For example, use 0 for\n"
  2262. "Sunday, 1 for Monday, etc. Use 6 for Saturday. You may not specify a\n"
  2263. "number greater than 6 or less than 0. The numbers should be entered\n"
  2264. "one after another in a list. For example, 0123 would be Sunday,\n"
  2265. "Monday, Tuesday, and Wednesday. 06 would be Sunday and Saturday. The\n"
  2266. "default is everyday.\n",
  2267. "Enter the replication days",
  2268. "all",
  2269. askCIRDaysSetup,
  2270. askCIRDaysNext
  2271. );
  2272. static DialogAction
  2273. askCIRDaysSetup(Dialog *me)
  2274. {
  2275. DialogAction action = DIALOG_NEXT;
  2276. long actionval = 0;
  2277. me->getUserData(ACTION, actionval);
  2278. action = (DialogAction)actionval;
  2279. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2280. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2281. return action;
  2282. if (dialogSetup(me, SLAPD_KEY_CIR_DAYS, "all") &&
  2283. getManager(me)->installMode() == Silent)
  2284. return DIALOG_ERROR;
  2285. const char *tmp;
  2286. if ((tmp = getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_DAYS)) &&
  2287. !*tmp)
  2288. me->setDefaultAns("all");
  2289. long setupval = 0;
  2290. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2291. setupval == SETUP_ONLY)
  2292. return DIALOG_NEXT;
  2293. return DIALOG_SAME;
  2294. }
  2295. static DialogAction
  2296. askCIRDaysNext(Dialog *me)
  2297. {
  2298. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2299. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2300. return DIALOG_NEXT;
  2301. const char *buf;
  2302. NSString val;
  2303. buf = me->input();
  2304. if (buf[0] == 0)
  2305. val = me->defaultAns();
  2306. else
  2307. val = buf;
  2308. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_DAYS, val);
  2309. int status = 0;
  2310. ostrstream msg;
  2311. char realval[8] = "-------";
  2312. if (!strncasecmp(val, "all", strlen(val)))
  2313. strcpy(realval, ""); // default is everyday
  2314. else
  2315. {
  2316. for (const char *ptr = val; *ptr; ++ptr)
  2317. {
  2318. if (!isdigit(*ptr))
  2319. {
  2320. msg << "The string [" << val << "] contains non-digit characters."
  2321. << " Please re enter the string." << ends;
  2322. status = 1;
  2323. break;
  2324. }
  2325. int ival = (int)(*ptr) - (int)'0';
  2326. if (ival > 6)
  2327. {
  2328. msg << "The string contains an invalid value [" << ival << "]."
  2329. << " Please re enter the string." << ends;
  2330. status = 2;
  2331. break;
  2332. }
  2333. // this step makes sure we get the numbers in order with no duplicates
  2334. realval[ival] = *ptr;
  2335. }
  2336. if (status)
  2337. {
  2338. DialogManagerType::showAlert(msg.str());
  2339. delete [] msg.str();
  2340. return DIALOG_SAME;
  2341. }
  2342. // realval now contains a string like
  2343. // 0---4-6, but we really want 046
  2344. int index = 0;
  2345. for (char *p2 = realval; *p2; ++p2)
  2346. {
  2347. if (*p2 != '-')
  2348. realval[index++] = *p2;
  2349. }
  2350. realval[index] = 0;
  2351. }
  2352. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_DAYS, realval);
  2353. return DIALOG_NEXT;
  2354. }
  2355. DialogInput askSIRDays(
  2356. "Please enter the days of the week on which you would like replication\n"
  2357. "to occur. The days are specified by a number. For example, use 0 for\n"
  2358. "Sunday, 1 for Monday, etc. Use 6 for Saturday. You may not specify a\n"
  2359. "number greater than 6 or less than 0. The numbers should be entered\n"
  2360. "one after another in a list. For example, 0123 would be Sunday,\n"
  2361. "Monday, Tuesday, and Wednesday. 06 would be Sunday and Saturday. The\n"
  2362. "default is everyday.\n",
  2363. "Enter the replication days",
  2364. "all",
  2365. askSIRDaysSetup,
  2366. askSIRDaysNext
  2367. );
  2368. static DialogAction
  2369. askSIRDaysSetup(Dialog *me)
  2370. {
  2371. DialogAction action = DIALOG_NEXT;
  2372. long actionval = 0;
  2373. me->getUserData(ACTION, actionval);
  2374. action = (DialogAction)actionval;
  2375. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2376. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2377. return action;
  2378. if (dialogSetup(me, SLAPD_KEY_SIR_DAYS, "all") &&
  2379. getManager(me)->installMode() == Silent)
  2380. return DIALOG_ERROR;
  2381. const char *tmp;
  2382. if ((tmp = getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_DAYS)) &&
  2383. !*tmp)
  2384. me->setDefaultAns("all");
  2385. long setupval = 0;
  2386. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2387. setupval == SETUP_ONLY)
  2388. return DIALOG_NEXT;
  2389. return DIALOG_SAME;
  2390. }
  2391. static DialogAction
  2392. askSIRDaysNext(Dialog *me)
  2393. {
  2394. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2395. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2396. return DIALOG_NEXT;
  2397. const char *buf;
  2398. NSString val;
  2399. buf = me->input();
  2400. if (buf[0] == 0)
  2401. val = me->defaultAns();
  2402. else
  2403. val = buf;
  2404. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_DAYS, val);
  2405. int status = 0;
  2406. ostrstream msg;
  2407. char realval[8] = "-------";
  2408. if (!strncasecmp(val, "all", strlen(val)))
  2409. strcpy(realval, ""); // default is everyday
  2410. else
  2411. {
  2412. for (const char *ptr = val; *ptr; ++ptr)
  2413. {
  2414. if (!isdigit(*ptr))
  2415. {
  2416. msg << "The string [" << val << "] contains non-digit characters."
  2417. << " Please re enter the string." << ends;
  2418. status = 1;
  2419. break;
  2420. }
  2421. int ival = (int)(*ptr) - (int)'0';
  2422. if (ival > 6)
  2423. {
  2424. msg << "The string contains an invalid value [" << ival << "]."
  2425. << " Please re enter the string." << ends;
  2426. status = 2;
  2427. break;
  2428. }
  2429. // this step makes sure we get the numbers in order with no duplicates
  2430. realval[ival] = *ptr;
  2431. }
  2432. if (status)
  2433. {
  2434. DialogManagerType::showAlert(msg.str());
  2435. delete [] msg.str();
  2436. return DIALOG_SAME;
  2437. }
  2438. // realval now contains a string like
  2439. // 0---4-6, but we really want 046
  2440. int index = 0;
  2441. for (char *p2 = realval; *p2; ++p2)
  2442. {
  2443. if (*p2 != '-')
  2444. realval[index++] = *p2;
  2445. }
  2446. realval[index] = 0;
  2447. }
  2448. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_DAYS, realval);
  2449. return DIALOG_NEXT;
  2450. }
  2451. DialogInput askCIRTimes(
  2452. "Please enter the time of day you would like replication to occur. The\n"
  2453. "time is specified as a range in the form HHMM-HHMM in 24 hour time.\n"
  2454. "HH represents the hour portion of the time, and MM the minutes.\n"
  2455. "Numbers less than 10 should be preceeded by a 0. For example, to\n"
  2456. "enable replication between 1 am and 4:30 am, specify 0100-0430. To\n"
  2457. "specify 11 am to 9 pm, use 1100-2100. 12 am to 12:59 am is specified\n"
  2458. "as 0000-0059. The default is all day.\n",
  2459. "Enter the replication times",
  2460. "all day",
  2461. askCIRTimesSetup,
  2462. askCIRTimesNext
  2463. );
  2464. static DialogAction
  2465. askCIRTimesSetup(Dialog *me)
  2466. {
  2467. DialogAction action = DIALOG_NEXT;
  2468. long actionval = 0;
  2469. me->getUserData(ACTION, actionval);
  2470. action = (DialogAction)actionval;
  2471. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2472. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2473. return action;
  2474. if (dialogSetup(me, SLAPD_KEY_CIR_TIMES, "all day") &&
  2475. getManager(me)->installMode() == Silent)
  2476. return DIALOG_ERROR;
  2477. long setupval = 0;
  2478. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2479. setupval == SETUP_ONLY)
  2480. return DIALOG_NEXT;
  2481. return DIALOG_SAME;
  2482. }
  2483. static DialogAction
  2484. askCIRTimesNext(Dialog *me)
  2485. {
  2486. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2487. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2488. return DIALOG_NEXT;
  2489. const char *buf;
  2490. NSString val;
  2491. buf = me->input();
  2492. if (buf[0] == 0)
  2493. val = me->defaultAns();
  2494. else
  2495. val = buf;
  2496. if (!strncasecmp(val, "all day", strlen(val)))
  2497. {
  2498. val = "";
  2499. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_TIMES, val);
  2500. return DIALOG_NEXT;
  2501. }
  2502. int status = 0;
  2503. ostrstream msg;
  2504. int pos = 0;
  2505. // format should be HHMM-HHMM
  2506. int maxvals[9] = {0, 23, 0, 59, 0, 0, 23, 0, 59};
  2507. char teststr[3]; // 2 digits plus \0
  2508. int testindex = 0;
  2509. for (const char *ptr = val; *ptr; ++ptr, ++pos)
  2510. {
  2511. // position 4 should contain the '-'
  2512. if (pos == 4 && *ptr != '-')
  2513. {
  2514. msg << "The time specification [" << val << "] is invalid.\n"
  2515. << "Please re enter the string." << ends;
  2516. status = 1;
  2517. break;
  2518. }
  2519. else if (pos == 4)
  2520. continue;
  2521. if (!isdigit(*ptr) && pos != 4)
  2522. {
  2523. msg << "The time specification [" << val << "] contains non-digit characters.\n"
  2524. << "Please re enter the string." << ends;
  2525. status = 2;
  2526. break;
  2527. }
  2528. teststr[testindex++] = *ptr;
  2529. if (pos == 1 || pos == 3 || pos == 6 || pos == 8)
  2530. {
  2531. teststr[testindex] = 0;
  2532. testindex = 0;
  2533. if (teststr[0] == '0')
  2534. teststr[0] = ' ';
  2535. int ival = atoi(teststr);
  2536. if (ival > maxvals[pos])
  2537. {
  2538. msg << "The string contains an invalid value [" << ival << "].\n"
  2539. << "Please re enter the string." << ends;
  2540. status = 3;
  2541. break;
  2542. }
  2543. }
  2544. }
  2545. if (pos != 9)
  2546. {
  2547. msg << "The string [" << val << "] is invalid.\n"
  2548. << "Please re enter the string." << ends;
  2549. status = 4;
  2550. }
  2551. if (status)
  2552. {
  2553. DialogManagerType::showAlert(msg.str());
  2554. delete [] msg.str();
  2555. return DIALOG_SAME;
  2556. }
  2557. return DIALOG_NEXT;
  2558. }
  2559. DialogInput askSIRTimes(
  2560. "Please enter the time of day you would like replication to occur. The\n"
  2561. "time is specified as a range in the form HHMM-HHMM in 24 hour time.\n"
  2562. "HH represents the hour portion of the time, and MM the minutes.\n"
  2563. "Numbers less than 10 should be preceeded by a 0. For example, to\n"
  2564. "enable replication between 1 am and 4:30 am, specify 0100-0430. To\n"
  2565. "specify 11 am to 9 pm, use 1100-2100. 12 am to 12:59 am is specified\n"
  2566. "as 0000-0059. The default is all day.\n",
  2567. "Enter the replication times",
  2568. "all day",
  2569. askSIRTimesSetup,
  2570. askSIRTimesNext
  2571. );
  2572. static DialogAction
  2573. askSIRTimesSetup(Dialog *me)
  2574. {
  2575. DialogAction action = DIALOG_NEXT;
  2576. long actionval = 0;
  2577. me->getUserData(ACTION, actionval);
  2578. action = (DialogAction)actionval;
  2579. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2580. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2581. return action;
  2582. if (dialogSetup(me, SLAPD_KEY_SIR_TIMES, "all day") &&
  2583. getManager(me)->installMode() == Silent)
  2584. return DIALOG_ERROR;
  2585. long setupval = 0;
  2586. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2587. setupval == SETUP_ONLY)
  2588. return DIALOG_NEXT;
  2589. return DIALOG_SAME;
  2590. }
  2591. static DialogAction
  2592. askSIRTimesNext(Dialog *me)
  2593. {
  2594. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2595. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2596. return DIALOG_NEXT;
  2597. const char *buf;
  2598. NSString val;
  2599. buf = me->input();
  2600. if (buf[0] == 0)
  2601. val = me->defaultAns();
  2602. else
  2603. val = buf;
  2604. if (!strncasecmp(val, "all day", strlen(val)))
  2605. {
  2606. val = "";
  2607. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_TIMES, val);
  2608. return DIALOG_NEXT;
  2609. }
  2610. int status = 0;
  2611. ostrstream msg;
  2612. int pos = 0;
  2613. // format should be HHMM-HHMM
  2614. int maxvals[9] = {0, 23, 0, 59, 0, 0, 23, 0, 59};
  2615. char teststr[3]; // 2 digits plus \0
  2616. int testindex = 0;
  2617. for (const char *ptr = val; *ptr; ++ptr, ++pos)
  2618. {
  2619. // position 4 should contain the '-'
  2620. if (pos == 4 && *ptr != '-')
  2621. {
  2622. msg << "The time specification [" << val << "] is invalid.\n"
  2623. << "Please re enter the string." << ends;
  2624. status = 1;
  2625. break;
  2626. }
  2627. else if (pos == 4)
  2628. continue;
  2629. if (!isdigit(*ptr) && pos != 4)
  2630. {
  2631. msg << "The time specification [" << val << "] contains non-digit characters.\n"
  2632. << "Please re enter the string." << ends;
  2633. status = 2;
  2634. break;
  2635. }
  2636. teststr[testindex++] = *ptr;
  2637. if (pos == 1 || pos == 3 || pos == 6 || pos == 8)
  2638. {
  2639. teststr[testindex] = 0;
  2640. testindex = 0;
  2641. if (teststr[0] == '0')
  2642. teststr[0] = ' ';
  2643. int ival = atoi(teststr);
  2644. if (ival > maxvals[pos])
  2645. {
  2646. msg << "The string contains an invalid value [" << ival << "].\n"
  2647. << "Please re enter the string." << ends;
  2648. status = 3;
  2649. break;
  2650. }
  2651. }
  2652. }
  2653. if (pos != 9)
  2654. {
  2655. msg << "The string [" << val << "] is invalid.\n"
  2656. << "Please re enter the string." << ends;
  2657. status = 4;
  2658. }
  2659. if (status)
  2660. {
  2661. DialogManagerType::showAlert(msg.str());
  2662. delete [] msg.str();
  2663. return DIALOG_SAME;
  2664. }
  2665. return DIALOG_NEXT;
  2666. }
  2667. DialogYesNo askUseExistingMC(
  2668. "Fedora server information is stored in the Fedora configuration\n"
  2669. "directory server, which you may have already set up. If so, you\n"
  2670. "should configure this server to be managed by the configuration\n"
  2671. "server. To do so, the following information about the configuration\n"
  2672. "server is required: the fully qualified host name of the form\n"
  2673. "<hostname>.<domainname>(e.g. hostname.domain.com), the port number,\n"
  2674. "the suffix, and the DN and password of a user having permission to\n"
  2675. "write the configuration information, usually the Fedora\n"
  2676. "configuration directory administrator.\n\n"
  2677. "If you want to install this software as a standalone server, or if you\n"
  2678. "want this instance to serve as your Fedora configuration directory\n"
  2679. "server, press Enter.\n",
  2680. "Do you want to register this software with an existing\n"
  2681. "Fedora configuration directory server?",
  2682. "No",
  2683. askUseExistingMCSetup,
  2684. askUseExistingMCNext
  2685. );
  2686. static DialogAction
  2687. askUseExistingMCSetup(Dialog *me)
  2688. {
  2689. #if DEBUG > 1
  2690. cerr << "Entering askUseExistingMCSetup" << endl;
  2691. #endif
  2692. DialogAction action = DIALOG_NEXT;
  2693. long actionval = 0;
  2694. me->getUserData(ACTION, actionval);
  2695. action = (DialogAction)actionval;
  2696. if (action != DIALOG_PREV)
  2697. {
  2698. if (getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL))
  2699. {
  2700. // tell the instance creator not to create the Config entries
  2701. // new instance
  2702. getManager(me)->getDefaultScript()->set(
  2703. SLAPD_KEY_USE_EXISTING_MC, "Yes");
  2704. getManager(me)->getDefaultScript()->set(
  2705. SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "No");
  2706. }
  2707. else
  2708. {
  2709. getManager(me)->getDefaultScript()->set(
  2710. SLAPD_KEY_USE_EXISTING_MC, "No");
  2711. getManager(me)->getDefaultScript()->set(
  2712. SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "Yes");
  2713. }
  2714. }
  2715. dialogSetup(me, SLAPD_KEY_USE_EXISTING_MC, "No");
  2716. long setupval = 0;
  2717. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2718. setupval == SETUP_ONLY)
  2719. {
  2720. #if DEBUG > 1
  2721. cerr << "Leaving askUseExistingMCSetup DIALOG_NEXT" << endl;
  2722. #endif
  2723. return DIALOG_NEXT;
  2724. }
  2725. #if DEBUG > 1
  2726. cerr << "Leaving askUseExistingMCSetup DIALOG_SAME" << endl;
  2727. #endif
  2728. return DIALOG_SAME;
  2729. }
  2730. static DialogAction
  2731. askUseExistingMCNext(Dialog *me)
  2732. {
  2733. #if DEBUG > 1
  2734. cerr << "Entering askUseExistingMCNext" << endl;
  2735. #endif
  2736. const char *buf = me->input();
  2737. if (!buf || !*buf)
  2738. {
  2739. buf = me->defaultAns();
  2740. if (!buf || !*buf)
  2741. buf = "No";
  2742. }
  2743. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_EXISTING_MC, buf);
  2744. if (!isValidYesNo(buf))
  2745. return DIALOG_SAME;
  2746. #if DEBUG > 1
  2747. cerr << "Leaving askUseExistingMCNext" << endl;
  2748. #endif
  2749. return DIALOG_NEXT;
  2750. }
  2751. DialogInput askMCHost(
  2752. "Enter the fully qualified domain name of the Fedora configuration\n"
  2753. "directory server host in the form <hostname>.<domainname>\n"
  2754. "(e.g. hostname.domain.com).\n",
  2755. "Fedora configuration directory server\nhost name",
  2756. 0,
  2757. askMCHostSetup,
  2758. askMCHostNext
  2759. );
  2760. static DialogAction
  2761. askMCHostSetup(Dialog *me)
  2762. {
  2763. DialogAction action = DIALOG_NEXT;
  2764. long actionval = 0;
  2765. me->getUserData(ACTION, actionval);
  2766. action = (DialogAction)actionval;
  2767. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2768. return action;
  2769. long setupval = 0;
  2770. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2771. setupval == SETUP_ONLY)
  2772. return DIALOG_NEXT;
  2773. return DIALOG_SAME;
  2774. }
  2775. static DialogAction
  2776. askMCHostNext(Dialog *me)
  2777. {
  2778. long setupval = 0;
  2779. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2780. setupval == SETUP_ONLY)
  2781. return DIALOG_NEXT;
  2782. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2783. return DIALOG_NEXT;
  2784. const char *buf = me->input();
  2785. const char *tmp;
  2786. if (buf[0] == 0)
  2787. {
  2788. tmp = me->defaultAns();
  2789. }
  2790. else
  2791. {
  2792. tmp = buf;
  2793. }
  2794. getManager(me)->getBaseScript()->set(SLAPD_KEY_K_LDAP_HOST, tmp);
  2795. if (!tmp || !isValid(tmp))
  2796. {
  2797. DialogManagerType::showAlert("Please enter a valid hostname");
  2798. return DIALOG_SAME;
  2799. }
  2800. return DIALOG_NEXT;
  2801. }
  2802. DialogInput askMCPort(
  2803. "Please specify the port number on which the Fedora configuration\n"
  2804. "directory server listens.\n",
  2805. "Fedora configuration directory server\nport number",
  2806. "389",
  2807. askMCPortSetup,
  2808. askMCPortNext
  2809. );
  2810. static DialogAction
  2811. askMCPortSetup(Dialog *me)
  2812. {
  2813. DialogAction action = DIALOG_NEXT;
  2814. long actionval = 0;
  2815. me->getUserData(ACTION, actionval);
  2816. action = (DialogAction)actionval;
  2817. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2818. return action;
  2819. long setupval = 0;
  2820. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2821. setupval == SETUP_ONLY)
  2822. return DIALOG_NEXT;
  2823. return DIALOG_SAME;
  2824. }
  2825. static DialogAction
  2826. askMCPortNext(Dialog *me)
  2827. {
  2828. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2829. return DIALOG_NEXT;
  2830. const char *buf = me->input();
  2831. const char *tmp;
  2832. char testbuf[1024];
  2833. int port, err = 0;
  2834. if (buf[0] == 0)
  2835. {
  2836. tmp = me->defaultAns();
  2837. }
  2838. else
  2839. {
  2840. tmp = buf;
  2841. }
  2842. getManager(me)->getBaseScript()->set(SLAPD_KEY_K_LDAP_PORT, tmp);
  2843. port = atoi(tmp);
  2844. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  2845. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  2846. {
  2847. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  2848. "Please choose another port between 1 and %d.\n\n",
  2849. port, MAXPORT);
  2850. err = -1;
  2851. }
  2852. if (err)
  2853. {
  2854. DialogManagerType::showAlert(testbuf);
  2855. return DIALOG_SAME;
  2856. }
  2857. return DIALOG_NEXT;
  2858. }
  2859. DialogInput askMCDN(
  2860. "To write configuration information into the Fedora configuration\n"
  2861. "directory, you must bind to the server as an entity with the\n"
  2862. "appropriate permissions. Usually, the Fedora configuration\n"
  2863. "directory administrator is used for this purpose, although you can\n"
  2864. "give other directory accounts the proper access.\n",
  2865. "Fedora configuration directory server\nadministrator ID",
  2866. 0,
  2867. askMCDNSetup,
  2868. askMCDNNext
  2869. );
  2870. static DialogAction
  2871. askMCDNSetup(Dialog *me)
  2872. {
  2873. DialogAction action = DIALOG_NEXT;
  2874. long actionval = 0;
  2875. me->getUserData(ACTION, actionval);
  2876. action = (DialogAction)actionval;
  2877. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2878. return action;
  2879. dialogSetup(me, SLAPD_KEY_SERVER_ADMIN_ID, "admin");
  2880. long setupval = 0;
  2881. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2882. setupval == SETUP_ONLY)
  2883. return DIALOG_NEXT;
  2884. return DIALOG_SAME;
  2885. }
  2886. static DialogAction
  2887. askMCDNNext(Dialog *me)
  2888. {
  2889. long setupval = 0;
  2890. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2891. setupval == SETUP_ONLY)
  2892. return DIALOG_NEXT;
  2893. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2894. return DIALOG_NEXT;
  2895. const char *slapdUser;
  2896. char *slapdPwd = 0;
  2897. const char *buf;
  2898. buf = me->input();
  2899. if (buf[0] == 0)
  2900. {
  2901. slapdUser = me->defaultAns();
  2902. }
  2903. else
  2904. {
  2905. slapdUser = buf;
  2906. }
  2907. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_ID, slapdUser);
  2908. if (!isValid(slapdUser))
  2909. {
  2910. DialogManagerType::showAlert("Please enter a valid string.");
  2911. return DIALOG_SAME;
  2912. }
  2913. while (1)
  2914. {
  2915. me->showString("Password: ");
  2916. if (me->getPassword () == 0)
  2917. {
  2918. return DIALOG_PREV;
  2919. }
  2920. else
  2921. {
  2922. char *inp = strdup(me->input());
  2923. if (inp[0] == 0)
  2924. {
  2925. free(inp);
  2926. continue;
  2927. }
  2928. else
  2929. {
  2930. slapdPwd = inp;
  2931. break;
  2932. }
  2933. }
  2934. }
  2935. if (slapdPwd)
  2936. {
  2937. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_PWD, slapdPwd);
  2938. free(slapdPwd);
  2939. int status;
  2940. if ((status = getManager(me)->verifyRemoteLdap(
  2941. SLAPD_KEY_K_LDAP_HOST,
  2942. SLAPD_KEY_K_LDAP_PORT,
  2943. SLAPD_KEY_BASE_SUFFIX,
  2944. SLAPD_KEY_SERVER_ADMIN_ID,
  2945. SLAPD_KEY_SERVER_ADMIN_PWD
  2946. ))
  2947. )
  2948. {
  2949. ostrstream msg;
  2950. msg << "Could not connect to ldap://"
  2951. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  2952. << ":"
  2953. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  2954. << "/"
  2955. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  2956. << endl << "for bind DN "
  2957. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  2958. << " status = " << status << endl
  2959. << "Please check your typing. If you have mis-typed, you can backup"
  2960. << endl
  2961. << "and retype. Otherwise, the remote server may be down at this time."
  2962. << endl
  2963. << "The installation cannot proceed."
  2964. << endl << ends;
  2965. DialogManagerType::showAlert(msg.str());
  2966. delete [] msg.str();
  2967. return DIALOG_SAME;
  2968. }
  2969. else if ((getManager(me)->installType() < Custom) &&
  2970. (status = getManager(me)->verifyAdminDomain(
  2971. SLAPD_KEY_K_LDAP_HOST,
  2972. SLAPD_KEY_K_LDAP_PORT,
  2973. SLAPD_KEY_BASE_SUFFIX,
  2974. SLAPD_KEY_ADMIN_DOMAIN,
  2975. SLAPD_KEY_SERVER_ADMIN_ID,
  2976. SLAPD_KEY_SERVER_ADMIN_PWD
  2977. ))
  2978. )
  2979. {
  2980. ostrstream msg;
  2981. msg << "Could not find the Admin Domain "
  2982. << getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)
  2983. << " in the server" << endl << "ldap://"
  2984. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  2985. << ":"
  2986. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  2987. << "/"
  2988. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  2989. << endl << "for bind DN "
  2990. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  2991. << " status = " << status << endl
  2992. << "You may need to re-run setup in Custom mode in order to specify"
  2993. << endl
  2994. << "the correct Admin Domain."
  2995. << endl
  2996. << "The installation cannot proceed."
  2997. << endl << ends;
  2998. DialogManagerType::showAlert(msg.str());
  2999. delete [] msg.str();
  3000. return DIALOG_SAME;
  3001. }
  3002. }
  3003. // tell the instance creator not to create the config entries in the
  3004. // new instance
  3005. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "No");
  3006. return DIALOG_NEXT;
  3007. }
  3008. DialogYesNo askDisableSchemaChecking(
  3009. "If you are going to import an old database immediately after or during\n"
  3010. "installation, and you think you may have problems with your old\n"
  3011. "schema, you may want to turn off schema checking until after the\n"
  3012. "import. If you choose to do this, schema checking will remain off\n"
  3013. "until you manually turn it back on. Fedora recommends that you turn\n"
  3014. "it back on as soon as possible.\n",
  3015. "Do you want to disable schema checking?",
  3016. "No",
  3017. askDisableSchemaCheckingSetup,
  3018. askDisableSchemaCheckingNext
  3019. );
  3020. static DialogAction
  3021. askDisableSchemaCheckingSetup(Dialog *me)
  3022. {
  3023. me = me;
  3024. long setupval = 0;
  3025. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3026. setupval == SETUP_ONLY)
  3027. return DIALOG_NEXT;
  3028. return DIALOG_SAME;
  3029. }
  3030. static DialogAction
  3031. askDisableSchemaCheckingNext(Dialog *me)
  3032. {
  3033. const char *buf = me->input();
  3034. if (!buf || !*buf)
  3035. {
  3036. buf = me->defaultAns();
  3037. if (!buf || !*buf)
  3038. buf = "No";
  3039. }
  3040. getManager(me)->getDefaultScript()->set(SLAPD_KEY_DISABLE_SCHEMA_CHECKING, buf);
  3041. if (!isValidYesNo(buf))
  3042. return DIALOG_SAME;
  3043. return DIALOG_NEXT;
  3044. }
  3045. DialogInput askMCAdminDomain(
  3046. "The Administration Domain is a part of the configuration directory\n"
  3047. "server used to store information about Fedora software. If you are\n"
  3048. "managing multiple software releases at the same time, or managing\n"
  3049. "information about multiple domains, you may use the Administration\n"
  3050. "Domain to keep them separate.\n\n"
  3051. "If you are not using administrative domains, press Enter to select the\n"
  3052. "default. Otherwise, enter some descriptive, unique name for the\n"
  3053. "administration domain, such as the name of the organization responsible\n"
  3054. "for managing the domain.\n",
  3055. "Administration Domain",
  3056. NULL,
  3057. askMCAdminDomainSetup,
  3058. askMCAdminDomainNext
  3059. );
  3060. static DialogAction
  3061. askMCAdminDomainSetup(Dialog *me)
  3062. {
  3063. if (!getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)) {
  3064. getManager(me)->getBaseScript()->set(
  3065. SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3066. }
  3067. DialogAction action = DIALOG_NEXT;
  3068. long actionval = 0;
  3069. me->getUserData(ACTION, actionval);
  3070. action = (DialogAction)actionval;
  3071. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3072. {
  3073. #if DEBUG > 1
  3074. cerr << "leaving askMCAdminDomainSetup " << action << endl;
  3075. #endif
  3076. return action;
  3077. }
  3078. // if we are creating the Configuration server, the admin domain will not
  3079. // yet exist, and we need to ask the user to create one. Otherwise, we are
  3080. // installing into an existing one
  3081. dialogSetup(me, SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3082. long setupval = 0;
  3083. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3084. setupval == SETUP_ONLY)
  3085. return DIALOG_NEXT;
  3086. return DIALOG_SAME;
  3087. }
  3088. static DialogAction
  3089. askMCAdminDomainNext(Dialog *me)
  3090. {
  3091. long setupval = 0;
  3092. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3093. setupval == SETUP_ONLY)
  3094. return DIALOG_NEXT;
  3095. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3096. return DIALOG_NEXT;
  3097. const char *buf;
  3098. int status = 0;
  3099. NSString val;
  3100. buf = me->input();
  3101. if (buf[0] == 0)
  3102. val = me->defaultAns();
  3103. else
  3104. val = buf;
  3105. getManager(me)->getBaseScript()->set(SLAPD_KEY_ADMIN_DOMAIN, val);
  3106. if (!isValid(val))
  3107. {
  3108. DialogManagerType::showAlert("Please enter a valid string.");
  3109. return DIALOG_SAME;
  3110. }
  3111. else if (isAValidDN(val))
  3112. {
  3113. DialogManagerType::showAlert("A DN is not allowed here. Please enter a valid string.");
  3114. return DIALOG_SAME;
  3115. }
  3116. else if ((status = getManager(me)->verifyAdminDomain(
  3117. SLAPD_KEY_K_LDAP_HOST,
  3118. SLAPD_KEY_K_LDAP_PORT,
  3119. SLAPD_KEY_BASE_SUFFIX,
  3120. SLAPD_KEY_ADMIN_DOMAIN,
  3121. SLAPD_KEY_SERVER_ADMIN_ID,
  3122. SLAPD_KEY_SERVER_ADMIN_PWD
  3123. ))
  3124. )
  3125. {
  3126. ostrstream msg;
  3127. msg << "Could not find the Admin Domain "
  3128. << getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)
  3129. << " in the server" << endl << "ldap://"
  3130. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  3131. << ":"
  3132. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  3133. << "/"
  3134. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  3135. << endl << "for bind DN "
  3136. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  3137. << " status = " << status << endl
  3138. << "Please check your typing. If you have mis-typed, you can backup"
  3139. << endl
  3140. << "and retype. Otherwise, the remote server may be down at this time."
  3141. << endl
  3142. << "The installation cannot proceed."
  3143. << endl << ends;
  3144. DialogManagerType::showAlert(msg.str());
  3145. delete [] msg.str();
  3146. return DIALOG_SAME;
  3147. }
  3148. return DIALOG_NEXT;
  3149. }
  3150. DialogInput askAdminDomain(
  3151. "The Administration Domain is a part of the configuration directory\n"
  3152. "server used to store information about Fedora software. If you are\n"
  3153. "managing multiple software releases at the same time, or managing\n"
  3154. "information about multiple domains, you may use the Administration\n"
  3155. "Domain to keep them separate.\n\n"
  3156. "If you are not using administrative domains, press Enter to select the\n"
  3157. "default. Otherwise, enter some descriptive, unique name for the\n"
  3158. "administration domain, such as the name of the organization responsible\n"
  3159. "for managing the domain.\n",
  3160. "Administration Domain",
  3161. NULL,
  3162. askAdminDomainSetup,
  3163. askAdminDomainNext
  3164. );
  3165. static DialogAction
  3166. askAdminDomainSetup(Dialog *me)
  3167. {
  3168. if (!getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)) {
  3169. getManager(me)->getBaseScript()->set(
  3170. SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3171. }
  3172. DialogAction action = DIALOG_NEXT;
  3173. long actionval = 0;
  3174. me->getUserData(ACTION, actionval);
  3175. action = (DialogAction)actionval;
  3176. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3177. return action;
  3178. // if we are creating the Configuration server, the admin domain will not
  3179. // yet exist, and we need to ask the user to create one. Otherwise, we are
  3180. // installing into an existing one
  3181. dialogSetup(me, SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3182. long setupval = 0;
  3183. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3184. setupval == SETUP_ONLY)
  3185. return DIALOG_NEXT;
  3186. return DIALOG_SAME;
  3187. }
  3188. static DialogAction
  3189. askAdminDomainNext(Dialog *me)
  3190. {
  3191. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3192. return DIALOG_NEXT;
  3193. const char *buf;
  3194. NSString val;
  3195. buf = me->input();
  3196. if (buf[0] == 0)
  3197. val = me->defaultAns();
  3198. else
  3199. val = buf;
  3200. getManager(me)->getBaseScript()->set(SLAPD_KEY_ADMIN_DOMAIN, val);
  3201. if (!isValid(val))
  3202. {
  3203. DialogManagerType::showAlert("Please enter a valid string.");
  3204. return DIALOG_SAME;
  3205. }
  3206. if (isAValidDN(val))
  3207. {
  3208. DialogManagerType::showAlert("A DN is not allowed here. Please enter a valid string.");
  3209. return DIALOG_SAME;
  3210. }
  3211. return DIALOG_NEXT;
  3212. }
  3213. DialogYesNo askUseExistingUG(
  3214. "If you already have a directory server you want to use to store your\n"
  3215. "data, such as user and group information, answer Yes to the following\n"
  3216. "question. You will be prompted for the host, port, suffix, and bind\n"
  3217. "DN to use for that directory server.\n\n"
  3218. "If you want this directory server to store your data, answer No.\n",
  3219. "Do you want to use another directory to store your data?",
  3220. "No",
  3221. askUseExistingUGSetup,
  3222. askUseExistingUGNext
  3223. );
  3224. static DialogAction
  3225. askUseExistingUGSetup(Dialog *me)
  3226. {
  3227. #if DEBUG > 1
  3228. cerr << "Entering askUseExistingUGSetup" << endl;
  3229. #endif
  3230. DialogAction action = DIALOG_NEXT;
  3231. long actionval = 0;
  3232. me->getUserData(ACTION, actionval);
  3233. action = (DialogAction)actionval;
  3234. // if this server is not an MC host, it must be a UG host
  3235. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3236. {
  3237. getManager(me)->getDefaultScript()->set(
  3238. SLAPD_KEY_USE_EXISTING_UG, "No");
  3239. #if DEBUG > 1
  3240. cerr << "Leaving askUseExistingUGSetup DIALOG_NEXT" << endl;
  3241. #endif
  3242. return action;
  3243. }
  3244. else if (getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_LDAP_URL))
  3245. {
  3246. getManager(me)->getDefaultScript()->set(
  3247. SLAPD_KEY_USE_EXISTING_UG, "Yes");
  3248. }
  3249. else
  3250. {
  3251. getManager(me)->getDefaultScript()->set(
  3252. SLAPD_KEY_USE_EXISTING_UG, "No");
  3253. }
  3254. dialogSetup(me, SLAPD_KEY_USE_EXISTING_UG, "No");
  3255. long setupval = 0;
  3256. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3257. setupval == SETUP_ONLY)
  3258. {
  3259. #if DEBUG > 1
  3260. cerr << "Leaving askUseExistingUGSetup DIALOG_NEXT" << endl;
  3261. #endif
  3262. return DIALOG_NEXT;
  3263. }
  3264. #if DEBUG > 1
  3265. cerr << "Leaving askUseExistingUGSetup DIALOG_SAME" << endl;
  3266. #endif
  3267. return DIALOG_SAME;
  3268. }
  3269. static DialogAction
  3270. askUseExistingUGNext(Dialog *me)
  3271. {
  3272. #if DEBUG > 1
  3273. cerr << "Entering askUseExistingUGNext" << endl;
  3274. #endif
  3275. const char *buf = me->input();
  3276. if (!buf || !*buf)
  3277. {
  3278. buf = me->defaultAns();
  3279. if (!buf || !*buf)
  3280. buf = "No";
  3281. }
  3282. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_EXISTING_UG, buf);
  3283. if (!isValidYesNo(buf))
  3284. return DIALOG_SAME;
  3285. #if DEBUG > 1
  3286. cerr << "Leaving askUseExistingUGNext DIALOG_NEXT" << endl;
  3287. #endif
  3288. return DIALOG_NEXT;
  3289. }
  3290. DialogInput askUGHost(
  3291. "Enter the fully qualified domain name of the user directory host of\n"
  3292. "the form <hostname>.<domainname> (e.g. hostname.domain.com).\n",
  3293. "User directory host name",
  3294. 0,
  3295. askUGHostSetup,
  3296. askUGHostNext
  3297. );
  3298. static DialogAction
  3299. askUGHostSetup(Dialog *me)
  3300. {
  3301. DialogAction action = DIALOG_NEXT;
  3302. long actionval = 0;
  3303. me->getUserData(ACTION, actionval);
  3304. action = (DialogAction)actionval;
  3305. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3306. return action;
  3307. dialogSetup(me, SLAPD_KEY_UG_HOST, 0);
  3308. long setupval = 0;
  3309. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3310. setupval == SETUP_ONLY)
  3311. return DIALOG_NEXT;
  3312. return DIALOG_SAME;
  3313. }
  3314. static DialogAction
  3315. askUGHostNext(Dialog *me)
  3316. {
  3317. long setupval = 0;
  3318. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3319. setupval == SETUP_ONLY)
  3320. return DIALOG_NEXT;
  3321. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3322. return DIALOG_NEXT;
  3323. const char *buf = me->input();
  3324. const char *tmp;
  3325. if (buf[0] == 0)
  3326. {
  3327. tmp = me->defaultAns();
  3328. }
  3329. else
  3330. {
  3331. tmp = buf;
  3332. }
  3333. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_HOST, tmp);
  3334. if (!tmp || !isValid(tmp))
  3335. {
  3336. DialogManagerType::showAlert("Please enter a valid hostname");
  3337. return DIALOG_SAME;
  3338. }
  3339. return DIALOG_NEXT;
  3340. }
  3341. DialogInput askUGPort(
  3342. "Please specify the port number on which the user directory listens.\n",
  3343. "User directory port number",
  3344. "389",
  3345. askUGPortSetup,
  3346. askUGPortNext
  3347. );
  3348. static DialogAction
  3349. askUGPortSetup(Dialog *me)
  3350. {
  3351. DialogAction action = DIALOG_NEXT;
  3352. long actionval = 0;
  3353. me->getUserData(ACTION, actionval);
  3354. action = (DialogAction)actionval;
  3355. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3356. return action;
  3357. dialogSetup(me, SLAPD_KEY_UG_PORT, me->defaultAns());
  3358. long setupval = 0;
  3359. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3360. setupval == SETUP_ONLY)
  3361. return DIALOG_NEXT;
  3362. return DIALOG_SAME;
  3363. }
  3364. static DialogAction
  3365. askUGPortNext(Dialog *me)
  3366. {
  3367. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3368. return DIALOG_NEXT;
  3369. const char *buf = me->input();
  3370. const char *tmp;
  3371. char testbuf[1024];
  3372. int port, err = 0;
  3373. if (buf[0] == 0)
  3374. {
  3375. tmp = me->defaultAns();
  3376. }
  3377. else
  3378. {
  3379. tmp = buf;
  3380. }
  3381. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_PORT, tmp);
  3382. port = atoi(tmp);
  3383. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  3384. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  3385. {
  3386. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  3387. "Please choose another port between 1 and %d.\n\n",
  3388. port, MAXPORT);
  3389. err = -1;
  3390. }
  3391. if (err)
  3392. {
  3393. DialogManagerType::showAlert(testbuf);
  3394. return DIALOG_SAME;
  3395. }
  3396. return DIALOG_NEXT;
  3397. }
  3398. DialogInput askUGDN(
  3399. "In order to add and modify information in the user directory, you must\n"
  3400. "be able to bind to the server as an entity with the correct\n"
  3401. "permissions. This user is usually the Directory Manager, although\n"
  3402. "other users may be given the proper access. You will also be asked to\n"
  3403. "provide the password.\n",
  3404. "User directory administrator ID",
  3405. 0,
  3406. askUGDNSetup,
  3407. askUGDNNext
  3408. );
  3409. static DialogAction
  3410. askUGDNSetup(Dialog *me)
  3411. {
  3412. DialogAction action = DIALOG_NEXT;
  3413. long actionval = 0;
  3414. me->getUserData(ACTION, actionval);
  3415. action = (DialogAction)actionval;
  3416. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3417. return action;
  3418. dialogSetup(me, SLAPD_KEY_USER_GROUP_ADMIN_ID, DEFAULT_SLAPDUSER);
  3419. long setupval = 0;
  3420. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3421. setupval == SETUP_ONLY)
  3422. return DIALOG_NEXT;
  3423. return DIALOG_SAME;
  3424. }
  3425. static DialogAction
  3426. askUGDNNext(Dialog *me)
  3427. {
  3428. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3429. return DIALOG_NEXT;
  3430. const char *slapdUser;
  3431. char *slapdPwd = 0;
  3432. const char *buf;
  3433. buf = me->input();
  3434. if (buf[0] == 0)
  3435. {
  3436. slapdUser = me->defaultAns();
  3437. }
  3438. else
  3439. {
  3440. slapdUser = buf;
  3441. }
  3442. getManager(me)->getBaseScript()->set(SLAPD_KEY_USER_GROUP_ADMIN_ID, slapdUser);
  3443. if (!isValid(slapdUser))
  3444. {
  3445. DialogManagerType::showAlert("Please enter a valid string.");
  3446. return DIALOG_SAME;
  3447. }
  3448. while (1)
  3449. {
  3450. me->showString("Password: ");
  3451. if (me->getPassword () == 0)
  3452. {
  3453. return DIALOG_PREV;
  3454. }
  3455. else
  3456. {
  3457. char *inp = strdup(me->input());
  3458. if (inp[0] == 0)
  3459. {
  3460. free(inp);
  3461. continue;
  3462. }
  3463. else
  3464. {
  3465. slapdPwd = inp;
  3466. break;
  3467. }
  3468. }
  3469. }
  3470. if (slapdPwd)
  3471. {
  3472. getManager(me)->getBaseScript()->set(SLAPD_KEY_USER_GROUP_ADMIN_PWD, slapdPwd);
  3473. free(slapdPwd);
  3474. int status;
  3475. if ((status = getManager(me)->verifyRemoteLdap(
  3476. SLAPD_KEY_UG_HOST,
  3477. SLAPD_KEY_UG_PORT,
  3478. SLAPD_KEY_UG_SUFFIX,
  3479. SLAPD_KEY_USER_GROUP_ADMIN_ID,
  3480. SLAPD_KEY_USER_GROUP_ADMIN_PWD
  3481. ))
  3482. )
  3483. {
  3484. ostrstream msg;
  3485. msg << "Could not connect to ldap://"
  3486. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_HOST)
  3487. << ":"
  3488. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_PORT)
  3489. << "/"
  3490. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_SUFFIX)
  3491. << endl << "for bind DN "
  3492. << getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_ADMIN_ID)
  3493. << " status = " << status << endl
  3494. << "Please check your typing. If you have mis-typed, you can backup"
  3495. << endl
  3496. << "and retype. Otherwise, the remote server may be down at this time."
  3497. << endl
  3498. << "The installation cannot proceed."
  3499. << endl << ends;
  3500. DialogManagerType::showAlert(msg.str());
  3501. delete [] msg.str();
  3502. return DIALOG_SAME;
  3503. }
  3504. }
  3505. return DIALOG_NEXT;
  3506. }
  3507. DialogInput askUGSuffix(
  3508. "Please specify the suffix for the user directory server.\n",
  3509. "User directory server suffix",
  3510. NULL,
  3511. askUGSuffixSetup,
  3512. askUGSuffixNext
  3513. );
  3514. static DialogAction
  3515. askUGSuffixSetup(Dialog *me)
  3516. {
  3517. DialogAction action = DIALOG_NEXT;
  3518. long actionval = 0;
  3519. me->getUserData(ACTION, actionval);
  3520. action = (DialogAction)actionval;
  3521. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3522. return action;
  3523. dialogSetup(me, SLAPD_KEY_UG_SUFFIX, getManager(me)->getDefaultSuffix());
  3524. long setupval = 0;
  3525. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3526. setupval == SETUP_ONLY)
  3527. return DIALOG_NEXT;
  3528. return DIALOG_SAME;
  3529. }
  3530. static DialogAction
  3531. askUGSuffixNext(Dialog *me)
  3532. {
  3533. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3534. return DIALOG_NEXT;
  3535. const char *buf;
  3536. NSString val;
  3537. buf = me->input();
  3538. if (buf[0] == 0)
  3539. val = me->defaultAns();
  3540. else
  3541. val = buf;
  3542. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_SUFFIX, val);
  3543. // check to see if it is a valid dn
  3544. if (!isAValidDN(val))
  3545. {
  3546. DialogManagerType::showAlert("The suffix must be a valid DN");
  3547. return DIALOG_SAME;
  3548. }
  3549. if (!isValid(val))
  3550. {
  3551. DialogManagerType::showAlert("Please enter a valid string.");
  3552. return DIALOG_SAME;
  3553. }
  3554. return DIALOG_NEXT;
  3555. }
  3556. DialogInput askReconfigMCAdminPwd(
  3557. (const char*)0,
  3558. "Fedora configuration directory server\nadministrator ID",
  3559. (const char*)0,
  3560. askReconfigMCAdminPwdSetup,
  3561. askReconfigMCAdminPwdNext
  3562. );
  3563. static DialogAction
  3564. askReconfigMCAdminPwdSetup(Dialog *me)
  3565. {
  3566. #if DEBUG > 1
  3567. cerr << "Entering askReconfigMCAdminPwdSetup" << endl;
  3568. #endif
  3569. NSString msg = NSString(
  3570. "In order to reconfigure your installation, the Configuration Directory\n"
  3571. "Administrator password is required. Here is your current information:\n\n"
  3572. "Configuration Directory: ") +
  3573. getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL) + "\n" +
  3574. "Configuration Administrator ID: " +
  3575. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID) + "\n" +
  3576. "\nAt the prompt, please enter the password for the Configuration Administrator.\n";
  3577. me->setText(msg);
  3578. me->setDefaultAns(getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID));
  3579. #if DEBUG > 1
  3580. cerr << "Leaving askReconfigMCAdminPwdSetup" << endl;
  3581. #endif
  3582. return DIALOG_SAME;
  3583. }
  3584. static DialogAction
  3585. askReconfigMCAdminPwdNext(Dialog *me)
  3586. {
  3587. const char *buf;
  3588. buf = me->input();
  3589. if (!buf || buf[0] == 0)
  3590. {
  3591. buf = me->defaultAns();
  3592. }
  3593. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_ID, buf);
  3594. if (!isValid(buf))
  3595. {
  3596. DialogManagerType::showAlert("Please enter a valid string.");
  3597. return DIALOG_SAME;
  3598. }
  3599. me->showString("Password: ");
  3600. while (1)
  3601. {
  3602. if (me->getPassword () == 0)
  3603. {
  3604. return DIALOG_PREV;
  3605. }
  3606. else
  3607. {
  3608. char *inp = strdup(me->input());
  3609. if (inp[0] == 0)
  3610. {
  3611. me->showString("Password: ");
  3612. continue;
  3613. }
  3614. else if (contains8BitChars(inp))
  3615. {
  3616. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  3617. return DIALOG_SAME;
  3618. }
  3619. else if (!isValid(inp))
  3620. {
  3621. DialogManagerType::showAlert("Please enter a valid password.");
  3622. return DIALOG_SAME;
  3623. }
  3624. else
  3625. {
  3626. int status;
  3627. if ((status = authLdapUser(
  3628. getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL),
  3629. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID),
  3630. inp, 0, 0)))
  3631. {
  3632. ostrstream msg;
  3633. msg << "Could not connect to "
  3634. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL)
  3635. << endl << "for ID "
  3636. << getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_ADMIN_ID)
  3637. << " status = " << status << endl
  3638. << "Please check your typing. If you have mis-typed, you can backup"
  3639. << endl
  3640. << "and retype. Otherwise, the remote server may be down at this time."
  3641. << endl
  3642. << "The reconfiguration cannot proceed."
  3643. << endl << ends;
  3644. DialogManagerType::showAlert(msg.str());
  3645. delete [] msg.str();
  3646. return DIALOG_SAME;
  3647. }
  3648. }
  3649. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_PWD, inp);
  3650. free(inp);
  3651. break;
  3652. }
  3653. }
  3654. return DIALOG_NEXT;
  3655. }