create_instance.c 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright 2001 Sun Microsystems, Inc.
  3. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. /*
  7. * create_instance.c: Routines for creating an instance of a Directory Server
  8. *
  9. * These routines are not thread safe.
  10. *
  11. * Rob McCool
  12. */
  13. #define GW_CONF 1
  14. #define PB_CONF 2
  15. #include "create_instance.h"
  16. #include "cfg_sspt.h"
  17. #include <stdio.h>
  18. #include <stdarg.h>
  19. #include <string.h>
  20. #include <sys/stat.h>
  21. #include <ctype.h>
  22. #define PATH_SIZE 1024
  23. #define ERR_SIZE 8192
  24. /* delay time in seconds between referential integrity updates
  25. 0 means continues */
  26. #define REFERINT_DELAY 0
  27. /* 1=log changes for replaction, 0=don't replicate changes */
  28. #define REFERINT_LOG_CHANGES 0
  29. #include "dsalib.h"
  30. #include "dirver.h"
  31. #include "nspr.h"
  32. #include "plstr.h"
  33. #ifdef XP_WIN32
  34. #define NOT_ABSOLUTE_PATH(str) \
  35. ((str[0] != '/') && (str[0] != '\\') && (str[2] != '/') && (str[2] != '\\'))
  36. #define EADDRINUSE WSAEADDRINUSE
  37. #define EACCES WSAEACCES
  38. #include <winsock.h>
  39. #include <io.h>
  40. #include <regparms.h>
  41. #include <nt/ntos.h>
  42. #define SHLIB_EXT "dll"
  43. #else
  44. #define NOT_ABSOLUTE_PATH(str) (str[0] != '/')
  45. #include <errno.h>
  46. #include <sys/types.h>
  47. #if !defined(HPUX) && !defined(LINUX2_0)
  48. #include <sys/select.h> /* FD_SETSIZE */
  49. #else
  50. #include <sys/types.h> /* FD_SETSIZE is in types.h on HPUX */
  51. #endif
  52. #if !defined(_WIN32) && !defined(AIX)
  53. #include <sys/resource.h> /* get/setrlimit stuff */
  54. #endif
  55. #include <sys/socket.h> /* socket flags */
  56. #include <netinet/in.h> /* sockaddr_in */
  57. #include <arpa/inet.h> /* inet_addr */
  58. #ifdef HPUX
  59. #define SHLIB_EXT "sl"
  60. #else
  61. #define SHLIB_EXT "so"
  62. #endif
  63. #endif
  64. /*
  65. NT doesn't strictly need these, but the libadmin API which is emulated
  66. below uses them.
  67. */
  68. #define NEWSCRIPT_MODE 0755
  69. #define NEWFILE_MODE 0644
  70. #define NEWDIR_MODE 0755
  71. #define NEWSECDIR_MODE 0700
  72. #include <stdarg.h>
  73. #ifdef XP_WIN32
  74. OS_TYPE NS_WINAPI INFO_GetOperatingSystem ();
  75. DWORD NS_WINAPI SERVICE_ReinstallNTService( LPCTSTR szServiceName,
  76. LPCTSTR szServiceDisplayName,
  77. LPCTSTR szServiceExe );
  78. #endif
  79. static void ds_gen_index(FILE* f, char* belowdn);
  80. static char *ds_gen_orgchart_conf(char *sroot, char *cs_path, server_config_s *cf);
  81. static char *ds_gen_gw_conf(char *sroot, char *cs_path, server_config_s *cf, int conf_type);
  82. static char *install_ds(char *sroot, server_config_s *cf, char *param_name);
  83. static int write_ldap_info(char *slapd_server_root, server_config_s *cf);
  84. #if defined (BUILD_PRESENCE)
  85. static char *gen_presence_init_script(char *sroot, server_config_s *cf,
  86. char *cs_path);
  87. static int init_presence(char *sroot, server_config_s *cf, char *cs_path);
  88. #endif
  89. #if defined( SOLARIS )
  90. /*
  91. * Solaris 9+ specific installation
  92. */
  93. extern int iDSISolaris;
  94. static char *sub_token(const char *, const char *, int, const char *, int);
  95. /*
  96. * If for some reasons, sub_token fails to generate the
  97. * "etc" and "var" server_root from the actual "server_root",
  98. * then the following hard-coded pathnames will be used.
  99. */
  100. #define SOLARIS_ETC_DIR "/etc/iplanet/ds5"
  101. #define SOLARIS_VAR_DIR "/var/ds5"
  102. /*
  103. * Solaris 9+ specific installation
  104. * The following function replaces the first occurence
  105. * of "token" in the string "s" by "replace"
  106. */
  107. static char *
  108. sub_token(const char *s, const char *token, int tokenlen,
  109. const char *replace, int replacelen)
  110. {
  111. char *n = 0, *d;
  112. char *ptr = (char*)strstr(s, token);
  113. const char *begin;
  114. int len;
  115. if (!ptr)
  116. return n;
  117. d = n = (char *) calloc(strlen(s) + replacelen + 1, 1);
  118. if (!n)
  119. return n;
  120. begin = s;
  121. len = (int)(ptr - begin);
  122. strncpy(d, begin, len);
  123. d += len;
  124. begin = ptr + tokenlen;
  125. len = replacelen;
  126. strncpy(d, replace, len);
  127. d += len;
  128. for (ptr = (char *)begin; ptr && *ptr; LDAP_UTF8INC(ptr))
  129. {
  130. *d = *ptr;
  131. LDAP_UTF8INC(d);
  132. }
  133. *d = 0;
  134. return n;
  135. }
  136. #endif /* SOLARIS */
  137. static char *make_error(char *fmt, ...)
  138. {
  139. static char errbuf[ERR_SIZE];
  140. va_list args;
  141. va_start(args, fmt);
  142. vsprintf(errbuf, fmt, args);
  143. va_end(args);
  144. return errbuf;
  145. }
  146. /* This is to determine if we can skip the port number checks. During
  147. migration or server cloning, we may want to copy over an old configuration,
  148. including the old port number, which may not currently have permission to
  149. use; if we don't need to start the server right away, we can skip
  150. certain checks
  151. */
  152. static int needToStartServer(server_config_s *cf)
  153. {
  154. if (cf && (
  155. (cf->cfg_sspt && !strcmp(cf->cfg_sspt, "1")) ||
  156. (cf->start_server && !strcmp(cf->start_server, "1"))
  157. ))
  158. {
  159. return 1;
  160. }
  161. return 0;
  162. }
  163. static char *
  164. myStrdup(const char *s)
  165. {
  166. if (s == NULL)
  167. return (char *)s;
  168. return strdup(s);
  169. }
  170. static int getSuiteSpotUserGroup(server_config_s* cf)
  171. {
  172. #ifdef XP_UNIX
  173. static const char *ssUsersFile = "shared/config/ssusers.conf";
  174. char realFile[PATH_SIZE];
  175. char buf[1024];
  176. FILE *fp = NULL;
  177. int status = 1;
  178. if (cf->servuser)
  179. return 0;
  180. sprintf(realFile, "%s/%s", cf->sroot, ssUsersFile);
  181. if (!(fp = fopen(realFile, "r")))
  182. return 1;
  183. while (fgets(buf, sizeof(buf), fp))
  184. {
  185. char *p = NULL;
  186. if (buf[0] == '#' || buf[0] == '\n')
  187. continue;
  188. buf[strlen(buf) - 1] = 0;
  189. if (NULL != (p = strstr(buf, "SuiteSpotUser")))
  190. {
  191. p += strlen("SuiteSpotUser");
  192. while (ldap_utf8isspace(p))
  193. LDAP_UTF8INC(p);
  194. cf->servuser = strdup(p);
  195. status = 0;
  196. break;
  197. }
  198. }
  199. if (fp)
  200. fclose(fp);
  201. return status;
  202. #else
  203. return 0;
  204. #endif
  205. }
  206. /* ----------------------- Create default settings ------------------------ */
  207. void set_defaults(char *sroot, char *hn, server_config_s *conf)
  208. {
  209. char *id = 0, *t = 0;
  210. conf->sroot = sroot;
  211. if (hn)
  212. {
  213. if( (t = strchr(hn, '.')) )
  214. *t = '\0';
  215. id = (char *) malloc(strlen(hn) + 1);
  216. sprintf(id, "%s", hn);
  217. if(t)
  218. *t = '.';
  219. }
  220. conf->servname = hn;
  221. conf->bindaddr = "";
  222. conf->servport = "80";
  223. conf->cfg_sspt = NULL;
  224. conf->suitespot3x_uid = NULL;
  225. conf->cfg_sspt_uid = NULL;
  226. conf->cfg_sspt_uidpw = NULL;
  227. conf->servport = "389";
  228. conf->secserv = "off";
  229. conf->secservport = "636";
  230. conf->ntsynch = "off";
  231. conf->ntsynchssl = "on";
  232. conf->ntsynchport = "5009";
  233. conf->rootpw = "";
  234. conf->roothashedpw = "";
  235. conf->loglevel = NULL;
  236. if (getenv("DEBUG_DS_LOG_LEVEL"))
  237. conf->loglevel = getenv("DEBUG_DS_LOG_LEVEL");
  238. conf->suffix = "dc=example, dc=com";
  239. #ifndef DONT_ALWAYS_CREATE_NETSCAPEROOT
  240. conf->netscaperoot = name_netscaperootDN;
  241. #endif /* DONT_ALWAYS_CREATE_NETSCAPEROOT */
  242. #define CREATE_SAMPLE_SUFFIX
  243. #ifdef CREATE_SAMPLE_SUFFIX
  244. conf->samplesuffix = "dc=example, dc=com";
  245. #endif /* CREATE_SAMPLE_SUFFIX */
  246. #ifdef TEST_CONFIG
  247. conf->netscaperoot = "cn=config40";
  248. #endif /* TEST_CONFIG */
  249. #define ROOT_RDN "cn=Directory Manager"
  250. conf->rootdn = ROOT_RDN;
  251. /* conf->rootdn = malloc(strlen(ROOT_RDN) + 2 + strlen(conf->suffix) + 1);
  252. sprintf(conf->rootdn, "%s, %s", ROOT_RDN, conf->suffix);*/
  253. conf->servid = id;
  254. #ifdef XP_UNIX
  255. conf->servuser = NULL;
  256. #ifdef THREAD_NSPR_KERNEL
  257. conf->numprocs = "1";
  258. conf->maxthreads = "128";
  259. #else
  260. conf->numprocs = "4";
  261. conf->maxthreads = "32";
  262. #endif
  263. #else /* XP_WIN32 */
  264. conf->maxthreads = "32";
  265. #endif
  266. conf->minthreads = "4";
  267. conf->upgradingServer = 0;
  268. conf->start_server = "1";
  269. conf->admin_domain = NULL;
  270. conf->config_ldap_url = NULL;
  271. conf->user_ldap_url = NULL;
  272. conf->use_existing_config_ds = 0;
  273. conf->use_existing_user_ds = 0;
  274. conf->consumerdn = NULL;
  275. conf->disable_schema_checking = NULL;
  276. conf->install_ldif_file = NULL;
  277. }
  278. /* ----------------- Sanity check a server configuration ------------------ */
  279. char *create_instance_checkport(char *, char *);
  280. char *create_instance_checkuser(char *);
  281. int create_instance_numbers(char *);
  282. int create_instance_exists(char *fn);
  283. char *create_instance_copy(char *, char *, int);
  284. char *create_instance_concatenate(char *, char *, int);
  285. int create_instance_mkdir(char *, int);
  286. char *create_instance_mkdir_p(char *, int);
  287. #if defined( SOLARIS )
  288. /*
  289. * Solaris 9+ specific installation
  290. */
  291. int create_instance_symlink(char *, char *);
  292. #endif /* SOLARIS */
  293. /*
  294. returns NULL if the given dn is a valid dn, or an error string
  295. */
  296. static char *
  297. isAValidDN(const char *dn_to_test)
  298. {
  299. char *t = 0;
  300. if (!dn_to_test || !*dn_to_test)
  301. {
  302. t = "No value specified for the parameter.";
  303. }
  304. else
  305. {
  306. char **rdnList = ldap_explode_dn(dn_to_test, 0);
  307. char **rdnNoTypes = ldap_explode_dn(dn_to_test, 1);
  308. if (!rdnList || !rdnList[0] || !rdnNoTypes || !rdnNoTypes[0] ||
  309. !*rdnNoTypes[0] || !PL_strcasecmp(rdnList[0], rdnNoTypes[0]))
  310. {
  311. t = make_error("The given value [%s] is not a valid DN.",
  312. dn_to_test);
  313. }
  314. if (rdnList)
  315. ldap_value_free(rdnList);
  316. if (rdnNoTypes)
  317. ldap_value_free(rdnNoTypes);
  318. }
  319. if (t)
  320. return t;
  321. return NULL;
  322. }
  323. /*
  324. prints a message if the given dn uses LDAPv2 style quoting
  325. */
  326. void
  327. checkForLDAPv2Quoting(const char *dn_to_test)
  328. {
  329. if (ds_dn_uses_LDAPv2_quoting(dn_to_test))
  330. {
  331. char *newdn = strdup(dn_to_test);
  332. char *t;
  333. dn_normalize_convert(newdn);
  334. t = make_error(
  335. "The given value [%s] is quoted in the deprecated LDAPv2 style\n"
  336. "quoting format. It will be automatically converted to use the\n"
  337. "LDAPv3 style escaped format [%s].", dn_to_test, newdn);
  338. free(newdn);
  339. ds_show_message(t);
  340. }
  341. return;
  342. }
  343. /*
  344. returns NULL if the given string contains no 8 bit chars, otherwise an
  345. error message
  346. */
  347. static char *
  348. contains8BitChars(const char *s)
  349. {
  350. char *t = 0;
  351. if (s && *s)
  352. {
  353. for (; !t && *s; ++s)
  354. {
  355. if (*s & 0x80)
  356. {
  357. t = make_error("The given value [%s] contains invalid 8 bit characters.",
  358. s);
  359. }
  360. }
  361. }
  362. return t;
  363. }
  364. static char *sanity_check(server_config_s *cf, char *param_name)
  365. {
  366. char *t, fn[PATH_SIZE];
  367. register int x;
  368. if (!param_name)
  369. return "Parameter param_name is null";
  370. /* if we don't need to start the server right away, we can skip the
  371. port number checks
  372. */
  373. if (!needToStartServer(cf))
  374. {
  375. if( (t = create_instance_checkport(cf->bindaddr, cf->servport)) )
  376. {
  377. strcpy(param_name, "servport");
  378. return t;
  379. }
  380. if ( cf->secserv && (strcmp(cf->secserv, "on") == 0) && (cf->secservport != NULL) &&
  381. (*(cf->secservport) != '\0') ) {
  382. if ( (t = create_instance_checkport(cf->bindaddr, cf->secservport)) ) {
  383. strcpy(param_name, "secservport");
  384. return t;
  385. }
  386. }
  387. if ( cf->ntsynch && (strcmp(cf->ntsynch, "on") == 0) && (cf->ntsynchport != NULL) &&
  388. (*(cf->ntsynchport) != '\0') ) {
  389. if ( (t = create_instance_checkport(cf->bindaddr, cf->ntsynchport)) ) {
  390. strcpy(param_name, "ntsynchport");
  391. return t;
  392. }
  393. }
  394. }
  395. /* is the server identifier good? */
  396. for(x=0; cf->servid[x]; x++) {
  397. if(strchr("/ &;`'\"|*!?~<>^()[]{}$\\", cf->servid[x])) {
  398. strcpy(param_name, "servid");
  399. return make_error("You used a shell-specific character in "
  400. "your server id (the character was %c).",
  401. cf->servid[x]);
  402. }
  403. }
  404. /* has that identifier already been used? */
  405. sprintf(fn, "%s%c%s-%s", cf->sroot, FILE_PATHSEP,
  406. PRODUCT_NAME, cf->servid);
  407. /* Not an error to upgrade! ???
  408. if ( !cf->upgradingServer ) {
  409. if(create_instance_exists(fn)) {
  410. strcpy(param_name, "servid");
  411. return make_error ("A server named '%s' already exists."
  412. "\nPlease choose another server identifier.",
  413. cf->servid);
  414. }
  415. }
  416. */
  417. #ifdef XP_UNIX
  418. if( (t = create_instance_checkuser(cf->servuser)) )
  419. {
  420. strcpy(param_name, "servuser");
  421. return t;
  422. }
  423. #endif
  424. /* make sure some drooling imbecile doesn't put in bogus numbers */
  425. #ifdef XP_UNIX
  426. if((!create_instance_numbers(cf->numprocs)) || (atoi(cf->numprocs) <= 0))
  427. {
  428. strcpy(param_name, "numprocs");
  429. return ("The number of processes must be not be zero or "
  430. "negative.");
  431. }
  432. #endif
  433. if((!create_instance_numbers(cf->maxthreads)) || (atoi(cf->maxthreads) <= 0))
  434. {
  435. strcpy(param_name, "maxthreads");
  436. return ("The maximum threads must be not be zero or negative.");
  437. }
  438. if((!create_instance_numbers(cf->minthreads)) || (atoi(cf->minthreads) <= 0))
  439. {
  440. strcpy(param_name, "minthreads");
  441. return ("The minumum threads must be not be zero or negative.");
  442. }
  443. if((atoi(cf->minthreads)) > (atoi(cf->maxthreads)))
  444. {
  445. strcpy(param_name, "minthreads");
  446. return ("Minimum threads must be less than maximum threads.");
  447. }
  448. /* see if the DN parameters are valid DNs */
  449. if (!cf->use_existing_user_ds && (t = isAValidDN(cf->suffix)))
  450. {
  451. strcpy(param_name, "suffix");
  452. return t;
  453. }
  454. checkForLDAPv2Quoting(cf->suffix);
  455. if (NULL != (t = isAValidDN(cf->rootdn)))
  456. {
  457. strcpy(param_name, "rootdn");
  458. return t;
  459. }
  460. checkForLDAPv2Quoting(cf->rootdn);
  461. if (cf->replicationdn && *cf->replicationdn && (t = isAValidDN(cf->replicationdn)))
  462. {
  463. strcpy(param_name, "replicationdn");
  464. return t;
  465. }
  466. checkForLDAPv2Quoting(cf->replicationdn);
  467. if (cf->consumerdn && *cf->consumerdn && (t = isAValidDN(cf->consumerdn)))
  468. {
  469. strcpy(param_name, "consumerdn");
  470. return t;
  471. }
  472. checkForLDAPv2Quoting(cf->consumerdn);
  473. if (cf->changelogsuffix && *cf->changelogsuffix &&
  474. (t = isAValidDN(cf->changelogsuffix)))
  475. {
  476. strcpy(param_name, "changelogsuffix");
  477. return t;
  478. }
  479. checkForLDAPv2Quoting(cf->changelogsuffix);
  480. if (cf->netscaperoot && *cf->netscaperoot &&
  481. (t = isAValidDN(cf->netscaperoot)))
  482. {
  483. strcpy(param_name, "netscaperoot");
  484. return t;
  485. }
  486. checkForLDAPv2Quoting(cf->netscaperoot);
  487. if (cf->samplesuffix && *cf->samplesuffix &&
  488. (t = isAValidDN(cf->samplesuffix)))
  489. {
  490. strcpy(param_name, "samplesuffix");
  491. return t;
  492. }
  493. checkForLDAPv2Quoting(cf->samplesuffix);
  494. if (NULL != (t = contains8BitChars(cf->rootpw)))
  495. {
  496. strcpy(param_name, "rootpw");
  497. return t;
  498. }
  499. if (NULL != (t = contains8BitChars(cf->cfg_sspt_uidpw)))
  500. {
  501. strcpy(param_name, "cfg_sspt_uidpw");
  502. return t;
  503. }
  504. if (NULL != (t = contains8BitChars(cf->replicationpw)))
  505. {
  506. strcpy(param_name, "replicationpw");
  507. return t;
  508. }
  509. if (NULL != (t = contains8BitChars(cf->consumerpw)))
  510. {
  511. strcpy(param_name, "consumerpw");
  512. return t;
  513. }
  514. if (cf->cfg_sspt_uid && *cf->cfg_sspt_uid)
  515. {
  516. /*
  517. If it is a valid DN, ok. Otherwise, it should be a uid, and should
  518. be checked for 8 bit chars
  519. */
  520. if (NULL != (t = isAValidDN(cf->cfg_sspt_uid)))
  521. {
  522. if (NULL != (t = contains8BitChars(cf->cfg_sspt_uid)))
  523. {
  524. strcpy(param_name, "cfg_sspt_uid");
  525. return t;
  526. }
  527. }
  528. else
  529. checkForLDAPv2Quoting(cf->cfg_sspt_uid);
  530. }
  531. return NULL;
  532. }
  533. /* ----- From a configuration, set up a new server in the server root ----- */
  534. /* ------------------ UNIX utilities for server creation ------------------ */
  535. #ifdef XP_UNIX
  536. #include <unistd.h>
  537. #include <pwd.h>
  538. char*
  539. chownfile (struct passwd* pw, char* fn)
  540. {
  541. if (pw != NULL && chown (fn, pw->pw_uid, pw->pw_gid) == -1) {
  542. if (pw->pw_name != NULL) {
  543. return make_error ("Could not change owner of %s to %s.",
  544. fn, pw->pw_name);
  545. } else {
  546. return make_error ("Could not change owner of %s to (UID %li, GID %li).",
  547. fn, (long)(pw->pw_uid), (long)(pw->pw_gid));
  548. }
  549. }
  550. return NULL;
  551. }
  552. char *chownlogs(char *sroot, char *user)
  553. {
  554. struct passwd *pw;
  555. char fn[PATH_SIZE];
  556. if(user && *user && !geteuid()) {
  557. if(!(pw = getpwnam(user)))
  558. return make_error("Could not find UID and GID of user '%s'.",
  559. user);
  560. sprintf(fn, "%s%clogs", sroot, FILE_PATHSEP);
  561. return chownfile (pw, fn);
  562. }
  563. return NULL;
  564. }
  565. char *chownconfig(char *sroot, char *user)
  566. {
  567. struct passwd *pw;
  568. char fn[PATH_SIZE];
  569. if(user && *user && !geteuid()) {
  570. if(!(pw = getpwnam(user)))
  571. return make_error("Could not find UID and GID of user '%s'.",
  572. user);
  573. sprintf(fn, "%s%cconfig", sroot, FILE_PATHSEP);
  574. return chownfile (pw, fn);
  575. }
  576. return NULL;
  577. }
  578. #else
  579. #define chownfile(a, b)
  580. #define chownlogs(a, b)
  581. #define chownconfig(a, b)
  582. #define chownsearch(a, b)
  583. #endif
  584. char *gen_script(char *s_root, char *name, char *fmt, ...)
  585. {
  586. char fn[PATH_SIZE];
  587. FILE *f;
  588. char *shell = "/bin/sh";
  589. va_list args;
  590. sprintf(fn, "%s%c%s", s_root, FILE_PATHSEP, name);
  591. if(!(f = fopen(fn, "w")))
  592. return make_error("Could not write to %s (%s).", fn, ds_system_errmsg());
  593. va_start(args, fmt);
  594. #if !defined( XP_WIN32 )
  595. #if defined( OSF1 )
  596. /*
  597. The standard /bin/sh has some rather strange behavior with "$@",
  598. so use the posix version wherever possible. OSF1 4.0D should
  599. always have this one available.
  600. */
  601. if (!access("/usr/bin/posix/sh", 0))
  602. shell = "/usr/bin/posix/sh";
  603. #endif /* OSF1 */
  604. fprintf(f, "#!%s\n\n", shell);
  605. /*
  606. Neutralize shared library access.
  607. On HP-UX, SHLIB_PATH is the historical variable.
  608. However on HP-UX 64 bit, LD_LIBRARY_PATH is also used.
  609. We unset both too.
  610. */
  611. #if defined( SOLARIS ) || defined( OSF1 ) || defined( LINUX2_0 )
  612. fprintf(f, "unset LD_LIBRARY_PATH\n");
  613. #endif
  614. #if defined( HPUX )
  615. fprintf(f, "unset SHLIB_PATH\n");
  616. fprintf(f, "unset LD_LIBRARY_PATH\n");
  617. #endif
  618. #if defined( AIX )
  619. fprintf(f, "unset LIBPATH\n");
  620. #endif
  621. #endif
  622. vfprintf(f, fmt, args);
  623. #if defined( XP_UNIX )
  624. fchmod(fileno(f), NEWSCRIPT_MODE);
  625. #endif
  626. fclose(f);
  627. #if defined( XP_WIN32 )
  628. chmod( fn, NEWSCRIPT_MODE);
  629. #endif
  630. return NULL;
  631. }
  632. char *gen_perl_script(char *s_root, char *cs_path, char *name, char *fmt, ...)
  633. {
  634. char myperl[PATH_SIZE];
  635. char fn[PATH_SIZE];
  636. FILE *f;
  637. va_list args;
  638. sprintf(fn, "%s%c%s", cs_path, FILE_PATHSEP, name);
  639. sprintf(myperl, "%s%cbin%cslapd%cadmin%cbin%cperl",
  640. s_root, FILE_PATHSEP, FILE_PATHSEP,
  641. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  642. if(!(f = fopen(fn, "w")))
  643. return make_error("Could not write to %s (%s).", fn, ds_system_errmsg());
  644. va_start(args, fmt);
  645. #if !defined( XP_WIN32 )
  646. fprintf(f, "#!%s\n\n", myperl);
  647. #endif
  648. vfprintf(f, fmt, args);
  649. #if defined( XP_UNIX )
  650. fchmod(fileno(f), NEWSCRIPT_MODE);
  651. #endif
  652. fclose(f);
  653. #if defined( XP_WIN32 )
  654. chmod( fn, NEWSCRIPT_MODE);
  655. #endif
  656. #if defined( SOLARIS )
  657. /*
  658. * Solaris 9+ specific installation
  659. * Log all non <server_root>/slapd-identifier files/directories
  660. * created by the post_installer so that they can be removed
  661. * during un-install.
  662. */
  663. if (iDSISolaris)
  664. logUninstallInfo(s_root, PRODUCT_NAME, PRODUCT_NAME, fn);
  665. #endif
  666. return NULL;
  667. }
  668. char *gen_perl_script_auto(char *s_root, char *cs_path, char *name,
  669. server_config_s *cf)
  670. {
  671. char myperl[PATH_SIZE];
  672. char fn[PATH_SIZE], ofn[PATH_SIZE];
  673. const char *table[10][2];
  674. sprintf(ofn, "%s%cbin%cslapd%cadmin%cscripts%ctemplate-%s", s_root,
  675. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  676. FILE_PATHSEP, name);
  677. sprintf(fn, "%s%c%s", cs_path, FILE_PATHSEP, name);
  678. sprintf(myperl, "!%s%cbin%cslapd%cadmin%cbin%cperl",
  679. s_root, FILE_PATHSEP, FILE_PATHSEP,
  680. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  681. table[0][0] = "DS-ROOT";
  682. table[0][1] = s_root;
  683. table[1][0] = "MY-DS-ROOT";
  684. table[1][1] = cs_path;
  685. table[2][0] = "SEP";
  686. table[2][1] = FILE_PATHSEPP;
  687. table[3][0] = "SERVER-NAME";
  688. table[3][1] = cf->servname;
  689. table[4][0] = "SERVER-PORT";
  690. table[4][1] = cf->servport;
  691. table[5][0] = "PERL-EXEC";
  692. table[6][0] = "DEV-NULL";
  693. #if !defined( XP_WIN32 )
  694. table[5][1] = myperl;
  695. table[6][1] = " /dev/null ";
  696. #else
  697. table[5][1] = " perl script";
  698. table[6][1] = " NUL ";
  699. #endif
  700. table[7][0] = "ROOT-DN";
  701. table[7][1] = cf->rootdn;
  702. table[8][0] = table[8][1] = NULL;
  703. if (generate_script(ofn, fn, NEWSCRIPT_MODE, table) != 0) {
  704. return make_error("Could not write %s to %s (%s).", ofn, fn,
  705. ds_system_errmsg());
  706. }
  707. #if defined( SOLARIS )
  708. /*
  709. * Solaris 9+ specific installation
  710. */
  711. if (iDSISolaris)
  712. logUninstallInfo(s_root, PRODUCT_NAME, PRODUCT_NAME, fn);
  713. #endif
  714. return NULL;
  715. }
  716. char *gen_perl_script_auto_for_migration(char *s_root, char *cs_path, char *name,
  717. server_config_s *cf)
  718. {
  719. char myperl[PATH_SIZE];
  720. char fn[PATH_SIZE], ofn[PATH_SIZE];
  721. const char *table[10][2];
  722. sprintf(ofn, "%s%cbin%cslapd%cadmin%cscripts%ctemplate-%s", s_root,
  723. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  724. FILE_PATHSEP, name);
  725. sprintf(fn, "%s%cbin%cslapd%cadmin%cbin%c%s", s_root, FILE_PATHSEP,
  726. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, name);
  727. sprintf(myperl, "!%s%cbin%cslapd%cadmin%cbin%cperl",
  728. s_root, FILE_PATHSEP, FILE_PATHSEP,
  729. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  730. table[0][0] = "DS-ROOT";
  731. table[0][1] = s_root;
  732. table[1][0] = "MY-DS-ROOT";
  733. table[1][1] = cs_path;
  734. table[2][0] = "SEP";
  735. table[2][1] = FILE_PATHSEPP;
  736. table[3][0] = "SERVER-NAME";
  737. table[3][1] = cf->servname;
  738. table[4][0] = "SERVER-PORT";
  739. table[4][1] = cf->servport;
  740. table[5][0] = "PERL-EXEC";
  741. table[6][0] = "DEV-NULL";
  742. #if !defined( XP_WIN32 )
  743. table[5][1] = myperl;
  744. table[6][1] = " /dev/null ";
  745. #else
  746. table[5][1] = " perl script";
  747. table[6][1] = " NUL ";
  748. #endif
  749. table[7][0] = "ROOT-DN";
  750. table[7][1] = cf->rootdn;
  751. table[8][0] = table[8][1] = NULL;
  752. if (generate_script(ofn, fn, NEWSCRIPT_MODE, table) != 0) {
  753. return make_error("Could not write %s to %s (%s).", ofn, fn,
  754. ds_system_errmsg());
  755. }
  756. #if defined( SOLARIS )
  757. /*
  758. * Solaris 9+ specific installation
  759. */
  760. if (iDSISolaris)
  761. logUninstallInfo(s_root, PRODUCT_NAME, PRODUCT_NAME, fn);
  762. #endif
  763. return NULL;
  764. }
  765. /* ------------------ NT utilities for server creation ------------------ */
  766. #ifdef XP_WIN32
  767. char *
  768. service_exists(char *servid)
  769. {
  770. DWORD status, lasterror = 0;
  771. char szServiceName[MAX_PATH] = {0};
  772. sprintf(szServiceName,"%s-%s", SVR_ID_SERVICE, servid);
  773. /* if the service already exists, error */
  774. status = SERVICE_GetNTServiceStatus(szServiceName, &lasterror );
  775. if ( (lasterror == ERROR_SERVICE_DOES_NOT_EXIST) ||
  776. (status == SERVRET_ERROR) || (status == SERVRET_REMOVED) ) {
  777. return 0;
  778. } else { return
  779. make_error("Server %s already exists: cannot create another. "
  780. "Please choose a different name or delete the "
  781. "existing server.",
  782. szServiceName);
  783. }
  784. return 0;
  785. }
  786. void setup_nteventlogging(char *szServiceId, char *szMessageFile)
  787. {
  788. HKEY hKey;
  789. char szKey[MAX_PATH];
  790. DWORD dwData;
  791. sprintf(szKey, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\%s", szServiceId);
  792. if(RegCreateKey(HKEY_LOCAL_MACHINE, szKey, &hKey) == ERROR_SUCCESS)
  793. {
  794. if(RegSetValueEx(hKey, "EventMessageFile", 0, REG_SZ, (LPBYTE)szMessageFile, strlen(szMessageFile) + 1) == ERROR_SUCCESS)
  795. {
  796. dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
  797. RegSetValueEx(hKey, "TypesSupported", 0, REG_DWORD, (LPBYTE) &dwData, sizeof(DWORD));
  798. }
  799. RegCloseKey(hKey);
  800. }
  801. }
  802. char *add_ntservice(server_config_s *cf)
  803. {
  804. char szMessageFile[MAX_PATH];
  805. char szServiceExe[MAX_PATH], szServiceDisplayName[MAX_PATH], szServiceName[MAX_PATH];
  806. DWORD dwLastError;
  807. sprintf ( szServiceExe, "%s/bin/%s/server/%s", cf->sroot,
  808. SVR_DIR_ROOT, SVR_EXE);
  809. sprintf ( szServiceName,"%s-%s", SVR_ID_SERVICE, cf->servid);
  810. sprintf ( szServiceDisplayName, "%s (%s)", SVR_NAME_FULL_VERSION,
  811. cf->servid);
  812. /* install new service - if already installed, try and remove and
  813. then reinstall */
  814. dwLastError = SERVICE_ReinstallNTService( szServiceName,
  815. szServiceDisplayName, szServiceExe );
  816. if ( dwLastError != NO_ERROR ) {
  817. return make_error ( "While installing %s Service, the "
  818. "NT Service Manager reported error %d (%s)",
  819. szServiceDisplayName, dwLastError, ds_system_errmsg() );
  820. }
  821. // setup event logging registry keys, do this after service creation
  822. sprintf(szMessageFile, "%s\\bin\\%s\\server\\%s", cf->sroot,
  823. SVR_DIR_ROOT, "slapdmessages30.dll");
  824. setup_nteventlogging(szServiceName, szMessageFile);
  825. // TODO: add perfmon setup code -ahakim 11/22/96
  826. return NULL;
  827. }
  828. char *setup_ntserver(server_config_s *cf)
  829. {
  830. char line[MAX_PATH], *sroot = cf->sroot;
  831. char subdir[MAX_PATH];
  832. char NumValuesBuf[3];
  833. DWORD Result;
  834. HKEY hServerKey;
  835. DWORD NumValues;
  836. DWORD iterator;
  837. int value_already_exists = 0;
  838. DWORD type_buffer;
  839. char value_data_buffer[MAX_PATH];
  840. DWORD sizeof_value_data_buffer;
  841. /* MLM - Adding ACL directories authdb and authdb/default */
  842. sprintf(subdir, "%s%cauthdb", sroot, FILE_PATHSEP);
  843. if( (create_instance_mkdir(subdir, NEWDIR_MODE)) )
  844. return make_error("mkdir %s failed (%s)", subdir, ds_system_errmsg());
  845. sprintf(subdir, "%s%cauthdb%cdefault", sroot, FILE_PATHSEP, FILE_PATHSEP);
  846. if( (create_instance_mkdir(subdir, NEWDIR_MODE)) )
  847. return make_error("mkdir %s failed (%s)", subdir, ds_system_errmsg());
  848. /* Create DS-nickname (corresponding to ServiceID) key in registry */
  849. sprintf(line, "%s\\%s\\%s-%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT,
  850. SVR_ID_SERVICE, cf->servid);
  851. Result = RegCreateKey(HKEY_LOCAL_MACHINE, line, &hServerKey);
  852. if (Result != ERROR_SUCCESS) {
  853. return make_error("Could not create registry server key %s - error %d (%s)",
  854. line, GetLastError(), ds_system_errmsg());
  855. }
  856. // note that SVR_ID_PRODUCT is being used here, which is of the form dsX
  857. // as opposed to SVR_ID_SERVICE, which is of the form dsX30
  858. sprintf(line, "%s\\%s-%s\\config", sroot, SVR_ID_PRODUCT, cf->servid);
  859. Result = RegSetValueEx(hServerKey, VALUE_CONFIG_PATH, 0, REG_SZ,
  860. line, strlen(line) + 1);
  861. RegCloseKey(hServerKey);
  862. /* Create SNMP key in registry */
  863. sprintf(line, "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT,
  864. KEY_SNMP_CURRENTVERSION);
  865. Result = RegCreateKey(HKEY_LOCAL_MACHINE, line, &hServerKey);
  866. if (Result != ERROR_SUCCESS) {
  867. return make_error("Could not create registry server key %s - error %d (%s)",
  868. line, GetLastError(), ds_system_errmsg());
  869. }
  870. /* Create the SNMP Pathname value */
  871. sprintf(line, "%s\\%s", sroot, SNMP_PATH);
  872. Result = RegSetValueEx(hServerKey, VALUE_APP_PATH, 0, REG_SZ,
  873. line, strlen(line) + 1);
  874. RegCloseKey(hServerKey);
  875. /* write SNMP extension agent value to Microsoft SNMP Part of Registry) */
  876. sprintf(line, "%s\\%s", KEY_SERVICES, KEY_SNMP_SERVICE);
  877. Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  878. line,
  879. 0,
  880. KEY_ALL_ACCESS,
  881. &hServerKey);
  882. /* if its there set the value, otherwise go on to the next thing */
  883. if (Result == ERROR_SUCCESS)
  884. {
  885. /* extension agents should have linearly increasing value,
  886. make sure it doesn't already exist, find last one and increment
  887. value for new key */
  888. sprintf(line, "%s\\%s\\%s", KEY_SOFTWARE_NETSCAPE, SVR_KEY_ROOT, KEY_SNMP_CURRENTVERSION);
  889. Result = RegQueryInfoKey(hServerKey, NULL, NULL, NULL, NULL, NULL,
  890. NULL, &NumValues, NULL, NULL, NULL, NULL);
  891. if (Result == ERROR_SUCCESS){
  892. for(iterator = 0; iterator <= NumValues; iterator++)
  893. {
  894. /* initialize to max size to avoid
  895. ERROR_MORE_DATA because size gets set
  896. to actual size of key after call
  897. to RegQueryValueEx, previously there
  898. was a bug if last key was smaller
  899. than this one it would return ERROR_MORE_DATA
  900. and it would not find the key if it was already there
  901. */
  902. sizeof_value_data_buffer=MAX_PATH;
  903. sprintf(NumValuesBuf, "%d", iterator);
  904. Result = RegQueryValueEx(hServerKey,
  905. NumValuesBuf,
  906. NULL,
  907. &type_buffer,
  908. value_data_buffer,
  909. &sizeof_value_data_buffer
  910. );
  911. if(!strcmp(value_data_buffer, line))
  912. {
  913. value_already_exists = 1;
  914. }
  915. }
  916. }
  917. if(!value_already_exists)
  918. {
  919. sprintf(NumValuesBuf, "%d", NumValues + 1);
  920. Result = RegSetValueEx(hServerKey, NumValuesBuf, 0, REG_SZ,
  921. line, strlen(line) + 1);
  922. /* couldn't set this value, so there is a real problem */
  923. if (Result != ERROR_SUCCESS)
  924. {
  925. return make_error("Could not set value %s (%d)",
  926. line, Result);
  927. }
  928. }
  929. }
  930. RegCloseKey(hServerKey);
  931. return NULL;
  932. }
  933. #endif
  934. /* ---------------------- Create configuration files ---------------------- */
  935. char *create_server(server_config_s *cf, char *param_name)
  936. {
  937. char line[PATH_SIZE], *t, *sroot = cf->sroot;
  938. char subdir[PATH_SIZE];
  939. #if defined( SOLARIS )
  940. /*
  941. * Solaris 9+ specific installation
  942. */
  943. char otherline[PATH_SIZE];
  944. char subdirvar[PATH_SIZE];
  945. char subdiretc[PATH_SIZE];
  946. char *sub;
  947. #endif /* SOLARIS */
  948. if (param_name)
  949. param_name[0] = 0; /* init to empty string */
  950. #ifdef XP_UNIX
  951. if (!cf->servuser)
  952. getSuiteSpotUserGroup(cf);
  953. #else
  954. /* Abort if the service exists on NT */
  955. if (t = service_exists(cf->servid)) {
  956. strcpy(param_name, "servid");
  957. return t;
  958. }
  959. #endif
  960. if( (t = sanity_check(cf, param_name)) )
  961. return t;
  962. /* Create slapd-nickname directory */
  963. #if defined( SOLARIS )
  964. /*
  965. * Verify if configuration is for native solaris packages
  966. * This is because if console is used to create instance
  967. * then -S is not passed to ds_create.
  968. * <server_root>/.native_solaris file acts as the flag
  969. */
  970. if (!iDSISolaris) {
  971. sprintf(otherline, "%s%c.native_solaris", sroot, FILE_PATHSEP);
  972. if (create_instance_exists(otherline)) {
  973. iDSISolaris = 1;
  974. }
  975. }
  976. if (iDSISolaris) {
  977. /*
  978. * Create the slapd-nickname directory under "var"
  979. */
  980. sub = sub_token(sroot,"/usr/iplanet/",13,"/var/",5);
  981. if (sub) {
  982. sprintf(subdirvar, "%s/"PRODUCT_NAME"-%s", sub, cf->servid);
  983. free(sub);
  984. }
  985. else {
  986. sprintf(subdirvar, "%s/"PRODUCT_NAME"-%s", SOLARIS_VAR_DIR, cf->servid);
  987. }
  988. if( (create_instance_mkdir_p(subdirvar, NEWDIR_MODE)) )
  989. return make_error("mkdir %s failed (%s)", subdirvar, ds_system_errmsg());
  990. /*
  991. * Create the slapd-nickname directory under "etc"
  992. */
  993. sub = sub_token(sroot,"/usr/",5,"/etc/",5);
  994. if (sub) {
  995. sprintf(subdiretc, "%s/"PRODUCT_NAME"-%s", sub, cf->servid);
  996. free(sub);
  997. }
  998. else {
  999. sprintf(subdiretc, "%s/"PRODUCT_NAME"-%s", SOLARIS_ETC_DIR, cf->servid);
  1000. }
  1001. if( (create_instance_mkdir_p(subdiretc, NEWDIR_MODE)) )
  1002. return make_error("mkdir %s failed (%s)", subdiretc, ds_system_errmsg());
  1003. sprintf(subdir, "%s%c"PRODUCT_NAME"-%s", sroot, FILE_PATHSEP,
  1004. cf->servid);
  1005. if( (create_instance_symlink(subdirvar, subdir)) )
  1006. return make_error("symlink %s ==> %s failed (%s)", subdir, subdirvar, ds_system_errmsg());
  1007. }
  1008. else {
  1009. sprintf(subdir, "%s%c"PRODUCT_NAME"-%s", sroot, FILE_PATHSEP,
  1010. cf->servid);
  1011. if( (create_instance_mkdir(subdir, NEWDIR_MODE)) )
  1012. return make_error("mkdir %s failed (%s)", subdir, ds_system_errmsg());
  1013. }
  1014. #else
  1015. sprintf(subdir, "%s%c"PRODUCT_NAME"-%s", sroot, FILE_PATHSEP,
  1016. cf->servid);
  1017. if( (create_instance_mkdir(subdir, NEWDIR_MODE)) )
  1018. return make_error("mkdir %s failed (%s)", subdir, ds_system_errmsg());
  1019. #endif /* SOLARIS */
  1020. /* Create slapd-nickname/config directory */
  1021. sprintf(line, "%s%cconfig", subdir, FILE_PATHSEP);
  1022. if( (create_instance_mkdir(line, NEWDIR_MODE)) )
  1023. return make_error("mkdir %s failed (%s)", line, ds_system_errmsg());
  1024. #if defined( SOLARIS )
  1025. if (iDSISolaris) {
  1026. sprintf(line, "%s%cconfig", subdirvar, FILE_PATHSEP);
  1027. sprintf(otherline, "%s%cconfig", subdiretc, FILE_PATHSEP);
  1028. if( (create_instance_symlink(line, otherline)) )
  1029. return make_error("symlink %s ==> %s failed (%s)", otherline, line, ds_system_errmsg());
  1030. }
  1031. #endif /* SOLARIS */
  1032. /* Create slapd-nickname/config/schema directory */
  1033. sprintf(line, "%s%cconfig%cschema", subdir, FILE_PATHSEP, FILE_PATHSEP);
  1034. if( (create_instance_mkdir(line, NEWDIR_MODE)) )
  1035. return make_error("mkdir %s failed (%s)", line, ds_system_errmsg());
  1036. #if defined (BUILD_PRESENCE)
  1037. /* Create slapd-nickname/config/presence directory */
  1038. sprintf(line, "%s%cconfig%cpresence", subdir, FILE_PATHSEP, FILE_PATHSEP);
  1039. if( (create_instance_mkdir(line, NEWDIR_MODE)) )
  1040. return make_error("mkdir %s failed (%s)", line, ds_system_errmsg());
  1041. #endif
  1042. /* Create slapd-nickname/logs directory */
  1043. sprintf(line, "%s%clogs", subdir, FILE_PATHSEP);
  1044. if( (create_instance_mkdir(line, NEWSECDIR_MODE)) )
  1045. return make_error("mkdir %s failed (%s)", line, ds_system_errmsg());
  1046. /* Create httpacl directory */
  1047. sprintf(line, "%s%chttpacl", cf->sroot, FILE_PATHSEP);
  1048. if( (create_instance_mkdir(line, NEWDIR_MODE)) )
  1049. return make_error("mkdir %s failed (%s)", line, ds_system_errmsg());
  1050. #if defined( SOLARIS )
  1051. if (iDSISolaris)
  1052. logUninstallInfo(sroot, PRODUCT_NAME, PRODUCT_NAME, line);
  1053. #endif /* SOLARIS */
  1054. #ifdef XP_UNIX
  1055. /* Start/stop/rotate/restart scripts */
  1056. #if defined( SOLARIS )
  1057. if (getenv("USE_DEBUGGER") && !iDSISolaris)
  1058. #else
  1059. if (getenv("USE_DEBUGGER"))
  1060. #endif /* SOLARIS */
  1061. {
  1062. char *debugger = getenv("DSINST_DEBUGGER");
  1063. char *debugger_command = getenv("DSINST_DEBUGGER_CMD");
  1064. if (! debugger) {
  1065. debugger = "/tools/ns/workshop/bin/dbx";
  1066. }
  1067. if (! debugger_command) {
  1068. debugger_command = "echo"; /* e.g. do nothing */
  1069. }
  1070. #ifdef OSF1
  1071. printf("-D %s -i %s/logs/pid -d %s -z\n", subdir, subdir,
  1072. cf->loglevel ? cf->loglevel : "0");
  1073. t = gen_script(subdir, START_SCRIPT,
  1074. "\n"
  1075. "# Script that starts the ns-slapd server.\n"
  1076. "# Exit status can be:\n"
  1077. "# 0: Server started successfully\n"
  1078. "# 1: Server could not be started\n"
  1079. "# 2: Server already running\n"
  1080. "\n"
  1081. "NETSITE_ROOT=%s\n"
  1082. "export NETSITE_ROOT\n"
  1083. "PIDFILE=%s/logs/pid\n"
  1084. "if test -f $PIDFILE ; then\n"
  1085. " PID=`cat $PIDFILE`\n"
  1086. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1087. " echo There is an ns-slapd process already running: $PID\n"
  1088. " exit 2;\n"
  1089. " else\n"
  1090. " rm -f $PIDFILE\n"
  1091. " fi\n"
  1092. "fi\n"
  1093. "cd %s/bin/%s/server; ./%s -D %s -i %s/logs/pid -d %s -z \"$@\" &\n"
  1094. "loop_counter=1\n"
  1095. "max_count=120\n"
  1096. "while test $loop_counter -le $max_count; do\n"
  1097. " loop_counter=`expr $loop_counter + 1`\n"
  1098. " if test ! -f $PIDFILE ; then\n"
  1099. " sleep 1;\n"
  1100. " else\n"
  1101. " PID=`cat $PIDFILE`\n"
  1102. /* rbyrne: setupsdk takes any message here as an error:
  1103. " echo Server has been started. ns-slapd process started: $PID\n"*/
  1104. " exit 0;\n"
  1105. " fi\n"
  1106. "done\n"
  1107. "echo Server not running!! Failed to start ns-slapd process.\n"
  1108. "exit 1\n",
  1109. sroot, subdir, sroot, PRODUCT_NAME, PRODUCT_BIN, subdir,
  1110. subdir,
  1111. cf->loglevel ? cf->loglevel : "0"
  1112. );
  1113. /*
  1114. t = gen_script(subdir, START_SCRIPT,
  1115. "NETSITE_ROOT=%s\n"
  1116. "export NETSITE_ROOT\n"
  1117. "cd %s/bin/%s/server; /usr/bin/X11/xterm -fn 10x20 -sb -sl 2000 -e /bin/ladebug "
  1118. "-I /u/richm/ds50/ldapserver/ldap/servers/slapd/back-ldbm "
  1119. "-I /u/richm/ds50/ldapserver/ldap/servers/slapd "
  1120. "%s &\n",
  1121. sroot, sroot, PRODUCT_NAME, PRODUCT_BIN
  1122. );
  1123. */
  1124. #else
  1125. t = gen_script(subdir, START_SCRIPT,
  1126. "\n"
  1127. "# Script that starts the ns-slapd server.\n"
  1128. "# Exit status can be:\n"
  1129. "# 0: Server started successfully\n"
  1130. "# 1: Server could not be started\n"
  1131. "# 2: Server already running\n"
  1132. "\n"
  1133. "NETSITE_ROOT=%s\n"
  1134. "export NETSITE_ROOT\n"
  1135. "PIDFILE=%s/logs/pid\n"
  1136. "if test -f $PIDFILE ; then\n"
  1137. " PID=`cat $PIDFILE`\n"
  1138. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1139. " echo There is an ns-slapd process already running: $PID\n"
  1140. " exit 2;\n"
  1141. " else\n"
  1142. " rm -f $PIDFILE\n"
  1143. " fi\n"
  1144. "fi\n"
  1145. "if [ -x /usr/local/bin/xterm ]; then\n"
  1146. " xterm=/usr/local/bin/xterm\n"
  1147. "else\n"
  1148. " xterm=/usr/openwin/bin/xterm\n"
  1149. "fi\n"
  1150. "cd %s/bin/%s/server; $xterm -title debugger -e %s -c \"dbxenv follow_fork_mode child ; stop in main ; %s ; run -D %s -i %s/logs/pid -d %s -z $*\" %s &\n"
  1151. "loop_counter=1\n"
  1152. "max_count=120\n"
  1153. "while test $loop_counter -le $max_count; do\n"
  1154. " loop_counter=`expr $loop_counter + 1`\n"
  1155. " if test ! -f $PIDFILE ; then\n"
  1156. " sleep 1;\n"
  1157. " else\n"
  1158. " PID=`cat $PIDFILE`\n"
  1159. /* rbyrne: setupsdk takes any message here as an error:
  1160. " echo Server has been started. ns-slapd process started: $PID\n"*/
  1161. " exit 0;\n"
  1162. " fi\n"
  1163. "done\n"
  1164. "echo Server not running!! Failed to start ns-slapd process.\n"
  1165. "exit 1\n",
  1166. sroot, subdir, sroot, PRODUCT_NAME, debugger, debugger_command,
  1167. subdir,
  1168. subdir, cf->loglevel ? cf->loglevel : "0", PRODUCT_BIN
  1169. );
  1170. #endif
  1171. }
  1172. else
  1173. {
  1174. t = gen_script(subdir, START_SCRIPT,
  1175. "\n"
  1176. "# Script that starts the ns-slapd server.\n"
  1177. "# Exit status can be:\n"
  1178. "# 0: Server started successfully\n"
  1179. "# 1: Server could not be started\n"
  1180. "# 2: Server already running\n"
  1181. "\n"
  1182. "NETSITE_ROOT=%s\n"
  1183. "export NETSITE_ROOT\n"
  1184. "PIDFILE=%s/logs/pid\n"
  1185. "STARTPIDFILE=%s/logs/startpid\n"
  1186. "if test -f $STARTPIDFILE ; then\n"
  1187. " PID=`cat $STARTPIDFILE`\n"
  1188. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1189. " echo There is an ns-slapd process already running: $PID\n"
  1190. " exit 2;\n"
  1191. " else\n"
  1192. " rm -f $STARTPIDFILE\n"
  1193. " fi\n"
  1194. "fi\n"
  1195. "if test -f $PIDFILE ; then\n"
  1196. " PID=`cat $PIDFILE`\n"
  1197. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1198. " echo There is an ns-slapd process already running: $PID\n"
  1199. " exit 2;\n"
  1200. " else\n"
  1201. " rm -f $PIDFILE\n"
  1202. " fi\n"
  1203. "fi\n"
  1204. "cd %s/bin/%s/server; ./%s -D %s -i %s/logs/pid -w $STARTPIDFILE \"$@\"\n"
  1205. "if [ $? -ne 0 ]; then\n"
  1206. " exit 1\n"
  1207. "fi\n"
  1208. "\n"
  1209. "loop_counter=1\n"
  1210. "# wait for 10 seconds for the start pid file to appear\n"
  1211. "max_count=10\n"
  1212. "while test $loop_counter -le $max_count; do\n"
  1213. " loop_counter=`expr $loop_counter + 1`\n"
  1214. " if test ! -f $STARTPIDFILE ; then\n"
  1215. " sleep 1;\n"
  1216. " else\n"
  1217. " PID=`cat $STARTPIDFILE`\n"
  1218. " fi\n"
  1219. "done\n"
  1220. "if test ! -f $STARTPIDFILE ; then\n"
  1221. " echo Server failed to start !!! Please check errors log for problems\n"
  1222. " exit 1\n"
  1223. "fi\n"
  1224. "loop_counter=1\n"
  1225. "# wait for 10 minutes (600 times 1 seconds)\n"
  1226. "max_count=600\n" /* 10 minutes */
  1227. "while test $loop_counter -le $max_count; do\n"
  1228. " loop_counter=`expr $loop_counter + 1`\n"
  1229. " if test ! -f $PIDFILE ; then\n"
  1230. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1231. " sleep 1\n"
  1232. " else\n"
  1233. " echo Server failed to start !!! Please check errors log for problems\n"
  1234. " exit 1\n"
  1235. " fi\n"
  1236. " else\n"
  1237. " PID=`cat $PIDFILE`\n"
  1238. /* rbyrne: setupsdk takes any message here as an error:
  1239. " echo Server has been started. ns-slapd process started: $PID\n"*/
  1240. " exit 0;\n"
  1241. " fi\n"
  1242. "done\n"
  1243. "echo Server not running!! Failed to start ns-slapd process. Please check the errors log for problems.\n"
  1244. "exit 1\n",
  1245. sroot, subdir, subdir, sroot, PRODUCT_NAME, PRODUCT_BIN, subdir,
  1246. subdir
  1247. );
  1248. }
  1249. if(t) return t;
  1250. t = gen_script(subdir, STOP_SCRIPT,
  1251. "\n"
  1252. "# Script that stops the ns-slapd server.\n"
  1253. "# Exit status can be:\n"
  1254. "# 0: Server stopped successfully\n"
  1255. "# 1: Server could not be stopped\n"
  1256. "# 2: Server was not running\n"
  1257. "\n"
  1258. "PIDFILE=%s/logs/pid\n"
  1259. "if test ! -f $PIDFILE ; then\n"
  1260. " echo No ns-slapd PID file found. Server is probably not running\n"
  1261. " exit 2\n"
  1262. "fi\n"
  1263. "PID=`cat $PIDFILE`\n"
  1264. "# see if the server is already stopped\n"
  1265. "kill -0 $PID > /dev/null 2>&1 || {\n"
  1266. " echo Server not running\n"
  1267. " if test -f $PIDFILE ; then\n"
  1268. " rm -f $PIDFILE\n"
  1269. " fi\n"
  1270. " exit 2\n"
  1271. "}\n"
  1272. "# server is running - kill it\n"
  1273. "kill $PID\n"
  1274. "loop_counter=1\n"
  1275. "# wait for 10 minutes (600 times 1 second)\n"
  1276. "max_count=600\n" /* 10 minutes */
  1277. "while test $loop_counter -le $max_count; do\n"
  1278. " loop_counter=`expr $loop_counter + 1`\n"
  1279. " if kill -0 $PID > /dev/null 2>&1 ; then\n"
  1280. " sleep 1;\n"
  1281. " else\n"
  1282. " if test -f $PIDFILE ; then\n"
  1283. " rm -f $PIDFILE\n"
  1284. " fi\n"
  1285. /* rbyrne: setupsdk takes any message here as an error:
  1286. " echo Server has been stopped. ns-slapd process stopped: $PID\n"*/
  1287. " exit 0\n"
  1288. " fi\n"
  1289. "done\n"
  1290. "if test -f $PIDFILE ; then\n"
  1291. " echo Server still running!! Failed to stop the ns-slapd process: $PID. Please check the errors log for problems.\n"
  1292. "fi\n"
  1293. "exit 1\n",
  1294. subdir);
  1295. if(t) return t;
  1296. t = gen_script(subdir, RESTART_SCRIPT,
  1297. "\n"
  1298. "# Script that restarts the ns-slapd server.\n"
  1299. "# Exit status can be:\n"
  1300. "# 0: Server restarted successfully\n"
  1301. "# 1: Server could not be started\n"
  1302. "# 2: Server started successfully (was not running)\n"
  1303. "# 3: Server could not be stopped\n"
  1304. "\n"
  1305. "server_already_stopped=0\n"
  1306. "%s/stop-slapd\n"
  1307. "status=$?\n"
  1308. "if [ $status -eq 1 ] ; then\n"
  1309. " exit 3;\n"
  1310. "else\n"
  1311. " if [ $status -eq 2 ] ; then\n"
  1312. " server_already_stopped=1\n"
  1313. " fi\n"
  1314. "fi\n"
  1315. "%s/start-slapd\n"
  1316. "status=$?\n"
  1317. "if [ $server_already_stopped -eq 1 ] && [ $status -eq 0 ] ; then\n"
  1318. " exit 2;\n"
  1319. "fi\n"
  1320. "exit $status\n",
  1321. subdir, subdir );
  1322. if(t) return t;
  1323. /* logs subdir owned by server user */
  1324. if( (t = chownlogs(subdir, cf->servuser)) )
  1325. return t;
  1326. /* config subdir owned by server user */
  1327. if( (t = chownconfig(subdir, cf->servuser)) )
  1328. return t;
  1329. #if defined( SOLARIS )
  1330. if (iDSISolaris) {
  1331. /* Need to change owner of the etc link too */
  1332. if( (t = chownconfig(subdiretc, cf->servuser)) )
  1333. return t;
  1334. }
  1335. #endif /* SOLARIS */
  1336. #else /* XP_WIN32 */
  1337. /* Windows platforms have some extra setup */
  1338. if( (t = setup_ntserver(cf)) )
  1339. return t;
  1340. /* generate start script */
  1341. t = gen_script(subdir, START_SCRIPT".bat", "net start slapd-%s\n", cf->servid);
  1342. if(t) return t;
  1343. /* generate stop script */
  1344. t = gen_script(subdir, STOP_SCRIPT".bat", "net stop slapd-%s\n", cf->servid);
  1345. if(t) return t;
  1346. /* generate restart script */
  1347. t = gen_script(subdir, RESTART_SCRIPT".bat", "net stop slapd-%s\n"
  1348. "net start slapd-%s\n", cf->servid, cf->servid);
  1349. if(t) return t;
  1350. #endif /* XP_WIN32 */
  1351. #ifdef XP_WIN32
  1352. if ( INFO_GetOperatingSystem () == OS_WINNT ) {
  1353. if( (t = add_ntservice(cf)) )
  1354. return t;
  1355. }
  1356. #endif
  1357. /* Create subdirectories and config files for directory server */
  1358. if( (t = install_ds(sroot, cf, param_name)) )
  1359. return t;
  1360. /* XXXrobm using link to start script instead of automatically doing it */
  1361. return NULL;
  1362. }
  1363. /* ------------------------- Copied from libadmin ------------------------- */
  1364. /*
  1365. These replace the versions in libadmin to allow error returns.
  1366. XXXrobm because libadmin calls itself a lot, I'm replacing ALL the
  1367. functions this file requires
  1368. */
  1369. int create_instance_exists(char *fn)
  1370. {
  1371. struct stat finfo;
  1372. if(stat(fn, &finfo) < 0)
  1373. return 0;
  1374. else
  1375. return 1;
  1376. }
  1377. int create_instance_mkdir(char *dir, int mode)
  1378. {
  1379. if(!create_instance_exists(dir)) {
  1380. #ifdef XP_UNIX
  1381. if(mkdir(dir, mode) == -1)
  1382. #else /* XP_WIN32 */
  1383. if(!CreateDirectory(dir, NULL))
  1384. #endif /* XP_WIN32 */
  1385. return -1;
  1386. }
  1387. return 0;
  1388. }
  1389. char *create_instance_mkdir_p(char *dir, int mode)
  1390. {
  1391. static char errmsg[ERR_SIZE];
  1392. struct stat fi;
  1393. char *t;
  1394. #ifdef XP_UNIX
  1395. t = dir + 1;
  1396. #else /* XP_WIN32 */
  1397. t = dir + 3;
  1398. #endif /* XP_WIN32 */
  1399. while(1) {
  1400. t = strchr(t, FILE_PATHSEP);
  1401. if(t) *t = '\0';
  1402. if(stat(dir, &fi) == -1) {
  1403. if(create_instance_mkdir(dir, mode) == -1) {
  1404. sprintf(errmsg, "mkdir %s failed (%s)", dir, ds_system_errmsg());
  1405. return errmsg;
  1406. }
  1407. }
  1408. if(t)
  1409. {
  1410. *t = FILE_PATHSEP;
  1411. LDAP_UTF8INC(t);
  1412. }
  1413. else break;
  1414. }
  1415. return NULL;
  1416. }
  1417. int create_instance_numbers(char *target)
  1418. {
  1419. char *p;
  1420. for(p=target; *p; LDAP_UTF8INC(p) )
  1421. {
  1422. if(!ldap_utf8isdigit(p))
  1423. return 0;
  1424. }
  1425. return 1;
  1426. }
  1427. #if defined( SOLARIS )
  1428. /*
  1429. * Solaris 9+ specific installation
  1430. */
  1431. int create_instance_symlink(char *actualpath, char *sympath)
  1432. {
  1433. if(symlink(actualpath, sympath) == -1)
  1434. return -1;
  1435. return 0;
  1436. }
  1437. #endif /* SOLARIS */
  1438. /* --------------------------------- try* --------------------------------- */
  1439. /* robm This doesn't use net_ abstractions because they drag in SSL */
  1440. int trybind(char *addr, int port)
  1441. {
  1442. int sd;
  1443. struct sockaddr_in sa_server;
  1444. int ret;
  1445. #ifdef XP_WIN32
  1446. WSADATA wsd;
  1447. if(WSAStartup(MAKEWORD(1, 1), &wsd) != 0)
  1448. return -1;
  1449. #endif
  1450. if ((sd = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP)) == -1)
  1451. goto you_lose;
  1452. if (addr == NULL)
  1453. addr = "127.0.0.1"; /* use the local loopback address */
  1454. memset((char *) &sa_server, 0, sizeof(sa_server));
  1455. sa_server.sin_family=AF_INET;
  1456. sa_server.sin_addr.s_addr = inet_addr(addr);
  1457. sa_server.sin_port=htons((short)port);
  1458. ret = connect(sd, (struct sockaddr *) &sa_server,sizeof(sa_server));
  1459. if (ret == -1)
  1460. ret = 0; /* could not connect, so port is not in use; that's good */
  1461. else
  1462. {
  1463. ret = -1; /* connection succeeded, port in use, bad */
  1464. errno = EADDRINUSE;
  1465. }
  1466. #ifdef XP_UNIX
  1467. close(sd);
  1468. #else
  1469. closesocket(sd);
  1470. WSACleanup();
  1471. #endif
  1472. return ret;
  1473. you_lose:
  1474. #ifdef XP_WIN32
  1475. WSACleanup();
  1476. #endif
  1477. return -1;
  1478. }
  1479. #ifdef XP_UNIX
  1480. #include <pwd.h>
  1481. #include <fcntl.h>
  1482. int tryuser(char *user)
  1483. {
  1484. struct passwd *pw;
  1485. char fn[128];
  1486. int fd, ret;
  1487. setpwent();
  1488. if(!(pw = getpwnam(user)))
  1489. return -1;
  1490. endpwent();
  1491. if(geteuid())
  1492. return 0;
  1493. sprintf(fn, "/tmp/trychown.%ld", (long)getpid());
  1494. if( (fd = creat(fn, 0777)) == -1)
  1495. return 0; /* Hmm. */
  1496. ret = chown(fn, pw->pw_uid, pw->pw_gid);
  1497. close(fd);
  1498. unlink(fn);
  1499. return (ret == -1 ? -2 : 0);
  1500. }
  1501. #endif /* XP_UNIX */
  1502. /* --------------------------- create_instance_check* ---------------------------- */
  1503. char *create_instance_checkport(char *addr, char *sport)
  1504. {
  1505. int port;
  1506. port = atoi(sport);
  1507. if((port < 1) || (port > 65535)) {
  1508. return ("Valid port numbers are between 1 and 65535");
  1509. }
  1510. if(trybind(addr, port) == -1) {
  1511. if(errno == EADDRINUSE) {
  1512. return make_error("Port %d is already in use", port);
  1513. }
  1514. /* XXXrobm if admin server not running as root, you lose. */
  1515. else if(errno == EACCES) {
  1516. return ("Ports below 1024 require super user access. "
  1517. "You must run the installation as root to install "
  1518. "on that port.");
  1519. } else {
  1520. ds_report_warning(DS_WARNING, "port", "That port is not available");
  1521. }
  1522. }
  1523. return NULL;
  1524. }
  1525. #ifdef XP_UNIX
  1526. char *create_instance_checkuser(char *user)
  1527. {
  1528. if (user && *user) switch(tryuser(user)) {
  1529. case -1:
  1530. return make_error ("Can't find a user named '%s'."
  1531. "\nPlease select or create another user.",
  1532. user);
  1533. case -2:
  1534. return make_error ("Can't change a file to be owned by %s."
  1535. "\nPlease select or create another user.",
  1536. user);
  1537. }
  1538. return NULL;
  1539. }
  1540. #endif
  1541. /* --------------------------------- copy --------------------------------- */
  1542. #define COPY_BUFFER_SIZE 4096
  1543. #ifdef XP_UNIX
  1544. char *create_instance_copy(char *sfile, char *dfile, int mode)
  1545. {
  1546. int sfd, dfd, len;
  1547. struct stat fi;
  1548. char copy_buffer[COPY_BUFFER_SIZE];
  1549. unsigned long read_len;
  1550. /* Make sure we're in the right umask */
  1551. umask(022);
  1552. if( (sfd = open(sfile, O_RDONLY)) == -1)
  1553. return make_error("Cannot open %s for reading (%s)", sfile,
  1554. ds_system_errmsg());
  1555. fstat(sfd, &fi);
  1556. if(!(S_ISREG(fi.st_mode))) {
  1557. close(sfd);
  1558. return make_error("%s is not a regular file", sfile);
  1559. }
  1560. len = fi.st_size;
  1561. if( (dfd = open(dfile, O_RDWR | O_CREAT | O_TRUNC, mode)) == -1)
  1562. return make_error("Cannot open file %s for writing (%s)", dfile,
  1563. ds_system_errmsg());
  1564. while(len) {
  1565. read_len = len>COPY_BUFFER_SIZE?COPY_BUFFER_SIZE:len;
  1566. if ( (read_len = read(sfd, copy_buffer, read_len)) == -1) {
  1567. make_error("Cannot read from file %s (%s)",
  1568. sfile, ds_system_errmsg());
  1569. }
  1570. if ( write(dfd, copy_buffer, read_len) != read_len) {
  1571. make_error("Error writing to file %s from copy of %s (%s)",
  1572. dfile, sfile, ds_system_errmsg());
  1573. }
  1574. len -= read_len;
  1575. }
  1576. close(sfd);
  1577. close(dfd);
  1578. /* BERT! */
  1579. return NULL;
  1580. }
  1581. #else /* XP_WIN32 */
  1582. char *create_instance_copy(char *sfile, char *dfile, int mode)
  1583. {
  1584. HANDLE sfd, dfd, MapHandle;
  1585. PCHAR fp;
  1586. PCHAR fpBase;
  1587. DWORD BytesWritten = 0;
  1588. DWORD len;
  1589. if( (sfd = CreateFile(sfile, GENERIC_READ,
  1590. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
  1591. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))
  1592. == INVALID_HANDLE_VALUE) {
  1593. return make_error("Cannot open file %s for reading (%s)", sfile,
  1594. ds_system_errmsg());
  1595. }
  1596. len = GetFileSize(sfd, NULL);
  1597. if( (MapHandle = CreateFileMapping(sfd, NULL, PAGE_READONLY,
  1598. 0, 0, NULL)) == NULL) {
  1599. return make_error("Cannot create file mapping of %s (%s)", sfile,
  1600. ds_system_errmsg());
  1601. }
  1602. if (!(fpBase = fp = MapViewOfFile(MapHandle, FILE_MAP_READ, 0, 0, 0))) {
  1603. return make_error("Cannot map file %s (%s)", sfile, ds_system_errmsg());
  1604. }
  1605. if( (dfd = CreateFile(dfile, GENERIC_READ | GENERIC_WRITE,
  1606. FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_ALWAYS,
  1607. FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) {
  1608. return make_error("Cannot open destination file %s for writing (%s)",
  1609. dfile, ds_system_errmsg());
  1610. }
  1611. while ( len) {
  1612. if(!WriteFile(dfd, fp, len, &BytesWritten, NULL)) {
  1613. return ("Cannot write new file %s (%s)", dfile, ds_system_errmsg());
  1614. }
  1615. len -= BytesWritten;
  1616. fp += BytesWritten;
  1617. }
  1618. CloseHandle(sfd);
  1619. UnmapViewOfFile(fpBase);
  1620. CloseHandle(MapHandle);
  1621. FlushFileBuffers(dfd);
  1622. CloseHandle(dfd);
  1623. /* BERT! */
  1624. return NULL;
  1625. }
  1626. #endif
  1627. static int
  1628. file_is_type_x(const char *dirname, const char *filename, PRFileType x)
  1629. {
  1630. struct PRFileInfo inf;
  1631. int status = 0;
  1632. int size = strlen(dirname) + strlen(filename) + 2; /* 1 for slash + 1 for null */
  1633. char *fullpath = calloc(sizeof(char), size);
  1634. sprintf(fullpath, "%s/%s", dirname, filename);
  1635. if (PR_SUCCESS == PR_GetFileInfo(fullpath, &inf) &&
  1636. inf.type == x)
  1637. status = 1;
  1638. free(fullpath);
  1639. return status;
  1640. }
  1641. /* return true if the given path and file corresponds to a directory */
  1642. static int
  1643. is_a_dir(const char *dirname, const char *filename)
  1644. {
  1645. return file_is_type_x(dirname, filename, PR_FILE_DIRECTORY);
  1646. }
  1647. #if 0 /* not being used */
  1648. /* return true if the given path and file corresponds to a regular file */
  1649. static int
  1650. is_a_file(const char *dirname, const char *filename)
  1651. {
  1652. return file_is_type_x(dirname, filename, PR_FILE_FILE);
  1653. }
  1654. #endif
  1655. static char *
  1656. ds_copy_group_files_using_mode(char *src_dir, char *dest_dir,
  1657. char *filter, int use_mode)
  1658. {
  1659. char *t = 0;
  1660. PRDir *ds = 0;
  1661. PRDirEntry *d = 0;
  1662. char src_file[PATH_SIZE], dest_file[PATH_SIZE], fullname[PATH_SIZE];
  1663. if(!(ds = PR_OpenDir(src_dir))) {
  1664. return make_error("Can't read directory %s (%s)", src_dir, ds_system_errmsg());
  1665. }
  1666. while( (d = PR_ReadDir(ds, 0)) ) {
  1667. if(d->name[0] != '.') {
  1668. if(!filter || strstr(d->name, filter)) {
  1669. sprintf(fullname, "%s/%s", src_dir, d->name);
  1670. if(PR_SUCCESS != PR_Access(fullname, PR_ACCESS_EXISTS))
  1671. continue;
  1672. sprintf(src_file, "%s%c%s", src_dir, FILE_PATHSEP, d->name);
  1673. sprintf(dest_file, "%s%c%s", dest_dir, FILE_PATHSEP, d->name);
  1674. if(is_a_dir(src_dir, d->name)) {
  1675. char *sub_src_dir = strdup(src_file);
  1676. char *sub_dest_dir = strdup(dest_file);
  1677. if( (t = create_instance_mkdir_p(sub_dest_dir, NEWDIR_MODE)) )
  1678. return(t);
  1679. if( (t = ds_copy_group_files_using_mode(sub_src_dir, sub_dest_dir, filter, use_mode)) )
  1680. return t;
  1681. free(sub_src_dir);
  1682. free(sub_dest_dir);
  1683. }
  1684. else {
  1685. if( (t = create_instance_copy(src_file, dest_file, use_mode)) )
  1686. return t;
  1687. }
  1688. }
  1689. }
  1690. }
  1691. PR_CloseDir(ds);
  1692. return(NULL);
  1693. }
  1694. static char *
  1695. ds_copy_group_files(char *src_dir, char *dest_dir, char *filter)
  1696. {
  1697. return ds_copy_group_files_using_mode(src_dir, dest_dir, filter,
  1698. NEWFILE_MODE);
  1699. }
  1700. #if 0 /* not being used */
  1701. static char *
  1702. ds_copy_group_bins(char *src_dir, char *dest_dir, char *filter,
  1703. int use_mode)
  1704. {
  1705. return ds_copy_group_files_using_mode(src_dir, dest_dir, filter,
  1706. NEWSCRIPT_MODE);
  1707. }
  1708. #endif
  1709. /* this macro was copied from libldap/tmplout.c */
  1710. #define HREF_CHAR_ACCEPTABLE( c ) (( c >= '-' && c <= '9' ) || \
  1711. ( c >= '@' && c <= 'Z' ) || \
  1712. ( c == '_' ) || \
  1713. ( c >= 'a' && c <= 'z' ))
  1714. /* this function is based on libldap/tmplout.c:strcat_escaped */
  1715. void fputs_escaped(char *s, FILE *fp)
  1716. {
  1717. char *hexdig = "0123456789ABCDEF";
  1718. register unsigned char c;
  1719. for ( ; (c = *(unsigned char*)s); ++s ) {
  1720. if ( HREF_CHAR_ACCEPTABLE( c )) {
  1721. putc( c, fp );
  1722. } else {
  1723. fprintf( fp, "%%%c%c", hexdig[ (c >> 4) & 0x0F ], hexdig[ c & 0x0F ] );
  1724. }
  1725. }
  1726. }
  1727. /* ------------- Create config files for Directory Server -------------- */
  1728. char *ds_cre_subdirs(char *sroot, server_config_s *cf, char *cs_path,
  1729. struct passwd* pw)
  1730. {
  1731. char subdir[PATH_SIZE], *t = NULL;
  1732. /* create subdir <a_server>/db */
  1733. sprintf(subdir, "%s%cdb", cs_path, FILE_PATHSEP);
  1734. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1735. return(t);
  1736. chownfile (pw, subdir);
  1737. /* create subdir <a_server>/ldif */
  1738. sprintf(subdir, "%s%cldif", cs_path, FILE_PATHSEP);
  1739. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1740. return(t);
  1741. chownfile (pw, subdir);
  1742. /* create subdir <a_server>/dsml */
  1743. sprintf(subdir, "%s%cdsml", cs_path, FILE_PATHSEP);
  1744. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1745. return(t);
  1746. chownfile (pw, subdir);
  1747. /* create subdir <a_server>/bak */
  1748. sprintf(subdir, "%s%cbak", cs_path, FILE_PATHSEP);
  1749. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1750. return(t);
  1751. chownfile (pw, subdir);
  1752. /* Create slapd-nickname/confbak directory */
  1753. sprintf(subdir, "%s%cconfbak", cs_path, FILE_PATHSEP);
  1754. if( (t=create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1755. return(t);
  1756. chownfile (pw, subdir);
  1757. /* create subdir <server_root>/dsgw/context */
  1758. sprintf(subdir, "%s%cclients", sroot, FILE_PATHSEP);
  1759. if (is_a_dir(subdir, "dsgw")) { /* only create dsgw stuff if we are installing it */
  1760. sprintf(subdir, "%s%cclients%cdsgw%ccontext", sroot, FILE_PATHSEP,FILE_PATHSEP,FILE_PATHSEP);
  1761. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1762. return(t);
  1763. }
  1764. /* create subdir <server_root>/bin/slapd/authck */
  1765. sprintf(subdir, "%s%cbin%cslapd%cauthck", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  1766. if( (t = create_instance_mkdir_p(subdir, NEWDIR_MODE)) )
  1767. return(t);
  1768. #if defined( SOLARIS )
  1769. /*
  1770. * Solaris 9+ specific installation
  1771. */
  1772. if (iDSISolaris)
  1773. logUninstallInfo(sroot, PRODUCT_NAME, PRODUCT_NAME, subdir);
  1774. #endif /* SOLARIS */
  1775. return (t);
  1776. }
  1777. #define CREATE_LDIF2DB() \
  1778. gen_perl_script_auto(mysroot, mycs_path, "ldif2db.pl", cf)
  1779. #define CREATE_DB2INDEX() \
  1780. gen_perl_script_auto(mysroot, mycs_path, "db2index.pl", cf)
  1781. #define CREATE_DB2LDIF() \
  1782. gen_perl_script_auto(mysroot, mycs_path, "db2ldif.pl", cf)
  1783. #define CREATE_DB2BAK() \
  1784. gen_perl_script_auto(mysroot, mycs_path, "db2bak.pl", cf)
  1785. #define CREATE_BAK2DB() \
  1786. gen_perl_script_auto(mysroot, mycs_path, "bak2db.pl", cf)
  1787. #define CREATE_VERIFYDB() \
  1788. gen_perl_script_auto(mysroot, mycs_path, "verify-db.pl", cf)
  1789. #define CREATE_REPL_MONITOR_CGI() \
  1790. gen_perl_script_auto(mysroot, cgics_path, "repl-monitor-cgi.pl", cf)
  1791. #define CREATE_ACCOUNT_INACT(_commandName) \
  1792. gen_perl_script_auto(mysroot, cs_path, _commandName, cf)
  1793. #define CREATE_DSML() \
  1794. gen_perl_script_auto(mysroot, mycs_path, "dsml-activate.pl", cf)
  1795. #define CREATE_MIGRATETO5() \
  1796. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateTo5", cf)
  1797. #define CREATE_MIGRATE50TO51() \
  1798. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrate50to51", cf)
  1799. #define CREATE_MIGRATEINSTANCE5() \
  1800. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateInstance5", cf)
  1801. #define CREATE_MIGRATE5TO6() \
  1802. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrate5to6", cf)
  1803. #define CREATE_MIGRATEINSTANCE6() \
  1804. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateInstance6", cf)
  1805. #define CREATE_MIGRATETO6() \
  1806. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateTo6", cf)
  1807. #define CREATE_MIGRATE5TO7() \
  1808. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrate5to7", cf)
  1809. #define CREATE_MIGRATE6TO7() \
  1810. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrate6to7", cf)
  1811. #define CREATE_MIGRATEINSTANCE7() \
  1812. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateInstance7", cf)
  1813. #define CREATE_MIGRATETO7() \
  1814. gen_perl_script_auto_for_migration(mysroot, mycs_path, "migrateTo7", cf)
  1815. #define CREATE_NEWPWPOLICY() \
  1816. gen_perl_script_auto(mysroot, mycs_path, "ns-newpwpolicy.pl", cf)
  1817. #ifdef XP_UNIX
  1818. char *ds_gen_scripts(char *sroot, server_config_s *cf, char *cs_path)
  1819. {
  1820. char *t = NULL;
  1821. char server[PATH_SIZE], admin[PATH_SIZE], tools[PATH_SIZE];
  1822. char cgics_path[PATH_SIZE];
  1823. char *cl_scripts[7] = {"dsstop", "dsstart", "dsrestart", "dsrestore", "dsbackup", "dsimport", "dsexport"};
  1824. char *cl_javafiles[7] = {"DSStop", "DSStart", "DSRestart", "DSRestore", "DSBackup", "DSImport", "DSExport"};
  1825. int cls = 0; /*Index into commandline script names and java names - RJP*/
  1826. char *mysroot, *mycs_path;
  1827. #if defined( SOLARIS )
  1828. /*
  1829. * Solaris 9+ specific installation
  1830. */
  1831. char fn[PATH_SIZE];
  1832. #endif /* SOLARIS */
  1833. mysroot = sroot;
  1834. mycs_path = cs_path;
  1835. sprintf(server, "%s/bin/"PRODUCT_NAME"/server", sroot);
  1836. sprintf(admin, "%s/bin/"PRODUCT_NAME"/admin/bin", sroot);
  1837. sprintf(tools, "%s/shared/bin", sroot);
  1838. sprintf(cgics_path, "%s%cbin%cadmin%cadmin%cbin", sroot,
  1839. FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  1840. t = gen_script(cs_path, "monitor",
  1841. "if [ \"x$1\" != \"x\" ];\nthen MDN=\"$1\";\nelse MDN=\"cn=monitor\";\n fi\n"
  1842. "cd %s\nPATH=%s:$PATH;export PATH\n"
  1843. "ldapsearch -p %s -b \"$MDN\" -s base \"objectClass=*\"\n",
  1844. tools, tools, cf->servport);
  1845. if(t) return t;
  1846. t = gen_script(cs_path, "saveconfig",
  1847. "cd %s\n"
  1848. "echo saving configuration ...\n"
  1849. "conf_ldif=%s/confbak/`date +%%Y_%%m_%%d_%%H%%M%%S`.ldif\n"
  1850. "./ns-slapd db2ldif -N -D %s "
  1851. "-s \"%s\" -a $conf_ldif -n NetscapeRoot 2>&1\n"
  1852. "if [ \"$?\" -ge 1 ] \nthen\n"
  1853. " echo Error occurred while saving configuration\n"
  1854. " exit 1\n"
  1855. "fi\n"
  1856. "exit 0\n",
  1857. server, cs_path, cs_path, cf->netscaperoot);
  1858. if(t) return t;
  1859. t = gen_script(cs_path, "restoreconfig",
  1860. "cd %s\n"
  1861. "conf_ldif=`ls -1t %s/confbak/*.ldif | head -1`\n"
  1862. "if [ -z \"$conf_ldif\" ]\n"
  1863. "then\n"
  1864. " echo No configuration to restore in %s/confbak ; exit 1\n"
  1865. "fi\n"
  1866. "echo Restoring $conf_ldif\n"
  1867. "./ns-slapd ldif2db -D %s"
  1868. " -i $conf_ldif -n NetscapeRoot 2>&1\n"
  1869. "exit $?\n",
  1870. server, cs_path, cs_path, cs_path);
  1871. if(t) return t;
  1872. t = gen_script(cs_path, "ldif2db",
  1873. "cd %s\n"
  1874. "if [ $# -lt 4 ]\nthen\n"
  1875. "\techo \"Usage: ldif2db -n backend_instance | {-s includesuffix}* [{-x excludesuffix}*]\"\n"
  1876. "\techo \" {-i ldiffile}* [-O]\"\n"
  1877. "\techo \"Note: either \\\"-n backend_instance\\\" or \\\"-s includesuffix\\\" and \\\"-i ldiffile\\\" are required.\"\n"
  1878. "\texit 1\n"
  1879. "fi\n\n"
  1880. "echo importing data ...\n"
  1881. "./ns-slapd ldif2db -D %s \"$@\" 2>&1\n"
  1882. "exit $?\n",
  1883. server, cs_path);
  1884. if(t) return t;
  1885. #if defined(UPGRADEDB)
  1886. t = gen_script(cs_path, "upgradedb",
  1887. "cd %s\n"
  1888. "if [ \"$#\" -eq 1 ]\nthen\n"
  1889. "\tbak_dir=$1\nelse\n"
  1890. "\tbak_dir=%s/bak/upgradedb_`date +%%Y_%%m_%%d_%%H_%%M_%%S`\nfi\n\n"
  1891. "echo upgrade index files ...\n"
  1892. "./ns-slapd upgradedb -D %s -a $bak_dir\n",
  1893. server, cs_path, cs_path);
  1894. if(t) return t;
  1895. #endif
  1896. /* new code for dsml import */
  1897. t = gen_script(cs_path, "dsml2db",
  1898. "cd %s\n"
  1899. "if [ $# -lt 4 ]\nthen\n"
  1900. "\techo \"Usage: dsml2db -n backend_instance | {-s includesuffix}* [{-x excludesuffix}*]\"\n"
  1901. "\techo \" {-i dsmlfile}\"\n"
  1902. "\techo \"Note: either \\\"-n backend_instance\\\" or \\\"-s includesuffix\\\" and \\\"-i dsmlfile\\\" are required.\"\n"
  1903. "\texit 1\n"
  1904. "fi\n\n"
  1905. "set_dsml=0\n"
  1906. "dsml_file=\"mydummy\"\n"
  1907. "space=\" \"\n"
  1908. "i=0\n"
  1909. "for arg in \"$@\"\ndo\n"
  1910. "\tif [ \"$arg\" = '-i' ];\n\tthen\n"
  1911. "\t\tset_dsml=1\n"
  1912. "\telif [ $set_dsml -eq 1 ];\n\tthen\n"
  1913. "\t\tdsml_file=$arg\n"
  1914. "\t\tset_dsml=2\n"
  1915. "\telse\n"
  1916. "\t\teval a$i=\\\"$arg\\\"\n"
  1917. "\t\ti=`expr $i + 1`\n"
  1918. "\tfi\n"
  1919. "done\n"
  1920. "max=$i; i=0;\n"
  1921. "shift $#\n"
  1922. "while [ $i -lt $max ]; do\n"
  1923. "\teval arg=\\$a$i\n"
  1924. "\tset -- \"$@\" \"$arg\"\n"
  1925. "\ti=`expr $i + 1`\n"
  1926. "done\n"
  1927. "\tif [ $dsml_file = \"mydummy\" ]\n\tthen\n\t"
  1928. "echo \"Need a DSML file as input\""
  1929. "\n\t\t exit 1"
  1930. "\n\tfi\n"
  1931. "\tif [ -f $dsml_file ] && [ -r $dsml_file ]\n\tthen\n"
  1932. "\t\t%s/bin/base/jre/bin/java -Dverify=true -classpath %s/java/jars/crimson.jar:%s/java/ldapjdk.jar:%s/java/jars/xmltools.jar com.netscape.xmltools.DSML2LDIF $dsml_file\n"
  1933. "\t\tif [ $? = 0 ]; then\n"
  1934. "\t\techo importing data ...\n"
  1935. "\t\t%s/bin/base/jre/bin/java -classpath %s/java/jars/crimson.jar:%s/java/ldapjdk.jar:%s/java/jars/xmltools.jar com.netscape.xmltools.DSML2LDIF $dsml_file | ./ns-slapd ldif2db -D %s \"$@\" -i -\n"
  1936. "\t\texit $?\n"
  1937. "\t\tfi\n"
  1938. "\telse\n"
  1939. "\t\techo \"File $dsml_file invalid. Absolute path is required.\"\n\t\texit 1\n"
  1940. "\tfi\n",
  1941. server,sroot,sroot,sroot,sroot,sroot,sroot,sroot,sroot,cs_path);
  1942. if(t) return t;
  1943. t = gen_script(cs_path, "ldif2ldap",
  1944. "cd %s\n"
  1945. "./ldapmodify -a -p %s -D \"$1\" -w \"$2\" -f $3\n",
  1946. tools, cf->servport);
  1947. if(t) return t;
  1948. t = CREATE_LDIF2DB();
  1949. if(t) return t;
  1950. t = CREATE_DB2INDEX();
  1951. if(t) return t;
  1952. /*
  1953. t = CREATE_MIGRATETO5();
  1954. if(t) return t;
  1955. t = CREATE_MIGRATE50TO51();
  1956. if(t) return t;
  1957. t = CREATE_MIGRATEINSTANCE5();
  1958. if(t) return t;
  1959. t = CREATE_MIGRATE5TO6();
  1960. if(t) return t;
  1961. t = CREATE_MIGRATEINSTANCE6();
  1962. if(t) return t;
  1963. t = CREATE_MIGRATETO6();
  1964. if(t) return t;
  1965. */
  1966. t = CREATE_MIGRATE5TO7();
  1967. if(t) return t;
  1968. t = CREATE_MIGRATE6TO7();
  1969. if(t) return t;
  1970. t = CREATE_MIGRATEINSTANCE7();
  1971. if(t) return t;
  1972. t = CREATE_MIGRATETO7();
  1973. if(t) return t;
  1974. t = gen_script(cs_path, "getpwenc",
  1975. "cd %s\n"
  1976. "PATH=%s:$PATH;export PATH\n"
  1977. "if [ $# -lt 2 ]\n"
  1978. "then\n"
  1979. "\techo \"Usage: getpwenc scheme passwd\"\n"
  1980. "\texit 1\n"
  1981. "fi\n\n"
  1982. "pwdhash -D %s -H -s \"$@\"\n",
  1983. server, server, cs_path);
  1984. if(t) return t;
  1985. t = gen_script(cs_path, "db2ldif",
  1986. "cd %s\n"
  1987. "if [ \"$#\" -lt 2 ];\nthen\n"
  1988. "\techo \"Usage: db2ldif {-n backend_instance}* | {-s includesuffix}*\"\n"
  1989. "\techo \" [{-x excludesuffix}*] [-a outputfile]\"\n"
  1990. "\techo \" [-N] [-r] [-C] [-u] [-U] [-m] [-M] [-1]\"\n"
  1991. "\techo \"Note: either \\\"-n backend_instance\\\" or \\\"-s includesuffix\\\" is required.\"\n"
  1992. "\texit 1\n"
  1993. "fi\n\n"
  1994. "set_ldif=0\n"
  1995. "ldif_file=\"mydummy\"\n"
  1996. "for arg in \"$@\"\ndo\n"
  1997. "\tif [ \"$arg\" = '-a' ];\n\tthen\n"
  1998. "\t\tset_ldif=1\n"
  1999. "\telif [ $set_ldif -eq 1 ];\n\tthen\n"
  2000. "\t\tldif_file=$arg\n"
  2001. "\t\tset_ldif=2\n"
  2002. "\tfi\n"
  2003. "done\n"
  2004. "if [ $ldif_file = \"mydummy\" ]\nthen\n"
  2005. "\tldif_file=%s/ldif/`date +%%Y_%%m_%%d_%%H%%M%%S`.ldif\nfi\n"
  2006. "if [ $set_ldif -eq 2 ]\nthen\n"
  2007. "./ns-slapd db2ldif -D %s \"$@\"\nelse\n"
  2008. "./ns-slapd db2ldif -D %s -a $ldif_file \"$@\"\nfi\n",
  2009. server, cs_path, cs_path, cs_path);
  2010. if(t) return t;
  2011. /* new code for dsml export */
  2012. t = gen_script(cs_path, "db2dsml",
  2013. "cd %s\n"
  2014. "if [ \"$#\" -lt 2 ];\nthen\n"
  2015. "\techo \"Usage: db2dsml {-n backend_instance} | {-s includesuffix}*\"\n"
  2016. "\techo \" [{-x excludesuffix}*] [-a outputfile]\"\n"
  2017. "\techo \" [-u]\"\n"
  2018. "\techo \"Note: either \\\"-n backend_instance\\\" or \\\"-s includesuffix\\\" is required.\"\n"
  2019. "\texit 1\n"
  2020. "fi\n\n"
  2021. "set_dsml=0\n"
  2022. "dsml_file=\"mydummy\"\n"
  2023. "arg_list=\"\"\n"
  2024. "space=\" \"\n"
  2025. "for arg in \"$@\"\ndo\n"
  2026. "\tif [ \"$arg\" = '-a' ];\n\tthen\n"
  2027. "\t\tset_dsml=1\n"
  2028. "\telif [ $set_dsml -eq 1 ];\n\tthen\n"
  2029. "\t\tdsml_file=$arg\n"
  2030. "\t\tset_dsml=2\n"
  2031. "\telse\n"
  2032. "\t\targ_list=$arg_list$space$arg\n"
  2033. "\tfi\n"
  2034. "done\n"
  2035. "if [ $dsml_file = \"mydummy\" ]\nthen\n"
  2036. "\tdsml_file=%s/dsml/`date +%%Y_%%m_%%d_%%H%%M%%S`.dsml\n"
  2037. "\techo dsmlfile: $dsml_file\n"
  2038. "fi\n"
  2039. "%s/bin/base/jre/bin/java -Dverify=true -classpath %s/java/ldapjdk.jar:%s/java/jars/xmltools.jar com.netscape.xmltools.LDIF2DSML -s -o $dsml_file \n"
  2040. "if [ $? = 0 ]; then\n"
  2041. "\t./ns-slapd db2ldif -D %s \"$@\" -a - | %s/bin/base/jre/bin/java -classpath %s/java/ldapjdk.jar:%s/java/jars/xmltools.jar com.netscape.xmltools.LDIF2DSML -s -o $dsml_file \n"
  2042. "fi\n",
  2043. server, cs_path, sroot, sroot, sroot, cs_path, sroot, sroot, sroot);
  2044. if(t) return t;
  2045. t = CREATE_DB2LDIF();
  2046. if(t) return t;
  2047. #if defined(UPGRADEDB)
  2048. t = gen_script(cs_path, "db2index",
  2049. "cd %s\n"
  2050. "if [ $# -eq 0 ]\n"
  2051. "then\n"
  2052. "\tbak_dir=%s/bak/reindex_`date +%%Y_%%m_%%d_%%H_%%M_%%S`\n"
  2053. "\t./ns-slapd upgradedb -D %s -f -a \"$bak_dir\"\n"
  2054. "elif [ $# -lt 4 ]\n"
  2055. "then\n"
  2056. "\techo \"Usage: db2index [-n backend_instance | {-s includesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]\"\n"
  2057. "\texit 1\n"
  2058. "else\n"
  2059. "\t./ns-slapd db2index -D %s \"$@\"\n"
  2060. "fi\n\n",
  2061. server, cs_path, cs_path, cs_path);
  2062. if(t) return t;
  2063. #endif
  2064. t = gen_script(cs_path, "vlvindex",
  2065. "cd %s\n"
  2066. "if [ $# -lt 4 ]\n"
  2067. "then\n"
  2068. "\techo \"Usage: vlvindex -n backend_instance | {-s includesuffix}* -T attribute\"\n"
  2069. "\techo Note: either \\\"-n backend_instance\\\" or \\\"-s includesuffix\\\" are required.\n"
  2070. "\texit 1\n"
  2071. "fi\n\n"
  2072. "./ns-slapd db2index -D %s \"$@\"\n",
  2073. server, cs_path);
  2074. if(t) return t;
  2075. t = gen_script(cs_path, "db2bak",
  2076. "cd %s\n"
  2077. "if [ \"$#\" -eq 1 ]\nthen\n"
  2078. "\tbak_dir=$1\nelse\n"
  2079. "\tbak_dir=%s/bak/`date +%%Y_%%m_%%d_%%H_%%M_%%S`\nfi\n\n"
  2080. "./ns-slapd db2archive -D %s -a $bak_dir\n",
  2081. server, cs_path, cs_path);
  2082. if(t) return t;
  2083. t = CREATE_DB2BAK();
  2084. if(t) return t;
  2085. t = gen_script(cs_path, "bak2db",
  2086. "if [ $# -lt 1 ] || [ $# -gt 3 ]\nthen\n"
  2087. " echo \"Usage: bak2db archivedir [-n backendname]\"\n"
  2088. " exit 1\n"
  2089. "else\n"
  2090. " archivedir=$1\n"
  2091. " shift\n"
  2092. "fi\n"
  2093. "while getopts \"n:\" flag\ndo\n"
  2094. " case $flag in\n"
  2095. " n) bename=$OPTARG;;\n"
  2096. " *) echo \"Usage: bak2db archivedir [-n backendname]\"; exit 2;;\n"
  2097. " esac\n"
  2098. "done\n\n"
  2099. "if [ 1 = `expr $archivedir : \"\\/\"` ]\nthen\n"
  2100. " archivedir=$archivedir\n"
  2101. "else\n"
  2102. " # relative\n"
  2103. " archivedir=`pwd`/$archivedir\nfi\n\n"
  2104. "cd %s\n"
  2105. "if [ \"$#\" -eq 2 ]\nthen\n"
  2106. " ./ns-slapd archive2db -D %s -a $archivedir -n $bename\n"
  2107. "else\n"
  2108. " ./ns-slapd archive2db -D %s -a $archivedir\n"
  2109. "fi\n",
  2110. server, cs_path, cs_path);
  2111. if(t) return t;
  2112. t = CREATE_BAK2DB();
  2113. if(t) return t;
  2114. t = CREATE_VERIFYDB();
  2115. if(t) return t;
  2116. t = CREATE_REPL_MONITOR_CGI();
  2117. if(t) return t;
  2118. t = CREATE_ACCOUNT_INACT("ns-inactivate.pl");
  2119. if(t) return t;
  2120. t = CREATE_ACCOUNT_INACT("ns-activate.pl");
  2121. if(t) return t;
  2122. t = CREATE_ACCOUNT_INACT("ns-accountstatus.pl");
  2123. if(t) return t;
  2124. t = CREATE_DSML();
  2125. if(t) return t;
  2126. t = CREATE_NEWPWPOLICY();
  2127. if(t) return t;
  2128. t = gen_script(cs_path, "suffix2instance",
  2129. "cd %s\n"
  2130. "if [ $# -lt 2 ]\n"
  2131. "then\n"
  2132. "\techo Usage: suffix2instance {-s includesuffix}*\n"
  2133. "\texit 1\n"
  2134. "fi\n\n"
  2135. "./ns-slapd suffix2instance -D %s \"$@\" 2>&1\n",
  2136. server, cs_path);
  2137. if(t) return t;
  2138. /*Generate the java commandline tools in bin/slapd/server*/
  2139. for (cls = 0; cls < 7; cls++) {
  2140. t = gen_script(server, cl_scripts[cls],
  2141. "cd %s\n\n"
  2142. "lang=${LANG:=en}\n"
  2143. "while [ $# -ge 1 ]\n"
  2144. "do\n"
  2145. " if [ $1 = '-l' ]\n"
  2146. " then\n"
  2147. " shift\n"
  2148. " lang=$1\n"
  2149. " else\n"
  2150. " arg=\"$arg $1\"\n"
  2151. " fi\n"
  2152. " shift\n"
  2153. "done\n"
  2154. "./bin/base/jre/bin/jre -classpath ./bin/base/jre/lib:"
  2155. "./bin/base/jre/lib/rt.jar:./bin/base/jre/lib/i18n.jar:"
  2156. "./java/base.jar:./java/jars/ds40.jar:./java/jars/ds40_${lang}.jar:"
  2157. "./java/swingall.jar:./java/ssl.zip:"
  2158. "./java/ldapjdk.jar:./java/mcc40.jar:./java/mcc40_${lang}.jar:"
  2159. "./java/nmclf40.jar:./java/nmclf40_${lang}.jar"
  2160. " com.netscape.admin.dirserv.cmdln.%s $arg\n",
  2161. sroot, cl_javafiles[cls]);
  2162. if(t) return t;
  2163. #if defined( SOLARIS )
  2164. /*
  2165. * Solaris 9+ specific installation
  2166. */
  2167. if (iDSISolaris)
  2168. {
  2169. sprintf(fn, "%s/%s", server, cl_scripts[cls]);
  2170. logUninstallInfo(sroot, PRODUCT_NAME, PRODUCT_NAME, fn);
  2171. }
  2172. #endif /* SOLARIS */
  2173. }
  2174. return (t);
  2175. }
  2176. #else
  2177. char *ds_gen_scripts(char *sroot, server_config_s *cf, char *cs_path)
  2178. {
  2179. char *t = NULL;
  2180. char server[PATH_SIZE], admin[PATH_SIZE], tools[PATH_SIZE];
  2181. char cgics_path[PATH_SIZE];
  2182. char *cl_scripts[7] = {"dsstop.bat", "dsstart.bat", "dsrestart.bat", "dsrestore.bat", "dsbackup.bat", "dsimport.bat", "dsexport.bat"};
  2183. char *cl_javafiles[7] = {"DSStop", "DSStart", "DSRestart", "DSRestore", "DSBackup", "DSImport", "DSExport"};
  2184. int cls = 0; /*Index into commandline script names and java names - RJP*/
  2185. char *mysroot, *mycs_path;
  2186. {
  2187. char *p, *q;
  2188. int n;
  2189. for (n = 0, p = sroot; p = strchr(p, '/'); n++, p++) ;
  2190. for (p = sroot; p = strchr(p, '\\'); n++, p++) ;
  2191. mysroot = (char *)malloc(strlen(sroot) + n + 1);
  2192. for (p = sroot, q = mysroot; *p; p++, q++) {
  2193. if ('/' == *p || '\\' == *p) {
  2194. *q++ = '\\';
  2195. *q = '\\';
  2196. } else
  2197. *q = *p;
  2198. }
  2199. *q = '\0';
  2200. for (n = 0, p = cs_path; p = strchr(p, '/'); n++, p++) ;
  2201. for (p = cs_path; p = strchr(p, '\\'); n++, p++) ;
  2202. mycs_path = (char *)malloc(strlen(cs_path) + n + 1);
  2203. for (p = cs_path, q = mycs_path; *p; p++, q++) {
  2204. if ('/' == *p || '\\' == *p) {
  2205. *q++ = '\\';
  2206. *q = '\\';
  2207. } else
  2208. *q = *p;
  2209. }
  2210. *q = '\0';
  2211. }
  2212. sprintf(server, "%s/bin/"PRODUCT_NAME"/server", sroot);
  2213. sprintf(admin, "%s/bin/"PRODUCT_NAME"/admin/bin", sroot);
  2214. sprintf(tools, "%s/shared/bin", sroot);
  2215. sprintf(cgics_path, "%s/bin/admin/admin/bin", sroot);
  2216. ds_unixtodospath( cs_path );
  2217. ds_unixtodospath( server );
  2218. ds_unixtodospath( admin );
  2219. ds_unixtodospath( sroot );
  2220. ds_unixtodospath( tools );
  2221. ds_unixtodospath( cgics_path );
  2222. t = gen_script(cs_path, "monitor.bat",
  2223. "@echo off\n"
  2224. "setlocal\n"
  2225. "set rc=0\n"
  2226. "if %%1.==. goto noparam\n"
  2227. "\"%s\\ldapsearch\" -p %s -b %%1 "
  2228. "-s base \"objectClass=*\"\n"
  2229. "set rc=%%errorlevel%%\n"
  2230. "goto proceed\n"
  2231. ":noparam\n"
  2232. "\"%s\\ldapsearch\" -p %s -b \"cn=monitor\" "
  2233. "-s base \"objectClass=*\"\n"
  2234. "set rc=%%errorlevel%%\n"
  2235. ":proceed\n"
  2236. "if defined MKSARGS exit %%rc%%\n"
  2237. "exit /b %%rc%%\n",
  2238. tools, cf->servport, tools, cf->servport);
  2239. if(t) return t;
  2240. t = gen_script(cs_path, "saveconfig.bat",
  2241. "@echo off\n"
  2242. "setlocal\n"
  2243. "set rc=0\n"
  2244. "PATH=\"%s\";%%PATH%%\n"
  2245. "namegen\n"
  2246. "call bstart\n"
  2247. "set config_ldif=%s\\confbak\\%%DATESTR%%.ldif\n"
  2248. "call bend\n"
  2249. "del bend.bat\n"
  2250. "slapd db2ldif -s \"%s\" -a \"%%config_ldif%%\" -N"
  2251. " -D \"%s\" -n NetscapeRoot 2>&1\n"
  2252. "set rc=%%errorlevel%%\n"
  2253. "if %%rc%%==0 goto done\n"
  2254. "echo Error occurred while saving configuration\n"
  2255. ":done\n"
  2256. "if defined MKSARGS exit %%rc%%\n"
  2257. "exit /b %%rc%%\n",
  2258. server, cs_path, cf->netscaperoot, cs_path);
  2259. if(t) return t;
  2260. t = gen_script(cs_path, "restoreconfig.bat",
  2261. "@echo off\n"
  2262. "setlocal\n"
  2263. "set rc=0\n"
  2264. "PATH=\"%s\";%%PATH%%\n"
  2265. "set latestscript=%s\\latest_config.bat\n"
  2266. "if EXIST \"%%latestscript%%\" del \"%%latestscript%%\"\n"
  2267. "latest_file \"%s\\confbak\\*.ldif\" \"%%latestscript%%\"\n"
  2268. "if not EXIST \"%%latestscript%%\" goto noconfig\n"
  2269. "call \"%%latestscript%%\"\n"
  2270. "del \"%%latestscript%%\"\n"
  2271. "slapd ldif2db -D \"%s\" -i \"%%LATEST_FILE%%\""
  2272. " -n NetscapeRoot 2>&1\n"
  2273. "set rc=%%errorlevel%%\n"
  2274. "if %%rc%%==0 goto done\n"
  2275. "echo Error occurred while saving configuration\n"
  2276. "goto done\n"
  2277. ":noconfig\n"
  2278. "set rc=0\n" /* no error */
  2279. "echo No configuration to restore in %s\\confbak\n"
  2280. ":done\n"
  2281. "if defined MKSARGS exit %%rc%%\n"
  2282. "exit /b %%rc%%\n",
  2283. server, cs_path, cs_path, cs_path, cs_path);
  2284. if(t) return t;
  2285. t = gen_script(cs_path, "ldif2db.bat",
  2286. "@if not \"%%echo%%\" == \"on\" echo off\n"
  2287. "setlocal\n"
  2288. "set rc=0\n"
  2289. "PATH=\"%s\";%%PATH%%\n\n"
  2290. "set noconfig=0\n"
  2291. "if [%%2] == [] goto incorrect\n"
  2292. "if [%%3] == [] goto incorrect\n"
  2293. "if [%%4] == [] goto incorrect\n\n"
  2294. "set args=\n"
  2295. ":getargs\n"
  2296. "if [%%1] == [] goto import\n"
  2297. "set args=%%args%% %%1\n"
  2298. "shift\n"
  2299. "goto getargs\n\n"
  2300. ":incorrect\n"
  2301. ":usage\n"
  2302. "echo \"Usage: ldif2db -n backend_instance | {-s \"includesuffix\"}* "
  2303. "{-i ldif-file}* [-O] [{-x \"excludesuffix\"}*]\"\n"
  2304. "set rc=1\n"
  2305. "goto done\n\n"
  2306. ":import\n"
  2307. "echo importing data ...\n"
  2308. "slapd ldif2db -D \"%s\" %%args%% 2>&1\n\n"
  2309. "set rc=%%errorlevel%%\n"
  2310. ":done\n"
  2311. "if defined MKSARGS exit %%rc%%\n"
  2312. "exit /b %%rc%%\n",
  2313. server, cs_path);
  2314. if(t) return t;
  2315. /* new code for dsml import */
  2316. t = gen_script(cs_path, "dsml2db.bat",
  2317. "@if not \"%%echo%%\" == \"on\" echo off\n"
  2318. "setlocal\n"
  2319. "set rc=0\n"
  2320. "PATH=\"%s\";%%PATH%%\n\n"
  2321. "set noconfig=0\n"
  2322. "if [%%2] == [] goto incorrect\n"
  2323. "if [%%3] == [] goto incorrect\n"
  2324. "if [%%4] == [] goto incorrect\n\n"
  2325. "set args=\n"
  2326. "goto getargs\n"
  2327. ":setdsml\n"
  2328. "set dsmlfile=\n"
  2329. "set dsmlfile=%%2\n"
  2330. "shift\n"
  2331. "shift\n"
  2332. "goto getargs\n"
  2333. ":getargs\n"
  2334. "if [%%1] == [] goto import\n"
  2335. "if [%%1] == [-i] goto setdsml\n"
  2336. "set args=%%args%% %%1\n"
  2337. "shift\n"
  2338. "goto getargs\n\n"
  2339. ":incorrect\n"
  2340. ":usage\n"
  2341. "echo \"Usage: dsml2db -n backend_instance | {-s \"includesuffix\"}* "
  2342. "{-i dsml-file} [{-x \"excludesuffix\"}*]\"\n"
  2343. "set rc=1\n"
  2344. "goto done\n\n"
  2345. ":import\n"
  2346. "%s\\bin\\base\\jre\\bin\\java -Dverify=true -classpath \".;%s\\java\\ldapjdk.jar;%s\\java\\jars\\crimson.jar;%s\\java\\jars\\xmltools.jar\" com.netscape.xmltools.DSML2LDIF %%dsmlfile%%\n"
  2347. "set rc=%%errorlevel%%\n"
  2348. "if %%rc%%==0 goto realimport else goto done\n"
  2349. ":realimport\n"
  2350. "echo importing data ...\n"
  2351. "%s\\bin\\base\\jre\\bin\\java -classpath \".;%s\\java\\ldapjdk.jar;%s\\java\\jars\\crimson.jar;%s\\java\\jars\\xmltools.jar\" com.netscape.xmltools.DSML2LDIF %%dsmlfile%% | slapd ldif2db -D \"%s\" -i - %%args%% 2>&1\n\n"
  2352. "set rc=%%errorlevel%%\n"
  2353. ":done\n"
  2354. "if defined MKSARGS exit %%rc%%\n"
  2355. "exit /b %%rc%%\n",
  2356. server, sroot, sroot, sroot, sroot, sroot, sroot, sroot, sroot, cs_path);
  2357. if(t) return t;
  2358. t = gen_script(cs_path, "ldif2ldap.bat",
  2359. "@echo off\n"
  2360. "\"%s\\ldapmodify\" -a -p %s -D %%1 -w %%2 -f %%3\n",
  2361. tools, cf->servport);
  2362. if(t) return t;
  2363. t = CREATE_LDIF2DB();
  2364. if(t) return t;
  2365. t = CREATE_DB2INDEX();
  2366. if(t) return t;
  2367. /*
  2368. t = CREATE_MIGRATETO5();
  2369. if(t) return t;
  2370. t = CREATE_MIGRATE50TO51();
  2371. if(t) return t;
  2372. t = CREATE_MIGRATEINSTANCE5();
  2373. if(t) return t;
  2374. t = CREATE_MIGRATETO6();
  2375. if(t) return t;
  2376. t = CREATE_MIGRATE5TO6();
  2377. if(t) return t;
  2378. t = CREATE_MIGRATEINSTANCE6();
  2379. if(t) return t;
  2380. */
  2381. t = CREATE_MIGRATE5TO7();
  2382. if(t) return t;
  2383. t = CREATE_MIGRATE6TO7();
  2384. if(t) return t;
  2385. t = CREATE_MIGRATEINSTANCE7();
  2386. if(t) return t;
  2387. t = CREATE_MIGRATETO7();
  2388. if(t) return t;
  2389. t = gen_script(cs_path, "getpwenc.bat",
  2390. "@echo off\n"
  2391. "\"%s\\pwdhash\" -D \"%s\" -H -s %%1 %%2\n",
  2392. server, cs_path);
  2393. if(t) return t;
  2394. t = gen_script(cs_path, "db2ldif.bat",
  2395. "@if not \"%%echo%%\" == \"on\" echo off\n\n"
  2396. "setlocal\n"
  2397. "set rc=0\n"
  2398. "PATH=\"%s\";%%PATH%%\n\n"
  2399. "if [%%2] == [] goto err\n\n"
  2400. "set arg=\n"
  2401. "set ldif_file=\n\n"
  2402. ":again\n"
  2403. "if \"%%1\" == \"\" goto next\n"
  2404. "if \"%%1\" == \"-n\" goto doubletag\n"
  2405. "if \"%%1\" == \"-s\" goto doubletag\n"
  2406. "if \"%%1\" == \"-x\" goto doubletag\n"
  2407. "if \"%%1\" == \"-a\" goto setldif\n"
  2408. "if \"%%1\" == \"-N\" goto singletag\n"
  2409. "if \"%%1\" == \"-r\" goto singletag\n"
  2410. "if \"%%1\" == \"-C\" goto singletag\n"
  2411. "if \"%%1\" == \"-u\" goto singletag\n"
  2412. "if \"%%1\" == \"-m\" goto singletag\n"
  2413. "if \"%%1\" == \"-o\" goto singletag\n"
  2414. "if \"%%1\" == \"-U\" goto singletag\n"
  2415. "if \"%%1\" == \"-M\" goto singletag\n"
  2416. "if \"%%1\" == \"-E\" goto singletag\n"
  2417. "goto next\n\n"
  2418. ":doubletag\n"
  2419. "set arg=%%1 %%2 %%arg%%\n"
  2420. "shift\n"
  2421. "shift\n"
  2422. "goto again\n\n"
  2423. ":singletag\n"
  2424. "set arg=%%1 %%arg%%\n"
  2425. "shift\n"
  2426. "goto again\n\n"
  2427. ":setldif\n"
  2428. "set ldif_file=%%2\n"
  2429. "shift\n"
  2430. "shift\n"
  2431. "goto again\n\n"
  2432. ":next\n"
  2433. "if not \"%%ldif_file%%\" == \"\" goto givenldif\n\n"
  2434. "namegen\n"
  2435. "call bstart\n"
  2436. "set ldif_file=\"%s\\ldif\\%%DATESTR%%.ldif\"\n"
  2437. "call bend\n"
  2438. "del bend.bat\n\n"
  2439. ":givenldif\n"
  2440. "\"%s\\slapd\" db2ldif -D \"%s\" -a %%ldif_file%% %%arg%%\n"
  2441. "set rc=%%errorlevel%%\n"
  2442. "goto done\n\n"
  2443. ":err\n"
  2444. "echo \"Usage: db2ldif -n backend_instance | "
  2445. "{-s \"includesuffix\"}* [{-x \"excludesuffix\"}*] [-N] [-r] [-C] "
  2446. "[-u] [-U] [-m] [-M] [-1] [-a outputfile]\"\n\n"
  2447. "set rc=1\n"
  2448. ":done\n"
  2449. "if defined MKSARGS exit %%rc%%\n"
  2450. "exit /b %%rc%%\n",
  2451. server, cs_path, server, cs_path);
  2452. if(t) return t;
  2453. t = CREATE_DB2LDIF();
  2454. if(t) return t;
  2455. /* new code for dsml export */
  2456. t = gen_script(cs_path, "db2dsml.bat",
  2457. "@if not \"%%echo%%\" == \"on\" echo off\n\n"
  2458. "setlocal\n"
  2459. "set rc=0\n"
  2460. "PATH=\"%s\";%%PATH%%\n\n"
  2461. "if [%%2] == [] goto err\n\n"
  2462. "set arg=\n"
  2463. "set dsml_file=\n\n"
  2464. ":again\n"
  2465. "if \"%%1\" == \"\" goto next\n"
  2466. "if \"%%1\" == \"-n\" goto doubletag\n"
  2467. "if \"%%1\" == \"-s\" goto doubletag\n"
  2468. "if \"%%1\" == \"-x\" goto doubletag\n"
  2469. "if \"%%1\" == \"-a\" goto setdsml\n"
  2470. "if \"%%1\" == \"-N\" goto singletag\n"
  2471. "if \"%%1\" == \"-r\" goto singletag\n"
  2472. "if \"%%1\" == \"-C\" goto singletag\n"
  2473. "if \"%%1\" == \"-u\" goto singletag\n"
  2474. "if \"%%1\" == \"-m\" goto singletag\n"
  2475. "if \"%%1\" == \"-o\" goto singletag\n"
  2476. "if \"%%1\" == \"-U\" goto singletag\n"
  2477. "if \"%%1\" == \"-M\" goto singletag\n"
  2478. "goto next\n\n"
  2479. ":doubletag\n"
  2480. "set arg=%%1 %%2 %%arg%%\n"
  2481. "shift\n"
  2482. "shift\n"
  2483. "goto again\n\n"
  2484. ":singletag\n"
  2485. "set arg=%%1 %%arg%%\n"
  2486. "shift\n"
  2487. "goto again\n\n"
  2488. ":setdsml\n"
  2489. "set dsml_file=%%2\n"
  2490. "shift\n"
  2491. "shift\n"
  2492. "goto again\n\n"
  2493. ":next\n"
  2494. "if not \"%%dsml_file%%\" == \"\" goto givendsml\n\n"
  2495. "namegen\n"
  2496. "call bstart\n"
  2497. "set dsml_file=\"%s\\dsml\\%%DATESTR%%.dsml\"\n"
  2498. "echo dsmlfile: %%dsml_file%%\n"
  2499. "call bend\n"
  2500. "del bend.bat\n\n"
  2501. ":givendsml\n"
  2502. "%s\\bin\\base\\jre\\bin\\java -Dverify=true -classpath \".;%s\\java\\ldapjdk.jar;%s\\java\\jars\\xmltools.jar\" com.netscape.xmltools.LDIF2DSML -s -o %%dsml_file%%\n"
  2503. "set rc=%%errorlevel%%\n"
  2504. "if %%rc%%==0 goto realimport else goto done\n\n"
  2505. ":realimport\n"
  2506. "\"%s\\slapd\" db2ldif -D \"%s\" -a - -1 %%arg%% | %s\\bin\\base\\jre\\bin\\java -classpath \".;%s\\java\\ldapjdk.jar;%s\\java\\jars\\xmltools.jar\" com.netscape.xmltools.LDIF2DSML -s -o %%dsml_file%%\n"
  2507. "set rc=%%errorlevel%%\n"
  2508. "goto done\n\n"
  2509. ":err\n"
  2510. "echo \"Usage: db2dsml -n backend_instance | "
  2511. "{-s \"includesuffix\"}* [{-x \"excludesuffix\"}*]"
  2512. "[-u] [-a outputfile]\"\n\n"
  2513. "set rc=1\n"
  2514. ":done\n"
  2515. "if defined MKSARGS exit %%rc%%\n"
  2516. "exit /b %%rc%%\n",
  2517. server, cs_path, sroot, sroot, sroot, server, cs_path, sroot, sroot, sroot);
  2518. if(t) return t;
  2519. t = gen_script(cs_path, "db2bak.bat",
  2520. "@echo off\n"
  2521. "setlocal\n"
  2522. "set rc=0\n"
  2523. "PATH=\"%s\";%%PATH%%\n"
  2524. "if %%1.==. goto nobak\n"
  2525. "set bakdir=%%1\n"
  2526. "goto backup\n"
  2527. ":nobak\n"
  2528. "namegen\n"
  2529. "call bstart\n"
  2530. "set bakdir=\"%s\\bak\\%%DATESTR%%\"\n"
  2531. "call bend\n"
  2532. "del bend.bat\n"
  2533. ":backup\n"
  2534. "\"%s\\slapd\" db2archive -D \"%s\" -a %%bakdir%% "
  2535. "%%2 %%3 %%4 %%5 %%6 %%7 %%8\n"
  2536. "set rc=%%errorlevel%%\n"
  2537. ":done\n"
  2538. "if defined MKSARGS exit %%rc%%\n"
  2539. "exit /b %%rc%%\n",
  2540. server, cs_path, server, cs_path);
  2541. if(t) return t;
  2542. t = CREATE_DB2BAK();
  2543. if(t) return t;
  2544. #if defined(UPGRADEDB)
  2545. t = gen_script(cs_path, "db2index.bat",
  2546. "@echo off\n"
  2547. "setlocal\n"
  2548. "set rc=0\n"
  2549. "PATH=\"%s\";%%PATH%%\n"
  2550. "if %%1.==. goto indexall\n\n"
  2551. "if %%2.==. goto err\n"
  2552. "if %%3.==. goto err\n\n"
  2553. "set bakdir=%%1\n"
  2554. "goto backup\n\n"
  2555. ":indexall\n"
  2556. "namegen\n"
  2557. "call bstart\n"
  2558. "set bakdir=\"%s\\bak\\%%DATESTR%%\"\n"
  2559. "call bend\n"
  2560. "del bend.bat\n"
  2561. "\"%s\\slapd\" upgradedb -D \"%s\" -f -a %%bakdir%%\n"
  2562. "set rc=%%errorlevel%%\n"
  2563. "goto done\n\n"
  2564. ":backup\n"
  2565. "\"%s\\slapd\" db2index -D \"%s\" "
  2566. "%%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8\n"
  2567. "set rc=%%errorlevel%%\n"
  2568. "goto done\n\n"
  2569. ":err\n"
  2570. "echo \"Usage: db2index [-n backend_instance | {-s instancesuffix}* -t attribute[:indextypes[:matchingrules]] -T vlvattribute]\"\n\n"
  2571. "set rc=1\n"
  2572. ":done\n"
  2573. "if defined MKSARGS exit %%rc%%\n"
  2574. "exit /b %%rc%%\n",
  2575. server, cs_path, server, cs_path, server, cs_path);
  2576. if(t) return t;
  2577. #endif
  2578. t = gen_script(cs_path, "vlvindex.bat",
  2579. "@echo off\n"
  2580. "setlocal\n"
  2581. "set rc=0\n"
  2582. "if [%%2] == [] goto usage\n"
  2583. "if [%%3] == [] goto usage\n"
  2584. "if [%%4] == [] goto usage\n\n"
  2585. "\"%s\\slapd\" db2index -D \"%s\" \"%%@\"\n"
  2586. "set rc=%%errorlevel%%\n"
  2587. "goto done\n\n"
  2588. ":usage\n"
  2589. "echo \"Usage: vlvindex -n backend_instance | {-s includesuffix}* {-T attribute}\"\n\n"
  2590. "set rc=1\n"
  2591. ":done\n"
  2592. "if defined MKSARGS exit %%rc%%\n"
  2593. "exit /b %%rc%%\n",
  2594. server, cs_path);
  2595. if(t) return t;
  2596. t = gen_script(cs_path, "bak2db.bat",
  2597. "@echo off\n"
  2598. "pushd & setlocal\n\n"
  2599. "if [%%1] == [] (goto :usage)\n"
  2600. "if not [%%4] == [] (goto :usage)\n\n"
  2601. "set archivedir=%%1\n"
  2602. "set rc=0\n\n"
  2603. ":getopts\n"
  2604. "shift\n"
  2605. "if [%%1]==[] (goto :main)\n"
  2606. "if [%%1]==[-n] (if not [%%2]==[] (set bename=%%2) else (goto :usage)) else (goto :getopts)\n\n"
  2607. ":main\n"
  2608. "call :relative %%archivedir%%\n"
  2609. "if defined bename (\n"
  2610. "\"%s\\slapd\" archive2db -D \"%s\" -a %%archivedir%% -n %%bename%%\n"
  2611. ") else (\n"
  2612. "\"%s\\slapd\" archive2db -D \"%s\" -a %%archivedir%%\n"
  2613. ")\n"
  2614. "set rc=%%ERRORLEVEL%%\n"
  2615. "popd\n"
  2616. "goto :done\n\n"
  2617. "goto :EOF\n"
  2618. ":usage\n"
  2619. "echo %%0 archivedir [-n backendname]\n"
  2620. "goto :done\n\n"
  2621. "goto :EOF\n"
  2622. ":relative\n"
  2623. "set archivedir=%%~f1\n\n"
  2624. "goto :EOF\n"
  2625. ":done\n"
  2626. "if defined MKSARGS exit %%rc%%\n"
  2627. "exit /b %%rc%%\n",
  2628. server, cs_path, server, cs_path);
  2629. if(t) return t;
  2630. #if defined(UPGRADEDB)
  2631. t = gen_script(cs_path, "upgradedb.bat",
  2632. "@echo off\n"
  2633. "setlocal\n"
  2634. "set rc=0\n"
  2635. "PATH=\"%s\";%%PATH%%\n"
  2636. "if %%1.==. goto nobak\n"
  2637. "set bakdir=%%1\n"
  2638. "goto backup\n"
  2639. ":nobak\n"
  2640. "namegen\n"
  2641. "call bstart\n"
  2642. "set bakdir=\"%s\\bak\\upgradedb_%%DATESTR%%\"\n"
  2643. "call bend\n"
  2644. "del bend.bat\n"
  2645. ":backup\n"
  2646. "\"%s\\slapd\" upgradedb -D \"%s\" -a %%bakdir%% "
  2647. "%%2 %%3 %%4 %%5 %%6 %%7 %%8\n"
  2648. "set rc=%%errorlevel%%\n"
  2649. ":done\n"
  2650. "if defined MKSARGS exit %%rc%%\n"
  2651. "exit /b %%rc%%\n",
  2652. server, cs_path, server, cs_path);
  2653. if(t) return t;
  2654. #endif
  2655. t = CREATE_BAK2DB();
  2656. if(t) return t;
  2657. t = CREATE_VERIFYDB();
  2658. if(t) return t;
  2659. t = CREATE_REPL_MONITOR_CGI();
  2660. if(t) return t;
  2661. t = gen_script(cs_path, "suffix2instance.bat",
  2662. "@if not \"%%echo%%\" == \"on\" echo off\n\n"
  2663. "setlocal\n"
  2664. "set rc=0\n"
  2665. "PATH=\"%s\";%%PATH%%\n\n"
  2666. "if [%%2] == [] goto err\n\n"
  2667. "set arg=\n\n"
  2668. ":again\n"
  2669. "if \"%%1\" == \"\" goto next\n"
  2670. "if \"%%1\" == \"-s\" goto doubletag\n"
  2671. "shift\n"
  2672. "goto again\n\n"
  2673. ":doubletag\n"
  2674. "set arg=%%1 %%2 %%arg%%\n"
  2675. "shift\n"
  2676. "shift\n"
  2677. "goto again\n\n"
  2678. ":next\n"
  2679. "\"%s\\slapd\" suffix2instance -D \"%s\" %%arg%%\n"
  2680. "set rc=%%errorlevel%%\n"
  2681. "goto done\n\n"
  2682. ":err\n"
  2683. "echo Usage: suffix2instance {-s \"suffix\"}*\n\n"
  2684. "set rc=1\n"
  2685. ":done\n"
  2686. "if defined MKSARGS exit %%rc%%\n"
  2687. "exit /b %%rc%%\n",
  2688. server, server, cs_path);
  2689. if(t) return t;
  2690. t = CREATE_ACCOUNT_INACT("ns-inactivate.pl");
  2691. if(t) return t;
  2692. t = CREATE_ACCOUNT_INACT("ns-activate.pl");
  2693. if(t) return t;
  2694. t = CREATE_ACCOUNT_INACT("ns-accountstatus.pl");
  2695. if(t) return t;
  2696. t = CREATE_DSML();
  2697. if(t) return t;
  2698. t = gen_script(cs_path, "dsml-activate.bat",
  2699. "@echo off\n"
  2700. "setlocal\n"
  2701. "PATH=%s\\bin\\slapd\\admin\\bin;%%PATH%%\n"
  2702. "perl \"%s\\dsml-activate.pl\" %%*\n"
  2703. "set rc=%%errorlevel%%\n"
  2704. "if defined MKSARGS exit %%rc%%\n"
  2705. "exit /b %%rc%%\n",
  2706. sroot, cs_path);
  2707. if(t) return t;
  2708. t = CREATE_NEWPWPOLICY();
  2709. if(t) return t;
  2710. t = gen_script(cs_path, "ns-newpwpolicy.cmd",
  2711. "@echo off\n"
  2712. "setlocal\n"
  2713. "PATH=%s\\bin\\slapd\\admin\\bin;%%PATH%%\n"
  2714. "perl \"%s\\ns-newpwpolicy.pl\" %%*\n"
  2715. "set rc=%%errorlevel%%\n"
  2716. "if defined MKSARGS exit %%rc%%\n"
  2717. "exit /b %%rc%%\n",
  2718. sroot, cs_path);
  2719. if(t) return t;
  2720. free(mysroot);
  2721. free(mycs_path);
  2722. /*Generate the java commandline tools in bin/slapd/server*/
  2723. for (cls = 0; cls < 7; cls++) {
  2724. t = gen_script(server, cl_scripts[cls],
  2725. "@echo off\npushd \"%s\"\n\n"
  2726. "setlocal\n"
  2727. "set LANG=en\n"
  2728. "set arg=\n"
  2729. "set rc=0\n"
  2730. ":getarg\n"
  2731. "if %%1.==. goto start\n"
  2732. "if %%1==-l goto getlang\n"
  2733. "set arg=%%arg%% %%1\n"
  2734. "shift\n"
  2735. "goto getarg\n"
  2736. ":getlang\n"
  2737. "shift\n"
  2738. "set LANG=%%1\n"
  2739. "shift\n"
  2740. "goto getarg\n"
  2741. ":start\n"
  2742. ".\\bin\\base\\jre\\bin\\jre -classpath "
  2743. ".;.\\java;.\\bin\\base\\jre\\lib;"
  2744. ".\\bin\\base\\jre\\lib\\rt.jar;.\\bin\\base\\jre\\lib\\i18n.jar;"
  2745. ".\\java\\base.jar;.\\java\\jars\\ds40.jar;.\\java\\jars\\ds40_%%LANG%%.jar;"
  2746. ".\\java\\swingall.jar;.\\java\\ssl.zip;"
  2747. ".\\java\\ldapjdk.jar;.\\java\\mcc40.jar;.\\java\\mcc40_%%LANG%%.jar;"
  2748. ".\\java\\nmclf40.jar;.\\java\\nmclf40_%%LANG%%.jar "
  2749. "com.netscape.admin.dirserv.cmdln.%s %%arg%%\n"
  2750. "set rc=%%errorlevel%%\n"
  2751. "popd\n"
  2752. "if defined MKSARGS exit %%rc%%\n"
  2753. "exit /b %%rc%%\n",
  2754. sroot, cl_javafiles[cls]);
  2755. if(t) return t;
  2756. }
  2757. return (t);
  2758. }
  2759. #endif
  2760. void
  2761. suffix_gen_conf(FILE* f, char * suffix, char *be_name)
  2762. {
  2763. int l;
  2764. char* belowdn;
  2765. fprintf(f, "dn: cn=%s,cn=ldbm database,cn=plugins,cn=config\n", be_name);
  2766. fprintf(f, "objectclass: top\n");
  2767. fprintf(f, "objectclass: extensibleObject\n");
  2768. fprintf(f, "objectclass: nsBackendInstance\n");
  2769. fprintf(f, "nsslapd-cachesize: -1\n");
  2770. fprintf(f, "nsslapd-cachememsize: 10485760\n");
  2771. fprintf(f, "nsslapd-suffix: %s\n", suffix);
  2772. fprintf(f, "cn: %s\n", be_name);
  2773. fprintf(f, "\n");
  2774. fprintf(f, "dn: cn=monitor,cn=%s,cn=ldbm database,cn=plugins,cn=config\n", be_name);
  2775. fprintf(f, "objectclass: top\n");
  2776. fprintf(f, "objectclass: extensibleObject\n");
  2777. fprintf(f, "cn: monitor\n");
  2778. fprintf(f, "\n");
  2779. fprintf(f, "dn: cn=\"%s\",cn=mapping tree,cn=config\n", suffix);
  2780. fprintf(f, "objectclass: top\n");
  2781. fprintf(f, "objectclass: extensibleObject\n");
  2782. fprintf(f, "objectclass: nsMappingTree\n");
  2783. fprintf(f, "cn: \"%s\"\n", suffix);
  2784. fprintf(f, "nsslapd-state: backend\n");
  2785. fprintf(f, "nsslapd-backend: %s\n", be_name);
  2786. fprintf(f, "\n");
  2787. /* Parent entry for attribute encryption config entries */
  2788. fprintf(f, "dn: cn=encrypted attributes,cn=%s,cn=ldbm database,cn=plugins,cn=config\n", be_name);
  2789. fprintf(f, "objectclass: top\n");
  2790. fprintf(f, "objectclass: extensibleObject\n");
  2791. fprintf(f, "cn: encrypted attributes\n");
  2792. fprintf(f, "\n");
  2793. /* Parent entry for attribute encryption keys */
  2794. fprintf(f, "dn: cn=encrypted attribute keys,cn=%s,cn=ldbm database,cn=plugins,cn=config\n", be_name);
  2795. fprintf(f, "objectclass: top\n");
  2796. fprintf(f, "objectclass: extensibleObject\n");
  2797. fprintf(f, "cn: encrypted attributes keys\n");
  2798. fprintf(f, "\n");
  2799. /* Indexes for the ldbm instance */
  2800. fprintf(f, "dn: cn=index,cn=%s,cn=ldbm database,cn=plugins,cn=config\n", be_name);
  2801. fprintf(f, "objectclass: top\n");
  2802. fprintf(f, "objectclass: extensibleObject\n");
  2803. fprintf(f, "cn: index\n");
  2804. fprintf(f, "\n");
  2805. l = strlen("cn=index,cn=") + strlen(be_name) + strlen(",cn=ldbm database,cn=plugins,cn=config");
  2806. belowdn = (char *)malloc(l + 1);
  2807. sprintf(belowdn, "cn=index,cn=%s,cn=ldbm database,cn=plugins,cn=config", be_name);
  2808. ds_gen_index(f, belowdn);
  2809. /* done with ldbm entries */
  2810. }
  2811. #define MKSYNTAX(_name,_fn) do { \
  2812. fprintf(f, "dn: cn=%s,cn=plugins,cn=config\n", (_name)); \
  2813. fprintf(f, "objectclass: top\n"); \
  2814. fprintf(f, "objectclass: nsSlapdPlugin\n"); \
  2815. fprintf(f, "objectclass: extensibleObject\n"); \
  2816. fprintf(f, "cn: %s\n",(_name)); \
  2817. fprintf(f, "nsslapd-pluginpath: %s/lib/syntax-plugin%s\n", sroot, shared_lib); \
  2818. fprintf(f, "nsslapd-plugininitfunc: %s\n", (_fn)); \
  2819. fprintf(f, "nsslapd-plugintype: syntax\n"); \
  2820. fprintf(f, "nsslapd-pluginenabled: on\n"); \
  2821. fprintf(f, "\n"); \
  2822. } while (0)
  2823. char *ds_gen_confs(char *sroot, server_config_s *cf,
  2824. char *cs_path)
  2825. {
  2826. char* t = NULL;
  2827. char src[PATH_SIZE], dest[PATH_SIZE];
  2828. char fn[PATH_SIZE], line[1024];
  2829. FILE *f = 0, *srcf = 0;
  2830. int rootdse = 0;
  2831. char *shared_lib;
  2832. sprintf(fn, "%s%cconfig%cdse.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  2833. if(!(f = fopen(fn, "w")))
  2834. return make_error("Can't write to %s (%s)", fn, ds_system_errmsg());
  2835. #if defined( XP_WIN32 )
  2836. shared_lib = ".dll";
  2837. #else
  2838. #ifdef HPUX
  2839. shared_lib = ".sl";
  2840. #else
  2841. #ifdef AIX
  2842. #if OSVERSION >= 4200
  2843. shared_lib = ".so";
  2844. #else
  2845. shared_lib = "_shr.a";
  2846. #endif
  2847. #else
  2848. shared_lib = ".so";
  2849. #endif
  2850. #endif
  2851. #endif
  2852. fprintf(f, "dn: cn=config\n");
  2853. fprintf(f, "cn: config\n");
  2854. fprintf(f, "objectclass:top\n");
  2855. fprintf(f, "objectclass:extensibleObject\n");
  2856. fprintf(f, "objectclass:nsslapdConfig\n");
  2857. fprintf(f, "nsslapd-accesslog-logging-enabled: on\n");
  2858. fprintf(f, "nsslapd-accesslog-maxlogsperdir: 10\n");
  2859. fprintf(f, "nsslapd-accesslog-mode: 600\n");
  2860. fprintf(f, "nsslapd-accesslog-maxlogsize: 100\n");
  2861. fprintf(f, "nsslapd-accesslog-logrotationtime: 1\n");
  2862. fprintf(f, "nsslapd-accesslog-logrotationtimeunit: day\n");
  2863. fprintf(f, "nsslapd-accesslog-logrotationsync-enabled: off\n");
  2864. fprintf(f, "nsslapd-accesslog-logrotationsynchour: 0\n");
  2865. fprintf(f, "nsslapd-accesslog-logrotationsyncmin: 0\n");
  2866. fprintf(f, "nsslapd-accesslog: %s/logs/access\n", cs_path);
  2867. fprintf(f, "nsslapd-enquote-sup-oc: off\n");
  2868. fprintf(f, "nsslapd-localhost: %s\n", cf->servname);
  2869. fprintf(f, "nsslapd-schemacheck: %s\n",
  2870. (cf->disable_schema_checking && !strcmp(cf->disable_schema_checking, "1")) ? "off" : "on");
  2871. fprintf(f, "nsslapd-rewrite-rfc1274: off\n");
  2872. fprintf(f, "nsslapd-return-exact-case: on\n");
  2873. fprintf(f, "nsslapd-ssl-check-hostname: on\n");
  2874. fprintf(f, "nsslapd-port: %s\n", cf->servport);
  2875. #if !defined( XP_WIN32 )
  2876. if (cf->servuser && *(cf->servuser)) {
  2877. fprintf(f, "nsslapd-localuser: %s\n", cf->servuser);
  2878. }
  2879. #endif
  2880. fprintf(f, "nsslapd-errorlog-logging-enabled: on\n");
  2881. fprintf(f, "nsslapd-errorlog-mode: 600\n");
  2882. fprintf(f, "nsslapd-errorlog-maxlogsperdir: 2\n");
  2883. fprintf(f, "nsslapd-errorlog-maxlogsize: 100\n");
  2884. fprintf(f, "nsslapd-errorlog-logrotationtime: 1\n");
  2885. fprintf(f, "nsslapd-errorlog-logrotationtimeunit: week\n");
  2886. fprintf(f, "nsslapd-errorlog-logrotationsync-enabled: off\n");
  2887. fprintf(f, "nsslapd-errorlog-logrotationsynchour: 0\n");
  2888. fprintf(f, "nsslapd-errorlog-logrotationsyncmin: 0\n");
  2889. fprintf(f, "nsslapd-errorlog: %s/logs/errors\n", cs_path);
  2890. if (cf->loglevel)
  2891. fprintf(f, "nsslapd-errorlog-level: %s\n", cf->loglevel);
  2892. fprintf(f, "nsslapd-auditlog: %s/logs/audit\n", cs_path);
  2893. fprintf(f, "nsslapd-auditlog-mode: 600\n");
  2894. fprintf(f, "nsslapd-auditlog-maxlogsize: 100\n");
  2895. fprintf(f, "nsslapd-auditlog-logrotationtime: 1\n");
  2896. fprintf(f, "nsslapd-auditlog-logrotationtimeunit: day\n");
  2897. fprintf(f, "nsslapd-rootdn: %s\n", cf->rootdn);
  2898. #if !defined(_WIN32) && !defined(AIX)
  2899. {
  2900. unsigned int maxdescriptors = FD_SETSIZE;
  2901. struct rlimit rl;
  2902. if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
  2903. maxdescriptors = (unsigned int)rl.rlim_max;
  2904. fprintf(f, "nsslapd-maxdescriptors: %d\n", maxdescriptors);
  2905. }
  2906. #endif
  2907. fprintf(f, "nsslapd-max-filter-nest-level: 40\n" );
  2908. fprintf(f, "nsslapd-rootpw: %s\n", cf->roothashedpw);
  2909. if (getenv("DEBUG_SINGLE_THREADED"))
  2910. fprintf(f, "nsslapd-threadnumber: 1\n");
  2911. fprintf(f, "\n");
  2912. fprintf(f, "dn: cn=plugins, cn=config\nobjectclass: top\nobjectclass: nsContainer\ncn: plugins\n");
  2913. fprintf(f, "\n");
  2914. fprintf(f, "dn: cn=Password Storage Schemes,cn=plugins, cn=config\n");
  2915. fprintf(f, "objectclass: top\nobjectclass: nsContainer\ncn: Password Storage Schemes\n");
  2916. fprintf(f, "\n");
  2917. fprintf(f, "dn: cn=SSHA,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2918. fprintf(f, "objectclass: top\n");
  2919. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2920. fprintf(f, "cn: SSHA\n");
  2921. fprintf(f, "nsslapd-pluginpath: %s/lib/pwdstorage-plugin%s\n", sroot, shared_lib);
  2922. fprintf(f, "nsslapd-plugininitfunc: ssha_pwd_storage_scheme_init\n");
  2923. fprintf(f, "nsslapd-plugintype: pwdstoragescheme\n");
  2924. fprintf(f, "nsslapd-pluginenabled: on\n");
  2925. fprintf(f, "\n");
  2926. fprintf(f, "dn: cn=SHA,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2927. fprintf(f, "objectclass: top\n");
  2928. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2929. fprintf(f, "cn: SHA\n");
  2930. fprintf(f, "nsslapd-pluginpath: %s/lib/pwdstorage-plugin%s\n", sroot, shared_lib);
  2931. fprintf(f, "nsslapd-plugininitfunc: sha_pwd_storage_scheme_init\n");
  2932. fprintf(f, "nsslapd-plugintype: pwdstoragescheme\n");
  2933. fprintf(f, "nsslapd-pluginenabled: on\n");
  2934. fprintf(f, "\n");
  2935. fprintf(f, "dn: cn=CRYPT,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2936. fprintf(f, "objectclass: top\n");
  2937. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2938. fprintf(f, "cn: CRYPT\n");
  2939. fprintf(f, "nsslapd-pluginpath: %s/lib/pwdstorage-plugin%s\n", sroot, shared_lib);
  2940. fprintf(f, "nsslapd-plugininitfunc: crypt_pwd_storage_scheme_init\n");
  2941. fprintf(f, "nsslapd-plugintype: pwdstoragescheme\n");
  2942. fprintf(f, "nsslapd-pluginenabled: on\n");
  2943. fprintf(f, "\n");
  2944. fprintf(f, "dn: cn=CLEAR,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2945. fprintf(f, "objectclass: top\n");
  2946. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2947. fprintf(f, "cn: CLEAR\n");
  2948. fprintf(f, "nsslapd-pluginpath: %s/lib/pwdstorage-plugin%s\n", sroot, shared_lib);
  2949. fprintf(f, "nsslapd-plugininitfunc: clear_pwd_storage_scheme_init\n");
  2950. fprintf(f, "nsslapd-plugintype: pwdstoragescheme\n");
  2951. fprintf(f, "nsslapd-pluginenabled: on\n");
  2952. fprintf(f, "\n");
  2953. fprintf(f, "dn: cn=NS-MTA-MD5,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2954. fprintf(f, "objectclass: top\n");
  2955. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2956. fprintf(f, "cn: NS-MTA-MD5\n");
  2957. fprintf(f, "nsslapd-pluginpath: %s/lib/pwdstorage-plugin%s\n", sroot, shared_lib);
  2958. fprintf(f, "nsslapd-plugininitfunc: ns_mta_md5_pwd_storage_scheme_init\n");
  2959. fprintf(f, "nsslapd-plugintype: pwdstoragescheme\n");
  2960. fprintf(f, "nsslapd-pluginenabled: on\n");
  2961. fprintf(f, "\n");
  2962. fprintf(f, "dn: cn=DES,cn=Password Storage Schemes,cn=plugins,cn=config\n");
  2963. fprintf(f, "objectclass: top\n");
  2964. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2965. fprintf(f, "objectclass: extensibleObject\n");
  2966. fprintf(f, "cn: DES\n");
  2967. fprintf(f, "nsslapd-pluginpath: %s/lib/des-plugin%s\n", sroot, shared_lib);
  2968. fprintf(f, "nsslapd-plugininitfunc: des_init\n");
  2969. fprintf(f, "nsslapd-plugintype: reverpwdstoragescheme\n");
  2970. fprintf(f, "nsslapd-pluginenabled: on\n");
  2971. fprintf(f, "nsslapd-pluginarg0: nsmultiplexorcredentials\n");
  2972. fprintf(f, "nsslapd-pluginarg1: nsds5ReplicaCredentials\n");
  2973. fprintf(f, "nsslapd-pluginid: des-storage-scheme\n");
  2974. fprintf(f, "\n");
  2975. MKSYNTAX("Case Ignore String Syntax","cis_init");
  2976. MKSYNTAX("Case Exact String Syntax","ces_init");
  2977. MKSYNTAX("Space Insensitive String Syntax","sicis_init");
  2978. MKSYNTAX("Binary Syntax","bin_init");
  2979. MKSYNTAX("Octet String Syntax","octetstring_init");
  2980. MKSYNTAX("Boolean Syntax","boolean_init");
  2981. MKSYNTAX("Generalized Time Syntax","time_init");
  2982. MKSYNTAX("Telephone Syntax","tel_init");
  2983. MKSYNTAX("Integer Syntax","int_init");
  2984. MKSYNTAX("Distinguished Name Syntax","dn_init");
  2985. MKSYNTAX("OID Syntax","oid_init");
  2986. MKSYNTAX("URI Syntax","uri_init");
  2987. MKSYNTAX("JPEG Syntax","jpeg_init");
  2988. MKSYNTAX("Country String Syntax","country_init");
  2989. MKSYNTAX("Postal Address Syntax","postal_init");
  2990. fprintf(f, "dn: cn=State Change Plugin,cn=plugins,cn=config\n");
  2991. fprintf(f, "objectclass: top\n");
  2992. fprintf(f, "objectclass: nsSlapdPlugin\n");
  2993. fprintf(f, "objectclass: extensibleObject\n");
  2994. fprintf(f, "cn: State Change Plugin\n");
  2995. fprintf(f, "nsslapd-pluginpath: %s/lib/statechange-plugin%s\n", sroot, shared_lib);
  2996. fprintf(f, "nsslapd-plugininitfunc: statechange_init\n");
  2997. fprintf(f, "nsslapd-plugintype: postoperation\n");
  2998. fprintf(f, "nsslapd-pluginenabled: on\n");
  2999. fprintf(f, "\n");
  3000. fprintf(f, "dn: cn=Roles Plugin,cn=plugins,cn=config\n");
  3001. fprintf(f, "objectclass: top\n");
  3002. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3003. fprintf(f, "objectclass: extensibleObject\n");
  3004. fprintf(f, "cn: Roles Plugin\n");
  3005. fprintf(f, "nsslapd-pluginpath: %s/lib/roles-plugin%s\n", sroot, shared_lib);
  3006. fprintf(f, "nsslapd-plugininitfunc: roles_init\n");
  3007. fprintf(f, "nsslapd-plugintype: postoperation\n");
  3008. fprintf(f, "nsslapd-pluginenabled: on\n");
  3009. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3010. fprintf(f, "nsslapd-plugin-depends-on-named: State Change Plugin\n");
  3011. fprintf(f, "nsslapd-plugin-depends-on-named: Views\n");
  3012. fprintf(f, "\n");
  3013. fprintf(f, "dn: cn=ACL Plugin,cn=plugins,cn=config\n");
  3014. fprintf(f, "objectclass: top\n");
  3015. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3016. fprintf(f, "objectclass: extensibleObject\n");
  3017. fprintf(f, "cn: ACL Plugin\n");
  3018. fprintf(f, "nsslapd-pluginpath: %s/lib/acl-plugin%s\n", sroot, shared_lib);
  3019. fprintf(f, "nsslapd-plugininitfunc: acl_init\n");
  3020. fprintf(f, "nsslapd-plugintype: accesscontrol\n");
  3021. fprintf(f, "nsslapd-pluginenabled: on\n");
  3022. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3023. fprintf(f, "\n");
  3024. fprintf(f, "dn: cn=ACL preoperation,cn=plugins,cn=config\n");
  3025. fprintf(f, "objectclass: top\n");
  3026. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3027. fprintf(f, "objectclass: extensibleObject\n");
  3028. fprintf(f, "cn: ACL preoperation\n");
  3029. fprintf(f, "nsslapd-pluginpath: %s/lib/acl-plugin%s\n", sroot, shared_lib);
  3030. fprintf(f, "nsslapd-plugininitfunc: acl_preopInit\n");
  3031. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3032. fprintf(f, "nsslapd-pluginenabled: on\n");
  3033. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3034. fprintf(f, "\n");
  3035. fprintf(f, "dn: cn=Legacy Replication Plugin,cn=plugins,cn=config\n");
  3036. fprintf(f, "objectclass: top\n");
  3037. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3038. fprintf(f, "objectclass: extensibleObject\n");
  3039. fprintf(f, "cn: Legacy Replication Plugin\n");
  3040. fprintf(f, "nsslapd-pluginpath: %s/lib/replication-plugin%s\n", sroot, shared_lib);
  3041. fprintf(f, "nsslapd-plugininitfunc: replication_legacy_plugin_init\n");
  3042. fprintf(f, "nsslapd-plugintype: object\n");
  3043. fprintf(f, "nsslapd-pluginenabled: on\n");
  3044. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3045. fprintf(f, "nsslapd-plugin-depends-on-named: Multimaster Replication Plugin\n");
  3046. fprintf(f, "\n");
  3047. fprintf(f, "dn: cn=Multimaster Replication Plugin,cn=plugins,cn=config\n");
  3048. fprintf(f, "objectclass: top\n");
  3049. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3050. fprintf(f, "objectclass: extensibleObject\n");
  3051. fprintf(f, "cn: Multimaster Replication Plugin\n");
  3052. fprintf(f, "nsslapd-pluginpath: %s/lib/replication-plugin%s\n", sroot, shared_lib);
  3053. fprintf(f, "nsslapd-plugininitfunc: replication_multimaster_plugin_init\n");
  3054. fprintf(f, "nsslapd-plugintype: object\n");
  3055. fprintf(f, "nsslapd-pluginenabled: on\n");
  3056. fprintf(f, "nsslapd-plugin-depends-on-named: ldbm database\n");
  3057. fprintf(f, "nsslapd-plugin-depends-on-named: DES\n");
  3058. fprintf(f, "\n");
  3059. fprintf(f, "dn: cn=Retro Changelog Plugin,cn=plugins,cn=config\n");
  3060. fprintf(f, "objectclass: top\n");
  3061. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3062. fprintf(f, "objectclass: extensibleObject\n");
  3063. fprintf(f, "cn: Retro Changelog Plugin\n");
  3064. fprintf(f, "nsslapd-pluginpath: %s/lib/retrocl-plugin%s\n", sroot, shared_lib);
  3065. fprintf(f, "nsslapd-plugininitfunc: retrocl_plugin_init\n");
  3066. fprintf(f, "nsslapd-plugintype: object\n");
  3067. fprintf(f, "nsslapd-pluginenabled: off\n");
  3068. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3069. fprintf(f, "\n");
  3070. /* cos needs to be placed before other same type'ed plugins (postoperation) */
  3071. fprintf(f, "dn: cn=Class of Service,cn=plugins,cn=config\n");
  3072. fprintf(f, "objectclass: top\n");
  3073. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3074. fprintf(f, "objectclass: extensibleObject\n");
  3075. fprintf(f, "cn: Class of Service\n");
  3076. fprintf(f, "nsslapd-pluginpath: %s/lib/cos-plugin%s\n", sroot, shared_lib);
  3077. fprintf(f, "nsslapd-plugininitfunc: cos_init\n");
  3078. fprintf(f, "nsslapd-plugintype: postoperation\n");
  3079. fprintf(f, "nsslapd-pluginenabled: on\n");
  3080. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3081. fprintf(f, "nsslapd-plugin-depends-on-named: State Change Plugin\n");
  3082. fprintf(f, "nsslapd-plugin-depends-on-named: Views\n");
  3083. fprintf(f, "\n");
  3084. fprintf(f, "dn: cn=Views,cn=plugins,cn=config\n");
  3085. fprintf(f, "objectclass: top\n");
  3086. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3087. fprintf(f, "objectclass: extensibleObject\n");
  3088. fprintf(f, "cn: Views\n");
  3089. fprintf(f, "nsslapd-pluginpath: %s/lib/views-plugin%s\n", sroot, shared_lib);
  3090. fprintf(f, "nsslapd-plugininitfunc: views_init\n");
  3091. fprintf(f, "nsslapd-plugintype: object\n");
  3092. fprintf(f, "nsslapd-pluginenabled: on\n");
  3093. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3094. fprintf(f, "nsslapd-plugin-depends-on-named: State Change Plugin\n");
  3095. fprintf(f, "\n");
  3096. /*
  3097. * LP: Turn referential integrity plugin OFF by default
  3098. * defect 518862
  3099. */
  3100. fprintf(f, "dn: cn=referential integrity postoperation,cn=plugins,cn=config\n");
  3101. fprintf(f, "objectclass: top\n");
  3102. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3103. fprintf(f, "objectclass: extensibleObject\n");
  3104. fprintf(f, "cn: referential integrity postoperation\n");
  3105. fprintf(f, "nsslapd-pluginpath: %s/lib/referint-plugin%s\n", sroot, shared_lib);
  3106. fprintf(f, "nsslapd-plugininitfunc: referint_postop_init\n");
  3107. fprintf(f, "nsslapd-plugintype: postoperation\n");
  3108. fprintf(f, "nsslapd-pluginenabled: off\n");
  3109. fprintf(f, "nsslapd-pluginArg0: %d\n", REFERINT_DELAY);
  3110. fprintf(f, "nsslapd-pluginArg1: %s/logs/referint\n", cs_path);
  3111. fprintf(f, "nsslapd-pluginArg2: %d\n", REFERINT_LOG_CHANGES);
  3112. fprintf(f, "nsslapd-pluginArg3: member\n");
  3113. fprintf(f, "nsslapd-pluginArg4: uniquemember\n");
  3114. fprintf(f, "nsslapd-pluginArg5: owner\n");
  3115. fprintf(f, "nsslapd-pluginArg6: seeAlso\n");
  3116. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3117. fprintf(f, "\n");
  3118. /*
  3119. NT synch is dead as of 5.0
  3120. fprintf(f, "dn: cn=ntSynchService preoperation,cn=plugins,cn=config\n");
  3121. fprintf(f, "objectclass: top\n");
  3122. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3123. fprintf(f, "objectclass: extensibleObject\n");
  3124. fprintf(f, "cn: ntSynchService preoperation\n");
  3125. fprintf(f, "nsslapd-pluginpath: %s/lib/ntsynch-plugin%s\n", sroot, shared_lib);
  3126. fprintf(f, "nsslapd-plugininitfunc: libntsynch_plugin_preop_init\n");
  3127. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3128. fprintf(f, "nsslapd-pluginenabled: on\n");
  3129. fprintf(f, "\n");
  3130. fprintf(f, "dn: cn=ntSynchService postoperation,cn=plugins,cn=config\n");
  3131. fprintf(f, "objectclass: top\n");
  3132. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3133. fprintf(f, "objectclass: extensibleObject\n");
  3134. fprintf(f, "cn: ntSynchService postoperation\n");
  3135. fprintf(f, "nsslapd-pluginpath: %s/lib/ntsynch-plugin%s\n", sroot, shared_lib);
  3136. fprintf(f, "nsslapd-plugininitfunc: libntsynch_plugin_postop_init\n");
  3137. fprintf(f, "nsslapd-plugintype: postoperation\n");
  3138. fprintf(f, "nsslapd-pluginenabled: on\n");
  3139. fprintf(f, "\n");
  3140. */
  3141. if (!cf->use_existing_user_ds) {
  3142. t = cf->suffix;
  3143. } else {
  3144. t = cf->netscaperoot;
  3145. }
  3146. /*
  3147. * LP: Turn attribute uniqueness plugin OFF by default
  3148. * defect 518862
  3149. */
  3150. fprintf(f, "dn: cn=attribute uniqueness,cn=plugins,cn=config\n");
  3151. fprintf(f, "objectclass: top\n");
  3152. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3153. fprintf(f, "objectclass: extensibleObject\n");
  3154. fprintf(f, "cn: attribute uniqueness\n");
  3155. fprintf(f, "nsslapd-pluginpath: %s/lib/attr-unique-plugin%s\n", sroot, shared_lib);
  3156. fprintf(f, "nsslapd-plugininitfunc: NSUniqueAttr_Init\n");
  3157. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3158. fprintf(f, "nsslapd-pluginenabled: off\n");
  3159. fprintf(f, "nsslapd-pluginarg0: uid\n");
  3160. fprintf(f, "nsslapd-pluginarg1: %s\n", t);
  3161. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3162. fprintf(f, "\n");
  3163. fprintf(f, "dn: cn=7-bit check,cn=plugins,cn=config\n");
  3164. fprintf(f, "objectclass: top\n");
  3165. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3166. fprintf(f, "objectclass: extensibleObject\n");
  3167. fprintf(f, "cn: 7-bit check\n");
  3168. fprintf(f, "nsslapd-pluginpath: %s/lib/attr-unique-plugin%s\n", sroot, shared_lib);
  3169. fprintf(f, "nsslapd-plugininitfunc: NS7bitAttr_Init\n");
  3170. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3171. fprintf(f, "nsslapd-pluginenabled: on\n");
  3172. fprintf(f, "nsslapd-pluginarg0: uid\n");
  3173. fprintf(f, "nsslapd-pluginarg1: mail\n");
  3174. fprintf(f, "nsslapd-pluginarg2: userpassword\n");
  3175. fprintf(f, "nsslapd-pluginarg3: ,\n");
  3176. fprintf(f, "nsslapd-pluginarg4: %s\n", t);
  3177. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3178. fprintf(f, "\n");
  3179. t = 0;
  3180. fprintf(f, "dn: cn=Internationalization Plugin,cn=plugins,cn=config\n");
  3181. fprintf(f, "objectclass: top\n");
  3182. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3183. fprintf(f, "objectclass: extensibleObject\n");
  3184. fprintf(f, "cn: Internationalization Plugin\n");
  3185. fprintf(f, "nsslapd-pluginpath: %s/lib/liblcoll%s\n", sroot, shared_lib);
  3186. fprintf(f, "nsslapd-plugininitfunc: orderingRule_init\n");
  3187. fprintf(f, "nsslapd-plugintype: matchingRule\n");
  3188. fprintf(f, "nsslapd-pluginenabled: on\n");
  3189. fprintf(f, "nsslapd-pluginarg0: %s/config/slapd-collations.conf\n", cs_path);
  3190. fprintf(f, "\n");
  3191. /* The HTTP client plugin */
  3192. fprintf(f, "dn: cn=HTTP Client,cn=plugins,cn=config\n");
  3193. fprintf(f, "objectclass: top\n");
  3194. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3195. fprintf(f, "objectclass: extensibleObject\n");
  3196. fprintf(f, "cn: HTTP Client\n");
  3197. fprintf(f, "nsslapd-pluginpath: %s/lib/http-client-plugin%s\n", sroot, shared_lib);
  3198. fprintf(f, "nsslapd-plugininitfunc: http_client_init\n");
  3199. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3200. fprintf(f, "nsslapd-pluginenabled: on\n");
  3201. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3202. fprintf(f, "\n");
  3203. #if defined (BUILD_PRESENCE)
  3204. /* The IM presence plugin root */
  3205. fprintf(f, "dn: cn=Presence,cn=plugins,cn=config\n");
  3206. fprintf(f, "objectclass: top\n");
  3207. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3208. fprintf(f, "objectclass: extensibleObject\n");
  3209. fprintf(f, "cn: Presence\n");
  3210. fprintf(f, "nsslapd-pluginpath: %s/lib/presence-plugin%s\n", sroot, shared_lib);
  3211. fprintf(f, "nsslapd-plugininitfunc: presence_init\n");
  3212. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3213. fprintf(f, "nsslapd-pluginenabled: on\n");
  3214. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3215. fprintf(f, "nsslapd-plugin-depends-on-named: HTTP Client\n");
  3216. fprintf(f, "\n");
  3217. /* The AIM presence plugin */
  3218. fprintf(f, "dn: cn=AIM Presence,cn=Presence,cn=plugins,cn=config\n");
  3219. fprintf(f, "objectclass: top\n");
  3220. fprintf(f, "objectclass: extensibleObject\n");
  3221. fprintf(f, "cn: AIM Presence\n");
  3222. fprintf(f, "nsim-id: nsAIMid\n");
  3223. fprintf(f, "nsim-urltext: http://big.oscar.aol.com/$nsaimid?on_url=http://online&off_url=http://offline\n");
  3224. fprintf(f, "nsim-urlgraphic: http://big.oscar.aol.com/$nsaimid?on_url=http://online&off_url=http://offline\n");
  3225. fprintf(f, "nsim-onvaluemaptext: http://online\n");
  3226. fprintf(f, "nsim-offvaluemaptext: http://offline\n");
  3227. fprintf(f, "nsim-urltextreturntype: TEXT\n");
  3228. fprintf(f, "nsim-urlgraphicreturntype: TEXT\n");
  3229. fprintf(f, "nsim-requestmethod: REDIRECT\n");
  3230. fprintf(f, "nsim-statustext: nsAIMStatusText\n");
  3231. fprintf(f, "nsim-statusgraphic: nsAIMStatusGraphic\n");
  3232. fprintf(f, "\n");
  3233. /* The ICQ presence plugin */
  3234. fprintf(f, "dn: cn=ICQ Presence,cn=Presence,cn=plugins,cn=config\n");
  3235. fprintf(f, "objectclass: top\n");
  3236. fprintf(f, "objectclass: extensibleObject\n");
  3237. fprintf(f, "cn: ICQ Presence\n");
  3238. fprintf(f, "nsim-id: nsICQid\n");
  3239. fprintf(f, "nsim-urltext: http://online.mirabilis.com/scripts/online.dll?icq=$nsicqid&img=5\n");
  3240. fprintf(f, "nsim-urlgraphic: http://online.mirabilis.com/scripts/online.dll?icq=$nsicqid&img=5\n");
  3241. fprintf(f, "nsim-onvaluemaptext: /lib/image/0,,4367,00.gif\n");
  3242. fprintf(f, "nsim-offvaluemaptext: /lib/image/0,,4349,00.gif\n");
  3243. fprintf(f, "nsim-urltextreturntype: TEXT\n");
  3244. fprintf(f, "nsim-urlgraphicreturntype: TEXT\n");
  3245. fprintf(f, "nsim-requestmethod: REDIRECT\n");
  3246. fprintf(f, "nsim-statustext: nsICQStatusText\n");
  3247. fprintf(f, "nsim-statusgraphic: nsICQStatusGraphic\n");
  3248. fprintf(f, "\n");
  3249. /* The Yahoo presence plugin */
  3250. fprintf(f, "dn: cn=Yahoo Presence,cn=Presence,cn=plugins,cn=config\n");
  3251. fprintf(f, "objectclass: top\n");
  3252. fprintf(f, "objectclass: extensibleObject\n");
  3253. fprintf(f, "cn: Yahoo Presence\n");
  3254. fprintf(f, "nsim-id: nsYIMid\n");
  3255. fprintf(f, "nsim-urltext: http://opi.yahoo.com/online?u=$nsyimid&m=t\n");
  3256. fprintf(f, "nsim-urlgraphic: http://opi.yahoo.com/online?u=$nsyimid&m=g&t=0\n");
  3257. fprintf(f, "nsim-onvaluemaptext: $nsyimid is ONLINE\n");
  3258. fprintf(f, "nsim-offvaluemaptext: $nsyimid is NOT ONLINE\n");
  3259. fprintf(f, "nsim-urltextreturntype: TEXT\n");
  3260. fprintf(f, "nsim-urlgraphicreturntype: BINARY\n");
  3261. fprintf(f, "nsim-requestmethod: GET\n");
  3262. fprintf(f, "nsim-statustext: nsYIMStatusText\n");
  3263. fprintf(f, "nsim-statusgraphic: nsYIMStatusGraphic\n");
  3264. fprintf(f, "\n");
  3265. #endif
  3266. /* enable pass thru authentication */
  3267. if (cf->use_existing_config_ds || cf->use_existing_user_ds)
  3268. {
  3269. LDAPURLDesc *desc = 0;
  3270. char *url = cf->use_existing_config_ds ? cf->config_ldap_url :
  3271. cf->user_ldap_url;
  3272. if (url && !ldap_url_parse(url, &desc) && desc)
  3273. {
  3274. char *suffix = desc->lud_dn;
  3275. char *service = !strncmp(url, "ldaps:", strlen("ldaps:")) ?
  3276. "ldaps" : "ldap";
  3277. if (cf->use_existing_config_ds)
  3278. {
  3279. suffix = cf->netscaperoot;
  3280. }
  3281. suffix = ds_URL_encode(suffix);
  3282. fprintf(f, "dn: cn=Pass Through Authentication,cn=plugins,cn=config\n");
  3283. fprintf(f, "objectclass: top\n");
  3284. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3285. fprintf(f, "objectclass: extensibleObject\n");
  3286. fprintf(f, "cn: Pass Through Authentication\n");
  3287. fprintf(f, "nsslapd-pluginpath: %s/lib/passthru-plugin%s\n", sroot, shared_lib);
  3288. fprintf(f, "nsslapd-plugininitfunc: passthruauth_init\n");
  3289. fprintf(f, "nsslapd-plugintype: preoperation\n");
  3290. fprintf(f, "nsslapd-pluginenabled: on\n");
  3291. fprintf(f, "nsslapd-pluginarg0: %s://%s:%d/%s\n", service, desc->lud_host, desc->lud_port,
  3292. suffix);
  3293. fprintf(f, "nsslapd-plugin-depends-on-type: database\n");
  3294. fprintf(f, "\n");
  3295. free(suffix);
  3296. ldap_free_urldesc(desc);
  3297. }
  3298. }
  3299. fprintf(f, "dn: cn=ldbm database,cn=plugins,cn=config\n");
  3300. fprintf(f, "objectclass: top\n");
  3301. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3302. fprintf(f, "objectclass: extensibleObject\n");
  3303. fprintf(f, "cn: ldbm database\n");
  3304. fprintf(f, "nsslapd-pluginpath: %s/lib/libback-ldbm%s\n", sroot, shared_lib);
  3305. fprintf(f, "nsslapd-plugininitfunc: ldbm_back_init\n");
  3306. fprintf(f, "nsslapd-plugintype: database\n");
  3307. fprintf(f, "nsslapd-pluginenabled: on\n");
  3308. fprintf(f, "nsslapd-plugin-depends-on-type: Syntax\n");
  3309. fprintf(f, "nsslapd-plugin-depends-on-type: matchingRule\n");
  3310. fprintf(f, "\n");
  3311. if (strlen(cf->suffix) == 0){
  3312. rootdse = 1;
  3313. }
  3314. /* Entries for the ldbm plugin */
  3315. fprintf(f, "dn: cn=config,cn=ldbm database,cn=plugins,cn=config\n");
  3316. fprintf(f, "objectclass: top\n");
  3317. fprintf(f, "objectclass: extensibleObject\n");
  3318. fprintf(f, "cn: config\n");
  3319. fprintf(f, "nsslapd-lookthroughlimit: 5000\n");
  3320. fprintf(f, "nsslapd-mode: 600\n");
  3321. fprintf(f, "nsslapd-directory: %s/db\n", cs_path);
  3322. fprintf(f, "nsslapd-dbcachesize: 10485760\n");
  3323. /* will be default from 6.2 or 6.11... */
  3324. if (getenv("USE_OLD_IDL_SWITCH")) {
  3325. fprintf(f, "nsslapd-idl-switch: old\n");
  3326. }
  3327. fprintf(f, "\n");
  3328. /* Placeholder for the default user-defined ldbm indexes */
  3329. fprintf(f, "dn: cn=default indexes, cn=config,cn=ldbm database,cn=plugins,cn=config\n");
  3330. fprintf(f, "objectclass: top\n");
  3331. fprintf(f, "objectclass: extensibleObject\n");
  3332. fprintf(f, "cn: default indexes\n");
  3333. fprintf(f, "\n");
  3334. /* default user-defined ldbm indexes */
  3335. ds_gen_index(f, "cn=default indexes, cn=config,cn=ldbm database,cn=plugins,cn=config");
  3336. fprintf(f, "dn: cn=monitor, cn=ldbm database, cn=plugins, cn=config\n");
  3337. fprintf(f, "objectclass: top\n");
  3338. fprintf(f, "objectclass: extensibleObject\n");
  3339. fprintf(f, "cn: monitor\n");
  3340. fprintf(f, "\n");
  3341. fprintf(f, "dn: cn=database, cn=monitor, cn=ldbm database, cn=plugins, cn=config\n");
  3342. fprintf(f, "objectclass: top\n");
  3343. fprintf(f, "objectclass: extensibleObject\n");
  3344. fprintf(f, "cn: database\n");
  3345. fprintf(f, "\n");
  3346. /* Entries for the chaining backend plugin */
  3347. fprintf(f, "dn: cn=chaining database,cn=plugins,cn=config\n");
  3348. fprintf(f, "objectclass: top\n");
  3349. fprintf(f, "objectclass: nsSlapdPlugin\n");
  3350. fprintf(f, "objectclass: extensibleObject\n");
  3351. fprintf(f, "cn: chaining database\n");
  3352. fprintf(f, "nsslapd-pluginpath: %s/lib/chainingdb-plugin%s\n", sroot, shared_lib);
  3353. fprintf(f, "nsslapd-plugininitfunc: chaining_back_init\n");
  3354. fprintf(f, "nsslapd-plugintype: database\n");
  3355. fprintf(f, "nsslapd-pluginenabled: on\n");
  3356. fprintf(f, "\n");
  3357. fprintf(f, "dn: cn=config,cn=chaining database,cn=plugins,cn=config\n");
  3358. fprintf(f, "objectclass: top\n");
  3359. fprintf(f, "objectclass: extensibleObject\n");
  3360. fprintf(f, "cn: config\n");
  3361. fprintf(f, "nsTransmittedControls: 2.16.840.1.113730.3.4.2\n");
  3362. fprintf(f, "nsTransmittedControls: 2.16.840.1.113730.3.4.9\n");
  3363. fprintf(f, "nsTransmittedControls: 1.2.840.113556.1.4.473\n");
  3364. fprintf(f, "nsTransmittedControls: 1.3.6.1.4.1.1466.29539.12\n");
  3365. fprintf(f, "nsPossibleChainingComponents: cn=resource limits,cn=components,cn=config\n");
  3366. fprintf(f, "nsPossibleChainingComponents: cn=certificate-based authentication,cn=components,cn=config\n");
  3367. fprintf(f, "nsPossibleChainingComponents: cn=ACL Plugin,cn=plugins,cn=config\n");
  3368. fprintf(f, "nsPossibleChainingComponents: cn=old plugin,cn=plugins,cn=config\n");
  3369. fprintf(f, "nsPossibleChainingComponents: cn=referential integrity postoperation,cn=plugins,cn=config\n");
  3370. fprintf(f, "nsPossibleChainingComponents: cn=attribute uniqueness,cn=plugins,cn=config\n");
  3371. fprintf(f, "\n");
  3372. free(t);
  3373. t = NULL;
  3374. /* suffix for the mapping tree */
  3375. fprintf(f, "dn: cn=mapping tree,cn=config\n");
  3376. fprintf(f, "objectclass: top\n");
  3377. fprintf(f, "objectclass: extensibleObject\n");
  3378. fprintf(f, "cn: mapping tree\n");
  3379. fprintf(f, "\n");
  3380. fprintf(f, "dn: cn=tasks,cn=config\n");
  3381. fprintf(f, "objectclass: top\n");
  3382. fprintf(f, "objectclass: extensibleObject\n");
  3383. fprintf(f, "cn: tasks\n");
  3384. fprintf(f, "\n");
  3385. /* Entries for the ldbm instances and mapping tree */
  3386. if ( cf->netscaperoot && !cf->use_existing_config_ds)
  3387. {
  3388. suffix_gen_conf(f, cf->netscaperoot, "NetscapeRoot");
  3389. }
  3390. if (!cf->use_existing_user_ds)
  3391. {
  3392. suffix_gen_conf(f, cf->suffix, "userRoot");
  3393. }
  3394. if ( cf->samplesuffix && cf->suffix && PL_strcasecmp(cf->samplesuffix, cf->suffix))
  3395. {
  3396. suffix_gen_conf(f, cf->samplesuffix, "sampleRoot");
  3397. }
  3398. if ( cf->testconfig && cf->suffix && PL_strcasecmp(cf->testconfig, cf->suffix))
  3399. {
  3400. suffix_gen_conf(f, cf->testconfig, "testRoot");
  3401. }
  3402. /* tasks */
  3403. fprintf(f, "dn: cn=import,cn=tasks,cn=config\n");
  3404. fprintf(f, "objectclass: top\n");
  3405. fprintf(f, "objectclass: extensibleObject\n");
  3406. fprintf(f, "cn: import\n");
  3407. fprintf(f, "\n");
  3408. fprintf(f, "dn: cn=export,cn=tasks,cn=config\n");
  3409. fprintf(f, "objectclass: top\n");
  3410. fprintf(f, "objectclass: extensibleObject\n");
  3411. fprintf(f, "cn: export\n");
  3412. fprintf(f, "\n");
  3413. fprintf(f, "dn: cn=backup,cn=tasks,cn=config\n");
  3414. fprintf(f, "objectclass: top\n");
  3415. fprintf(f, "objectclass: extensibleObject\n");
  3416. fprintf(f, "cn: backup\n");
  3417. fprintf(f, "\n");
  3418. fprintf(f, "dn: cn=restore,cn=tasks,cn=config\n");
  3419. fprintf(f, "objectclass: top\n");
  3420. fprintf(f, "objectclass: extensibleObject\n");
  3421. fprintf(f, "cn: restore\n");
  3422. fprintf(f, "\n");
  3423. #if defined(UPGRADEDB)
  3424. fprintf(f, "dn: cn=upgradedb,cn=tasks,cn=config\n");
  3425. fprintf(f, "objectclass: top\n");
  3426. fprintf(f, "objectclass: extensibleObject\n");
  3427. fprintf(f, "cn: upgradedb\n");
  3428. fprintf(f, "\n");
  3429. #endif
  3430. /* END of tasks */
  3431. fprintf(f, "dn: cn=replication,cn=config\n");
  3432. fprintf(f, "objectclass: top\n");
  3433. fprintf(f, "objectclass: extensibleObject\n");
  3434. fprintf(f, "cn: replication\n");
  3435. fprintf(f, "\n");
  3436. if( cf->replicationdn && *(cf->replicationdn) )
  3437. {
  3438. fprintf(f, "dn: cn=replication4,cn=replication,cn=config\n");
  3439. fprintf(f, "cn: replication4\n");
  3440. fprintf(f, "objectclass: top\n");
  3441. fprintf(f, "objectclass: nsConsumer4Config\n");
  3442. fprintf(f, "nsslapd-updatedn: %s\n", cf->replicationdn);
  3443. fprintf(f, "nsslapd-updatepw: %s\n", cf->replicationhashedpw);
  3444. fprintf(f, "\n");
  3445. }
  3446. if(cf->changelogdir && *(cf->changelogdir) )
  3447. {
  3448. fprintf(f, "dn: cn=changelog4,cn=config\n");
  3449. fprintf(f, "cn: changelog4\n");
  3450. fprintf(f, "objectclass: top\n");
  3451. fprintf(f, "objectclass: nsChangelog4Config\n");
  3452. fprintf(f, "nsslapd-changelogdir: %s\n", cf->changelogdir);
  3453. fprintf(f, "nsslapd-changelogsuffix: %s\n", cf->changelogsuffix);
  3454. fprintf(f, "nsslapd-changelogmaxage: 2d\n");
  3455. fprintf(f, "\n");
  3456. /* create the changelog directory */
  3457. if( (t = create_instance_mkdir_p(cf->changelogdir, NEWDIR_MODE)) )
  3458. return(t);
  3459. }
  3460. fclose (f);
  3461. sprintf(src, "%s%cconfig%cdse.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3462. sprintf(fn, "%s%cconfig%cdse_original.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3463. create_instance_copy(src, fn, 0600);
  3464. /*
  3465. * generate slapd-collations.conf
  3466. */
  3467. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cconfig%c%s-collations.conf",
  3468. sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3469. FILE_PATHSEP, PRODUCT_NAME);
  3470. sprintf(dest, "%s%cconfig%c%s-collations.conf", cs_path, FILE_PATHSEP,
  3471. FILE_PATHSEP, PRODUCT_NAME);
  3472. if (!(srcf = fopen(src, "r"))) {
  3473. return make_error("Can't read from %s (%s)", src, ds_system_errmsg());
  3474. }
  3475. if (!(f = fopen(dest, "w"))) {
  3476. return make_error("Can't write to %s (%s)", dest, ds_system_errmsg());
  3477. }
  3478. while (fgets(line, sizeof(line), srcf)) {
  3479. if ((line[0] != '\0') && (fputs(line, f) == EOF)) {
  3480. make_error("Error writing to file %s from copy of %s (%s)",
  3481. dest, src, ds_system_errmsg());
  3482. }
  3483. }
  3484. if (!feof(srcf)) {
  3485. make_error("Error reading from file %s (%s)", src, ds_system_errmsg());
  3486. }
  3487. fclose(srcf);
  3488. fclose(f);
  3489. sprintf(src, "%s/bin/slapd/install/schema", sroot);
  3490. sprintf(dest, "%s/config/schema", cs_path);
  3491. if (NULL != (t = ds_copy_group_files(src, dest, 0)))
  3492. return t;
  3493. #if defined (BUILD_PRESENCE)
  3494. sprintf(src, "%s/bin/slapd/install/presence", sroot);
  3495. sprintf(dest, "%s/config/presence", cs_path);
  3496. if (t = ds_copy_group_files(src, dest, 0))
  3497. return t;
  3498. #endif
  3499. /* Generate the orgchart configuration */
  3500. sprintf(src, "%s/clients", sroot);
  3501. if (is_a_dir(src, "orgchart")) {
  3502. if (NULL != (t = ds_gen_orgchart_conf(sroot, cs_path, cf))) {
  3503. return t;
  3504. }
  3505. }
  3506. /* Generate dsgw.conf */
  3507. sprintf(src, "%s/clients", sroot);
  3508. if (is_a_dir(src, "dsgw")) {
  3509. if (NULL != (t = ds_gen_gw_conf(sroot, cs_path, cf, GW_CONF))) {
  3510. return t;
  3511. }
  3512. /* Generate pb.conf */
  3513. if (NULL != (t = ds_gen_gw_conf(sroot, cs_path, cf, PB_CONF))) {
  3514. return t;
  3515. }
  3516. }
  3517. return NULL; /* Everything worked fine */
  3518. }
  3519. /*
  3520. * Function: ds_gen_gw_conf
  3521. *
  3522. * Returns: pointer to error message, or NULL if all went well
  3523. *
  3524. * Description: This generates the gateway configuration files
  3525. * for the regular gateway stuff and for the phonebook.
  3526. *
  3527. * Author: RJP
  3528. *
  3529. */
  3530. static char *
  3531. ds_gen_gw_conf(char *sroot, char *cs_path, server_config_s *cf, int conf_type)
  3532. {
  3533. char dest[PATH_SIZE];
  3534. char src[PATH_SIZE];
  3535. char line[1024];
  3536. FILE *f = NULL;
  3537. FILE *srcf = NULL;
  3538. char *t = NULL;
  3539. const char *ctxt;
  3540. if (conf_type == GW_CONF) {
  3541. ctxt = "dsgw";
  3542. } else {
  3543. ctxt = "pb";
  3544. }
  3545. /*
  3546. * generate .../dsgw/context/[dsgw|pb].conf by creating the file, placing
  3547. * install-specific config. file lines at the start of file, and then
  3548. * copying the rest from NS-HOME/dsgw/config/dsgw.tmpl
  3549. */
  3550. sprintf(dest, "%s%cclients%cdsgw%ccontext%c%s.conf", sroot, FILE_PATHSEP,FILE_PATHSEP,
  3551. FILE_PATHSEP, FILE_PATHSEP, ctxt);
  3552. /* If the config file already exists, just return success */
  3553. if (create_instance_exists(dest)) {
  3554. return(NULL);
  3555. }
  3556. /* Attempt to open that bad boy */
  3557. if(!(f = fopen(dest, "w"))) {
  3558. return make_error("Can't write to %s (%s)", dest, ds_system_errmsg());
  3559. }
  3560. /* Write out the appropriate values */
  3561. fprintf(f, "# Used by Netscape Directory Server Gateway\n");
  3562. fprintf(f, "baseurl\t\"ldap://%s:%s/", cf->servname, cf->servport);
  3563. fputs_escaped(cf->suffix, f);
  3564. fputs("\"\n\n",f);
  3565. if (cf->rootdn && *(cf->rootdn)) {
  3566. t = ds_enquote_config_value(DS_ROOTDN, cf->rootdn);
  3567. fprintf(f, "dirmgr\t%s\n\n", t );
  3568. if (t != cf->rootdn) free(t);
  3569. }
  3570. t = ds_enquote_config_value(DS_SUFFIX, cf->suffix);
  3571. fprintf(f, "location-suffix\t%s\n\n", t);
  3572. if (t != cf->suffix) free(t);
  3573. fprintf(f, "securitypath\t\"%s%calias%c%s-cert.db\"\n\n", sroot, FILE_PATHSEP, FILE_PATHSEP, ctxt );
  3574. fprintf(f, "# The url base to the orgchart application.\n#No link from the DSGW to the orgchart will appear in the UI if this configuration line is commented out.\n");
  3575. fprintf(f, "url-orgchart-base\thttp://%s:%s/clients/orgchart/bin/org?context=%s&data=\n\n", cf->servname, cf->adminport ? cf->adminport : "80", ctxt);
  3576. /* copy in template */
  3577. if (conf_type == GW_CONF) {
  3578. sprintf(src, "%s%cclients%cdsgw%cconfig%cdsgw.tmpl",
  3579. sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  3580. } else if (conf_type == PB_CONF) {
  3581. sprintf(src, "%s%cclients%cdsgw%cpbconfig%cpb.tmpl",
  3582. sroot, FILE_PATHSEP,FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  3583. } else {
  3584. /*This should never, ever happen if this function is called correctly*/
  3585. fclose(f);
  3586. return make_error("Unknown gateway config file requested");
  3587. }
  3588. /* Try to open the dsgw.conf template file (dsgw.tmpl) */
  3589. if(!(srcf = fopen(src, "r"))) {
  3590. fclose(f);
  3591. return make_error("Can't read %s (%s)", src, ds_system_errmsg());
  3592. }
  3593. while(fgets(line, sizeof(line), srcf)) {
  3594. fputs(line, f);
  3595. }
  3596. fclose(srcf);
  3597. fclose(f);
  3598. /* Generate default.conf */
  3599. if (conf_type == GW_CONF) {
  3600. struct passwd* pw = NULL;
  3601. char defaultconf[PATH_SIZE];
  3602. #if !defined( XP_WIN32 )
  3603. /* find the server's UID and GID */
  3604. if (cf->servuser && *(cf->servuser)) {
  3605. if ((pw = getpwnam (cf->servuser)) == NULL) {
  3606. return make_error("Could not find UID and GID of user '%s'.", cf->servuser);
  3607. } else if (pw->pw_name == NULL) {
  3608. pw->pw_name = cf->servuser;
  3609. }
  3610. }
  3611. #endif
  3612. sprintf(defaultconf, "%s%cclients%cdsgw%ccontext%cdefault.conf", sroot,
  3613. FILE_PATHSEP,FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP);
  3614. create_instance_copy(dest, defaultconf, NEWFILE_MODE);
  3615. chownfile (pw, defaultconf);
  3616. }
  3617. unlink(src);
  3618. return NULL;
  3619. }
  3620. /*
  3621. * Function: ds_gen_orgchart_conf
  3622. *
  3623. * Returns: pointer to error message, or NULL if all went well
  3624. *
  3625. * Description: This generates the orgchart configuration file
  3626. *
  3627. * Author: RJP
  3628. *
  3629. */
  3630. static char *
  3631. ds_gen_orgchart_conf(char *sroot, char *cs_path, server_config_s *cf)
  3632. {
  3633. char dest[PATH_SIZE];
  3634. char src[PATH_SIZE];
  3635. char line[1024];
  3636. FILE *f = NULL;
  3637. FILE *srcf = NULL;
  3638. /*
  3639. * generate .../clients/orgchart/config.txt by creating the file, placing
  3640. * install-specific config. file lines at the start of file, and then
  3641. * copying the rest from NS-HOME/clients/orgchart/config.tmpl
  3642. */
  3643. sprintf(dest, "%s%cclients%corgchart%cconfig.txt", sroot, FILE_PATHSEP,
  3644. FILE_PATHSEP, FILE_PATHSEP );
  3645. sprintf(src, "%s%cclients%corgchart%cconfig.tmpl", sroot, FILE_PATHSEP,
  3646. FILE_PATHSEP, FILE_PATHSEP);
  3647. /* If the config file already exists, just return success */
  3648. if (create_instance_exists(dest)) {
  3649. return(NULL);
  3650. }
  3651. /* Attempt to open that bad boy */
  3652. if(!(f = fopen(dest, "w"))) {
  3653. return make_error("Cannot write to %s (%s)", dest, ds_system_errmsg());
  3654. }
  3655. /* Write out the appropriate values */
  3656. fprintf(f, "#############\n#\n#\n");
  3657. fprintf(f, "# Configuration file for Netscape Directory Server Org Chart\n");
  3658. fprintf(f, "# ----------------------------------------------------------\n#\n#\n");
  3659. fprintf(f, "#############\n\n\n#\n");
  3660. fprintf(f, "# Blank lines in this file, as well as lines that\n");
  3661. fprintf(f, "# start with at least one \"#\" character, are both ignored.\n");
  3662. fprintf(f, "#\n#\n");
  3663. fprintf(f, "# Name/Value pairs below are (and need to be) separated with\n");
  3664. fprintf(f, "# one or more tabs (or spaces)\n");
  3665. fprintf(f, "#\n");
  3666. fprintf(f, "ldap-host\t%s\n", cf->servname);
  3667. fprintf(f, "ldap-port\t%s\n", cf->servport);
  3668. fprintf(f, "ldap-search-base\t%s\n\n", cf->suffix);
  3669. fprintf(f, "#\n# If you would like to have the phonebook icon visible, you must\n");
  3670. fprintf(f, "# supply the partial phonebook URL below, which will have each\n");
  3671. fprintf(f, "# given user's DN attribute value concatenated to the end.\n");
  3672. fprintf(f, "#\n# For example, you could specify below something close to:\n");
  3673. fprintf(f, "#\n# url-phonebook-base http://hostname.domain.com/dsgw/bin/dosearch?context=default&hp=localhost&dn=\n#\n\n");
  3674. fprintf(f, "url-phonebook-base\thttp://%s:%s/clients/dsgw/bin/dosearch?context=pb&hp=%s:%s&dn=\n\n",cf->servname, cf->adminport ? cf->adminport : "80", cf->servname, cf->servport);
  3675. /* Try to open the config.txt template file (config.tmpl) */
  3676. if(!(srcf = fopen(src, "r"))) {
  3677. fclose(f);
  3678. return make_error("Can't read %s (%s)", src, ds_system_errmsg());
  3679. }
  3680. while(fgets(line, sizeof(line), srcf)) {
  3681. fputs(line, f);
  3682. }
  3683. fclose(srcf);
  3684. fclose(f);
  3685. unlink(src);
  3686. return NULL;
  3687. }
  3688. #if defined (BUILD_PRESENCE)
  3689. /*
  3690. * Function: gen_presence_init
  3691. *
  3692. * Description: Creates a script to initialize images for use in the IM
  3693. * Presence plugin.
  3694. */
  3695. #define PRESENCE_LDIF "init_presence_images.ldif"
  3696. static char *gen_presence_init_script(char *sroot, server_config_s *cf,
  3697. char *cs_path)
  3698. {
  3699. char fn[PATH_SIZE];
  3700. char dir[PATH_SIZE];
  3701. FILE *f;
  3702. sprintf(dir, "%s%cconfig%cpresence",
  3703. cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3704. sprintf(fn, "%s%c%s",
  3705. dir, FILE_PATHSEP, PRESENCE_LDIF);
  3706. if(!(f = fopen(fn, "w")))
  3707. return make_error("Could not write to %s (%s).", fn, ds_system_errmsg());
  3708. fprintf( f,
  3709. "dn:cn=ICQ Presence,cn=Presence,cn=plugins,cn=config\n"
  3710. "changeType:modify\n"
  3711. "replace:nsim-onvaluemapgraphic\n"
  3712. "nsim-onvaluemapgraphic: %s%cicq-online.gif\n"
  3713. "\n"
  3714. "dn:cn=ICQ Presence,cn=Presence,cn=plugins,cn=config\n"
  3715. "changeType:modify\n"
  3716. "replace:nsim-offvaluemapgraphic\n"
  3717. "nsim-offvaluemapgraphic: %s%cicq-offline.gif\n"
  3718. "\n"
  3719. "dn:cn=ICQ Presence,cn=Presence,cn=plugins,cn=config\n"
  3720. "changeType:modify\n"
  3721. "replace:nsim-disabledvaluemapgraphic\n"
  3722. "nsim-disabledvaluemapgraphic: %s%cicq-disabled.gif\n"
  3723. "\n"
  3724. "dn:cn=AIM Presence,cn=Presence,cn=plugins,cn=config\n"
  3725. "changeType:modify\n"
  3726. "replace:nsim-onvaluemapgraphic\n"
  3727. "nsim-onvaluemapgraphic: %s%caim-online.gif\n"
  3728. "\n"
  3729. "dn:cn=AIM Presence,cn=Presence,cn=plugins,cn=config\n"
  3730. "changeType:modify\n"
  3731. "replace:nsim-offvaluemapgraphic\n"
  3732. "nsim-offvaluemapgraphic: %s%caim-offline.gif\n"
  3733. "\n"
  3734. "dn:cn=AIM Presence,cn=Presence,cn=plugins,cn=config\n"
  3735. "changeType:modify\n"
  3736. "replace:nsim-disabledvaluemapgraphic\n"
  3737. "nsim-disabledvaluemapgraphic: %s%caim-offline.gif\n"
  3738. "\n"
  3739. "dn:cn=Yahoo Presence,cn=Presence,cn=plugins,cn=config\n"
  3740. "changeType:modify\n"
  3741. "replace:nsim-offvaluemapgraphic\n"
  3742. "nsim-offvaluemapgraphic: %s%cyahoo-offline.gif\n"
  3743. "\n"
  3744. "dn:cn=Yahoo Presence,cn=Presence,cn=plugins,cn=config\n"
  3745. "changeType:modify\n"
  3746. "replace:nsim-onvaluemapgraphic\n"
  3747. "nsim-onvaluemapgraphic: %s%cyahoo-online.gif\n"
  3748. "\n"
  3749. "dn:cn=Yahoo Presence,cn=Presence,cn=plugins,cn=config\n"
  3750. "changeType:modify\n"
  3751. "replace:nsim-disabledvaluemapgraphic\n"
  3752. "nsim-disabledvaluemapgraphic: %s%cyahoo-offline.gif\n",
  3753. dir, FILE_PATHSEP,
  3754. dir, FILE_PATHSEP,
  3755. dir, FILE_PATHSEP,
  3756. dir, FILE_PATHSEP,
  3757. dir, FILE_PATHSEP,
  3758. dir, FILE_PATHSEP,
  3759. dir, FILE_PATHSEP,
  3760. dir, FILE_PATHSEP,
  3761. dir, FILE_PATHSEP
  3762. );
  3763. fclose(f);
  3764. return NULL;
  3765. }
  3766. /*
  3767. * Function init_presence
  3768. *
  3769. * Description: Runs ldapmodify to initialize the images used by the
  3770. * IM presence plugin
  3771. */
  3772. static int init_presence(char *sroot, server_config_s *cf, char *cs_path)
  3773. {
  3774. char cmd[PATH_SIZE];
  3775. char tools[PATH_SIZE];
  3776. char precmd[PATH_SIZE];
  3777. precmd[0] = 0;
  3778. sprintf(tools, "%s%cshared%cbin", sroot, FILE_PATHSEP, FILE_PATHSEP);
  3779. #ifdef XP_UNIX
  3780. sprintf(precmd, "cd %s;", tools);
  3781. #endif
  3782. sprintf(cmd, "%s%s%cldapmodify -q -p %d -b -D \"%s\" -w \"%s\" "
  3783. "-f %s%s%cconfig%cpresence%c%s%s",
  3784. precmd,
  3785. tools, FILE_PATHSEP,
  3786. atoi(cf->servport),
  3787. cf->rootdn,
  3788. cf->rootpw,
  3789. ENQUOTE, cs_path, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3790. PRESENCE_LDIF, ENQUOTE);
  3791. return ds_exec_and_report( cmd );
  3792. }
  3793. #endif
  3794. /*
  3795. * Function: ds_gen_index
  3796. *
  3797. * Description: This generates the default index list.
  3798. * This function is passed the parent entry below which the nsIndex
  3799. * entries must be created. This allows to use it when creating:
  3800. * - the default index list (ie belowdn = cn=default indexes,cn=config...)
  3801. * - the userRoot backend (ie belowdn = cn=index,cn=userRoot...)
  3802. *
  3803. */
  3804. static void
  3805. ds_gen_index(FILE* f, char* belowdn)
  3806. {
  3807. #define MKINDEX(_name, _inst, _sys, _type1, _type2, _type3) do { \
  3808. fprintf(f, "dn: cn=%s,%s\n", (_name), (_inst)); \
  3809. fprintf(f, "objectclass: top\n"); \
  3810. fprintf(f, "objectclass: nsIndex\n"); \
  3811. fprintf(f, "cn: %s\n", (_name)); \
  3812. fprintf(f, "nssystemindex: %s\n", (_sys) ? "true" : "false"); \
  3813. if (_type1) \
  3814. fprintf(f, "nsindextype: %s\n", (_type1)); \
  3815. if (_type2) \
  3816. fprintf(f, "nsindextype: %s\n", (_type2)); \
  3817. if (_type3) \
  3818. fprintf(f, "nsindextype: %s\n", (_type3)); \
  3819. fprintf(f, "\n"); \
  3820. } while (0)
  3821. MKINDEX("aci", belowdn, 1, "pres", NULL, NULL);
  3822. MKINDEX("cn", belowdn, 0, "pres", "eq", "sub");
  3823. MKINDEX("entrydn", belowdn, 1, "eq", NULL, NULL);
  3824. MKINDEX("givenName", belowdn, 0, "pres", "eq", "sub");
  3825. MKINDEX("mail", belowdn, 0, "pres", "eq", "sub");
  3826. MKINDEX("mailAlternateAddress", belowdn, 0, "eq", NULL, NULL);
  3827. MKINDEX("mailHost", belowdn, 0, "eq", NULL, NULL);
  3828. MKINDEX("member", belowdn, 0, "eq", NULL, NULL);
  3829. MKINDEX("nsCalXItemId", belowdn, 0, "pres", "eq", "sub");
  3830. MKINDEX("nsLIProfileName", belowdn, 0, "eq", NULL, NULL);
  3831. MKINDEX("nsUniqueId", belowdn, 1, "eq", NULL, NULL);
  3832. MKINDEX("nswcalCALID", belowdn, 0, "eq", NULL, NULL);
  3833. MKINDEX("numsubordinates", belowdn, 1, "pres", NULL, NULL);
  3834. MKINDEX("objectclass", belowdn, 1, "eq", NULL, NULL);
  3835. MKINDEX("owner", belowdn, 0, "eq", NULL, NULL);
  3836. MKINDEX("parentid", belowdn, 1, "eq", NULL, NULL);
  3837. MKINDEX("pipstatus", belowdn, 0, "eq", NULL, NULL);
  3838. MKINDEX("pipuid", belowdn, 0, "pres", NULL, NULL);
  3839. MKINDEX("seeAlso", belowdn, 0, "eq", NULL, NULL);
  3840. MKINDEX("sn", belowdn, 0, "pres", "eq", "sub");
  3841. MKINDEX("telephoneNumber", belowdn, 0, "pres", "eq", "sub");
  3842. MKINDEX("uid", belowdn, 0, "eq", NULL, NULL);
  3843. MKINDEX("uniquemember", belowdn, 0, "eq", NULL, NULL);
  3844. }
  3845. static char *install_ds(char *sroot, server_config_s *cf, char *param_name)
  3846. {
  3847. SLAPD_CONFIG slapd_conf;
  3848. QUERY_VARS query_vars;
  3849. char *t, src[PATH_SIZE], dest[PATH_SIZE], big_line[PATH_SIZE];
  3850. char cs_path[PATH_SIZE];
  3851. struct passwd* pw = NULL;
  3852. int isrunning;
  3853. int status = 0;
  3854. #ifdef XP_WIN32
  3855. WSADATA wsadata;
  3856. #endif
  3857. #if !defined( XP_WIN32 )
  3858. /* find the server's UID and GID */
  3859. if (cf->servuser && *(cf->servuser)) {
  3860. if ((pw = getpwnam (cf->servuser)) == NULL) {
  3861. strcpy(param_name, "servuser");
  3862. return make_error("Could not find UID and GID of user '%s'.",
  3863. cf->servuser);
  3864. } else if (pw->pw_name == NULL) {
  3865. pw->pw_name = cf->servuser;
  3866. }
  3867. }
  3868. #endif
  3869. sprintf(cs_path, "%s%c"PRODUCT_NAME"-%s", sroot, FILE_PATHSEP, cf->servid);
  3870. /* create all <a_server>/<subdirs> */
  3871. if ( (t = ds_cre_subdirs(sroot, cf, cs_path, pw)) )
  3872. return(t);
  3873. /* Generate all scripts */
  3874. if ( (t = ds_gen_scripts(sroot, cf, cs_path)) )
  3875. return(t);
  3876. #if defined( XP_WIN32 )
  3877. ds_dostounixpath( sroot );
  3878. ds_dostounixpath( cs_path );
  3879. #endif
  3880. /* Generate all conf files */
  3881. if ( (t = ds_gen_confs(sroot, cf, cs_path)) )
  3882. return(t);
  3883. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cldif%cExample.ldif", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3884. FILE_PATHSEP);
  3885. sprintf(dest, "%s%cldif%cExample.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3886. create_instance_copy(src, dest, NEWFILE_MODE);
  3887. chownfile (pw, dest);
  3888. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cldif%cExample-roles.ldif", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3889. FILE_PATHSEP);
  3890. sprintf(dest, "%s%cldif%cExample-roles.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3891. create_instance_copy(src, dest, NEWFILE_MODE);
  3892. chownfile (pw, dest);
  3893. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cldif%cExample-views.ldif", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3894. FILE_PATHSEP);
  3895. sprintf(dest, "%s%cldif%cExample-views.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3896. create_instance_copy(src, dest, NEWFILE_MODE);
  3897. chownfile (pw, dest);
  3898. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cldif%cEuropean.ldif", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3899. FILE_PATHSEP);
  3900. sprintf(dest, "%s%cldif%cEuropean.ldif", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3901. create_instance_copy(src, dest, NEWFILE_MODE);
  3902. chownfile (pw, dest);
  3903. /* new code for dsml sample files */
  3904. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cdsml%cExample.dsml", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3905. FILE_PATHSEP);
  3906. sprintf(dest, "%s%cdsml%cExample.dsml", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3907. create_instance_copy(src, dest, NEWFILE_MODE);
  3908. chownfile (pw, dest);
  3909. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cdsml%cExample-roles.dsml", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3910. FILE_PATHSEP);
  3911. sprintf(dest, "%s%cdsml%cExample-roles.dsml", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3912. create_instance_copy(src, dest, NEWFILE_MODE);
  3913. chownfile (pw, dest);
  3914. sprintf(src, "%s%cbin%c"PRODUCT_NAME"%cinstall%cdsml%cEuropean.dsml", sroot, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP, FILE_PATHSEP,
  3915. FILE_PATHSEP);
  3916. sprintf(dest, "%s%cdsml%cEuropean.dsml", cs_path, FILE_PATHSEP, FILE_PATHSEP);
  3917. create_instance_copy(src, dest, NEWFILE_MODE);
  3918. chownfile (pw, dest);
  3919. /*
  3920. If the user has specified an LDIF file to use to initialize the database,
  3921. load it now
  3922. */
  3923. if (cf->install_ldif_file && !access(cf->install_ldif_file, 0))
  3924. {
  3925. char msg[2*PATH_SIZE] = {0};
  3926. int status = ds_ldif2db_backend_subtree(cf->install_ldif_file, NULL, cf->suffix);
  3927. if (status)
  3928. sprintf(msg, "The file %s could not be loaded",
  3929. cf->install_ldif_file);
  3930. else
  3931. sprintf(msg, "The file %s was successfully loaded",
  3932. cf->install_ldif_file);
  3933. ds_show_message(msg);
  3934. free(cf->install_ldif_file);
  3935. cf->install_ldif_file = NULL;
  3936. }
  3937. /*
  3938. All of the config files have been written, and the server should
  3939. be ready to go. Start the server if the user specified to start
  3940. it or if we are configuring the server to serve as the repository
  3941. for SuiteSpot (Mission Control) information
  3942. Only attempt to start the server if the port is not in use
  3943. */
  3944. if(needToStartServer(cf) &&
  3945. !(t = create_instance_checkport(cf->bindaddr, cf->servport)))
  3946. {
  3947. sprintf(big_line,"SERVER_NAMES=slapd-%s",cf->servid);
  3948. putenv(big_line);
  3949. isrunning = ds_get_updown_status();
  3950. if (isrunning != DS_SERVER_UP)
  3951. {
  3952. int start_status = 0;
  3953. int verbose = 1;
  3954. char instance_dir[PATH_SIZE], errorlog[PATH_SIZE];
  3955. if (getenv("USE_DEBUGGER"))
  3956. verbose = 0;
  3957. /* slapd-nickname directory */
  3958. sprintf(instance_dir, "%s%c"PRODUCT_NAME"-%s", sroot, FILE_PATHSEP,
  3959. cf->servid);
  3960. /* error log file */
  3961. sprintf(errorlog, "%s%clogs%cerrors", instance_dir, FILE_PATHSEP,
  3962. FILE_PATHSEP);
  3963. start_status = ds_bring_up_server_install(verbose, instance_dir, errorlog);
  3964. if (start_status != DS_SERVER_UP)
  3965. {
  3966. /*
  3967. If we were going to configure the server for SuiteSpot (Mission
  3968. Control), the server must be running. Therefore, it is a very
  3969. bad thing, and we want to exit with a non zero exit code so the
  3970. caller will know something went wrong.
  3971. Otherwise, if the user just wanted to start the server for some
  3972. reason, just exit with a zero and the messages printed will
  3973. let the user know the server wasn't started.
  3974. */
  3975. char *msg;
  3976. if (start_status == DS_SERVER_PORT_IN_USE)
  3977. msg = "The server could not be started because the port is in use.";
  3978. else if (start_status == DS_SERVER_MAX_SEMAPHORES)
  3979. msg = "No more servers may be installed on this system.\nPlease refer to documentation for information about how to\nincrease the number of installed servers per system.";
  3980. else if (start_status == DS_SERVER_CORRUPTED_DB)
  3981. msg = "The server could not be started because the database is corrupted.";
  3982. else if (start_status == DS_SERVER_NO_RESOURCES)
  3983. msg = "The server could not be started because the operating system is out of resources (e.g. CPU memory).";
  3984. else if (start_status == DS_SERVER_COULD_NOT_START)
  3985. msg = "The server could not be started due to invalid command syntax or operating system resource limits.";
  3986. else
  3987. msg = "The server could not be started.";
  3988. if( cf->cfg_sspt && !strcmp(cf->cfg_sspt, "1") )
  3989. {
  3990. ds_report_error(DS_SYSTEM_ERROR, "server", msg);
  3991. return msg;
  3992. }
  3993. else
  3994. {
  3995. ds_show_message(msg);
  3996. return 0;
  3997. }
  3998. }
  3999. else
  4000. {
  4001. ds_show_message("Your new directory server has been started.");
  4002. }
  4003. }
  4004. /* write ldap.conf */
  4005. write_ldap_info( sroot, cf );
  4006. #ifdef XP_UNIX
  4007. ds_become_localuser_name (cf->servuser);
  4008. #endif
  4009. #ifdef XP_WIN32
  4010. if( errno = WSAStartup(0x0101, &wsadata ) != 0 )
  4011. {
  4012. char szTmp[512];
  4013. /*replaced errno > -1 && errno < sys_nerr ? sys_errlist[errno] :
  4014. "unknown" with strerror(errno)*/
  4015. sprintf(szTmp, "Error: Windows Sockets initialization failed errno %d (%s)<br>\n", errno,
  4016. strerror(errno), 0 );
  4017. fprintf (stdout, szTmp);
  4018. return 0;
  4019. }
  4020. #endif /* XP_WIN32 */
  4021. memset( &query_vars, 0, sizeof(query_vars) );
  4022. if (!cf->use_existing_user_ds)
  4023. query_vars.suffix = myStrdup( cf->suffix );
  4024. query_vars.ssAdmID = myStrdup( cf->cfg_sspt_uid );
  4025. query_vars.ssAdmPW1 = myStrdup( cf->cfg_sspt_uidpw );
  4026. query_vars.ssAdmPW2 = myStrdup( cf->cfg_sspt_uidpw );
  4027. query_vars.rootDN = myStrdup( cf->rootdn );
  4028. query_vars.rootPW = myStrdup( cf->rootpw );
  4029. query_vars.admin_domain =
  4030. myStrdup( cf->admin_domain );
  4031. query_vars.netscaperoot = myStrdup( cf->netscaperoot );
  4032. query_vars.testconfig = myStrdup( cf->testconfig );
  4033. query_vars.consumerDN = myStrdup(cf->consumerdn);
  4034. query_vars.consumerPW = myStrdup(cf->consumerhashedpw);
  4035. if (cf->cfg_sspt && !strcmp(cf->cfg_sspt, "1"))
  4036. query_vars.cfg_sspt = 1;
  4037. else
  4038. query_vars.cfg_sspt = 0;
  4039. if (cf->suitespot3x_uid)
  4040. query_vars.config_admin_uid = myStrdup(cf->suitespot3x_uid);
  4041. else
  4042. query_vars.config_admin_uid = myStrdup(cf->cfg_sspt_uid);
  4043. memset(&slapd_conf, 0, sizeof(SLAPD_CONFIG));
  4044. if (sroot)
  4045. strcpy(slapd_conf.slapd_server_root, sroot);
  4046. if (cf->servport)
  4047. slapd_conf.port = atoi(cf->servport);
  4048. if (cf->servname)
  4049. strcpy(slapd_conf.host, cf->servname);
  4050. status = config_suitespot(&slapd_conf, &query_vars);
  4051. if (status == -1) /* invalid or null arguments or configuration */
  4052. return "Invalid arguments for server configuration.";
  4053. }
  4054. else if (t) /* just notify the user about the port conflict */
  4055. {
  4056. ds_show_message(t);
  4057. }
  4058. #if defined (BUILD_PRESENCE)
  4059. /* Create script for initializing IM Presence images */
  4060. if ((NULL == t) && (0 == status))
  4061. {
  4062. if ( (t = gen_presence_init_script(sroot, cf, cs_path)) )
  4063. return(t);
  4064. /* Initialize IM Presence images */
  4065. status = init_presence(sroot, cf, cs_path);
  4066. if (status)
  4067. return make_error ("ds_exec_and_report() failed (%d).", status);
  4068. }
  4069. #endif
  4070. if (status)
  4071. return make_error ("Could not configure server (%d).", status);
  4072. return(NULL);
  4073. }
  4074. /* write_ldap_info() : writes ldap.conf */
  4075. static int
  4076. write_ldap_info( char *slapd_server_root, server_config_s *cf)
  4077. {
  4078. FILE* fp;
  4079. int ret = 0;
  4080. char* fmt = "%s/shared/config/ldap.conf";
  4081. char* infoFileName;
  4082. if (!slapd_server_root) {
  4083. return -1;
  4084. }
  4085. infoFileName = (char*)malloc(strlen(fmt) + strlen(slapd_server_root) + 1);
  4086. sprintf(infoFileName, fmt, slapd_server_root);
  4087. if ((fp = fopen(infoFileName, "w")) == NULL)
  4088. {
  4089. ret = -1;
  4090. }
  4091. else
  4092. {
  4093. fprintf(fp, "url\tldap://%s:%d/",
  4094. cf->servname, atoi(cf->servport));
  4095. if (cf->suffix)
  4096. fprintf(fp, "%s", cf->suffix);
  4097. fprintf(fp, "\n");
  4098. if (cf->cfg_sspt_uid) {
  4099. fprintf(fp, "admnm\t%s\n", cf->cfg_sspt_uid);
  4100. }
  4101. fclose(fp);
  4102. }
  4103. #if defined( SOLARIS )
  4104. /*
  4105. * Solaris 9+ specific installation
  4106. */
  4107. if (iDSISolaris)
  4108. logUninstallInfo(slapd_server_root, PRODUCT_NAME, PRODUCT_NAME, infoFileName);
  4109. #endif /* SOLARIS */
  4110. free(infoFileName);
  4111. return ret;
  4112. }