plugin.c 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* plugin.c - routines for setting up and calling plugins */
  13. #include <stddef.h>
  14. #include <stdio.h>
  15. #include <plhash.h>
  16. #include "slap.h"
  17. /* this defines are used for plugin configuration */
  18. #define LOCAL_DATA "local data"
  19. #define REMOTE_DATA "remote data"
  20. #define ALL_DATA "*"
  21. #define ROOT_BIND "directory manager"
  22. #define ANONYMOUS_BIND "anonymous"
  23. /* dependency checking flags */
  24. #define CHECK_ALL 0
  25. #define CHECK_TYPE 1
  26. /* plugin removal flags */
  27. #define PLUGIN_NOT_FOUND 0
  28. #define PLUGIN_REMOVED 1
  29. #define PLUGIN_BUSY 2
  30. static char *critical_plugins[] = { "cn=ldbm database,cn=plugins,cn=config",
  31. "cn=ACL Plugin,cn=plugins,cn=config",
  32. "cn=ACL preoperation,cn=plugins,cn=config",
  33. "cn=chaining database,cn=plugins,cn=config",
  34. "cn=Multimaster Replication Plugin,cn=plugins,cn=config",
  35. NULL };
  36. /* Forward Declarations */
  37. static int plugin_call_list (struct slapdplugin *list, int operation, Slapi_PBlock *pb);
  38. static int plugin_call_one (struct slapdplugin *list, int operation, Slapi_PBlock *pb);
  39. static int plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int call_one);
  40. static PRBool plugin_invoke_plugin_pb (struct slapdplugin *plugin, int operation, Slapi_PBlock *pb);
  41. static PRBool plugin_matches_operation (Slapi_DN *target_spec, PluginTargetData *ptd,
  42. PRBool bindop, PRBool isroot, PRBool islocal, ber_tag_t method);
  43. static void plugin_config_init (struct pluginconfig *config);
  44. static void plugin_config_cleanup (struct pluginconfig *config);
  45. static int plugin_config_set_action (int *action, char *value);
  46. static struct pluginconfig* plugin_get_config (struct slapdplugin *plugin);
  47. static void default_plugin_init();
  48. static void ptd_init (PluginTargetData *ptd);
  49. static void ptd_cleanup (PluginTargetData *ptd);
  50. static void ptd_add_subtree (PluginTargetData *ptd, Slapi_DN *subtree);
  51. static void ptd_set_special_data (PluginTargetData *ptd, int type);
  52. static Slapi_DN *ptd_get_first_subtree (const PluginTargetData *ptd, int *cookie);
  53. static Slapi_DN *ptd_get_next_subtree (const PluginTargetData *ptd, int *cookie);
  54. static PRBool ptd_is_special_data_set (const PluginTargetData *ptd, int type);
  55. int ptd_get_subtree_count (const PluginTargetData *ptd);
  56. static void plugin_set_global (PluginTargetData *ptd);
  57. static PRBool plugin_is_global (const PluginTargetData *ptd);
  58. static void plugin_set_default_access (struct pluginconfig *config);
  59. static int plugin_delete_check_dependency(struct slapdplugin *plugin_entry, int flag, char *returntext);
  60. static char *plugin_get_type_str( int type );
  61. static void plugin_cleanup_list();
  62. static int plugin_remove_plugins(struct slapdplugin *plugin_entry, char *plugin_type);
  63. static void plugin_remove_from_shutdown(struct slapdplugin *plugin_entry);
  64. static void plugin_free(struct slapdplugin *plugin);
  65. static PLHashTable *global_plugin_dns = NULL;
  66. /* The global plugin list is indexed by the PLUGIN_LIST_* constants defined in slap.h */
  67. static struct slapdplugin *global_plugin_list[PLUGIN_LIST_GLOBAL_MAX];
  68. /* plugin structure used to configure internal operation issued by the core server */
  69. static int global_server_plg_initialised = 0;
  70. struct slapdplugin global_server_plg;
  71. /* plugin structure used to configure internal operation issued by the core server */
  72. static int global_server_plg_id_initialised = 0;
  73. struct slapi_componentid global_server_id_plg;
  74. /* plugin structure used to configure operations issued by the old plugins that
  75. do not pass their identity in the operation */
  76. static struct slapdplugin global_default_plg;
  77. /* Enable/disable plugin callbacks for clean startup */
  78. static int global_plugin_callbacks_enabled = 0;
  79. static Slapi_RWLock *global_rwlock = NULL;
  80. void
  81. global_plugin_init()
  82. {
  83. if((global_rwlock = slapi_new_rwlock()) == NULL){
  84. slapi_log_error( SLAPI_LOG_FATAL, "startup", "Failed to create global plugin rwlock.\n" );
  85. exit (1);
  86. }
  87. }
  88. static void
  89. add_plugin_to_list(struct slapdplugin **list, struct slapdplugin *plugin)
  90. {
  91. struct slapdplugin **tmp;
  92. struct slapdplugin *last = NULL;
  93. int plugin_added = 0;
  94. /* Insert the plugin into list based off of precedence. */
  95. for ( tmp = list; *tmp; tmp = &(*tmp)->plg_next )
  96. {
  97. if (plugin->plg_precedence < (*tmp)->plg_precedence)
  98. {
  99. if (last)
  100. {
  101. /* Insert item between last and tmp. */
  102. plugin->plg_next = *tmp;
  103. last->plg_next = plugin;
  104. } else {
  105. /* Add as the first list item. */
  106. plugin->plg_next = *tmp;
  107. *list = plugin;
  108. }
  109. plugin_added = 1;
  110. /* We've added the plug-in to the
  111. * list, so bail from the loop. */
  112. break;
  113. }
  114. /* Save a pointer to this plugin so we can
  115. * refer to it on the next loop iteration. */
  116. last = *tmp;
  117. }
  118. /* If we didn't add the plug-in to the list yet,
  119. * it needs to be added to the end of the list. */
  120. if (!plugin_added)
  121. {
  122. *tmp = plugin;
  123. }
  124. }
  125. struct slapdplugin *
  126. get_plugin_list(int plugin_list_index)
  127. {
  128. return global_plugin_list[plugin_list_index];
  129. }
  130. /*
  131. * As the plugin configuration information is read an array of
  132. * entries is built which reflect the plugins. The entries
  133. * are added after the syntax plugins are started so that the
  134. * nodes in the attribute tree are initialised correctly.
  135. */
  136. typedef struct entry_and_plugin {
  137. Slapi_Entry *e;
  138. struct slapdplugin *plugin;
  139. struct entry_and_plugin *next;
  140. } entry_and_plugin_t;
  141. static entry_and_plugin_t *dep_plugin_entries = NULL; /* for dependencies */
  142. #if 0
  143. static entry_and_plugin_t *plugin_entries = NULL;
  144. static void
  145. add_plugin_entries()
  146. {
  147. entry_and_plugin_t *ep = plugin_entries;
  148. entry_and_plugin_t *deleteep = 0;
  149. while (ep)
  150. {
  151. int plugin_actions = 0;
  152. Slapi_PBlock newpb;
  153. pblock_init(&newpb);
  154. slapi_add_entry_internal_set_pb(&newpb, ep->e, NULL,
  155. ep->plugin, plugin_actions);
  156. slapi_pblock_set(&newpb, SLAPI_TARGET_DN, (void*)slapi_entry_get_dn_const(ep->e));
  157. slapi_pblock_set(&newpb, SLAPI_TARGET_SDN, (void*)slapi_entry_get_sdn_const(ep->e));
  158. slapi_add_internal_pb(&newpb);
  159. deleteep = ep;
  160. ep = ep->next;
  161. slapi_ch_free((void**)&deleteep);
  162. pblock_done(&newpb);
  163. }
  164. plugin_entries = NULL;
  165. }
  166. #endif
  167. static int
  168. plugin_is_critical(Slapi_Entry *plugin_entry)
  169. {
  170. char *plugin_dn = NULL;
  171. int i;
  172. plugin_dn = slapi_entry_get_ndn(plugin_entry);
  173. for( i = 0; critical_plugins[i]; i++){
  174. if(strcasecmp(plugin_dn, critical_plugins[i]) == 0){
  175. return 1;
  176. }
  177. }
  178. return 0;
  179. }
  180. static void
  181. new_plugin_entry(entry_and_plugin_t **ep, Slapi_Entry *e, struct slapdplugin *plugin)
  182. {
  183. entry_and_plugin_t *oldep = 0;
  184. entry_and_plugin_t *iterep = *ep;
  185. entry_and_plugin_t *newep =
  186. (entry_and_plugin_t*)slapi_ch_calloc(1,sizeof(entry_and_plugin_t));
  187. newep->e = e;
  188. newep->plugin = plugin;
  189. while(iterep)
  190. {
  191. oldep = iterep;
  192. iterep = iterep->next;
  193. }
  194. newep->next = 0;
  195. if(oldep)
  196. oldep->next = newep;
  197. else
  198. *ep = newep;
  199. }
  200. static void
  201. add_plugin_entry_dn(const Slapi_DN *plugin_dn)
  202. {
  203. if (!global_plugin_dns)
  204. {
  205. global_plugin_dns = PL_NewHashTable(20, PL_HashString,
  206. PL_CompareStrings,
  207. PL_CompareValues, 0, 0);
  208. }
  209. PL_HashTableAdd(global_plugin_dns,
  210. slapi_sdn_get_ndn(plugin_dn),
  211. (void*)plugin_dn);
  212. }
  213. #define SLAPI_PLUGIN_NONE_IF_NULL( s ) ((s) == NULL ? "none" : (s))
  214. /*
  215. * Allows a plugin to register a plugin.
  216. * This was added so that 'object' plugins could register all
  217. * the plugin interfaces that it supports.
  218. */
  219. int
  220. slapi_register_plugin(
  221. const char *plugintype,
  222. int enabled,
  223. const char *initsymbol,
  224. slapi_plugin_init_fnptr initfunc,
  225. const char *name,
  226. char **argv,
  227. void *group_identity
  228. )
  229. {
  230. return slapi_register_plugin_ext(plugintype, enabled, initsymbol,
  231. initfunc, name, argv, group_identity, PLUGIN_DEFAULT_PRECEDENCE);
  232. }
  233. int
  234. slapi_register_plugin_ext(
  235. const char *plugintype,
  236. int enabled,
  237. const char *initsymbol,
  238. slapi_plugin_init_fnptr initfunc,
  239. const char *name,
  240. char **argv,
  241. void *group_identity,
  242. int precedence
  243. )
  244. {
  245. Slapi_Entry *e = NULL;
  246. char returntext[SLAPI_DSE_RETURNTEXT_SIZE] = "";
  247. char *dn = slapi_ch_smprintf("cn=%s,%s", name, PLUGIN_BASE_DN);
  248. Slapi_DN *sdn = slapi_sdn_new_normdn_passin(dn);
  249. int found_precedence;
  250. int ii = 0;
  251. int rc = 0;
  252. e = slapi_entry_alloc();
  253. /* this function consumes dn */
  254. slapi_entry_init_ext(e, sdn, NULL);
  255. slapi_sdn_free(&sdn);
  256. slapi_entry_attr_set_charptr(e, "cn", name);
  257. slapi_entry_attr_set_charptr(e, ATTR_PLUGIN_TYPE, plugintype);
  258. if (!enabled)
  259. slapi_entry_attr_set_charptr(e, ATTR_PLUGIN_ENABLED, "off");
  260. slapi_entry_attr_set_charptr(e, ATTR_PLUGIN_INITFN, initsymbol);
  261. /* If the plugin belong to a group, get the precedence from the group */
  262. found_precedence = precedence;
  263. if ((found_precedence == PLUGIN_DEFAULT_PRECEDENCE) && group_identity) {
  264. struct slapi_componentid * cid = (struct slapi_componentid *) group_identity;
  265. if (cid->sci_plugin && (cid->sci_plugin->plg_precedence != PLUGIN_DEFAULT_PRECEDENCE)) {
  266. slapi_log_error(SLAPI_LOG_PLUGIN, NULL,
  267. "Plugin precedence (%s) reset to group precedence (%s): %d \n",
  268. name ? name : "",
  269. cid->sci_plugin->plg_name ? cid->sci_plugin->plg_name : "",
  270. cid->sci_plugin->plg_precedence);
  271. found_precedence = cid->sci_plugin->plg_precedence;
  272. }
  273. }
  274. slapi_entry_attr_set_int(e, ATTR_PLUGIN_PRECEDENCE, found_precedence);
  275. for (ii = 0; argv && argv[ii]; ++ii) {
  276. char argname[64];
  277. PR_snprintf(argname, sizeof(argname), "%s%d", ATTR_PLUGIN_ARG, ii);
  278. slapi_entry_attr_set_charptr(e, argname, argv[ii]);
  279. }
  280. /* plugin_setup copies the given entry */
  281. rc = plugin_setup(e, group_identity, initfunc, 0, returntext);
  282. slapi_entry_free(e);
  283. return rc;
  284. }
  285. int
  286. plugin_call_plugins( Slapi_PBlock *pb, int whichfunction )
  287. {
  288. int plugin_list_number= -1;
  289. int rc= 0;
  290. int do_op = global_plugin_callbacks_enabled;
  291. if ( pb == NULL )
  292. {
  293. return( 0 );
  294. }
  295. switch ( whichfunction ) {
  296. case SLAPI_PLUGIN_PRE_BIND_FN:
  297. case SLAPI_PLUGIN_PRE_UNBIND_FN:
  298. case SLAPI_PLUGIN_PRE_SEARCH_FN:
  299. case SLAPI_PLUGIN_PRE_COMPARE_FN:
  300. case SLAPI_PLUGIN_PRE_MODIFY_FN:
  301. case SLAPI_PLUGIN_PRE_MODRDN_FN:
  302. case SLAPI_PLUGIN_PRE_ADD_FN:
  303. case SLAPI_PLUGIN_PRE_DELETE_FN:
  304. case SLAPI_PLUGIN_PRE_ABANDON_FN:
  305. case SLAPI_PLUGIN_PRE_ENTRY_FN:
  306. case SLAPI_PLUGIN_PRE_REFERRAL_FN:
  307. case SLAPI_PLUGIN_PRE_RESULT_FN:
  308. plugin_list_number= PLUGIN_LIST_PREOPERATION;
  309. break;
  310. case SLAPI_PLUGIN_POST_BIND_FN:
  311. case SLAPI_PLUGIN_POST_UNBIND_FN:
  312. case SLAPI_PLUGIN_POST_SEARCH_FN:
  313. case SLAPI_PLUGIN_POST_SEARCH_FAIL_FN:
  314. case SLAPI_PLUGIN_POST_COMPARE_FN:
  315. case SLAPI_PLUGIN_POST_MODIFY_FN:
  316. case SLAPI_PLUGIN_POST_MODRDN_FN:
  317. case SLAPI_PLUGIN_POST_ADD_FN:
  318. case SLAPI_PLUGIN_POST_DELETE_FN:
  319. case SLAPI_PLUGIN_POST_ABANDON_FN:
  320. case SLAPI_PLUGIN_POST_ENTRY_FN:
  321. case SLAPI_PLUGIN_POST_REFERRAL_FN:
  322. case SLAPI_PLUGIN_POST_RESULT_FN:
  323. plugin_list_number= PLUGIN_LIST_POSTOPERATION;
  324. break;
  325. case SLAPI_PLUGIN_BE_PRE_MODIFY_FN:
  326. case SLAPI_PLUGIN_BE_PRE_MODRDN_FN:
  327. case SLAPI_PLUGIN_BE_PRE_ADD_FN:
  328. case SLAPI_PLUGIN_BE_PRE_DELETE_FN:
  329. case SLAPI_PLUGIN_BE_PRE_CLOSE_FN:
  330. case SLAPI_PLUGIN_BE_PRE_BACKUP_FN:
  331. plugin_list_number= PLUGIN_LIST_BEPREOPERATION;
  332. do_op = 1; /* always allow backend callbacks (even during startup) */
  333. break;
  334. case SLAPI_PLUGIN_BE_POST_MODIFY_FN:
  335. case SLAPI_PLUGIN_BE_POST_MODRDN_FN:
  336. case SLAPI_PLUGIN_BE_POST_ADD_FN:
  337. case SLAPI_PLUGIN_BE_POST_DELETE_FN:
  338. case SLAPI_PLUGIN_BE_POST_OPEN_FN:
  339. case SLAPI_PLUGIN_BE_POST_BACKUP_FN:
  340. plugin_list_number= PLUGIN_LIST_BEPOSTOPERATION;
  341. do_op = 1; /* always allow backend callbacks (even during startup) */
  342. break;
  343. case SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN:
  344. case SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN:
  345. case SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN:
  346. case SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN:
  347. case SLAPI_PLUGIN_INTERNAL_PRE_BIND_FN:
  348. plugin_list_number= PLUGIN_LIST_INTERNAL_PREOPERATION;
  349. break;
  350. case SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN:
  351. case SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN:
  352. case SLAPI_PLUGIN_INTERNAL_POST_ADD_FN:
  353. case SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN:
  354. plugin_list_number= PLUGIN_LIST_INTERNAL_POSTOPERATION;
  355. break;
  356. case SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN:
  357. case SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN:
  358. case SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN:
  359. case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN:
  360. case SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN:
  361. plugin_list_number= PLUGIN_LIST_BETXNPREOPERATION;
  362. do_op = 1; /* always allow backend callbacks (even during startup) */
  363. break;
  364. case SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN:
  365. case SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN:
  366. case SLAPI_PLUGIN_BE_TXN_POST_ADD_FN:
  367. case SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN:
  368. plugin_list_number= PLUGIN_LIST_BETXNPOSTOPERATION;
  369. do_op = 1; /* always allow backend callbacks (even during startup) */
  370. break;
  371. case SLAPI_PLUGIN_PRE_EXTOP_FN:
  372. plugin_list_number= PLUGIN_LIST_PREEXTENDED_OPERATION;
  373. break;
  374. case SLAPI_PLUGIN_POST_EXTOP_FN:
  375. plugin_list_number= PLUGIN_LIST_POSTEXTENDED_OPERATION;
  376. break;
  377. }
  378. if(plugin_list_number!=-1 && do_op)
  379. {
  380. /* We stash the pblock plugin pointer to preserve the callers context */
  381. struct slapdplugin *p;
  382. int locked = 0;
  383. locked = slapi_td_get_plugin_locked();
  384. if (!locked) {
  385. slapi_rwlock_rdlock(global_rwlock);
  386. }
  387. slapi_pblock_get(pb, SLAPI_PLUGIN, &p);
  388. /* Call the operation on the Global Plugins */
  389. rc = plugin_call_list(global_plugin_list[plugin_list_number], whichfunction, pb);
  390. slapi_pblock_set(pb, SLAPI_PLUGIN, p);
  391. if (!locked) {
  392. slapi_rwlock_unlock(global_rwlock);
  393. }
  394. }
  395. else
  396. {
  397. /* Programmer error! or the callback is denied during startup */
  398. }
  399. return rc;
  400. }
  401. void
  402. plugin_call_entrystore_plugins(char **entrystr, uint *size)
  403. {
  404. struct slapdplugin *p;
  405. for (p = global_plugin_list[PLUGIN_LIST_LDBM_ENTRY_FETCH_STORE];
  406. p != NULL; p = p->plg_next )
  407. {
  408. if (p->plg_entrystorefunc)
  409. (*p->plg_entrystorefunc)(entrystr, size);
  410. }
  411. }
  412. void
  413. plugin_call_entryfetch_plugins(char **entrystr, uint *size)
  414. {
  415. struct slapdplugin *p;
  416. for (p = global_plugin_list[PLUGIN_LIST_LDBM_ENTRY_FETCH_STORE];
  417. p != NULL; p = p->plg_next )
  418. {
  419. if (p->plg_entryfetchfunc)
  420. (*p->plg_entryfetchfunc)(entrystr, size);
  421. }
  422. }
  423. /*
  424. * plugin_determine_exop_plugins
  425. *
  426. * A call to this function will determine the correct plugin that is required
  427. * based on the extended operation ID.
  428. *
  429. * extoid : The extended operation oid as a *char
  430. * plugin: A pointer to a struct slapdplugin *. IE &*p This will be set by the function.
  431. * return: SLAPI_PLUGIN_EXTENDED_NOT_HANDLED if no plugin. Otherwise, the SLAPI_PLUGIN_* type that the plugin is.
  432. */
  433. int
  434. plugin_determine_exop_plugins( const char *oid, struct slapdplugin **plugin)
  435. {
  436. struct slapdplugin *p = NULL;
  437. int list_type = 0;
  438. int i = 0;
  439. int l = 0;
  440. int rc = SLAPI_PLUGIN_EXTENDED_NOT_HANDLED;
  441. int list_types[] = {PLUGIN_LIST_EXTENDED_OPERATION, PLUGIN_LIST_BE_TXN_EXTENDED_OPERATION};
  442. for ( l = 0; l < 2; ++l ) {
  443. list_type = list_types[l];
  444. for ( p = global_plugin_list[list_type]; p != NULL; p = p->plg_next ) {
  445. if ( p->plg_exhandler != NULL && p->plg_exoids != NULL ) {
  446. for ( i = 0; p->plg_exoids[i] != NULL; i++ ) {
  447. if ( strcasecmp( oid, p->plg_exoids[i] ) == 0 ) {
  448. *plugin = p;
  449. rc = p->plg_type;
  450. /* break; */
  451. /* WB - 48870, return early so that we can get the plugin
  452. * that is set earlier in the list. This prevents the
  453. * need to change add_plugin_to_list, which may have
  454. * side effects.
  455. */
  456. return rc;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. return rc;
  463. }
  464. /*
  465. * call extended operation plugins
  466. *
  467. * return SLAPI_PLUGIN_EXTENDED_SENT_RESULT if one of the extended operation
  468. * plugins sent a result.
  469. * return SLAPI_PLUGIN_EXTENDED_NOT_HANDLED if no extended operation plugins
  470. * handled the operation.
  471. * otherwise, return an LDAP error code (possibly a merge of the errors
  472. * returned by the plugins we called).
  473. */
  474. int
  475. plugin_call_exop_plugins( Slapi_PBlock *pb, struct slapdplugin *p )
  476. {
  477. int rc;
  478. slapi_pblock_set( pb, SLAPI_PLUGIN, p );
  479. set_db_default_result_handlers( pb );
  480. rc = (*p->plg_exhandler)( pb );
  481. return (rc);
  482. }
  483. /*
  484. * Attempt to convert the extended operation 'oid' to a string by
  485. * examining the registered plugins. Returns NULL if no plugin is
  486. * registered for this OID.
  487. *
  488. * Our first choice is to use an OID-specific name that has been
  489. * registered by a plugin via the SLAPI_PLUGIN_EXT_OP_NAMELIST pblock setting.
  490. * Our second choice is to use the plugin's ID (short name).
  491. * Our third choice is to use the plugin's RDN (under cn=config).
  492. */
  493. const char *
  494. plugin_extended_op_oid2string( const char *oid )
  495. {
  496. struct slapdplugin *p;
  497. int j = 0;
  498. int rc = 0;
  499. const char *rval = NULL;
  500. rc = plugin_determine_exop_plugins( oid, &p);
  501. if ((rc == SLAPI_PLUGIN_EXTENDEDOP || rc == SLAPI_PLUGIN_BETXNEXTENDEDOP) && p != NULL ) {
  502. /* We have the plugin, p set, so lets fill it in */
  503. if ( NULL != p->plg_exnames ) {
  504. for ( j = 0; p->plg_exnames[j] != NULL; ++j ) {
  505. /* I'm not sure what this does ....*/
  506. ;
  507. }
  508. rval = p->plg_exnames[j]; /* OID-related name */
  509. }
  510. if ( NULL == rval ) {
  511. if ( NULL != p->plg_desc.spd_id ) {
  512. rval = p->plg_desc.spd_id; /* short name */
  513. } else {
  514. rval = p->plg_name; /* RDN */
  515. }
  516. }
  517. }
  518. return( rval );
  519. }
  520. Slapi_Backend *
  521. plugin_extended_op_getbackend( Slapi_PBlock *pb, struct slapdplugin *p )
  522. {
  523. // struct slapdplugin *p;
  524. int rc;
  525. /* This could be an error type, but for now we expect the caller to check
  526. * that it's not null
  527. */
  528. Slapi_Backend *result = NULL;
  529. rc = (*p->plg_be_exhandler)( pb, &result );
  530. if (rc != LDAP_SUCCESS) {
  531. /* Do we need to do anything? Or it is the parents job? */
  532. result = NULL;
  533. }
  534. return( result );
  535. }
  536. static int
  537. plugin_cmp_plugins(struct slapdplugin *p1, struct slapdplugin *p2)
  538. {
  539. int rc = 0;
  540. if( p1->plg_dn ){
  541. if(p2->plg_dn && strcasecmp(p1->plg_dn, p2->plg_dn) == 0){
  542. rc = 1;
  543. } else if(p2->plg_id && strcasecmp(p1->plg_dn, p2->plg_id) == 0){
  544. rc = 1;
  545. }
  546. } else if(p1->plg_id){
  547. if(p2->plg_id && strcasecmp(p1->plg_id, p2->plg_id) == 0){
  548. rc = 1;
  549. } else if(p2->plg_dn && strcasecmp(p2->plg_dn, p1->plg_id) == 0){
  550. rc = 1;
  551. }
  552. }
  553. return rc;
  554. }
  555. /*
  556. * kexcoff: return the slapdplugin structure
  557. */
  558. struct slapdplugin *
  559. plugin_get_pwd_storage_scheme(char *name, int len, int index)
  560. {
  561. /* index could be PLUGIN_LIST_PWD_STORAGE_SCHEME or PLUGIN_LIST_REVER_PWD_STORAGE_SCHEME */
  562. struct slapdplugin *p;
  563. for ( p = global_plugin_list[index]; p != NULL; p = p->plg_next ) {
  564. if (strlen(p->plg_pwdstorageschemename) == len) {
  565. if (strncasecmp(p->plg_pwdstorageschemename, name, len) == 0) {
  566. return( p );
  567. }
  568. }
  569. }
  570. return( NULL );
  571. }
  572. char *
  573. plugin_get_pwd_storage_scheme_list(int index)
  574. {
  575. /* index could be PLUGIN_LIST_PWD_STORAGE_SCHEME or PLUGIN_LIST_REVER_PWD_STORAGE_SCHEME */
  576. struct slapdplugin *p = NULL;
  577. char *names_list = NULL;
  578. int len = 0;
  579. /* first pass - calculate space needed for comma delimited list */
  580. for ( p = global_plugin_list[index]; p != NULL; p = p->plg_next ) {
  581. if ( p->plg_pwdstorageschemeenc != NULL )
  582. {
  583. /* + 1 for comma, 1 for space, 1 for null */
  584. len += strlen(p->plg_pwdstorageschemename) + 3;
  585. }
  586. }
  587. /* no plugins? */
  588. if (!len)
  589. return NULL;
  590. /* next, allocate the space */
  591. names_list = (char *)slapi_ch_malloc(len+1);
  592. *names_list = 0;
  593. /* second pass - write the string */
  594. for ( p = global_plugin_list[index]; p != NULL; p = p->plg_next ) {
  595. if ( p->plg_pwdstorageschemeenc != NULL )
  596. {
  597. strcat(names_list, p->plg_pwdstorageschemename);
  598. if (p->plg_next != NULL)
  599. strcat(names_list, ", ");
  600. }
  601. }
  602. return( names_list );
  603. }
  604. int slapi_send_ldap_intermediate( Slapi_PBlock *pb, LDAPControl **ectrls,
  605. char *responseName, struct berval *responseValue)
  606. {
  607. /* no SLAPI_PLUGIN_DB_INTERMEDIATE_FN defined
  608. * always directly call slapd_ function
  609. */
  610. return send_ldap_intermediate(pb, ectrls, responseName, responseValue);
  611. }
  612. int
  613. slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e, LDAPControl **ectrls,
  614. char **attrs, int attrsonly )
  615. {
  616. IFP fn = NULL;
  617. slapi_pblock_get(pb,SLAPI_PLUGIN_DB_ENTRY_FN,(void*)&fn);
  618. if (NULL == fn)
  619. {
  620. return -1;
  621. }
  622. return (*fn)(pb,e,ectrls,attrs,attrsonly);
  623. }
  624. void
  625. slapi_set_ldap_result( Slapi_PBlock *pb, int err, char *matched, char *text,
  626. int nentries, struct berval **urls )
  627. {
  628. char * old_matched = NULL;
  629. char * old_text = NULL;
  630. char * matched_copy = slapi_ch_strdup(matched);
  631. char * text_copy = slapi_ch_strdup(text);
  632. /* free the old matched and text, if any */
  633. slapi_pblock_get(pb, SLAPI_RESULT_MATCHED, &old_matched);
  634. slapi_ch_free_string(&old_matched);
  635. slapi_pblock_get(pb, SLAPI_RESULT_TEXT, &old_text);
  636. slapi_ch_free_string(&old_text);
  637. /* set the new stuff */
  638. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &err);
  639. slapi_pblock_set(pb, SLAPI_RESULT_MATCHED, matched_copy);
  640. slapi_pblock_set(pb, SLAPI_RESULT_TEXT, text_copy);
  641. }
  642. void
  643. slapi_send_ldap_result_from_pb( Slapi_PBlock *pb)
  644. {
  645. int err;
  646. char *matched;
  647. char *text;
  648. IFP fn = NULL;
  649. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &err);
  650. slapi_pblock_get(pb, SLAPI_RESULT_TEXT, &text);
  651. slapi_pblock_get(pb, SLAPI_RESULT_MATCHED, &matched);
  652. slapi_pblock_get(pb,SLAPI_PLUGIN_DB_RESULT_FN,(void*)&fn);
  653. if (NULL != fn)
  654. {
  655. (*fn)(pb,err,matched,text,0,NULL);
  656. }
  657. slapi_pblock_set(pb, SLAPI_RESULT_TEXT, NULL);
  658. slapi_pblock_set(pb, SLAPI_RESULT_MATCHED, NULL);
  659. slapi_ch_free((void **)&matched);
  660. slapi_ch_free((void **)&text);
  661. }
  662. void
  663. slapi_send_ldap_result( Slapi_PBlock *pb, int err, char *matched, char *text,
  664. int nentries, struct berval **urls )
  665. {
  666. IFP fn = NULL;
  667. Slapi_Operation *operation;
  668. long op_type;
  669. /* GB : for spanning requests over multiple backends */
  670. if (err == LDAP_NO_SUCH_OBJECT)
  671. {
  672. slapi_pblock_get (pb, SLAPI_OPERATION, &operation);
  673. op_type = operation_get_type(operation);
  674. if (op_type == SLAPI_OPERATION_SEARCH)
  675. {
  676. if (urls || nentries)
  677. {
  678. LDAPDebug( LDAP_DEBUG_ANY, "ERROR : urls or nentries set"
  679. "in sendldap_result while NO_SUCH_OBJECT returned\n",0,0,0);
  680. }
  681. slapi_set_ldap_result(pb, err, matched, text, 0, NULL);
  682. return;
  683. }
  684. }
  685. slapi_pblock_set(pb, SLAPI_RESULT_CODE, &err);
  686. slapi_pblock_get(pb,SLAPI_PLUGIN_DB_RESULT_FN,(void*)&fn);
  687. if (NULL == fn)
  688. {
  689. return ;
  690. }
  691. /*
  692. * Call the result function. It should set pb->pb_op->o_status to
  693. * SLAPI_OP_STATUS_RESULT_SENT right after sending the result to
  694. * the client or otherwise consuming it.
  695. */
  696. (*fn)(pb,err,matched,text,nentries,urls);
  697. }
  698. int
  699. slapi_send_ldap_referral( Slapi_PBlock *pb, Slapi_Entry *e, struct berval **refs,
  700. struct berval ***urls )
  701. {
  702. IFP fn = NULL;
  703. slapi_pblock_get(pb,SLAPI_PLUGIN_DB_REFERRAL_FN,(void*)&fn);
  704. if (NULL == fn)
  705. {
  706. return -1;
  707. }
  708. return (*fn)(pb,e,refs,urls);
  709. }
  710. /***********************************************************
  711. start of plugin dependency code
  712. ************************************************************/
  713. /* struct _plugin_dep_type
  714. * we shall not presume to know all plugin types
  715. * so as to allow new types to be added without
  716. * requiring changes to this code (hopefully)
  717. * so we need to dynamically keep track of them
  718. */
  719. typedef struct _plugin_dep_type{
  720. char *type; /* the string descriptor */
  721. int num_not_started; /* the count of plugins which have yet to be started for this type */
  722. struct _plugin_dep_type *next;
  723. } *plugin_dep_type;
  724. /* _plugin_dep_config
  725. * we need somewhere to collect the plugin configurations
  726. * prior to attempting to resolve dependencies
  727. */
  728. typedef struct _plugin_dep_config {
  729. char *name;
  730. char *type;
  731. Slapi_PBlock pb;
  732. struct slapdplugin *plugin;
  733. Slapi_Entry *e;
  734. int entry_created;
  735. int op_done;
  736. char **depends_type_list;
  737. int total_type;
  738. char **depends_named_list;
  739. int total_named;
  740. char *config_area;
  741. int removed;
  742. } plugin_dep_config;
  743. static void plugin_free_plugin_dep_config(plugin_dep_config **config);
  744. /* list of plugins which should be shutdown in reverse order */
  745. static plugin_dep_config *global_plugin_shutdown_order = 0;
  746. static int global_plugins_started = 0;
  747. /*
  748. * find_plugin_type
  749. *
  750. * searches the list for the plugin type
  751. * and returns the plugin_dep_type if found
  752. */
  753. static plugin_dep_type
  754. find_plugin_type(plugin_dep_type head, char *type)
  755. {
  756. plugin_dep_type ret = 0;
  757. plugin_dep_type iter = head;
  758. while(iter)
  759. {
  760. if(!slapi_UTF8CASECMP(iter->type, type))
  761. {
  762. ret = iter;
  763. break;
  764. }
  765. iter = iter->next;
  766. }
  767. return ret;
  768. }
  769. /*
  770. * increment_plugin_type
  771. *
  772. * searches the list for the plugin type
  773. * and increments its not started value
  774. * returns the current type count on success -1 on failure
  775. * to find the type
  776. */
  777. static int
  778. increment_plugin_type(plugin_dep_type head, char *type)
  779. {
  780. int ret = -1;
  781. plugin_dep_type the_type;
  782. if ((the_type = find_plugin_type(head, type)) != NULL)
  783. ret = ++the_type->num_not_started;
  784. return ret;
  785. }
  786. /*
  787. * decrement_plugin_type
  788. *
  789. * searches the list for the plugin type
  790. * and decrements its not started value
  791. * returns the current type count on success -1 on failure
  792. * to find the type
  793. */
  794. static int
  795. decrement_plugin_type(plugin_dep_type head, char *type)
  796. {
  797. int ret = -1;
  798. plugin_dep_type the_type;
  799. if ((the_type = find_plugin_type(head, type)) != NULL)
  800. ret = --the_type->num_not_started;
  801. return ret;
  802. }
  803. /*
  804. * add_plugin_type
  805. *
  806. * Either increments the count of the plugin type
  807. * or when it does not exist, adds it to the list
  808. */
  809. static int
  810. add_plugin_type(plugin_dep_type *head, char *type)
  811. {
  812. int ret = -1;
  813. if(*head)
  814. {
  815. if(0 < increment_plugin_type(*head, type))
  816. {
  817. ret = 0;
  818. }
  819. }
  820. if(ret)
  821. {
  822. /* create new head */
  823. plugin_dep_type tmp_head;
  824. tmp_head = (plugin_dep_type)slapi_ch_malloc(sizeof(struct _plugin_dep_type));
  825. tmp_head->num_not_started = 1;
  826. tmp_head->type = slapi_ch_strdup(type);
  827. ret = 0;
  828. tmp_head->next = *head;
  829. (*head) = tmp_head;
  830. }
  831. return ret;
  832. }
  833. /*
  834. * plugin_create_stringlist
  835. *
  836. * Creates a string list from values of the entries
  837. * attribute passed in as args - used to track dependencies
  838. *
  839. */
  840. int
  841. plugin_create_stringlist( Slapi_Entry *plugin_entry, char *attr_name,
  842. int *total_strings, char ***list)
  843. {
  844. Slapi_Attr *attr = 0;
  845. int hint = 0;
  846. int num_vals = 0;
  847. int val_index = 0;
  848. Slapi_Value *val = NULL;
  849. if(0 == slapi_entry_attr_find( plugin_entry, attr_name, &attr ))
  850. {
  851. /* allocate memory for the string array */
  852. slapi_attr_get_numvalues( attr, &num_vals);
  853. if(num_vals)
  854. {
  855. *total_strings = num_vals;
  856. *list = (char **)slapi_ch_calloc(num_vals + 1, sizeof(char*));
  857. }
  858. else
  859. goto bail; /* if this ever happens, then they are running on a TSR-80 */
  860. val_index = 0;
  861. hint = slapi_attr_first_value( attr, &val );
  862. while(val_index < num_vals)
  863. {
  864. /* add the value to the array */
  865. (*list)[val_index] = (char*)slapi_ch_strdup(slapi_value_get_string(val));
  866. hint = slapi_attr_next_value( attr, hint, &val );
  867. val_index++;
  868. }
  869. }
  870. else
  871. *total_strings = num_vals;
  872. bail:
  873. return num_vals;
  874. }
  875. /*
  876. * Remove the plugin from the DN hashtable
  877. */
  878. static void
  879. plugin_remove_from_list(char *plugin_dn)
  880. {
  881. Slapi_DN *hash_sdn;
  882. hash_sdn = (Slapi_DN *)PL_HashTableLookup(global_plugin_dns, plugin_dn);
  883. if(hash_sdn){
  884. PL_HashTableRemove(global_plugin_dns, plugin_dn);
  885. slapi_sdn_free(&hash_sdn);
  886. }
  887. }
  888. /*
  889. * The main plugin was successfully started, set it and its
  890. * registered plugin functions as started.
  891. */
  892. static void
  893. plugin_set_plugins_started(struct slapdplugin *plugin_entry)
  894. {
  895. struct slapdplugin *plugin = NULL;
  896. int type = 0;
  897. /* look everywhere for other plugin functions with the plugin id */
  898. for(type = 0; type < PLUGIN_LIST_GLOBAL_MAX; type++){
  899. plugin = global_plugin_list[type];
  900. while(plugin){
  901. if(plugin_cmp_plugins(plugin_entry, plugin)){
  902. plugin->plg_started = 1;
  903. }
  904. plugin = plugin->plg_next;
  905. }
  906. }
  907. }
  908. /*
  909. * A plugin dependency changed, update the dependency list
  910. */
  911. void
  912. plugin_update_dep_entries(Slapi_Entry *plugin_entry)
  913. {
  914. entry_and_plugin_t *ep;
  915. slapi_rwlock_wrlock(global_rwlock);
  916. ep = dep_plugin_entries;
  917. while(ep){
  918. if(ep->plugin && ep->e){
  919. if(slapi_sdn_compare(slapi_entry_get_sdn(ep->e), slapi_entry_get_sdn(plugin_entry)) == 0){
  920. slapi_entry_free(ep->e);
  921. ep->e = slapi_entry_dup(plugin_entry);
  922. break;
  923. }
  924. }
  925. ep = ep->next;
  926. }
  927. slapi_rwlock_unlock(global_rwlock);
  928. }
  929. /*
  930. * Attempt to start a plugin that was either just added or just enabled.
  931. */
  932. int
  933. plugin_start(Slapi_Entry *entry, char *returntext)
  934. {
  935. entry_and_plugin_t *ep = dep_plugin_entries;
  936. plugin_dep_config *global_tmp_list = NULL;
  937. plugin_dep_config *config = NULL;
  938. plugin_dep_type the_plugin_type;
  939. plugin_dep_type plugin_head = 0;
  940. Slapi_PBlock pb;
  941. Slapi_Entry *plugin_entry;
  942. struct slapdplugin *plugin;
  943. char *value;
  944. int plugins_started = 1;
  945. int num_plg_started = 0;
  946. int shutdown_index = 0;
  947. int total_plugins = 0;
  948. int plugin_index = 0;
  949. int plugin_idx = -1;
  950. int index = 0;
  951. int ret = 0;
  952. int i = 0;
  953. global_plugins_started = 0;
  954. /* Count the plugins so we can allocate memory for the config array */
  955. while(ep){
  956. if(slapi_sdn_compare(slapi_entry_get_sdn(ep->e), slapi_entry_get_sdn(entry)) == 0){
  957. plugin_idx = total_plugins;
  958. }
  959. total_plugins++;
  960. ep = ep->next;
  961. }
  962. /* allocate the config array */
  963. config = (plugin_dep_config*)slapi_ch_calloc(total_plugins + 1, sizeof(plugin_dep_config));
  964. ep = dep_plugin_entries;
  965. /* Collect relevant config */
  966. while(ep){
  967. plugin = ep->plugin;
  968. if(plugin == 0){
  969. continue;
  970. }
  971. pblock_init(&pb);
  972. slapi_pblock_set( &pb, SLAPI_ARGC, &plugin->plg_argc);
  973. slapi_pblock_set( &pb, SLAPI_ARGV, &plugin->plg_argv);
  974. config[plugin_index].pb = pb;
  975. config[plugin_index].e = ep->e;
  976. /* add type */
  977. plugin_entry = ep->e;
  978. if(plugin_entry){
  979. /*
  980. * Pass the plugin DN in SLAPI_TARGET_SDN and the plugin entry
  981. * in SLAPI_ADD_ENTRY. For this to actually work, we need to
  982. * create an operation and include that in the pblock as well,
  983. * because these two items are stored in the operation parameters.
  984. */
  985. Operation *op = internal_operation_new(SLAPI_OPERATION_ADD, 0);
  986. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_OPERATION, op);
  987. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_TARGET_SDN,
  988. (void*)(slapi_entry_get_sdn_const(plugin_entry)));
  989. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_ADD_ENTRY,
  990. plugin_entry );
  991. /* Pass the plugin alternate config area DN in SLAPI_PLUGIN_CONFIG_AREA. */
  992. value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_CONFIG_AREA);
  993. if(value){
  994. config[plugin_index].config_area = value;
  995. value = NULL;
  996. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_PLUGIN_CONFIG_AREA,
  997. config[plugin_index].config_area);
  998. }
  999. value = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype");
  1000. if(value){
  1001. add_plugin_type( &plugin_head, value);
  1002. config[plugin_index].type = value;
  1003. value = NULL;
  1004. }
  1005. /* now the name */
  1006. value = slapi_entry_attr_get_charptr(plugin_entry, "cn");
  1007. if(value){
  1008. config[plugin_index].name = value;
  1009. value = NULL;
  1010. }
  1011. config[plugin_index].plugin = plugin;
  1012. /* now add dependencies */
  1013. plugin_create_stringlist( plugin_entry, ATTR_PLUGIN_DEPENDS_ON_NAMED,
  1014. &(config[plugin_index].total_named), &(config[plugin_index].depends_named_list));
  1015. plugin_create_stringlist( plugin_entry, ATTR_PLUGIN_DEPENDS_ON_TYPE,
  1016. &(config[plugin_index].total_type), &(config[plugin_index].depends_type_list));
  1017. }
  1018. plugin_index++;
  1019. ep = ep->next;
  1020. }
  1021. /*
  1022. * Prepare list of shutdown order (we need nothing fancier right now
  1023. * than the reverse startup order) The list may include NULL entries,
  1024. * these will be plugins which were never started
  1025. */
  1026. shutdown_index = total_plugins - 1;
  1027. global_tmp_list = (plugin_dep_config*)slapi_ch_calloc(total_plugins, sizeof(plugin_dep_config));
  1028. /* now resolve dependencies
  1029. * cycle through list, if a plugin has no dependencies then start it
  1030. * then remove it from the dependency lists of all other plugins
  1031. * and decrement the corresponding element of the plugin types array
  1032. * for depends_type we will need to check the array of plugin types
  1033. * to see if all type dependencies are at zero prior to start
  1034. * if one cycle fails to load any plugins we have failed, however
  1035. * we shall continue loading plugins in case a configuration error
  1036. * can correct itself
  1037. */
  1038. while(plugins_started && num_plg_started < total_plugins){
  1039. for(plugin_index = 0, plugins_started = 0; plugin_index < total_plugins; plugin_index++){
  1040. /* perform op on plugins only once */
  1041. if(config[plugin_index].op_done == 0){
  1042. int enabled = 0;
  1043. int satisfied = 0;
  1044. int break_out = 0;
  1045. /*
  1046. * determine if plugin is enabled
  1047. * some processing is necessary even
  1048. * if it is not
  1049. */
  1050. if ( NULL != config[plugin_index].e && (value = slapi_entry_attr_get_charptr(config[plugin_index].e,
  1051. ATTR_PLUGIN_ENABLED)) &&
  1052. !strcasecmp(value, "on"))
  1053. {
  1054. enabled = 1;
  1055. } else {
  1056. enabled = 0;
  1057. }
  1058. slapi_ch_free_string(&value);
  1059. /*
  1060. * make sure named dependencies have been satisfied
  1061. * that means that the list of names should contain all
  1062. * null entries
  1063. */
  1064. if(enabled && config[plugin_index].total_named){
  1065. i = 0;
  1066. while(break_out == 0 && i < config[plugin_index].total_named){
  1067. satisfied = 1;
  1068. if((config[plugin_index].depends_named_list)[i] != 0){
  1069. satisfied = 0;
  1070. break_out = 1;
  1071. }
  1072. i++;
  1073. }
  1074. if(!satisfied)
  1075. continue;
  1076. }
  1077. /*
  1078. * make sure the type dependencies have been satisfied
  1079. * that means for each type in the list, it's number of
  1080. * plugins left not started is zero
  1081. */
  1082. satisfied = 0;
  1083. break_out = 0;
  1084. if(enabled && config[plugin_index].total_type){
  1085. i = 0;
  1086. while(break_out == 0 && i < config[plugin_index].total_type){
  1087. satisfied = 1;
  1088. the_plugin_type = find_plugin_type(plugin_head, (config[plugin_index].depends_type_list)[i]);
  1089. if(the_plugin_type && the_plugin_type->num_not_started != 0){
  1090. satisfied = 0;
  1091. break_out = 1;
  1092. }
  1093. i++;
  1094. }
  1095. if(!satisfied)
  1096. continue;
  1097. }
  1098. /**** This plugins dependencies have now been satisfied ****/
  1099. satisfied = 1; /* symbolic only */
  1100. config[plugin_index].entry_created = 1;
  1101. if (enabled){
  1102. if(plugin_index == plugin_idx){
  1103. /* finally, perform the op on the plugin */
  1104. LDAPDebug( LDAP_DEBUG_PLUGIN, "Starting %s plugin %s\n" ,
  1105. config[plugin_index].type, config[plugin_index].name, 0 );
  1106. /*
  1107. * Put the plugin into the temporary pblock so the startup functions have
  1108. * access to the real plugin for registering callbacks, task, etc.
  1109. */
  1110. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_PLUGIN, config[plugin_index].plugin);
  1111. ret = plugin_call_one( config[plugin_index].plugin, SLAPI_PLUGIN_START_FN,
  1112. &(config[plugin_index].pb));
  1113. pblock_done(&(config[plugin_index].pb));
  1114. if(ret){
  1115. /*
  1116. * Delete the plugin(undo everything), as we don't know how far the start
  1117. * function got.
  1118. */
  1119. LDAPDebug( LDAP_DEBUG_ANY, "Failed to start %s plugin %s\n" ,
  1120. config[plugin_index].type, config[plugin_index].name, 0 );
  1121. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Failed to start plugin \"%s\". See errors log.",
  1122. config[plugin_index].name);
  1123. plugin_delete(entry, returntext, 1);
  1124. goto done;
  1125. } else {
  1126. /*
  1127. * Set the plugin and its registered functions as started.
  1128. */
  1129. plugin_set_plugins_started(config[plugin_index].plugin);
  1130. }
  1131. }
  1132. /* Add this plugin to the shutdown list */
  1133. global_tmp_list[shutdown_index] = config[plugin_index];
  1134. shutdown_index--;
  1135. global_plugins_started++;
  1136. /* remove this named plugin from other plugins lists */
  1137. for(i = 0; i < total_plugins; i++){
  1138. index = 0;
  1139. while(index < config[i].total_named){
  1140. if((config[i].depends_named_list)[index] != 0 &&
  1141. !slapi_UTF8CASECMP((config[i].depends_named_list)[index], config[plugin_index].name))
  1142. {
  1143. slapi_ch_free((void**)&((config[i].depends_named_list)[index]));
  1144. }
  1145. index++;
  1146. }
  1147. }
  1148. } else {
  1149. pblock_done(&(config[plugin_index].pb));
  1150. }
  1151. /* decrement the type counter for this plugin type */
  1152. decrement_plugin_type(plugin_head, config[plugin_index].type);
  1153. config[plugin_index].op_done = 1;
  1154. num_plg_started++;
  1155. plugins_started = 1;
  1156. } /* !op_done */
  1157. } /* plugin loop */
  1158. } /* while plugins not started */
  1159. if(plugins_started == 0){
  1160. /* a dependency was not resolved - error */
  1161. LDAPDebug( LDAP_DEBUG_ANY, "Error: Failed to resolve plugin dependencies\n" , 0, 0, 0 );
  1162. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Failed to resolve plugin dependencies.");
  1163. /* list the plugins yet to perform op */
  1164. i = 0;
  1165. while(i < total_plugins){
  1166. if(config[i].op_done == 0){
  1167. LDAPDebug( LDAP_DEBUG_ANY, "Error: %s plugin %s is not started\n" , config[i].type, config[i].name, 0 );
  1168. plugin_remove_plugins(config[i].plugin, config[i].type);
  1169. }
  1170. i++;
  1171. }
  1172. ret = -1;
  1173. }
  1174. done:
  1175. /*
  1176. * Free the plugin list, then rebuild it
  1177. */
  1178. if(ret == LDAP_SUCCESS){
  1179. /* Ok, everything went well, use the new global_shutdown list */
  1180. plugin_free_plugin_dep_config(&global_plugin_shutdown_order);
  1181. global_plugin_shutdown_order = global_tmp_list;
  1182. } else {
  1183. /*
  1184. * problem, undo what we've done in plugin_setup.
  1185. */
  1186. plugin_free_plugin_dep_config(&global_tmp_list);
  1187. }
  1188. /*
  1189. * need the details in config to hang around for shutdown
  1190. * config itself may be deleted since its contents have been
  1191. * copied by value to the shutdown list
  1192. */
  1193. plugin_free_plugin_dep_config(&config);
  1194. if(plugin_head){
  1195. plugin_dep_type next;
  1196. while(plugin_head){
  1197. next = plugin_head->next;
  1198. slapi_ch_free_string(&plugin_head->type);
  1199. slapi_ch_free((void *)&plugin_head);
  1200. plugin_head = next;
  1201. }
  1202. }
  1203. /* Finally enable registered plugin functions */
  1204. global_plugin_callbacks_enabled = 1;
  1205. return ret;
  1206. }
  1207. static void
  1208. plugin_free_plugin_dep_config(plugin_dep_config **cfg)
  1209. {
  1210. plugin_dep_config *config = *cfg;
  1211. int index = 0;
  1212. int i = 0;
  1213. if(config){
  1214. while( config[index].plugin ){
  1215. if(config[index].depends_named_list){
  1216. for(i = 0; i < config[index].total_named; i++){
  1217. slapi_ch_free((void**)&(config[index].depends_named_list)[i]);
  1218. }
  1219. slapi_ch_free((void**)&(config[index].depends_named_list));
  1220. }
  1221. if(config[index].depends_type_list){
  1222. for(i = 0; i < config[index].total_type; i++){
  1223. slapi_ch_free((void**)&(config[index].depends_type_list)[i]);
  1224. }
  1225. slapi_ch_free((void**)&(config[index].depends_type_list));
  1226. }
  1227. slapi_ch_free_string(&config[index].type);
  1228. slapi_ch_free_string(&config[index].name);
  1229. slapi_ch_free_string(&config[index].config_area);
  1230. pblock_done(&config[index].pb);
  1231. index++;
  1232. }
  1233. slapi_ch_free((void**)&config);
  1234. *cfg = NULL;
  1235. }
  1236. }
  1237. /*
  1238. * Take a given plugin and recursively set all the plugin dependency names
  1239. */
  1240. void
  1241. plugin_get_plugin_dependencies(char *plugin_name, char ***names)
  1242. {
  1243. entry_and_plugin_t *ep = dep_plugin_entries;
  1244. char **depends = NULL;
  1245. char *dep_attr = "nsslapd-plugin-depends-on-named";
  1246. int i;
  1247. /* Add the original plugin name to the list */
  1248. if (!charray_inlist(*names, plugin_name)){
  1249. charray_add(names, slapi_ch_strdup(plugin_name));
  1250. }
  1251. /* Find the plugin and grab its dependencies */
  1252. while(ep)
  1253. {
  1254. if (ep->plugin){
  1255. if(strcasecmp(ep->plugin->plg_name, plugin_name) == 0){
  1256. /* We found our plugin, now grab its dependencies */
  1257. depends = slapi_entry_attr_get_charray(ep->e, dep_attr);
  1258. break;
  1259. }
  1260. }
  1261. ep = ep->next;
  1262. }
  1263. if (depends){
  1264. /* Add the plugin's dependencies */
  1265. charray_merge_nodup(names, depends, 1);
  1266. /* Add each dependency's dependencies */
  1267. for (i = 0; depends[i]; i++){
  1268. /* recurse */
  1269. plugin_get_plugin_dependencies(depends[i], names);
  1270. }
  1271. slapi_ch_array_free(depends);
  1272. }
  1273. }
  1274. /*
  1275. * plugin_dependency_startall()
  1276. *
  1277. * Starts all plugins (apart from syntax and matching rule) in order
  1278. * of dependency.
  1279. *
  1280. * Dependencies will be determined by these multi-valued attributes:
  1281. *
  1282. * nsslapd-plugin-depends-on-type : all plugins whose type value matches one of these values must
  1283. * be started prior to this plugin
  1284. *
  1285. * nsslapd-plugin-depends-on-named : the plugin whose cn value matches one of these values must
  1286. * be started prior to this plugin
  1287. */
  1288. static int
  1289. plugin_dependency_startall(int argc, char** argv, char *errmsg, int operation, char** plugin_list)
  1290. {
  1291. int ret = 0;
  1292. Slapi_PBlock pb;
  1293. int total_plugins = 0;
  1294. plugin_dep_config *config = 0;
  1295. plugin_dep_type plugin_head = 0;
  1296. int plugin_index = 0;
  1297. Slapi_Entry *plugin_entry;
  1298. int i = 0; /* general index iterator */
  1299. plugin_dep_type the_plugin_type;
  1300. int index = 0;
  1301. char *value = NULL;
  1302. int plugins_started;
  1303. int num_plg_started;
  1304. struct slapdplugin *plugin;
  1305. entry_and_plugin_t *ep = dep_plugin_entries;
  1306. int shutdown_index = 0;
  1307. /*
  1308. * Disable registered plugin functions so preops/postops/etc
  1309. * dont get called prior to the plugin being started (due to
  1310. * plugins performing ops on the DIT)
  1311. */
  1312. global_plugin_callbacks_enabled = 0;
  1313. /* Count the plugins so we can allocate memory for the config array */
  1314. while(ep)
  1315. {
  1316. total_plugins++;
  1317. ep = ep->next;
  1318. }
  1319. /* allocate the config array */
  1320. config = (plugin_dep_config*)slapi_ch_calloc(total_plugins + 1, sizeof(plugin_dep_config));
  1321. ep = dep_plugin_entries;
  1322. if (plugin_list){
  1323. /* We have a plugin list, so we need to reset the plugin count */
  1324. total_plugins = 0;
  1325. }
  1326. /* Collect relevant config */
  1327. while(ep)
  1328. {
  1329. plugin = ep->plugin;
  1330. if(plugin == 0){
  1331. ep = ep->next;
  1332. continue;
  1333. }
  1334. if (plugin_list){
  1335. /*
  1336. * We have a specific list of plugins to start, skip the others...
  1337. */
  1338. int found = 0;
  1339. for (i = 0; plugin_list[i]; i++){
  1340. if (strcasecmp(plugin->plg_name, plugin_list[i]) == 0){
  1341. found = 1;
  1342. break;
  1343. }
  1344. }
  1345. if (!found){
  1346. /* Skip this plugin, it's not in the list */
  1347. ep = ep->next;
  1348. continue;
  1349. } else {
  1350. total_plugins++;
  1351. }
  1352. }
  1353. pblock_init(&pb);
  1354. slapi_pblock_set( &pb, SLAPI_ARGC, &argc);
  1355. slapi_pblock_set( &pb, SLAPI_ARGV, &argv);
  1356. config[plugin_index].pb = pb;
  1357. config[plugin_index].e = ep->e;
  1358. /* add type */
  1359. plugin_entry = ep->e;
  1360. if(plugin_entry)
  1361. {
  1362. /*
  1363. * Pass the plugin DN in SLAPI_TARGET_SDN and the plugin entry
  1364. * in SLAPI_ADD_ENTRY. For this to actually work, we need to
  1365. * create an operation and include that in the pblock as well,
  1366. * because these two items are stored in the operation parameters.
  1367. */
  1368. /* WARNING: memory leak here - op is only freed by a pblock_done,
  1369. and this only happens below if the plugin is enabled - a short
  1370. circuit goto bail may also cause a leak - however, since this
  1371. only happens a few times at startup, this is not a very serious
  1372. leak - just after the call to plugin_call_one */
  1373. Operation *op = internal_operation_new(SLAPI_OPERATION_ADD, 0);
  1374. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_OPERATION, op);
  1375. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_TARGET_SDN,
  1376. (void*)(slapi_entry_get_sdn_const(plugin_entry)));
  1377. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_ADD_ENTRY,
  1378. plugin_entry );
  1379. /* Pass the plugin alternate config area DN in SLAPI_PLUGIN_CONFIG_AREA. */
  1380. value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_CONFIG_AREA);
  1381. if(value)
  1382. {
  1383. config[plugin_index].config_area = value;
  1384. value = NULL;
  1385. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_PLUGIN_CONFIG_AREA,
  1386. config[plugin_index].config_area);
  1387. }
  1388. value = slapi_entry_attr_get_charptr(plugin_entry, "nsslapd-plugintype");
  1389. if(value)
  1390. {
  1391. add_plugin_type( &plugin_head, value);
  1392. config[plugin_index].type = value;
  1393. value = NULL;
  1394. }
  1395. /* now the name */
  1396. value = slapi_entry_attr_get_charptr(plugin_entry, "cn");
  1397. if(value)
  1398. {
  1399. config[plugin_index].name = value;
  1400. value = NULL;
  1401. }
  1402. config[plugin_index].plugin = plugin;
  1403. /* now add dependencies */
  1404. plugin_create_stringlist( plugin_entry, "nsslapd-plugin-depends-on-named",
  1405. &(config[plugin_index].total_named), &(config[plugin_index].depends_named_list));
  1406. plugin_create_stringlist( plugin_entry, "nsslapd-plugin-depends-on-type",
  1407. &(config[plugin_index].total_type), &(config[plugin_index].depends_type_list));
  1408. }
  1409. plugin_index++;
  1410. ep = ep->next;
  1411. }
  1412. /* prepare list of shutdown order (we need nothing fancier right now
  1413. * than the reverse startup order) The list may include NULL entries,
  1414. * these will be plugins which were never started
  1415. */
  1416. shutdown_index = total_plugins - 1;
  1417. global_plugin_shutdown_order = (plugin_dep_config*)slapi_ch_calloc(total_plugins + 1, sizeof(plugin_dep_config));
  1418. /* now resolve dependencies
  1419. * cycle through list, if a plugin has no dependencies then start it
  1420. * then remove it from the dependency lists of all other plugins
  1421. * and decrement the corresponding element of the plugin types array
  1422. * for depends_type we will need to check the array of plugin types
  1423. * to see if all type dependencies are at zero prior to start
  1424. * if one cycle fails to load any plugins we have failed, however
  1425. * we shall continue loading plugins in case a configuration error
  1426. * can correct itself
  1427. */
  1428. plugins_started = 1;
  1429. num_plg_started = 0;
  1430. while(plugins_started && num_plg_started < total_plugins)
  1431. {
  1432. plugins_started = 0;
  1433. for(plugin_index=0; plugin_index < total_plugins; plugin_index++)
  1434. {
  1435. /* perform op on plugins only once */
  1436. if(config[plugin_index].op_done == 0)
  1437. {
  1438. int enabled = 0;
  1439. int satisfied = 0;
  1440. int break_out = 0;
  1441. /*
  1442. * determine if plugin is enabled
  1443. * some processing is necessary even
  1444. * if it is not
  1445. */
  1446. if ( NULL != config[plugin_index].e && (value = slapi_entry_attr_get_charptr(config[plugin_index].e,
  1447. ATTR_PLUGIN_ENABLED)) &&
  1448. !strcasecmp(value, "on"))
  1449. {
  1450. enabled = 1;
  1451. }
  1452. else
  1453. enabled = 0;
  1454. slapi_ch_free((void**)&value);
  1455. /*
  1456. * make sure named dependencies have been satisfied
  1457. * that means that the list of names should contain all
  1458. * null entries
  1459. */
  1460. if(enabled && config[plugin_index].total_named)
  1461. {
  1462. i = 0;
  1463. while(break_out == 0 && i < config[plugin_index].total_named)
  1464. {
  1465. satisfied = 1;
  1466. if((config[plugin_index].depends_named_list)[i] != 0)
  1467. {
  1468. satisfied = 0;
  1469. break_out = 1;
  1470. }
  1471. i++;
  1472. }
  1473. if(!satisfied)
  1474. continue;
  1475. }
  1476. /*
  1477. * make sure the type dependencies have been satisfied
  1478. * that means for each type in the list, it's number of
  1479. * plugins left not started is zero
  1480. *
  1481. */
  1482. satisfied = 0;
  1483. break_out = 0;
  1484. if(enabled && config[plugin_index].total_type)
  1485. {
  1486. i = 0;
  1487. while(break_out == 0 && i < config[plugin_index].total_type)
  1488. {
  1489. satisfied = 1;
  1490. the_plugin_type = find_plugin_type(plugin_head, (config[plugin_index].depends_type_list)[i]);
  1491. if(the_plugin_type && the_plugin_type->num_not_started != 0)
  1492. {
  1493. satisfied = 0;
  1494. break_out = 1;
  1495. }
  1496. i++;
  1497. }
  1498. if(!satisfied)
  1499. continue;
  1500. }
  1501. /**** This plugins dependencies have now been satisfied ****/
  1502. satisfied = 1; /* symbolic only */
  1503. /*
  1504. * Add the plugins entry to the DSE so the plugin can get
  1505. * its config (both enabled and disabled have entries
  1506. */
  1507. if(!config[plugin_index].entry_created)
  1508. {
  1509. int plugin_actions = 0;
  1510. Slapi_PBlock newpb;
  1511. Slapi_Entry *newe;
  1512. pblock_init(&newpb);
  1513. newe = slapi_entry_dup( config[plugin_index].e );
  1514. slapi_add_entry_internal_set_pb(&newpb, newe, NULL,
  1515. plugin_get_default_component_id(), plugin_actions);
  1516. slapi_pblock_set(&newpb, SLAPI_TARGET_SDN, (void*)slapi_entry_get_sdn_const(newe));
  1517. slapi_add_internal_pb(&newpb);
  1518. pblock_done(&newpb);
  1519. config[plugin_index].entry_created = 1;
  1520. }
  1521. /*
  1522. * only actually start plugin and remove from lists if its enabled
  1523. * we do remove from plugin type list however - rule is dependency on
  1524. * zero or more for type
  1525. */
  1526. if (enabled)
  1527. {
  1528. /* finally, perform the op on the plugin */
  1529. LDAPDebug( LDAP_DEBUG_PLUGIN, "Starting %s plugin %s\n" , config[plugin_index].type, config[plugin_index].name, 0 );
  1530. /*
  1531. * Put the plugin into the temporary pblock so the startup functions have
  1532. * access to the real plugin for registering callbacks, tasks, etc.
  1533. */
  1534. slapi_pblock_set(&(config[plugin_index].pb), SLAPI_PLUGIN, config[plugin_index].plugin);
  1535. ret = plugin_call_one( config[plugin_index].plugin, operation, &(config[plugin_index].pb));
  1536. pblock_done(&(config[plugin_index].pb));
  1537. if(ret)
  1538. {
  1539. /*
  1540. * We will not exit here. If we allow plugins to load normally it is
  1541. * possible that a configuration error (dependencies which were not
  1542. * configured properly) can be recovered from. If there really is a
  1543. * problem then the plugin will never start and eventually it will
  1544. * trigger an exit anyway.
  1545. */
  1546. LDAPDebug( LDAP_DEBUG_ANY, "Failed to start %s plugin %s\n" , config[plugin_index].type, config[plugin_index].name, 0 );
  1547. continue;
  1548. } else {
  1549. /* now set the plugin and all its registered plugin functions as started */
  1550. plugin_set_plugins_started(config[plugin_index].plugin);
  1551. }
  1552. /* Add this plugin to the shutdown list */
  1553. global_plugin_shutdown_order[shutdown_index] = config[plugin_index];
  1554. shutdown_index--;
  1555. global_plugins_started++;
  1556. /* remove this named plugin from other plugins lists */
  1557. for(i=0; i<total_plugins; i++)
  1558. {
  1559. index = 0;
  1560. while(index < config[i].total_named)
  1561. {
  1562. if((config[i].depends_named_list)[index] != 0 && !slapi_UTF8CASECMP((config[i].depends_named_list)[index], config[plugin_index].name))
  1563. {
  1564. slapi_ch_free((void**)&((config[i].depends_named_list)[index]));
  1565. (config[i].depends_named_list)[index] = 0;
  1566. }
  1567. index++;
  1568. }
  1569. }
  1570. } else {
  1571. pblock_done(&(config[plugin_index].pb));
  1572. }
  1573. /* decrement the type counter for this plugin type */
  1574. decrement_plugin_type(plugin_head, config[plugin_index].type);
  1575. config[plugin_index].op_done = 1;
  1576. num_plg_started++;
  1577. plugins_started = 1;
  1578. }
  1579. }
  1580. }
  1581. if(plugins_started == 0)
  1582. {
  1583. /* a dependency was not resolved - error */
  1584. LDAPDebug( LDAP_DEBUG_ANY, "Error: Failed to resolve plugin dependencies\n" , 0, 0, 0 );
  1585. /* list the plugins yet to perform op */
  1586. i = 0;
  1587. while(i < total_plugins)
  1588. {
  1589. if(config[i].op_done == 0)
  1590. {
  1591. LDAPDebug( LDAP_DEBUG_ANY, "Error: %s plugin %s is not started\n" , config[i].type, config[i].name, 0 );
  1592. }
  1593. i++;
  1594. }
  1595. exit(1);
  1596. }
  1597. /*
  1598. * need the details in config to hang around for shutdown
  1599. * config itself may be deleted since its contents have been
  1600. * copied by value to the shutdown list
  1601. */
  1602. plugin_free_plugin_dep_config(&config);
  1603. /* Finally enable registered plugin functions */
  1604. global_plugin_callbacks_enabled = 1;
  1605. return ret;
  1606. }
  1607. /*
  1608. * plugin_dependency_closeall
  1609. *
  1610. * uses the shutdown list created at startup to close
  1611. * plugins in the correct order
  1612. *
  1613. * For now this leaks the list and contents, but since
  1614. * it hangs around until shutdown anyway, we don't care
  1615. *
  1616. */
  1617. void
  1618. plugin_dependency_closeall()
  1619. {
  1620. Slapi_PBlock pb;
  1621. int plugins_closed = 0;
  1622. int index = 0;
  1623. while(plugins_closed<global_plugins_started)
  1624. {
  1625. /*
  1626. * the first few entries may not be valid
  1627. * since the list was created in the reverse
  1628. * order and some plugins may have been counted
  1629. * for the purpose of list allocation but are
  1630. * disabled and so were never started
  1631. *
  1632. * we check that here
  1633. */
  1634. if(global_plugin_shutdown_order[index].name)
  1635. {
  1636. if(!global_plugin_shutdown_order[index].removed){
  1637. pblock_init(&pb);
  1638. plugin_set_stopped(global_plugin_shutdown_order[index].plugin);
  1639. plugin_op_all_finished(global_plugin_shutdown_order[index].plugin);
  1640. plugin_call_one( global_plugin_shutdown_order[index].plugin, SLAPI_PLUGIN_CLOSE_FN, &pb);
  1641. /* set plg_closed to 1 to prevent any further plugin pre/post op function calls */
  1642. global_plugin_shutdown_order[index].plugin->plg_closed = 1;
  1643. }
  1644. plugins_closed++;
  1645. }
  1646. index++;
  1647. }
  1648. }
  1649. /***********************************************************
  1650. end of plugin dependency code
  1651. ************************************************************/
  1652. /*
  1653. * Function: plugin_startall
  1654. *
  1655. * Returns: squat
  1656. *
  1657. * Description: Some plugins may need to do some stuff after all the config
  1658. * stuff is done with. So this function goes through and starts all plugins
  1659. */
  1660. void
  1661. plugin_startall(int argc, char** argv, char **plugin_list)
  1662. {
  1663. /* initialize special plugin structures */
  1664. default_plugin_init ();
  1665. plugin_dependency_startall(argc, argv, "plugin startup failed\n",
  1666. SLAPI_PLUGIN_START_FN, plugin_list);
  1667. }
  1668. /*
  1669. * Function: plugin_close_all
  1670. *
  1671. * Returns: squat
  1672. *
  1673. * Description: cleanup routine, allows plugins to kill threads, free memory started in start fn
  1674. *
  1675. */
  1676. void
  1677. plugin_closeall(int close_backends, int close_globals)
  1678. {
  1679. entry_and_plugin_t *iterp, *nextp;
  1680. plugin_dependency_closeall();
  1681. /* free the plugin dependency entry list */
  1682. iterp = dep_plugin_entries;
  1683. while (iterp) {
  1684. nextp = iterp->next;
  1685. slapi_entry_free(iterp->e);
  1686. plugin_free(iterp->plugin);
  1687. slapi_ch_free((void **)&iterp);
  1688. iterp = nextp;
  1689. }
  1690. dep_plugin_entries = NULL;
  1691. }
  1692. static int
  1693. plugin_call_list (struct slapdplugin *list, int operation, Slapi_PBlock *pb)
  1694. {
  1695. return plugin_call_func(list, operation, pb, 0);
  1696. }
  1697. static int
  1698. plugin_call_one (struct slapdplugin *list, int operation, Slapi_PBlock *pb)
  1699. {
  1700. return plugin_call_func(list, operation, pb, 1);
  1701. }
  1702. /*
  1703. * Return codes:
  1704. * - For preoperation plugins, returns the return code passed back from the first
  1705. * plugin that fails, or zero if all plugins succeed.
  1706. * - For bepreop and bepostop plugins, returns a bitwise OR of the return codes
  1707. * returned by all the plugins called (there's only one bepreop and one bepostop
  1708. * in DS 5.0 anyway).
  1709. * - For postoperation plugins, returns 0.
  1710. */
  1711. static int
  1712. plugin_call_func (struct slapdplugin *list, int operation, Slapi_PBlock *pb, int call_one)
  1713. {
  1714. /* Invoke the operation on the plugins that are registered for the subtree effected by the operation. */
  1715. int rc;
  1716. int return_value = 0;
  1717. int count = 0;
  1718. for (; list != NULL; list = list->plg_next)
  1719. {
  1720. IFP func = NULL;
  1721. slapi_pblock_set (pb, SLAPI_PLUGIN, list);
  1722. set_db_default_result_handlers (pb); /* JCM: What's this do? Is it needed here? */
  1723. if (slapi_pblock_get (pb, operation, &func) == 0 &&
  1724. func != NULL &&
  1725. plugin_invoke_plugin_pb (list, operation, pb) &&
  1726. list->plg_closed == 0)
  1727. {
  1728. char *n = list->plg_name;
  1729. LDAPDebug( LDAP_DEBUG_TRACE , "Calling plugin '%s' #%d type %d\n", (n==NULL?"noname":n), count, operation );
  1730. /* counters_to_errors_log("before plugin call"); */
  1731. /*
  1732. * Only call the plugin function if:
  1733. *
  1734. * [1] The plugin is started, and we are NOT trying to restart it.
  1735. * [2] The plugin is started, and we are stopping it.
  1736. * [3] The plugin is stopped, and we are trying to start it.
  1737. *
  1738. * This frees up the plugins from having to check if the plugin is already started when
  1739. * calling the START and CLOSE functions - prevents double starts and stops.
  1740. */
  1741. slapi_plugin_op_started(list);
  1742. if (((SLAPI_PLUGIN_START_FN == operation && !list->plg_started) || /* Starting it up for the first time */
  1743. (SLAPI_PLUGIN_CLOSE_FN == operation && !list->plg_stopped) || /* Shutting down, plugin has been stopped */
  1744. (SLAPI_PLUGIN_START_FN != operation && list->plg_started)) && /* Started, and not trying to start again */
  1745. ( rc = func (pb)) != 0 )
  1746. {
  1747. slapi_plugin_op_finished(list);
  1748. if (SLAPI_PLUGIN_PREOPERATION == list->plg_type ||
  1749. SLAPI_PLUGIN_INTERNAL_PREOPERATION == list->plg_type ||
  1750. SLAPI_PLUGIN_START_FN == operation )
  1751. {
  1752. /*
  1753. * We bail out of plugin processing for preop plugins
  1754. * that return a non-zero return code. This allows preop
  1755. * plugins to cause further preop processing to terminate, and
  1756. * causes the operation to be vetoed.
  1757. */
  1758. return_value = rc;
  1759. break;
  1760. }
  1761. else if (SLAPI_PLUGIN_BEPREOPERATION == list->plg_type ||
  1762. SLAPI_PLUGIN_BETXNPREOPERATION == list->plg_type ||
  1763. SLAPI_PLUGIN_BEPOSTOPERATION == list->plg_type ||
  1764. SLAPI_PLUGIN_BETXNPOSTOPERATION == list->plg_type )
  1765. {
  1766. /*
  1767. * respect fatal error SLAPI_PLUGIN_FAILURE (-1);
  1768. * should not OR it.
  1769. */
  1770. if (SLAPI_PLUGIN_FAILURE == rc) {
  1771. return_value = rc;
  1772. } else if (SLAPI_PLUGIN_FAILURE != return_value) {
  1773. /* OR the result into the return value
  1774. * for be pre/postops */
  1775. return_value |= rc;
  1776. }
  1777. }
  1778. } else {
  1779. if(SLAPI_PLUGIN_CLOSE_FN == operation){
  1780. /* successfully stopped the plugin */
  1781. list->plg_stopped = 1;
  1782. }
  1783. slapi_plugin_op_finished(list);
  1784. }
  1785. /* counters_to_errors_log("after plugin call"); */
  1786. }
  1787. count++;
  1788. if(call_one)
  1789. break;
  1790. }
  1791. return( return_value );
  1792. }
  1793. int
  1794. slapi_berval_cmp (const struct berval* L, const struct berval* R) /* JCM - This does not belong here. But, where should it go? */
  1795. {
  1796. int result = 0;
  1797. if(L == NULL && R != NULL){
  1798. return 1;
  1799. } else if(L != NULL && R == NULL){
  1800. return -1;
  1801. } else if(L == NULL && R == NULL){
  1802. return 0;
  1803. }
  1804. if (L->bv_len < R->bv_len) {
  1805. result = memcmp (L->bv_val, R->bv_val, L->bv_len);
  1806. if (result == 0)
  1807. result = -1;
  1808. } else {
  1809. result = memcmp (L->bv_val, R->bv_val, R->bv_len);
  1810. if (result == 0 && (L->bv_len > R->bv_len))
  1811. result = 1;
  1812. }
  1813. return result;
  1814. }
  1815. static char **supported_saslmechanisms = NULL;
  1816. static Slapi_RWLock *supported_saslmechanisms_lock = NULL;
  1817. /*
  1818. * register a supported SASL mechanism so it will be returned as part of the
  1819. * root DSE.
  1820. */
  1821. void
  1822. slapi_register_supported_saslmechanism( char *mechanism )
  1823. {
  1824. if ( mechanism != NULL ) {
  1825. if (NULL == supported_saslmechanisms_lock) {
  1826. /* This is thread safe, as it gets executed by
  1827. * a single thread at init time (main->init_saslmechanisms) */
  1828. supported_saslmechanisms_lock = slapi_new_rwlock();
  1829. if (NULL == supported_saslmechanisms_lock) {
  1830. /* Out of resources */
  1831. slapi_log_error(SLAPI_LOG_FATAL, "startup",
  1832. "slapi_register_supported_saslmechanism: failed to create lock.\n");
  1833. exit (1);
  1834. }
  1835. }
  1836. slapi_rwlock_wrlock(supported_saslmechanisms_lock);
  1837. charray_add( &supported_saslmechanisms, slapi_ch_strdup( mechanism ));
  1838. slapi_rwlock_unlock(supported_saslmechanisms_lock);
  1839. }
  1840. }
  1841. /*
  1842. * return pointer to NULL-terminated array of supported SASL mechanisms.
  1843. * This function is not MTSafe and should be deprecated.
  1844. * slapi_get_supported_saslmechanisms_copy should be used instead.
  1845. */
  1846. char **
  1847. slapi_get_supported_saslmechanisms( void )
  1848. {
  1849. return( supported_saslmechanisms );
  1850. }
  1851. /*
  1852. * return pointer to NULL-terminated array of supported SASL mechanisms.
  1853. */
  1854. char **
  1855. slapi_get_supported_saslmechanisms_copy( void )
  1856. {
  1857. char ** ret = NULL;
  1858. slapi_rwlock_rdlock(supported_saslmechanisms_lock);
  1859. ret = charray_dup(supported_saslmechanisms);
  1860. slapi_rwlock_unlock(supported_saslmechanisms_lock);
  1861. return( ret );
  1862. }
  1863. static char **supported_extended_ops = NULL;
  1864. static Slapi_RWLock *extended_ops_lock = NULL;
  1865. /*
  1866. * register all of the LDAPv3 extended operations we know about.
  1867. */
  1868. void
  1869. ldapi_init_extended_ops( void )
  1870. {
  1871. extended_ops_lock = slapi_new_rwlock();
  1872. if (NULL == extended_ops_lock) {
  1873. /* Out of resources */
  1874. slapi_log_error(SLAPI_LOG_FATAL, "startup",
  1875. "ldapi_init_extended_ops: failed to create lock.\n");
  1876. exit (1);
  1877. }
  1878. slapi_rwlock_wrlock(extended_ops_lock);
  1879. charray_add(&supported_extended_ops,
  1880. slapi_ch_strdup(EXTOP_BULK_IMPORT_START_OID));
  1881. charray_add(&supported_extended_ops,
  1882. slapi_ch_strdup(EXTOP_BULK_IMPORT_DONE_OID));
  1883. /* add future supported extops here... */
  1884. slapi_rwlock_unlock(extended_ops_lock);
  1885. }
  1886. /*
  1887. * register an extended op. so it can be returned as part of the root DSE.
  1888. */
  1889. void
  1890. ldapi_register_extended_op( char **opoids )
  1891. {
  1892. int i;
  1893. slapi_rwlock_wrlock(extended_ops_lock);
  1894. for ( i = 0; opoids != NULL && opoids[i] != NULL; ++i ) {
  1895. if ( !charray_inlist( supported_extended_ops, opoids[i] )) {
  1896. charray_add( &supported_extended_ops, slapi_ch_strdup( opoids[i] ));
  1897. }
  1898. }
  1899. slapi_rwlock_unlock(extended_ops_lock);
  1900. }
  1901. /*
  1902. * retrieve supported extended operation OIDs
  1903. * return 0 if successful and -1 if not.
  1904. * This function is not MTSafe and should be deprecated.
  1905. * slapi_get_supported_extended_ops_copy should be used instead.
  1906. */
  1907. char **
  1908. slapi_get_supported_extended_ops( void )
  1909. {
  1910. return( supported_extended_ops );
  1911. }
  1912. /*
  1913. * retrieve supported extended operation OIDs
  1914. * return 0 if successful and -1 if not.
  1915. */
  1916. char **
  1917. slapi_get_supported_extended_ops_copy( void )
  1918. {
  1919. char ** ret = NULL;
  1920. slapi_rwlock_rdlock(extended_ops_lock);
  1921. ret = charray_dup(supported_extended_ops);
  1922. slapi_rwlock_unlock(extended_ops_lock);
  1923. return( ret );
  1924. }
  1925. /*
  1926. looks up the given string type to convert to the internal integral type; also
  1927. returns the plugin list associated with the plugin type
  1928. returns 0 upon success and non-zero upon failure
  1929. */
  1930. static int
  1931. plugin_get_type_and_list(
  1932. const char *plugintype,
  1933. int *type,
  1934. struct slapdplugin ***plugin_list
  1935. )
  1936. {
  1937. int plugin_list_index = -1;
  1938. if ( strcasecmp( plugintype, "database" ) == 0 ) {
  1939. *type = SLAPI_PLUGIN_DATABASE;
  1940. plugin_list_index= PLUGIN_LIST_DATABASE;
  1941. } else if ( strcasecmp( plugintype, "extendedop" ) == 0 ) {
  1942. *type = SLAPI_PLUGIN_EXTENDEDOP;
  1943. plugin_list_index= PLUGIN_LIST_EXTENDED_OPERATION;
  1944. } else if ( strcasecmp( plugintype, "preoperation" ) == 0 ) {
  1945. *type = SLAPI_PLUGIN_PREOPERATION;
  1946. plugin_list_index= PLUGIN_LIST_PREOPERATION;
  1947. } else if ( strcasecmp( plugintype, "postoperation" ) == 0 ) {
  1948. *type = SLAPI_PLUGIN_POSTOPERATION;
  1949. plugin_list_index= PLUGIN_LIST_POSTOPERATION;
  1950. } else if ( strcasecmp( plugintype, "matchingrule" ) == 0 ) {
  1951. *type = SLAPI_PLUGIN_MATCHINGRULE;
  1952. plugin_list_index= PLUGIN_LIST_MATCHINGRULE;
  1953. } else if ( strcasecmp( plugintype, "syntax" ) == 0 ) {
  1954. *type = SLAPI_PLUGIN_SYNTAX;
  1955. plugin_list_index= PLUGIN_LIST_SYNTAX;
  1956. } else if ( strcasecmp( plugintype, "accesscontrol" ) == 0 ) {
  1957. *type = SLAPI_PLUGIN_ACL;
  1958. plugin_list_index= PLUGIN_LIST_ACL;
  1959. } else if ( strcasecmp( plugintype, "bepreoperation" ) == 0 ) {
  1960. *type = SLAPI_PLUGIN_BEPREOPERATION;
  1961. plugin_list_index= PLUGIN_LIST_BEPREOPERATION;
  1962. } else if ( strcasecmp( plugintype, "bepostoperation" ) == 0 ) {
  1963. *type = SLAPI_PLUGIN_BEPOSTOPERATION;
  1964. plugin_list_index= PLUGIN_LIST_BEPOSTOPERATION;
  1965. } else if ( strcasecmp( plugintype, "betxnpreoperation" ) == 0 ) {
  1966. *type = SLAPI_PLUGIN_BETXNPREOPERATION;
  1967. plugin_list_index= PLUGIN_LIST_BETXNPREOPERATION;
  1968. } else if ( strcasecmp( plugintype, "betxnpostoperation" ) == 0 ) {
  1969. *type = SLAPI_PLUGIN_BETXNPOSTOPERATION;
  1970. plugin_list_index= PLUGIN_LIST_BETXNPOSTOPERATION;
  1971. } else if ( strcasecmp( plugintype, "internalpreoperation" ) == 0 ) {
  1972. *type = SLAPI_PLUGIN_INTERNAL_PREOPERATION;
  1973. plugin_list_index= PLUGIN_LIST_INTERNAL_PREOPERATION;
  1974. } else if ( strcasecmp( plugintype, "internalpostoperation" ) == 0 ) {
  1975. *type = SLAPI_PLUGIN_INTERNAL_POSTOPERATION;
  1976. plugin_list_index= PLUGIN_LIST_INTERNAL_POSTOPERATION;
  1977. } else if ( strcasecmp( plugintype, "entry" ) == 0 ) {
  1978. *type = SLAPI_PLUGIN_ENTRY;
  1979. plugin_list_index= PLUGIN_LIST_ENTRY;
  1980. } else if ( strcasecmp( plugintype, "object" ) == 0 ) {
  1981. *type = SLAPI_PLUGIN_TYPE_OBJECT;
  1982. plugin_list_index= PLUGIN_LIST_OBJECT;
  1983. } else if ( strcasecmp( plugintype, "pwdstoragescheme" ) == 0 ) {
  1984. *type = SLAPI_PLUGIN_PWD_STORAGE_SCHEME;
  1985. plugin_list_index= PLUGIN_LIST_PWD_STORAGE_SCHEME;
  1986. } else if ( strcasecmp( plugintype, "reverpwdstoragescheme" ) == 0 ) {
  1987. *type = SLAPI_PLUGIN_REVER_PWD_STORAGE_SCHEME;
  1988. plugin_list_index= PLUGIN_LIST_REVER_PWD_STORAGE_SCHEME;
  1989. } else if ( strcasecmp( plugintype, "vattrsp" ) == 0 ) {
  1990. *type = SLAPI_PLUGIN_VATTR_SP;
  1991. plugin_list_index= PLUGIN_LIST_VATTR_SP;
  1992. } else if ( strcasecmp( plugintype, "ldbmentryfetchstore" ) == 0 ) {
  1993. *type = SLAPI_PLUGIN_LDBM_ENTRY_FETCH_STORE;
  1994. plugin_list_index= PLUGIN_LIST_LDBM_ENTRY_FETCH_STORE;
  1995. } else if ( strcasecmp( plugintype, "index" ) == 0 ) {
  1996. *type = SLAPI_PLUGIN_INDEX;
  1997. plugin_list_index= PLUGIN_LIST_INDEX;
  1998. } else if ( strcasecmp( plugintype, "betxnextendedop" ) == 0 ) {
  1999. *type = SLAPI_PLUGIN_BETXNEXTENDEDOP;
  2000. plugin_list_index= PLUGIN_LIST_BE_TXN_EXTENDED_OPERATION;
  2001. } else if ( strcasecmp( plugintype, "preextendedop" ) == 0 ) {
  2002. *type = SLAPI_PLUGIN_PREEXTOPERATION;
  2003. plugin_list_index= PLUGIN_LIST_PREEXTENDED_OPERATION;
  2004. } else if ( strcasecmp( plugintype, "postextendedop" ) == 0 ) {
  2005. *type = SLAPI_PLUGIN_POSTEXTOPERATION;
  2006. plugin_list_index= PLUGIN_LIST_POSTEXTENDED_OPERATION;
  2007. } else {
  2008. return( 1 ); /* unknown plugin type - pass to backend */
  2009. }
  2010. if (plugin_list_index >= 0)
  2011. *plugin_list = &global_plugin_list[plugin_list_index];
  2012. return 0;
  2013. }
  2014. static char *
  2015. plugin_get_type_str( int type )
  2016. {
  2017. if ( type == SLAPI_PLUGIN_DATABASE){
  2018. return "database";
  2019. } else if ( type == SLAPI_PLUGIN_EXTENDEDOP){
  2020. return "extendedop";
  2021. } else if ( type == SLAPI_PLUGIN_PREOPERATION){
  2022. return "preoperation";
  2023. } else if ( type == SLAPI_PLUGIN_POSTOPERATION){
  2024. return "postoperation";
  2025. } else if ( type == SLAPI_PLUGIN_MATCHINGRULE){
  2026. return "matchingrule";
  2027. } else if ( type == SLAPI_PLUGIN_SYNTAX){
  2028. return "syntax";
  2029. } else if ( type == SLAPI_PLUGIN_ACL){
  2030. return "accesscontrol";
  2031. } else if ( type == SLAPI_PLUGIN_BEPREOPERATION){
  2032. return "bepreoperation";
  2033. } else if ( type == SLAPI_PLUGIN_BEPOSTOPERATION){
  2034. return "bepostoperation";
  2035. } else if ( type == SLAPI_PLUGIN_BETXNPREOPERATION){
  2036. return "betxnpreoperation";
  2037. } else if ( type == SLAPI_PLUGIN_BETXNPOSTOPERATION){
  2038. return "betxnpostoperation";
  2039. } else if ( type == SLAPI_PLUGIN_INTERNAL_PREOPERATION){
  2040. return "internalpreoperation";
  2041. } else if ( type == SLAPI_PLUGIN_INTERNAL_POSTOPERATION){
  2042. return "internalpostoperation";
  2043. } else if ( type == SLAPI_PLUGIN_ENTRY){
  2044. return "entry";
  2045. } else if ( type == SLAPI_PLUGIN_TYPE_OBJECT){
  2046. return "object";
  2047. } else if ( type == SLAPI_PLUGIN_PWD_STORAGE_SCHEME){
  2048. return "pwdstoragescheme";
  2049. } else if ( type == SLAPI_PLUGIN_REVER_PWD_STORAGE_SCHEME){
  2050. return "reverpwdstoragescheme";
  2051. } else if ( type == SLAPI_PLUGIN_VATTR_SP){
  2052. return "vattrsp";
  2053. } else if ( type == SLAPI_PLUGIN_LDBM_ENTRY_FETCH_STORE){
  2054. return "ldbmentryfetchstore";
  2055. } else if ( type == SLAPI_PLUGIN_INDEX){
  2056. return "index";
  2057. } else {
  2058. return NULL; /* unknown plugin type - pass to backend */
  2059. }
  2060. }
  2061. static const char *
  2062. plugin_exists(const Slapi_DN *plugin_dn)
  2063. {
  2064. /* check to see if the plugin name is unique */
  2065. const char *retval = 0;
  2066. if (global_plugin_dns && PL_HashTableLookup(global_plugin_dns,
  2067. slapi_sdn_get_ndn(plugin_dn)))
  2068. {
  2069. retval = slapi_sdn_get_dn(plugin_dn);
  2070. }
  2071. return retval;
  2072. }
  2073. /*
  2074. * A plugin config change has occurred, restart the plugin (delete/add).
  2075. * If something goes wrong, revert to the original plugin entry.
  2076. */
  2077. int
  2078. plugin_restart(Slapi_Entry *pentryBefore, Slapi_Entry *pentryAfter)
  2079. {
  2080. char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
  2081. int rc = LDAP_SUCCESS;
  2082. /*
  2083. * We can not restart a critical plugin, but the operation should still
  2084. * be allowed
  2085. */
  2086. if(plugin_is_critical(pentryBefore)){
  2087. LDAPDebug(LDAP_DEBUG_ANY, "plugin_restart: Plugin (%s) is critical "
  2088. "to server operation. Server requires restart for changes to "
  2089. "take effect.\n", slapi_entry_get_dn(pentryBefore),0,0);
  2090. return 0;
  2091. }
  2092. slapi_rwlock_wrlock(global_rwlock);
  2093. slapi_td_set_plugin_locked();
  2094. if(plugin_delete(pentryBefore, returntext, 1) == LDAP_SUCCESS){
  2095. if(plugin_add(pentryAfter, returntext, 1) == LDAP_SUCCESS){
  2096. LDAPDebug(LDAP_DEBUG_PLUGIN, "plugin_restart: Plugin (%s) has been successfully "
  2097. "restarted after configuration change.\n",
  2098. slapi_entry_get_dn(pentryAfter),0,0);
  2099. } else {
  2100. LDAPDebug(LDAP_DEBUG_ANY, "plugin_restart: Plugin (%s) failed to restart after "
  2101. "configuration change (%s). Reverting to original plugin entry.\n",
  2102. slapi_entry_get_dn(pentryAfter), returntext, 0);
  2103. if(plugin_add(pentryBefore, returntext, 1) != LDAP_SUCCESS){
  2104. LDAPDebug(LDAP_DEBUG_ANY, "plugin_restart: Plugin (%s) failed to reload "
  2105. "original plugin (%s)\n",slapi_entry_get_dn(pentryBefore), returntext, 0);
  2106. }
  2107. rc = 1;
  2108. }
  2109. } else {
  2110. LDAPDebug(LDAP_DEBUG_ANY,"plugin_restart: failed to disable/stop the plugin (%s): %s\n",
  2111. slapi_entry_get_dn(pentryBefore), returntext, 0);
  2112. rc = 1;
  2113. }
  2114. slapi_rwlock_unlock(global_rwlock);
  2115. slapi_td_set_plugin_unlocked();
  2116. return rc;
  2117. }
  2118. static int
  2119. plugin_set_subtree_config(PluginTargetData *subtree_config, const char *val)
  2120. {
  2121. int status = 0;
  2122. if (strcasecmp (val, ALL_DATA) == 0) /* allow access to both local and remote data */
  2123. {
  2124. plugin_set_global (subtree_config);
  2125. }
  2126. else if (strcasecmp (val, LOCAL_DATA) == 0) /* allow access to all locally hosted data */
  2127. {
  2128. ptd_set_special_data (subtree_config, PLGC_DATA_LOCAL);
  2129. }
  2130. else if (strcasecmp (val, REMOTE_DATA) == 0)/* allow access to requests for remote data */
  2131. {
  2132. ptd_set_special_data (subtree_config, PLGC_DATA_REMOTE);
  2133. }
  2134. else /* dn */
  2135. {
  2136. ptd_add_subtree (subtree_config, slapi_sdn_new_dn_byval(val));
  2137. }
  2138. /* I suppose we could check the val at this point to make sure
  2139. its a valid DN . . . */
  2140. return status;
  2141. }
  2142. static int
  2143. set_plugin_config_from_entry(
  2144. const Slapi_Entry *plugin_entry,
  2145. struct slapdplugin *plugin
  2146. )
  2147. {
  2148. struct pluginconfig *config = &plugin->plg_conf;
  2149. char *value = 0;
  2150. char **values = 0;
  2151. int i = 0;
  2152. int status = 0;
  2153. PRBool target_seen = PR_FALSE;
  2154. PRBool bind_seen = PR_FALSE;
  2155. if ((value = slapi_entry_attr_get_charptr(plugin_entry,
  2156. ATTR_PLUGIN_SCHEMA_CHECK)) != NULL)
  2157. {
  2158. if (plugin_config_set_action(&config->plgc_schema_check, value))
  2159. {
  2160. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2161. "from entry %s\n", value, ATTR_PLUGIN_SCHEMA_CHECK,
  2162. slapi_entry_get_dn_const(plugin_entry));
  2163. status = 1;
  2164. }
  2165. slapi_ch_free((void**)&value);
  2166. }
  2167. if ((value = slapi_entry_attr_get_charptr(plugin_entry,
  2168. ATTR_PLUGIN_LOG_ACCESS)) != NULL)
  2169. {
  2170. if (plugin_config_set_action(&config->plgc_log_access, value))
  2171. {
  2172. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2173. "from entry %s\n", value, ATTR_PLUGIN_LOG_ACCESS,
  2174. slapi_entry_get_dn_const(plugin_entry));
  2175. status = 1;
  2176. }
  2177. slapi_ch_free((void**)&value);
  2178. }
  2179. if ((value = slapi_entry_attr_get_charptr(plugin_entry,
  2180. ATTR_PLUGIN_LOG_AUDIT)) != NULL)
  2181. {
  2182. if (plugin_config_set_action(&config->plgc_log_audit, value))
  2183. {
  2184. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2185. "from entry %s\n", value, ATTR_PLUGIN_LOG_AUDIT,
  2186. slapi_entry_get_dn_const(plugin_entry));
  2187. status = 1;
  2188. }
  2189. slapi_ch_free((void**)&value);
  2190. }
  2191. if ((value = slapi_entry_attr_get_charptr(plugin_entry,
  2192. ATTR_PLUGIN_INVOKE_FOR_REPLOP)) != NULL)
  2193. {
  2194. if (plugin_config_set_action(&config->plgc_invoke_for_replop, value))
  2195. {
  2196. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2197. "from entry %s\n", value, ATTR_PLUGIN_INVOKE_FOR_REPLOP,
  2198. slapi_entry_get_dn_const(plugin_entry));
  2199. status = 1;
  2200. }
  2201. slapi_ch_free((void**)&value);
  2202. }
  2203. values = slapi_entry_attr_get_charray(plugin_entry,
  2204. ATTR_PLUGIN_TARGET_SUBTREE);
  2205. for (i=0; values && values[i]; i++)
  2206. {
  2207. if (plugin_set_subtree_config(&(config->plgc_target_subtrees), values[i]))
  2208. {
  2209. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2210. "from entry %s\n", values[i], ATTR_PLUGIN_TARGET_SUBTREE,
  2211. slapi_entry_get_dn_const(plugin_entry));
  2212. status = 1;
  2213. break;
  2214. }
  2215. else
  2216. {
  2217. target_seen = PR_TRUE;
  2218. }
  2219. }
  2220. slapi_ch_array_free(values);
  2221. values = slapi_entry_attr_get_charray(plugin_entry,
  2222. ATTR_PLUGIN_EXCLUDE_TARGET_SUBTREE);
  2223. for (i=0; values && values[i]; i++)
  2224. {
  2225. if (plugin_set_subtree_config(&(config->plgc_excluded_target_subtrees), values[i]))
  2226. {
  2227. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2228. "from entry %s\n", values[i], ATTR_PLUGIN_EXCLUDE_TARGET_SUBTREE,
  2229. slapi_entry_get_dn_const(plugin_entry));
  2230. status = 1;
  2231. break;
  2232. }
  2233. }
  2234. slapi_ch_array_free(values);
  2235. values = slapi_entry_attr_get_charray(plugin_entry,
  2236. ATTR_PLUGIN_BIND_SUBTREE);
  2237. for (i=0; values && values[i]; i++)
  2238. {
  2239. if (plugin_set_subtree_config(&(config->plgc_bind_subtrees), values[i]))
  2240. {
  2241. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2242. "from entry %s\n", values[i], ATTR_PLUGIN_BIND_SUBTREE,
  2243. slapi_entry_get_dn_const(plugin_entry));
  2244. status = 1;
  2245. break;
  2246. }
  2247. else
  2248. {
  2249. bind_seen = PR_TRUE;
  2250. }
  2251. }
  2252. slapi_ch_array_free(values);
  2253. values = slapi_entry_attr_get_charray(plugin_entry,
  2254. ATTR_PLUGIN_EXCLUDE_BIND_SUBTREE);
  2255. for (i=0; values && values[i]; i++)
  2256. {
  2257. if (plugin_set_subtree_config(&(config->plgc_excluded_bind_subtrees), values[i]))
  2258. {
  2259. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: invalid value %s for attribute %s "
  2260. "from entry %s\n", values[i], ATTR_PLUGIN_EXCLUDE_BIND_SUBTREE,
  2261. slapi_entry_get_dn_const(plugin_entry));
  2262. status = 1;
  2263. break;
  2264. }
  2265. }
  2266. slapi_ch_array_free(values);
  2267. /* set target subtree default - allow access to all data */
  2268. if (!target_seen)
  2269. {
  2270. plugin_set_global(&(config->plgc_target_subtrees));
  2271. }
  2272. /* set bind subtree default - allow access to local data only */
  2273. if (!bind_seen)
  2274. {
  2275. ptd_set_special_data(&(config->plgc_bind_subtrees), PLGC_DATA_LOCAL);
  2276. ptd_set_special_data(&(config->plgc_bind_subtrees), PLGC_DATA_REMOTE);
  2277. }
  2278. return status;
  2279. }
  2280. /* This function is called after the plugin init function has been called
  2281. which fills in the desc part of the plugin
  2282. */
  2283. static int
  2284. add_plugin_description(Slapi_Entry *e, const char *attrname, char *val)
  2285. {
  2286. struct berval desc;
  2287. struct berval *newval[2] = {0, 0};
  2288. int status = 0;
  2289. desc.bv_val = SLAPI_PLUGIN_NONE_IF_NULL( val );
  2290. desc.bv_len = strlen(desc.bv_val);
  2291. newval[0] = &desc;
  2292. if ((status = entry_replace_values(e, attrname, newval)) != 0)
  2293. {
  2294. LDAPDebug(LDAP_DEBUG_PLUGIN, "Error: failed to add value %s to "
  2295. "attribute %s of entry %s\n", val, attrname,
  2296. slapi_entry_get_dn_const(e));
  2297. status = 1;
  2298. }
  2299. return status;
  2300. }
  2301. /*
  2302. * The plugin initfunc sets some vendor and version information in the plugin.
  2303. * This function extracts that and adds it as attributes to `e'. If
  2304. * `plugin' is NULL, the plugin is located based on the DN in `e'.
  2305. *
  2306. * Returns 0 if all goes well and 1 if not.
  2307. */
  2308. int
  2309. plugin_add_descriptive_attributes( Slapi_Entry *e, struct slapdplugin *plugin )
  2310. {
  2311. int status = 0;
  2312. if ( NULL == plugin ) {
  2313. int i;
  2314. const Slapi_DN *ednp = slapi_entry_get_sdn_const( e );
  2315. Slapi_DN pdn;
  2316. struct slapdplugin *plugtmp;
  2317. for( i = 0; NULL == plugin && i < PLUGIN_LIST_GLOBAL_MAX; ++i )
  2318. {
  2319. for ( plugtmp = global_plugin_list[i]; NULL == plugin && plugtmp;
  2320. plugtmp = plugtmp->plg_next)
  2321. {
  2322. slapi_sdn_init_normdn_byref( &pdn, plugtmp->plg_dn );
  2323. if ( 0 == slapi_sdn_compare( &pdn, ednp ))
  2324. {
  2325. plugin = plugtmp;
  2326. }
  2327. slapi_sdn_done( &pdn );
  2328. }
  2329. }
  2330. if ( NULL == plugin )
  2331. {
  2332. /* This can happen for things such as disabled syntax plug-ins. We
  2333. * just treat this as a warning to allow the description attributes
  2334. * to be set to a default value to avoid an objectclass violation. */
  2335. LDAPDebug(LDAP_DEBUG_PLUGIN,
  2336. "Warning: couldn't find plugin %s in global list. "
  2337. "Adding default descriptive values.\n",
  2338. slapi_entry_get_dn_const(e), 0, 0 );
  2339. }
  2340. }
  2341. if (add_plugin_description(e, ATTR_PLUGIN_PLUGINID,
  2342. plugin ? plugin->plg_desc.spd_id : NULL))
  2343. {
  2344. status = 1;
  2345. }
  2346. if (add_plugin_description(e, ATTR_PLUGIN_VERSION,
  2347. plugin ? plugin->plg_desc.spd_version : NULL))
  2348. {
  2349. status = 1;
  2350. }
  2351. if (add_plugin_description(e, ATTR_PLUGIN_VENDOR,
  2352. plugin ? plugin->plg_desc.spd_vendor: NULL))
  2353. {
  2354. status = 1;
  2355. }
  2356. if (add_plugin_description(e, ATTR_PLUGIN_DESC,
  2357. plugin ? plugin->plg_desc.spd_description : NULL))
  2358. {
  2359. status = 1;
  2360. }
  2361. return status;
  2362. }
  2363. /*
  2364. clean up the memory associated with the plugin
  2365. */
  2366. static void
  2367. plugin_free(struct slapdplugin *plugin)
  2368. {
  2369. slapi_log_error(SLAPI_LOG_TRACE, "plugin_free", "Freeing %s \n", plugin->plg_name );
  2370. charray_free(plugin->plg_argv);
  2371. slapi_ch_free_string(&plugin->plg_libpath);
  2372. slapi_ch_free_string(&plugin->plg_initfunc);
  2373. slapi_ch_free_string(&plugin->plg_name);
  2374. slapi_ch_free_string(&plugin->plg_dn);
  2375. if (plugin->plg_type == SLAPI_PLUGIN_PWD_STORAGE_SCHEME) {
  2376. slapi_ch_free_string(&plugin->plg_pwdstorageschemename);
  2377. }
  2378. release_componentid(plugin->plg_identity);
  2379. slapi_counter_destroy(&plugin->plg_op_counter);
  2380. if (!plugin->plg_group)
  2381. plugin_config_cleanup(&plugin->plg_conf);
  2382. slapi_ch_free((void**)&plugin);
  2383. }
  2384. /***********************************
  2385. This is the main entry point for plugin configuration. The plugin_entry argument
  2386. should already contain the necessary fields required to initialize the plugin and
  2387. to give it a proper name in the plugin configuration DIT.
  2388. Argument:
  2389. Slapi_Entry *plugin_entry - the required attributes are
  2390. dn: the dn of the plugin entry
  2391. cn: the unique name of the plugin
  2392. nsslapd-pluginType: one of the several recognized plugin types e.g. "postoperation"
  2393. if p_initfunc is given, pluginPath and pluginInitFunc are optional
  2394. nsslapd-pluginPath: full path and file name of the dll implementing the plugin
  2395. nsslapd-pluginInitFunc: the name of the plugin initialization function
  2396. the optional attributes are:
  2397. nsslapd-pluginArg0
  2398. ...
  2399. nsslapd-pluginArg[N-1] - the (old style) arguments to the plugin, where N varies
  2400. from 0 to the number of arguments. The numbers must be consecutive i.e. no
  2401. skipping
  2402. Instead of using nsslapd-pluginArgN, it is encouraged for you to use named
  2403. parameters e.g.
  2404. nsslapd-tweakThis: 1
  2405. nsslapd-tweakThat: 2
  2406. etc.
  2407. nsslapd-pluginEnabled: "on"|"off" - by default, the plugin will be enabled unless
  2408. this attribute is present and has the value "off"
  2409. for other known attributes, see set_plugin_config_from_entry() above
  2410. all other attributes will be ignored
  2411. The reason this parameter is not const is because it may be modified. This
  2412. function will modify it if the plugin init function is called successfully
  2413. to add the description attributes, and the plugin init function may modify
  2414. it as well.
  2415. Argument:
  2416. group - the group to which this plugin will belong - each member of a plugin group
  2417. shares the pluginconfig of the group leader; refer to the function plugin_get_config
  2418. for more information
  2419. Argument:
  2420. add_entry - if true, the entry will be added to the DIT using the given
  2421. DN in the plugin_entry - this is the default behavior; if false, the
  2422. plugin entry will not show up in the DIT
  2423. ************************************/
  2424. int
  2425. plugin_setup(Slapi_Entry *plugin_entry, struct slapi_componentid *group,
  2426. slapi_plugin_init_fnptr p_initfunc, int add_entry, char *returntext)
  2427. {
  2428. int ii = 0;
  2429. char attrname[SLAPD_TYPICAL_ATTRIBUTE_NAME_MAX_LENGTH];
  2430. char *value = NULL;
  2431. char **values = NULL;
  2432. struct slapdplugin *plugin = NULL;
  2433. struct slapdplugin **plugin_list = NULL;
  2434. struct slapi_componentid *cid = NULL;
  2435. const char *existname = 0;
  2436. slapi_plugin_init_fnptr initfunc = p_initfunc;
  2437. Slapi_PBlock pb;
  2438. int status = 0;
  2439. int enabled = 1;
  2440. char *configdir = 0;
  2441. int skipped;
  2442. attrname[0] = '\0';
  2443. if (!slapi_entry_get_sdn_const(plugin_entry))
  2444. {
  2445. LDAPDebug0Args(LDAP_DEBUG_ANY, "plugin_setup: DN is missing from the plugin.\n");
  2446. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Plugin is missing dn.");
  2447. return -1;
  2448. }
  2449. if ((existname = plugin_exists(slapi_entry_get_sdn_const(plugin_entry))) != NULL)
  2450. {
  2451. LDAPDebug(LDAP_DEBUG_ANY, "plugin_setup: the plugin named %s already exists, "
  2452. "or is already setup.\n", existname, 0, 0);
  2453. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,
  2454. "the plugin named %s already exists, or is already setup.", existname);
  2455. return -1;
  2456. }
  2457. /*
  2458. * create a new plugin structure, fill it in, and prepare to
  2459. * call the plugin's init function. the init function will
  2460. * set the plugin function pointers.
  2461. */
  2462. plugin = (struct slapdplugin *)slapi_ch_calloc(1, sizeof(struct slapdplugin));
  2463. plugin->plg_dn = slapi_ch_strdup(slapi_entry_get_ndn(plugin_entry));
  2464. plugin->plg_closed = 0;
  2465. if (!(value = slapi_entry_attr_get_charptr(plugin_entry,
  2466. ATTR_PLUGIN_TYPE)))
  2467. {
  2468. /* error: required attribute %s missing */
  2469. LDAPDebug(LDAP_DEBUG_ANY, "Error: required attribute %s is missing from entry \"%s\"\n",
  2470. ATTR_PLUGIN_TYPE, slapi_entry_get_dn_const(plugin_entry), 0);
  2471. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,"required attribute %s is missing from entry",
  2472. ATTR_PLUGIN_TYPE);
  2473. status = -1;
  2474. goto PLUGIN_CLEANUP;
  2475. }
  2476. else
  2477. {
  2478. status = plugin_get_type_and_list(value, &plugin->plg_type,
  2479. &plugin_list);
  2480. if ( status != 0 ) {
  2481. /* error: unknown plugin type */
  2482. LDAPDebug(LDAP_DEBUG_ANY, "Error: unknown plugin type \"%s\" in entry \"%s\"\n",
  2483. value, slapi_entry_get_dn_const(plugin_entry), 0);
  2484. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "unknown plugin type \"%s\" in entry", value);
  2485. slapi_ch_free_string(&value);
  2486. status = -1;
  2487. goto PLUGIN_CLEANUP;
  2488. }
  2489. slapi_ch_free_string(&value);
  2490. }
  2491. if (!status &&
  2492. !(value = slapi_entry_attr_get_charptr(plugin_entry, "cn")))
  2493. {
  2494. /* error: required attribute %s missing */
  2495. LDAPDebug(LDAP_DEBUG_ANY, "Error: required attribute %s is missing from entry \"%s\"\n",
  2496. "cn", slapi_entry_get_dn_const(plugin_entry), 0);
  2497. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "required attribute \"cn\" is missing from entry");
  2498. status = -1;
  2499. goto PLUGIN_CLEANUP;
  2500. }
  2501. else
  2502. {
  2503. /* plg_name is normalized once here */
  2504. plugin->plg_name = slapi_create_rdn_value("%s", value);
  2505. slapi_ch_free((void**)&value);
  2506. }
  2507. if (!(value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_PRECEDENCE)))
  2508. {
  2509. /* A precedence isn't set, so just use the default. */
  2510. plugin->plg_precedence = PLUGIN_DEFAULT_PRECEDENCE;
  2511. }
  2512. else
  2513. {
  2514. /* A precedence was set, so let's make sure it's valid. */
  2515. int precedence = 0;
  2516. char *endptr = NULL;
  2517. /* Convert the value. */
  2518. precedence = strtol(value, &endptr, 10);
  2519. /* Make sure the precedence is within our valid
  2520. * range and that we had no conversion errors. */
  2521. if ((*value == '\0') || (*endptr != '\0') ||
  2522. (precedence < PLUGIN_MIN_PRECEDENCE) || (precedence > PLUGIN_MAX_PRECEDENCE))
  2523. {
  2524. LDAPDebug(LDAP_DEBUG_ANY, "Error: value for attribute %s must be "
  2525. "an integer between %d and %d\n", ATTR_PLUGIN_PRECEDENCE,
  2526. PLUGIN_MIN_PRECEDENCE, PLUGIN_MAX_PRECEDENCE);
  2527. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "value for attribute %s must be "
  2528. "an integer between %d and %d.", ATTR_PLUGIN_PRECEDENCE,
  2529. PLUGIN_MIN_PRECEDENCE, PLUGIN_MAX_PRECEDENCE);
  2530. status = -1;
  2531. slapi_ch_free((void**)&value);
  2532. goto PLUGIN_CLEANUP;
  2533. }
  2534. else
  2535. {
  2536. plugin->plg_precedence = precedence;
  2537. }
  2538. slapi_ch_free((void**)&value);
  2539. }
  2540. if (!(value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_INITFN)))
  2541. {
  2542. if (!initfunc)
  2543. {
  2544. /* error: required attribute %s missing */
  2545. LDAPDebug(LDAP_DEBUG_ANY, "Error: required attribute %s is missing from entry \"%s\"\n",
  2546. ATTR_PLUGIN_INITFN, slapi_entry_get_dn_const(plugin_entry), 0);
  2547. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"required attribute %s is missing from entry.",
  2548. ATTR_PLUGIN_INITFN);
  2549. status = -1;
  2550. goto PLUGIN_CLEANUP;
  2551. }
  2552. }
  2553. else
  2554. {
  2555. plugin->plg_initfunc = value; /* plugin owns value's memory now, don't free */
  2556. }
  2557. if (!initfunc)
  2558. {
  2559. PRBool loadNow = PR_FALSE;
  2560. PRBool loadGlobal = PR_FALSE;
  2561. if (!(value = slapi_entry_attr_get_charptr(plugin_entry,
  2562. ATTR_PLUGIN_PATH)))
  2563. {
  2564. /* error: required attribute %s missing */
  2565. LDAPDebug(LDAP_DEBUG_ANY, "Error: required attribute %s is missing from entry \"%s\"\n",
  2566. ATTR_PLUGIN_PATH, slapi_entry_get_dn_const(plugin_entry), 0);
  2567. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "required attribute %s is missing from entry.",
  2568. ATTR_PLUGIN_PATH);
  2569. status = -1;
  2570. goto PLUGIN_CLEANUP;
  2571. }
  2572. else
  2573. {
  2574. plugin->plg_libpath = value; /* plugin owns value's memory now, don't free */
  2575. }
  2576. loadNow = slapi_entry_attr_get_bool(plugin_entry, ATTR_PLUGIN_LOAD_NOW);
  2577. loadGlobal = slapi_entry_attr_get_bool(plugin_entry, ATTR_PLUGIN_LOAD_GLOBAL);
  2578. /*
  2579. * load the plugin's init function
  2580. */
  2581. if ((initfunc = (slapi_plugin_init_fnptr)sym_load_with_flags(plugin->plg_libpath,
  2582. plugin->plg_initfunc, plugin->plg_name, 1 /* report errors */,
  2583. loadNow, loadGlobal)) == NULL)
  2584. {
  2585. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Failed to load plugin's init function.");
  2586. status = -1;
  2587. goto PLUGIN_CLEANUP;
  2588. }
  2589. }
  2590. if (!status && group) /* uses group's config; see plugin_get_config */
  2591. {
  2592. struct slapi_componentid * cid = (struct slapi_componentid *) group;
  2593. plugin->plg_group = (struct slapdplugin *) cid->sci_plugin;
  2594. }
  2595. else if (!status) /* using own config */
  2596. {
  2597. plugin_config_init(&(plugin->plg_conf));
  2598. set_plugin_config_from_entry(plugin_entry, plugin);
  2599. }
  2600. /*
  2601. * If this is a registered plugin function, then set the plugin id so we can remove
  2602. * this plugin later if needed.
  2603. */
  2604. if(group){
  2605. plugin->plg_id = group->sci_component_name;
  2606. }
  2607. /* add the plugin arguments */
  2608. value = 0;
  2609. ii = 0;
  2610. PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ii);
  2611. skipped = 0;
  2612. #define MAXSKIPPED 10 /* Max allowed missing args */
  2613. do {
  2614. /*
  2615. * nsslapd-pluginarg0: val0
  2616. * nsslapd-pluginarg0: val00
  2617. * nsslapd-pluginarg2: val2
  2618. * nsslapd-pluginarg5: val5
  2619. * ==>
  2620. * treated as
  2621. * nsslapd-pluginarg0: val0
  2622. * nsslapd-pluginarg1: val00
  2623. * nsslapd-pluginarg2: val2
  2624. * nsslapd-pluginarg3: val5
  2625. */
  2626. char **vp = values = slapi_entry_attr_get_charray(plugin_entry, attrname);
  2627. if (values) {
  2628. charray_add(&plugin->plg_argv, slapi_ch_strdup(*vp));
  2629. plugin->plg_argc++;
  2630. for (vp++; vp && *vp; vp++) {
  2631. charray_add(&plugin->plg_argv, slapi_ch_strdup(*vp));
  2632. plugin->plg_argc++;
  2633. }
  2634. charray_free(values);
  2635. } else {
  2636. skipped++;
  2637. }
  2638. PR_snprintf(attrname, sizeof(attrname), "%s%d", ATTR_PLUGIN_ARG, ++ii);
  2639. } while (skipped < MAXSKIPPED);
  2640. memset((char *)&pb, '\0', sizeof(pb));
  2641. slapi_pblock_set(&pb, SLAPI_PLUGIN, plugin);
  2642. slapi_pblock_set(&pb, SLAPI_PLUGIN_VERSION, (void *)SLAPI_PLUGIN_CURRENT_VERSION);
  2643. cid = generate_componentid (plugin,NULL);
  2644. /* We take a copy of the pointer to this so we can free it correctly. */
  2645. plugin->plg_identity = cid;
  2646. slapi_pblock_set(&pb, SLAPI_PLUGIN_IDENTITY, (void*)cid);
  2647. configdir = config_get_configdir();
  2648. slapi_pblock_set(&pb, SLAPI_CONFIG_DIRECTORY, configdir);
  2649. /* see if the plugin is enabled or not */
  2650. if ((value = slapi_entry_attr_get_charptr(plugin_entry,
  2651. ATTR_PLUGIN_ENABLED)) &&
  2652. !strcasecmp(value, "off"))
  2653. {
  2654. enabled = 0;
  2655. }
  2656. else
  2657. {
  2658. enabled = 1;
  2659. }
  2660. slapi_pblock_set(&pb, SLAPI_PLUGIN_ENABLED, &enabled);
  2661. slapi_pblock_set(&pb, SLAPI_PLUGIN_CONFIG_ENTRY, plugin_entry);
  2662. plugin->plg_op_counter = slapi_counter_new();
  2663. if (enabled && (*initfunc)(&pb) != 0)
  2664. {
  2665. LDAPDebug(LDAP_DEBUG_ANY, "Init function \"%s\" for \"%s\" plugin in library \"%s\" failed\n",
  2666. plugin->plg_initfunc, plugin->plg_name, plugin->plg_libpath);
  2667. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Init function \"%s\" for \"%s\" plugin in "
  2668. "library \"%s\" failed.",plugin->plg_initfunc, plugin->plg_name, plugin->plg_libpath);
  2669. status = -1;
  2670. /*
  2671. * The init function might have added the plugin to the global list before
  2672. * it failed - attempt to remove it just in case it was added.
  2673. */
  2674. plugin_remove_plugins(plugin, value);
  2675. slapi_ch_free((void**)&value);
  2676. goto PLUGIN_CLEANUP;
  2677. }
  2678. if ( !status ) {
  2679. status = plugin_add_descriptive_attributes( plugin_entry, plugin );
  2680. }
  2681. slapi_ch_free((void**)&value);
  2682. if(enabled)
  2683. {
  2684. /* don't use raw pointer from plugin_entry because it
  2685. will be freed later by the caller */
  2686. Slapi_DN *dn_copy = slapi_sdn_dup(slapi_entry_get_sdn_const(plugin_entry));
  2687. add_plugin_to_list(plugin_list, plugin);
  2688. add_plugin_entry_dn(dn_copy);
  2689. }
  2690. if (add_entry)
  2691. {
  2692. /* make a copy of the plugin entry for our own use because it will
  2693. be freed later by the caller */
  2694. Slapi_Entry *e_copy = slapi_entry_dup(plugin_entry);
  2695. /* new_plugin_entry(&plugin_entries, plugin_entry, plugin); */
  2696. new_plugin_entry(&dep_plugin_entries, e_copy, plugin);
  2697. }
  2698. PLUGIN_CLEANUP:
  2699. if (status)
  2700. plugin_free(plugin);
  2701. slapi_ch_free((void **)&configdir);
  2702. return status;
  2703. }
  2704. /*
  2705. * We added a plugin, do our setup and then start the plugin. This is the same as adding a plugin
  2706. * or enabling a disabled plugin.
  2707. */
  2708. int
  2709. plugin_add(Slapi_Entry *entry, char *returntext, int locked)
  2710. {
  2711. int rc = LDAP_SUCCESS;
  2712. if(!locked){
  2713. slapi_rwlock_wrlock(global_rwlock);
  2714. slapi_td_set_plugin_locked();
  2715. }
  2716. if((rc = plugin_setup(entry, 0, 0, 1, returntext)) != LDAP_SUCCESS){
  2717. LDAPDebug(LDAP_DEBUG_PLUGIN, "plugin_add: plugin_setup failed for (%s)\n",slapi_entry_get_dn(entry), rc, 0);
  2718. goto done;
  2719. }
  2720. if((rc = plugin_start(entry, returntext)) != LDAP_SUCCESS){
  2721. LDAPDebug(LDAP_DEBUG_PLUGIN, "plugin_add: plugin_start failed for (%s)\n",slapi_entry_get_dn(entry), rc, 0);
  2722. goto done;
  2723. }
  2724. done:
  2725. if(!locked){
  2726. slapi_rwlock_unlock(global_rwlock);
  2727. slapi_td_set_plugin_unlocked();
  2728. }
  2729. return rc;
  2730. }
  2731. static char *
  2732. get_dep_plugin_list(char **plugins)
  2733. {
  2734. char output[1024];
  2735. int first_plugin = 1;
  2736. int len = 0;
  2737. int i ;
  2738. for(i = 0; plugins && plugins[i]; i++){
  2739. if(first_plugin){
  2740. PL_strncpyz(output,plugins[i], sizeof(output) - 3);
  2741. len += strlen(plugins[i]);
  2742. first_plugin = 0;
  2743. } else {
  2744. PL_strcatn(output ,sizeof(output) -3, ", ");
  2745. PL_strcatn(output, sizeof(output) -3, plugins[i]);
  2746. len += strlen(plugins[i]);
  2747. }
  2748. if(len > (sizeof(output) - 3)){
  2749. /*
  2750. * We could not print all the plugins, show that we truncated
  2751. * the list by adding "..."
  2752. */
  2753. PL_strcatn(output ,sizeof(output) , "...");
  2754. }
  2755. }
  2756. return slapi_ch_strdup(output);
  2757. }
  2758. /*
  2759. * Make sure the removal of this plugin does not breaking any existing dependencies
  2760. */
  2761. static int
  2762. plugin_delete_check_dependency(struct slapdplugin *plugin_entry, int flag, char *returntext)
  2763. {
  2764. entry_and_plugin_t *ep = dep_plugin_entries;
  2765. plugin_dep_config *config = NULL;
  2766. struct slapdplugin *plugin = NULL;
  2767. Slapi_Entry *pentry = NULL;
  2768. char *plugin_name = plugin_entry->plg_name;
  2769. char *plugin_type = plugin_get_type_str(plugin_entry->plg_type);
  2770. char **dep_plugins = NULL;
  2771. char *value = NULL;
  2772. char **list = NULL;
  2773. int dep_type_count = 0;
  2774. int type_count = 0;
  2775. int total_plugins = 0;
  2776. int plugin_index = 0;
  2777. int index = 0;
  2778. int rc = LDAP_SUCCESS;
  2779. int i;
  2780. while(ep){
  2781. total_plugins++;
  2782. ep = ep->next;
  2783. }
  2784. /* allocate the config array */
  2785. config = (plugin_dep_config*)slapi_ch_calloc(total_plugins + 1, sizeof(plugin_dep_config));
  2786. ep = dep_plugin_entries;
  2787. /*
  2788. * Collect relevant config
  2789. */
  2790. while(ep){
  2791. plugin = ep->plugin;
  2792. if(plugin == 0){
  2793. goto next;
  2794. }
  2795. /*
  2796. * We are not concerned with disabled plugins
  2797. */
  2798. value = slapi_entry_attr_get_charptr(ep->e, ATTR_PLUGIN_ENABLED);
  2799. if(value){
  2800. if(strcasecmp(value, "off") == 0){
  2801. slapi_ch_free_string(&value);
  2802. goto next;
  2803. }
  2804. slapi_ch_free_string(&value);
  2805. } else {
  2806. goto next;
  2807. }
  2808. if(!ep->plugin){
  2809. goto next;
  2810. }
  2811. config[plugin_index].e = ep->e;
  2812. pentry = ep->e;
  2813. if(pentry){
  2814. config[plugin_index].plugin = plugin;
  2815. plugin_create_stringlist( pentry, "nsslapd-plugin-depends-on-named",
  2816. &(config[plugin_index].total_named), &(config[plugin_index].depends_named_list));
  2817. plugin_create_stringlist( pentry, "nsslapd-plugin-depends-on-type",
  2818. &(config[plugin_index].total_type), &(config[plugin_index].depends_type_list));
  2819. }
  2820. plugin_index++;
  2821. next:
  2822. ep = ep->next;
  2823. }
  2824. /*
  2825. * Start checking every plugin for dependency issues
  2826. */
  2827. for(index = 0; index < plugin_index; index++){
  2828. if((plugin = config[index].plugin)){
  2829. /*
  2830. * We can skip ourselves, and our registered plugins.
  2831. */
  2832. if( plugin_cmp_plugins(plugin, plugin_entry))
  2833. {
  2834. continue;
  2835. }
  2836. /*
  2837. * Check all the plugins to see if one is depending on this plugin(name)
  2838. */
  2839. if(flag == CHECK_ALL && config[index].depends_named_list){
  2840. list = config[index].depends_named_list;
  2841. for(i = 0; list && list[i]; i++){
  2842. if(strcasecmp(list[i], plugin_name) == 0){
  2843. /* We have a dependency, we can not disable this pluign */
  2844. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete_check_dependency: can not disable plugin(%s) due "
  2845. "to dependency name issues with plugin (%s)\n",
  2846. plugin_name, config[index].plugin->plg_name, 0);
  2847. rc = -1;
  2848. goto free_and_return;
  2849. }
  2850. }
  2851. }
  2852. /*
  2853. * Check all the plugins to see if one is depending on this plugin(type).
  2854. */
  2855. if(config[index].depends_type_list){
  2856. list = config[index].depends_type_list;
  2857. for(i = 0; list && list[i]; i++){
  2858. if(strcasecmp(list[i], plugin_type) == 0){
  2859. charray_add(&dep_plugins, slapi_ch_strdup(plugin->plg_name));
  2860. dep_type_count++;
  2861. break;
  2862. }
  2863. }
  2864. }
  2865. }
  2866. }
  2867. /*
  2868. * Now check the dependency type count.
  2869. */
  2870. if(dep_type_count > 0){
  2871. /*
  2872. * There are plugins that depend on this plugin type. Now, get a plugin count of this
  2873. * type of plugin. If we are the only plugin of this type, we can not disable it.
  2874. */
  2875. for(index = 0; index < plugin_index; index++){
  2876. if((plugin = config[index].plugin)){
  2877. /* Skip ourselves, and our registered plugins. */
  2878. if( plugin_cmp_plugins(plugin, plugin_entry))
  2879. {
  2880. continue;
  2881. }
  2882. if(plugin->plg_type == plugin_entry->plg_type){
  2883. /* there is at least one other plugin of this type, its ok to disable */
  2884. type_count = 1;
  2885. break;
  2886. }
  2887. }
  2888. }
  2889. if(type_count == 0){ /* this is the only plugin of this type - return an error */
  2890. char *plugins = get_dep_plugin_list(dep_plugins);
  2891. /*
  2892. * The plugin type was changed, but since other plugins currently have dependencies,
  2893. * we can not dynamically apply the change. This is will most likely cause issues
  2894. * at the next server startup.
  2895. */
  2896. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Plugin (%s) type (%s) is needed "
  2897. "by other plugins(%s), it can not be dynamically disabled/removed at this time.",
  2898. plugin_name, plugin_type, plugins);
  2899. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete_check_dependency: %s\n",
  2900. returntext, 0, 0);
  2901. slapi_ch_free_string(&plugins);
  2902. rc = -1;
  2903. }
  2904. }
  2905. free_and_return:
  2906. /*
  2907. * Free the config list
  2908. */
  2909. charray_free(dep_plugins);
  2910. if(config){
  2911. index = 0;
  2912. while( config[index].plugin){
  2913. charray_free(config[index].depends_type_list);
  2914. charray_free(config[index].depends_named_list);
  2915. index++;
  2916. }
  2917. slapi_ch_free((void**)&config);
  2918. }
  2919. return rc;
  2920. }
  2921. /*
  2922. * Mark the plugin in the shutdown list a removed
  2923. */
  2924. static void
  2925. plugin_remove_from_shutdown(struct slapdplugin *plugin_entry)
  2926. {
  2927. struct slapdplugin *plugin = NULL;
  2928. int index = 0;
  2929. for(;index < global_plugins_started; index++){
  2930. if((plugin = global_plugin_shutdown_order[index].plugin)){
  2931. if(global_plugin_shutdown_order[index].removed){
  2932. continue;
  2933. }
  2934. /* "plugin_entry" can be the main plugin for registered function */
  2935. if(plugin_cmp_plugins(plugin, plugin_entry))
  2936. {
  2937. /*
  2938. * We have our index, just mark it as removed. The global list gets rewritten
  2939. * the next time we add or enable a plugin.
  2940. */
  2941. global_plugin_shutdown_order[index].removed = 1;
  2942. return;
  2943. }
  2944. }
  2945. }
  2946. }
  2947. /*
  2948. * Free the plugins that have been set to be removed.
  2949. */
  2950. static void
  2951. plugin_cleanup_list()
  2952. {
  2953. struct slapdplugin *plugin = NULL;
  2954. entry_and_plugin_t *ep = dep_plugin_entries;
  2955. entry_and_plugin_t *ep_prev = NULL, *ep_next = NULL;
  2956. while(ep){
  2957. plugin = ep->plugin;
  2958. ep_next = ep->next;
  2959. if(plugin && plugin->plg_removed){
  2960. if(ep_prev){
  2961. ep_prev->next = ep->next;
  2962. } else {
  2963. dep_plugin_entries = ep->next;
  2964. }
  2965. slapi_entry_free(ep->e);
  2966. if(ep->plugin){
  2967. plugin_free(ep->plugin);
  2968. }
  2969. slapi_ch_free((void **)&ep);
  2970. } else {
  2971. ep_prev = ep;
  2972. }
  2973. ep = ep_next;
  2974. }
  2975. }
  2976. /*
  2977. * Look at all the plugins for any matches. Then mark the ones we need
  2978. * to delete. After checking all the plugins, then we free the ones that
  2979. * were marked to be removed.
  2980. */
  2981. static int
  2982. plugin_remove_plugins(struct slapdplugin *plugin_entry, char *plugin_type)
  2983. {
  2984. struct slapdplugin *plugin = NULL;
  2985. struct slapdplugin *plugin_next = NULL;
  2986. struct slapdplugin *plugin_prev = NULL;
  2987. int removed = PLUGIN_NOT_FOUND;
  2988. int type;
  2989. /* look everywhere for other plugin functions with the plugin id */
  2990. for(type = 0; type < PLUGIN_LIST_GLOBAL_MAX; type++){
  2991. plugin = global_plugin_list[type];
  2992. plugin_prev = NULL;
  2993. while(plugin){
  2994. plugin_next = plugin->plg_next;
  2995. /*
  2996. * Check for the two types of plugins:
  2997. * the main plugin, and its registered plugin functions.
  2998. */
  2999. if(plugin_cmp_plugins(plugin_entry, plugin)){
  3000. /*
  3001. * Call the close function, cleanup the hashtable & the global shutdown list
  3002. */
  3003. Slapi_PBlock pb;
  3004. pblock_init(&pb);
  3005. plugin_set_stopped(plugin);
  3006. if (slapi_counter_get_value(plugin->plg_op_counter) > 0){
  3007. /*
  3008. * Plugin is still busy, and we might be blocking it
  3009. * by holding global plugin lock so return for now.
  3010. */
  3011. return PLUGIN_BUSY;
  3012. }
  3013. plugin_call_one( plugin, SLAPI_PLUGIN_CLOSE_FN, &pb);
  3014. if(plugin_prev){
  3015. plugin_prev->plg_next = plugin_next;
  3016. } else {
  3017. global_plugin_list[type] = plugin_next;
  3018. }
  3019. /*
  3020. * Remove plugin the DN hashtable, update the shutdown list,
  3021. * and mark the plugin for deletion
  3022. */
  3023. plugin_remove_from_list(plugin->plg_dn);
  3024. plugin_remove_from_shutdown(plugin);
  3025. plugin->plg_removed = 1;
  3026. plugin->plg_started = 0;
  3027. removed = PLUGIN_REMOVED;
  3028. } else {
  3029. plugin_prev = plugin;
  3030. }
  3031. plugin = plugin_next;
  3032. }
  3033. }
  3034. if(removed){
  3035. /*
  3036. * Now free the marked plugins, we could not do this earlier because
  3037. * we also needed to check for plugins registered functions. As both
  3038. * plugin types share the same slapi_plugin entry.
  3039. */
  3040. plugin_cleanup_list();
  3041. }
  3042. return removed;
  3043. }
  3044. /*
  3045. * We are removing a plugin from the global list. This happens when we delete a plugin, or disable it.
  3046. */
  3047. int
  3048. plugin_delete(Slapi_Entry *plugin_entry, char *returntext, int locked)
  3049. {
  3050. struct slapdplugin **plugin_list = NULL;
  3051. struct slapdplugin *plugin = NULL;
  3052. const char *plugin_dn = slapi_entry_get_dn_const(plugin_entry);
  3053. char *value = NULL;
  3054. int removed = PLUGIN_BUSY;
  3055. int type = 0;
  3056. int rc = LDAP_SUCCESS;
  3057. /* Critical server plugins can not be disabled */
  3058. if(plugin_is_critical(plugin_entry)){
  3059. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete: plugin \"%s\" is critical to server operations, and can not be disabled\n",
  3060. slapi_entry_get_dn_const(plugin_entry), 0, 0);
  3061. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Plugin \"%s\" is critical to server operations, and can not "
  3062. "be disabled.\n",slapi_entry_get_dn_const(plugin_entry));
  3063. rc = -1;
  3064. goto done;
  3065. }
  3066. if (!(value = slapi_entry_attr_get_charptr(plugin_entry, ATTR_PLUGIN_TYPE))){
  3067. /* error: required attribute %s missing */
  3068. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete: required attribute %s is missing from entry \"%s\"\n",
  3069. ATTR_PLUGIN_TYPE, slapi_entry_get_dn_const(plugin_entry), 0);
  3070. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Plugin delete failed: required attribute %s "
  3071. "is missing from entry.",ATTR_PLUGIN_TYPE);
  3072. rc = -1;
  3073. goto done;
  3074. } else {
  3075. while(removed == PLUGIN_BUSY){
  3076. removed = PLUGIN_NOT_FOUND;
  3077. if(!locked){
  3078. slapi_rwlock_wrlock(global_rwlock);
  3079. slapi_td_set_plugin_locked();
  3080. }
  3081. rc = plugin_get_type_and_list(value, &type, &plugin_list);
  3082. if ( rc != 0 ) {
  3083. /* error: unknown plugin type */
  3084. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete: unknown plugin type \"%s\" in entry \"%s\"\n",
  3085. value, slapi_entry_get_dn_const(plugin_entry), 0);
  3086. PR_snprintf (returntext, SLAPI_DSE_RETURNTEXT_SIZE, "Plugin delete failed: unknown plugin type "
  3087. "\"%s\" in entry.",value);
  3088. rc = -1;
  3089. goto unlock;
  3090. }
  3091. /*
  3092. * Skip syntax/matching rule/database plugins - these can not be disabled as it
  3093. * could break existing schema. We allow the update to occur, but it will
  3094. * not take effect until the next server restart.
  3095. */
  3096. if(type == SLAPI_PLUGIN_SYNTAX || type == SLAPI_PLUGIN_MATCHINGRULE || type == SLAPI_PLUGIN_DATABASE){
  3097. removed = PLUGIN_REMOVED; /* avoids error check below */
  3098. goto unlock;
  3099. }
  3100. /*
  3101. * Now remove the plugin from the list and the hashtable
  3102. */
  3103. for(plugin = *plugin_list; plugin ; plugin = plugin->plg_next){
  3104. if(strcasecmp(plugin->plg_dn, plugin_dn) == 0){
  3105. /*
  3106. * Make sure there are no other plugins that depend on this one before removing it
  3107. */
  3108. if(plugin_delete_check_dependency(plugin, CHECK_ALL, returntext) != LDAP_SUCCESS){
  3109. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete: failed to disable/delete plugin (%s)\n",
  3110. plugin->plg_dn,0,0);
  3111. rc = -1;
  3112. break;
  3113. }
  3114. removed = plugin_remove_plugins(plugin, value);
  3115. break;
  3116. }
  3117. }
  3118. unlock:
  3119. if(!locked){
  3120. slapi_rwlock_unlock(global_rwlock);
  3121. slapi_td_set_plugin_unlocked();
  3122. }
  3123. }
  3124. }
  3125. done:
  3126. slapi_ch_free_string(&value);
  3127. if(!removed && rc == 0){
  3128. PR_snprintf(returntext, SLAPI_DSE_RETURNTEXT_SIZE,"Plugin delete failed: could not find plugin "
  3129. "in the global list.");
  3130. LDAPDebug(LDAP_DEBUG_ANY, "plugin_delete: did not find plugin(%s) in the global list.\n",
  3131. slapi_entry_get_dn_const(plugin_entry),0,0);
  3132. rc = -1;
  3133. }
  3134. return rc;
  3135. }
  3136. /* set default configuration parameters */
  3137. static void
  3138. plugin_config_init (struct pluginconfig *config)
  3139. {
  3140. PR_ASSERT (config);
  3141. ptd_init (&config->plgc_target_subtrees);
  3142. ptd_init (&config->plgc_excluded_target_subtrees);
  3143. ptd_init (&config->plgc_bind_subtrees);
  3144. ptd_init (&config->plgc_excluded_bind_subtrees);
  3145. config->plgc_schema_check = PLGC_ON;
  3146. config->plgc_invoke_for_replop = PLGC_ON;
  3147. /* currently, we leave it up to plugin, but don't actually tell plugins that they can choose.
  3148. We want changes to always be logged by regular plugins to avoid data inconsistency, but we
  3149. want to allow internal plugins like replication to make the decision.*/
  3150. config->plgc_log_change = PLGC_UPTOPLUGIN;
  3151. config->plgc_log_access = PLGC_OFF;
  3152. config->plgc_log_audit = PLGC_OFF;
  3153. }
  3154. static int
  3155. plugin_config_set_action (int *action, char *value)
  3156. {
  3157. PR_ASSERT (action);
  3158. PR_ASSERT (value);
  3159. if (strcasecmp (value, "on") == 0)
  3160. {
  3161. *action = PLGC_ON;
  3162. }
  3163. else if (strcasecmp (value, "off") == 0)
  3164. {
  3165. *action = PLGC_OFF;
  3166. }
  3167. else if (strcasecmp (value, "uptoplugin") == 0)
  3168. {
  3169. *action = PLGC_UPTOPLUGIN;
  3170. }
  3171. else
  3172. {
  3173. slapi_log_error(SLAPI_LOG_FATAL, NULL,
  3174. "plugin_config_set_action: invalid action %s\n", value);
  3175. return -1;
  3176. }
  3177. return 0;
  3178. }
  3179. static void
  3180. plugin_config_cleanup (struct pluginconfig *config)
  3181. {
  3182. PR_ASSERT (config);
  3183. ptd_cleanup (&config->plgc_target_subtrees);
  3184. ptd_cleanup (&config->plgc_excluded_target_subtrees);
  3185. ptd_cleanup (&config->plgc_bind_subtrees);
  3186. ptd_cleanup (&config->plgc_excluded_bind_subtrees);
  3187. }
  3188. #if 0
  3189. static char*
  3190. plugin_config_action_to_string (int action)
  3191. {
  3192. switch (action)
  3193. {
  3194. case PLGC_ON: return "on";
  3195. case PLGC_OFF: return "off";
  3196. case PLGC_UPTOPLUGIN: return "uptoplugin";
  3197. default: return NULL;
  3198. }
  3199. }
  3200. #endif
  3201. static struct pluginconfig*
  3202. plugin_get_config (struct slapdplugin *plugin)
  3203. {
  3204. struct slapdplugin *temp = plugin;
  3205. PR_ASSERT (plugin);
  3206. while (temp->plg_group)
  3207. {
  3208. temp = temp->plg_group;
  3209. }
  3210. return &(temp->plg_conf);
  3211. }
  3212. static PRBool
  3213. plugin_invoke_plugin_pb (struct slapdplugin *plugin, int operation, Slapi_PBlock *pb)
  3214. {
  3215. Slapi_DN *target_spec;
  3216. PRBool rc;
  3217. PR_ASSERT (plugin);
  3218. PR_ASSERT (pb);
  3219. /* we always allow initialization and cleanup operations */
  3220. if (operation == SLAPI_PLUGIN_START_FN ||
  3221. operation == SLAPI_PLUGIN_POSTSTART_FN ||
  3222. operation == SLAPI_PLUGIN_CLOSE_FN ||
  3223. operation == SLAPI_PLUGIN_CLEANUP_FN ||
  3224. operation == SLAPI_PLUGIN_BE_PRE_CLOSE_FN ||
  3225. operation == SLAPI_PLUGIN_BE_POST_OPEN_FN ||
  3226. operation == SLAPI_PLUGIN_BE_PRE_BACKUP_FN ||
  3227. operation == SLAPI_PLUGIN_BE_POST_BACKUP_FN)
  3228. return PR_TRUE;
  3229. PR_ASSERT (pb->pb_op);
  3230. target_spec = operation_get_target_spec (pb->pb_op);
  3231. rc = plugin_invoke_plugin_sdn (plugin, operation, pb, target_spec);
  3232. return rc;
  3233. }
  3234. PRBool
  3235. plugin_invoke_plugin_sdn (struct slapdplugin *plugin, int operation, Slapi_PBlock *pb, Slapi_DN *target_spec)
  3236. {
  3237. PluginTargetData *ptd;
  3238. PluginTargetData *excludedPtd;
  3239. struct pluginconfig *config;
  3240. Slapi_Backend *be;
  3241. int isroot;
  3242. PRBool islocal;
  3243. PRBool bindop;
  3244. unsigned long op;
  3245. ber_tag_t method = LBER_ERROR;
  3246. PR_ASSERT (plugin);
  3247. if (!pb) {
  3248. LDAPDebug(LDAP_DEBUG_ANY, "plugin_invoke_plugin_sdn: NULL pblock.\n", 0, 0, 0);
  3249. return PR_FALSE;
  3250. }
  3251. /* get configuration from the group plugin if necessary */
  3252. config = plugin_get_config (plugin);
  3253. slapi_pblock_get(pb, SLAPI_BIND_METHOD, &method);
  3254. /* check if plugin is configured to service replicated operations */
  3255. if (!config->plgc_invoke_for_replop)
  3256. {
  3257. int repl_op;
  3258. slapi_pblock_get (pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op);
  3259. if (repl_op)
  3260. return PR_FALSE;
  3261. }
  3262. if (pb->pb_op)
  3263. {
  3264. op = operation_get_type(pb->pb_op);
  3265. if (op == SLAPI_OPERATION_BIND || op == SLAPI_OPERATION_UNBIND)
  3266. {
  3267. bindop = PR_TRUE;
  3268. }
  3269. else
  3270. {
  3271. bindop = PR_FALSE;
  3272. }
  3273. slapi_pblock_get (pb, SLAPI_REQUESTOR_ISROOT, &isroot);
  3274. }
  3275. else
  3276. {
  3277. bindop = PR_FALSE;
  3278. isroot = 1;
  3279. }
  3280. slapi_pblock_get (pb, SLAPI_BACKEND, &be);
  3281. /* determine whether data are local or remote */
  3282. /* remote if chaining backend or default backend */
  3283. if ( be!=NULL ) {
  3284. islocal=!(slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA));
  3285. } else {
  3286. islocal = be != defbackend_get_backend();
  3287. }
  3288. if (bindop)
  3289. {
  3290. ptd = &(config->plgc_bind_subtrees);
  3291. excludedPtd = &(config->plgc_excluded_bind_subtrees);
  3292. }
  3293. else
  3294. {
  3295. ptd = &(config->plgc_target_subtrees);
  3296. excludedPtd = &(config->plgc_excluded_target_subtrees);
  3297. }
  3298. if (plugin_matches_operation (target_spec, excludedPtd, bindop, isroot, islocal, method) == PR_TRUE) {
  3299. return PR_FALSE;
  3300. }
  3301. return plugin_matches_operation (target_spec, ptd, bindop, isroot, islocal, method);
  3302. }
  3303. /* this interface is exposed to be used by internal operations.
  3304. */
  3305. char* plugin_get_dn (const struct slapdplugin *plugin)
  3306. {
  3307. char *plugindn = NULL;
  3308. char *pattern = "cn=%s," PLUGIN_BASE_DN; /* cn=plugins,cn=config */
  3309. if (plugin == NULL) /* old plugin that does not pass identity - use default */
  3310. plugin = &global_default_plg;
  3311. if (plugin->plg_name == NULL)
  3312. return NULL;
  3313. /* plg_name is normalized in plugin_setup. So, we can use smprintf */
  3314. plugindn = slapi_ch_smprintf(pattern, plugin->plg_name);
  3315. if (NULL == plugindn) {
  3316. slapi_log_error(SLAPI_LOG_FATAL, NULL,
  3317. "plugin_get_dn: failed to create plugin dn "
  3318. "(plugin name: %s)\n", plugin->plg_name);
  3319. return NULL;
  3320. }
  3321. return plugindn;
  3322. }
  3323. static PRBool plugin_is_global (const PluginTargetData *ptd)
  3324. {
  3325. /* plugin is considered to be global if it is invoked for
  3326. global data, local data and anonymous bind (bind target
  3327. data only). We don't include directory manager here
  3328. as it is considered to be part of local data */
  3329. return (ptd_is_special_data_set (ptd, PLGC_DATA_LOCAL) &&
  3330. ptd_is_special_data_set (ptd, PLGC_DATA_REMOTE) &&
  3331. ptd_is_special_data_set (ptd, PLGC_DATA_BIND_ANONYMOUS) &&
  3332. ptd_is_special_data_set (ptd, PLGC_DATA_BIND_ROOT));
  3333. }
  3334. static void plugin_set_global (PluginTargetData *ptd)
  3335. {
  3336. PR_ASSERT (ptd);
  3337. /* plugin is global if it is allowed access to all data */
  3338. ptd_set_special_data (ptd, PLGC_DATA_LOCAL);
  3339. ptd_set_special_data (ptd, PLGC_DATA_REMOTE);
  3340. ptd_set_special_data (ptd, PLGC_DATA_BIND_ANONYMOUS);
  3341. ptd_set_special_data (ptd, PLGC_DATA_BIND_ROOT);
  3342. }
  3343. static void plugin_set_default_access (struct pluginconfig *config)
  3344. {
  3345. /* by default, plugins are invoked if dn is local for bind operations,
  3346. and for all requests for all other operations */
  3347. PR_ASSERT (config);
  3348. plugin_set_global (&config->plgc_target_subtrees);
  3349. ptd_set_special_data (&config->plgc_bind_subtrees, PLGC_DATA_LOCAL);
  3350. ptd_set_special_data (&config->plgc_bind_subtrees, PLGC_DATA_REMOTE);
  3351. }
  3352. /* determine whether operation should be allowed based on plugin configuration */
  3353. PRBool plugin_allow_internal_op (Slapi_DN *target_spec, struct slapdplugin *plugin)
  3354. {
  3355. struct pluginconfig *config = plugin_get_config (plugin);
  3356. Slapi_Backend *be;
  3357. int islocal;
  3358. if (plugin_is_global (&config->plgc_excluded_target_subtrees))
  3359. return PR_FALSE;
  3360. if (plugin_is_global (&config->plgc_target_subtrees))
  3361. return PR_TRUE;
  3362. /* ONREPL - we do be_select to decide whether the request is for local
  3363. or remote data. We might need to reconsider how to do this
  3364. for performance reasons since be_select will be done again
  3365. once the operation goes through */
  3366. be = slapi_be_select(target_spec);
  3367. /* determine whether data are local or remote */
  3368. /* remote if chaining backend or default backend */
  3369. if ( be!=NULL ) {
  3370. islocal=!(slapi_be_is_flag_set(be,SLAPI_BE_FLAG_REMOTE_DATA));
  3371. } else {
  3372. islocal = be != defbackend_get_backend();
  3373. }
  3374. /* SIMPLE auth method sends us through original code path in plugin_mathches_operation */
  3375. if (plugin_matches_operation (target_spec, &config->plgc_excluded_target_subtrees,
  3376. PR_FALSE, PR_FALSE, islocal, LDAP_AUTH_SIMPLE) == PR_TRUE) {
  3377. return PR_FALSE;
  3378. }
  3379. return plugin_matches_operation (target_spec, &config->plgc_target_subtrees,
  3380. PR_FALSE, PR_FALSE, islocal, LDAP_AUTH_SIMPLE);
  3381. }
  3382. static PRBool plugin_matches_operation (Slapi_DN *target_spec, PluginTargetData *ptd,
  3383. PRBool bindop, PRBool isroot, PRBool islocal, ber_tag_t method)
  3384. {
  3385. int cookie;
  3386. Slapi_DN *subtree;
  3387. /* check for special cases */
  3388. if (plugin_is_global (ptd))
  3389. return PR_TRUE;
  3390. /* if method is SASL we can have a null DN so bypass this check*/
  3391. if(method != LDAP_AUTH_SASL) {
  3392. if (bindop && target_spec && (slapi_sdn_get_dn (target_spec) == NULL ||
  3393. slapi_sdn_get_dn (target_spec)[0] == '\0'))
  3394. {
  3395. return (ptd_is_special_data_set (ptd, PLGC_DATA_BIND_ANONYMOUS));
  3396. }
  3397. }
  3398. /* check for root bind */
  3399. if (bindop && isroot)
  3400. {
  3401. return (ptd_is_special_data_set (ptd, PLGC_DATA_BIND_ROOT));
  3402. }
  3403. /* check for local data */
  3404. if (ptd_is_special_data_set (ptd, PLGC_DATA_LOCAL) && islocal)
  3405. {
  3406. return PR_TRUE;
  3407. }
  3408. /* check for remote data */
  3409. if (ptd_is_special_data_set (ptd, PLGC_DATA_REMOTE) && !islocal)
  3410. {
  3411. return (PR_TRUE);
  3412. }
  3413. subtree = ptd_get_first_subtree (ptd, &cookie);
  3414. while (subtree)
  3415. {
  3416. if (slapi_sdn_issuffix (target_spec, subtree))
  3417. return (PR_TRUE);
  3418. subtree = ptd_get_next_subtree (ptd, &cookie);
  3419. }
  3420. return PR_FALSE;
  3421. }
  3422. /* build operation action bitmap based on plugin configuration and actions specified for the operation */
  3423. int plugin_build_operation_action_bitmap (int input_actions, const struct slapdplugin *plugin)
  3424. {
  3425. int result_actions = 0;
  3426. /* old plugin that does not pass its identity to the operation */
  3427. if (plugin == NULL)
  3428. plugin = &global_default_plg;
  3429. if (plugin->plg_conf.plgc_log_access || config_get_plugin_logging())
  3430. result_actions |= OP_FLAG_ACTION_LOG_ACCESS;
  3431. if (plugin->plg_conf.plgc_log_audit || config_get_plugin_logging())
  3432. result_actions |= OP_FLAG_ACTION_LOG_AUDIT;
  3433. /*
  3434. * OP_FLAG_ACTION_INVOKE_FOR_REPLOP is now used only by URP code.
  3435. * If someday this code needs to reclaim the flag, it has to use
  3436. * another flag to avoid the conflict with URP code.
  3437. *
  3438. * if (plugin->plg_conf.plgc_invoke_for_replop)
  3439. * result_actions |= OP_FLAG_ACTION_INVOKE_FOR_REPLOP;
  3440. */
  3441. switch (plugin->plg_conf.plgc_schema_check)
  3442. {
  3443. case PLGC_OFF: result_actions &= ~OP_FLAG_ACTION_SCHEMA_CHECK;
  3444. break;
  3445. case PLGC_ON: result_actions |= OP_FLAG_ACTION_SCHEMA_CHECK;
  3446. break;
  3447. case PLGC_UPTOPLUGIN: break;
  3448. default: PR_ASSERT (PR_FALSE);
  3449. }
  3450. switch (plugin->plg_conf.plgc_log_change)
  3451. {
  3452. case PLGC_OFF: result_actions &= ~OP_FLAG_ACTION_LOG_CHANGES;
  3453. break;
  3454. case PLGC_ON: result_actions |= OP_FLAG_ACTION_LOG_CHANGES;
  3455. break;
  3456. case PLGC_UPTOPLUGIN: break;
  3457. default: PR_ASSERT (PR_FALSE);
  3458. }
  3459. return result_actions;
  3460. }
  3461. const struct slapdplugin*
  3462. plugin_get_server_plg()
  3463. {
  3464. if(!global_server_plg_initialised)
  3465. {
  3466. global_server_plg.plg_name = "server";
  3467. plugin_set_global (&global_server_plg.plg_conf.plgc_target_subtrees);
  3468. global_server_plg.plg_conf.plgc_log_access = 1;
  3469. global_server_plg.plg_conf.plgc_log_audit = 1;
  3470. global_server_plg.plg_conf.plgc_schema_check = 1;
  3471. global_server_plg.plg_conf.plgc_log_change = 1;
  3472. global_server_plg_initialised= 1;
  3473. global_server_plg_initialised= 1;
  3474. }
  3475. return &global_server_plg;
  3476. }
  3477. struct slapi_componentid * plugin_get_default_component_id() {
  3478. if(!global_server_plg_id_initialised) {
  3479. global_server_id_plg.sci_plugin=plugin_get_server_plg();
  3480. global_server_id_plg.sci_component_name=
  3481. plugin_get_dn(global_server_id_plg.sci_plugin);
  3482. global_server_plg_id_initialised=1;
  3483. }
  3484. return &global_server_id_plg;
  3485. }
  3486. static void
  3487. default_plugin_init()
  3488. {
  3489. global_default_plg.plg_name = "old plugin";
  3490. plugin_config_init (&global_default_plg.plg_conf);
  3491. plugin_set_default_access (&global_default_plg.plg_conf);
  3492. }
  3493. #if 0
  3494. static void trace_plugin_invocation (Slapi_DN *target_spec, PluginTargetData *ptd,
  3495. PRBool bindop, PRBool isroot, PRBool islocal, int invoked)
  3496. {
  3497. int cookie, i = 0;
  3498. Slapi_DN *sdn;
  3499. slapi_log_error (SLAPI_LOG_FATAL, NULL,
  3500. "Invocation parameters: target_spec = %s, bindop = %d, isroot=%d, islocal=%d\n"
  3501. "Plugin configuration: local_data=%d, remote_data=%d, anonymous_bind=%d, root_bind=%d\n",
  3502. slapi_sdn_get_ndn (target_spec), bindop, isroot, islocal, ptd->special_data[0],
  3503. ptd->special_data[1], ptd->special_data[2], ptd->special_data[3]);
  3504. sdn = ptd_get_first_subtree (ptd, &cookie);
  3505. while (sdn)
  3506. {
  3507. slapi_log_error (SLAPI_LOG_FATAL, NULL, "target_subtree%d: %s\n", i, slapi_sdn_get_ndn (sdn));
  3508. sdn = ptd_get_next_subtree (ptd, &cookie);
  3509. }
  3510. slapi_log_error (SLAPI_LOG_FATAL, NULL, invoked ? "Plugin is invoked\n" : "Plugin is not invoked\n");
  3511. }
  3512. #endif
  3513. /* functions to manipulate PluginTargetData type */
  3514. static void ptd_init (PluginTargetData *ptd)
  3515. {
  3516. PR_ASSERT (ptd);
  3517. dl_init (&ptd->subtrees, 0 /* initial count */);
  3518. memset (&ptd->special_data, 0, sizeof (ptd->special_data));
  3519. }
  3520. static void ptd_cleanup (PluginTargetData *ptd)
  3521. {
  3522. PR_ASSERT (ptd);
  3523. dl_cleanup (&ptd->subtrees, (FREEFN)slapi_sdn_free);
  3524. memset (&ptd->special_data, 0, sizeof (ptd->special_data));
  3525. }
  3526. static void ptd_add_subtree (PluginTargetData *ptd, Slapi_DN *subtree)
  3527. {
  3528. PR_ASSERT (ptd);
  3529. PR_ASSERT (subtree);
  3530. dl_add (&ptd->subtrees, subtree);
  3531. }
  3532. static void ptd_set_special_data (PluginTargetData *ptd, int type)
  3533. {
  3534. PR_ASSERT (ptd);
  3535. PR_ASSERT (type >= 0 && type < PLGC_DATA_MAX);
  3536. ptd->special_data [type] = PR_TRUE;
  3537. }
  3538. #if 0
  3539. static void ptd_clear_special_data (PluginTargetData *ptd, int type)
  3540. {
  3541. PR_ASSERT (ptd);
  3542. PR_ASSERT (type >= 0 && type < PLGC_DATA_MAX);
  3543. ptd->special_data [type] = PR_FALSE;
  3544. }
  3545. #endif
  3546. static Slapi_DN *ptd_get_first_subtree (const PluginTargetData *ptd, int *cookie)
  3547. {
  3548. PR_ASSERT (ptd);
  3549. return dl_get_first (&ptd->subtrees, cookie);
  3550. }
  3551. static Slapi_DN *ptd_get_next_subtree (const PluginTargetData *ptd, int *cookie)
  3552. {
  3553. PR_ASSERT (ptd);
  3554. return dl_get_next (&ptd->subtrees, cookie);
  3555. }
  3556. static PRBool ptd_is_special_data_set (const PluginTargetData *ptd, int type)
  3557. {
  3558. PR_ASSERT (ptd);
  3559. PR_ASSERT (type >= 0 && type < PLGC_DATA_MAX);
  3560. return ptd->special_data [type];
  3561. }
  3562. #if 0
  3563. static Slapi_DN* ptd_delete_subtree (PluginTargetData *ptd, Slapi_DN *subtree)
  3564. {
  3565. PR_ASSERT (ptd);
  3566. PR_ASSERT (subtree);
  3567. return (Slapi_DN*)dl_delete (&ptd->subtrees, subtree, (CMPFN)slapi_sdn_compare, NULL);
  3568. }
  3569. #endif
  3570. int ptd_get_subtree_count (const PluginTargetData *ptd)
  3571. {
  3572. PR_ASSERT (ptd);
  3573. return dl_get_count (&ptd->subtrees);
  3574. }
  3575. /* needed by command-line tasks to find an instance's plugin */
  3576. struct slapdplugin *plugin_get_by_name(char *name)
  3577. {
  3578. int x;
  3579. struct slapdplugin *plugin;
  3580. for(x = 0; x < PLUGIN_LIST_GLOBAL_MAX; x++) {
  3581. for(plugin = global_plugin_list[x]; plugin; plugin = plugin->plg_next) {
  3582. if (!strcmp(name, plugin->plg_name)) {
  3583. return plugin;
  3584. }
  3585. }
  3586. }
  3587. return NULL;
  3588. }
  3589. struct slapi_componentid *
  3590. generate_componentid ( struct slapdplugin * pp , char * name )
  3591. {
  3592. struct slapi_componentid * idp;
  3593. idp = (struct slapi_componentid *) slapi_ch_calloc(1, sizeof( *idp ));
  3594. if ( pp )
  3595. idp->sci_plugin=pp;
  3596. else
  3597. idp->sci_plugin=(struct slapdplugin *) plugin_get_server_plg();
  3598. if ( name )
  3599. idp->sci_component_name = slapi_ch_strdup(name);
  3600. else
  3601. /* Use plugin dn */
  3602. idp->sci_component_name = plugin_get_dn( idp->sci_plugin );
  3603. if (idp->sci_component_name)
  3604. slapi_dn_normalize(idp->sci_component_name);
  3605. return idp;
  3606. }
  3607. void release_componentid ( struct slapi_componentid * id )
  3608. {
  3609. if ( id ) {
  3610. if ( id->sci_component_name ) {
  3611. slapi_ch_free((void **)&id->sci_component_name);
  3612. id->sci_component_name=NULL;
  3613. }
  3614. slapi_ch_free((void **)&id);
  3615. }
  3616. }
  3617. /* used in main.c if -V flag is given */
  3618. static void slapd_print_plugin_version (
  3619. struct slapdplugin *plg,
  3620. struct slapdplugin *prev
  3621. )
  3622. {
  3623. if (plg == NULL || plg->plg_libpath == NULL) return;
  3624. /* same library as previous - don't print twice */
  3625. if (prev != NULL && prev->plg_libpath != NULL) {
  3626. if (strcmp(prev->plg_libpath,plg->plg_libpath) == 0) {
  3627. return;
  3628. }
  3629. }
  3630. printf("%s: %s\n",
  3631. plg->plg_libpath,
  3632. plg->plg_desc.spd_version ? plg->plg_desc.spd_version : "");
  3633. }
  3634. static void slapd_print_pluginlist_versions(struct slapdplugin *plg)
  3635. {
  3636. struct slapdplugin *p,*prev = NULL;
  3637. for (p = plg; p != NULL; p = p->plg_next) {
  3638. slapd_print_plugin_version(p,prev);
  3639. prev = p;
  3640. }
  3641. }
  3642. void plugin_print_versions(void)
  3643. {
  3644. int i;
  3645. for (i = 0; i < PLUGIN_LIST_GLOBAL_MAX; i++) {
  3646. slapd_print_pluginlist_versions(get_plugin_list(i));
  3647. }
  3648. }
  3649. /*
  3650. * Prints a list of plugins in execution order for each
  3651. * plug-in type. This will only be printed at the
  3652. * SLAPI_LOG_PLUGIN log level.
  3653. */
  3654. void plugin_print_lists(void)
  3655. {
  3656. int i;
  3657. struct slapdplugin *list = NULL;
  3658. struct slapdplugin *tmp = NULL;
  3659. for (i = 0; i < PLUGIN_LIST_GLOBAL_MAX; i++) {
  3660. if ((list = get_plugin_list(i)))
  3661. {
  3662. slapi_log_error(SLAPI_LOG_PLUGIN, NULL,
  3663. "---- Plugin List (type %d) ----\n", i);
  3664. for ( tmp = list; tmp; tmp = tmp->plg_next )
  3665. {
  3666. slapi_log_error(SLAPI_LOG_PLUGIN, NULL, " %s (precedence: %d)\n",
  3667. tmp->plg_name, tmp->plg_precedence);
  3668. }
  3669. }
  3670. }
  3671. }
  3672. /*
  3673. * check the spedified plugin entry and its nssladp-pluginEnabled value
  3674. * Return Value: 1 if the plugin is on.
  3675. * : 0 otherwise.
  3676. */
  3677. int
  3678. plugin_enabled(const char *plugin_name, void *identity)
  3679. {
  3680. Slapi_PBlock *search_pb = NULL;
  3681. Slapi_Entry **entries = NULL, **ep = NULL;
  3682. Slapi_Value *on_off = slapi_value_new_string("on");
  3683. char *filter = NULL;
  3684. int rc = 0; /* disabled, by default */
  3685. filter = slapi_filter_sprintf("cn=%s%s", ESC_NEXT_VAL, plugin_name);
  3686. search_pb = slapi_pblock_new();
  3687. slapi_search_internal_set_pb(search_pb, PLUGIN_BASE_DN, LDAP_SCOPE_ONELEVEL,
  3688. filter, NULL, 0, NULL, NULL, identity, 0);
  3689. slapi_search_internal_pb(search_pb);
  3690. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  3691. if (LDAP_SUCCESS != rc) { /* plugin is not available */
  3692. rc = 0; /* disabled, by default */
  3693. goto bail;
  3694. }
  3695. slapi_pblock_get(search_pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  3696. for (ep = entries; ep && *ep; ep++) {
  3697. if (slapi_entry_attr_has_syntax_value(*ep, "nsslapd-pluginEnabled", on_off)) {
  3698. rc = 1; /* plugin is on */
  3699. goto bail;
  3700. }
  3701. }
  3702. bail:
  3703. slapi_value_free(&on_off);
  3704. slapi_free_search_results_internal(search_pb);
  3705. slapi_pblock_destroy(search_pb);
  3706. slapi_ch_free_string(&filter);
  3707. return rc;
  3708. }
  3709. /*
  3710. * Set given "type: attr" to the plugin default config entry
  3711. * (cn=plugin default config,cn=config) unless the same "type: attr" pair
  3712. * already exists in the entry.
  3713. */
  3714. int
  3715. slapi_set_plugin_default_config(const char *type, Slapi_Value *value)
  3716. {
  3717. Slapi_PBlock pb;
  3718. Slapi_Entry **entries = NULL;
  3719. int rc = LDAP_SUCCESS;
  3720. char **search_attrs = NULL; /* used by search */
  3721. if (NULL == type || '\0' == *type || NULL == value ) { /* nothing to do */
  3722. return rc;
  3723. }
  3724. charray_add(&search_attrs, slapi_ch_strdup(type));
  3725. /* cn=plugin default config,cn=config */
  3726. pblock_init(&pb);
  3727. slapi_search_internal_set_pb(&pb,
  3728. SLAPI_PLUGIN_DEFAULT_CONFIG, /* Base DN (normalized) */
  3729. LDAP_SCOPE_BASE,
  3730. "(objectclass=*)",
  3731. search_attrs, /* Attrs */
  3732. 0, /* AttrOnly */
  3733. NULL, /* Controls */
  3734. NULL, /* UniqueID */
  3735. (void *)plugin_get_default_component_id(),
  3736. 0);
  3737. slapi_search_internal_pb(&pb);
  3738. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  3739. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  3740. if (LDAP_SUCCESS == rc && entries && *entries) {
  3741. /* plugin default config entry exists */
  3742. int exists = 0;
  3743. Slapi_Attr *attr = NULL;
  3744. rc = slapi_entry_attr_find(*entries, type, &attr);
  3745. if (0 == rc) { /* type exists in the entry */
  3746. if (0 ==
  3747. slapi_attr_value_find(attr, slapi_value_get_berval(value))) {
  3748. /* value exists in the entry; we don't have to do anything. */
  3749. exists = 1;
  3750. }
  3751. }
  3752. slapi_free_search_results_internal(&pb);
  3753. pblock_done(&pb);
  3754. if (!exists) {
  3755. /* The argument attr is not in the plugin default config.
  3756. * Let's add it. */
  3757. Slapi_Mods smods;
  3758. Slapi_Value *va[2];
  3759. va[0] = value;
  3760. va[1] = NULL;
  3761. slapi_mods_init(&smods, 1);
  3762. slapi_mods_add_mod_values(&smods, LDAP_MOD_ADD, type, va);
  3763. pblock_init(&pb);
  3764. slapi_modify_internal_set_pb(&pb, SLAPI_PLUGIN_DEFAULT_CONFIG,
  3765. slapi_mods_get_ldapmods_byref(&smods),
  3766. NULL, NULL, /* UniqueID */
  3767. (void *)plugin_get_default_component_id(),
  3768. 0 /* Flags */ );
  3769. slapi_modify_internal_pb(&pb);
  3770. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  3771. slapi_mods_done(&smods);
  3772. pblock_done(&pb);
  3773. }
  3774. } else { /* cn=plugin default config does not exist. Let's add it. */
  3775. Slapi_Mods smods;
  3776. Slapi_Value *va[2];
  3777. slapi_free_search_results_internal(&pb);
  3778. pblock_done(&pb);
  3779. va[0] = value;
  3780. va[1] = NULL;
  3781. slapi_mods_init(&smods, 1);
  3782. slapi_mods_add_string(&smods, LDAP_MOD_ADD, "objectClass", "top");
  3783. slapi_mods_add_string(&smods, LDAP_MOD_ADD, "objectClass",
  3784. "extensibleObject");
  3785. slapi_mods_add_mod_values(&smods, LDAP_MOD_ADD, type, va);
  3786. pblock_init(&pb);
  3787. slapi_add_internal_set_pb(&pb, SLAPI_PLUGIN_DEFAULT_CONFIG,
  3788. slapi_mods_get_ldapmods_byref(&smods), NULL,
  3789. (void *)plugin_get_default_component_id(),
  3790. 0 /* Flags */ );
  3791. slapi_add_internal_pb(&pb);
  3792. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  3793. slapi_mods_done(&smods);
  3794. pblock_done(&pb);
  3795. }
  3796. charray_free(search_attrs);
  3797. return rc;
  3798. }
  3799. /*
  3800. * Get attribute values of given type from the plugin default config entry
  3801. * (cn=plugin default config,cn=config).
  3802. *
  3803. * Caller is responsible to free attrs by slapi_valueset_free.
  3804. */
  3805. int
  3806. slapi_get_plugin_default_config(char *type, Slapi_ValueSet **valueset)
  3807. {
  3808. Slapi_PBlock pb;
  3809. Slapi_Entry **entries = NULL;
  3810. int rc = LDAP_PARAM_ERROR;
  3811. char **search_attrs = NULL; /* used by search */
  3812. if (NULL == type || '\0' == *type || NULL == valueset) { /* nothing to do */
  3813. return rc;
  3814. }
  3815. charray_add(&search_attrs, slapi_ch_strdup(type));
  3816. /* cn=plugin default config,cn=config */
  3817. pblock_init(&pb);
  3818. slapi_search_internal_set_pb(&pb,
  3819. SLAPI_PLUGIN_DEFAULT_CONFIG, /* Base DN (normalized) */
  3820. LDAP_SCOPE_BASE,
  3821. "(objectclass=*)",
  3822. search_attrs, /* Attrs */
  3823. 0, /* AttrOnly */
  3824. NULL, /* Controls */
  3825. NULL, /* UniqueID */
  3826. (void *)plugin_get_default_component_id(),
  3827. 0);
  3828. slapi_search_internal_pb(&pb);
  3829. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  3830. slapi_pblock_get(&pb, SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &entries);
  3831. if (LDAP_SUCCESS == rc && entries && *entries) {
  3832. /* default config entry exists */
  3833. /* retrieve attribute values from the entry */
  3834. Slapi_Attr *attr = NULL;
  3835. rc = slapi_entry_attr_find(*entries, type, &attr);
  3836. if (0 == rc) { /* type value exists */
  3837. rc = slapi_attr_get_valueset(attr, valueset);
  3838. } else {
  3839. rc = LDAP_NO_SUCH_ATTRIBUTE;
  3840. }
  3841. }
  3842. slapi_free_search_results_internal(&pb);
  3843. pblock_done(&pb);
  3844. charray_free(search_attrs);
  3845. return rc;
  3846. }
  3847. void
  3848. slapi_set_plugin_open_rootdn_bind(Slapi_PBlock *pb){
  3849. struct pluginconfig *config = &pb->pb_plugin->plg_conf;
  3850. ptd_set_special_data(&(config->plgc_bind_subtrees), PLGC_DATA_BIND_ROOT);
  3851. }
  3852. PRBool
  3853. slapi_disordely_shutdown(PRBool set)
  3854. {
  3855. static PRBool is_disordely_shutdown = PR_FALSE;
  3856. if (set) {
  3857. is_disordely_shutdown = PR_TRUE;
  3858. }
  3859. return (is_disordely_shutdown);
  3860. }
  3861. /*
  3862. * Plugin operation counters
  3863. *
  3864. * Since most plugins can now be stopped and started dynamically we need
  3865. * to take special care when calling a close function. Since many plugins
  3866. * use global locks and data structures, these can not be freed/destroyed
  3867. * while there are active operations using them.
  3868. */
  3869. void
  3870. slapi_plugin_op_started(void *p)
  3871. {
  3872. struct slapdplugin *plugin = (struct slapdplugin *)p;
  3873. if(plugin){
  3874. slapi_counter_increment(plugin->plg_op_counter);
  3875. }
  3876. }
  3877. void
  3878. slapi_plugin_op_finished(void *p)
  3879. {
  3880. struct slapdplugin *plugin = (struct slapdplugin *)p;
  3881. if(plugin){
  3882. slapi_counter_decrement(plugin->plg_op_counter);
  3883. }
  3884. }
  3885. /*
  3886. * Waits for the operation counter to hit zero
  3887. */
  3888. void
  3889. plugin_op_all_finished(struct slapdplugin *p)
  3890. {
  3891. while(p && slapi_counter_get_value(p->plg_op_counter) > 0){
  3892. DS_Sleep(PR_MillisecondsToInterval(100));
  3893. }
  3894. }
  3895. void
  3896. plugin_set_started(struct slapdplugin *p)
  3897. {
  3898. p->plg_started = 1;
  3899. p->plg_stopped = 0;
  3900. }
  3901. void
  3902. plugin_set_stopped(struct slapdplugin *p)
  3903. {
  3904. /*
  3905. * We do not set "plg_stopped" here, because that is only used
  3906. * once the plugin has called its CLOSE function. Setting
  3907. * "plg_started" to 0 will prevent new operations from calling
  3908. * the plugin.
  3909. */
  3910. p->plg_started = 0;
  3911. }
  3912. int
  3913. slapi_plugin_running(Slapi_PBlock *pb)
  3914. {
  3915. int rc = 0;
  3916. if(pb->pb_plugin){
  3917. rc = pb->pb_plugin->plg_started;
  3918. }
  3919. return rc;
  3920. }
  3921. /*
  3922. * Allow "database" plugins to call the backend/backend txn plugins.
  3923. */
  3924. int
  3925. slapi_plugin_call_preop_be_plugins(Slapi_PBlock *pb, int function)
  3926. {
  3927. int be_func, betxn_func;
  3928. int rc = 0;
  3929. switch(function){
  3930. case SLAPI_PLUGIN_ADD_OP:
  3931. be_func = SLAPI_PLUGIN_BE_PRE_ADD_FN;
  3932. betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN;
  3933. break;
  3934. case SLAPI_PLUGIN_MOD_OP:
  3935. be_func = SLAPI_PLUGIN_BE_PRE_MODIFY_FN;
  3936. betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN;
  3937. break;
  3938. case SLAPI_PLUGIN_MODRDN_OP:
  3939. be_func = SLAPI_PLUGIN_BE_PRE_MODRDN_FN;
  3940. betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN;
  3941. break;
  3942. case SLAPI_PLUGIN_DEL_OP:
  3943. be_func = SLAPI_PLUGIN_BE_PRE_DELETE_FN;
  3944. betxn_func = SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN;
  3945. break;
  3946. default:
  3947. /* invalid function */
  3948. slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_preop_betxn_plugins",
  3949. "Invalid function specified - backend plugins will not be called.\n");
  3950. return 0;
  3951. }
  3952. /*
  3953. * Call the be preop plugins.
  3954. */
  3955. plugin_call_plugins(pb, be_func);
  3956. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  3957. /*
  3958. * Call the betxn preop plugins.
  3959. */
  3960. if (rc == LDAP_SUCCESS) {
  3961. plugin_call_plugins(pb, betxn_func);
  3962. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  3963. }
  3964. return rc;
  3965. }
  3966. int
  3967. slapi_plugin_call_postop_be_plugins(Slapi_PBlock *pb, int function)
  3968. {
  3969. int be_func, betxn_func;
  3970. int rc = 0;
  3971. switch(function){
  3972. case SLAPI_PLUGIN_ADD_OP:
  3973. be_func = SLAPI_PLUGIN_BE_POST_ADD_FN;
  3974. betxn_func = SLAPI_PLUGIN_BE_TXN_POST_ADD_FN;
  3975. break;
  3976. case SLAPI_PLUGIN_MOD_OP:
  3977. be_func = SLAPI_PLUGIN_BE_POST_MODIFY_FN;
  3978. betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN;
  3979. break;
  3980. case SLAPI_PLUGIN_MODRDN_OP:
  3981. be_func = SLAPI_PLUGIN_BE_POST_MODRDN_FN;
  3982. betxn_func = SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN;
  3983. break;
  3984. case SLAPI_PLUGIN_DEL_OP:
  3985. be_func = SLAPI_PLUGIN_BE_POST_DELETE_FN;
  3986. betxn_func = SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN;
  3987. break;
  3988. default:
  3989. /* invalid function */
  3990. slapi_log_error(SLAPI_LOG_FATAL, "slapi_plugin_call_postop_betxn_plugins",
  3991. "Invalid function specified - backend plugins will not be called.\n");
  3992. return 0;
  3993. }
  3994. /* next, give the be txn plugins a crack at it */;
  3995. plugin_call_plugins(pb, betxn_func);
  3996. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  3997. /* finally, give the be plugins a crack at it */
  3998. plugin_call_plugins(pb, be_func);
  3999. if (rc == LDAP_SUCCESS) {
  4000. slapi_pblock_get(pb, SLAPI_RESULT_CODE, &rc);
  4001. }
  4002. return rc;
  4003. }