ux-dialog.cc 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339
  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. DialogYesNo 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. me->setInputLen(1024); // it seems to get reset somewhere . . .
  944. long setupval = 0;
  945. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  946. setupval == SETUP_ONLY)
  947. return DIALOG_NEXT;
  948. return DIALOG_SAME;
  949. }
  950. static DialogAction
  951. askPopulateNext(Dialog *me)
  952. {
  953. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  954. return DIALOG_NEXT;
  955. const char *buf = me->input();
  956. if (!buf || !*buf)
  957. {
  958. buf = me->defaultAns();
  959. if (!buf || !*buf)
  960. buf = "No";
  961. }
  962. if (buf && !strncasecmp(buf, "none", strlen(buf)))
  963. {
  964. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_ORG_ENTRIES, "No");
  965. getManager(me)->getDefaultScript()->
  966. set(SLAPD_KEY_INSTALL_LDIF_FILE, "none");
  967. }
  968. else if (buf && !strncasecmp(buf, "suggest", strlen(buf)))
  969. {
  970. getManager(me)->getDefaultScript()->
  971. set(SLAPD_KEY_INSTALL_LDIF_FILE, "suggest");
  972. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ADD_ORG_ENTRIES, "Yes");
  973. } else {
  974. getManager(me)->getDefaultScript()->set(SLAPD_KEY_INSTALL_LDIF_FILE, buf);
  975. if (!InstUtil::fileExists(buf))
  976. {
  977. NSString msg = NSString("The specified filename ") + buf + "\n" +
  978. "does not exist. Please try again.\n";
  979. DialogManagerType::showAlert(msg);
  980. return DIALOG_SAME;
  981. }
  982. else
  983. {
  984. getManager(me)->getDefaultScript()->
  985. set(SLAPD_KEY_ADD_ORG_ENTRIES, "Yes");
  986. getManager(me)->getDefaultScript()->
  987. set(SLAPD_KEY_INSTALL_LDIF_FILE, buf);
  988. }
  989. }
  990. return DIALOG_NEXT;
  991. }
  992. DialogInput askOrgSize(
  993. "Your directory will be populated with entries based on the size of\n"
  994. "your organization. The choices are small or large. Please specify 1\n"
  995. "for small and 2 for large.\n",
  996. "Organization size (1 or 2)",
  997. "1",
  998. askOrgSizeSetup,
  999. askOrgSizeNext
  1000. );
  1001. static DialogAction
  1002. askOrgSizeSetup(Dialog *me)
  1003. {
  1004. DialogAction action = DIALOG_NEXT;
  1005. long actionval = 0;
  1006. me->getUserData(ACTION, actionval);
  1007. action = (DialogAction)actionval;
  1008. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  1009. return action;
  1010. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_ADD_ORG_ENTRIES))
  1011. return action;
  1012. else if (dialogSetup(me, SLAPD_KEY_ORG_SIZE, "1") &&
  1013. getManager(me)->installMode() == Silent)
  1014. return DIALOG_ERROR;
  1015. long setupval = 0;
  1016. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1017. setupval == SETUP_ONLY)
  1018. return DIALOG_NEXT;
  1019. return DIALOG_SAME;
  1020. }
  1021. static DialogAction
  1022. askOrgSizeNext(Dialog *me)
  1023. {
  1024. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER))
  1025. return DIALOG_NEXT;
  1026. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_ADD_ORG_ENTRIES))
  1027. return DIALOG_NEXT;
  1028. const char *buf = me->input();
  1029. const char *tmp;
  1030. char testbuf[1024];
  1031. int num, err = 0;
  1032. if (buf[0] == 0)
  1033. {
  1034. tmp = me->defaultAns();
  1035. }
  1036. else
  1037. {
  1038. tmp = buf;
  1039. }
  1040. getManager(me)->getDefaultScript()->set(SLAPD_KEY_ORG_SIZE, tmp);
  1041. num = atoi(tmp);
  1042. if (num != 1 && num != 2)
  1043. {
  1044. PR_snprintf(testbuf, sizeof(testbuf), "Please enter a 1 or a 2\n\n");
  1045. err = -1;
  1046. }
  1047. if (err)
  1048. {
  1049. DialogManagerType::showAlert(testbuf);
  1050. return DIALOG_SAME;
  1051. }
  1052. return DIALOG_NEXT;
  1053. }
  1054. DialogYesNo askReplication(
  1055. "Replication is used to duplicate all or part of a directory server to\n"
  1056. "another directory server. This can be used for failsafe purposes, to\n"
  1057. "ensure that the directory data is always online and up-to-date in case\n"
  1058. "one server goes down. It is also useful for distributing directory\n"
  1059. "data from a central main repository to remote directory servers.\n",
  1060. "Do you want to configure this directory server\nto use replication?",
  1061. "No",
  1062. askReplicationSetup,
  1063. askReplicationNext
  1064. );
  1065. static DialogAction
  1066. askReplicationSetup(Dialog *me)
  1067. {
  1068. me = me;
  1069. long setupval = 0;
  1070. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1071. setupval == SETUP_ONLY)
  1072. return DIALOG_NEXT;
  1073. return DIALOG_SAME;
  1074. }
  1075. static DialogAction
  1076. askReplicationNext(Dialog *me)
  1077. {
  1078. const char *buf = me->input();
  1079. if (!buf || !*buf)
  1080. {
  1081. buf = me->defaultAns();
  1082. if (!buf || !*buf)
  1083. buf = "No";
  1084. }
  1085. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_REPLICATION, buf);
  1086. if (!isValidYesNo(buf))
  1087. return DIALOG_SAME;
  1088. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1089. {
  1090. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_SUPPLIER, "No");
  1091. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_CONSUMER, "No");
  1092. }
  1093. return DIALOG_NEXT;
  1094. }
  1095. DialogYesNo askCIR(
  1096. "You may want to set up your directory server as a consumer server to\n"
  1097. "receive replicated entries from another directory server. The first\n"
  1098. "two of the following methods configure this server as a consumer:\n\n"
  1099. "1) The supplier server will push its entries to this server (SIR)\n"
  1100. "2) This server will pull the entries from the supplier (CIR)\n"
  1101. "3) This server will not be a consumer for replication (NONE)\n",
  1102. "Do you want to set up this server as a consumer\n"
  1103. "for replication? (1, 2, or 3)",
  1104. "3",
  1105. askCIRSetup,
  1106. askCIRNext
  1107. );
  1108. static DialogAction
  1109. askCIRSetup(Dialog *me)
  1110. {
  1111. DialogAction action = DIALOG_NEXT;
  1112. long actionval = 0;
  1113. me->getUserData(ACTION, actionval);
  1114. action = (DialogAction)actionval;
  1115. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1116. return action;
  1117. long setupval = 0;
  1118. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1119. setupval == SETUP_ONLY)
  1120. return DIALOG_NEXT;
  1121. return DIALOG_SAME;
  1122. }
  1123. static DialogAction
  1124. askCIRNext(Dialog *me)
  1125. {
  1126. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1127. return DIALOG_NEXT;
  1128. const char *buf = me->input();
  1129. if (!buf || !*buf)
  1130. {
  1131. buf = me->defaultAns();
  1132. if (!buf || !*buf)
  1133. buf = "3";
  1134. }
  1135. int val = atoi(buf);
  1136. if (!val || val < 1 || val > 3)
  1137. {
  1138. DialogManagerType::showAlert("Please enter a 1, 2, or 3.");
  1139. return DIALOG_SAME;
  1140. }
  1141. else if (val == 3)
  1142. {
  1143. buf = "No";
  1144. }
  1145. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_CONSUMER, buf);
  1146. return DIALOG_NEXT;
  1147. }
  1148. DialogYesNo askSIR(
  1149. "You may want to set up your directory server as a supplier server to\n"
  1150. "replicate its entries to another directory server. The first two of\n"
  1151. "the following methods configure this server as a supplier:\n\n"
  1152. "1) This server will push its entries to another one (SIR)\n"
  1153. "2) Another server will pull entries from this one (CIR)\n"
  1154. "3) This server will not be a supplier for replication (NONE)\n",
  1155. "Do you want to set up this server as a supplier\n"
  1156. "for replication? (1, 2, or 3)",
  1157. "3",
  1158. askSIRSetup,
  1159. askSIRNext
  1160. );
  1161. static DialogAction
  1162. askSIRSetup(Dialog *me)
  1163. {
  1164. DialogAction action = DIALOG_NEXT;
  1165. long actionval = 0;
  1166. me->getUserData(ACTION, actionval);
  1167. action = (DialogAction)actionval;
  1168. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1169. return action;
  1170. long setupval = 0;
  1171. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1172. setupval == SETUP_ONLY)
  1173. return DIALOG_NEXT;
  1174. return DIALOG_SAME;
  1175. }
  1176. static DialogAction
  1177. askSIRNext(Dialog *me)
  1178. {
  1179. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_REPLICATION))
  1180. return DIALOG_NEXT;
  1181. const char *buf = me->input();
  1182. if (!buf || !*buf)
  1183. {
  1184. buf = me->defaultAns();
  1185. if (!buf || !*buf)
  1186. buf = "3";
  1187. }
  1188. int val = atoi(buf);
  1189. if (!val || val < 1 || val > 3)
  1190. {
  1191. DialogManagerType::showAlert("Please enter a 1, 2, or 3.");
  1192. return DIALOG_SAME;
  1193. }
  1194. else if (val == 3)
  1195. {
  1196. buf = "No";
  1197. }
  1198. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SETUP_SUPPLIER, buf);
  1199. return DIALOG_NEXT;
  1200. }
  1201. DialogInput askCIRHost(
  1202. "Please specify the host name of the server from which the replicated\n"
  1203. "entries will be copied.\n",
  1204. "Supplier host name",
  1205. 0,
  1206. askCIRHostSetup,
  1207. askCIRHostNext
  1208. );
  1209. static DialogAction
  1210. askCIRHostSetup(Dialog *me)
  1211. {
  1212. DialogAction action = DIALOG_NEXT;
  1213. long actionval = 0;
  1214. me->getUserData(ACTION, actionval);
  1215. action = (DialogAction)actionval;
  1216. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1217. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1218. return action;
  1219. else if (dialogSetup(me, SLAPD_KEY_CIR_HOST, 0) &&
  1220. getManager(me)->installMode() == Silent)
  1221. return DIALOG_ERROR;
  1222. long setupval = 0;
  1223. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1224. setupval == SETUP_ONLY)
  1225. return DIALOG_NEXT;
  1226. return DIALOG_SAME;
  1227. }
  1228. static DialogAction
  1229. askCIRHostNext(Dialog *me)
  1230. {
  1231. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1232. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1233. return DIALOG_NEXT;
  1234. const char *buf = me->input();
  1235. const char *tmp;
  1236. if (buf[0] == 0)
  1237. {
  1238. tmp = me->defaultAns();
  1239. }
  1240. else
  1241. {
  1242. tmp = buf;
  1243. }
  1244. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_HOST, tmp);
  1245. if (!tmp || !isValid(tmp))
  1246. {
  1247. DialogManagerType::showAlert("Please enter a valid hostname");
  1248. return DIALOG_SAME;
  1249. }
  1250. return DIALOG_NEXT;
  1251. }
  1252. DialogInput askCIRPort(
  1253. "Please specify the port of the server from which the replicated\n"
  1254. "entries will be copied.\n",
  1255. "Supplier port",
  1256. "389",
  1257. askCIRPortSetup,
  1258. askCIRPortNext
  1259. );
  1260. static DialogAction
  1261. askCIRPortSetup(Dialog *me)
  1262. {
  1263. DialogAction action = DIALOG_NEXT;
  1264. long actionval = 0;
  1265. me->getUserData(ACTION, actionval);
  1266. action = (DialogAction)actionval;
  1267. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1268. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1269. return action;
  1270. const char *defaultPort = "389";
  1271. if (getManager(me)->featureIsEnabled(SLAPD_KEY_CIR_SECURITY_ON))
  1272. defaultPort = "636";
  1273. if (dialogSetup(me, SLAPD_KEY_CIR_PORT, defaultPort) &&
  1274. getManager(me)->installMode() == Silent)
  1275. return DIALOG_ERROR;
  1276. long setupval = 0;
  1277. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1278. setupval == SETUP_ONLY)
  1279. return DIALOG_NEXT;
  1280. return DIALOG_SAME;
  1281. }
  1282. static DialogAction
  1283. askCIRPortNext(Dialog *me)
  1284. {
  1285. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1286. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1287. return DIALOG_NEXT;
  1288. const char *buf = me->input();
  1289. const char *tmp;
  1290. char testbuf[1024];
  1291. int port, err = 0;
  1292. if (buf[0] == 0)
  1293. {
  1294. tmp = me->defaultAns();
  1295. }
  1296. else
  1297. {
  1298. tmp = buf;
  1299. }
  1300. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_PORT, tmp);
  1301. port = atoi(tmp);
  1302. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  1303. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  1304. {
  1305. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  1306. "Please choose another port between 1 and %d.\n\n",
  1307. port, MAXPORT);
  1308. err = -1;
  1309. }
  1310. if (err)
  1311. {
  1312. DialogManagerType::showAlert(testbuf);
  1313. return DIALOG_SAME;
  1314. }
  1315. return DIALOG_NEXT;
  1316. }
  1317. DialogInput askCIRDN(
  1318. "Replication requires that this consumer has access to the portion of\n"
  1319. "the remote directory to be replicated. This requires a bind DN and\n"
  1320. "password for access to the supplier. You will first be asked for the\n"
  1321. "bind DN, then the password.\n",
  1322. "Replication DN",
  1323. NULL,
  1324. askCIRDNSetup,
  1325. askCIRDNNext
  1326. );
  1327. static DialogAction
  1328. askCIRDNSetup(Dialog *me)
  1329. {
  1330. DialogAction action = DIALOG_NEXT;
  1331. long actionval = 0;
  1332. me->getUserData(ACTION, actionval);
  1333. action = (DialogAction)actionval;
  1334. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1335. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1336. return action;
  1337. if (dialogSetup(me, SLAPD_KEY_CIR_BINDDN, getManager(me)->getConsumerDN()) &&
  1338. getManager(me)->installMode() == Silent)
  1339. return DIALOG_ERROR;
  1340. long setupval = 0;
  1341. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1342. setupval == SETUP_ONLY)
  1343. return DIALOG_NEXT;
  1344. return DIALOG_SAME;
  1345. }
  1346. static DialogAction
  1347. askCIRDNNext(Dialog *me)
  1348. {
  1349. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1350. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1351. return DIALOG_NEXT;
  1352. const char *slapdUser;
  1353. char *slapdPwd = 0;
  1354. const char *buf;
  1355. buf = me->input();
  1356. if (buf[0] == 0)
  1357. {
  1358. slapdUser = me->defaultAns();
  1359. }
  1360. else
  1361. {
  1362. slapdUser = buf;
  1363. }
  1364. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_BINDDN, slapdUser);
  1365. // check to see if it is a valid DN
  1366. if (!isAValidDN(slapdUser))
  1367. {
  1368. DialogManagerType::showAlert("The consumer must be a valid DN.");
  1369. return DIALOG_SAME;
  1370. }
  1371. else if (!isValid(slapdUser))
  1372. {
  1373. DialogManagerType::showAlert("Please enter a valid string.");
  1374. return DIALOG_SAME;
  1375. }
  1376. while (1)
  1377. {
  1378. me->showString("Password: ");
  1379. if (me->getPassword () == 0)
  1380. {
  1381. return DIALOG_PREV;
  1382. }
  1383. else
  1384. {
  1385. char *inp = strdup(me->input());
  1386. if (inp[0] == 0)
  1387. {
  1388. free(inp);
  1389. continue;
  1390. }
  1391. else
  1392. {
  1393. slapdPwd = inp;
  1394. break;
  1395. }
  1396. }
  1397. }
  1398. if (slapdPwd)
  1399. {
  1400. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_BINDDNPWD, slapdPwd);
  1401. free(slapdPwd);
  1402. }
  1403. return DIALOG_NEXT;
  1404. }
  1405. DialogInput askCIRSuffix(
  1406. "Please enter the full DN of the part of the tree to replicate,\n"
  1407. "including the suffix (e.g. ou=People, o=company.com).\n",
  1408. "Enter the directory path",
  1409. NULL,
  1410. askCIRSuffixSetup,
  1411. askCIRSuffixNext
  1412. );
  1413. static DialogAction
  1414. askCIRSuffixSetup(Dialog *me)
  1415. {
  1416. DialogAction action = DIALOG_NEXT;
  1417. long actionval = 0;
  1418. me->getUserData(ACTION, actionval);
  1419. action = (DialogAction)actionval;
  1420. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1421. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1422. return action;
  1423. if (dialogSetup(me, SLAPD_KEY_CIR_SUFFIX, getManager(me)->getDefaultSuffix()) &&
  1424. getManager(me)->installMode() == Silent)
  1425. return DIALOG_ERROR;
  1426. long setupval = 0;
  1427. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1428. setupval == SETUP_ONLY)
  1429. return DIALOG_NEXT;
  1430. return DIALOG_SAME;
  1431. }
  1432. static DialogAction
  1433. askCIRSuffixNext(Dialog *me)
  1434. {
  1435. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1436. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1437. return DIALOG_NEXT;
  1438. const char *buf;
  1439. NSString val;
  1440. buf = me->input();
  1441. if (buf[0] == 0)
  1442. val = me->defaultAns();
  1443. else
  1444. val = buf;
  1445. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_SUFFIX, val);
  1446. // check val to see if it is a valid DN
  1447. if (!isAValidDN(val))
  1448. {
  1449. DialogManagerType::showAlert("The suffix must be a valid DN.");
  1450. return DIALOG_SAME;
  1451. }
  1452. if (!isValid(val))
  1453. {
  1454. DialogManagerType::showAlert("Please enter a valid string.");
  1455. return DIALOG_SAME;
  1456. }
  1457. int status;
  1458. if ((status = getManager(me)->verifyRemoteLdap(
  1459. SLAPD_KEY_CIR_HOST,
  1460. SLAPD_KEY_CIR_PORT,
  1461. SLAPD_KEY_CIR_SUFFIX,
  1462. SLAPD_KEY_CIR_BINDDN,
  1463. SLAPD_KEY_CIR_BINDDNPWD
  1464. ))
  1465. )
  1466. {
  1467. ostrstream msg;
  1468. msg << "Could not connect to ldap://"
  1469. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_HOST)
  1470. << ":"
  1471. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_PORT)
  1472. << "/"
  1473. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_SUFFIX)
  1474. << endl << "for bind DN "
  1475. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_CIR_BINDDN)
  1476. << " status = " << status << endl
  1477. << "Please check your typing. If you have mis-typed, you can backup"
  1478. << endl
  1479. << "and retype. Otherwise, the remote server may be down at this time."
  1480. << endl
  1481. << "The replication agreement will be created anyway. Proceeding..."
  1482. << endl << ends;
  1483. DialogManagerType::showAlert(msg.str());
  1484. delete [] msg.str();
  1485. return DIALOG_NEXT;
  1486. }
  1487. return DIALOG_NEXT;
  1488. }
  1489. DialogYesNo askCIRSSL(
  1490. "You may use SSL authentication for replication if you have enabled it\n"
  1491. "on the remote server.\n",
  1492. "Do you want to use SSL?",
  1493. "No",
  1494. askCIRSSLSetup,
  1495. askCIRSSLNext
  1496. );
  1497. static DialogAction
  1498. askCIRSSLSetup(Dialog *me)
  1499. {
  1500. DialogAction action = DIALOG_NEXT;
  1501. long actionval = 0;
  1502. me->getUserData(ACTION, actionval);
  1503. action = (DialogAction)actionval;
  1504. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1505. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1506. return action;
  1507. long setupval = 0;
  1508. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1509. setupval == SETUP_ONLY)
  1510. return DIALOG_NEXT;
  1511. return DIALOG_SAME;
  1512. }
  1513. static DialogAction
  1514. askCIRSSLNext(Dialog *me)
  1515. {
  1516. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1517. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1518. return DIALOG_NEXT;
  1519. const char *buf = me->input();
  1520. if (!buf || !*buf)
  1521. {
  1522. buf = me->defaultAns();
  1523. if (!buf || !*buf)
  1524. buf = "No";
  1525. }
  1526. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_SECURITY_ON, buf);
  1527. if (!isValidYesNo(buf))
  1528. return DIALOG_SAME;
  1529. return DIALOG_NEXT;
  1530. }
  1531. DialogInput askCIRInterval(
  1532. "Please specify the time interval to check the remote server for new\n"
  1533. "entries to be replicated. Use the directory server console to set up\n"
  1534. "more fine-grained control. Specify the time in minutes. Use a 0\n"
  1535. "(zero) to indicate that changes should be propagated immediately all\n"
  1536. "the time.\n",
  1537. "Replication Sync Interval (in minutes)",
  1538. "10",
  1539. askCIRIntervalSetup,
  1540. askCIRIntervalNext
  1541. );
  1542. static DialogAction
  1543. askCIRIntervalSetup(Dialog *me)
  1544. {
  1545. DialogAction action = DIALOG_NEXT;
  1546. long actionval = 0;
  1547. me->getUserData(ACTION, actionval);
  1548. action = (DialogAction)actionval;
  1549. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1550. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1551. return action;
  1552. if (dialogSetup(me, SLAPD_KEY_CIR_INTERVAL, "10") &&
  1553. getManager(me)->installMode() == Silent)
  1554. return DIALOG_ERROR;
  1555. long setupval = 0;
  1556. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1557. setupval == SETUP_ONLY)
  1558. return DIALOG_NEXT;
  1559. return DIALOG_SAME;
  1560. }
  1561. static DialogAction
  1562. askCIRIntervalNext(Dialog *me)
  1563. {
  1564. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1565. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  1566. return DIALOG_NEXT;
  1567. const char *buf = me->input();
  1568. const char *tmp;
  1569. char testbuf[1024];
  1570. int interval, err = 0;
  1571. if (buf[0] == 0)
  1572. {
  1573. tmp = me->defaultAns();
  1574. }
  1575. else
  1576. {
  1577. tmp = buf;
  1578. }
  1579. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_INTERVAL, tmp);
  1580. interval = atoi(tmp);
  1581. if (!isdigit((*tmp)) || interval < 0)
  1582. {
  1583. PR_snprintf(testbuf, sizeof(testbuf), "Please specify an integer greater than or equal to 0");
  1584. err = -1;
  1585. }
  1586. if (err)
  1587. {
  1588. DialogManagerType::showAlert(testbuf);
  1589. return DIALOG_SAME;
  1590. }
  1591. return DIALOG_NEXT;
  1592. }
  1593. DialogInput askChangeLogSuffix(
  1594. "Changes to the database will be kept under a separate suffix in the\n"
  1595. "directory tree. These changes are used to replicate changes to other\n"
  1596. "directory servers.\n",
  1597. "Changelog suffix",
  1598. "cn=changelog",
  1599. askChangeLogSuffixSetup,
  1600. askChangeLogSuffixNext
  1601. );
  1602. static DialogAction
  1603. askChangeLogSuffixSetup(Dialog *me)
  1604. {
  1605. DialogAction action = DIALOG_NEXT;
  1606. long actionval = 0;
  1607. me->getUserData(ACTION, actionval);
  1608. action = (DialogAction)actionval;
  1609. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1610. return action;
  1611. if (dialogSetup(me, SLAPD_KEY_CHANGELOGSUFFIX, "cn=changelog") &&
  1612. getManager(me)->installMode() == Silent)
  1613. return DIALOG_ERROR;
  1614. long setupval = 0;
  1615. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1616. setupval == SETUP_ONLY)
  1617. return DIALOG_NEXT;
  1618. return DIALOG_SAME;
  1619. }
  1620. static DialogAction
  1621. askChangeLogSuffixNext(Dialog *me)
  1622. {
  1623. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1624. return DIALOG_NEXT;
  1625. const char *buf;
  1626. NSString val;
  1627. buf = me->input();
  1628. if (buf[0] == 0)
  1629. val = me->defaultAns();
  1630. else
  1631. val = buf;
  1632. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CHANGELOGSUFFIX, val);
  1633. // check to see if val is a valid DN
  1634. if (!isAValidDN(val))
  1635. {
  1636. DialogManagerType::showAlert("The ChangeLog suffix must be a valid DN");
  1637. return DIALOG_SAME;
  1638. }
  1639. else if (!isValid(val))
  1640. {
  1641. DialogManagerType::showAlert("Please enter a valid string.");
  1642. return DIALOG_SAME;
  1643. }
  1644. return DIALOG_NEXT;
  1645. }
  1646. DialogInput askChangeLogDir(
  1647. "Changes to the main database will be kept in a separate database\n"
  1648. "stored in a separate directory path, usually under your server\n"
  1649. "instance directory.\n",
  1650. "Changelog database\n"
  1651. "directory",
  1652. NULL,
  1653. askChangeLogDirSetup,
  1654. askChangeLogDirNext
  1655. );
  1656. static DialogAction
  1657. askChangeLogDirSetup(Dialog *me)
  1658. {
  1659. DialogAction action = DIALOG_NEXT;
  1660. long actionval = 0;
  1661. me->getUserData(ACTION, actionval);
  1662. action = (DialogAction)actionval;
  1663. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1664. return action;
  1665. NSString dir = NSString(
  1666. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ROOT)
  1667. ) + "/slapd-" +
  1668. getManager(me)->getDefaultScript()->get(SLAPD_KEY_SERVER_IDENTIFIER) +
  1669. "/logs/changelogdb";
  1670. if (dialogSetup(me, SLAPD_KEY_CHANGELOGDIR, dir) &&
  1671. getManager(me)->installMode() == Silent)
  1672. return DIALOG_ERROR;
  1673. long setupval = 0;
  1674. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1675. setupval == SETUP_ONLY)
  1676. return DIALOG_NEXT;
  1677. return DIALOG_SAME;
  1678. }
  1679. static DialogAction
  1680. askChangeLogDirNext(Dialog *me)
  1681. {
  1682. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER))
  1683. return DIALOG_NEXT;
  1684. const char *buf;
  1685. NSString val;
  1686. buf = me->input();
  1687. if (buf[0] == 0)
  1688. val = me->defaultAns();
  1689. else
  1690. val = buf;
  1691. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CHANGELOGDIR, val);
  1692. if (InstUtil::dirExists(val) && !InstUtil::dirWritable(val))
  1693. {
  1694. DialogManagerType::showAlert("You do not have access to that directory. Please try again.");
  1695. return DIALOG_SAME;
  1696. }
  1697. return DIALOG_NEXT;
  1698. }
  1699. DialogInput askReplicationDN(
  1700. "In order to allow remote servers to replicate new entries to this\n"
  1701. "server, the remote server must have the ability to bind to this server\n"
  1702. "as some entity with permission to do so. The Supplier DN is the DN of\n"
  1703. "the entity the remote server will use to connect to this server to\n"
  1704. "supply updates. The Supplier DN also requires a password which you\n"
  1705. "will be prompted for after the DN.\n",
  1706. "Supplier Bind DN",
  1707. "cn=supplier",
  1708. askReplicationDNSetup,
  1709. askReplicationDNNext
  1710. );
  1711. static DialogAction
  1712. askReplicationDNSetup(Dialog *me)
  1713. {
  1714. DialogAction action = DIALOG_NEXT;
  1715. long actionval = 0;
  1716. me->getUserData(ACTION, actionval);
  1717. action = (DialogAction)actionval;
  1718. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1719. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "1"))
  1720. return action;
  1721. if (dialogSetup(me, SLAPD_KEY_REPLICATIONDN, "cn=supplier") &&
  1722. getManager(me)->installMode() == Silent)
  1723. return DIALOG_ERROR;
  1724. long setupval = 0;
  1725. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1726. setupval == SETUP_ONLY)
  1727. return DIALOG_NEXT;
  1728. return DIALOG_SAME;
  1729. }
  1730. static DialogAction
  1731. askReplicationDNNext(Dialog *me)
  1732. {
  1733. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  1734. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "1"))
  1735. return DIALOG_NEXT;
  1736. const char *replicationdn;
  1737. const char *replicationpw;
  1738. const char *buf;
  1739. buf = me->input();
  1740. if (buf[0] == 0)
  1741. {
  1742. replicationdn = me->defaultAns();
  1743. }
  1744. else
  1745. {
  1746. replicationdn = buf;
  1747. }
  1748. getManager(me)->getDefaultScript()->set(SLAPD_KEY_REPLICATIONDN, replicationdn);
  1749. // check to see if it is a valid DN
  1750. if (!isAValidDN(replicationdn))
  1751. {
  1752. DialogManagerType::showAlert("The Supplier Bind DN must be a valid DN");
  1753. return DIALOG_SAME;
  1754. }
  1755. if (!isValid(replicationdn))
  1756. {
  1757. DialogManagerType::showAlert("Please enter a valid string.");
  1758. return DIALOG_SAME;
  1759. }
  1760. while (1)
  1761. {
  1762. me->showString("Password: ");
  1763. if (me->getPassword () == 0)
  1764. {
  1765. return DIALOG_PREV;
  1766. }
  1767. else
  1768. {
  1769. char *inp = strdup(me->input());
  1770. if (inp[0] == 0)
  1771. {
  1772. continue;
  1773. }
  1774. else if (contains8BitChars(inp))
  1775. {
  1776. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  1777. return DIALOG_SAME;
  1778. }
  1779. else if (!isValid(inp))
  1780. {
  1781. DialogManagerType::showAlert("Please enter a valid password.");
  1782. return DIALOG_SAME;
  1783. }
  1784. else
  1785. {
  1786. me->showString("Password (again): ");
  1787. if (me->getPassword() == 0)
  1788. {
  1789. return DIALOG_PREV;
  1790. }
  1791. else
  1792. {
  1793. replicationpw = me->input();
  1794. if (strcmp(inp,replicationpw))
  1795. {
  1796. DialogManagerType::showAlert("Passwords don't match.");
  1797. return DIALOG_SAME;
  1798. }
  1799. break;
  1800. }
  1801. }
  1802. free(inp);
  1803. }
  1804. }
  1805. getManager(me)->getDefaultScript()->set(SLAPD_KEY_REPLICATIONPWD, replicationpw);
  1806. return DIALOG_NEXT;
  1807. }
  1808. DialogInput askConsumerDN(
  1809. "In order to allow remote servers to replicate new entries from this\n"
  1810. "server, the remote server must have the ability to bind to this server\n"
  1811. "as some entity with permission to do so. The Consumer DN is the DN of\n"
  1812. "the entity the remote server will use to connect to this server to\n"
  1813. "pull the new entries. This entity will have access to the entire\n"
  1814. "database as well as the changelog entries. The Consumer DN also\n"
  1815. "requires a password which you will be prompted for after the DN. If\n"
  1816. "you leave this entry blank, no consumer bind DN will be created. The\n"
  1817. "default is no consumer bind DN.\n",
  1818. "Consumer Bind DN",
  1819. NULL,
  1820. askConsumerDNSetup,
  1821. askConsumerDNNext
  1822. );
  1823. static DialogAction
  1824. askConsumerDNSetup(Dialog *me)
  1825. {
  1826. DialogAction action = DIALOG_NEXT;
  1827. long actionval = 0;
  1828. me->getUserData(ACTION, actionval);
  1829. action = (DialogAction)actionval;
  1830. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1831. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "2"))
  1832. return action;
  1833. if (dialogSetup(me, SLAPD_KEY_CONSUMERDN, 0) &&
  1834. getManager(me)->installMode() == Silent)
  1835. return DIALOG_ERROR;
  1836. long setupval = 0;
  1837. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1838. setupval == SETUP_ONLY)
  1839. return DIALOG_NEXT;
  1840. return DIALOG_SAME;
  1841. }
  1842. static DialogAction
  1843. askConsumerDNNext(Dialog *me)
  1844. {
  1845. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1846. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "2"))
  1847. return DIALOG_NEXT;
  1848. const char *consumerdn;
  1849. const char *consumerpw;
  1850. const char *buf;
  1851. buf = me->input();
  1852. if (buf[0] == 0)
  1853. {
  1854. consumerdn = me->defaultAns();
  1855. }
  1856. else
  1857. {
  1858. consumerdn = buf;
  1859. }
  1860. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CONSUMERDN, consumerdn);
  1861. if (!consumerdn || !*consumerdn ||
  1862. !strncasecmp(consumerdn, "none", strlen(consumerdn)))
  1863. {
  1864. getManager(me)->getDefaultScript()->remove(SLAPD_KEY_CONSUMERDN);
  1865. return DIALOG_NEXT;
  1866. }
  1867. // check to see if it is a valid dn
  1868. if (!isAValidDN(consumerdn))
  1869. {
  1870. DialogManagerType::showAlert("The Consumer Bind DN must be a valid DN");
  1871. return DIALOG_SAME;
  1872. }
  1873. else if (!isValid(consumerdn))
  1874. {
  1875. DialogManagerType::showAlert("Please enter a valid string.");
  1876. return DIALOG_SAME;
  1877. }
  1878. while (1)
  1879. {
  1880. me->showString("Password: ");
  1881. if (me->getPassword () == 0)
  1882. {
  1883. return DIALOG_PREV;
  1884. }
  1885. else
  1886. {
  1887. char *inp = strdup(me->input());
  1888. if (inp[0] == 0)
  1889. {
  1890. continue;
  1891. }
  1892. else if (contains8BitChars(inp))
  1893. {
  1894. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  1895. return DIALOG_SAME;
  1896. }
  1897. else if (!isValid(inp))
  1898. {
  1899. DialogManagerType::showAlert("Please enter a valid password.");
  1900. return DIALOG_SAME;
  1901. }
  1902. else
  1903. {
  1904. me->showString("Password (again): ");
  1905. if (me->getPassword() == 0)
  1906. {
  1907. return DIALOG_PREV;
  1908. }
  1909. else
  1910. {
  1911. consumerpw = me->input();
  1912. if (strcmp(inp,consumerpw))
  1913. {
  1914. DialogManagerType::showAlert("Passwords don't match.");
  1915. return DIALOG_SAME;
  1916. }
  1917. break;
  1918. }
  1919. }
  1920. free(inp);
  1921. }
  1922. }
  1923. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CONSUMERPWD, consumerpw);
  1924. return DIALOG_NEXT;
  1925. }
  1926. DialogInput askSIRHost(
  1927. "Please specify the host name of the server to which the replicated\n"
  1928. "entries will be pushed.\n",
  1929. "Consumer host name",
  1930. 0,
  1931. askSIRHostSetup,
  1932. askSIRHostNext
  1933. );
  1934. static DialogAction
  1935. askSIRHostSetup(Dialog *me)
  1936. {
  1937. DialogAction action = DIALOG_NEXT;
  1938. long actionval = 0;
  1939. me->getUserData(ACTION, actionval);
  1940. action = (DialogAction)actionval;
  1941. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1942. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1943. return action;
  1944. else if (dialogSetup(me, SLAPD_KEY_SIR_HOST, 0) &&
  1945. getManager(me)->installMode() == Silent)
  1946. return DIALOG_ERROR;
  1947. long setupval = 0;
  1948. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  1949. setupval == SETUP_ONLY)
  1950. return DIALOG_NEXT;
  1951. return DIALOG_SAME;
  1952. }
  1953. static DialogAction
  1954. askSIRHostNext(Dialog *me)
  1955. {
  1956. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1957. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1958. return DIALOG_NEXT;
  1959. const char *buf = me->input();
  1960. const char *tmp;
  1961. if (buf[0] == 0)
  1962. {
  1963. tmp = me->defaultAns();
  1964. }
  1965. else
  1966. {
  1967. tmp = buf;
  1968. }
  1969. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_HOST, tmp);
  1970. if (!tmp || !isValid(tmp))
  1971. {
  1972. DialogManagerType::showAlert("Please enter a valid hostname");
  1973. return DIALOG_SAME;
  1974. }
  1975. return DIALOG_NEXT;
  1976. }
  1977. DialogInput askSIRPort(
  1978. "Please specify the port of the server to which the replicated entries\n"
  1979. "will be pushed.\n",
  1980. "Consumer port",
  1981. "389",
  1982. askSIRPortSetup,
  1983. askSIRPortNext
  1984. );
  1985. static DialogAction
  1986. askSIRPortSetup(Dialog *me)
  1987. {
  1988. DialogAction action = DIALOG_NEXT;
  1989. long actionval = 0;
  1990. me->getUserData(ACTION, actionval);
  1991. action = (DialogAction)actionval;
  1992. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  1993. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  1994. return action;
  1995. const char *defaultPort = "389";
  1996. if (getManager(me)->featureIsEnabled(SLAPD_KEY_SIR_SECURITY_ON))
  1997. defaultPort = "636";
  1998. if (dialogSetup(me, SLAPD_KEY_SIR_PORT, defaultPort) &&
  1999. getManager(me)->installMode() == Silent)
  2000. return DIALOG_ERROR;
  2001. long setupval = 0;
  2002. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2003. setupval == SETUP_ONLY)
  2004. return DIALOG_NEXT;
  2005. return DIALOG_SAME;
  2006. }
  2007. static DialogAction
  2008. askSIRPortNext(Dialog *me)
  2009. {
  2010. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2011. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2012. return DIALOG_NEXT;
  2013. const char *buf = me->input();
  2014. const char *tmp;
  2015. char testbuf[1024];
  2016. int port, err = 0;
  2017. if (buf[0] == 0)
  2018. {
  2019. tmp = me->defaultAns();
  2020. }
  2021. else
  2022. {
  2023. tmp = buf;
  2024. }
  2025. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_PORT, tmp);
  2026. port = atoi(tmp);
  2027. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  2028. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  2029. {
  2030. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  2031. "Please choose another port between 1 and %d.\n\n",
  2032. port, MAXPORT);
  2033. err = -1;
  2034. }
  2035. if (err)
  2036. {
  2037. DialogManagerType::showAlert(testbuf);
  2038. return DIALOG_SAME;
  2039. }
  2040. return DIALOG_NEXT;
  2041. }
  2042. DialogInput askSIRDN(
  2043. "Replication requires that this supplier has access to the portion of\n"
  2044. "the remote directory to be replicated. This requires a bind DN and\n"
  2045. "password for access to the consumer. You will first be asked for the\n"
  2046. "bind DN, then the password. This is the same as the Supplier DN on\n"
  2047. "the consumer.\n",
  2048. "Replication DN on the Consumer",
  2049. "cn=supplier",
  2050. askSIRDNSetup,
  2051. askSIRDNNext
  2052. );
  2053. static DialogAction
  2054. askSIRDNSetup(Dialog *me)
  2055. {
  2056. DialogAction action = DIALOG_NEXT;
  2057. long actionval = 0;
  2058. me->getUserData(ACTION, actionval);
  2059. action = (DialogAction)actionval;
  2060. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2061. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2062. return action;
  2063. if (dialogSetup(me, SLAPD_KEY_SIR_BINDDN, "cn=supplier") &&
  2064. getManager(me)->installMode() == Silent)
  2065. return DIALOG_ERROR;
  2066. long setupval = 0;
  2067. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2068. setupval == SETUP_ONLY)
  2069. return DIALOG_NEXT;
  2070. return DIALOG_SAME;
  2071. }
  2072. static DialogAction
  2073. askSIRDNNext(Dialog *me)
  2074. {
  2075. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2076. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2077. return DIALOG_NEXT;
  2078. const char *slapdUser;
  2079. char *slapdPwd = 0;
  2080. const char *buf;
  2081. buf = me->input();
  2082. if (buf[0] == 0)
  2083. {
  2084. slapdUser = me->defaultAns();
  2085. }
  2086. else
  2087. {
  2088. slapdUser = buf;
  2089. }
  2090. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_BINDDN, slapdUser);
  2091. // check to see if it is a valid dn
  2092. if (!isAValidDN(slapdUser))
  2093. {
  2094. DialogManagerType::showAlert("The Consumer Replication DN must be a valid DN");
  2095. return DIALOG_SAME;
  2096. }
  2097. else if (!isValid(slapdUser))
  2098. {
  2099. DialogManagerType::showAlert("Please enter a valid string.");
  2100. return DIALOG_SAME;
  2101. }
  2102. while (1)
  2103. {
  2104. me->showString("Password: ");
  2105. if (me->getPassword () == 0)
  2106. {
  2107. return DIALOG_PREV;
  2108. }
  2109. else
  2110. {
  2111. char *inp = strdup(me->input());
  2112. if (inp[0] == 0)
  2113. {
  2114. free(inp);
  2115. continue;
  2116. }
  2117. else
  2118. {
  2119. slapdPwd = inp;
  2120. break;
  2121. }
  2122. }
  2123. }
  2124. if (slapdPwd)
  2125. {
  2126. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_BINDDNPWD, slapdPwd);
  2127. free(slapdPwd);
  2128. }
  2129. return DIALOG_NEXT;
  2130. }
  2131. DialogInput askSIRSuffix(
  2132. "Please enter the full DN of the part of the tree to replicate,\n"
  2133. "including the suffix (e.g. ou=People, o=company.com).\n",
  2134. "Directory path (DN)",
  2135. NULL,
  2136. askSIRSuffixSetup,
  2137. askSIRSuffixNext
  2138. );
  2139. static DialogAction
  2140. askSIRSuffixSetup(Dialog *me)
  2141. {
  2142. DialogAction action = DIALOG_NEXT;
  2143. long actionval = 0;
  2144. me->getUserData(ACTION, actionval);
  2145. action = (DialogAction)actionval;
  2146. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2147. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2148. return action;
  2149. if (dialogSetup(me, SLAPD_KEY_SIR_SUFFIX, getManager(me)->getDefaultSuffix()) &&
  2150. getManager(me)->installMode() == Silent)
  2151. return DIALOG_ERROR;
  2152. long setupval = 0;
  2153. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2154. setupval == SETUP_ONLY)
  2155. return DIALOG_NEXT;
  2156. return DIALOG_SAME;
  2157. }
  2158. static DialogAction
  2159. askSIRSuffixNext(Dialog *me)
  2160. {
  2161. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2162. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2163. return DIALOG_NEXT;
  2164. const char *buf;
  2165. NSString val;
  2166. buf = me->input();
  2167. if (buf[0] == 0)
  2168. val = me->defaultAns();
  2169. else
  2170. val = buf;
  2171. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_SUFFIX, val);
  2172. // check to see if it is a valid dn
  2173. if (!isAValidDN(val))
  2174. {
  2175. DialogManagerType::showAlert("The suffix must be a valid DN");
  2176. return DIALOG_SAME;
  2177. }
  2178. else if (!isValid(val))
  2179. {
  2180. DialogManagerType::showAlert("Please enter a valid string.");
  2181. return DIALOG_SAME;
  2182. }
  2183. int status;
  2184. if ((status = getManager(me)->verifyRemoteLdap(
  2185. SLAPD_KEY_SIR_HOST,
  2186. SLAPD_KEY_SIR_PORT,
  2187. SLAPD_KEY_SIR_SUFFIX,
  2188. SLAPD_KEY_SIR_BINDDN,
  2189. SLAPD_KEY_SIR_BINDDNPWD
  2190. ))
  2191. )
  2192. {
  2193. ostrstream msg;
  2194. msg << "Could not connect to ldap://"
  2195. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_HOST)
  2196. << ":"
  2197. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_PORT)
  2198. << "/"
  2199. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_SUFFIX)
  2200. << endl << "for bind DN "
  2201. << getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_BINDDN)
  2202. << " status = " << status << endl
  2203. << "Please check your typing. If you have mis-typed, you can backup"
  2204. << endl
  2205. << "and retype. Otherwise, the remote server may be down at this time."
  2206. << endl
  2207. << "The replication agreement will be created anyway. Proceeding..."
  2208. << endl << ends;
  2209. DialogManagerType::showAlert(msg.str());
  2210. delete [] msg.str();
  2211. return DIALOG_NEXT;
  2212. }
  2213. return DIALOG_NEXT;
  2214. }
  2215. DialogYesNo askSIRSSL(
  2216. "You may use SSL authentication for replication if you have enabled it\n"
  2217. "on the remote server.\n",
  2218. "Do you want to use SSL?",
  2219. "No",
  2220. askSIRSSLSetup,
  2221. askSIRSSLNext
  2222. );
  2223. static DialogAction
  2224. askSIRSSLSetup(Dialog *me)
  2225. {
  2226. DialogAction action = DIALOG_NEXT;
  2227. long actionval = 0;
  2228. me->getUserData(ACTION, actionval);
  2229. action = (DialogAction)actionval;
  2230. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2231. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2232. return action;
  2233. long setupval = 0;
  2234. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2235. setupval == SETUP_ONLY)
  2236. return DIALOG_NEXT;
  2237. return DIALOG_SAME;
  2238. }
  2239. static DialogAction
  2240. askSIRSSLNext(Dialog *me)
  2241. {
  2242. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2243. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2244. return DIALOG_NEXT;
  2245. const char *buf = me->input();
  2246. if (!buf || !*buf)
  2247. {
  2248. buf = me->defaultAns();
  2249. if (!buf || !*buf)
  2250. buf = "No";
  2251. }
  2252. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_SECURITY_ON, buf);
  2253. if (!isValidYesNo(buf))
  2254. return DIALOG_SAME;
  2255. return DIALOG_NEXT;
  2256. }
  2257. DialogInput askCIRDays(
  2258. "Please enter the days of the week on which you would like replication\n"
  2259. "to occur. The days are specified by a number. For example, use 0 for\n"
  2260. "Sunday, 1 for Monday, etc. Use 6 for Saturday. You may not specify a\n"
  2261. "number greater than 6 or less than 0. The numbers should be entered\n"
  2262. "one after another in a list. For example, 0123 would be Sunday,\n"
  2263. "Monday, Tuesday, and Wednesday. 06 would be Sunday and Saturday. The\n"
  2264. "default is everyday.\n",
  2265. "Enter the replication days",
  2266. "all",
  2267. askCIRDaysSetup,
  2268. askCIRDaysNext
  2269. );
  2270. static DialogAction
  2271. askCIRDaysSetup(Dialog *me)
  2272. {
  2273. DialogAction action = DIALOG_NEXT;
  2274. long actionval = 0;
  2275. me->getUserData(ACTION, actionval);
  2276. action = (DialogAction)actionval;
  2277. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2278. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2279. return action;
  2280. if (dialogSetup(me, SLAPD_KEY_CIR_DAYS, "all") &&
  2281. getManager(me)->installMode() == Silent)
  2282. return DIALOG_ERROR;
  2283. const char *tmp;
  2284. if ((tmp = getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_DAYS)) &&
  2285. !*tmp)
  2286. me->setDefaultAns("all");
  2287. long setupval = 0;
  2288. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2289. setupval == SETUP_ONLY)
  2290. return DIALOG_NEXT;
  2291. return DIALOG_SAME;
  2292. }
  2293. static DialogAction
  2294. askCIRDaysNext(Dialog *me)
  2295. {
  2296. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2297. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2298. return DIALOG_NEXT;
  2299. const char *buf;
  2300. NSString val;
  2301. buf = me->input();
  2302. if (buf[0] == 0)
  2303. val = me->defaultAns();
  2304. else
  2305. val = buf;
  2306. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_DAYS, val);
  2307. int status = 0;
  2308. ostrstream msg;
  2309. char realval[8] = "-------";
  2310. if (!strncasecmp(val, "all", strlen(val)))
  2311. strcpy(realval, ""); // default is everyday
  2312. else
  2313. {
  2314. for (const char *ptr = val; *ptr; ++ptr)
  2315. {
  2316. if (!isdigit(*ptr))
  2317. {
  2318. msg << "The string [" << val << "] contains non-digit characters."
  2319. << " Please re enter the string." << ends;
  2320. status = 1;
  2321. break;
  2322. }
  2323. int ival = (int)(*ptr) - (int)'0';
  2324. if (ival > 6)
  2325. {
  2326. msg << "The string contains an invalid value [" << ival << "]."
  2327. << " Please re enter the string." << ends;
  2328. status = 2;
  2329. break;
  2330. }
  2331. // this step makes sure we get the numbers in order with no duplicates
  2332. realval[ival] = *ptr;
  2333. }
  2334. if (status)
  2335. {
  2336. DialogManagerType::showAlert(msg.str());
  2337. delete [] msg.str();
  2338. return DIALOG_SAME;
  2339. }
  2340. // realval now contains a string like
  2341. // 0---4-6, but we really want 046
  2342. int index = 0;
  2343. for (char *p2 = realval; *p2; ++p2)
  2344. {
  2345. if (*p2 != '-')
  2346. realval[index++] = *p2;
  2347. }
  2348. realval[index] = 0;
  2349. }
  2350. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_DAYS, realval);
  2351. return DIALOG_NEXT;
  2352. }
  2353. DialogInput askSIRDays(
  2354. "Please enter the days of the week on which you would like replication\n"
  2355. "to occur. The days are specified by a number. For example, use 0 for\n"
  2356. "Sunday, 1 for Monday, etc. Use 6 for Saturday. You may not specify a\n"
  2357. "number greater than 6 or less than 0. The numbers should be entered\n"
  2358. "one after another in a list. For example, 0123 would be Sunday,\n"
  2359. "Monday, Tuesday, and Wednesday. 06 would be Sunday and Saturday. The\n"
  2360. "default is everyday.\n",
  2361. "Enter the replication days",
  2362. "all",
  2363. askSIRDaysSetup,
  2364. askSIRDaysNext
  2365. );
  2366. static DialogAction
  2367. askSIRDaysSetup(Dialog *me)
  2368. {
  2369. DialogAction action = DIALOG_NEXT;
  2370. long actionval = 0;
  2371. me->getUserData(ACTION, actionval);
  2372. action = (DialogAction)actionval;
  2373. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2374. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2375. return action;
  2376. if (dialogSetup(me, SLAPD_KEY_SIR_DAYS, "all") &&
  2377. getManager(me)->installMode() == Silent)
  2378. return DIALOG_ERROR;
  2379. const char *tmp;
  2380. if ((tmp = getManager(me)->getDefaultScript()->get(SLAPD_KEY_SIR_DAYS)) &&
  2381. !*tmp)
  2382. me->setDefaultAns("all");
  2383. long setupval = 0;
  2384. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2385. setupval == SETUP_ONLY)
  2386. return DIALOG_NEXT;
  2387. return DIALOG_SAME;
  2388. }
  2389. static DialogAction
  2390. askSIRDaysNext(Dialog *me)
  2391. {
  2392. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2393. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2394. return DIALOG_NEXT;
  2395. const char *buf;
  2396. NSString val;
  2397. buf = me->input();
  2398. if (buf[0] == 0)
  2399. val = me->defaultAns();
  2400. else
  2401. val = buf;
  2402. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_DAYS, val);
  2403. int status = 0;
  2404. ostrstream msg;
  2405. char realval[8] = "-------";
  2406. if (!strncasecmp(val, "all", strlen(val)))
  2407. strcpy(realval, ""); // default is everyday
  2408. else
  2409. {
  2410. for (const char *ptr = val; *ptr; ++ptr)
  2411. {
  2412. if (!isdigit(*ptr))
  2413. {
  2414. msg << "The string [" << val << "] contains non-digit characters."
  2415. << " Please re enter the string." << ends;
  2416. status = 1;
  2417. break;
  2418. }
  2419. int ival = (int)(*ptr) - (int)'0';
  2420. if (ival > 6)
  2421. {
  2422. msg << "The string contains an invalid value [" << ival << "]."
  2423. << " Please re enter the string." << ends;
  2424. status = 2;
  2425. break;
  2426. }
  2427. // this step makes sure we get the numbers in order with no duplicates
  2428. realval[ival] = *ptr;
  2429. }
  2430. if (status)
  2431. {
  2432. DialogManagerType::showAlert(msg.str());
  2433. delete [] msg.str();
  2434. return DIALOG_SAME;
  2435. }
  2436. // realval now contains a string like
  2437. // 0---4-6, but we really want 046
  2438. int index = 0;
  2439. for (char *p2 = realval; *p2; ++p2)
  2440. {
  2441. if (*p2 != '-')
  2442. realval[index++] = *p2;
  2443. }
  2444. realval[index] = 0;
  2445. }
  2446. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_DAYS, realval);
  2447. return DIALOG_NEXT;
  2448. }
  2449. DialogInput askCIRTimes(
  2450. "Please enter the time of day you would like replication to occur. The\n"
  2451. "time is specified as a range in the form HHMM-HHMM in 24 hour time.\n"
  2452. "HH represents the hour portion of the time, and MM the minutes.\n"
  2453. "Numbers less than 10 should be preceeded by a 0. For example, to\n"
  2454. "enable replication between 1 am and 4:30 am, specify 0100-0430. To\n"
  2455. "specify 11 am to 9 pm, use 1100-2100. 12 am to 12:59 am is specified\n"
  2456. "as 0000-0059. The default is all day.\n",
  2457. "Enter the replication times",
  2458. "all day",
  2459. askCIRTimesSetup,
  2460. askCIRTimesNext
  2461. );
  2462. static DialogAction
  2463. askCIRTimesSetup(Dialog *me)
  2464. {
  2465. DialogAction action = DIALOG_NEXT;
  2466. long actionval = 0;
  2467. me->getUserData(ACTION, actionval);
  2468. action = (DialogAction)actionval;
  2469. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2470. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2471. return action;
  2472. if (dialogSetup(me, SLAPD_KEY_CIR_TIMES, "all day") &&
  2473. getManager(me)->installMode() == Silent)
  2474. return DIALOG_ERROR;
  2475. long setupval = 0;
  2476. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2477. setupval == SETUP_ONLY)
  2478. return DIALOG_NEXT;
  2479. return DIALOG_SAME;
  2480. }
  2481. static DialogAction
  2482. askCIRTimesNext(Dialog *me)
  2483. {
  2484. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_CONSUMER) ||
  2485. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_CONSUMER), "2"))
  2486. return DIALOG_NEXT;
  2487. const char *buf;
  2488. NSString val;
  2489. buf = me->input();
  2490. if (buf[0] == 0)
  2491. val = me->defaultAns();
  2492. else
  2493. val = buf;
  2494. if (!strncasecmp(val, "all day", strlen(val)))
  2495. {
  2496. val = "";
  2497. getManager(me)->getDefaultScript()->set(SLAPD_KEY_CIR_TIMES, val);
  2498. return DIALOG_NEXT;
  2499. }
  2500. int status = 0;
  2501. ostrstream msg;
  2502. int pos = 0;
  2503. // format should be HHMM-HHMM
  2504. int maxvals[9] = {0, 23, 0, 59, 0, 0, 23, 0, 59};
  2505. char teststr[3]; // 2 digits plus \0
  2506. int testindex = 0;
  2507. for (const char *ptr = val; *ptr; ++ptr, ++pos)
  2508. {
  2509. // position 4 should contain the '-'
  2510. if (pos == 4 && *ptr != '-')
  2511. {
  2512. msg << "The time specification [" << val << "] is invalid.\n"
  2513. << "Please re enter the string." << ends;
  2514. status = 1;
  2515. break;
  2516. }
  2517. else if (pos == 4)
  2518. continue;
  2519. if (!isdigit(*ptr) && pos != 4)
  2520. {
  2521. msg << "The time specification [" << val << "] contains non-digit characters.\n"
  2522. << "Please re enter the string." << ends;
  2523. status = 2;
  2524. break;
  2525. }
  2526. teststr[testindex++] = *ptr;
  2527. if (pos == 1 || pos == 3 || pos == 6 || pos == 8)
  2528. {
  2529. teststr[testindex] = 0;
  2530. testindex = 0;
  2531. if (teststr[0] == '0')
  2532. teststr[0] = ' ';
  2533. int ival = atoi(teststr);
  2534. if (ival > maxvals[pos])
  2535. {
  2536. msg << "The string contains an invalid value [" << ival << "].\n"
  2537. << "Please re enter the string." << ends;
  2538. status = 3;
  2539. break;
  2540. }
  2541. }
  2542. }
  2543. if (pos != 9)
  2544. {
  2545. msg << "The string [" << val << "] is invalid.\n"
  2546. << "Please re enter the string." << ends;
  2547. status = 4;
  2548. }
  2549. if (status)
  2550. {
  2551. DialogManagerType::showAlert(msg.str());
  2552. delete [] msg.str();
  2553. return DIALOG_SAME;
  2554. }
  2555. return DIALOG_NEXT;
  2556. }
  2557. DialogInput askSIRTimes(
  2558. "Please enter the time of day you would like replication to occur. The\n"
  2559. "time is specified as a range in the form HHMM-HHMM in 24 hour time.\n"
  2560. "HH represents the hour portion of the time, and MM the minutes.\n"
  2561. "Numbers less than 10 should be preceeded by a 0. For example, to\n"
  2562. "enable replication between 1 am and 4:30 am, specify 0100-0430. To\n"
  2563. "specify 11 am to 9 pm, use 1100-2100. 12 am to 12:59 am is specified\n"
  2564. "as 0000-0059. The default is all day.\n",
  2565. "Enter the replication times",
  2566. "all day",
  2567. askSIRTimesSetup,
  2568. askSIRTimesNext
  2569. );
  2570. static DialogAction
  2571. askSIRTimesSetup(Dialog *me)
  2572. {
  2573. DialogAction action = DIALOG_NEXT;
  2574. long actionval = 0;
  2575. me->getUserData(ACTION, actionval);
  2576. action = (DialogAction)actionval;
  2577. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2578. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2579. return action;
  2580. if (dialogSetup(me, SLAPD_KEY_SIR_TIMES, "all day") &&
  2581. getManager(me)->installMode() == Silent)
  2582. return DIALOG_ERROR;
  2583. long setupval = 0;
  2584. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2585. setupval == SETUP_ONLY)
  2586. return DIALOG_NEXT;
  2587. return DIALOG_SAME;
  2588. }
  2589. static DialogAction
  2590. askSIRTimesNext(Dialog *me)
  2591. {
  2592. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_SETUP_SUPPLIER) ||
  2593. strcmp(getManager(me)->getDefaultScript()->get(SLAPD_KEY_SETUP_SUPPLIER), "1"))
  2594. return DIALOG_NEXT;
  2595. const char *buf;
  2596. NSString val;
  2597. buf = me->input();
  2598. if (buf[0] == 0)
  2599. val = me->defaultAns();
  2600. else
  2601. val = buf;
  2602. if (!strncasecmp(val, "all day", strlen(val)))
  2603. {
  2604. val = "";
  2605. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SIR_TIMES, val);
  2606. return DIALOG_NEXT;
  2607. }
  2608. int status = 0;
  2609. ostrstream msg;
  2610. int pos = 0;
  2611. // format should be HHMM-HHMM
  2612. int maxvals[9] = {0, 23, 0, 59, 0, 0, 23, 0, 59};
  2613. char teststr[3]; // 2 digits plus \0
  2614. int testindex = 0;
  2615. for (const char *ptr = val; *ptr; ++ptr, ++pos)
  2616. {
  2617. // position 4 should contain the '-'
  2618. if (pos == 4 && *ptr != '-')
  2619. {
  2620. msg << "The time specification [" << val << "] is invalid.\n"
  2621. << "Please re enter the string." << ends;
  2622. status = 1;
  2623. break;
  2624. }
  2625. else if (pos == 4)
  2626. continue;
  2627. if (!isdigit(*ptr) && pos != 4)
  2628. {
  2629. msg << "The time specification [" << val << "] contains non-digit characters.\n"
  2630. << "Please re enter the string." << ends;
  2631. status = 2;
  2632. break;
  2633. }
  2634. teststr[testindex++] = *ptr;
  2635. if (pos == 1 || pos == 3 || pos == 6 || pos == 8)
  2636. {
  2637. teststr[testindex] = 0;
  2638. testindex = 0;
  2639. if (teststr[0] == '0')
  2640. teststr[0] = ' ';
  2641. int ival = atoi(teststr);
  2642. if (ival > maxvals[pos])
  2643. {
  2644. msg << "The string contains an invalid value [" << ival << "].\n"
  2645. << "Please re enter the string." << ends;
  2646. status = 3;
  2647. break;
  2648. }
  2649. }
  2650. }
  2651. if (pos != 9)
  2652. {
  2653. msg << "The string [" << val << "] is invalid.\n"
  2654. << "Please re enter the string." << ends;
  2655. status = 4;
  2656. }
  2657. if (status)
  2658. {
  2659. DialogManagerType::showAlert(msg.str());
  2660. delete [] msg.str();
  2661. return DIALOG_SAME;
  2662. }
  2663. return DIALOG_NEXT;
  2664. }
  2665. DialogYesNo askUseExistingMC(
  2666. "Fedora server information is stored in the Fedora configuration\n"
  2667. "directory server, which you may have already set up. If so, you\n"
  2668. "should configure this server to be managed by the configuration\n"
  2669. "server. To do so, the following information about the configuration\n"
  2670. "server is required: the fully qualified host name of the form\n"
  2671. "<hostname>.<domainname>(e.g. hostname.domain.com), the port number,\n"
  2672. "the suffix, and the DN and password of a user having permission to\n"
  2673. "write the configuration information, usually the Fedora\n"
  2674. "configuration directory administrator.\n\n"
  2675. "If you want to install this software as a standalone server, or if you\n"
  2676. "want this instance to serve as your Fedora configuration directory\n"
  2677. "server, press Enter.\n",
  2678. "Do you want to register this software with an existing\n"
  2679. "Fedora configuration directory server?",
  2680. "No",
  2681. askUseExistingMCSetup,
  2682. askUseExistingMCNext
  2683. );
  2684. static DialogAction
  2685. askUseExistingMCSetup(Dialog *me)
  2686. {
  2687. #if DEBUG > 1
  2688. cerr << "Entering askUseExistingMCSetup" << endl;
  2689. #endif
  2690. DialogAction action = DIALOG_NEXT;
  2691. long actionval = 0;
  2692. me->getUserData(ACTION, actionval);
  2693. action = (DialogAction)actionval;
  2694. if (action != DIALOG_PREV)
  2695. {
  2696. if (getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL))
  2697. {
  2698. // tell the instance creator not to create the Config entries
  2699. // new instance
  2700. getManager(me)->getDefaultScript()->set(
  2701. SLAPD_KEY_USE_EXISTING_MC, "Yes");
  2702. getManager(me)->getDefaultScript()->set(
  2703. SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "No");
  2704. }
  2705. else
  2706. {
  2707. getManager(me)->getDefaultScript()->set(
  2708. SLAPD_KEY_USE_EXISTING_MC, "No");
  2709. getManager(me)->getDefaultScript()->set(
  2710. SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "Yes");
  2711. }
  2712. }
  2713. dialogSetup(me, SLAPD_KEY_USE_EXISTING_MC, "No");
  2714. long setupval = 0;
  2715. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2716. setupval == SETUP_ONLY)
  2717. {
  2718. #if DEBUG > 1
  2719. cerr << "Leaving askUseExistingMCSetup DIALOG_NEXT" << endl;
  2720. #endif
  2721. return DIALOG_NEXT;
  2722. }
  2723. #if DEBUG > 1
  2724. cerr << "Leaving askUseExistingMCSetup DIALOG_SAME" << endl;
  2725. #endif
  2726. return DIALOG_SAME;
  2727. }
  2728. static DialogAction
  2729. askUseExistingMCNext(Dialog *me)
  2730. {
  2731. #if DEBUG > 1
  2732. cerr << "Entering askUseExistingMCNext" << endl;
  2733. #endif
  2734. const char *buf = me->input();
  2735. if (!buf || !*buf)
  2736. {
  2737. buf = me->defaultAns();
  2738. if (!buf || !*buf)
  2739. buf = "No";
  2740. }
  2741. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_EXISTING_MC, buf);
  2742. if (!isValidYesNo(buf))
  2743. return DIALOG_SAME;
  2744. #if DEBUG > 1
  2745. cerr << "Leaving askUseExistingMCNext" << endl;
  2746. #endif
  2747. return DIALOG_NEXT;
  2748. }
  2749. DialogInput askMCHost(
  2750. "Enter the fully qualified domain name of the Fedora configuration\n"
  2751. "directory server host in the form <hostname>.<domainname>\n"
  2752. "(e.g. hostname.domain.com).\n",
  2753. "Fedora configuration directory server\nhost name",
  2754. 0,
  2755. askMCHostSetup,
  2756. askMCHostNext
  2757. );
  2758. static DialogAction
  2759. askMCHostSetup(Dialog *me)
  2760. {
  2761. DialogAction action = DIALOG_NEXT;
  2762. long actionval = 0;
  2763. me->getUserData(ACTION, actionval);
  2764. action = (DialogAction)actionval;
  2765. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2766. return action;
  2767. long setupval = 0;
  2768. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2769. setupval == SETUP_ONLY)
  2770. return DIALOG_NEXT;
  2771. return DIALOG_SAME;
  2772. }
  2773. static DialogAction
  2774. askMCHostNext(Dialog *me)
  2775. {
  2776. long setupval = 0;
  2777. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2778. setupval == SETUP_ONLY)
  2779. return DIALOG_NEXT;
  2780. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2781. return DIALOG_NEXT;
  2782. const char *buf = me->input();
  2783. const char *tmp;
  2784. if (buf[0] == 0)
  2785. {
  2786. tmp = me->defaultAns();
  2787. }
  2788. else
  2789. {
  2790. tmp = buf;
  2791. }
  2792. getManager(me)->getBaseScript()->set(SLAPD_KEY_K_LDAP_HOST, tmp);
  2793. if (!tmp || !isValid(tmp))
  2794. {
  2795. DialogManagerType::showAlert("Please enter a valid hostname");
  2796. return DIALOG_SAME;
  2797. }
  2798. return DIALOG_NEXT;
  2799. }
  2800. DialogInput askMCPort(
  2801. "Please specify the port number on which the Fedora configuration\n"
  2802. "directory server listens.\n",
  2803. "Fedora configuration directory server\nport number",
  2804. "389",
  2805. askMCPortSetup,
  2806. askMCPortNext
  2807. );
  2808. static DialogAction
  2809. askMCPortSetup(Dialog *me)
  2810. {
  2811. DialogAction action = DIALOG_NEXT;
  2812. long actionval = 0;
  2813. me->getUserData(ACTION, actionval);
  2814. action = (DialogAction)actionval;
  2815. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2816. return action;
  2817. long setupval = 0;
  2818. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2819. setupval == SETUP_ONLY)
  2820. return DIALOG_NEXT;
  2821. return DIALOG_SAME;
  2822. }
  2823. static DialogAction
  2824. askMCPortNext(Dialog *me)
  2825. {
  2826. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2827. return DIALOG_NEXT;
  2828. const char *buf = me->input();
  2829. const char *tmp;
  2830. char testbuf[1024];
  2831. int port, err = 0;
  2832. if (buf[0] == 0)
  2833. {
  2834. tmp = me->defaultAns();
  2835. }
  2836. else
  2837. {
  2838. tmp = buf;
  2839. }
  2840. getManager(me)->getBaseScript()->set(SLAPD_KEY_K_LDAP_PORT, tmp);
  2841. port = atoi(tmp);
  2842. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  2843. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  2844. {
  2845. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  2846. "Please choose another port between 1 and %d.\n\n",
  2847. port, MAXPORT);
  2848. err = -1;
  2849. }
  2850. if (err)
  2851. {
  2852. DialogManagerType::showAlert(testbuf);
  2853. return DIALOG_SAME;
  2854. }
  2855. return DIALOG_NEXT;
  2856. }
  2857. DialogInput askMCDN(
  2858. "To write configuration information into the Fedora configuration\n"
  2859. "directory, you must bind to the server as an entity with the\n"
  2860. "appropriate permissions. Usually, the Fedora configuration\n"
  2861. "directory administrator is used for this purpose, although you can\n"
  2862. "give other directory accounts the proper access.\n",
  2863. "Fedora configuration directory server\nadministrator ID",
  2864. 0,
  2865. askMCDNSetup,
  2866. askMCDNNext
  2867. );
  2868. static DialogAction
  2869. askMCDNSetup(Dialog *me)
  2870. {
  2871. DialogAction action = DIALOG_NEXT;
  2872. long actionval = 0;
  2873. me->getUserData(ACTION, actionval);
  2874. action = (DialogAction)actionval;
  2875. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2876. return action;
  2877. dialogSetup(me, SLAPD_KEY_SERVER_ADMIN_ID, "admin");
  2878. long setupval = 0;
  2879. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2880. setupval == SETUP_ONLY)
  2881. return DIALOG_NEXT;
  2882. return DIALOG_SAME;
  2883. }
  2884. static DialogAction
  2885. askMCDNNext(Dialog *me)
  2886. {
  2887. long setupval = 0;
  2888. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  2889. setupval == SETUP_ONLY)
  2890. return DIALOG_NEXT;
  2891. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  2892. return DIALOG_NEXT;
  2893. const char *slapdUser;
  2894. char *slapdPwd = 0;
  2895. const char *buf;
  2896. buf = me->input();
  2897. if (buf[0] == 0)
  2898. {
  2899. slapdUser = me->defaultAns();
  2900. }
  2901. else
  2902. {
  2903. slapdUser = buf;
  2904. }
  2905. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_ID, slapdUser);
  2906. if (!isValid(slapdUser))
  2907. {
  2908. DialogManagerType::showAlert("Please enter a valid string.");
  2909. return DIALOG_SAME;
  2910. }
  2911. while (1)
  2912. {
  2913. me->showString("Password: ");
  2914. if (me->getPassword () == 0)
  2915. {
  2916. return DIALOG_PREV;
  2917. }
  2918. else
  2919. {
  2920. char *inp = strdup(me->input());
  2921. if (inp[0] == 0)
  2922. {
  2923. free(inp);
  2924. continue;
  2925. }
  2926. else
  2927. {
  2928. slapdPwd = inp;
  2929. break;
  2930. }
  2931. }
  2932. }
  2933. if (slapdPwd)
  2934. {
  2935. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_PWD, slapdPwd);
  2936. free(slapdPwd);
  2937. int status;
  2938. if ((status = getManager(me)->verifyRemoteLdap(
  2939. SLAPD_KEY_K_LDAP_HOST,
  2940. SLAPD_KEY_K_LDAP_PORT,
  2941. SLAPD_KEY_BASE_SUFFIX,
  2942. SLAPD_KEY_SERVER_ADMIN_ID,
  2943. SLAPD_KEY_SERVER_ADMIN_PWD
  2944. ))
  2945. )
  2946. {
  2947. ostrstream msg;
  2948. msg << "Could not connect to ldap://"
  2949. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  2950. << ":"
  2951. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  2952. << "/"
  2953. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  2954. << endl << "for bind DN "
  2955. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  2956. << " status = " << status << endl
  2957. << "Please check your typing. If you have mis-typed, you can backup"
  2958. << endl
  2959. << "and retype. Otherwise, the remote server may be down at this time."
  2960. << endl
  2961. << "The installation cannot proceed."
  2962. << endl << ends;
  2963. DialogManagerType::showAlert(msg.str());
  2964. delete [] msg.str();
  2965. return DIALOG_SAME;
  2966. }
  2967. else if ((getManager(me)->installType() < Custom) &&
  2968. (status = getManager(me)->verifyAdminDomain(
  2969. SLAPD_KEY_K_LDAP_HOST,
  2970. SLAPD_KEY_K_LDAP_PORT,
  2971. SLAPD_KEY_BASE_SUFFIX,
  2972. SLAPD_KEY_ADMIN_DOMAIN,
  2973. SLAPD_KEY_SERVER_ADMIN_ID,
  2974. SLAPD_KEY_SERVER_ADMIN_PWD
  2975. ))
  2976. )
  2977. {
  2978. ostrstream msg;
  2979. msg << "Could not find the Admin Domain "
  2980. << getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)
  2981. << " in the server" << endl << "ldap://"
  2982. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  2983. << ":"
  2984. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  2985. << "/"
  2986. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  2987. << endl << "for bind DN "
  2988. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  2989. << " status = " << status << endl
  2990. << "You may need to re-run setup in Custom mode in order to specify"
  2991. << endl
  2992. << "the correct Admin Domain."
  2993. << endl
  2994. << "The installation cannot proceed."
  2995. << endl << ends;
  2996. DialogManagerType::showAlert(msg.str());
  2997. delete [] msg.str();
  2998. return DIALOG_SAME;
  2999. }
  3000. }
  3001. // tell the instance creator not to create the config entries in the
  3002. // new instance
  3003. getManager(me)->getDefaultScript()->set(SLAPD_KEY_SLAPD_CONFIG_FOR_MC, "No");
  3004. return DIALOG_NEXT;
  3005. }
  3006. DialogYesNo askDisableSchemaChecking(
  3007. "If you are going to import an old database immediately after or during\n"
  3008. "installation, and you think you may have problems with your old\n"
  3009. "schema, you may want to turn off schema checking until after the\n"
  3010. "import. If you choose to do this, schema checking will remain off\n"
  3011. "until you manually turn it back on. Fedora recommends that you turn\n"
  3012. "it back on as soon as possible.\n",
  3013. "Do you want to disable schema checking?",
  3014. "No",
  3015. askDisableSchemaCheckingSetup,
  3016. askDisableSchemaCheckingNext
  3017. );
  3018. static DialogAction
  3019. askDisableSchemaCheckingSetup(Dialog *me)
  3020. {
  3021. me = me;
  3022. long setupval = 0;
  3023. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3024. setupval == SETUP_ONLY)
  3025. return DIALOG_NEXT;
  3026. return DIALOG_SAME;
  3027. }
  3028. static DialogAction
  3029. askDisableSchemaCheckingNext(Dialog *me)
  3030. {
  3031. const char *buf = me->input();
  3032. if (!buf || !*buf)
  3033. {
  3034. buf = me->defaultAns();
  3035. if (!buf || !*buf)
  3036. buf = "No";
  3037. }
  3038. getManager(me)->getDefaultScript()->set(SLAPD_KEY_DISABLE_SCHEMA_CHECKING, buf);
  3039. if (!isValidYesNo(buf))
  3040. return DIALOG_SAME;
  3041. return DIALOG_NEXT;
  3042. }
  3043. DialogInput askMCAdminDomain(
  3044. "The Administration Domain is a part of the configuration directory\n"
  3045. "server used to store information about Fedora software. If you are\n"
  3046. "managing multiple software releases at the same time, or managing\n"
  3047. "information about multiple domains, you may use the Administration\n"
  3048. "Domain to keep them separate.\n\n"
  3049. "If you are not using administrative domains, press Enter to select the\n"
  3050. "default. Otherwise, enter some descriptive, unique name for the\n"
  3051. "administration domain, such as the name of the organization responsible\n"
  3052. "for managing the domain.\n",
  3053. "Administration Domain",
  3054. NULL,
  3055. askMCAdminDomainSetup,
  3056. askMCAdminDomainNext
  3057. );
  3058. static DialogAction
  3059. askMCAdminDomainSetup(Dialog *me)
  3060. {
  3061. if (!getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)) {
  3062. getManager(me)->getBaseScript()->set(
  3063. SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3064. }
  3065. DialogAction action = DIALOG_NEXT;
  3066. long actionval = 0;
  3067. me->getUserData(ACTION, actionval);
  3068. action = (DialogAction)actionval;
  3069. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3070. {
  3071. #if DEBUG > 1
  3072. cerr << "leaving askMCAdminDomainSetup " << action << endl;
  3073. #endif
  3074. return action;
  3075. }
  3076. // if we are creating the Configuration server, the admin domain will not
  3077. // yet exist, and we need to ask the user to create one. Otherwise, we are
  3078. // installing into an existing one
  3079. dialogSetup(me, SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3080. long setupval = 0;
  3081. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3082. setupval == SETUP_ONLY)
  3083. return DIALOG_NEXT;
  3084. return DIALOG_SAME;
  3085. }
  3086. static DialogAction
  3087. askMCAdminDomainNext(Dialog *me)
  3088. {
  3089. long setupval = 0;
  3090. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3091. setupval == SETUP_ONLY)
  3092. return DIALOG_NEXT;
  3093. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3094. return DIALOG_NEXT;
  3095. const char *buf;
  3096. int status = 0;
  3097. NSString val;
  3098. buf = me->input();
  3099. if (buf[0] == 0)
  3100. val = me->defaultAns();
  3101. else
  3102. val = buf;
  3103. getManager(me)->getBaseScript()->set(SLAPD_KEY_ADMIN_DOMAIN, val);
  3104. if (!isValid(val))
  3105. {
  3106. DialogManagerType::showAlert("Please enter a valid string.");
  3107. return DIALOG_SAME;
  3108. }
  3109. else if (isAValidDN(val))
  3110. {
  3111. DialogManagerType::showAlert("A DN is not allowed here. Please enter a valid string.");
  3112. return DIALOG_SAME;
  3113. }
  3114. else if ((status = getManager(me)->verifyAdminDomain(
  3115. SLAPD_KEY_K_LDAP_HOST,
  3116. SLAPD_KEY_K_LDAP_PORT,
  3117. SLAPD_KEY_BASE_SUFFIX,
  3118. SLAPD_KEY_ADMIN_DOMAIN,
  3119. SLAPD_KEY_SERVER_ADMIN_ID,
  3120. SLAPD_KEY_SERVER_ADMIN_PWD
  3121. ))
  3122. )
  3123. {
  3124. ostrstream msg;
  3125. msg << "Could not find the Admin Domain "
  3126. << getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)
  3127. << " in the server" << endl << "ldap://"
  3128. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_HOST)
  3129. << ":"
  3130. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_PORT)
  3131. << "/"
  3132. << getManager(me)->getBaseScript()->get(SLAPD_KEY_BASE_SUFFIX)
  3133. << endl << "for bind DN "
  3134. << getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID)
  3135. << " status = " << status << endl
  3136. << "Please check your typing. If you have mis-typed, you can backup"
  3137. << endl
  3138. << "and retype. Otherwise, the remote server may be down at this time."
  3139. << endl
  3140. << "The installation cannot proceed."
  3141. << endl << ends;
  3142. DialogManagerType::showAlert(msg.str());
  3143. delete [] msg.str();
  3144. return DIALOG_SAME;
  3145. }
  3146. return DIALOG_NEXT;
  3147. }
  3148. DialogInput askAdminDomain(
  3149. "The Administration Domain is a part of the configuration directory\n"
  3150. "server used to store information about Fedora software. If you are\n"
  3151. "managing multiple software releases at the same time, or managing\n"
  3152. "information about multiple domains, you may use the Administration\n"
  3153. "Domain to keep them separate.\n\n"
  3154. "If you are not using administrative domains, press Enter to select the\n"
  3155. "default. Otherwise, enter some descriptive, unique name for the\n"
  3156. "administration domain, such as the name of the organization responsible\n"
  3157. "for managing the domain.\n",
  3158. "Administration Domain",
  3159. NULL,
  3160. askAdminDomainSetup,
  3161. askAdminDomainNext
  3162. );
  3163. static DialogAction
  3164. askAdminDomainSetup(Dialog *me)
  3165. {
  3166. if (!getManager(me)->getBaseScript()->get(SLAPD_KEY_ADMIN_DOMAIN)) {
  3167. getManager(me)->getBaseScript()->set(
  3168. SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3169. }
  3170. DialogAction action = DIALOG_NEXT;
  3171. long actionval = 0;
  3172. me->getUserData(ACTION, actionval);
  3173. action = (DialogAction)actionval;
  3174. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3175. return action;
  3176. // if we are creating the Configuration server, the admin domain will not
  3177. // yet exist, and we need to ask the user to create one. Otherwise, we are
  3178. // installing into an existing one
  3179. dialogSetup(me, SLAPD_KEY_ADMIN_DOMAIN, getManager(me)->getDNSDomain());
  3180. long setupval = 0;
  3181. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3182. setupval == SETUP_ONLY)
  3183. return DIALOG_NEXT;
  3184. return DIALOG_SAME;
  3185. }
  3186. static DialogAction
  3187. askAdminDomainNext(Dialog *me)
  3188. {
  3189. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3190. return DIALOG_NEXT;
  3191. const char *buf;
  3192. NSString val;
  3193. buf = me->input();
  3194. if (buf[0] == 0)
  3195. val = me->defaultAns();
  3196. else
  3197. val = buf;
  3198. getManager(me)->getBaseScript()->set(SLAPD_KEY_ADMIN_DOMAIN, val);
  3199. if (!isValid(val))
  3200. {
  3201. DialogManagerType::showAlert("Please enter a valid string.");
  3202. return DIALOG_SAME;
  3203. }
  3204. if (isAValidDN(val))
  3205. {
  3206. DialogManagerType::showAlert("A DN is not allowed here. Please enter a valid string.");
  3207. return DIALOG_SAME;
  3208. }
  3209. return DIALOG_NEXT;
  3210. }
  3211. DialogYesNo askUseExistingUG(
  3212. "If you already have a directory server you want to use to store your\n"
  3213. "data, such as user and group information, answer Yes to the following\n"
  3214. "question. You will be prompted for the host, port, suffix, and bind\n"
  3215. "DN to use for that directory server.\n\n"
  3216. "If you want this directory server to store your data, answer No.\n",
  3217. "Do you want to use another directory to store your data?",
  3218. "No",
  3219. askUseExistingUGSetup,
  3220. askUseExistingUGNext
  3221. );
  3222. static DialogAction
  3223. askUseExistingUGSetup(Dialog *me)
  3224. {
  3225. #if DEBUG > 1
  3226. cerr << "Entering askUseExistingUGSetup" << endl;
  3227. #endif
  3228. DialogAction action = DIALOG_NEXT;
  3229. long actionval = 0;
  3230. me->getUserData(ACTION, actionval);
  3231. action = (DialogAction)actionval;
  3232. // if this server is not an MC host, it must be a UG host
  3233. if (getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_MC))
  3234. {
  3235. getManager(me)->getDefaultScript()->set(
  3236. SLAPD_KEY_USE_EXISTING_UG, "No");
  3237. #if DEBUG > 1
  3238. cerr << "Leaving askUseExistingUGSetup DIALOG_NEXT" << endl;
  3239. #endif
  3240. return action;
  3241. }
  3242. else if (getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_LDAP_URL))
  3243. {
  3244. getManager(me)->getDefaultScript()->set(
  3245. SLAPD_KEY_USE_EXISTING_UG, "Yes");
  3246. }
  3247. else
  3248. {
  3249. getManager(me)->getDefaultScript()->set(
  3250. SLAPD_KEY_USE_EXISTING_UG, "No");
  3251. }
  3252. dialogSetup(me, SLAPD_KEY_USE_EXISTING_UG, "No");
  3253. long setupval = 0;
  3254. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3255. setupval == SETUP_ONLY)
  3256. {
  3257. #if DEBUG > 1
  3258. cerr << "Leaving askUseExistingUGSetup DIALOG_NEXT" << endl;
  3259. #endif
  3260. return DIALOG_NEXT;
  3261. }
  3262. #if DEBUG > 1
  3263. cerr << "Leaving askUseExistingUGSetup DIALOG_SAME" << endl;
  3264. #endif
  3265. return DIALOG_SAME;
  3266. }
  3267. static DialogAction
  3268. askUseExistingUGNext(Dialog *me)
  3269. {
  3270. #if DEBUG > 1
  3271. cerr << "Entering askUseExistingUGNext" << endl;
  3272. #endif
  3273. const char *buf = me->input();
  3274. if (!buf || !*buf)
  3275. {
  3276. buf = me->defaultAns();
  3277. if (!buf || !*buf)
  3278. buf = "No";
  3279. }
  3280. getManager(me)->getDefaultScript()->set(SLAPD_KEY_USE_EXISTING_UG, buf);
  3281. if (!isValidYesNo(buf))
  3282. return DIALOG_SAME;
  3283. #if DEBUG > 1
  3284. cerr << "Leaving askUseExistingUGNext DIALOG_NEXT" << endl;
  3285. #endif
  3286. return DIALOG_NEXT;
  3287. }
  3288. DialogInput askUGHost(
  3289. "Enter the fully qualified domain name of the user directory host of\n"
  3290. "the form <hostname>.<domainname> (e.g. hostname.domain.com).\n",
  3291. "User directory host name",
  3292. 0,
  3293. askUGHostSetup,
  3294. askUGHostNext
  3295. );
  3296. static DialogAction
  3297. askUGHostSetup(Dialog *me)
  3298. {
  3299. DialogAction action = DIALOG_NEXT;
  3300. long actionval = 0;
  3301. me->getUserData(ACTION, actionval);
  3302. action = (DialogAction)actionval;
  3303. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3304. return action;
  3305. dialogSetup(me, SLAPD_KEY_UG_HOST, 0);
  3306. long setupval = 0;
  3307. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3308. setupval == SETUP_ONLY)
  3309. return DIALOG_NEXT;
  3310. return DIALOG_SAME;
  3311. }
  3312. static DialogAction
  3313. askUGHostNext(Dialog *me)
  3314. {
  3315. long setupval = 0;
  3316. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3317. setupval == SETUP_ONLY)
  3318. return DIALOG_NEXT;
  3319. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3320. return DIALOG_NEXT;
  3321. const char *buf = me->input();
  3322. const char *tmp;
  3323. if (buf[0] == 0)
  3324. {
  3325. tmp = me->defaultAns();
  3326. }
  3327. else
  3328. {
  3329. tmp = buf;
  3330. }
  3331. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_HOST, tmp);
  3332. if (!tmp || !isValid(tmp))
  3333. {
  3334. DialogManagerType::showAlert("Please enter a valid hostname");
  3335. return DIALOG_SAME;
  3336. }
  3337. return DIALOG_NEXT;
  3338. }
  3339. DialogInput askUGPort(
  3340. "Please specify the port number on which the user directory listens.\n",
  3341. "User directory port number",
  3342. "389",
  3343. askUGPortSetup,
  3344. askUGPortNext
  3345. );
  3346. static DialogAction
  3347. askUGPortSetup(Dialog *me)
  3348. {
  3349. DialogAction action = DIALOG_NEXT;
  3350. long actionval = 0;
  3351. me->getUserData(ACTION, actionval);
  3352. action = (DialogAction)actionval;
  3353. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3354. return action;
  3355. dialogSetup(me, SLAPD_KEY_UG_PORT, me->defaultAns());
  3356. long setupval = 0;
  3357. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3358. setupval == SETUP_ONLY)
  3359. return DIALOG_NEXT;
  3360. return DIALOG_SAME;
  3361. }
  3362. static DialogAction
  3363. askUGPortNext(Dialog *me)
  3364. {
  3365. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3366. return DIALOG_NEXT;
  3367. const char *buf = me->input();
  3368. const char *tmp;
  3369. char testbuf[1024];
  3370. int port, err = 0;
  3371. if (buf[0] == 0)
  3372. {
  3373. tmp = me->defaultAns();
  3374. }
  3375. else
  3376. {
  3377. tmp = buf;
  3378. }
  3379. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_PORT, tmp);
  3380. port = atoi(tmp);
  3381. PR_snprintf(testbuf, sizeof(testbuf), "%d", port);
  3382. if (strncmp(testbuf, tmp, 6) || port > MAXPORT || port < 1)
  3383. {
  3384. PR_snprintf(testbuf, sizeof(testbuf), "OVERFLOW ERROR: Unable to bind to port %d\n"
  3385. "Please choose another port between 1 and %d.\n\n",
  3386. port, MAXPORT);
  3387. err = -1;
  3388. }
  3389. if (err)
  3390. {
  3391. DialogManagerType::showAlert(testbuf);
  3392. return DIALOG_SAME;
  3393. }
  3394. return DIALOG_NEXT;
  3395. }
  3396. DialogInput askUGDN(
  3397. "In order to add and modify information in the user directory, you must\n"
  3398. "be able to bind to the server as an entity with the correct\n"
  3399. "permissions. This user is usually the Directory Manager, although\n"
  3400. "other users may be given the proper access. You will also be asked to\n"
  3401. "provide the password.\n",
  3402. "User directory administrator ID",
  3403. 0,
  3404. askUGDNSetup,
  3405. askUGDNNext
  3406. );
  3407. static DialogAction
  3408. askUGDNSetup(Dialog *me)
  3409. {
  3410. DialogAction action = DIALOG_NEXT;
  3411. long actionval = 0;
  3412. me->getUserData(ACTION, actionval);
  3413. action = (DialogAction)actionval;
  3414. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3415. return action;
  3416. dialogSetup(me, SLAPD_KEY_USER_GROUP_ADMIN_ID, DEFAULT_SLAPDUSER);
  3417. long setupval = 0;
  3418. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3419. setupval == SETUP_ONLY)
  3420. return DIALOG_NEXT;
  3421. return DIALOG_SAME;
  3422. }
  3423. static DialogAction
  3424. askUGDNNext(Dialog *me)
  3425. {
  3426. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3427. return DIALOG_NEXT;
  3428. const char *slapdUser;
  3429. char *slapdPwd = 0;
  3430. const char *buf;
  3431. buf = me->input();
  3432. if (buf[0] == 0)
  3433. {
  3434. slapdUser = me->defaultAns();
  3435. }
  3436. else
  3437. {
  3438. slapdUser = buf;
  3439. }
  3440. getManager(me)->getBaseScript()->set(SLAPD_KEY_USER_GROUP_ADMIN_ID, slapdUser);
  3441. if (!isValid(slapdUser))
  3442. {
  3443. DialogManagerType::showAlert("Please enter a valid string.");
  3444. return DIALOG_SAME;
  3445. }
  3446. while (1)
  3447. {
  3448. me->showString("Password: ");
  3449. if (me->getPassword () == 0)
  3450. {
  3451. return DIALOG_PREV;
  3452. }
  3453. else
  3454. {
  3455. char *inp = strdup(me->input());
  3456. if (inp[0] == 0)
  3457. {
  3458. free(inp);
  3459. continue;
  3460. }
  3461. else
  3462. {
  3463. slapdPwd = inp;
  3464. break;
  3465. }
  3466. }
  3467. }
  3468. if (slapdPwd)
  3469. {
  3470. getManager(me)->getBaseScript()->set(SLAPD_KEY_USER_GROUP_ADMIN_PWD, slapdPwd);
  3471. free(slapdPwd);
  3472. int status;
  3473. if ((status = getManager(me)->verifyRemoteLdap(
  3474. SLAPD_KEY_UG_HOST,
  3475. SLAPD_KEY_UG_PORT,
  3476. SLAPD_KEY_UG_SUFFIX,
  3477. SLAPD_KEY_USER_GROUP_ADMIN_ID,
  3478. SLAPD_KEY_USER_GROUP_ADMIN_PWD
  3479. ))
  3480. )
  3481. {
  3482. ostrstream msg;
  3483. msg << "Could not connect to ldap://"
  3484. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_HOST)
  3485. << ":"
  3486. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_PORT)
  3487. << "/"
  3488. << getManager(me)->getBaseScript()->get(SLAPD_KEY_UG_SUFFIX)
  3489. << endl << "for bind DN "
  3490. << getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_ADMIN_ID)
  3491. << " status = " << status << endl
  3492. << "Please check your typing. If you have mis-typed, you can backup"
  3493. << endl
  3494. << "and retype. Otherwise, the remote server may be down at this time."
  3495. << endl
  3496. << "The installation cannot proceed."
  3497. << endl << ends;
  3498. DialogManagerType::showAlert(msg.str());
  3499. delete [] msg.str();
  3500. return DIALOG_SAME;
  3501. }
  3502. }
  3503. return DIALOG_NEXT;
  3504. }
  3505. DialogInput askUGSuffix(
  3506. "Please specify the suffix for the user directory server.\n",
  3507. "User directory server suffix",
  3508. NULL,
  3509. askUGSuffixSetup,
  3510. askUGSuffixNext
  3511. );
  3512. static DialogAction
  3513. askUGSuffixSetup(Dialog *me)
  3514. {
  3515. DialogAction action = DIALOG_NEXT;
  3516. long actionval = 0;
  3517. me->getUserData(ACTION, actionval);
  3518. action = (DialogAction)actionval;
  3519. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3520. return action;
  3521. dialogSetup(me, SLAPD_KEY_UG_SUFFIX, getManager(me)->getDefaultSuffix());
  3522. long setupval = 0;
  3523. if (me->getUserData(SETUP_DEFAULTS, setupval) == SETUP_ONLY ||
  3524. setupval == SETUP_ONLY)
  3525. return DIALOG_NEXT;
  3526. return DIALOG_SAME;
  3527. }
  3528. static DialogAction
  3529. askUGSuffixNext(Dialog *me)
  3530. {
  3531. if (!getManager(me)->featureIsEnabled(SLAPD_KEY_USE_EXISTING_UG))
  3532. return DIALOG_NEXT;
  3533. const char *buf;
  3534. NSString val;
  3535. buf = me->input();
  3536. if (buf[0] == 0)
  3537. val = me->defaultAns();
  3538. else
  3539. val = buf;
  3540. getManager(me)->getBaseScript()->set(SLAPD_KEY_UG_SUFFIX, val);
  3541. // check to see if it is a valid dn
  3542. if (!isAValidDN(val))
  3543. {
  3544. DialogManagerType::showAlert("The suffix must be a valid DN");
  3545. return DIALOG_SAME;
  3546. }
  3547. if (!isValid(val))
  3548. {
  3549. DialogManagerType::showAlert("Please enter a valid string.");
  3550. return DIALOG_SAME;
  3551. }
  3552. return DIALOG_NEXT;
  3553. }
  3554. DialogInput askReconfigMCAdminPwd(
  3555. (const char*)0,
  3556. "Fedora configuration directory server\nadministrator ID",
  3557. (const char*)0,
  3558. askReconfigMCAdminPwdSetup,
  3559. askReconfigMCAdminPwdNext
  3560. );
  3561. static DialogAction
  3562. askReconfigMCAdminPwdSetup(Dialog *me)
  3563. {
  3564. #if DEBUG > 1
  3565. cerr << "Entering askReconfigMCAdminPwdSetup" << endl;
  3566. #endif
  3567. NSString msg = NSString(
  3568. "In order to reconfigure your installation, the Configuration Directory\n"
  3569. "Administrator password is required. Here is your current information:\n\n"
  3570. "Configuration Directory: ") +
  3571. getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL) + "\n" +
  3572. "Configuration Administrator ID: " +
  3573. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID) + "\n" +
  3574. "\nAt the prompt, please enter the password for the Configuration Administrator.\n";
  3575. me->setText(msg);
  3576. me->setDefaultAns(getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID));
  3577. #if DEBUG > 1
  3578. cerr << "Leaving askReconfigMCAdminPwdSetup" << endl;
  3579. #endif
  3580. return DIALOG_SAME;
  3581. }
  3582. static DialogAction
  3583. askReconfigMCAdminPwdNext(Dialog *me)
  3584. {
  3585. const char *buf;
  3586. buf = me->input();
  3587. if (!buf || buf[0] == 0)
  3588. {
  3589. buf = me->defaultAns();
  3590. }
  3591. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_ID, buf);
  3592. if (!isValid(buf))
  3593. {
  3594. DialogManagerType::showAlert("Please enter a valid string.");
  3595. return DIALOG_SAME;
  3596. }
  3597. me->showString("Password: ");
  3598. while (1)
  3599. {
  3600. if (me->getPassword () == 0)
  3601. {
  3602. return DIALOG_PREV;
  3603. }
  3604. else
  3605. {
  3606. char *inp = strdup(me->input());
  3607. if (inp[0] == 0)
  3608. {
  3609. me->showString("Password: ");
  3610. continue;
  3611. }
  3612. else if (contains8BitChars(inp))
  3613. {
  3614. DialogManagerType::showAlert("Password must contain 7 bit characters only.");
  3615. return DIALOG_SAME;
  3616. }
  3617. else if (!isValid(inp))
  3618. {
  3619. DialogManagerType::showAlert("Please enter a valid password.");
  3620. return DIALOG_SAME;
  3621. }
  3622. else
  3623. {
  3624. int status;
  3625. if ((status = authLdapUser(
  3626. getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL),
  3627. getManager(me)->getBaseScript()->get(SLAPD_KEY_SERVER_ADMIN_ID),
  3628. inp, 0, 0)))
  3629. {
  3630. ostrstream msg;
  3631. msg << "Could not connect to "
  3632. << getManager(me)->getBaseScript()->get(SLAPD_KEY_K_LDAP_URL)
  3633. << endl << "for ID "
  3634. << getManager(me)->getBaseScript()->get(SLAPD_KEY_USER_GROUP_ADMIN_ID)
  3635. << " status = " << status << endl
  3636. << "Please check your typing. If you have mis-typed, you can backup"
  3637. << endl
  3638. << "and retype. Otherwise, the remote server may be down at this time."
  3639. << endl
  3640. << "The reconfiguration cannot proceed."
  3641. << endl << ends;
  3642. DialogManagerType::showAlert(msg.str());
  3643. delete [] msg.str();
  3644. return DIALOG_SAME;
  3645. }
  3646. }
  3647. getManager(me)->getBaseScript()->set(SLAPD_KEY_SERVER_ADMIN_PWD, inp);
  3648. free(inp);
  3649. break;
  3650. }
  3651. }
  3652. return DIALOG_NEXT;
  3653. }