ldclt.c 105 KB

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