ldclt.c 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333
  1. #ident "ldclt @(#)ldclt.c 1.89 01/06/19"
  2. /** BEGIN COPYRIGHT BLOCK
  3. * This Program is free software; you can redistribute it and/or modify it under
  4. * the terms of the GNU General Public License as published by the Free Software
  5. * Foundation; version 2 of the License.
  6. *
  7. * This Program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along with
  12. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  13. * Place, Suite 330, Boston, MA 02111-1307 USA.
  14. *
  15. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  16. * right to link the code of this Program with code not covered under the GNU
  17. * General Public License ("Non-GPL Code") and to distribute linked combinations
  18. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  19. * permitted under this exception must only link to the code of this Program
  20. * through those well defined interfaces identified in the file named EXCEPTION
  21. * found in the source code files (the "Approved Interfaces"). The files of
  22. * Non-GPL Code may instantiate templates or use macros or inline functions from
  23. * the Approved Interfaces without causing the resulting work to be covered by
  24. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  25. * additions to the list of Approved Interfaces. You must obey the GNU General
  26. * Public License in all respects for all of the Program code and other code used
  27. * in conjunction with the Program except the Non-GPL Code covered by this
  28. * exception. If you modify this file, you may extend this exception to your
  29. * version of the file, but you are not obligated to do so. If you do not wish to
  30. * provide this exception without modification, you must delete this exception
  31. * statement from your version and license this file solely under the GPL without
  32. * exception.
  33. *
  34. *
  35. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  36. * Copyright (C) 2006 Red Hat, Inc.
  37. * All rights reserved.
  38. * END COPYRIGHT BLOCK **/
  39. #ifdef HAVE_CONFIG_H
  40. # include <config.h>
  41. #endif
  42. /*
  43. FILE : ldclt.c
  44. AUTHOR : Jean-Luc SCHWING
  45. VERSION : 1.0
  46. DATE : 03 December 1998
  47. DESCRIPTION :
  48. This file is the main file of the ldclt tool. This tool
  49. is targetted to be a multi-threaded ldap client,
  50. specially designed to ensure good reliability of both
  51. the basic ldap server purpose, and the replication
  52. processes. It is *not* targetted against the
  53. functionnality aspect of the product, but rather on the
  54. stress and long-term operation.
  55. LOCAL : None.
  56. HISTORY :
  57. ---------+--------------+------------------------------------------------------
  58. dd/mm/yy | Author | Comments
  59. ---------+--------------+------------------------------------------------------
  60. 03/12/98 | JL Schwing | Creation
  61. ---------+--------------+------------------------------------------------------
  62. 10/12/98 | JL Schwing | 1.2 : Add statistics report when exiting.
  63. ---------+--------------+------------------------------------------------------
  64. 10/12/98 | JL Schwing | 1.3 : Trap SIGQUIL to issue statistics without exit.
  65. | Bug fix - call ldap_err2string() to decode ldap errs.
  66. ---------+--------------+------------------------------------------------------
  67. 11/12/98 | JL Schwing | 1.4 : Implement max errors threshold.
  68. | fflush(stdout) after each printf.
  69. | Will exit(0) on SIGINT
  70. ---------+--------------+------------------------------------------------------
  71. 14/12/98 | JL Schwing | 1.5 : Implement "-e close".
  72. | Ensure thread not dead prior to issue "no activity"
  73. | Add statts for the number of dead threads.
  74. ---------+--------------+------------------------------------------------------
  75. 16/12/98 | JL Schwing | 1.6 : Implement "-e add" and "-e delete".
  76. | Improve printout of options.
  77. ---------+--------------+------------------------------------------------------
  78. 24/12/98 | JL Schwing | 1.7 : Fix memory problem.
  79. ---------+--------------+------------------------------------------------------
  80. 28/12/98 | JL Schwing | 1.8 : Add more statistics.
  81. ---------+--------------+------------------------------------------------------
  82. 29/12/98 | JL Schwing | 1.9 : Implement -Q.
  83. ---------+--------------+------------------------------------------------------
  84. 29/12/98 | JL Schwing | 1.10: Don't print pending stats if not asynchronous.
  85. ---------+--------------+------------------------------------------------------
  86. 29/12/98 | JL Schwing | 1.11: Fix typo.
  87. ---------+--------------+------------------------------------------------------
  88. 30/12/98 | JL Schwing | 1.12: Protect messages "no activity for %d seconds"
  89. | by SUPER_QUIET mode.
  90. ---------+--------------+------------------------------------------------------
  91. 11/01/99 | JL Schwing | 1.13: Implement "-e emailPerson".
  92. ---------+--------------+------------------------------------------------------
  93. 13/01/99 | JL Schwing | 1.14: Implement "-e string".
  94. ---------+--------------+------------------------------------------------------
  95. 14/01/99 | JL Schwing | 1.15: Implement "-s <scope>".
  96. ---------+--------------+------------------------------------------------------
  97. 18/01/99 | JL Schwing | 1.16: Implement "-e randombase".
  98. ---------+--------------+------------------------------------------------------
  99. 18/01/99 | JL Schwing | 1.17: Implement "-e v2".
  100. ---------+--------------+------------------------------------------------------
  101. 21/01/99 | JL Schwing | 1.18: Implement "-e ascii".
  102. ---------+--------------+------------------------------------------------------
  103. 26/01/99 | JL Schwing | 1.19: Implement "-e noloop".
  104. ---------+--------------+------------------------------------------------------
  105. 28/01/99 | JL Schwing | 1.20: Implement "-T <total>".
  106. ---------+--------------+------------------------------------------------------
  107. 04/05/99 | JL Schwing | 1.21: Implement operations list.
  108. ---------+--------------+------------------------------------------------------
  109. 06/05/99 | JL Schwing | 1.25: Add proper shutdwon (wait for check threads).
  110. | Implement "-P <master port>".
  111. ---------+--------------+------------------------------------------------------
  112. 06/05/99 | JL Schwing | 1.26: Implement "-e modrdn".
  113. ---------+--------------+------------------------------------------------------
  114. 06/05/99 | F. Pistolesi | 1.27: Some fixes.
  115. ---------+--------------+------------------------------------------------------
  116. 07/05/99 | JL Schwing | 1.28: Some fixes.
  117. ---------+--------------+------------------------------------------------------
  118. 19/05/99 | JL Schwing | 1.30: Implement "-e rename".
  119. | Set the threads status to DEAD when nb of opers done.
  120. | Lint-cleanup.
  121. ---------+--------------+------------------------------------------------------
  122. 21/05/99 | JL Schwing | 1.31: Fix Unitialized Memory Read for head's mutex.
  123. ---------+--------------+------------------------------------------------------
  124. 27/05/99 | JL Schwing | 1.32 : Add statistics to check threads.
  125. ---------+--------------+------------------------------------------------------
  126. 28/05/99 | JL Schwing | 1.33 : Add new option -W (wait).
  127. ---------+--------------+------------------------------------------------------
  128. 02/06/99 | JL Schwing | 1.34 : Add flag in main ctx to know if slave was
  129. | connected or not.
  130. | Add counter of operations received in check threads.
  131. ---------+--------------+------------------------------------------------------
  132. 06/03/00 | JL Schwing | 1.35: Test malloc() and strdup() return value.
  133. ---------+--------------+------------------------------------------------------
  134. 04/08/00 | JL Schwing | 1.36: Add stats on nb inactivity per thread.
  135. ---------+--------------+------------------------------------------------------
  136. 08/08/00 | JL Schwing | 1.37: Print global statistics every 1000 loops.
  137. ---------+--------------+------------------------------------------------------
  138. 18/08/00 | JL Schwing | 1.38: Print global statistics every 90 loops.
  139. | Bug fix in this new feature.
  140. | Print ldclt version.
  141. | Print date of begin and of end.
  142. | Add new function ldcltExit().
  143. ---------+--------------+------------------------------------------------------
  144. 25/08/00 | JL Schwing | 1.39: Implement consistent exit status...
  145. ---------+--------------+------------------------------------------------------
  146. 25/08/00 | JL Schwing | 1.40: Will only load images if -e emailPerson
  147. ---------+--------------+------------------------------------------------------
  148. 11/10/00 | B Kolics | 1.41: Implement "-Z certfile".
  149. ---------+--------------+------------------------------------------------------
  150. 26/10/00 | B Kolics | 1.42: Move SSL client initialization to basicInit()
  151. -------------------------------------------------------------------------------
  152. 07/11/00 | JL Schwing | 1.43: Add handlers for dynamic load of ssl-related
  153. | functions.
  154. | Add new function sslDynLoadInit().
  155. -----------------------------------------------------------------------------
  156. 07/11/00 | JL Schwing | 1.44: Implement "-e inetOrgPerson".
  157. ---------+--------------+------------------------------------------------------
  158. 08/11/00 | JL Schwing | 1.45: Improve error message when initiating ssl.
  159. ---------+--------------+------------------------------------------------------
  160. 13/11/00 | JL Schwing | 1.46: Add new options "-e randombaselow and ...high"
  161. | Made use of exit (EXIT_PARAMS) in main().
  162. ---------+--------------+------------------------------------------------------
  163. 14/11/00 | JL Schwing | 1.47: Port on AIX.
  164. ---------+--------------+------------------------------------------------------
  165. 16/11/00 | JL Schwing | 1.48: Implement "-e imagesdir=path".
  166. ---------+--------------+------------------------------------------------------
  167. 17/11/00 | JL Schwing | 1.49: Implement "-e smoothshutdown".
  168. | Forget to add mode decoding.
  169. | Add new function shutdownThreads().
  170. ---------+--------------+------------------------------------------------------
  171. 21/11/00 | JL Schwing | 1.50: Implement "-e attreplace=name:mask"
  172. | Add new function parseFilter().
  173. ---------+--------------+------------------------------------------------------
  174. 22/11/00 | JL Schwing | 1.51: Will now use LD_LIBRARY_PATH to load libssl.
  175. ---------+--------------+------------------------------------------------------
  176. 24/11/00 | B Kolics | 1.52: Added SSL client authentication
  177. ---------+--------------+------------------------------------------------------
  178. 29/11/00 | JL Schwing | 1.53: Port on NT 4.
  179. ---------+--------------+------------------------------------------------------
  180. 30/11/00 | JL Schwing | 1.54: Bug fix - bad error message if -eimagesdir=path
  181. ---------+--------------+------------------------------------------------------
  182. 01/12/00 | JL Schwing | 1.55: Port on Linux.
  183. ---------+--------------+------------------------------------------------------
  184. 01/12/00 | JL Schwing | 1.56: Port on HP-UX.
  185. ---------+--------------+------------------------------------------------------
  186. 07/12/00 | JL Schwing | 1.57: Bug fix - crash SIGBUS in main:1840 if no
  187. | filter is provided to the tool.
  188. | Build the argv list before parsing.
  189. ---------+--------------+------------------------------------------------------
  190. 15/12/00 | JL Schwing | 1.58: Implement "-e counteach".
  191. | Implement "-e withnewparent".
  192. ---------+--------------+------------------------------------------------------
  193. 18/12/00 | JL Schwing | 1.59: Fix an exit status problem.
  194. ---------+--------------+------------------------------------------------------
  195. 18/12/00 | JL Schwing | 1.60: Minor fix/improvement in -I management.
  196. ---------+--------------+------------------------------------------------------
  197. 19/12/00 | JL Schwing | 1.61: Implement "-e noglobalstats".
  198. ---------+--------------+------------------------------------------------------
  199. 19/12/00 | JL Schwing | 1.62: Add comments.
  200. ---------+--------------+------------------------------------------------------
  201. 03/01/01 | JL Schwing | 1.63: Implement "-e attrsonly=value".
  202. ---------+--------------+------------------------------------------------------
  203. 05/01/01 | JL Schwing | 1.64: Implement "-e randombinddn" and associated
  204. | "-e randombinddnlow/high"
  205. ---------+--------------+------------------------------------------------------
  206. 08/01/01 | JL Schwing | 1.65: Implement "-e scalab01".
  207. | Replace all exit() by ldcltExit()
  208. ---------+--------------+------------------------------------------------------
  209. 12/01/01 | JL Schwing | 1.66: Second set of options for -e scalab01
  210. | Sanity check in decodeExecParams().
  211. ---------+--------------+------------------------------------------------------
  212. 26/02/01 | JL Schwing | 1.67: Use ldclt_sleep() not sleep() (NT issue).
  213. ---------+--------------+------------------------------------------------------
  214. 08/03/01 | JL Schwing | 1.68: Change referrals handling.
  215. | Use a static char[] to store ldclt version.
  216. | Add new function decodeReferralParams().
  217. ---------+--------------+------------------------------------------------------
  218. 14/03/01 | JL Schwing | 1.69: Implement "-e commoncounter"
  219. | Add a control for referral mode.
  220. ---------+--------------+------------------------------------------------------
  221. 14/03/01 | JL Schwing | 1.70: Implement "-e dontsleeponserverdown".
  222. ---------+--------------+------------------------------------------------------
  223. 14/03/01 | JL Schwing | 1.71: Misc fixes for HP-UX compilation.
  224. ---------+--------------+------------------------------------------------------
  225. 15/03/01 | JL Schwing | 1.72: Implement "-e attrlist=name:name:name"
  226. | Implement "-e randomattrlist=name:name:name"
  227. ---------+--------------+------------------------------------------------------
  228. 19/03/01 | JL Schwing | 1.73: Implement "-e object=filename"
  229. | Bug fix - understand EXIT_INIT in ldcltExit().
  230. | Implement "-e genldif=filename"
  231. | Add new function tttctxInit().
  232. ---------+--------------+------------------------------------------------------
  233. 21/03/01 | JL Schwing | 1.74: Implements variables in "-e object=filename"
  234. | Add new function copyVersObject().
  235. ---------+--------------+------------------------------------------------------
  236. 23/03/01 | JL Schwing | 1.75: Implements data file list support in variants.
  237. | Implements "-e rdn=value".
  238. | Add new functions copyVersAttribute() decodeRdnParam()
  239. ---------+--------------+------------------------------------------------------
  240. 28/03/01 | JL Schwing | 1.76: Update options checking for "-e rdn=value".
  241. ---------+--------------+------------------------------------------------------
  242. 28/03/01 | JL Schwing | 1.77: Support -e commoncounter with -e rdn/object
  243. | Remove MAX_ATTRLIST - use MAX_ATTRIBS.
  244. | Bug fix - forget to initiate some fields in -e rdn=
  245. ---------+--------------+------------------------------------------------------
  246. 02/04/01 | JL Schwing | 1.78: Bug fix : large files support for -e genldif.
  247. ---------+--------------+------------------------------------------------------
  248. 03/04/01 | JL Schwing | 1.79: Port on _WIN32 and OSF1.
  249. ---------+--------------+------------------------------------------------------
  250. 05/04/01 | JL Schwing | 1.80: Bug fix - forget to print genldif file name.
  251. ---------+--------------+------------------------------------------------------
  252. 05/04/01 | JL Schwing | 1.81: Implement -e append.
  253. ---------+--------------+------------------------------------------------------
  254. 11/04/01 | JL Schwing | 1.82: Bug fix in -e append.
  255. ---------+--------------+------------------------------------------------------
  256. 23/04/01 | JL Schwing | 1.83: Improved arguments print at startup.
  257. | Add new function buildArgListString().
  258. ---------+--------------+------------------------------------------------------
  259. 23/04/01 | JL Schwing | 1.84: Exit on error 2 if extra arguments provided.
  260. ---------+--------------+------------------------------------------------------
  261. 03/05/01 | JL Schwing | 1.85: Implement -e randombinddnfromfile=filename.
  262. ---------+--------------+------------------------------------------------------
  263. 04/05/01 | JL Schwing | 1.86: Implement -e bindonly.
  264. ---------+--------------+------------------------------------------------------
  265. 04/05/01 | JL Schwing | 1.87: Fix options check.
  266. ---------+--------------+------------------------------------------------------
  267. 16/06/01 | JL Schwing | 1.89: Allow SSL for HP-UX.
  268. ---------+--------------+------------------------------------------------------
  269. */
  270. #include <stdlib.h> /* exit(), etc... */
  271. #include <stdio.h> /* printf(), etc... */
  272. #include <signal.h> /* sigset(), etc... */
  273. #include <string.h> /* strerror(), etc... */
  274. #include <errno.h> /* errno, etc... */ /*JLS 06-03-00*/
  275. #include <fcntl.h> /* O_RDONLY, etc... */ /*JLS 02-04-01*/
  276. #include <time.h> /* ctime(), etc... */ /*JLS 18-08-00*/
  277. #include <lber.h> /* ldap C-API BER decl. */
  278. #include <ldap.h> /* ldap C-API decl. */
  279. #if !defined(USE_OPENLDAP)
  280. #include <ldap_ssl.h> /* ldapssl_init(), etc... */
  281. #endif
  282. #ifdef LDAP_H_FROM_QA_WKA
  283. #include <proto-ldap.h> /* ldap C-API prototypes */
  284. #endif
  285. #ifndef _WIN32 /*JLS 29-11-00*/
  286. #include <pthread.h> /* pthreads(), etc... */
  287. #include <unistd.h> /* close(), etc... */
  288. #include <dlfcn.h> /* dlopen(), etc... */ /*JLS 07-11-00*/
  289. #include <sys/resource.h> /* setrlimit(), etc... */
  290. #include <sys/time.h> /* struct rlimit, etc... */
  291. #endif
  292. #include "nspr.h"
  293. #include "port.h" /* Portability definitions */ /*JLS 29-11-00*/
  294. #include "ldclt.h" /* This tool's include file */
  295. #include "utils.h" /* Utilities functions */ /*JLS 16-11-00*/
  296. #include "scalab01.h" /* Scalab01 specific */ /*JLS 12-01-01*/
  297. #include <sys/types.h>
  298. #include <sys/stat.h>
  299. /*
  300. * Global variables
  301. */
  302. main_context mctx; /* Main context */
  303. thread_context tctx [MAX_THREADS]; /* Threads contextes */
  304. check_context cctx [MAX_SLAVES]; /* Check threads contextes */
  305. int masterPort=16000;
  306. extern char *ldcltVersion; /* ldclt version */ /*JLS 18-08-00*/
  307. /* New function */ /*JLS 18-08-00*/
  308. /* ****************************************************************************
  309. FUNCTION : ldcltExit
  310. PURPOSE : Print the last data then exit the process.
  311. INPUT : status = exit status
  312. OUTPUT : None.
  313. RETURN : None.
  314. DESCRIPTION :
  315. *****************************************************************************/
  316. void
  317. ldcltExit (
  318. int status)
  319. {
  320. time_t tim;
  321. tim = time (NULL);
  322. printf ("ldclt[%d]: Ending at %s", mctx.pid, ctime (&tim));
  323. printf ("ldclt[%d]: Exit status %d - ", mctx.pid, status);
  324. switch (status) /*JLS 25-08-00*/
  325. { /*JLS 25-08-00*/
  326. case EXIT_OK: /*JLS 25-08-00*/
  327. printf ("No problem during execution.\n"); /*JLS 25-08-00*/
  328. break; /*JLS 25-08-00*/
  329. case EXIT_PARAMS: /*JLS 25-08-00*/
  330. printf ("Error in parameters.\n"); /*JLS 25-08-00*/
  331. break; /*JLS 25-08-00*/
  332. case EXIT_MAX_ERRORS: /*JLS 25-08-00*/
  333. printf ("Max errors reached.\n"); /*JLS 25-08-00*/
  334. break; /*JLS 25-08-00*/
  335. case EXIT_NOBIND: /*JLS 25-08-00*/
  336. printf ("Cannot bind.\n"); /*JLS 25-08-00*/
  337. break; /*JLS 25-08-00*/
  338. case EXIT_LOADSSL: /*JLS 07-11-00*/
  339. printf ("Cannot load libssl.\n"); /*JLS 07-11-00*/
  340. break; /*JLS 07-11-00*/
  341. case EXIT_INIT: /*JLS 19-03-01*/
  342. printf ("Cannot initialize ldclt.\n"); /*JLS 19-03-01*/
  343. break; /*JLS 19-03-01*/
  344. case EXIT_OTHER: /*JLS 25-08-00*/
  345. printf ("Other kind of error.\n"); /*JLS 25-08-00*/
  346. break; /*JLS 25-08-00*/
  347. default: /*JLS 25-08-00*/
  348. printf ("Undocumented error - update source code.\n"); /*JLS 25-08-00*/
  349. break; /*JLS 25-08-00*/
  350. } /*JLS 25-08-00*/
  351. exit (status);
  352. }
  353. /* New */ /*JLS 23-03-01*/
  354. /* ****************************************************************************
  355. FUNCTION : copyVersAttribute
  356. PURPOSE : Copy a versatile object's attribute
  357. INPUT : srcattr = source attribute
  358. OUTPUT : dstattr = destination attribute
  359. RETURN : -1 if error, 0 else.
  360. DESCRIPTION :
  361. *****************************************************************************/
  362. int
  363. copyVersAttribute (
  364. vers_attribute *srcattr,
  365. vers_attribute *dstattr)
  366. {
  367. vers_field *src; /* Source field */
  368. vers_field *dst; /* Destination field */
  369. dstattr->name = srcattr->name;
  370. dstattr->src = srcattr->src;
  371. dstattr->field = (vers_field *) malloc (sizeof (vers_field));
  372. /*
  373. * Copy each field of the attribute
  374. */
  375. src = srcattr->field;
  376. dst = dstattr->field;
  377. while (src != NULL)
  378. {
  379. memcpy (dst, src, sizeof (vers_field));
  380. dst->commonField = src; /*JLS 28-03-01*/
  381. if ((src = src->next) != NULL)
  382. {
  383. dst->next = (vers_field *) malloc (sizeof (vers_field));
  384. dst = dst->next;
  385. }
  386. }
  387. /*
  388. * Do we need a buffer ?
  389. */
  390. if (srcattr->buf == NULL) /*JLS 28-03-01*/
  391. dstattr->buf = NULL; /*JLS 28-03-01*/
  392. else /*JLS 28-03-01*/
  393. dstattr->buf = (char *) malloc (MAX_FILTER);
  394. /*
  395. * End of function
  396. */
  397. return (0);
  398. }
  399. /* New */ /*JLS 21-03-01*/
  400. /* ****************************************************************************
  401. FUNCTION : copyVersObject
  402. PURPOSE : Copy a versatile object.
  403. INPUT : None.
  404. OUTPUT : None.
  405. RETURN : NULL if error, copy of the object else.
  406. DESCRIPTION :
  407. *****************************************************************************/
  408. vers_object *
  409. copyVersObject (
  410. vers_object *srcobj)
  411. {
  412. vers_object *newobj; /* New object */
  413. int i; /* For the loops */
  414. /*
  415. * Copy the object and initiates the buffers...
  416. */
  417. newobj = (vers_object *) malloc (sizeof (vers_object));
  418. newobj->attribsNb = srcobj->attribsNb;
  419. newobj->fname = srcobj->fname;
  420. /*
  421. * Initiates the variables
  422. */
  423. for (i=0 ; i+VAR_MIN < VAR_MAX ; i++)
  424. if (srcobj->var[i] == NULL)
  425. newobj->var[i] = NULL;
  426. else
  427. newobj->var[i] = (char *) malloc (MAX_FILTER);
  428. /*
  429. * Maybe copy the rdn ?
  430. */
  431. if (srcobj->rdn != NULL)
  432. {
  433. newobj->rdnName = strdup (srcobj->rdnName);
  434. newobj->rdn = (vers_attribute *) malloc (sizeof (vers_attribute));
  435. if (copyVersAttribute (srcobj->rdn, newobj->rdn) < 0)
  436. return (NULL);
  437. }
  438. /*
  439. * Copy each attribute
  440. */
  441. for (i=0 ; i < srcobj->attribsNb ; i++)
  442. if (copyVersAttribute (&(srcobj->attribs[i]), &(newobj->attribs[i])) < 0)
  443. return (NULL);
  444. /*
  445. * Return the new object
  446. */
  447. return (newobj);
  448. }
  449. /* New */ /*JLS 19-03-01*/
  450. /* ****************************************************************************
  451. FUNCTION : tttctxInit
  452. PURPOSE : Initiates the thread context
  453. INPUT : num = thread number
  454. OUTPUT : tttctx = initiates context
  455. RETURN : -1 if error, 0 else.
  456. DESCRIPTION :
  457. *****************************************************************************/
  458. int
  459. tttctxInit (
  460. int num,
  461. thread_context *tttctx)
  462. {
  463. int ret; /* ldclt_mutex_init() return value */
  464. /*
  465. * Initialize data for this thread
  466. */
  467. tttctx->active = mctx.inactivMax + 1;
  468. tttctx->attrlist[0] = NULL;
  469. tttctx->exitStatus = EXIT_OK;
  470. tttctx->nbInactRow = 0;
  471. tttctx->nbInactTot = 0;
  472. tttctx->mode = mctx.mode;
  473. tttctx->status = FREE;
  474. tttctx->thrdNum = num;
  475. tttctx->totalReq = mctx.totalReq;
  476. sprintf (tttctx->thrdId, "T%03d", tttctx->thrdNum);
  477. if (mctx.mod2 & M2_OBJECT)
  478. {
  479. tttctx->bufObject1 = (char *) malloc (MAX_FILTER);
  480. if ((tttctx->object = copyVersObject (&(mctx.object))) == NULL)
  481. return(-1);
  482. }
  483. /*
  484. * Initiate the mutexes that protect the private data structures.
  485. */
  486. if ((ret = ldclt_mutex_init(&(tttctx->nbOpers_mutex))) != 0)
  487. {
  488. fprintf (stderr, "ldclt: %s\n", strerror (ret));
  489. fprintf (stderr,"Error: cannot initiate nbOpers_mutex %s\n",tttctx->thrdId);
  490. fflush (stderr);
  491. return (-1);
  492. }
  493. if ((ret = ldclt_mutex_init (&(tttctx->status_mutex))) != 0)
  494. {
  495. fprintf (stderr, "ldclt: %s\n", strerror (ret));
  496. fprintf (stderr, "Error: cannot initiate status_mutex %s\n",tttctx->thrdId);
  497. fflush (stderr);
  498. return (-1);
  499. }
  500. return (0);
  501. }
  502. /* ****************************************************************************
  503. FUNCTION : runThem
  504. PURPOSE : This function implements the launching of the threads.
  505. The monitoring will be realized in monitorIt().
  506. This function also create the check threads if needed.
  507. INPUT : None.
  508. OUTPUT : None.
  509. RETURN : -1 if error, 0 else.
  510. DESCRIPTION :
  511. *****************************************************************************/
  512. int
  513. runThem (void)
  514. {
  515. int i; /* For the loops */ /*JLS 23-03-01*/
  516. int ret; /* pthread_xxx() return value */
  517. #ifdef SOLARIS /*JLS 17-11-00*/
  518. /*
  519. * Maybe create the check operation threads.
  520. */
  521. if (mctx.slavesNb > 0)
  522. {
  523. for (i=0 ; i<mctx.slavesNb ; i++)
  524. {
  525. if (mctx.mode & VERY_VERBOSE)
  526. printf ("ldclt[%d]: Creating thread C%03d\n", mctx.pid, i);
  527. /*
  528. * Initiate context for this thread
  529. */
  530. cctx[i].headListOp = mctx.opListTail;
  531. cctx[i].status = DEAD;
  532. cctx[i].thrdNum = i;
  533. cctx[i].calls = 0;
  534. cctx[i].slaveName = NULL;
  535. cctx[i].nbEarly = 0;
  536. cctx[i].nbLate = 0;
  537. cctx[i].nbLostOp = 0;
  538. cctx[i].nbNotOnList = 0;
  539. cctx[i].nbOpRecv = 0;
  540. cctx[i].nbRepFail32 = 0;
  541. cctx[i].nbRepFail68 = 0;
  542. cctx[i].nbRepFailX = 0;
  543. cctx[i].nbStillOnQ = 0;
  544. }
  545. /*
  546. * Create the main (aka monitoring) check operation thread.
  547. */
  548. if ((ret = ldclt_thread_create (NULL, opCheckMain, NULL)) != 0)
  549. {
  550. fprintf (stderr, "ldclt[%d]: %s\n", mctx.pid, strerror (ret));
  551. fprintf (stderr, "ldclt[%d]: Error: cannot create thread C%03d\n", mctx.pid, i);
  552. fflush (stderr);
  553. return (-1);
  554. }
  555. }
  556. #endif /* SOLARIS */ /*JLS 14-11-00*/
  557. /*
  558. * Maybe we need to start a special control thread ?
  559. */
  560. if (mctx.mode & SCALAB01) /*JLS 08-01-01*/
  561. { /*JLS 08-01-01*/
  562. ldclt_tid dummy; /* Don't need tid */ /*JLS 14-03-01*/
  563. /*JLS 08-01-01*/
  564. if ((ret = ldclt_thread_create (&dummy, /*JLS 08-01-01*/
  565. scalab01_control, (void *)NULL)) != 0) /*JLS 08-01-01*/
  566. { /*JLS 08-01-01*/
  567. fprintf (stderr, "ldclt[%d]: %s\n", mctx.pid, strerror (ret)); /*JLS 08-01-01*/
  568. fprintf (stderr, "ldclt[%d]: Error: cannot create thread scalab01_control\n", mctx.pid);
  569. fflush (stderr); /*JLS 08-01-01*/
  570. return (-1); /*JLS 08-01-01*/
  571. } /*JLS 08-01-01*/
  572. ldclt_sleep (2); /* Time to initialize */ /*JLS 26-02-01*/
  573. } /*JLS 08-01-01*/
  574. /*
  575. * Ok, the check operation threads are now created (if needed).
  576. * Let's create the (working) ldap client threads.
  577. */
  578. for (i=0 ; i<mctx.nbThreads ; i++)
  579. {
  580. if (mctx.mode & VERY_VERBOSE)
  581. printf ("ldclt[%d]: Creating thread T%03d\n", mctx.pid, i);
  582. if (tttctxInit (i, &(tctx[i])) < 0) /*JLS 19-03-01*/
  583. return (-1); /*JLS 19-03-01*/
  584. /*
  585. * Create the thread
  586. */
  587. if ((ret = ldclt_thread_create (&(tctx[i].tid),
  588. threadMain, (void *)&(tctx[i]))) != 0)
  589. {
  590. fprintf (stderr, "ldclt[%d]: %s\n", mctx.pid, strerror (ret));
  591. fprintf (stderr, "ldclt[%d]: Error: cannot create thread T%03d\n", mctx.pid, i);
  592. fflush (stderr);
  593. return (-1);
  594. }
  595. }
  596. return (0);
  597. }
  598. /* New function */ /*JLS 17-11-00*/
  599. /* ****************************************************************************
  600. FUNCTION : shutdownThreads
  601. PURPOSE : This function is targetted to shutdown the threads.
  602. INPUT : None.
  603. OUTPUT : None.
  604. RETURN : -1 if error, 0 else.
  605. DESCRIPTION :
  606. *****************************************************************************/
  607. int
  608. shutdownThreads (void)
  609. {
  610. int i; /* To process the threads */
  611. int status; /* Thread's status */
  612. int allDead; /* All threads are dead */
  613. int maxLoops; /* Max loops waiting for DEAD */
  614. int ret; /* Return code */
  615. /*
  616. * Command all the threads to shutdown.
  617. * Must set to MUST_SHUTDOWN only if not dead, hence need to
  618. * expose the mutex here...
  619. */
  620. for (i=0 ; i<mctx.nbThreads ; i++)
  621. {
  622. if ((ret = ldclt_mutex_lock (&(tctx[i].status_mutex))) != 0)
  623. {
  624. fprintf (stderr,
  625. "Cannot mutex_lock(T%03d), error=%d (%s)\n",
  626. tctx[i].thrdNum, ret, strerror (ret));
  627. printf ("Cannot command shutdwon to thread %d\n", tctx[i].thrdNum);
  628. return (-1);
  629. }
  630. if (tctx[i].status != DEAD)
  631. tctx[i].status = MUST_SHUTDOWN;
  632. if ((ret = ldclt_mutex_unlock (&(tctx[i].status_mutex))) != 0)
  633. {
  634. fprintf (stderr,
  635. "Cannot mutex_unlock(T%03d), error=%d (%s)\n",
  636. tctx[i].thrdNum, ret, strerror (ret));
  637. printf ("Cannot command shutdwon to thread %d\n", tctx[i].thrdNum);
  638. return (-1);
  639. }
  640. }
  641. /*
  642. * Wait (maybe ?) for the thread to actually die...
  643. */
  644. if (mctx.mode & SMOOTHSHUTDOWN)
  645. {
  646. int alivecnt;
  647. allDead = 0;
  648. maxLoops = 20;
  649. while (maxLoops && !allDead)
  650. {
  651. allDead = 1;
  652. alivecnt = 0;
  653. for (i=0 ; i<mctx.nbThreads ; i++)
  654. {
  655. if (getThreadStatus (&(tctx[i]), &status) < 0)
  656. {
  657. printf ("Cannot command shutdown to thread %d\n", tctx[i].thrdNum);
  658. return (-1);
  659. }
  660. if (status != DEAD)
  661. {
  662. allDead = 0;
  663. alivecnt++;
  664. }
  665. }
  666. maxLoops--;
  667. if (!allDead)
  668. ldclt_sleep (1);
  669. }
  670. if (!maxLoops)
  671. {
  672. printf ("%d thread(s) don't die...\n", alivecnt);
  673. return (-1);
  674. }
  675. }
  676. return (0);
  677. }
  678. /* ****************************************************************************
  679. FUNCTION : monitorThem
  680. PURPOSE : This function will monitor all the client threads.
  681. INPUT : None.
  682. OUTPUT : None.
  683. RETURN : -1 if error, 0 else.
  684. DESCRIPTION :
  685. *****************************************************************************/
  686. int
  687. monitorThem (void)
  688. {
  689. int i; /* To parse the threads */
  690. int ret; /* Return value */
  691. int nbOpers; /* This thread nb of operations */
  692. int nbOpersTot; /* Total nb of operations */
  693. int allDead = 0; /* All threads are dead */
  694. int status; /* Thread's status */ /*JLS 17-11-00*/
  695. time_t t;
  696. struct tm *tmstr;
  697. char timestamp[128];
  698. while (!allDead)
  699. {
  700. ldclt_sleep (mctx.sampling);
  701. if (mctx.tsfmt) {
  702. t = time(NULL);
  703. tmstr = localtime(&t);
  704. strftime(timestamp, sizeof(timestamp), mctx.tsfmt, tmstr);
  705. } else {
  706. timestamp[0] = '\0';
  707. }
  708. nbOpersTot = 0;
  709. allDead = 1; /* Assume all threads are dead */
  710. /*
  711. * Parse all the threads
  712. */
  713. for (i=0 ; i<mctx.nbThreads ; i++)
  714. {
  715. status = RUNNING;
  716. if ((ret = ldclt_mutex_lock (&(tctx[i].nbOpers_mutex))) != 0)
  717. {
  718. fprintf (stderr,
  719. "ldclt[%d]: Cannot mutex_lock(T%03d), error=%d (%s)\n",
  720. mctx.pid, tctx[i].thrdNum, ret, strerror (ret));
  721. fflush (stderr);
  722. return (-1);
  723. }
  724. nbOpers = tctx[i].nbOpers;
  725. tctx[i].nbOpers = 0;
  726. if ((ret = ldclt_mutex_unlock (&(tctx[i].nbOpers_mutex))) != 0)
  727. {
  728. fprintf (stderr,
  729. "ldclt[%d]: Cannot mutex_unlock(T%03d), error=%d (%s)\n",
  730. mctx.pid, tctx[i].thrdNum, ret, strerror (ret));
  731. fflush (stderr);
  732. return (-1);
  733. }
  734. /*
  735. * Report results, and check activity
  736. */
  737. if (mctx.mode & VERY_VERBOSE)
  738. printf ("ldclt[%d]: T%03d: nbOpers = %d\n", mctx.pid, tctx[i].thrdNum, nbOpers);
  739. if (nbOpers != 0)
  740. {
  741. tctx[i].active = mctx.inactivMax + 1;
  742. tctx[i].nbInactRow = 0; /*JLS 04-08-00*/
  743. nbOpersTot += nbOpers;
  744. }
  745. else
  746. {
  747. tctx[i].active--;
  748. if (getThreadStatus (&(tctx[i]), &status) < 0) /*JLS 17-11-00*/
  749. { /*JLS 17-11-00*/
  750. printf ("ldclt[%d]: T%03d: Cannot get status\n", mctx.pid, tctx[i].thrdNum);
  751. status = RUNNING; /* Be conservative */ /*JLS 17-11-00*/
  752. } /*JLS 17-11-00*/
  753. if ((!(tctx[i].active)) && (status != DEAD)) /*JLS 17-11-00*/
  754. {
  755. tctx[i].nbInactRow++; /*JLS 04-08-00*/
  756. tctx[i].nbInactTot++; /*JLS 04-08-00*/
  757. if (!(mctx.mode & SUPER_QUIET))
  758. {
  759. printf ("ldclt[%d]: T%03d: No activity for %d seconds"
  760. " -- %5d in row, total %5d\n", /*JLS 04-08-00*/
  761. mctx.pid, tctx[i].thrdNum,
  762. (mctx.inactivMax + 1) * mctx.sampling,
  763. tctx[i].nbInactRow, tctx[i].nbInactTot);/*JLS 08-08-00*/
  764. fflush (stdout);
  765. }
  766. tctx[i].active = mctx.inactivMax + 1;
  767. mctx.nbNoActivity++;
  768. }
  769. }
  770. if (status != DEAD) /*JLS 17-11-00*/
  771. allDead = 0;
  772. } /* For each thread */
  773. /*
  774. * Summary of operations
  775. */
  776. printf ("%s%sldclt[%d]: Average rate: %7.2f/thr (%7.2f/sec), total: %6d\n",
  777. timestamp, mctx.tsfmt ? "|" : "",
  778. mctx.pid, (float)nbOpersTot/(float)mctx.nbThreads,
  779. (float)nbOpersTot/(float)mctx.sampling, nbOpersTot);
  780. fflush (stdout);
  781. /*
  782. * Gather global statistics
  783. */
  784. mctx.totNbOpers += nbOpersTot;
  785. mctx.totNbSamples++;
  786. /*
  787. * Maybe the number of samples is achieved ?
  788. */
  789. mctx.nbSamples--;
  790. if (mctx.nbSamples == 0)
  791. {
  792. if (shutdownThreads() < 0) /*JLS 17-11-00*/
  793. printf ("ldclt[%d]: Problem while shutting down threads,\n", mctx.pid);
  794. allDead = 1;
  795. printf ("ldclt[%d]: Number of samples achieved. Bye-bye...\n", mctx.pid);
  796. }
  797. /*
  798. * Maybe global statistics to print ?
  799. * Keep this at the end of the loop !!!
  800. */
  801. if ((!allDead) && (!(--mctx.globStatsCnt))) /*JLS 18-08-00*/
  802. { /*JLS 08-08-00*/
  803. if (printGlobalStatistics() < 0) /*JLS 08-08-00*/
  804. { /*JLS 08-08-00*/
  805. printf ("ldclt[%d]: Cannot print global statistics...\n", mctx.pid);
  806. printf ("ldclt[%d]: Bye-bye...", mctx.pid);
  807. ldcltExit (EXIT_OTHER); /*JLS 25-08-00*/
  808. } /*JLS 08-08-00*/
  809. mctx.globStatsCnt = DEF_GLOBAL_NB; /*JLS 08-08-00*/
  810. } /*JLS 08-08-00*/
  811. } /* while (!allDead) */
  812. #ifdef SOLARIS /*JLS 17-11-00*/
  813. /*
  814. * Well, all the productors are dead.
  815. * Let's wait for the consumers (aka ckeck threads)
  816. */
  817. allDead = 0;
  818. if (mctx.slavesNb > 0)
  819. while (!allDead)
  820. {
  821. allDead=1;
  822. for (i=0 ; i<mctx.slavesNb ; i++)
  823. if (cctx[i].status != DEAD)
  824. allDead = 0;
  825. if (!allDead)
  826. ldclt_sleep (1);
  827. }
  828. #endif /*JLS 17-11-00*/
  829. /*
  830. * Check the exit status of the threads
  831. */
  832. for (i=0 ; i<mctx.nbThreads ; i++) /*JLS 08-08-00*/
  833. if (tctx[i].exitStatus > mctx.exitStatus) /*JLS 08-08-00*/
  834. mctx.exitStatus = tctx[i].exitStatus; /*JLS 08-08-00*/
  835. /*
  836. * If there, all threads are dead
  837. */
  838. printf ("ldclt[%d]: All threads are dead - exit.\n", mctx.pid);
  839. fflush (stdout);
  840. return (0);
  841. }
  842. /* ****************************************************************************
  843. FUNCTION : printGlobalStatistics
  844. PURPOSE : This function will print the global statistics numbers.
  845. INPUT : None.
  846. OUTPUT : None.
  847. RETURN : -1 if error, 0 else.
  848. DESCRIPTION :
  849. *****************************************************************************/
  850. int
  851. printGlobalStatistics (void)
  852. {
  853. int i; /* For the loops */
  854. char buf[256]; /* To build the error strings */
  855. int found; /* Something was found */
  856. int total; /* Total statistics */
  857. /*
  858. * Pending operations statistics
  859. */
  860. if (mctx.mode & ASYNC)
  861. {
  862. total = 0;
  863. for (i=0 ; i<mctx.nbThreads ; i++)
  864. {
  865. printf ("ldclt[%d]: T%03d: pendingNb=%d\n", mctx.pid, tctx[i].thrdNum, tctx[i].pendingNb);
  866. total += tctx[i].pendingNb;
  867. }
  868. printf ("ldclt[%d]: Global total pending operations: %d\n", mctx.pid, total);
  869. }
  870. /*
  871. * Operations statistics
  872. */
  873. printf ("ldclt[%d]: Global average rate: %7.2f/thr (%6.2f/sec), total: %6d\n",
  874. mctx.pid, (float)mctx.totNbOpers/(float)mctx.nbThreads,
  875. (float)mctx.totNbOpers/(float)(mctx.sampling*mctx.totNbSamples),
  876. mctx.totNbOpers);
  877. /*
  878. * No activity reports.
  879. */
  880. if (mctx.nbNoActivity == 0)
  881. printf ("ldclt[%d]: Global number times \"no activity\" reports: never\n", mctx.pid);
  882. else
  883. printf ("ldclt[%d]: Global number times \"no activity\" reports: %d\n",
  884. mctx.pid, mctx.nbNoActivity);
  885. /*
  886. * Dead threads statistics
  887. */
  888. total = 0;
  889. for (i=0 ; i<mctx.nbThreads ; i++)
  890. if (tctx[i].status == DEAD)
  891. total++;
  892. if (total != 0)
  893. printf ("ldclt[%d]: Global number of dead threads: %d\n", mctx.pid, total);
  894. /*
  895. * Errors statistics
  896. * No mutex because this function is called at exit
  897. * Note: Maybe implement a way to stop the running threads ?
  898. */
  899. found = 0;
  900. for (i=0 ; i<MAX_ERROR_NB ; i++)
  901. if (mctx.errors[i] > 0)
  902. {
  903. found = 1;
  904. sprintf (buf, "(%s)", my_ldap_err2string (i));
  905. printf ("ldclt[%d]: Global error %2d %s occurs %5d times\n",
  906. mctx.pid, i, buf, mctx.errors[i]);
  907. }
  908. if (mctx.errorsBad > 0)
  909. {
  910. found = 1;
  911. printf ("ldclt[%d]: Global illegal errors (codes not in [0, %d]) occurs %5d times\n",
  912. mctx.pid, MAX_ERROR_NB-1, mctx.errorsBad);
  913. }
  914. if (!found)
  915. printf ("ldclt[%d]: Global no error occurs during this session.\n", mctx.pid);
  916. /*
  917. * Check threads statistics
  918. */
  919. if (mctx.slavesNb > 0)
  920. {
  921. if (!(mctx.slaveConn))
  922. printf ("ldclt[%d]: Problem: slave never connected !!!!\n", mctx.pid);
  923. else
  924. {
  925. total = 0;
  926. for (i=0 ; i<mctx.slavesNb ; i++)
  927. total += cctx[i].nbOpRecv;
  928. printf ("ldclt[%d]: Global number of replication operations received: %5d\n",
  929. mctx.pid, total);
  930. total = 0;
  931. for (i=0 ; i<mctx.slavesNb ; i++)
  932. total += cctx[i].nbEarly;
  933. printf ("ldclt[%d]: Global number of early replication: %5d\n",
  934. mctx.pid, total);
  935. total = 0;
  936. for (i=0 ; i<mctx.slavesNb ; i++)
  937. total += cctx[i].nbLate;
  938. printf ("ldclt[%d]: Global number of late replication: %5d\n",
  939. mctx.pid, total);
  940. total = 0;
  941. for (i=0 ; i<mctx.slavesNb ; i++)
  942. total += cctx[i].nbLostOp;
  943. printf ("ldclt[%d]: Global number of lost operation: %5d\n",
  944. mctx.pid, total);
  945. total = 0;
  946. for (i=0 ; i<mctx.slavesNb ; i++)
  947. total += cctx[i].nbNotOnList;
  948. printf ("ldclt[%d]: Global number of not on list replication op.: %5d\n",
  949. mctx.pid, total);
  950. total = 0;
  951. for (i=0 ; i<mctx.slavesNb ; i++)
  952. total += cctx[i].nbRepFail32;
  953. printf ("ldclt[%d]: Global number of repl failed LDAP_NO_SUCH_OBJECT: %5d\n",
  954. mctx.pid, total);
  955. total = 0;
  956. for (i=0 ; i<mctx.slavesNb ; i++)
  957. total += cctx[i].nbRepFail68;
  958. printf ("ldclt[%d]: Global number of repl failed LDAP_ALREADY_EXISTS: %5d\n",
  959. mctx.pid, total);
  960. total = 0;
  961. for (i=0 ; i<mctx.slavesNb ; i++)
  962. total += cctx[i].nbRepFailX;
  963. printf ("ldclt[%d]: Global number of repl failed other error: %5d\n",
  964. mctx.pid, total);
  965. total = 0;
  966. for (i=0 ; i<mctx.slavesNb ; i++)
  967. total += cctx[i].nbStillOnQ;
  968. printf ("ldclt[%d]: Global number of repl still on Queue: %5d\n",
  969. mctx.pid, total);
  970. }
  971. }
  972. /*
  973. * Normal end
  974. */
  975. fflush (stdout);
  976. return (0);
  977. }
  978. #ifndef _WIN32 /*JLS 29-11-00*/
  979. /* ****************************************************************************
  980. FUNCTION : trapVector
  981. PURPOSE : Interruption vector for SIGINT and SIGQUIT
  982. INPUT : sig = the signal
  983. OUTPUT : None.
  984. RETURN : -1 if error, 0 else.
  985. DESCRIPTION : Issue statistics report. If SIGINT, exit the tool.
  986. The other signal (SIGQUIT) will only issue statistics.
  987. *****************************************************************************/
  988. void
  989. trapVector (
  990. int sig,
  991. siginfo_t *siginfo,
  992. void *truc)
  993. {
  994. printf ("\n"); /* Jump over the ^C or ^\ */
  995. (void) printGlobalStatistics();
  996. if (sig == SIGINT)
  997. {
  998. printf ("Catch SIGINT - exit...\n");
  999. fflush (stdout);
  1000. ldcltExit (mctx.exitStatus); /*JLS 25-08-00*/
  1001. }
  1002. return;
  1003. }
  1004. #endif /* _WIN32 */ /*JLS 29-11-00*/
  1005. /* ****************************************************************************
  1006. FUNCTION : initMainThread
  1007. PURPOSE : Initiates the main thread
  1008. INPUT : None.
  1009. OUTPUT : None.
  1010. RETURN : -1 if error, 0 else.
  1011. DESCRIPTION :
  1012. *****************************************************************************/
  1013. int
  1014. initMainThread (void)
  1015. {
  1016. #ifndef _WIN32 /*JLS 29-11-00*/
  1017. struct sigaction act;
  1018. /*
  1019. * Trap SIGINT.
  1020. */
  1021. #ifdef LDCLT_CAST_SIGACTION /*JLS 01-12-00*/
  1022. act.sa_handler = (void(*)(int)) trapVector; /*JLS 14-11-00*/
  1023. #else /*JLS 14-11-00*/
  1024. act.sa_handler = trapVector;
  1025. #endif /*JLS 14-11-00*/
  1026. act.sa_sigaction = trapVector;
  1027. act.sa_flags = SA_NODEFER;
  1028. sigemptyset (&(act.sa_mask));
  1029. sigaddset (&(act.sa_mask), SIGINT);
  1030. sigfillset (&(act.sa_mask));
  1031. if (sigaction (SIGINT, &act, NULL) < 0)
  1032. {
  1033. perror ("ldclt");
  1034. fprintf (stderr, "ldclt[%d]: Error: cannot sigaction(SIGINT)\n", mctx.pid);
  1035. fflush (stderr);
  1036. return (-1);
  1037. }
  1038. /*
  1039. * Trap SIGQUIT.
  1040. */
  1041. #ifdef LDCLT_CAST_SIGACTION /*JLS 01-12-00*/
  1042. act.sa_handler = (void(*)(int)) trapVector; /*JLS 14-11-00*/
  1043. #else /*JLS 14-11-00*/
  1044. act.sa_handler = trapVector;
  1045. #endif /*JLS 14-11-00*/
  1046. act.sa_sigaction = trapVector;
  1047. act.sa_flags = SA_NODEFER;
  1048. sigemptyset (&(act.sa_mask));
  1049. sigaddset (&(act.sa_mask), SIGQUIT);
  1050. sigfillset (&(act.sa_mask));
  1051. if (sigaction (SIGQUIT, &act, NULL) < 0)
  1052. {
  1053. perror ("ldclt");
  1054. fprintf (stderr, "ldclt[%d]: Error: cannot sigaction(SIGQUIT)\n", mctx.pid);
  1055. fflush (stderr);
  1056. return (-1);
  1057. }
  1058. #endif /* _WIN32 */ /*JLS 29-11-00*/
  1059. return (0);
  1060. }
  1061. /* New function */ /*JLS 21-11-00*/
  1062. /* ****************************************************************************
  1063. FUNCTION : parseFilter
  1064. PURPOSE : This function parse a string in the form abcXXXdef
  1065. and returns the head, tail and number of digits for
  1066. the XXX part.
  1067. INPUT : src = source string
  1068. OUTPUT : head = head ==> abc
  1069. tail = tail ==> def
  1070. ndigits = number of digits
  1071. RETURN : -1 if error, 0 else.
  1072. DESCRIPTION :
  1073. *****************************************************************************/
  1074. int
  1075. parseFilter (
  1076. char *src,
  1077. char **head,
  1078. char **tail,
  1079. int *ndigits)
  1080. {
  1081. int i, j;
  1082. for (i=0 ; (i<strlen(src)) && (src[i]!='X') ; i++);
  1083. *head = (char *)malloc(i+1);
  1084. if (*head == NULL)
  1085. {
  1086. printf ("Error: cannot malloc(*head), error=%d (%s)\n",
  1087. errno, strerror (errno));
  1088. return (-1);
  1089. }
  1090. strncpy (*head, src, i);
  1091. (*head)[i] = '\0';
  1092. for (j=i ; (i<strlen(src)) && (src[j]=='X') ; j++);
  1093. *tail = (char *)malloc(strlen(src)-j+1);
  1094. if (*tail == NULL)
  1095. {
  1096. printf ("Error: cannot malloc(*tail), error=%d (%s)\n",
  1097. errno, strerror (errno));
  1098. return (-1);
  1099. }
  1100. strcpy (*tail, &(src[j]));
  1101. *ndigits = j-i;
  1102. return (0);
  1103. }
  1104. /* ****************************************************************************
  1105. FUNCTION : basicInit
  1106. PURPOSE : This function performs the basic initializations of
  1107. this tool, as soon as all the options are decoded.
  1108. INPUT : None.
  1109. OUTPUT : None.
  1110. RETURN : -1 if error, 0 else.
  1111. DESCRIPTION :
  1112. *****************************************************************************/
  1113. #define BUFFERSIZE 1024 /* buffer size for buffer */
  1114. int
  1115. basicInit (void)
  1116. {
  1117. #ifndef _WIN32 /*JLS 29-11-00*/
  1118. struct rlimit rlp; /* For setrlimit() */
  1119. #endif /* _WIN32 */ /*JLS 29-11-00*/
  1120. int i; /* For the loops */ /*JLS 21-11-00*/
  1121. int ret; /* Return value */
  1122. int oflags;/* open() flags */ /*JLS 05-04-01*/
  1123. struct stat file_st ; /* file status checker for attreplacefile option */
  1124. int fd = -1;
  1125. FILE *attrF; /* file pointer for attreplacefile option */
  1126. char buffer[BUFFERSIZE]; /* buffer used to read attreplacefile content */
  1127. /*
  1128. * Misc inits
  1129. */
  1130. mctx.timeval.tv_sec = mctx.timeout;
  1131. mctx.timeval.tv_usec = 0;
  1132. mctx.timevalZero.tv_sec = 0;
  1133. mctx.timevalZero.tv_usec = 0;
  1134. /*
  1135. * Initiate the utilities
  1136. */
  1137. if (utilsInit() < 0) /*JLS 14-11-00*/
  1138. { /*JLS 14-11-00*/
  1139. fprintf (stderr, "Cannot initialize utilities.\n"); /*JLS 14-11-00*/
  1140. return (-1); /*JLS 14-11-00*/
  1141. } /*JLS 14-11-00*/
  1142. /*
  1143. * Maybe random data to be read from file ?
  1144. */
  1145. if (mctx.mod2 & M2_RNDBINDFILE) /*JLS 03-05-01*/
  1146. { /*JLS 03-05-01*/
  1147. mctx.rndBindDlf = dataListFile (mctx.rndBindFname); /*JLS 03-05-01*/
  1148. if (mctx.rndBindDlf == NULL) /*JLS 03-05-01*/
  1149. { /*JLS 03-05-01*/
  1150. fprintf (stderr, "Error : cannot read %s\n", /*JLS 03-05-01*/
  1151. mctx.rndBindFname); /*JLS 03-05-01*/
  1152. fflush (stderr); /*JLS 03-05-01*/
  1153. return (-1); /*JLS 03-05-01*/
  1154. } /*JLS 03-05-01*/
  1155. } /*JLS 03-05-01*/
  1156. /*
  1157. * Genldif output file ?
  1158. * This file should not already exist.
  1159. */
  1160. if (mctx.mod2 & M2_GENLDIF) /*JLS 19-03-01*/
  1161. { /*JLS 19-03-01*/
  1162. if (!(mctx.mod2 & M2_APPEND)) /*JLS 11-04-01*/
  1163. { /*JLS 11-04-01*/
  1164. mctx.genldifFile = open (mctx.genldifName, O_RDONLY); /*JLS 02-04-01*/
  1165. if (mctx.genldifFile != -1) /*JLS 02-04-01*/
  1166. { /*JLS 19-03-01*/
  1167. fprintf (stderr,"Error: File exits %s\n", /*JLS 19-03-01*/
  1168. mctx.genldifName); /*JLS 19-03-01*/
  1169. fflush (stderr); /*JLS 19-03-01*/
  1170. return (-1); /*JLS 19-03-01*/
  1171. } /*JLS 19-03-01*/
  1172. } /*JLS 11-04-01*/
  1173. if (mctx.mod2 & M2_APPEND) /*JLS 05-04-01*/
  1174. oflags = O_APPEND|O_WRONLY|O_CREAT; /*JLS 05-04-01*/
  1175. else /*JLS 05-04-01*/
  1176. oflags = O_EXCL|O_WRONLY|O_CREAT; /*JLS 05-04-01*/
  1177. #if !defined(_WIN32) && !defined(OSF1) && !defined(__LP64__) && !defined(_LP64) /*JLS 05-04-01*/
  1178. oflags |= O_LARGEFILE; /*JLS 05-04-01*/
  1179. #endif /*JLS 03-04-01*/
  1180. mctx.genldifFile = open (mctx.genldifName, oflags, 0666); /*JLS 05-04-01*/
  1181. if (mctx.genldifFile == -1) /*JLS 02-04-01*/
  1182. { /*JLS 19-03-01*/
  1183. fprintf (stderr, "ldclt: %s\n", strerror (errno)); /*JLS 19-03-01*/
  1184. fprintf (stderr,"Error: cannot create %s\n", /*JLS 19-03-01*/
  1185. mctx.genldifName); /*JLS 19-03-01*/
  1186. fflush (stderr); /*JLS 19-03-01*/
  1187. return (-1); /*JLS 19-03-01*/
  1188. } /*JLS 19-03-01*/
  1189. mctx.nbThreads = 1; /*JLS 19-03-01*/
  1190. } /*JLS 19-03-01*/
  1191. /*
  1192. * Maybe common counter ?
  1193. */
  1194. if ((mctx.mode & COMMON_COUNTER) &&(!(mctx.mod2 & M2_OBJECT)))/*JLS 28-03-01*/
  1195. { /*JLS 14-03-01*/
  1196. if ((ret = ldclt_mutex_init(&(mctx.lastVal_mutex))) != 0) /*JLS 14-03-01*/
  1197. { /*JLS 14-03-01*/
  1198. fprintf (stderr, "ldclt: %s\n", strerror (ret)); /*JLS 14-03-01*/
  1199. fprintf (stderr,"Error: cannot initiate lastVal_mutex\n");/*JLS 14-03-01*/
  1200. fflush (stderr); /*JLS 14-03-01*/
  1201. return (-1); /*JLS 14-03-01*/
  1202. } /*JLS 14-03-01*/
  1203. mctx.lastVal = mctx.randomLow-mctx.incr; /*JLS 14-03-01*/
  1204. } /*JLS 14-03-01*/
  1205. /*
  1206. * Set appropriate number of files...
  1207. */
  1208. #ifndef _WIN32 /*JLS 29-11-00*/
  1209. if (mctx.nbThreads > 54)
  1210. {
  1211. if (getrlimit (RLIMIT_NOFILE, &rlp) < 0)
  1212. {
  1213. perror ("ldclt");
  1214. fprintf (stderr, "Error: cannot getrlimit()\n");
  1215. fflush (stderr);
  1216. return (-1);
  1217. }
  1218. rlp.rlim_cur = rlp.rlim_max;
  1219. if (setrlimit (RLIMIT_NOFILE, &rlp) < 0)
  1220. {
  1221. perror ("ldclt");
  1222. fprintf (stderr, "Error: cannot setrlimit()\n");
  1223. fflush (stderr);
  1224. return (-1);
  1225. }
  1226. if (mctx.mode & VERBOSE)
  1227. printf ("Set file number to %u\n", (unsigned int)rlp.rlim_max);
  1228. }
  1229. #endif /* _WIN32 */ /*JLS 29-11-00*/
  1230. /*
  1231. * Maybe an object to read ?
  1232. */
  1233. if (mctx.mod2 & M2_OBJECT) /*JLS 19-03-01*/
  1234. if (readObject (&(mctx.object)) < 0) /*JLS 19-03-01*/
  1235. { /*JLS 19-03-01*/
  1236. printf ("Error: cannot parse %s\n", mctx.object.fname); /*JLS 19-03-01*/
  1237. return (-1); /*JLS 19-03-01*/
  1238. } /*JLS 19-03-01*/
  1239. /*
  1240. * Maybe random filter to prepare ?
  1241. */
  1242. if ((mctx.mode & (RANDOM | INCREMENTAL)) &&
  1243. (!(mctx.mod2 & M2_RDN_VALUE))) /*JLS 23-03-01*/
  1244. {
  1245. if (parseFilter (mctx.filter, &(mctx.randomHead), /*JLS 21-11-00*/
  1246. &(mctx.randomTail), &(mctx.randomNbDigit)) < 0) /*JLS 21-11-00*/
  1247. { /*JLS 21-11-00*/
  1248. printf ("Error: cannot parse filter...\n"); /*JLS 21-11-00*/
  1249. return (-1); /*JLS 21-11-00*/
  1250. } /*JLS 21-11-00*/
  1251. }
  1252. /*
  1253. * Maybe random base DN to prepare ?
  1254. */
  1255. if (mctx.mode & RANDOM_BASE)
  1256. {
  1257. if (parseFilter (mctx.baseDN, &(mctx.baseDNHead), /*JLS 21-11-00*/
  1258. &(mctx.baseDNTail), &(mctx.baseDNNbDigit)) < 0) /*JLS 21-11-00*/
  1259. { /*JLS 21-11-00*/
  1260. printf ("Error: cannot parse base DN...\n"); /*JLS 21-11-00*/
  1261. return (-1); /*JLS 21-11-00*/
  1262. } /*JLS 21-11-00*/
  1263. }
  1264. /*
  1265. * Maybe random bind DN to prepare ?
  1266. */
  1267. if (mctx.mode & RANDOM_BINDDN) /*JLS 05-01-01*/
  1268. { /*JLS 05-01-01*/
  1269. if (parseFilter (mctx.bindDN, &(mctx.bindDNHead), /*JLS 05-01-01*/
  1270. &(mctx.bindDNTail), &(mctx.bindDNNbDigit)) < 0) /*JLS 05-01-01*/
  1271. { /*JLS 05-01-01*/
  1272. printf ("Error: cannot parse bind DN...\n"); /*JLS 05-01-01*/
  1273. return (-1); /*JLS 05-01-01*/
  1274. } /*JLS 05-01-01*/
  1275. if (parseFilter (mctx.passwd, &(mctx.passwdHead), /*JLS 05-01-01*/
  1276. &(mctx.passwdTail), &(mctx.passwdNbDigit)) < 0) /*JLS 05-01-01*/
  1277. { /*JLS 05-01-01*/
  1278. printf ("Error: cannot parse password...\n"); /*JLS 05-01-01*/
  1279. return (-1); /*JLS 05-01-01*/
  1280. } /*JLS 05-01-01*/
  1281. } /*JLS 05-01-01*/
  1282. /*
  1283. * Maybe random authid to prepare ?
  1284. */
  1285. if (mctx.mod2 & M2_RANDOM_SASLAUTHID)
  1286. {
  1287. if (parseFilter (mctx.sasl_authid, &(mctx.sasl_authid_head),
  1288. &(mctx.sasl_authid_tail), &(mctx.sasl_authid_nbdigit)) < 0)
  1289. {
  1290. printf ("Error: cannot parse bind DN...\n");
  1291. return (-1);
  1292. }
  1293. }
  1294. /*
  1295. * Maybe an attribute replacement to prepare ?
  1296. */
  1297. if (mctx.mode & ATTR_REPLACE) /*JLS 21-11-00*/
  1298. { /*JLS 21-11-00*/
  1299. /*
  1300. * Find the attribute name
  1301. */
  1302. for (i=0 ; (i<strlen(mctx.attrpl)) && /*JLS 21-11-00*/
  1303. (mctx.attrpl[i]!=':') ; i++); /*JLS 21-11-00*/
  1304. mctx.attrplName = (char *)malloc(i+1); /*JLS 21-11-00*/
  1305. strncpy (mctx.attrplName, mctx.attrpl, i); /*JLS 21-11-00*/
  1306. mctx.attrplName[i] = '\0'; /*JLS 21-11-00*/
  1307. /*
  1308. * Parse the attribute value
  1309. */
  1310. if (parseFilter (mctx.attrpl+i+1, &(mctx.attrplHead), /*JLS 21-11-00*/
  1311. &(mctx.attrplTail), &(mctx.attrplNbDigit)) < 0) /*JLS 21-11-00*/
  1312. { /*JLS 21-11-00*/
  1313. printf ("Error: cannot parse attreplace...\n"); /*JLS 21-11-00*/
  1314. return (-1); /*JLS 21-11-00*/
  1315. } /*JLS 21-11-00*/
  1316. } /*JLS 21-11-00*/
  1317. /*YI parse reference atrr and dereference attr */
  1318. /*
  1319. * Parse deref subvalue
  1320. */
  1321. if ((mctx.mod2 & M2_DEREF) && mctx.attrpl)
  1322. {
  1323. /*
  1324. * Find the reference attribute name
  1325. */
  1326. for (i=0 ; (i<strlen(mctx.attrpl)) &&
  1327. (mctx.attrpl[i]!=':') ; i++);
  1328. mctx.attRef= (char *)malloc(i+1);
  1329. strncpy (mctx.attRef, mctx.attrpl, i);
  1330. mctx.attRef[i] = '\0';
  1331. /*
  1332. * Parse the deference attribute value
  1333. */
  1334. mctx.attRefDef= (char *)malloc(strlen(mctx.attrpl + i) + 2);
  1335. if (mctx.attRefDef== NULL) {
  1336. printf ("Error: unable to allocate memory for attRefDef\n");
  1337. return (-1);
  1338. }
  1339. strncpy(mctx.attRefDef, mctx.attrpl+i+1, strlen(mctx.attrpl+i+1));
  1340. mctx.attRefDef[strlen(mctx.attrpl+i+1)] = '\0';
  1341. }
  1342. /*
  1343. * Parse attreplacefile subvalue
  1344. */
  1345. if ((mctx.mod2 & M2_ATTR_REPLACE_FILE) && mctx.attrpl)
  1346. {
  1347. /*
  1348. * Find the attribute name
  1349. */
  1350. for (i=0 ; (i<strlen(mctx.attrpl)) &&
  1351. (mctx.attrpl[i]!=':') ; i++);
  1352. mctx.attrplName = (char *)malloc(i+1);
  1353. strncpy (mctx.attrplName, mctx.attrpl, i);
  1354. mctx.attrplName[i] = '\0';
  1355. /*
  1356. * Parse the attribute value
  1357. */
  1358. mctx.attrplFile = (char *)malloc(strlen(mctx.attrpl+i) + 2);
  1359. if (mctx.attrplFile == NULL) {
  1360. printf ("Error: unable to allocate memory for attreplfile\n");
  1361. return (-1);
  1362. }
  1363. strncpy(mctx.attrplFile, mctx.attrpl+i+1, strlen(mctx.attrpl+i+1));
  1364. mctx.attrplFile[strlen(mctx.attrpl+i+1)] = '\0';
  1365. /*
  1366. * start working on file verification here
  1367. (1) check whether file exist
  1368. (2) check whether we have permission to read it
  1369. (3) save the content into mctx.attrplFileContent
  1370. */
  1371. fd = open(mctx.attrplFile, O_RDONLY);
  1372. if (fd == -1)
  1373. {
  1374. printf("ERROR reading attr file [%s]\n",mctx.attrplFile);
  1375. return (-1);
  1376. }else{
  1377. printf("file opened for reading\n");
  1378. }
  1379. /* determine file size here */
  1380. if (fstat(fd, &file_st) < 0){
  1381. printf ("attr replace file [%s] does not exist, exit\n", mctx.attrplFile);
  1382. close(fd);
  1383. return (-1);
  1384. }else{
  1385. mctx.attrplFileSize = file_st.st_size;
  1386. printf ("file has size [%d] bytes\n", mctx.attrplFileSize );
  1387. }
  1388. /* open file to read */
  1389. if ((attrF = fdopen(fd, "r")) == NULL )
  1390. {
  1391. printf("ERROR reading attr file [%s]\n",mctx.attrplFile);
  1392. close(fd);
  1393. return (-1);
  1394. }else{
  1395. printf("file opened for reading\n");
  1396. }
  1397. /* start to read file content */
  1398. mctx.attrplFileContent = (char *)malloc(mctx.attrplFileSize + 1);
  1399. i=0;
  1400. while ( (ret = fread(buffer, BUFFERSIZE , 1, attrF)) )
  1401. {
  1402. memcpy(mctx.attrplFileContent+i, buffer , ret);
  1403. memset(buffer ,'\0', BUFFERSIZE);
  1404. i += ret;
  1405. }
  1406. /* copy remainding content into mctx.attrplFileContent */
  1407. /* ???
  1408. * Why you need to copy buffer twice to fill the gap?
  1409. * Could there any chance (mctx.attrplFileSize - 1 - i) > BUFFERSIZE ?
  1410. */
  1411. if (i<mctx.attrplFileSize)
  1412. {
  1413. memcpy(mctx.attrplFileContent+i, buffer , (mctx.attrplFileSize - 1 - i));
  1414. memset(buffer ,'\0', BUFFERSIZE ); /* clear the buffer */
  1415. }
  1416. mctx.attrplFileContent[mctx.attrplFileSize]='\0'; /* append the close bit */
  1417. if ((fclose(attrF)) == EOF )
  1418. {
  1419. printf("ERROR closing attr file [%s]\n",mctx.attrplFile);
  1420. return (-1);
  1421. }else{
  1422. printf("file closed\n");
  1423. }
  1424. }
  1425. /*
  1426. * Initiates statistics fields
  1427. */
  1428. mctx.totNbOpers = 0;
  1429. mctx.totNbSamples = 0;
  1430. mctx.errorsBad = 0;
  1431. for (i=0 ; i<MAX_ERROR_NB ; i++)
  1432. mctx.errors[i] = 0;
  1433. /*
  1434. * Initiate the mutex that protect the errors statistics
  1435. */
  1436. if ((ret = ldclt_mutex_init(&(mctx.errors_mutex))) != 0)
  1437. {
  1438. fprintf (stderr, "ldclt: %s\n", strerror (ret));
  1439. fprintf (stderr, "Error: cannot initiate errors_mutex\n");
  1440. fflush (stderr);
  1441. return (-1);
  1442. }
  1443. /*
  1444. * Load the images
  1445. */
  1446. if (mctx.mode & (OC_EMAILPERSON|OC_INETORGPRSON)) /*JLS 07-11-00*/
  1447. if (loadImages (mctx.imagesDir) < 0) /*JLS 16-11-00*/
  1448. return (-1);
  1449. /*
  1450. * Maybe we should initiate the operation list mutex and other check-related
  1451. * thing...
  1452. */
  1453. if (mctx.slavesNb > 0)
  1454. {
  1455. /*
  1456. * Initiates the mutex
  1457. */
  1458. if ((ret = ldclt_mutex_init(&(mctx.opListTail_mutex))) != 0)
  1459. {
  1460. fprintf (stderr, "ldclt: %s\n", strerror (ret));
  1461. fprintf (stderr, "Error: cannot initiate opListTail_mutex\n");
  1462. fflush (stderr);
  1463. return (-1);
  1464. }
  1465. /*
  1466. * Initiates the first operation with empty dummy values
  1467. * We need to initiate this entry to dummy values because some opXyz()
  1468. * functions will access this entry careless.
  1469. */
  1470. mctx.opListTail = (oper *) malloc (sizeof (oper));
  1471. if (mctx.opListTail == NULL) /*JLS 06-03-00*/
  1472. { /*JLS 06-03-00*/
  1473. printf ("Error: cannot malloc(mctx.opListTail), error=%d (%s)\n",
  1474. errno, strerror (errno)); /*JLS 06-03-00*/
  1475. return (-1); /*JLS 06-03-00*/
  1476. } /*JLS 06-03-00*/
  1477. mctx.opListTail->dn = strdup("Dummy initial dn");
  1478. if (mctx.opListTail->dn == NULL) /*JLS 06-03-00*/
  1479. { /*JLS 06-03-00*/
  1480. printf ("Error: cannot strdup(mctx.opListTail->dn), error=%d (%s)\n",
  1481. errno, strerror (errno)); /*JLS 06-03-00*/
  1482. return (-1); /*JLS 06-03-00*/
  1483. } /*JLS 06-03-00*/
  1484. mctx.opListTail->attribs[0].type = NULL;
  1485. mctx.opListTail->newRdn = NULL;
  1486. mctx.opListTail->newParent = NULL;
  1487. mctx.opListTail->skipped = 0;
  1488. mctx.opListTail->next = NULL;
  1489. if ((ret=ldclt_mutex_init(&(mctx.opListTail->skipped_mutex))) != 0)
  1490. {
  1491. fprintf (stderr, "ldclt: %s\n", strerror (ret));
  1492. fprintf (stderr, "Error: cannot initiate opListTail->skipped_mutex\n");
  1493. fflush (stderr);
  1494. return (-1);
  1495. }
  1496. }
  1497. #if !defined(USE_OPENLDAP)
  1498. /*
  1499. * SSL is enabled ?
  1500. */
  1501. if (mctx.mode & SSL)
  1502. {
  1503. /*
  1504. * The initialization of certificate based and basic authentication differs
  1505. * B Kolics 23-11-00
  1506. */
  1507. if (mctx.mode & CLTAUTH)
  1508. {
  1509. if (ldapssl_clientauth_init(mctx.certfile, NULL, 1, mctx.keydbfile, NULL) < 0)
  1510. {
  1511. fprintf (stderr, "ldclt: %s\n", strerror (errno));
  1512. fprintf (stderr, "Cannot ldapssl_clientauth_init (%s,%s)\n",
  1513. mctx.certfile, mctx.keydbfile);
  1514. fflush (stderr);
  1515. return (-1);
  1516. }
  1517. } else {
  1518. if (ldapssl_client_init(mctx.certfile, NULL) < 0)
  1519. {
  1520. fprintf (stderr, "ldclt: %s\n", strerror (errno));
  1521. fprintf (stderr, "Cannot ldapssl_client_init (%s)\n", /*JLS 08-11-00*/
  1522. mctx.certfile); /*JLS 08-11-00*/
  1523. fflush (stderr);
  1524. return (-1);
  1525. }
  1526. }
  1527. }
  1528. #endif /* !defined(USE_OPENLDAP) */
  1529. /*
  1530. * Specific scenarios initialization...
  1531. */
  1532. if (mctx.mode & SCALAB01) /*JLS 08-01-01*/
  1533. if (scalab01_init() < 0) /*JLS 08-01-01*/
  1534. { /*JLS 08-01-01*/
  1535. fprintf (stderr, "ldclt: cannot init scalab01\n"); /*JLS 08-01-01*/
  1536. fflush (stderr); /*JLS 08-01-01*/
  1537. return (-1); /*JLS 08-01-01*/
  1538. } /*JLS 08-01-01*/
  1539. /*
  1540. * Normal end
  1541. */
  1542. return (0);
  1543. }
  1544. /* ****************************************************************************
  1545. FUNCTION : printModeValues
  1546. PURPOSE : This function is targetted to print the bits mask of
  1547. the mode field.
  1548. INPUT : None.
  1549. OUTPUT : None.
  1550. RETURN : None.
  1551. DESCRIPTION :
  1552. *****************************************************************************/
  1553. void
  1554. dumpModeValues (void)
  1555. {
  1556. if (mctx.mode & QUIET)
  1557. printf (" quiet");
  1558. if (mctx.mode & SUPER_QUIET)
  1559. printf (" super_quiet");
  1560. if (mctx.mode & VERBOSE)
  1561. printf (" verbose");
  1562. if (mctx.mode & VERY_VERBOSE)
  1563. printf (" very_verbose");
  1564. if (mctx.mode & COUNT_EACH) /*JLS 15-12-00*/
  1565. printf (" counteach"); /*JLS 15-12-00*/
  1566. if (mctx.mode & LDAP_V2)
  1567. printf (" v2");
  1568. if (mctx.mode & ASYNC)
  1569. printf (" asynchronous");
  1570. if (mctx.mode & INCREMENTAL)
  1571. printf (" incremental");
  1572. if (mctx.mode & COMMON_COUNTER) /*JLS 14-03-01*/
  1573. printf (" commoncounter"); /*JLS 14-03-01*/
  1574. if (mctx.mode & NOLOOP)
  1575. printf (" noloop");
  1576. if (mctx.mode & RANDOM)
  1577. printf (" random");
  1578. if (mctx.mode & RANDOM_BASE)
  1579. printf (" randombase");
  1580. if (mctx.mode & RANDOM_BINDDN) /*JLS 05-01-01*/
  1581. printf (" randombinddn"); /*JLS 05-01-01*/
  1582. if (mctx.mode & STRING)
  1583. printf (" string");
  1584. if (mctx.mode & ASCII_7BITS)
  1585. printf (" ascii");
  1586. if (mctx.mode & CLOSE_FD)
  1587. printf (" close_fd");
  1588. if (mctx.mode & BIND_EACH_OPER)
  1589. printf (" bind_each_operation");
  1590. if (mctx.mode & SSL)
  1591. printf (" ssl");
  1592. if (mctx.mode & CLTAUTH)
  1593. printf (" ssl_with_client_authentication"); /* BK 23-11-00*/
  1594. if (mctx.mod2 & M2_SASLAUTH)
  1595. printf (" saslauth");
  1596. if (mctx.mod2 & M2_RANDOM_SASLAUTHID)
  1597. printf (" randomauthid");
  1598. if (mctx.mode & SMOOTHSHUTDOWN) /*JLS 17-11-00*/
  1599. printf (" smoothshutdown"); /*JLS 17-11-00*/
  1600. if (mctx.mode & DONT_SLEEP_DOWN) /*JLS 14-03-01*/
  1601. printf (" dontsleeponserverdown"); /*JLS 14-03-01*/
  1602. if (mctx.mode & ADD_ENTRIES)
  1603. printf (" add");
  1604. if (mctx.mode & ATTR_REPLACE) /*JLS 21-11-00*/
  1605. printf (" attrib_replace"); /*JLS 21-11-00*/
  1606. if (mctx.mod2 & M2_BINDONLY) /*JLS 04-05-01*/
  1607. printf (" bindonly"); /*JLS 04-05-01*/
  1608. if (mctx.mode & DELETE_ENTRIES)
  1609. printf (" delete");
  1610. if (mctx.mode & EXACT_SEARCH)
  1611. printf (" exact_search");
  1612. if (mctx.mode & RANDOM_ATTRLIST) /*JLS 15-03-01*/
  1613. printf (" randomattrlist"); /*JLS 15-03-01*/
  1614. if (mctx.mode & RENAME_ENTRIES)
  1615. printf (" rename");
  1616. if (mctx.mode & WITH_NEWPARENT) /*JLS 15-12-00*/
  1617. printf (" withnewparent"); /*JLS 15-12-00*/
  1618. if (mctx.mod2 & M2_GENLDIF) /*JLS 08-01-01*/
  1619. printf (" genldif=%s", mctx.genldifName); /*JLS 05-04-01*/
  1620. if (mctx.mode & SCALAB01) /*JLS 08-01-01*/
  1621. printf (" scalab01"); /*JLS 08-01-01*/
  1622. if (mctx.mode & OC_EMAILPERSON)
  1623. printf (" class=emailPerson");
  1624. if (mctx.mode & OC_PERSON)
  1625. printf (" class=person");
  1626. if (mctx.mode & OC_INETORGPRSON) /*JLS 07-11-00*/
  1627. printf (" class=inetOrgPerson"); /*JLS 07-11-00*/
  1628. if (mctx.mod2 & M2_OBJECT) /*JLS 19-03-01*/
  1629. printf (" object=%s", mctx.object.fname); /*JLS 19-03-01*/
  1630. if (mctx.mod2 & M2_RNDBINDFILE) /*JLS 04-05-01*/
  1631. printf (" randombinddnfromfile=%s", mctx.rndBindFname); /*JLS 04-05-01*/
  1632. return;
  1633. }
  1634. /*
  1635. * Scope parameters (-s sub-options)
  1636. */
  1637. char *scopeParams[] = {
  1638. #define SP_ONE 0
  1639. "one",
  1640. #define SP_SUBTREE 1
  1641. "subtree",
  1642. #define SP_BASE 2
  1643. "base",
  1644. NULL
  1645. };
  1646. /* ****************************************************************************
  1647. FUNCTION : decodeScopeParams
  1648. PURPOSE : Decode the scope parameters (ak asub-options of the
  1649. option -s).
  1650. INPUT : optarg = argument to decode
  1651. OUTPUT : None.
  1652. RETURN : -1 if error, 0 else.
  1653. DESCRIPTION :
  1654. *****************************************************************************/
  1655. int
  1656. decodeScopeParams (
  1657. char *optarg)
  1658. {
  1659. char *suboptions; /* To parse optarg */
  1660. char *subvalue; /* Current sub-option */
  1661. suboptions = optarg;
  1662. while (*suboptions != '\0')
  1663. {
  1664. switch (getsubopt (&suboptions, scopeParams, &subvalue))
  1665. {
  1666. case SP_BASE:
  1667. mctx.scope = LDAP_SCOPE_BASE;
  1668. break;
  1669. case SP_ONE:
  1670. mctx.scope = LDAP_SCOPE_ONELEVEL;
  1671. break;
  1672. case SP_SUBTREE:
  1673. mctx.scope = LDAP_SCOPE_SUBTREE;
  1674. break;
  1675. default:
  1676. fprintf (stderr, "Error: illegal option -s %s\n", subvalue);
  1677. return (-1);
  1678. break;
  1679. }
  1680. }
  1681. return (0);
  1682. }
  1683. /* ****************************************************************************
  1684. FUNCTION : saslSetParam
  1685. PURPOSE : Sets SASL parameters
  1686. INPUT : saslarg = value to decode
  1687. OUTPUT : None.
  1688. RETURN : -1 if error, 0 otherwise.
  1689. DESCRIPTION : Copied from Mozilla LDAP C SDK (common.c)
  1690. *****************************************************************************/
  1691. int
  1692. saslSetParam (
  1693. char *saslarg)
  1694. {
  1695. char *attr = NULL;
  1696. int argnamelen;
  1697. if (saslarg == NULL) {
  1698. fprintf (stderr, "Error: missing SASL argument\n");
  1699. return (-1);
  1700. }
  1701. attr = strchr(saslarg, '=');
  1702. if (attr == NULL) {
  1703. fprintf( stderr, "Didn't find \"=\" character in %s\n", saslarg);
  1704. return (-1);
  1705. }
  1706. argnamelen = attr - saslarg;
  1707. attr++;
  1708. if (!strncasecmp(saslarg, "secProp", argnamelen)) {
  1709. if ( mctx.sasl_secprops != NULL ) {
  1710. fprintf( stderr, "secProp previously specified\n");
  1711. return (-1);
  1712. }
  1713. if (( mctx.sasl_secprops = strdup(attr)) == NULL ) {
  1714. perror ("malloc");
  1715. exit (LDAP_NO_MEMORY);
  1716. }
  1717. } else if (!strncasecmp(saslarg, "realm", argnamelen)) {
  1718. if ( mctx.sasl_realm != NULL ) {
  1719. fprintf( stderr, "Realm previously specified\n");
  1720. return (-1);
  1721. }
  1722. if (( mctx.sasl_realm = strdup(attr)) == NULL ) {
  1723. perror ("malloc");
  1724. exit (LDAP_NO_MEMORY);
  1725. }
  1726. } else if (!strncasecmp(saslarg, "authzid", argnamelen)) {
  1727. if (mctx.sasl_username != NULL) {
  1728. fprintf( stderr, "Authorization name previously specified\n");
  1729. return (-1);
  1730. }
  1731. if (( mctx.sasl_username = strdup(attr)) == NULL ) {
  1732. perror ("malloc");
  1733. exit (LDAP_NO_MEMORY);
  1734. }
  1735. } else if (!strncasecmp(saslarg, "authid", argnamelen)) {
  1736. if ( mctx.sasl_authid != NULL ) {
  1737. fprintf( stderr, "Authentication name previously specified\n");
  1738. return (-1);
  1739. }
  1740. if (( mctx.sasl_authid = strdup(attr)) == NULL) {
  1741. perror ("malloc");
  1742. exit (LDAP_NO_MEMORY);
  1743. }
  1744. } else if (!strncasecmp(saslarg, "mech", argnamelen)) {
  1745. if ( mctx.sasl_mech != NULL ) {
  1746. fprintf( stderr, "Mech previously specified\n");
  1747. return (-1);
  1748. }
  1749. if (( mctx.sasl_mech = strdup(attr)) == NULL) {
  1750. perror ("malloc");
  1751. exit (LDAP_NO_MEMORY);
  1752. }
  1753. } else if (!strncasecmp(saslarg, "flags", argnamelen)) {
  1754. int len = strlen(attr);
  1755. if (len && !strncasecmp(attr, "automatic", len)) {
  1756. mctx.sasl_flags = LDAP_SASL_AUTOMATIC;
  1757. } else if (len && !strncasecmp(attr, "interactive", len)) {
  1758. mctx.sasl_flags = LDAP_SASL_INTERACTIVE;
  1759. } else if (len && !strncasecmp(attr, "quiet", len)) {
  1760. mctx.sasl_flags = LDAP_SASL_QUIET;
  1761. } else {
  1762. fprintf(stderr, "Invalid SASL flags value [%s]: must be one of "
  1763. "automatic, interactive, or quiet\n", attr);
  1764. return (-1);
  1765. }
  1766. } else {
  1767. fprintf (stderr, "Invalid SASL attribute name %s\n", saslarg);
  1768. return (-1);
  1769. }
  1770. return 0;
  1771. }
  1772. /* New function */ /*JLS 08-03-01*/
  1773. /* ****************************************************************************
  1774. FUNCTION : decodeReferralParams
  1775. PURPOSE : Decode -e referral params.
  1776. INPUT : val = value to decode
  1777. OUTPUT : None.
  1778. RETURN : -1 if error, decoded value otherwise.
  1779. DESCRIPTION :
  1780. *****************************************************************************/
  1781. int
  1782. decodeReferralParams (
  1783. char *val)
  1784. {
  1785. if (val == NULL)
  1786. {
  1787. fprintf (stderr, "Error: missing arg referral\n");
  1788. return (-1);
  1789. }
  1790. if (!strcmp (val, "on"))
  1791. return (REFERRAL_ON);
  1792. if (!strcmp (val, "off"))
  1793. return (REFERRAL_OFF);
  1794. if (!strcmp (val, "rebind"))
  1795. return (REFERRAL_REBIND);
  1796. fprintf (stderr, "Error: illegal arg %s for referral\n", val);
  1797. return (-1);
  1798. }
  1799. /* ****************************************************************************
  1800. FUNCTION : addAttrToList
  1801. PURPOSE : Add attributes in the attribute list.
  1802. INPUT : list = list to process.
  1803. OUTPUT : None.
  1804. RETURN : -1 if error, 0 else.
  1805. DESCRIPTION :
  1806. *****************************************************************************/
  1807. int
  1808. addAttrToList (
  1809. char *list)
  1810. {
  1811. int start; /* Start of the attr name */
  1812. int end; /* End of the attr name */
  1813. /*
  1814. * Sanity check
  1815. */
  1816. if ((list == NULL) || (!(strlen(list))))
  1817. {
  1818. fprintf (stderr, "Error: missing attrlist\n");
  1819. return (-1);
  1820. }
  1821. /*
  1822. * The main loop.
  1823. */
  1824. start = 0;
  1825. while (start < strlen (list))
  1826. {
  1827. /*
  1828. * Maybe no more room in the structures ?
  1829. */
  1830. if ((mctx.attrlistNb+1) == MAX_ATTRIBS)
  1831. {
  1832. fprintf (stderr, "Error : too many attributes in attrlist\n");
  1833. return (-1);
  1834. }
  1835. for (end=start ; (list[end]!='\0') && (list[end]!=':') ; end++);
  1836. mctx.attrlist[mctx.attrlistNb] = (char *) malloc (1+end-start);
  1837. strncpy (mctx.attrlist[mctx.attrlistNb], &(list[start]), end-start);
  1838. mctx.attrlist[mctx.attrlistNb][end-start] = '\0';
  1839. mctx.attrlistNb++;
  1840. start = end+1;
  1841. }
  1842. return (0);
  1843. }
  1844. /* New */ /*JLS 23-03-01*/
  1845. /* ****************************************************************************
  1846. FUNCTION : decodeRdnParam
  1847. PURPOSE : Decodes a -e rdn=value parameter.
  1848. INPUT : value = value to decode.
  1849. OUTPUT : None.
  1850. RETURN : -1 if error, 0 else.
  1851. DESCRIPTION :
  1852. *****************************************************************************/
  1853. int
  1854. decodeRdnParam (
  1855. char *value)
  1856. {
  1857. int i; /* For the loops */
  1858. /*
  1859. * Note : ldclt does allow parameters overload. Ideally, we should
  1860. * free memory if a rdn has already been provided, but let's
  1861. * simply lost this data...
  1862. * Anyway, there is not a lot of memory used here...
  1863. */
  1864. mctx.object.rdn = (vers_attribute *) malloc (sizeof (vers_attribute));
  1865. mctx.object.rdn->buf = NULL; /*JLS 28-03-01*/
  1866. /*
  1867. * Find this attribute's name
  1868. */
  1869. for (i=0 ; (value[i] != '\0') && (value[i] != ':') ; i++);
  1870. if (value[i] == '\0')
  1871. {
  1872. fprintf (stderr, "Error: missing rdn attribute name\n");
  1873. return (-1);
  1874. }
  1875. mctx.object.rdnName = (char *) malloc (i+1);
  1876. strncpy (mctx.object.rdnName, value, i);
  1877. mctx.object.rdnName[i] = '\0';
  1878. /*
  1879. * Decode the value
  1880. */
  1881. if (parseAttribValue ("-e rdn=", &(mctx.object),
  1882. value+i+1, mctx.object.rdn) < 0)
  1883. return (-1);
  1884. return (0);
  1885. }
  1886. /*
  1887. * Exec params (-e sub-options)
  1888. */
  1889. char *execParams[] = {
  1890. #define EP_EXACT_SEARCH 0
  1891. "esearch",
  1892. #define EP_BIND_EACH_OPER 1
  1893. "bindeach",
  1894. #define EP_RANDOM 2
  1895. "random",
  1896. #define EP_CLOSE_FD 3
  1897. "close",
  1898. #define EP_INCREMENTAL 4
  1899. "incr",
  1900. #define EP_ADD_ENTRIES 5
  1901. "add",
  1902. #define EP_OC_PERSON 6
  1903. "person",
  1904. #define EP_DELETE_ENTRIES 7
  1905. "delete",
  1906. #define EP_OC_EMAILPERSON 8
  1907. "emailPerson",
  1908. #define EP_STRING 9
  1909. "string",
  1910. #define EP_RANDOM_BASE 10
  1911. "randombase",
  1912. #define EP_LDAP_V2 11
  1913. "v2",
  1914. #define EP_ASCII_7BITS 12
  1915. "ascii",
  1916. #define EP_NOLOOP 13
  1917. "noloop",
  1918. #define EP_RENAME 14
  1919. "rename",
  1920. #define EP_OC_INETORGPRSON 15 /*JLS 07-11-00*/
  1921. "inetOrgPerson", /*JLS 07-11-00*/
  1922. #define EP_RANDOM_BASE_LOW 16 /*JLS 13-11-00*/
  1923. "randombaselow", /*JLS 13-11-00*/
  1924. #define EP_RANDOM_BASE_HIGH 17 /*JLS 13-11-00*/
  1925. "randombasehigh", /*JLS 13-11-00*/
  1926. #define EP_IMAGES_DIR 18 /*JLS 16-11-00*/
  1927. "imagesdir", /*JLS 16-11-00*/
  1928. #define EP_SMOOTH_SHUTDOWN 19 /*JLS 17-11-00*/
  1929. "smoothshutdown", /*JLS 17-11-00*/
  1930. #define EP_ATT_REPLACE 20 /*JLS 21-11-00*/
  1931. "attreplace", /*JLS 21-11-00*/
  1932. #define EP_CLTCERT_NAME 21 /* BK 23-11-00*/
  1933. "cltcertname", /* BK 23-11-00*/
  1934. #define EP_KEYDB_FILE 22 /* BK 23-11-00*/
  1935. "keydbfile", /* BK 23-11-00*/
  1936. #define EP_KEYDB_PIN 23 /* BK 23-11-00*/
  1937. "keydbpin", /* BK 23-11-00*/
  1938. #define EP_COUNT_EACH 24 /*JLS 15-12-00*/
  1939. "counteach", /*JLS 15-12-00*/
  1940. #define EP_WITH_NEWPARENT 25 /*JLS 15-12-00*/
  1941. "withnewparent", /*JLS 15-12-00*/
  1942. #define EP_NO_GLOBAL_STATS 26 /*JLS 19-12-00*/
  1943. "noglobalstats", /*JLS 19-12-00*/
  1944. #define EP_ATTRSONLY 27 /*JLS 03-01-01*/
  1945. "attrsonly", /*JLS 03-01-01*/
  1946. #define EP_RANDOMBINDDN 28 /*JLS 05-01-01*/
  1947. "randombinddn", /*JLS 05-01-01*/
  1948. #define EP_RANDOMBINDDNHIGH 29 /*JLS 05-01-01*/
  1949. "randombinddnhigh", /*JLS 05-01-01*/
  1950. #define EP_RANDOMBINDDNLOW 30 /*JLS 05-01-01*/
  1951. "randombinddnlow", /*JLS 05-01-01*/
  1952. #define EP_SCALAB01 31 /*JLS 08-01-01*/
  1953. "scalab01", /*JLS 08-01-01*/
  1954. #define EP_SCALAB01_CNXDURATION 32 /*JLS 12-01-01*/
  1955. "scalab01_cnxduration", /*JLS 12-01-01*/
  1956. #define EP_SCALAB01_WAIT 33 /*JLS 12-01-01*/
  1957. "scalab01_wait", /*JLS 12-01-01*/
  1958. #define EP_SCALAB01_MAXCNXNB 34 /*JLS 12-01-01*/
  1959. "scalab01_maxcnxnb", /*JLS 12-01-01*/
  1960. #define EP_REFERRAL 35 /*JLS 08-03-01*/
  1961. "referral", /*JLS 08-03-01*/
  1962. #define EP_COMMONCOUNTER 36 /*JLS 14-03-01*/
  1963. "commoncounter", /*JLS 14-03-01*/
  1964. #define EP_DONTSLEEPONSERVERDOWN 37 /*JLS 14-03-01*/
  1965. "dontsleeponserverdown", /*JLS 14-03-01*/
  1966. #define EP_ATTRLIST 38 /*JLS 15-03-01*/
  1967. "attrlist", /*JLS 15-03-01*/
  1968. #define EP_RANDOMATTRLIST 39 /*JLS 15-03-01*/
  1969. "randomattrlist", /*JLS 15-03-01*/
  1970. #define EP_OBJECT 40 /*JLS 19-03-01*/
  1971. "object", /*JLS 19-03-01*/
  1972. #define EP_GENLDIF 41 /*JLS 19-03-01*/
  1973. "genldif", /*JLS 19-03-01*/
  1974. #define EP_RDN 42 /*JLS 23-03-01*/
  1975. "rdn", /*JLS 23-03-01*/
  1976. #define EP_APPEND 43 /*JLS 05-04-01*/
  1977. "append", /*JLS 05-04-01*/
  1978. #define EP_RANDOMBINDDNFROMFILE 44 /*JLS 03-05-01*/
  1979. "randombinddnfromfile", /*JLS 03-05-01*/
  1980. #define EP_BINDONLY 45 /*JLS 04-05-01*/
  1981. "bindonly", /*JLS 04-05-01*/
  1982. #define EP_RANDOMSASLAUTHID 46
  1983. "randomauthid",
  1984. #define EP_RANDOMSASLAUTHIDHIGH 47
  1985. "randomauthidhigh",
  1986. #define EP_RANDOMSASLAUTHIDLOW 48
  1987. "randomauthidlow",
  1988. #define EP_ABANDON 49
  1989. "abandon",
  1990. #define EP_DEREF 50
  1991. "deref",
  1992. #define EP_ATT_REPLACE_FILE 51
  1993. "attreplacefile",
  1994. #define EP_SRCH_NENTRIES 52 /* number of entries that must be returned by each search */
  1995. "srchnentries",
  1996. #define EP_SAMP_INTERVAL 53 /* sampling interval */
  1997. "sampinterval",
  1998. #define EP_TIMESTAMP 54 /* show timestamp when reporting progress */
  1999. "timestamp",
  2000. #define EP_NOZEROPAD 55 /* do not zero pad numbers created by XXX patterns in values and RDNs */
  2001. "nozeropad",
  2002. NULL
  2003. };
  2004. /* ****************************************************************************
  2005. FUNCTION : decodeExecParams
  2006. PURPOSE : Decode the execution parameters (aka sub-options of the
  2007. option -e).
  2008. INPUT : optarg = argument to decode.
  2009. OUTPUT : None.
  2010. RETURN : -1 if error, 0 else.
  2011. DESCRIPTION :
  2012. *****************************************************************************/
  2013. int
  2014. decodeExecParams (
  2015. char *optarg)
  2016. {
  2017. char *suboptions; /* To parse optarg */
  2018. char *subvalue; /* Current sub-option */
  2019. suboptions = optarg;
  2020. while (*suboptions != '\0')
  2021. {
  2022. switch (getsubopt (&suboptions, execParams, &subvalue))
  2023. {
  2024. case EP_ADD_ENTRIES:
  2025. mctx.mode |= ADD_ENTRIES;
  2026. break;
  2027. case EP_APPEND: /*JLS 05-04-01*/
  2028. mctx.mod2 |= M2_APPEND; /*JLS 05-04-01*/
  2029. break; /*JLS 05-04-01*/
  2030. case EP_ASCII_7BITS:
  2031. mctx.mode |= ASCII_7BITS;
  2032. break;
  2033. case EP_ATT_REPLACE: /*JLS 21-11-00*/
  2034. mctx.mode |= ATTR_REPLACE; /*JLS 21-11-00*/
  2035. if (subvalue == NULL) /*JLS 21-11-00*/
  2036. { /*JLS 21-11-00*/
  2037. fprintf (stderr, "Error: missing arg attreplace\n"); /*JLS 21-11-00*/
  2038. return (-1); /*JLS 21-11-00*/
  2039. } /*JLS 21-11-00*/
  2040. mctx.attrpl = strdup (subvalue); /*JLS 21-11-00*/
  2041. break; /*JLS 21-11-00*/
  2042. case EP_ATT_REPLACE_FILE:
  2043. mctx.mod2 |= M2_ATTR_REPLACE_FILE;
  2044. if (subvalue == NULL)
  2045. {
  2046. fprintf (stderr, "Error: missing arg attreplacefile\n");
  2047. return (-1);
  2048. }
  2049. mctx.attrpl = strdup (subvalue);
  2050. break;
  2051. case EP_ATTRLIST: /*JLS 15-03-01*/
  2052. return (addAttrToList (subvalue)); /*JLS 15-03-01*/
  2053. break; /*JLS 15-03-01*/
  2054. case EP_ATTRSONLY: /*JLS 03-01-01*/
  2055. if (subvalue == NULL) /*JLS 12-01-01*/
  2056. { /*JLS 12-01-01*/
  2057. fprintf (stderr, "Error: missing arg attrsonly\n"); /*JLS 12-01-01*/
  2058. return (-1); /*JLS 12-01-01*/
  2059. } /*JLS 12-01-01*/
  2060. mctx.attrsonly = atoi (subvalue); /*JLS 03-01-01*/
  2061. break; /*JLS 03-01-01*/
  2062. case EP_BIND_EACH_OPER:
  2063. mctx.mode |= BIND_EACH_OPER;
  2064. break;
  2065. case EP_BINDONLY: /*JLS 04-05-01*/
  2066. mctx.mod2 |= M2_BINDONLY; /*JLS 04-05-01*/
  2067. break; /*JLS 04-05-01*/
  2068. case EP_CLOSE_FD:
  2069. mctx.mode |= CLOSE_FD;
  2070. break;
  2071. case EP_CLTCERT_NAME: /* BK 23-11-00*/
  2072. mctx.mode |= CLTAUTH; /* BK 23-11-00*/
  2073. if (subvalue == NULL) /* BK 23-11-00*/
  2074. { /* BK 23-11-00*/
  2075. fprintf (stderr,"Error: missing arg for cltcertname\n");
  2076. /* BK 23-11-00*/
  2077. return (-1); /* BK 23-11-00*/
  2078. } /* BK 23-11-00*/
  2079. mctx.cltcertname = strdup (subvalue); /* BK 23-11-00*/
  2080. break; /* BK 23-11-00*/
  2081. case EP_COMMONCOUNTER: /*JLS 14-03-01*/
  2082. mctx.mode |= COMMON_COUNTER; /*JLS 14-03-01*/
  2083. break; /*JLS 14-03-01*/
  2084. case EP_COUNT_EACH: /*JLS 15-12-00*/
  2085. mctx.mode |= COUNT_EACH; /*JLS 15-12-00*/
  2086. break; /*JLS 15-12-00*/
  2087. case EP_DELETE_ENTRIES:
  2088. mctx.mode |= DELETE_ENTRIES;
  2089. break;
  2090. case EP_DONTSLEEPONSERVERDOWN: /*JLS 14-03-01*/
  2091. mctx.mode |= DONT_SLEEP_DOWN; /*JLS 14-03-01*/
  2092. break; /*JLS 14-03-01*/
  2093. case EP_EXACT_SEARCH:
  2094. mctx.mode |= EXACT_SEARCH;
  2095. break;
  2096. case EP_IMAGES_DIR: /*JLS 16-11-00*/
  2097. if (subvalue == NULL) /*JLS 16-11-00*/
  2098. { /*JLS 16-11-00*/
  2099. fprintf(stderr,"Error: missing arg for imagesdir\n"); /*JLS 16-11-00*/
  2100. return (-1); /*JLS 16-11-00*/
  2101. } /*JLS 16-11-00*/
  2102. mctx.imagesDir = strdup (subvalue); /*JLS 16-11-00*/
  2103. break; /*JLS 16-11-00*/
  2104. case EP_INCREMENTAL:
  2105. mctx.mode |= INCREMENTAL;
  2106. if (subvalue)
  2107. mctx.incr = atoi (subvalue);
  2108. break;
  2109. case EP_KEYDB_FILE: /* BK 23-11-00*/
  2110. mctx.mode |= CLTAUTH; /* BK 23-11-00*/
  2111. if (subvalue == NULL) /* BK 23-11-00*/
  2112. { /* BK 23-11-00*/
  2113. fprintf (stderr,"Error: missing arg for keydbfile\n");/* BK 23-11-00*/
  2114. return (-1); /* BK 23-11-00*/
  2115. } /* BK 23-11-00*/
  2116. mctx.keydbfile = strdup (subvalue); /* BK 23-11-00*/
  2117. break; /* BK 23-11-00*/
  2118. case EP_KEYDB_PIN: /* BK 23-11-00*/
  2119. mctx.mode |= CLTAUTH; /* BK 23-11-00*/
  2120. if (subvalue == NULL) /* BK 23-11-00*/
  2121. { /* BK 23-11-00*/
  2122. fprintf (stderr,"Error: missing arg for keydbpin\n"); /* BK 23-11-00*/
  2123. return (-1); /* BK 23-11-00*/
  2124. } /* BK 23-11-00*/
  2125. mctx.keydbpin = strdup (subvalue); /* BK 23-11-00*/
  2126. break; /* BK 23-11-00*/
  2127. case EP_LDAP_V2:
  2128. mctx.mode |= LDAP_V2;
  2129. break;
  2130. case EP_NO_GLOBAL_STATS: /*JLS 19-12-00*/
  2131. mctx.globStatsCnt = -1; /*JLS 19-12-00*/
  2132. break; /*JLS 19-12-00*/
  2133. case EP_NOLOOP:
  2134. mctx.mode |= NOLOOP;
  2135. break;
  2136. case EP_NOZEROPAD:
  2137. mctx.mod2 |= M2_NOZEROPAD;
  2138. break;
  2139. case EP_OBJECT: /*JLS 19-03-01*/
  2140. mctx.mod2 |= M2_OBJECT; /*JLS 19-03-01*/
  2141. if (subvalue == NULL) /*JLS 19-03-01*/
  2142. { /*JLS 19-03-01*/
  2143. fprintf (stderr, "Error: missing object filename\n"); /*JLS 19-03-01*/
  2144. return (-1); /*JLS 19-03-01*/
  2145. } /*JLS 19-03-01*/
  2146. mctx.object.fname = strdup (subvalue); /*JLS 19-03-01*/
  2147. break; /*JLS 19-03-01*/
  2148. case EP_OC_EMAILPERSON:
  2149. mctx.mode |= OC_EMAILPERSON;
  2150. break;
  2151. case EP_GENLDIF: /*JLS 19-03-01*/
  2152. mctx.mod2 |= M2_GENLDIF; /*JLS 19-03-01*/
  2153. if (subvalue == NULL) /*JLS 19-03-01*/
  2154. { /*JLS 19-03-01*/
  2155. fprintf (stderr, "Error: missing genldif filename\n");/*JLS 19-03-01*/
  2156. return (-1); /*JLS 19-03-01*/
  2157. } /*JLS 19-03-01*/
  2158. mctx.genldifName = strdup (subvalue); /*JLS 19-03-01*/
  2159. break; /*JLS 19-03-01*/
  2160. case EP_OC_INETORGPRSON: /*JLS 07-11-00*/
  2161. mctx.mode |= OC_INETORGPRSON; /*JLS 07-11-00*/
  2162. break; /*JLS 07-11-00*/
  2163. case EP_OC_PERSON:
  2164. mctx.mode |= OC_PERSON;
  2165. break;
  2166. case EP_RANDOM:
  2167. mctx.mode |= RANDOM;
  2168. break;
  2169. case EP_RANDOM_BASE:
  2170. mctx.mode |= RANDOM_BASE;
  2171. break;
  2172. case EP_RANDOM_BASE_HIGH: /*JLS 13-11-00*/
  2173. mctx.mode |= RANDOM_BASE; /*JLS 13-11-00*/
  2174. if (subvalue == NULL) /*JLS 12-01-01*/
  2175. { /*JLS 12-01-01*/
  2176. fprintf(stderr,"Error: missing arg randombasehigh\n");/*JLS 12-01-01*/
  2177. return (-1); /*JLS 12-01-01*/
  2178. } /*JLS 12-01-01*/
  2179. mctx.baseDNHigh = atoi (subvalue); /*JLS 13-11-00*/
  2180. break; /*JLS 13-11-00*/
  2181. case EP_RANDOM_BASE_LOW: /*JLS 13-11-00*/
  2182. mctx.mode |= RANDOM_BASE; /*JLS 13-11-00*/
  2183. if (subvalue == NULL) /*JLS 12-01-01*/
  2184. { /*JLS 12-01-01*/
  2185. fprintf(stderr, "Error: missing arg randombaselow\n");/*JLS 12-01-01*/
  2186. return (-1); /*JLS 12-01-01*/
  2187. } /*JLS 12-01-01*/
  2188. mctx.baseDNLow = atoi (subvalue); /*JLS 13-11-00*/
  2189. break; /*JLS 13-11-00*/
  2190. case EP_RANDOMATTRLIST: /*JLS 15-03-01*/
  2191. mctx.mode |= RANDOM_ATTRLIST; /*JLS 15-03-01*/
  2192. return (addAttrToList (subvalue)); /*JLS 15-03-01*/
  2193. break; /*JLS 15-03-01*/
  2194. case EP_RANDOMBINDDN: /*JLS 05-01-01*/
  2195. mctx.mode |= RANDOM_BINDDN; /*JLS 05-01-01*/
  2196. break; /*JLS 05-01-01*/
  2197. case EP_RANDOMBINDDNFROMFILE: /*JLS 03-05-01*/
  2198. mctx.mod2 |= M2_RNDBINDFILE; /*JLS 03-05-01*/
  2199. if (subvalue == NULL) /*JLS 03-05-01*/
  2200. { /*JLS 03-05-01*/
  2201. fprintf(stderr,"Error: missing file name for randombinddnfromfile\n");
  2202. return (-1); /*JLS 03-05-01*/
  2203. } /*JLS 03-05-01*/
  2204. mctx.rndBindFname = strdup (subvalue); /*JLS 03-05-01*/
  2205. break; /*JLS 03-05-01*/
  2206. case EP_RANDOMBINDDNHIGH: /*JLS 05-01-01*/
  2207. mctx.mode |= RANDOM_BINDDN; /*JLS 05-01-01*/
  2208. if (subvalue == NULL) /*JLS 12-01-01*/
  2209. { /*JLS 12-01-01*/
  2210. fprintf(stderr,"Error: missing arg randombindhigh\n");/*JLS 12-01-01*/
  2211. return (-1); /*JLS 12-01-01*/
  2212. } /*JLS 12-01-01*/
  2213. mctx.bindDNHigh = atoi (subvalue); /*JLS 05-01-01*/
  2214. break; /*JLS 05-01-01*/
  2215. case EP_RANDOMBINDDNLOW: /*JLS 05-01-01*/
  2216. mctx.mode |= RANDOM_BINDDN; /*JLS 05-01-01*/
  2217. if (subvalue == NULL) /*JLS 12-01-01*/
  2218. { /*JLS 12-01-01*/
  2219. fprintf(stderr, "Error: missing arg randombindlow\n");/*JLS 12-01-01*/
  2220. return (-1); /*JLS 12-01-01*/
  2221. } /*JLS 12-01-01*/
  2222. mctx.bindDNLow = atoi (subvalue); /*JLS 05-01-01*/
  2223. break; /*JLS 05-01-01*/
  2224. case EP_RANDOMSASLAUTHID:
  2225. mctx.mod2 |= M2_RANDOM_SASLAUTHID;
  2226. break;
  2227. case EP_RANDOMSASLAUTHIDHIGH:
  2228. mctx.mod2 |= M2_RANDOM_SASLAUTHID;
  2229. if (subvalue == NULL)
  2230. {
  2231. fprintf(stderr,"Error: missing arg randomauthidhigh\n");
  2232. return (-1);
  2233. }
  2234. mctx.sasl_authid_high = atoi (subvalue);
  2235. break;
  2236. case EP_RANDOMSASLAUTHIDLOW:
  2237. mctx.mod2 |= M2_RANDOM_SASLAUTHID;
  2238. if (subvalue == NULL)
  2239. {
  2240. fprintf(stderr, "Error: missing arg randomauthidlow\n");
  2241. return (-1);
  2242. }
  2243. mctx.sasl_authid_low = atoi (subvalue);
  2244. break;
  2245. case EP_RDN: /*JLS 23-03-01*/
  2246. if (decodeRdnParam (subvalue) < 0) /*JLS 23-03-01*/
  2247. return (-1); /*JLS 23-03-01*/
  2248. mctx.mod2 |= M2_RDN_VALUE; /*JLS 23-03-01*/
  2249. break; /*JLS 23-03-01*/
  2250. case EP_REFERRAL: /*JLS 08-03-01*/
  2251. if ((mctx.referral=decodeReferralParams(subvalue))<0) /*JLS 08-03-01*/
  2252. return (-1); /*JLS 08-03-01*/
  2253. break; /*JLS 08-03-01*/
  2254. case EP_RENAME:
  2255. mctx.mode |= RENAME_ENTRIES;
  2256. break;
  2257. case EP_SCALAB01: /*JLS 08-01-01*/
  2258. mctx.mode |= SCALAB01; /*JLS 08-01-01*/
  2259. break; /*JLS 08-01-01*/
  2260. case EP_SCALAB01_CNXDURATION: /*JLS 12-01-01*/
  2261. mctx.mode |= SCALAB01; /*JLS 12-01-01*/
  2262. if (subvalue == NULL) /*JLS 12-01-01*/
  2263. { /*JLS 12-01-01*/
  2264. fprintf (stderr, "Error: missing arg scalab01_cnxduration\n");
  2265. return (-1); /*JLS 12-01-01*/
  2266. } /*JLS 12-01-01*/
  2267. s1ctx.cnxduration = atoi (subvalue); /*JLS 12-01-01*/
  2268. break; /*JLS 12-01-01*/
  2269. case EP_SCALAB01_MAXCNXNB: /*JLS 12-01-01*/
  2270. mctx.mode |= SCALAB01; /*JLS 12-01-01*/
  2271. if (subvalue == NULL) /*JLS 12-01-01*/
  2272. { /*JLS 12-01-01*/
  2273. fprintf (stderr, "Error: missing arg scalab01_maxcnxnb\n");
  2274. return (-1); /*JLS 12-01-01*/
  2275. } /*JLS 12-01-01*/
  2276. s1ctx.maxcnxnb = atoi (subvalue); /*JLS 12-01-01*/
  2277. break; /*JLS 12-01-01*/
  2278. case EP_SCALAB01_WAIT: /*JLS 12-01-01*/
  2279. mctx.mode |= SCALAB01; /*JLS 12-01-01*/
  2280. if (subvalue == NULL) /*JLS 12-01-01*/
  2281. { /*JLS 12-01-01*/
  2282. fprintf(stderr, "Error: missing arg scalab01_wait\n");/*JLS 12-01-01*/
  2283. return (-1); /*JLS 12-01-01*/
  2284. } /*JLS 12-01-01*/
  2285. s1ctx.wait = atoi (subvalue); /*JLS 12-01-01*/
  2286. break; /*JLS 12-01-01*/
  2287. case EP_SMOOTH_SHUTDOWN: /*JLS 17-11-00*/
  2288. mctx.mode |= SMOOTHSHUTDOWN; /*JLS 17-11-00*/
  2289. break; /*JLS 17-11-00*/
  2290. case EP_STRING:
  2291. mctx.mode |= STRING;
  2292. break;
  2293. case EP_WITH_NEWPARENT: /*JLS 15-12-00*/
  2294. mctx.mode |= WITH_NEWPARENT; /*JLS 15-12-00*/
  2295. break; /*JLS 15-12-00*/
  2296. case EP_ABANDON:
  2297. mctx.mod2 |= M2_ABANDON;
  2298. break;
  2299. case EP_DEREF:
  2300. mctx.mod2 |= M2_DEREF;
  2301. if (subvalue) {
  2302. /* if -e deref=deref:attr is given, "deref:attr" is set to attrpl */
  2303. mctx.attrpl = strdup (subvalue);
  2304. } else {
  2305. mctx.attrpl = NULL;
  2306. }
  2307. break;
  2308. case EP_SRCH_NENTRIES:
  2309. mctx.srch_nentries = atoi (subvalue);
  2310. break;
  2311. case EP_SAMP_INTERVAL:
  2312. mctx.sampling = atoi (subvalue);
  2313. break;
  2314. case EP_TIMESTAMP:
  2315. if (subvalue) {
  2316. mctx.tsfmt = strdup (subvalue);
  2317. } else {
  2318. mctx.tsfmt = strdup (DEFAULT_TIMESTAMP_FMT);
  2319. }
  2320. break;
  2321. default:
  2322. fprintf (stderr, "Error: illegal option -e %s\n", subvalue);
  2323. return (-1);
  2324. break;
  2325. }
  2326. }
  2327. /*
  2328. * SSL client authentication is only supported in LDAP_V3, because we have
  2329. * to perform a SASL BIND operation in this case, and it is V3 specific
  2330. */
  2331. if ((mctx.mode & LDAP_V2) && (mctx.mode & CLTAUTH))
  2332. {
  2333. fprintf
  2334. (stderr,"Error: SSL client authentication is supported in LDAPv3 only");
  2335. return (-1);
  2336. }
  2337. return (0);
  2338. }
  2339. /* New function */ /*JLS 23-04-01*/
  2340. /* ****************************************************************************
  2341. FUNCTION : buildArgListString
  2342. PURPOSE : Saved the arguments of ldclt into a string.
  2343. INPUT : argc, argv
  2344. OUTPUT : None.
  2345. RETURN : The resulting string.
  2346. DESCRIPTION :
  2347. *****************************************************************************/
  2348. char *
  2349. buildArgListString (
  2350. int argc,
  2351. char **argv)
  2352. {
  2353. char *argvList; /* Arg list */
  2354. int lgth; /* Length of argv list */
  2355. int i; /* For the loops */
  2356. /*
  2357. * Compute the length
  2358. */
  2359. lgth = 0;
  2360. for (i=0 ; i<argc ; i++)
  2361. {
  2362. lgth += strlen (argv[i]) + 1;
  2363. if ((strchr (argv[i], ' ') != NULL) || (strchr (argv[i], '\t') != NULL))
  2364. lgth += 2;
  2365. }
  2366. argvList = (char *) malloc (lgth);
  2367. argvList[0] = '\0';
  2368. strcat (argvList, argv[0]);
  2369. for (i=1 ; i<argc ; i++)
  2370. {
  2371. strcat (argvList, " ");
  2372. if ((strchr (argv[i], ' ') == NULL) && (strchr (argv[i], '\t') == NULL))
  2373. strcat (argvList, argv[i]);
  2374. else
  2375. {
  2376. strcat (argvList, "\"");
  2377. strcat (argvList, argv[i]);
  2378. strcat (argvList, "\"");
  2379. }
  2380. }
  2381. return (argvList);
  2382. }
  2383. /* ****************************************************************************
  2384. FUNCTION : main
  2385. PURPOSE : Main function of ldclt
  2386. INPUT : argc, argv = see man page
  2387. OUTPUT : None.
  2388. RETURN : -1 if error, 0 else.
  2389. DESCRIPTION :
  2390. *****************************************************************************/
  2391. int
  2392. main (
  2393. int argc,
  2394. char **argv)
  2395. {
  2396. int opt_ret; /* For getopt() */
  2397. int i; /* For the loops */
  2398. time_t tim; /* For time() */ /*JLS 18-08-00*/
  2399. char *argvList; /* To keep track in core files */ /*JLS 07-12-00*/
  2400. int found; /* General purpose variable */ /*JLS 18-12-00*/
  2401. char verStr[40]; /* Version string */ /*JLS 13-03-01*/
  2402. PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 0); /* for PR_CallOnce, others */
  2403. /*
  2404. * Build the argv list to keep track of it...
  2405. * Print version.
  2406. * We are using a string variable to keep the version in the core files.
  2407. */
  2408. argvList = buildArgListString (argc, argv); /*JLS 23-04-01*/
  2409. sprintf (verStr, "ldclt version %s", ldcltVersion); /*JLS 13-03-01*/
  2410. printf ("%s\n", verStr); /*JLS 13-03-01*/
  2411. /*
  2412. * Initialization
  2413. */
  2414. mctx.attrlistNb = 0; /*JLS 15-03-01*/
  2415. mctx.attrsonly = DEF_ATTRSONLY; /*JLS 03-01-01*/
  2416. mctx.baseDN = "dc=example,dc=com";
  2417. mctx.baseDNLow = -1; /*JLS 13-11-00*/
  2418. mctx.baseDNHigh = -1; /*JLS 13-11-00*/
  2419. mctx.bindDN = NULL;
  2420. mctx.bindDNLow = -1; /*JLS 05-01-01*/
  2421. mctx.bindDNHigh = -1; /*JLS 05-01-01*/
  2422. mctx.dlf = NULL; /*JLS 23-03-01*/
  2423. mctx.exitStatus = EXIT_OK; /*JLS 25-08-00*/
  2424. mctx.filter = NULL;
  2425. mctx.globStatsCnt = DEF_GLOBAL_NB; /*JLS 08-08-00*/
  2426. mctx.hostname = "localhost";
  2427. mctx.ignErrNb = 0;
  2428. mctx.images = NULL; /*JLS 17-11-00*/
  2429. mctx.imagesDir = DEF_IMAGES_PATH; /*JLS 16-11-00*/
  2430. mctx.inactivMax = DEF_INACTIV_MAX;
  2431. mctx.incr = 1;
  2432. mctx.maxErrors = DEF_MAX_ERRORS;
  2433. mctx.mode = NOTHING;
  2434. mctx.mod2 = NOTHING;
  2435. mctx.nbNoActivity = 0;
  2436. mctx.nbSamples = -1;
  2437. mctx.nbThreads = DEF_NB_THREADS;
  2438. mctx.opListTail = NULL;
  2439. mctx.passwd = NULL;
  2440. mctx.pid = getpid();
  2441. mctx.port = DEF_PORT;
  2442. mctx.randomLow = -1;
  2443. mctx.randomHigh = -1;
  2444. mctx.referral = DEF_REFERRAL; /*JLS 08-03-01*/
  2445. mctx.sampling = DEF_SAMPLING;
  2446. mctx.sasl_authid = NULL;
  2447. mctx.sasl_flags = LDAP_SASL_QUIET;
  2448. mctx.sasl_mech = NULL;
  2449. mctx.sasl_realm = NULL;
  2450. mctx.sasl_secprops = NULL;
  2451. mctx.sasl_username = NULL;
  2452. mctx.scope = DEF_SCOPE;
  2453. mctx.slaveConn = 0;
  2454. mctx.slavesNb = 0;
  2455. mctx.srch_nentries = -1;
  2456. mctx.timeout = DEF_TIMEOUT;
  2457. mctx.totalReq = -1;
  2458. mctx.waitSec = 0;
  2459. s1ctx.cnxduration = SCALAB01_DEF_CNX_DURATION; /*JLS 12-01-01*/
  2460. s1ctx.maxcnxnb = SCALAB01_DEF_MAX_CNX; /*JLS 12-01-01*/
  2461. s1ctx.wait = SCALAB01_DEF_WAIT_TIME; /*JLS 12-01-01*/
  2462. /*
  2463. * Initiates the object *NOW*
  2464. * It is mandatory to do it *NOW* because of -e rdn option.
  2465. */
  2466. mctx.object.attribsNb = 0; /*JLS 23-03-01*/
  2467. mctx.object.rdn = NULL; /*JLS 23-03-01*/
  2468. for (i=0 ; i+VAR_MIN < VAR_MAX ; i++) /*JLS 23-03-01*/
  2469. mctx.object.var[i] = NULL; /*JLS 23-03-01*/
  2470. /*
  2471. * Get options
  2472. */
  2473. while ((opt_ret = getopt (argc, argv,
  2474. "a:b:D:e:E:f:h:i:I:n:N:o:p:qQr:R:s:S:t:T:vVw:W:Z:H")) != EOF)
  2475. switch (opt_ret)
  2476. {
  2477. case 'a':
  2478. mctx.mode |= ASYNC;
  2479. mctx.asyncMax = atoi (optarg);
  2480. mctx.asyncMin = mctx.asyncMax / 2;
  2481. break;
  2482. case 'b':
  2483. mctx.baseDN = optarg;
  2484. break;
  2485. case 'D':
  2486. mctx.bindDN = optarg;
  2487. break;
  2488. case 'e':
  2489. if (decodeExecParams (optarg) < 0)
  2490. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2491. break;
  2492. case 'E':
  2493. mctx.maxErrors = atoi (optarg);
  2494. break;
  2495. case 'f':
  2496. mctx.filter = optarg;
  2497. break;
  2498. case 'h':
  2499. mctx.hostname = optarg;
  2500. break;
  2501. case 'i':
  2502. mctx.inactivMax = atoi (optarg);
  2503. break;
  2504. case 'I':
  2505. found = 0; /*JLS 18-12-00*/
  2506. for (i=0 ; i<mctx.ignErrNb ; i++) /*JLS 18-12-00*/
  2507. if (mctx.ignErr[i] == atoi (optarg)) /*JLS 18-12-00*/
  2508. found = 1; /*JLS 18-12-00*/
  2509. if (found) /*JLS 18-12-00*/
  2510. break; /*JLS 18-12-00*/
  2511. if (mctx.ignErrNb == MAX_IGN_ERRORS)
  2512. {
  2513. fprintf (stderr, "Error: too many errors to ignore.\n");
  2514. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2515. }
  2516. mctx.ignErr[mctx.ignErrNb++] = atoi (optarg);
  2517. break;
  2518. case 'n':
  2519. mctx.nbThreads = atoi (optarg);
  2520. break;
  2521. case 'N':
  2522. mctx.nbSamples = atoi (optarg);
  2523. break;
  2524. case 'o':
  2525. if (saslSetParam (optarg) < 0)
  2526. ldcltExit (EXIT_PARAMS);
  2527. mctx.mod2 |= M2_SASLAUTH;
  2528. break;
  2529. case 'p':
  2530. mctx.port = atoi (optarg);
  2531. break;
  2532. case 'P':
  2533. masterPort = atoi (optarg);
  2534. break;
  2535. case 'q':
  2536. mctx.mode |= QUIET;
  2537. break;
  2538. case 'Q':
  2539. mctx.mode |= QUIET;
  2540. mctx.mode |= SUPER_QUIET;
  2541. break;
  2542. case 'r':
  2543. mctx.randomLow = atoi (optarg);
  2544. break;
  2545. case 'R':
  2546. mctx.randomHigh = atoi (optarg);
  2547. break;
  2548. case 's':
  2549. if (decodeScopeParams (optarg) < 0)
  2550. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2551. break;
  2552. case 't':
  2553. mctx.timeout = atoi (optarg);
  2554. break;
  2555. case 'S':
  2556. mctx.slaves[mctx.slavesNb] = optarg;
  2557. mctx.slavesNb++;
  2558. break;
  2559. case 'T':
  2560. mctx.totalReq = atoi (optarg);
  2561. break;
  2562. case 'v':
  2563. mctx.mode |= VERBOSE;
  2564. break;
  2565. case 'V':
  2566. mctx.mode |= VERBOSE;
  2567. mctx.mode |= VERY_VERBOSE;
  2568. break;
  2569. case 'w':
  2570. mctx.passwd = optarg;
  2571. break;
  2572. case 'W':
  2573. mctx.waitSec = atoi (optarg);
  2574. break;
  2575. case 'Z':
  2576. mctx.mode |= SSL;
  2577. mctx.certfile = optarg;
  2578. break;
  2579. case 'H':
  2580. usage ();
  2581. ldcltExit (EXIT_OK); /*JLS 18-12-00*/
  2582. break;
  2583. case '?':
  2584. usage ();
  2585. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2586. break;
  2587. }
  2588. /*
  2589. * It should not be any extra argument.
  2590. */
  2591. if (optind != argc) /*JLS 23-04-01*/
  2592. { /*JLS 23-04-01*/
  2593. fprintf (stderr, "Error: unexpected extra arguments.\n"); /*JLS 23-04-01*/
  2594. ldcltExit (EXIT_PARAMS); /*JLS 23-04-01*/
  2595. } /*JLS 23-04-01*/
  2596. /*
  2597. * If scalab01 is set, then some other features are automatically enabled.
  2598. */
  2599. if (mctx.mode & SCALAB01) /*JLS 08-01-01*/
  2600. { /*JLS 08-01-01*/
  2601. mctx.mode |= BIND_EACH_OPER; /*JLS 08-01-01*/
  2602. mctx.mode |= RANDOM_BINDDN; /*JLS 08-01-01*/
  2603. } /*JLS 08-01-01*/
  2604. /*
  2605. * Check coherency
  2606. */
  2607. if (mctx.nbThreads <= 0)
  2608. {
  2609. fprintf (stderr, "Error: it must be at least 1 thread, not \"%d\"\n",
  2610. mctx.nbThreads);
  2611. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2612. }
  2613. if (mctx.nbThreads > MAX_THREADS)
  2614. {
  2615. fprintf (stderr, "Error: too many threads %d, maximum is %d\n",
  2616. mctx.nbThreads, MAX_THREADS);
  2617. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2618. }
  2619. if ((!(mctx.mode & VALID_OPERS)) &&
  2620. (!(mctx.mod2 & M2_VALID_OPERS))) /*JLS 04-05-01*/
  2621. {
  2622. fprintf (stderr, "Error: don't know what to do...\n");
  2623. fprintf (stderr, "Error: please use option -e for this purpose.\n");
  2624. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2625. }
  2626. if ((mctx.mod2 & M2_APPEND) && (!(mctx.mod2 & M2_GENLDIF))) /*JLS 05-04-01*/
  2627. { /*JLS 05-04-01*/
  2628. fprintf (stderr, "Error: -e append requires -e genldif.\n");/*JLS 05-04-01*/
  2629. ldcltExit (EXIT_PARAMS); /*JLS 05-04-01*/
  2630. } /*JLS 05-04-01*/
  2631. if ((mctx.filter != NULL) && (mctx.mod2 & M2_RDN_VALUE)) /*JLS 23-03-01*/
  2632. { /*JLS 23-03-01*/
  2633. fprintf (stderr, "Error: -f and -e rdn= are exclusive.\n"); /*JLS 23-03-01*/
  2634. ldcltExit (EXIT_PARAMS); /*JLS 23-03-01*/
  2635. } /*JLS 23-03-01*/
  2636. if ((mctx.mod2 & M2_RDN_VALUE) && (mctx.mode & RANDOM)) /*JLS 28-03-01*/
  2637. { /*JLS 28-03-01*/
  2638. fprintf (stderr, "Error: exclusive -e random and -e rdn\n");/*JLS 28-03-01*/
  2639. ldcltExit (EXIT_PARAMS); /*JLS 28-03-01*/
  2640. } /*JLS 28-03-01*/
  2641. if ((mctx.mod2 & M2_RDN_VALUE) && (mctx.mode & INCREMENTAL)) /*JLS 28-03-01*/
  2642. { /*JLS 28-03-01*/
  2643. fprintf (stderr, "Error: exclusive -e incr and -e rdn\n"); /*JLS 28-03-01*/
  2644. ldcltExit (EXIT_PARAMS); /*JLS 28-03-01*/
  2645. } /*JLS 28-03-01*/
  2646. if ((mctx.mode & NEED_FILTER) &&
  2647. ((mctx.filter == NULL) && (!(mctx.mod2 & M2_RDN_VALUE)))) /*JLS 23-03-01*/
  2648. {
  2649. fprintf (stderr, "Error: missing filter...\n");
  2650. fprintf (stderr, "Error: use -f or -e rdn=value for this purpose.\n");
  2651. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2652. }
  2653. if ((!((mctx.mode & NEED_FILTER) || (mctx.mod2 & M2_GENLDIF) ||
  2654. (mctx.mod2 & M2_NEED_FILTER)))/*JLS 04-05-01*/
  2655. && (mctx.filter != NULL)) /*JLS 04-05-01*/
  2656. { /*JLS 04-05-01*/
  2657. fprintf (stderr, "Error: do not need filter -f\n"); /*JLS 04-05-01*/
  2658. ldcltExit (EXIT_PARAMS); /*JLS 04-05-01*/
  2659. } /*JLS 04-05-01*/
  2660. if ((!((mctx.mode & NEED_FILTER) || (mctx.mod2 & M2_GENLDIF)))/*JLS 04-05-01*/
  2661. && (mctx.mod2 & M2_RDN_VALUE)) /*JLS 04-05-01*/
  2662. { /*JLS 04-05-01*/
  2663. fprintf (stderr, "Error: do not need -e rdn=value\n"); /*JLS 04-05-01*/
  2664. ldcltExit (EXIT_PARAMS); /*JLS 04-05-01*/
  2665. } /*JLS 04-05-01*/
  2666. if ((mctx.mod2 & M2_RDN_VALUE) && /*JLS 28-03-01*/
  2667. ((mctx.randomLow >= 0) || (mctx.randomHigh > 0))) /*JLS 28-03-01*/
  2668. { /*JLS 28-03-01*/
  2669. fprintf (stderr, "Error: -e rdn exclusive with -r or -R\n");/*JLS 28-03-01*/
  2670. ldcltExit (EXIT_PARAMS); /*JLS 28-03-01*/
  2671. } /*JLS 28-03-01*/
  2672. if (mctx.mode & NEED_RANGE) /*JLS 28-03-01*/
  2673. { /*JLS 28-03-01*/
  2674. if (((mctx.randomLow >= 0) && (mctx.randomHigh < 0)) ||
  2675. ((mctx.randomLow < 0) && (mctx.randomHigh > 0)) ||
  2676. (mctx.randomLow > mctx.randomHigh))
  2677. {
  2678. fprintf (stderr, "Error: invalid random levels %d and %d\n",
  2679. mctx.randomLow, mctx.randomHigh);
  2680. fprintf (stderr, "Error: use both options -r and -R for this purpose.\n");
  2681. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2682. }
  2683. if ((mctx.randomLow < 0) && (mctx.randomHigh < 0)) /*JLS 28-03-01*/
  2684. {
  2685. fprintf (stderr, "Error: missing values range.\n");
  2686. fprintf (stderr, "Error: use both options -r and -R for this purpose.\n");
  2687. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2688. }
  2689. } /*JLS 28-03-01*/
  2690. if (mctx.inactivMax < 0)
  2691. {
  2692. fprintf (stderr, "Error: max times inactivity should not be negative.\n");
  2693. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2694. }
  2695. if (mctx.maxErrors < 0)
  2696. {
  2697. fprintf (stderr, "Error: max allowed errors should not be negative.\n");
  2698. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2699. }
  2700. if ((mctx.mode & INCREMENTAL) && (mctx.mode & RANDOM))
  2701. {
  2702. fprintf (stderr, "Error: modes -e incr and -e random are exclusive.\n");
  2703. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2704. }
  2705. if ((mctx.mode & NOLOOP) && (!(mctx.mode & INCREMENTAL)))
  2706. {
  2707. fprintf (stderr, "Error: mode -e noloop requires mode -e incr.\n");
  2708. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2709. }
  2710. if ((mctx.mode & NEED_RND_INCR) &&
  2711. (!((mctx.mode & (RANDOM|INCREMENTAL)) || (mctx.mod2 & M2_RDN_VALUE))))
  2712. {
  2713. fprintf (stderr, "Error: -e add requires either -e incr/random/rdn\n");
  2714. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2715. }
  2716. if (mctx.filter != NULL) /*JLS 07-12-00*/
  2717. { /*JLS 07-12-00*/
  2718. for (i=0 ; (mctx.filter[i] != '\0') && (mctx.filter[i] != '=') ; i++);
  2719. if (mctx.filter[i] != '=')
  2720. {
  2721. fprintf (stderr, "Error: filter must be \"attrib=value\", not \"%s\"\n",
  2722. mctx.filter);
  2723. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2724. }
  2725. } /*JLS 07-12-00*/
  2726. if ((mctx.mode & NEED_CLASSES) &&
  2727. (!((mctx.mode & THE_CLASSES) || (mctx.mod2 & M2_OBJECT))))
  2728. {
  2729. fprintf (stderr, "Error: missing classes (option -e)\n");
  2730. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2731. }
  2732. if ((mctx.mode & STRING) && (!(mctx.mode & RANDOM)))
  2733. {
  2734. fprintf (stderr, "Error: -e string is only valid with -e random.\n");
  2735. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2736. }
  2737. if (mctx.waitSec < 0)
  2738. {
  2739. fprintf (stderr, "Error: -W should have a positive value.\n");
  2740. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2741. }
  2742. if ((mctx.mode & RANDOM_BASE) && /*JLS 13-11-00*/
  2743. ((mctx.baseDNLow < 0) || (mctx.baseDNHigh < 0))) /*JLS 13-11-00*/
  2744. { /*JLS 13-11-00*/
  2745. fprintf (stderr, "Error: missing ranges for randombase.\n");/*JLS 13-11-00*/
  2746. fprintf (stderr, "Error: use option -e randombaselow=\n"); /*JLS 13-11-00*/
  2747. fprintf (stderr, "Error: use option -e randombasehigh=\n"); /*JLS 13-11-00*/
  2748. ldcltExit (EXIT_PARAMS); /*JLS 13-11-00*/
  2749. } /*JLS 13-11-00*/
  2750. if ((mctx.mod2 & M2_RNDBINDFILE) && /*JLS 03-05-01*/
  2751. (mctx.mode & RANDOM_BINDDN)) /*JLS 03-05-01*/
  2752. { /*JLS 03-05-01*/
  2753. fprintf (stderr, /*JLS 03-05-01*/
  2754. "Error : exclusive -e randombinddn and -e randombinddnfromfile\n");
  2755. ldcltExit (EXIT_PARAMS); /*JLS 03-05-01*/
  2756. } /*JLS 03-05-01*/
  2757. if ((mctx.mode & RANDOM_BINDDN) && /*JLS 05-01-01*/
  2758. ((mctx.bindDNLow < 0) || (mctx.bindDNHigh < 0))) /*JLS 05-01-01*/
  2759. { /*JLS 05-01-01*/
  2760. fprintf(stderr,"Error: missing ranges for randombinddn.\n");/*JLS 05-01-01*/
  2761. fprintf(stderr,"Error: use option -e randombinddnlow=\n"); /*JLS 05-01-01*/
  2762. fprintf(stderr,"Error: use option -e randombinddnhigh=\n"); /*JLS 05-01-01*/
  2763. ldcltExit (EXIT_PARAMS); /*JLS 05-01-01*/
  2764. } /*JLS 05-01-01*/
  2765. if ((mctx.mod2 & M2_RANDOM_SASLAUTHID) &&
  2766. ((mctx.sasl_authid_low < 0) || (mctx.sasl_authid_high < 0)))
  2767. {
  2768. fprintf(stderr,"Error: missing ranges for randomauthid.\n");
  2769. fprintf(stderr,"Error: use option -e randomauthidlow=\n");
  2770. fprintf(stderr,"Error: use option -e randomauthidhigh=\n");
  2771. ldcltExit (EXIT_PARAMS); /*JLS 05-01-01*/
  2772. } /*JLS 05-01-01*/
  2773. if (mctx.mode & CLTAUTH) /* BK 23-11-00*/
  2774. { /* BK 23-11-00*/
  2775. if (!(mctx.mode & SSL)) /* BK 23-11-00*/
  2776. { /* BK 23-11-00*/
  2777. fprintf (stderr, "Error: no certificate DB specified.\n");/* BK 23-11-00*/
  2778. fprintf (stderr, "Error: use -Z certfile.\n"); /* BK 23-11-00*/
  2779. ldcltExit (EXIT_PARAMS); /* BK 23-11-00*/
  2780. } /* BK 23-11-00*/
  2781. if (mctx.cltcertname == NULL) /* BK 23-11-00*/
  2782. { /* BK 23-11-00*/
  2783. fprintf (stderr, "Error: no client certificate name specified.\n");
  2784. /* BK 23-11-00*/
  2785. fprintf (stderr, "Error: use option -e cltcertname=\n"); /* BK 23-11-00*/
  2786. ldcltExit (EXIT_PARAMS); /* BK 23-11-00*/
  2787. } /* BK 23-11-00*/
  2788. if (mctx.keydbfile == NULL) /* BK 23-11-00*/
  2789. { /* BK 23-11-00*/
  2790. fprintf (stderr, "Error: no key database file specified.\n");
  2791. /* BK 23-11-00*/
  2792. fprintf (stderr, "Error: use option -e keydbfile=\n"); /* BK 23-11-00*/
  2793. ldcltExit (EXIT_PARAMS); /* BK 23-11-00*/
  2794. } /* BK 23-11-00*/
  2795. if (mctx.keydbpin == NULL) /* BK 23-11-00*/
  2796. { /* BK 23-11-00*/
  2797. fprintf (stderr, "Error: no key database password specified.\n");
  2798. /* BK 23-11-00*/
  2799. fprintf (stderr, "Error: use option -e keydbpin=\n"); /* BK 23-11-00*/
  2800. ldcltExit (EXIT_PARAMS); /* BK 23-11-00*/
  2801. } /* BK 23-11-00*/
  2802. }
  2803. if ((mctx.mode & WITH_NEWPARENT) && /*JLS 15-12-00*/
  2804. (!(mctx.mode & RENAME_ENTRIES))) /*JLS 15-12-00*/
  2805. { /*JLS 15-12-00*/
  2806. fprintf (stderr, "Error : option -e withnewparent needs -e rename\n");
  2807. ldcltExit (EXIT_PARAMS); /*JLS 15-12-00*/
  2808. } /*JLS 15-12-00*/
  2809. if ((mctx.attrsonly != 0) && (mctx.attrsonly != 1)) /*JLS 03-01-01*/
  2810. { /*JLS 03-01-01*/
  2811. fprintf (stderr, "Error : option -e attrsonly=%d not 0|1\n",/*JLS 03-01-01*/
  2812. mctx.attrsonly); /*JLS 03-01-01*/
  2813. ldcltExit (EXIT_PARAMS); /*JLS 03-01-01*/
  2814. } /*JLS 03-01-01*/
  2815. if (mctx.mode & SCALAB01) /*JLS 12-01-01*/
  2816. { /*JLS 12-01-01*/
  2817. if (s1ctx.cnxduration <= 0) /*JLS 12-01-01*/
  2818. { /*JLS 12-01-01*/
  2819. fprintf (stderr, "Error : -e scalab01_cnxduration=%d <= 0\n",
  2820. s1ctx.cnxduration); /*JLS 12-01-01*/
  2821. ldcltExit (EXIT_PARAMS); /*JLS 12-01-01*/
  2822. } /*JLS 12-01-01*/
  2823. if (s1ctx.maxcnxnb <= 0) /*JLS 12-01-01*/
  2824. { /*JLS 12-01-01*/
  2825. fprintf (stderr, "Error : -e scalab01_maxcnxnb=%d <= 0\n",/*JLS 12-01-01*/
  2826. s1ctx.maxcnxnb); /*JLS 12-01-01*/
  2827. ldcltExit (EXIT_PARAMS); /*JLS 12-01-01*/
  2828. } /*JLS 12-01-01*/
  2829. if (s1ctx.wait <= 0) /*JLS 12-01-01*/
  2830. { /*JLS 12-01-01*/
  2831. fprintf (stderr, "Error : -e scalab01_wait=%d <= 0\n", /*JLS 12-01-01*/
  2832. s1ctx.wait); /*JLS 12-01-01*/
  2833. ldcltExit (EXIT_PARAMS); /*JLS 12-01-01*/
  2834. } /*JLS 12-01-01*/
  2835. } /*JLS 12-01-01*/
  2836. if ((mctx.referral == REFERRAL_REBIND) && /*JLS 14-03-01*/
  2837. ((mctx.bindDN == NULL) || (mctx.passwd == NULL))) /*JLS 14-03-01*/
  2838. { /*JLS 14-03-01*/
  2839. fprintf (stderr, "Error: -e referral=rebind needs -D and -w\n");/*14-03-01*/
  2840. ldcltExit (EXIT_PARAMS); /*JLS 14-03-01*/
  2841. } /*JLS 14-03-01*/
  2842. if ((mctx.mode & COMMON_COUNTER) && /*JLS 14-03-01*/
  2843. (!((mctx.mode & INCREMENTAL) || (mctx.mod2 & M2_OBJECT))))/*JLS 28-03-01*/
  2844. { /*JLS 14-03-01*/
  2845. fprintf (stderr, "Error: -e commoncounter needs -e incr or -e object\n");
  2846. ldcltExit (EXIT_PARAMS); /*JLS 14-03-01*/
  2847. } /*JLS 14-03-01*/
  2848. if ((mctx.attrlistNb != 0) && (!(mctx.mode & EXACT_SEARCH))) /*JLS 15-03-01*/
  2849. { /*JLS 15-03-01*/
  2850. fprintf(stderr,"Error : -e attrlist requires -e esearch\n");/*JLS 15-03-01*/
  2851. ldcltExit (EXIT_PARAMS); /*JLS 15-03-01*/
  2852. } /*JLS 15-03-01*/
  2853. if ((mctx.mod2 & M2_GENLDIF) && (mctx.mode & VALID_OPERS)) /*JLS 19-03-01*/
  2854. { /*JLS 19-03-01*/
  2855. fprintf(stderr,"Error : -e genldif is exclusive.\n"); /*JLS 19-03-01*/
  2856. ldcltExit (EXIT_PARAMS); /*JLS 19-03-01*/
  2857. } /*JLS 19-03-01*/
  2858. if ((mctx.mod2 & M2_RDN_VALUE) && (!(mctx.mod2 & M2_OBJECT))) /*JLS 23-03-01*/
  2859. { /*JLS 23-03-01*/
  2860. fprintf(stderr,"Error : -e rdn needs -e object.\n"); /*JLS 23-03-01*/
  2861. ldcltExit (EXIT_PARAMS); /*JLS 23-03-01*/
  2862. } /*JLS 23-03-01*/
  2863. /*
  2864. * Basic initialization from the user's parameters/options
  2865. */
  2866. if (basicInit() < 0)
  2867. ldcltExit (EXIT_INIT); /*JLS 18-12-00*/
  2868. /*
  2869. * What are we doing now...
  2870. */
  2871. if (mctx.mode & VERBOSE)
  2872. {
  2873. printf ("%s\n", argvList); /*JLS 07-12-00*/
  2874. printf ("Process ID = %d\n", mctx.pid);
  2875. printf ("Host to connect = %s\n", mctx.hostname);
  2876. printf ("Port number = %d\n", mctx.port);
  2877. if (mctx.bindDN == NULL)
  2878. printf ("Bind DN = NULL\n");
  2879. else
  2880. printf ("Bind DN = %s\n", mctx.bindDN);
  2881. if (mctx.passwd == NULL)
  2882. printf ("Passwd = NULL\n");
  2883. else
  2884. printf ("Passwd = %s\n", mctx.passwd);
  2885. switch (mctx.referral) /*JLS 08-03-01*/
  2886. { /*JLS 08-03-01*/
  2887. case REFERRAL_OFF: /*JLS 08-03-01*/
  2888. printf ("Referral = off\n"); /*JLS 08-03-01*/
  2889. break; /*JLS 08-03-01*/
  2890. case REFERRAL_ON: /*JLS 08-03-01*/
  2891. printf ("Referral = on\n"); /*JLS 08-03-01*/
  2892. break; /*JLS 08-03-01*/
  2893. case REFERRAL_REBIND: /*JLS 08-03-01*/
  2894. printf ("Referral = rebind\n"); /*JLS 08-03-01*/
  2895. break; /*JLS 08-03-01*/
  2896. } /*JLS 08-03-01*/
  2897. printf ("Base DN = %s\n", mctx.baseDN);
  2898. if (mctx.filter == NULL)
  2899. printf ("Filter = NULL\n");
  2900. else
  2901. printf ("Filter = \"%s\"\n", mctx.filter);
  2902. if (mctx.attrlistNb > 0) /*JLS 15-03-01*/
  2903. { /*JLS 15-03-01*/
  2904. printf ("Attributes list ="); /*JLS 15-03-01*/
  2905. for (i=0 ; i<mctx.attrlistNb ; i++) /*JLS 15-03-01*/
  2906. printf (" %s", mctx.attrlist[i]); /*JLS 15-03-01*/
  2907. printf ("\n"); /*JLS 15-03-01*/
  2908. } /*JLS 15-03-01*/
  2909. printf ("Max times inactive = %d\n", mctx.inactivMax);
  2910. printf ("Max allowed errors = %d\n", mctx.maxErrors);
  2911. printf ("Number of samples = %d\n", mctx.nbSamples);
  2912. printf ("Number of threads = %d\n", mctx.nbThreads);
  2913. printf ("Total op. req. = %d\n", mctx.totalReq);
  2914. printf ("Running mode = 0x%08x\n", mctx.mode);
  2915. printf ("Running mode =");
  2916. dumpModeValues (); /*JLS 19-03-01*/
  2917. printf ("\n");
  2918. if (mctx.mode & SCALAB01) /*JLS 12-01-01*/
  2919. { /*JLS 12-01-01*/
  2920. printf("Scalab01 cnx dur. = %d sec\n",s1ctx.cnxduration);/*JLS 12-01-01*/
  2921. printf ("Scalab01 max nb cnx= %d\n", s1ctx.maxcnxnb); /*JLS 12-01-01*/
  2922. printf ("Scalab01 wait time = %d sec\n", s1ctx.wait); /*JLS 12-01-01*/
  2923. } /*JLS 12-01-01*/
  2924. printf ("LDAP oper. timeout = %d sec\n", mctx.timeout);
  2925. printf ("Sampling interval = %d sec\n", mctx.sampling);
  2926. if (mctx.mode & EXACT_SEARCH)
  2927. { /*JLS 03-01-01*/
  2928. switch (mctx.scope)
  2929. {
  2930. case LDAP_SCOPE_BASE:
  2931. printf ("Scope = base\n");
  2932. break;
  2933. case LDAP_SCOPE_ONELEVEL:
  2934. printf ("Scope = one level\n");
  2935. break;
  2936. case LDAP_SCOPE_SUBTREE:
  2937. printf ("Scope = subtree\n");
  2938. break;
  2939. }
  2940. printf ("Attrsonly = %d\n", mctx.attrsonly); /*JLS 03-01-01*/
  2941. } /*JLS 03-01-01*/
  2942. if (mctx.images != NULL) /*JLS 17-11-00*/
  2943. printf ("Images directory = %s\n", mctx.imagesDir); /*JLS 17-11-00*/
  2944. if ((mctx.mode & NEED_RANGE) && (mctx.randomLow >= 0)) /*JLS 28-03-01*/
  2945. printf ("Values range = [%d , %d]\n",
  2946. mctx.randomLow, mctx.randomHigh);
  2947. if ((mctx.mode & (RANDOM | INCREMENTAL)) &&
  2948. (!(mctx.mod2 & M2_RDN_VALUE))) /*JLS 23-03-01*/
  2949. {
  2950. printf ("Filter's head = \"%s\"\n", mctx.randomHead);
  2951. printf ("Filter's tail = \"%s\"\n", mctx.randomTail);
  2952. }
  2953. if (mctx.mode & RANDOM_BASE)
  2954. {
  2955. printf ("Base DN's head = \"%s\"\n", mctx.baseDNHead);
  2956. printf ("Base DN's tail = \"%s\"\n", mctx.baseDNTail);
  2957. printf ("Base DN's range = [%d , %d]\n", /*JLS 13-11-00*/
  2958. mctx.baseDNLow, mctx.baseDNHigh); /*JLS 13-11-00*/
  2959. }
  2960. if (mctx.mode & RANDOM_BINDDN) /*JLS 05-01-01*/
  2961. { /*JLS 05-01-01*/
  2962. printf ("Bind DN's head = \"%s\"\n", mctx.bindDNHead);/*JLS 05-01-01*/
  2963. printf ("Bind DN's tail = \"%s\"\n", mctx.bindDNTail);/*JLS 05-01-01*/
  2964. printf ("Bind DN's range = [%d , %d]\n", /*JLS 05-01-01*/
  2965. mctx.bindDNLow, mctx.bindDNHigh); /*JLS 05-01-01*/
  2966. printf ("Bind passwd's head = \"%s\"\n", mctx.passwdHead);/*JLS 05-01-01*/
  2967. printf ("Bind passwd's tail = \"%s\"\n", mctx.passwdTail);/*JLS 05-01-01*/
  2968. } /*JLS 05-01-01*/
  2969. if (mctx.mod2 & M2_RANDOM_SASLAUTHID)
  2970. { /*JLS 05-01-01*/
  2971. printf ("Bind Authid's head = \"%s\"\n", mctx.sasl_authid_head);
  2972. printf ("Bind Authid's tail = \"%s\"\n", mctx.sasl_authid_tail);
  2973. printf ("Bind Authid's range = [%d , %d]\n",
  2974. mctx.sasl_authid_low, mctx.sasl_authid_high);
  2975. } /*JLS 05-01-01*/
  2976. if (mctx.mode & ATTR_REPLACE) /*JLS 21-11-00*/
  2977. { /*JLS 21-11-00*/
  2978. printf ("Attribute's head = \"%s\"\n", mctx.attrplHead);/*JLS 21-11-00*/
  2979. printf ("Attribute's tail = \"%s\"\n", mctx.attrplTail);/*JLS 21-11-00*/
  2980. } /*JLS 21-11-00*/
  2981. if (mctx.mod2 & M2_ATTR_REPLACE_FILE)
  2982. {
  2983. printf ("Attribute to replace = \"%s\"\n", mctx.attrplName);
  2984. printf ("Attribute value file = \"%s\"\n", mctx.attrplFile);
  2985. }
  2986. if (mctx.mod2 & M2_DEREF)
  2987. {
  2988. printf (" Referenced Attribute = \"%s\"\n", mctx.attRef);
  2989. printf ("Dereferenced Attribute = \"%s\"\n", mctx.attRefDef);
  2990. }
  2991. if (mctx.mode & ASYNC)
  2992. {
  2993. printf ("Async max pending = %d\n", mctx.asyncMax);
  2994. printf ("Async min pending = %d\n", mctx.asyncMin);
  2995. }
  2996. for (i=0 ; i<mctx.ignErrNb ; i++)
  2997. printf ("Ignore error = %d (%s)\n",
  2998. mctx.ignErr[i], my_ldap_err2string (mctx.ignErr[i]));
  2999. fflush (stdout);
  3000. if (mctx.slavesNb > 0)
  3001. {
  3002. printf ("Slave(s) to check =");
  3003. for (i=0 ; i<mctx.slavesNb ; i++)
  3004. printf (" %s", mctx.slaves[i]);
  3005. printf ("\n");
  3006. }
  3007. }
  3008. /*
  3009. * Let's go!
  3010. */
  3011. tim = time(NULL);
  3012. printf ("ldclt[%d]: Starting at %s\n", mctx.pid, ctime (&tim)); /*JLS 18-08-00*/
  3013. if (runThem() < 0)
  3014. ldcltExit (EXIT_OTHER); /*JLS 25-08-00*/
  3015. if (initMainThread() < 0)
  3016. ldcltExit (EXIT_OTHER); /*JLS 25-08-00*/
  3017. if (monitorThem() < 0)
  3018. ldcltExit (EXIT_OTHER); /*JLS 25-08-00*/
  3019. if (printGlobalStatistics() < 0)
  3020. ldcltExit (EXIT_OTHER); /*JLS 25-08-00*/
  3021. ldcltExit (mctx.exitStatus); /*JLS 25-08-00*/
  3022. return mctx.exitStatus;
  3023. }
  3024. /* End of file */