ux-dialog.cc 103 KB

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