1
0

ldclt.c 107 KB

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