ldclt.c 93 KB

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