ldclt.c 108 KB

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