1
0

ldclt.c 102 KB

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