1
0

acllas.c 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539
  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. #include <ipfstruct.h>
  13. #include "acl.h"
  14. /*
  15. A word on this file:
  16. The various routines here implement each component of the subject of an aci
  17. eg. "groupdn", "userdn","roledn", "userattr" etc.
  18. They are responsible for evaluating each individual keyword not for doing
  19. the boolean combination of these keywords, nor for combining multiple
  20. allow()/deny() statements--that's libaccess's job.
  21. For example, for "groupdn", DS_LASGroupDnEval might have to evaluate
  22. something like this:
  23. "groupdn = "ldap:///cn=G1,o=sun.com || ldap:///cn=G2,o=sun.com"
  24. The "=" here may be "!=" as well and these routines take care of the
  25. comparator.
  26. These rotuines get called via acl__TestRights(), which calls
  27. ACL_EvalTestRights() a libaccess routine (the immediately calling routine is
  28. ACLEvalAce() in oneeval.cpp).
  29. They should return LAS_EVAL_TRUE, if that keyword component evaluates to
  30. TRUE, LAS_EVAL_FALSE if it evaluates to FALSE and LAS_EVAL_FAIL if an
  31. error occurrs during evaluation. Note that once any component of a subject
  32. returns LAS_EVAL_FAIL, the evaluation in libaccess stops and the whole
  33. subject does not match and that aci is not applied.
  34. */
  35. /*
  36. A word on three-valued logic:
  37. In general when you do boolean combination of terms some of which
  38. may evaluate to UNDEFINED then you need to define what the combination
  39. means.
  40. So, for example libaccess implements a scheme which once UNDEFINED
  41. is returned for a term, it bales out of the
  42. evaluation and the whole expression evaluates to UNDEFINED.
  43. In this case the aci will not apply.
  44. On the other hand LDAP filters (cf. rfc2251 4.5.1) say that for OR,
  45. an expression will
  46. evaluate to TRUE if any term is TRUE, even if some terms are UNDEFINED.
  47. Other off the cuff options might be to redefine UNDEFINED to be FALSE,
  48. or TRUE.
  49. Which is best ?
  50. Well it probably depends on exactly what is to decided based on the
  51. evaluation of the logical expression. However, the final suggestion is
  52. almost certainly
  53. bad--you are unlikely to want to take an action based on an undefined
  54. result and
  55. defining UNDEFINED to be either TRUE or FALSE may result in the overall
  56. expression
  57. returning TRUE--a security hole. The only case this might work is if you
  58. are dealing with restricted
  59. expressions eg. terms may only be AND'ed togther--in this case defining
  60. UNDEFINED to be FALSE would guarantee a result of FALSE.
  61. The libaccess approach of returning UNDEFINED once an UNDEFINED is
  62. encountered during
  63. evaluation is not too bad--at least it guarantees that no aci will apply
  64. based on an
  65. undefined value. However, with an aci like this "...allow(all) A or B"
  66. where A returned UNDEFINED, you might be disappointed not to receive the
  67. rights if it was B that
  68. was granting you the rights and evaluation of A, which has nothing to do
  69. with you, returns UNDEFINED. In the case of an aci like
  70. "...deny(all) A or B" then the same
  71. situation is arguably a security hole. Note that this scheme also makes
  72. the final result
  73. dependent on the evaluation order and so if the evaluation engine does
  74. anything fancy internally (eg. reordering the terms in an OR so that fast
  75. to evaluate ones came first) then
  76. this would need to be documented so that a user (or a tool) could look at
  77. the external syntax and figure out the result of the evaluation.
  78. Also it breaks commutivity and De Morgans law.
  79. The LDAP filter scheme is starting to look good--it solves the problems of
  80. the
  81. libaccess approach, makes the final result of an expression independent of
  82. the evaluation order and
  83. gives you back commutivity of OR and AND. De Morgans is still broken, but
  84. that's because of the asymmetry of behaviour of UNDEFINED with OR and AND.
  85. So...?
  86. For acis, in general it can look like this:
  87. "...allow(rights)(LogicalCombinationofBindRule);
  88. deny(LogicalCombinationOfBindRule)...."
  89. A BindRule is one of the "userdn", "groupdn" or "userattr" things and it
  90. can look like this:
  91. "groupdn = "ldap:///cn=G1,o=sun.com || ldap:///cn=G2,o=sun.com"
  92. The "=" here may be "!=" as well and these routines take care of the
  93. comparator.
  94. For "userattr" keywords a mutilvalued attribute amounts a logical OR of the
  95. individual values. There is also a logical OR over the different levels
  96. as specified by the "parent" keyword.
  97. In fact there are three levels of logical combination:
  98. 1. In the aclplugin:
  99. The "||" and "!=" combinator for BindRule keywords like userdn and
  100. groupdn.
  101. The fact that for the "userattr" keyword, a mutilvalued attribute is
  102. evaluated as "||". Same for the different levels.
  103. 2. In libaccess:
  104. The logical combination of BindRules.
  105. 3. In libaccess:
  106. The evaluation of multiple BindRules seperated by ";", which means OR.
  107. The LDAP filter three-valued logic SHOULD be applied to each level but
  108. here's the way it works right now:
  109. 1. At this level it depends....
  110. DS_LASIpGetter - get attr for IP -
  111. returns ip address or LAS_EVAL_FAIL for error.
  112. no logical combination.
  113. DS_LASDnsGetter - get attr for DNS-
  114. returns dns name or LAS_EVAL_FAIL for error
  115. no logical combination.
  116. DS_LASUserDnEval - LAS Evaluation for USERDN -
  117. three-valued logic
  118. logical combination: || and !=
  119. DS_LASGroupDnEval - LAS Evaluation for GROUPDN -
  120. three-valued logic
  121. logical combination: || and !=
  122. DS_LASRoleDnEval - LAS Evaluation for ROLEDN -
  123. three-valued logic
  124. logical combination: || and !=
  125. DS_LASUserDnAttrEval - LAS Evaluation for USERDNATTR and SELFDNATTR-
  126. three-valued logic
  127. logical combination || (over specified attribute values and
  128. parent keyword levels), !=
  129. DS_LASAuthMethodEval - LAS Evaluation for AUTHMETHOD -
  130. three-valued logic ( logical combinations: !=)
  131. DS_LASGroupDnAttrEval - LAS Evaluation for GROUPDNATTR -
  132. three-valued logic
  133. logical combination || (over specified attribute values and
  134. parent keyword levels), !=
  135. DS_LASUserAttrEval - LAS Evaluation for USERATTR -
  136. USER, GROUPDN and ROLEDN as above.
  137. LDAPURL -- three-valued logic (logical combinations: || over
  138. specified attribute vales, !=)
  139. attrname#attrvalue -- three-valued logic, logical combination:!=
  140. 2. The libaccess scheme applies at this level.
  141. 3. The LDAP filter three-valued logic applies at this level.
  142. Example of realistic, non-bizarre things that cause evaluation of a
  143. BindRule to be undefined are exceeding some resource limits (nesting level,
  144. lookthrough limit) in group membership evaluation, or trying to get ADD
  145. permission from the "userattr" keyword at "parent" level 0.
  146. Note that not everything that might be construed as an error needs to be
  147. taken as UNDEFINED. For example, things like not finding a user or an
  148. attribute in an entry can be defined away as TRUE or FALSE. eg. in an
  149. LDAP filter (cn=rob) applied to an entry where cn is not present is FALSE,
  150. not UNDEFINED. Similarly, if the number of levels in a parent keyword
  151. exceeds the allowed limit, we just ignore the rest--though this
  152. is a syntax error which should be detected at parse time.
  153. */
  154. /* To get around warning: declared in ldapserver/lib/ldaputil/ldaputili.h */
  155. extern int ldapu_member_certificate_match (void* cert, const char* desc);
  156. /****************************************************************************/
  157. /* Defines, Constants, ande Declarations */
  158. /****************************************************************************/
  159. static char* const type_objectClass = "objectclass";
  160. static char* const filter_groups = "(|(objectclass=groupOfNames) (objectclass=groupOfUniqueNames)(objectclass=groupOfCertificates)(objectclass=groupOfURLs))";
  161. static char* const type_member = "member";
  162. static char* const type_uniquemember = "uniquemember";
  163. static char* const type_memberURL = "memberURL";
  164. static char* const type_memberCert = "memberCertificateDescription";
  165. /* cache strategy for groups */
  166. #define ACLLAS_CACHE_MEMBER_GROUPS 0x1
  167. #define ACLLAS_CACHE_NOT_MEMBER_GROUPS 0x2
  168. #define ACLLAS_CACHE_ALL_GROUPS 0x3
  169. /****************************************************************************/
  170. /* prototypes */
  171. /****************************************************************************/
  172. static int acllas__handle_group_entry(Slapi_Entry *, void *);
  173. static int acllas__user_ismember_of_group(struct acl_pblock *aclpb,
  174. char* groupDN,
  175. char* clientDN,
  176. int cache_status,
  177. CERTCertificate *clientCert);
  178. static int acllas__user_has_role( struct acl_pblock *aclpb,
  179. Slapi_DN *roleDN, Slapi_DN *clientDn);
  180. static int acllas__add_allgroups (Slapi_Entry* e, void *callback_data);
  181. static int acllas__eval_memberGroupDnAttr (char *attrName,
  182. Slapi_Entry *e,
  183. char *n_clientdn,
  184. struct acl_pblock *aclpb);
  185. static int acllas__verify_client (Slapi_Entry* e, void *callback_data);
  186. static int acllas__verify_ldapurl (Slapi_Entry* e, void *callback_data);
  187. static char* acllas__dn_parent( char *dn, int level);
  188. static int acllas__get_members (Slapi_Entry* e, void *callback_data);
  189. static int acllas__client_match_URL (struct acl_pblock *aclpb,
  190. char *n_dn, char *url );
  191. static int acllas__handle_client_search (Slapi_Entry *e, void *callback_data);
  192. static int __acllas_setup ( NSErr_t *errp, char *attr_name, CmpOp_t comparator, int allow_range,
  193. char *attr_pattern, int *cachable, void **LAS_cookie,
  194. PList_t subject, PList_t resource, PList_t auth_info,
  195. PList_t global_auth, char *lasType, char *lasName, lasInfo *linfo);
  196. int
  197. aclutil_evaluate_macro( char * user, lasInfo *lasinfo,
  198. acl_eval_types evalType );
  199. static int
  200. acllas_eval_one_user( struct acl_pblock *aclpb,
  201. char * clientDN, char *userKeyword);
  202. static int
  203. acllas_eval_one_group(char *group, lasInfo *lasinfo);
  204. static int
  205. acllas_eval_one_role(char *role, lasInfo *lasinfo);
  206. static char **
  207. acllas_replace_dn_macro( char *rule, char *matched_val, lasInfo *lasinfo);
  208. static char **
  209. acllas_replace_attr_macro( char *rule, lasInfo *lasinfo);
  210. static int
  211. acllas_eval_one_target_filter( char * str, Slapi_Entry *e);
  212. /****************************************************************************/
  213. int
  214. DS_LASIpGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  215. auth_info, PList_t global_auth, void *arg)
  216. {
  217. struct acl_pblock *aclpb = NULL;
  218. PRNetAddr *client_praddr = NULL;
  219. char ip_str[256];
  220. int rv = LAS_EVAL_TRUE;
  221. rv = ACL_GetAttribute(errp, DS_PROP_ACLPB, (void **)&aclpb, subject, resource, auth_info, global_auth);
  222. if ( rv != LAS_EVAL_TRUE || ( NULL == aclpb )) {
  223. acl_print_acllib_err(errp, NULL);
  224. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  225. "DS_LASIpGetter:Unable to get the ACLPB(%d)\n", rv);
  226. return LAS_EVAL_FAIL;
  227. }
  228. client_praddr = (PRNetAddr *)slapi_ch_malloc(sizeof(PRNetAddr));
  229. if(client_praddr == NULL){
  230. slapi_log_error( SLAPI_LOG_FATAL, plugin_name, "DS_LASIpGetter: failed to allocate client_praddr\n");
  231. return( LAS_EVAL_FAIL );
  232. }
  233. if ( slapi_pblock_get( aclpb->aclpb_pblock, SLAPI_CONN_CLIENTNETADDR, client_praddr ) != 0 ) {
  234. slapi_log_error( SLAPI_LOG_FATAL, plugin_name, "DS_LASIpGetter: Could not get client IP.\n" );
  235. slapi_ch_free((void **)&client_praddr);
  236. return( LAS_EVAL_FAIL );
  237. }
  238. rv = PListInitProp(subject, 0, ACL_ATTR_IP, (void *)client_praddr, NULL);
  239. if (rv < 0) {
  240. slapi_log_error ( SLAPI_LOG_ACL, plugin_name, "DS_LASIpGetter: "
  241. "Couldn't set the client addr property(%d)\n", rv );
  242. slapi_ch_free((void **)&client_praddr);
  243. return LAS_EVAL_FAIL;
  244. }
  245. if( PR_NetAddrToString(client_praddr, ip_str, sizeof(ip_str)) == PR_SUCCESS){
  246. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "DS_LASIpGetter: "
  247. "Returning client ip address '%s'\n", ip_str);
  248. } else {
  249. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "DS_LASIpGetter: "
  250. "Returning client ip address 'unknown'\n");
  251. }
  252. return LAS_EVAL_TRUE;
  253. }
  254. /*
  255. * This is called from the libaccess code when it needs to find a dns name.
  256. * It's called from ACL_GetAttribute() when it finds that ACL_ATTR_DNS is
  257. * not already part of the proplist.
  258. *
  259. */
  260. int
  261. DS_LASDnsGetter(NSErr_t *errp, PList_t subject, PList_t resource, PList_t
  262. auth_info, PList_t global_auth, void *arg)
  263. {
  264. struct acl_pblock *aclpb = NULL;
  265. PRNetAddr client_praddr;
  266. PRHostEnt *hp;
  267. char *dnsName = NULL;
  268. int rv;
  269. struct berval **clientDns;
  270. rv = ACL_GetAttribute(errp, DS_PROP_ACLPB, (void **)&aclpb,
  271. subject, resource, auth_info, global_auth);
  272. if ( rv != LAS_EVAL_TRUE || ( NULL == aclpb )) {
  273. acl_print_acllib_err(errp, NULL);
  274. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  275. "DS_LASDnsGetter:Unable to get the ACLPB(%d)\n", rv);
  276. return LAS_EVAL_FAIL;
  277. }
  278. if ( slapi_pblock_get( aclpb->aclpb_pblock, SLAPI_CLIENT_DNS, &clientDns ) != 0 ) {
  279. slapi_log_error( SLAPI_LOG_FATAL, plugin_name, "Could not get client IP.\n" );
  280. return( LAS_EVAL_FAIL );
  281. }
  282. /*
  283. * If the client hostname has already been put into the pblock then
  284. * use that. Otherwise we work it out and add it ourselves.
  285. * This info is connection-lifetime so with multiple operaitons on the same
  286. * connection we will only do the calculation once.
  287. *
  288. * rbyrneXXX surely this code would be better in connection.c so
  289. * the name would be just there waiting for us, and everyone else.
  290. *
  291. */
  292. if ( clientDns && clientDns[0] != NULL && clientDns[0]->bv_val ) {
  293. dnsName = clientDns[0]->bv_val;
  294. } else {
  295. struct berval **dnsList;
  296. char buf[PR_NETDB_BUF_SIZE];
  297. if ( slapi_pblock_get( aclpb->aclpb_pblock, SLAPI_CONN_CLIENTNETADDR, &client_praddr ) != 0 ) {
  298. slapi_log_error( SLAPI_LOG_FATAL, plugin_name, "Could not get client IP.\n" );
  299. return( LAS_EVAL_FAIL );
  300. }
  301. hp = (PRHostEnt *)slapi_ch_malloc( sizeof(PRHostEnt) );
  302. if ( PR_GetHostByAddr( &(client_praddr), (char *)buf, sizeof(buf), hp ) == PR_SUCCESS ) {
  303. if ( hp->h_name != NULL ) {
  304. dnsList = (struct berval**)
  305. slapi_ch_calloc (1, sizeof(struct berval*) * (1 + 1));
  306. *dnsList = (struct berval*)
  307. slapi_ch_calloc ( 1, sizeof(struct berval));
  308. dnsName = (*dnsList)->bv_val = slapi_ch_strdup( hp->h_name );
  309. (*dnsList)->bv_len = strlen ( (*dnsList)->bv_val );
  310. slapi_pblock_set( aclpb->aclpb_pblock, SLAPI_CLIENT_DNS, &dnsList );
  311. }
  312. }
  313. slapi_ch_free( (void **)&hp );
  314. }
  315. if ( NULL == dnsName ) return LAS_EVAL_FAIL;
  316. rv = PListInitProp(subject, 0, ACL_ATTR_DNS, dnsName, NULL);
  317. if (rv < 0) {
  318. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  319. "DS_LASDnsGetter:Couldn't set the DNS property(%d)\n", rv );
  320. return LAS_EVAL_FAIL;
  321. }
  322. slapi_log_error ( SLAPI_LOG_ACL, plugin_name, "DNS name: %s\n", dnsName );
  323. return LAS_EVAL_TRUE;
  324. }
  325. /***************************************************************************/
  326. /* New LASes */
  327. /* */
  328. /* 1. user, groups. -- stubs to report errors. Not supported. */
  329. /* 2. userdn */
  330. /* 3. groupdn */
  331. /* 4. userdnattr */
  332. /* 5. authmethod */
  333. /* 6. groupdnattr */
  334. /* 7. roledn */
  335. /* */
  336. /* */
  337. /***************************************************************************/
  338. int
  339. DS_LASUserEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  340. char *attr_pattern, int *cachable, void **LAS_cookie,
  341. PList_t subject, PList_t resource, PList_t auth_info,
  342. PList_t global_auth)
  343. {
  344. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  345. "User LAS is not supported in the ACL\n");
  346. return LAS_EVAL_INVALID;
  347. }
  348. int
  349. DS_LASGroupEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  350. char *attr_pattern, int *cachable, void **LAS_cookie,
  351. PList_t subject, PList_t resource, PList_t auth_info,
  352. PList_t global_auth)
  353. {
  354. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  355. "Group LAS is not supported in the ACL\n");
  356. return LAS_EVAL_INVALID;
  357. }
  358. /***************************************************************************
  359. *
  360. * DS_LASUserDnEval
  361. * Evaluate the "userdn" LAS. See if the user has rights.
  362. *
  363. * Input:
  364. * attr_name The string "userdn" - in lower case.
  365. * comparator CMP_OP_EQ or CMP_OP_NE only
  366. * attr_pattern A comma-separated list of users
  367. * cachable Always set to FALSE.
  368. * subject Subject property list
  369. * resource Resource property list
  370. * auth_info Authentication info, if any
  371. *
  372. * Returns:
  373. * retcode The usual LAS return codes.
  374. *
  375. * Error Handling:
  376. * None.
  377. *
  378. **************************************************************************/
  379. int
  380. DS_LASUserDnEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  381. char *attr_pattern, int *cachable, void **LAS_cookie,
  382. PList_t subject, PList_t resource, PList_t auth_info,
  383. PList_t global_auth)
  384. {
  385. char *users = NULL;
  386. char *s_user, *user = NULL;
  387. char *ptr = NULL;
  388. char *end_dn = NULL;
  389. char *n_edn = NULL;
  390. char *parent_dn = NULL;
  391. int matched;
  392. int rc;
  393. short len;
  394. const size_t LDAP_URL_prefix_len = strlen(LDAP_URL_prefix);
  395. const size_t LDAPS_URL_prefix_len = strlen(LDAPS_URL_prefix);
  396. lasInfo lasinfo;
  397. int got_undefined = 0;
  398. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  399. attr_pattern,cachable,LAS_cookie,
  400. subject, resource, auth_info,global_auth,
  401. DS_LAS_USERDN, "DS_LASUserDnEval", &lasinfo )) ) {
  402. return LAS_EVAL_FAIL;
  403. }
  404. users = slapi_ch_strdup(attr_pattern);
  405. user = users;
  406. matched = ACL_FALSE;
  407. /* check if the clientdn is one of the users */
  408. while(user != 0 && *user != 0 && matched != ACL_TRUE ) {
  409. /* ignore leading whitespace */
  410. while(ldap_utf8isspace(user))
  411. LDAP_UTF8INC(user);
  412. /* Now we must see the userdn in the following
  413. ** formats:
  414. **
  415. ** The following formats are supported:
  416. **
  417. ** 1. The DN itself:
  418. ** allow (read) userdn = "ldap:///cn=prasanta, ..."
  419. **
  420. ** 2. keyword SELF:
  421. ** allow (write)
  422. ** userdn = "ldap:///self"
  423. **
  424. ** 3. Pattern:
  425. ** deny (read) userdn = "ldap:///cn=*, o=netscape, c = us";
  426. **
  427. ** 4. Anonymous user
  428. ** deny (read, write) userdn = "ldap:///anyone"
  429. **
  430. ** 5. All users (All authenticated users)
  431. ** allow (search) ** userdn = "ldap:///all"
  432. ** 6. parent "ldap:///parent"
  433. ** 7. Synamic users using the URL
  434. **
  435. **
  436. ** DNs must be separated by "||". Ex:
  437. ** allow (read)
  438. ** userdn = "ldap:///DN1 || ldap:///DN2"
  439. */
  440. /* The DN is now "ldap:///DN"
  441. ** remove the "ldap:///" part
  442. */
  443. if (strncasecmp (user, LDAP_URL_prefix, LDAP_URL_prefix_len) == 0) {
  444. s_user = user;
  445. user += LDAP_URL_prefix_len;
  446. } else if (strncasecmp (user, LDAPS_URL_prefix, LDAPS_URL_prefix_len) == 0) {
  447. s_user = user;
  448. user += LDAPS_URL_prefix_len;
  449. } else {
  450. char ebuf[ BUFSIZ ];
  451. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  452. "DS_LASUserDnEval:Syntax error(%s)\n",
  453. escape_string_with_punctuation( user, ebuf ));
  454. return LAS_EVAL_FAIL;
  455. }
  456. /* Now we have the starting point of the "userdn" */
  457. if ((end_dn = strstr(user, "||")) != NULL) {
  458. auto char *t = end_dn;
  459. LDAP_UTF8INC(end_dn);
  460. LDAP_UTF8INC(end_dn);
  461. *t = 0;
  462. }
  463. /* Now user is a null terminated string */
  464. if (*user) {
  465. while(ldap_utf8isspace(user))
  466. LDAP_UTF8INC(user);
  467. /* ignore trailing whitespace */
  468. len = strlen(user);
  469. ptr = user+len-1;
  470. while(ptr >= user && ldap_utf8isspace(ptr)) {
  471. *ptr = '\0';
  472. LDAP_UTF8DEC(ptr);
  473. }
  474. }
  475. /*
  476. ** Check , if the user is a anonymous user. In that case
  477. ** We must find the rule "ldap:///anyone"
  478. */
  479. if (lasinfo.anomUser) {
  480. if (strcasecmp(user, "anyone") == 0 ) {
  481. /* matches -- anonymous user */
  482. matched = ACL_TRUE;
  483. break;
  484. }
  485. } else {
  486. /* URL format */
  487. if ((PL_strcasestr (user, ACL_RULE_MACRO_DN_KEY) != NULL) ||
  488. (PL_strcasestr (user, ACL_RULE_MACRO_DN_LEVELS_KEY) != NULL) ||
  489. (PL_strcasestr (user, ACL_RULE_MACRO_ATTR_KEY) != NULL)) {
  490. matched = aclutil_evaluate_macro( s_user, &lasinfo,
  491. ACL_EVAL_USER);
  492. if (matched == ACL_TRUE) {
  493. break;
  494. }
  495. } else if (strchr (user, '?') != NULL) {
  496. /* URL format */
  497. if (acllas__client_match_URL ( lasinfo.aclpb, lasinfo.clientDn,
  498. s_user) == ACL_TRUE) {
  499. matched = ACL_TRUE;
  500. break;
  501. }
  502. } else if (strcasecmp(user, "anyone") == 0 ) {
  503. /* Anyone means anyone in the world */
  504. matched = ACL_TRUE;
  505. break;
  506. } else if (strcasecmp(user, "self") == 0) {
  507. if (n_edn == NULL) {
  508. n_edn = slapi_entry_get_ndn ( lasinfo.resourceEntry );
  509. }
  510. if (slapi_utf8casecmp((ACLUCHP)lasinfo.clientDn, (ACLUCHP)n_edn) == 0)
  511. matched = ACL_TRUE;
  512. break;
  513. } else if (strcasecmp(user, "parent") == 0) {
  514. if (n_edn == NULL) {
  515. n_edn = slapi_entry_get_ndn ( lasinfo.resourceEntry );
  516. }
  517. /* get the parent */
  518. parent_dn = slapi_dn_parent(n_edn);
  519. if (parent_dn &&
  520. slapi_utf8casecmp ((ACLUCHP)lasinfo.clientDn, (ACLUCHP)parent_dn) == 0)
  521. matched = ACL_TRUE;
  522. if (parent_dn) slapi_ch_free ( (void **) &parent_dn );
  523. break;
  524. } else if (strcasecmp(user, "all") == 0) {
  525. /* matches -- */
  526. matched = ACL_TRUE;
  527. break;
  528. } else if (strchr(user, '*')) {
  529. char line[200];
  530. char *lineptr = &line[0];
  531. char *newline = NULL;
  532. int lenu = 0;
  533. Slapi_Filter *f = NULL;
  534. char *tt;
  535. int filterChoice;
  536. /*
  537. ** what we are doing is faking the str2simple()
  538. ** function with a "userdn = "user")
  539. */
  540. for (tt = user; *tt; tt++)
  541. *tt = TOLOWER ( *tt );
  542. if ((lenu = strlen(user)) > 190) { /* 200 - 9 for "(userdn=%s)" */
  543. newline = slapi_ch_malloc(lenu + 10);
  544. lineptr = newline;
  545. }
  546. sprintf (lineptr, "(userdn=%s)", user);
  547. if ((f = slapi_str2filter (lineptr)) == NULL) {
  548. if (newline) slapi_ch_free((void **) &newline);
  549. /* try the next one */
  550. break;
  551. }
  552. if (newline) slapi_ch_free((void **) &newline);
  553. filterChoice = slapi_filter_get_choice ( f );
  554. if (( filterChoice != LDAP_FILTER_SUBSTRINGS) &&
  555. ( filterChoice != LDAP_FILTER_PRESENT)) {
  556. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  557. "DS_LASUserDnEval:Error in gen. filter(%s)\n", user);
  558. }
  559. if ((rc = acl_match_substring( f,
  560. lasinfo.clientDn,
  561. 1 /*exact match */)
  562. ) == ACL_TRUE) {
  563. matched = ACL_TRUE;
  564. slapi_filter_free(f,1);
  565. break;
  566. }
  567. if (rc == ACL_ERR) {
  568. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  569. "DS_LASUserDnEval:Error in matching patteren(%s)\n",
  570. user);
  571. }
  572. slapi_filter_free(f,1);
  573. } else {
  574. /* Must be a simple dn then */
  575. char *normed = slapi_create_dn_string("%s", user);
  576. if (NULL == normed) {
  577. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  578. "DS_LASUserDnEval:Error in normalizing dn(%s)\n", user);
  579. normed = user;
  580. }
  581. rc = slapi_utf8casecmp((ACLUCHP)lasinfo.clientDn, (ACLUCHP)normed);
  582. if (normed != user) {
  583. slapi_ch_free_string(&normed);
  584. }
  585. if (0 == rc) {
  586. matched = ACL_TRUE;
  587. break;
  588. }
  589. }
  590. }
  591. if ( matched == ACL_DONT_KNOW ) {
  592. /* record this but keep going--maybe another user will evaluate to TRUE */
  593. got_undefined = 1;
  594. }
  595. /* Nothing matched -- try the next DN */
  596. user = end_dn;
  597. } /* end of while */
  598. slapi_ch_free ( (void **) &users);
  599. /*
  600. * If no terms were undefined, then evaluate as normal.
  601. * If there was an undefined term, but another one was TRUE, then we also evaluate
  602. * as normal. Otherwise, the whole expression is UNDEFINED.
  603. */
  604. if ( matched == ACL_TRUE || !got_undefined ) {
  605. if (comparator == CMP_OP_EQ) {
  606. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  607. } else {
  608. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  609. }
  610. } else {
  611. rc = LAS_EVAL_FAIL;
  612. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  613. "Returning UNDEFINED for userdn evaluation.\n");
  614. }
  615. return rc;
  616. }
  617. /***************************************************************************
  618. *
  619. * DS_LASGroupDnEval
  620. *
  621. *
  622. * Input:
  623. * attr_name The string "userdn" - in lower case.
  624. * comparator CMP_OP_EQ or CMP_OP_NE only
  625. * attr_pattern A comma-separated list of users
  626. * cachable Always set to FALSE.
  627. * subject Subject property list
  628. * resource Resource property list
  629. * auth_info Authentication info, if any
  630. *
  631. * Returns:
  632. * retcode The usual LAS return code
  633. * If the client is in any of the groups mentioned this groupdn keywrod
  634. * then returns LAS_EVAL_TRUE, if he's not in any LAS_EVAL_FALSE.
  635. * If any of the membership evaluations fail, then it goes on to evaluate the
  636. * others.
  637. *
  638. * Error Handling:
  639. * None.
  640. *
  641. **************************************************************************/
  642. int
  643. DS_LASGroupDnEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  644. char *attr_pattern, int *cachable, void **LAS_cookie,
  645. PList_t subject, PList_t resource, PList_t auth_info,
  646. PList_t global_auth)
  647. {
  648. char *groups;
  649. char *groupNameOrig;
  650. char *groupName;
  651. char *ptr;
  652. char *end_dn;
  653. int matched;
  654. int rc;
  655. int len;
  656. const size_t LDAP_URL_prefix_len = strlen(LDAP_URL_prefix);
  657. int any_group = 0;
  658. lasInfo lasinfo;
  659. int got_undefined = 0;
  660. /* the setup should not fail under normal operation */
  661. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  662. attr_pattern,cachable,LAS_cookie,
  663. subject, resource, auth_info,global_auth,
  664. DS_LAS_GROUPDN, "DS_LASGroupDnEval", &lasinfo )) ) {
  665. return LAS_EVAL_FAIL;
  666. }
  667. groups = slapi_ch_strdup(attr_pattern);
  668. groupNameOrig = groupName = groups;
  669. matched = ACL_FALSE;
  670. /* check if the groupdn is one of the users */
  671. while(groupName != 0 && *groupName != 0 && matched != ACL_TRUE) {
  672. /* ignore leading whitespace */
  673. while(ldap_utf8isspace(groupName))
  674. LDAP_UTF8INC(groupName);
  675. /*
  676. ** The syntax allowed for the groupdn is
  677. **
  678. ** Example:
  679. ** groupdn = "ldap:///dn1 || ldap:///dn2";
  680. **
  681. */
  682. if (strncasecmp (groupName, LDAP_URL_prefix,
  683. LDAP_URL_prefix_len) == 0) {
  684. groupName += LDAP_URL_prefix_len;
  685. } else {
  686. char ebuf[ BUFSIZ ];
  687. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  688. "DS_LASGroupDnEval:Syntax error(%s)\n",
  689. escape_string_with_punctuation( groupName, ebuf ));
  690. }
  691. /* Now we have the starting point of the "groupdn" */
  692. if ((end_dn = strstr(groupName, "||")) != NULL) {
  693. auto char *t = end_dn;
  694. LDAP_UTF8INC(end_dn);
  695. LDAP_UTF8INC(end_dn);
  696. /* removing trailing spaces */
  697. LDAP_UTF8DEC(t);
  698. while (' ' == *t || '\t' == *t) {
  699. LDAP_UTF8DEC(t);
  700. }
  701. LDAP_UTF8INC(t);
  702. *t = '\0';
  703. /* removing beginning spaces */
  704. while (' ' == *end_dn || '\t' == *end_dn) {
  705. LDAP_UTF8INC(end_dn);
  706. }
  707. }
  708. if (*groupName) {
  709. while(ldap_utf8isspace(groupName))
  710. LDAP_UTF8INC(groupName);
  711. /* ignore trailing whitespace */
  712. len = strlen(groupName);
  713. ptr = groupName+len-1;
  714. while(ptr >= groupName && ldap_utf8isspace(ptr)) {
  715. *ptr = '\0';
  716. LDAP_UTF8DEC(ptr);
  717. }
  718. }
  719. /*
  720. ** Now we have the DN of the group. Evaluate the "clientdn"
  721. ** and see if the user is a member of the group.
  722. */
  723. if (0 == (strcasecmp(groupName, "anyone"))) {
  724. any_group = 1;
  725. }
  726. if (any_group) {
  727. /* anyone in the world */
  728. matched = ACL_TRUE;
  729. break;
  730. } else if ( lasinfo.anomUser &&
  731. (lasinfo.aclpb->aclpb_clientcert == NULL) && (!any_group)) {
  732. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  733. "Group not evaluated(%s)\n", groupName);
  734. break;
  735. } else {
  736. if ((PL_strcasestr (groupName, ACL_RULE_MACRO_DN_KEY) != NULL) ||
  737. (PL_strcasestr (groupName, ACL_RULE_MACRO_DN_LEVELS_KEY) != NULL) ||
  738. (PL_strcasestr (groupName, ACL_RULE_MACRO_ATTR_KEY) != NULL)) {
  739. matched = aclutil_evaluate_macro( groupName, &lasinfo,
  740. ACL_EVAL_GROUP);
  741. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  742. "DS_LASGroupDnEval: Param group name:%s\n",
  743. groupName);
  744. } else {
  745. LDAPURLDesc *ludp = NULL;
  746. int urlerr = 0;
  747. int rval;
  748. Slapi_PBlock *myPb = NULL;
  749. Slapi_Entry **grpentries = NULL;
  750. /* Groupdn is full ldapurl? */
  751. if ((0 == (urlerr = slapi_ldap_url_parse(groupNameOrig, &ludp, 0, NULL))) &&
  752. NULL != ludp->lud_dn &&
  753. -1 != ludp->lud_scope &&
  754. NULL != ludp->lud_filter) {
  755. /* Yes, it is full ldapurl; Let's run the search */
  756. myPb = slapi_pblock_new ();
  757. slapi_search_internal_set_pb(
  758. myPb,
  759. ludp->lud_dn,
  760. ludp->lud_scope,
  761. ludp->lud_filter,
  762. NULL,
  763. 0,
  764. NULL /* controls */,
  765. NULL /* uniqueid */,
  766. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  767. 0 );
  768. slapi_search_internal_pb(myPb);
  769. slapi_pblock_get(myPb, SLAPI_PLUGIN_INTOP_RESULT, &rval);
  770. if (rval == LDAP_SUCCESS) {
  771. Slapi_Entry **ep;
  772. slapi_pblock_get(myPb,
  773. SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &grpentries);
  774. if ((grpentries != NULL) && (grpentries[0] != NULL)) {
  775. char *edn = NULL;
  776. for (ep = grpentries; *ep; ep++) {
  777. /* groups having ACI */
  778. edn = slapi_entry_get_ndn(*ep);
  779. matched = acllas_eval_one_group(edn, &lasinfo);
  780. if (ACL_TRUE == matched) {
  781. break; /* matched ! */
  782. }
  783. }
  784. }
  785. }
  786. slapi_free_search_results_internal(myPb);
  787. slapi_pblock_destroy (myPb);
  788. } else {
  789. if (urlerr) {
  790. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  791. "DS_LASGroupDnEval: Groupname [%s] not a valid ldap url: %d (%s)\n",
  792. groupNameOrig, urlerr, slapi_urlparse_err2string(urlerr));
  793. }
  794. /* normal evaluation */
  795. matched = acllas_eval_one_group( groupName, &lasinfo );
  796. }
  797. if ( ludp ) {
  798. ldap_free_urldesc( ludp );
  799. }
  800. }
  801. if ( matched == ACL_TRUE ) {
  802. break;
  803. } else if ( matched == ACL_DONT_KNOW ) {
  804. /* record this but keep going--maybe another group will evaluate to TRUE */
  805. got_undefined = 1;
  806. }
  807. }
  808. /* Nothing matched -- try the next DN */
  809. groupNameOrig = groupName = end_dn;
  810. } /* end of while */
  811. /*
  812. * If no terms were undefined, then evaluate as normal.
  813. * If there was an undefined term, but another one was TRUE, then we also evaluate
  814. * as normal. Otherwise, the whole expression is UNDEFINED.
  815. */
  816. if ( matched == ACL_TRUE || !got_undefined ) {
  817. if (comparator == CMP_OP_EQ) {
  818. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  819. } else {
  820. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  821. }
  822. } else {
  823. rc = LAS_EVAL_FAIL;
  824. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  825. "Returning UNDEFINED for groupdn evaluation.\n");
  826. }
  827. slapi_ch_free ((void**) &groups);
  828. return rc;
  829. }
  830. /***************************************************************************
  831. *
  832. * DS_LASRoleDnEval
  833. *
  834. *
  835. * Input:
  836. * attr_name The string "roledn" - in lower case.
  837. * comparator CMP_OP_EQ or CMP_OP_NE only
  838. * attr_pattern A "||" sperated list of roles
  839. * cachable Always set to FALSE.
  840. * subject Subject property list
  841. * resource Resource property list
  842. * auth_info Authentication info, if any
  843. *
  844. * Returns:
  845. * retcode The usual LAS return codes.
  846. *
  847. * Error Handling:
  848. * None.
  849. *
  850. **************************************************************************/
  851. int
  852. DS_LASRoleDnEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  853. char *attr_pattern, int *cachable, void **LAS_cookie,
  854. PList_t subject, PList_t resource, PList_t auth_info,
  855. PList_t global_auth)
  856. {
  857. char *roles;
  858. char *role;
  859. char *ptr;
  860. char *end_dn;
  861. int matched;
  862. int rc;
  863. int len;
  864. const size_t LDAP_URL_prefix_len = strlen(LDAP_URL_prefix);
  865. int any_role = 0;
  866. lasInfo lasinfo;
  867. int got_undefined = 0;
  868. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  869. attr_pattern,cachable,LAS_cookie,
  870. subject, resource, auth_info,global_auth,
  871. DS_LAS_ROLEDN, "DS_LASRoleDnEval",
  872. &lasinfo )) ) {
  873. return LAS_EVAL_FALSE;
  874. }
  875. roles = slapi_ch_strdup(attr_pattern);
  876. role = roles;
  877. matched = ACL_FALSE;
  878. /* check if the roledn is one of the users */
  879. while(role != 0 && *role != 0 && matched != ACL_TRUE) {
  880. /* ignore leading whitespace */
  881. while(ldap_utf8isspace(role))
  882. LDAP_UTF8INC(role);
  883. /*
  884. ** The syntax allowed for the roledn is
  885. **
  886. ** Example:
  887. ** roledn = "ldap:///roledn1 || ldap:///roledn2";
  888. **
  889. */
  890. if (strncasecmp (role, LDAP_URL_prefix,
  891. LDAP_URL_prefix_len) == 0) {
  892. role += LDAP_URL_prefix_len;
  893. } else {
  894. char ebuf[ BUFSIZ ];
  895. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  896. "DS_LASRoleDnEval:Syntax error(%s)\n",
  897. escape_string_with_punctuation( role, ebuf ));
  898. }
  899. /* Now we have the starting point of the "roledn" */
  900. if ((end_dn = strstr(role, "||")) != NULL) {
  901. auto char *t = end_dn;
  902. LDAP_UTF8INC(end_dn);
  903. LDAP_UTF8INC(end_dn);
  904. *t = 0;
  905. }
  906. if (*role) {
  907. while(ldap_utf8isspace(role))
  908. LDAP_UTF8INC(role);
  909. /* ignore trailing whitespace */
  910. len = strlen(role);
  911. ptr = role+len-1;
  912. while(ptr >= role && ldap_utf8isspace(ptr)) {
  913. *ptr = '\0';
  914. LDAP_UTF8DEC(ptr);
  915. }
  916. }
  917. /*
  918. ** Now we have the DN of the role. Evaluate the "clientdn"
  919. ** and see if the user has this role.
  920. */
  921. if (0 == (strcasecmp(role, "anyone"))) {
  922. any_role = 1;
  923. }
  924. if (any_role) {
  925. /* anyone in the world */
  926. matched = ACL_TRUE;
  927. break;
  928. } else if ( lasinfo.anomUser &&
  929. (lasinfo.aclpb->aclpb_clientcert == NULL) && (!any_role)) {
  930. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  931. "Role not evaluated(%s) for anon user\n", role);
  932. break;
  933. } else {
  934. /* Take care of param strings */
  935. if ((PL_strcasestr (role, ACL_RULE_MACRO_DN_KEY) != NULL) ||
  936. (PL_strcasestr (role, ACL_RULE_MACRO_DN_LEVELS_KEY) != NULL) ||
  937. (PL_strcasestr (role, ACL_RULE_MACRO_ATTR_KEY) != NULL)) {
  938. matched = aclutil_evaluate_macro( role, &lasinfo,
  939. ACL_EVAL_ROLE);
  940. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  941. "DS_LASRoleDnEval: Param role name:%s\n",
  942. role);
  943. } else {/* normal evaluation */
  944. matched = acllas_eval_one_role( role, &lasinfo);
  945. }
  946. if ( matched == ACL_TRUE ) {
  947. break;
  948. } else if ( matched == ACL_DONT_KNOW ) {
  949. /* record this but keep going--maybe another role will evaluate to TRUE */
  950. got_undefined = 1;
  951. }
  952. }
  953. /* Nothing matched -- try the next DN */
  954. role = end_dn;
  955. } /* end of while */
  956. /*
  957. * If no terms were undefined, then evaluate as normal.
  958. * If there was an undefined term, but another one was TRUE, then we also evaluate
  959. * as normal. Otherwise, the whole expression is UNDEFINED.
  960. */
  961. if ( matched == ACL_TRUE || !got_undefined ) {
  962. if (comparator == CMP_OP_EQ) {
  963. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  964. } else {
  965. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  966. }
  967. } else {
  968. rc = LAS_EVAL_FAIL;
  969. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  970. "Returning UNDEFINED for roledn evaluation.\n");
  971. }
  972. slapi_ch_free ((void**) &roles);
  973. return rc;
  974. }
  975. /***************************************************************************
  976. *
  977. * DS_LASUserDnAttrEval
  978. *
  979. *
  980. * Input:
  981. * attr_name The string "userdn" - in lower case.
  982. * comparator CMP_OP_EQ or CMP_OP_NE only
  983. * attr_pattern A comma-separated list of users
  984. * cachable Always set to FALSE.
  985. * subject Subject property list
  986. * resource Resource property list
  987. * auth_info Authentication info, if any
  988. *
  989. * Returns:
  990. * retcode The usual LAS return codes.
  991. *
  992. * Error Handling:
  993. * None.
  994. *
  995. **************************************************************************/
  996. struct userdnattr_info {
  997. char *attr;
  998. int result;
  999. char *clientdn;
  1000. Acl_PBlock *aclpb;
  1001. };
  1002. #define ACLLAS_MAX_LEVELS 10
  1003. int
  1004. DS_LASUserDnAttrEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  1005. char *attr_pattern, int *cachable, void **LAS_cookie,
  1006. PList_t subject, PList_t resource, PList_t auth_info,
  1007. PList_t global_auth)
  1008. {
  1009. char *n_currEntryDn = NULL;
  1010. char *s_attrName, *attrName;
  1011. char *ptr;
  1012. int matched;
  1013. int rc, len, i;
  1014. char *val;
  1015. Slapi_Attr *a;
  1016. int levels[ACLLAS_MAX_LEVELS];
  1017. int numOflevels =0;
  1018. struct userdnattr_info info = {0};
  1019. char *attrs[2] = { LDAP_ALL_USER_ATTRS, NULL };
  1020. lasInfo lasinfo;
  1021. int got_undefined = 0;
  1022. PRBool selfdn;
  1023. if (attr_name == NULL ||
  1024. (strcmp(DS_LAS_SELFDNATTR, attr_name) && strcmp(DS_LAS_USERDNATTR, attr_name))) {
  1025. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  1026. "DS_LASUserDnattr: invalid attr_name (should be %s or %s)\n",
  1027. DS_LAS_SELFDNATTR, DS_LAS_USERDNATTR);
  1028. return LAS_EVAL_FAIL;
  1029. }
  1030. selfdn = (strcmp(DS_LAS_SELFDNATTR, attr_name) == 0) ? PR_TRUE : PR_FALSE;
  1031. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  1032. attr_pattern,cachable,LAS_cookie,
  1033. subject, resource, auth_info,global_auth,
  1034. attr_name, "DS_LASUserDnAttrEval",
  1035. &lasinfo )) ) {
  1036. return LAS_EVAL_FAIL;
  1037. }
  1038. /*
  1039. ** The userdnAttr syntax is
  1040. ** userdnattr = <attribute> or
  1041. ** userdnattr = parent[0,2,4].attribute"
  1042. ** Ex:
  1043. ** userdnattr = manager; or
  1044. ** userdnattr = "parent[0,2,4].manager";
  1045. **
  1046. ** Here 0 means current level, 2 means grandfather and
  1047. ** 4 (great great grandfather)
  1048. **
  1049. ** The function of this LAS is to compare the value of the
  1050. ** attribute in the Slapi_Entry with the "userdn".
  1051. **
  1052. ** Ex: userdn: "cn=prasanta, o= netscape, c= us"
  1053. ** and in the Slapi_Entry the manager attribute has
  1054. ** manager = <value>. Compare the userdn with manager.value to
  1055. ** determine the result.
  1056. **
  1057. */
  1058. s_attrName = attrName = slapi_ch_strdup (attr_pattern);
  1059. /* ignore leading/trailing whitespace */
  1060. while(ldap_utf8isspace(attrName)) LDAP_UTF8INC(attrName);
  1061. len = strlen(attrName);
  1062. ptr = attrName+len-1;
  1063. while(ptr >= attrName && ldap_utf8isspace(ptr)) {
  1064. *ptr = '\0';
  1065. LDAP_UTF8DEC(ptr);
  1066. }
  1067. /* See if we have a parent[2].attr" rule */
  1068. if (strstr(attrName, "parent[") != NULL) {
  1069. char *word, *str, *next = NULL;
  1070. numOflevels = 0;
  1071. n_currEntryDn = slapi_entry_get_ndn ( lasinfo.resourceEntry );
  1072. str = attrName;
  1073. ldap_utf8strtok_r(str, "[],. ",&next);
  1074. /* The first word is "parent[" and so it's not important */
  1075. while ((word= ldap_utf8strtok_r(NULL, "[],.", &next)) != NULL) {
  1076. if (ldap_utf8isdigit(word)) {
  1077. while (word && ldap_utf8isspace(word)) LDAP_UTF8INC(word);
  1078. if (numOflevels < ACLLAS_MAX_LEVELS)
  1079. levels[numOflevels++] = atoi (word);
  1080. else {
  1081. /*
  1082. * Here, ignore the extra levels..it's really
  1083. * a syntax error which should have been ruled out at parse time
  1084. */
  1085. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  1086. "DS_LASUserDnattr: Exceeded the ATTR LIMIT:%d: Ignoring extra levels\n",
  1087. ACLLAS_MAX_LEVELS);
  1088. }
  1089. } else {
  1090. /* Must be the attr name. We can goof of by
  1091. ** having parent[1,2,a] but then you have to be
  1092. ** stupid to do that.
  1093. */
  1094. char *p = word;
  1095. if (*--p == '.') {
  1096. attrName = word;
  1097. break;
  1098. }
  1099. }
  1100. }
  1101. info.attr = attrName;
  1102. info.clientdn = lasinfo.clientDn;
  1103. info.result = 0;
  1104. } else {
  1105. levels[0] = 0;
  1106. numOflevels = 1;
  1107. }
  1108. /* No attribute name specified--it's a syntax error and so undefined */
  1109. if (attrName == NULL ) {
  1110. slapi_ch_free ( (void**) &s_attrName);
  1111. return LAS_EVAL_FAIL;
  1112. }
  1113. slapi_log_error( SLAPI_LOG_ACL, plugin_name,"Attr:%s\n" , attrName);
  1114. matched = ACL_FALSE;
  1115. for (i=0; i < numOflevels; i++) {
  1116. if ( levels[i] == 0 ) {
  1117. Slapi_Value *sval=NULL;
  1118. const struct berval *attrVal;
  1119. int numValues = 0;
  1120. int j;
  1121. /*
  1122. * For the add operation, the resource itself (level 0)
  1123. * must never be allowed to grant access--
  1124. * This is because access would be granted based on a value
  1125. * of an attribute in the new entry--security hole.
  1126. *
  1127. */
  1128. if ( lasinfo.aclpb->aclpb_optype == SLAPI_OPERATION_ADD) {
  1129. if (selfdn) {
  1130. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1131. "ACL info: %s DOES allow ADD permission at level 0.\n", attr_name);
  1132. } else {
  1133. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1134. "ACL info: %s does not allow ADD permission at level 0.\n", attr_name);
  1135. got_undefined = 1;
  1136. continue;
  1137. }
  1138. }
  1139. slapi_entry_attr_find( lasinfo.resourceEntry, attrName, &a);
  1140. if ( NULL == a ) continue;
  1141. if (selfdn) {
  1142. /* Checks that attrName has only one value. This is the only condition enforced
  1143. * when using SELFDN
  1144. */
  1145. slapi_attr_get_numvalues((const Slapi_Attr *) a, &numValues);
  1146. if (numValues != 1) {
  1147. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  1148. "DS_LASSelfDnAttrEval: fail because the retrieved %s in resource has more than one value (%d)\n",
  1149. attrName, numValues);
  1150. got_undefined = 1;
  1151. continue;
  1152. }
  1153. }
  1154. j= slapi_attr_first_value ( a,&sval );
  1155. while ( j != -1 ) {
  1156. attrVal = slapi_value_get_berval ( sval );
  1157. /* Here if atleast 1 value matches then we are done.*/
  1158. val = slapi_create_dn_string("%s", attrVal->bv_val);
  1159. if (NULL == val) {
  1160. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  1161. "DS_LASUserDnAttrEval: Invalid syntax: %s\n",
  1162. attrVal->bv_val );
  1163. slapi_ch_free ( (void**) &s_attrName);
  1164. return LAS_EVAL_FAIL;
  1165. }
  1166. if (slapi_utf8casecmp((ACLUCHP)val, (ACLUCHP)lasinfo.clientDn ) == 0) {
  1167. char ebuf [ BUFSIZ ];
  1168. /* Wow it matches */
  1169. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1170. "%s matches(%s, %s) level (%d)\n", attr_name,
  1171. val,
  1172. ACL_ESCAPE_STRING_WITH_PUNCTUATION (lasinfo.clientDn, ebuf),
  1173. 0);
  1174. matched = ACL_TRUE;
  1175. slapi_ch_free ( (void **) &val);
  1176. break;
  1177. }
  1178. slapi_ch_free ( (void**) &val);
  1179. j = slapi_attr_next_value ( a, j, &sval );
  1180. }
  1181. } else {
  1182. char *p_dn; /* parent dn */
  1183. p_dn = acllas__dn_parent (n_currEntryDn, levels[i]);
  1184. if (p_dn == NULL) continue;
  1185. /* use new search internal API */
  1186. {
  1187. Slapi_PBlock *aPb = slapi_pblock_new ();
  1188. /*
  1189. * This search may be chained if chaining for ACL is
  1190. * is enabled in the backend and the entry is in
  1191. * a chained backend.
  1192. */
  1193. slapi_search_internal_set_pb ( aPb,
  1194. p_dn,
  1195. LDAP_SCOPE_BASE,
  1196. "objectclass=*",
  1197. &attrs[0],
  1198. 0,
  1199. NULL /* controls */,
  1200. NULL /* uniqueid */,
  1201. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  1202. 0 /* actions */);
  1203. slapi_search_internal_callback_pb(aPb,
  1204. &info /* callback_data */,
  1205. NULL/* result_callback */,
  1206. acllas__verify_client,
  1207. NULL /* referral_callback */);
  1208. slapi_pblock_destroy(aPb);
  1209. }
  1210. /*
  1211. * Currently info.result is boolean so
  1212. * we do not need to check for ACL_DONT_KNOW
  1213. */
  1214. if (info.result) {
  1215. matched = ACL_TRUE;
  1216. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1217. "%s matches at level (%d)\n", attr_name, levels[i]);
  1218. }
  1219. }
  1220. if (matched == ACL_TRUE) {
  1221. break;
  1222. }
  1223. }
  1224. slapi_ch_free ( (void **) &s_attrName);
  1225. /*
  1226. * If no terms were undefined, then evaluate as normal.
  1227. * If there was an undefined term, but another one was TRUE, then we also evaluate
  1228. * as normal. Otherwise, the whole expression is UNDEFINED.
  1229. */
  1230. if ( matched == ACL_TRUE || !got_undefined ) {
  1231. if (comparator == CMP_OP_EQ) {
  1232. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  1233. } else {
  1234. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  1235. }
  1236. } else {
  1237. rc = LAS_EVAL_FAIL;
  1238. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1239. "Returning UNDEFINED for %s evaluation.\n", attr_name);
  1240. }
  1241. return rc;
  1242. }
  1243. /***************************************************************************
  1244. *
  1245. * DS_LASLdapUrlAttrEval
  1246. *
  1247. *
  1248. * Input:
  1249. * attr_name The string "ldapurl" - in lower case.
  1250. * comparator CMP_OP_EQ or CMP_OP_NE only
  1251. * attr_pattern A comma-separated list of users
  1252. * cachable Always set to FALSE.
  1253. * subject Subject property list
  1254. * resource Resource property list
  1255. * auth_info Authentication info, if any
  1256. * las_info LAS info to pass the resource entry
  1257. *
  1258. * Returns:
  1259. * retcode The usual LAS return codes.
  1260. *
  1261. * Error Handling:
  1262. * None.
  1263. *
  1264. **************************************************************************/
  1265. int
  1266. DS_LASLdapUrlAttrEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  1267. char *attr_pattern, int *cachable, void **LAS_cookie,
  1268. PList_t subject, PList_t resource, PList_t auth_info,
  1269. PList_t global_auth, lasInfo lasinfo)
  1270. {
  1271. char *n_currEntryDn = NULL;
  1272. char *s_attrName = NULL, *attrName = NULL;
  1273. char *ptr;
  1274. int matched;
  1275. int rc, len, i;
  1276. int levels[ACLLAS_MAX_LEVELS];
  1277. int numOflevels =0;
  1278. struct userdnattr_info info = {0};
  1279. char *attrs[2] = { LDAP_ALL_USER_ATTRS, NULL };
  1280. int got_undefined = 0;
  1281. /*
  1282. ** The ldapurlAttr syntax is
  1283. ** userdnattr = <attribute> or
  1284. ** userdnattr = parent[0,2,4].attribute"
  1285. ** Ex:
  1286. ** userdnattr = manager; or
  1287. ** userdnattr = "parent[0,2,4].manager";
  1288. **
  1289. ** Here 0 means current level, 2 means grandfather and
  1290. ** 4 (great great grandfather)
  1291. **
  1292. ** The function of this LAS is to compare the value of the
  1293. ** attribute in the Slapi_Entry with the "ldapurl".
  1294. **
  1295. ** Ex: ldapurl: ldap:///dc=example,dc=com??sub?(l=Mountain View)
  1296. ** and in the Slapi_Entry of the bind user has
  1297. ** l = Mountain View. Compare the bind user's 'l' and the value to
  1298. ** determine the result.
  1299. **
  1300. */
  1301. s_attrName = attrName = slapi_ch_strdup(attr_pattern);
  1302. /* ignore leading/trailing whitespace */
  1303. while (ldap_utf8isspace(attrName)) LDAP_UTF8INC(attrName);
  1304. len = strlen(attrName);
  1305. ptr = attrName+len-1;
  1306. while (ptr >= attrName && ldap_utf8isspace(ptr)) {
  1307. *ptr = '\0';
  1308. LDAP_UTF8DEC(ptr);
  1309. }
  1310. /* See if we have a parent[2].attr" rule */
  1311. if (strstr(attrName, "parent[") != NULL) {
  1312. char *word, *str, *next = NULL;
  1313. numOflevels = 0;
  1314. n_currEntryDn = slapi_entry_get_ndn ( lasinfo.resourceEntry );
  1315. str = attrName;
  1316. ldap_utf8strtok_r(str, "[],. ",&next);
  1317. /* The first word is "parent[" and so it's not important */
  1318. while ((word= ldap_utf8strtok_r(NULL, "[],.", &next)) != NULL) {
  1319. if (ldap_utf8isdigit(word)) {
  1320. while (word && ldap_utf8isspace(word)) LDAP_UTF8INC(word);
  1321. if (numOflevels < ACLLAS_MAX_LEVELS)
  1322. levels[numOflevels++] = atoi (word);
  1323. else {
  1324. /*
  1325. * Here, ignore the extra levels..it's really
  1326. * a syntax error which should have been ruled out at parse time
  1327. */
  1328. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  1329. "DS_LASLdapUrlattr: Exceeded the ATTR LIMIT:%d: Ignoring extra levels\n",
  1330. ACLLAS_MAX_LEVELS);
  1331. }
  1332. } else {
  1333. /* Must be the attr name. We can goof of by
  1334. ** having parent[1,2,a] but then you have to be
  1335. ** stupid to do that.
  1336. */
  1337. char *p = word;
  1338. if (*--p == '.') {
  1339. attrName = word;
  1340. break;
  1341. }
  1342. }
  1343. }
  1344. info.attr = attrName;
  1345. info.clientdn = lasinfo.clientDn;
  1346. info.aclpb = lasinfo.aclpb;
  1347. info.result = 0;
  1348. } else {
  1349. levels[0] = 0;
  1350. numOflevels = 1;
  1351. }
  1352. /* No attribute name specified--it's a syntax error and so undefined */
  1353. if (attrName == NULL ) {
  1354. slapi_ch_free ( (void**) &s_attrName);
  1355. return LAS_EVAL_FAIL;
  1356. }
  1357. slapi_log_error( SLAPI_LOG_ACL, plugin_name,"Attr:%s\n" , attrName);
  1358. matched = ACL_FALSE;
  1359. for (i = 0; i < numOflevels; i++) {
  1360. if ( levels[i] == 0 ) { /* parent[0] or the target itself */
  1361. Slapi_Value *sval = NULL;
  1362. const struct berval *attrVal;
  1363. Slapi_Attr *attrs;
  1364. int i;
  1365. /* Get the attr from the resouce entry */
  1366. if ( 0 == slapi_entry_attr_find (lasinfo.resourceEntry,
  1367. attrName, &attrs) ) {
  1368. i = slapi_attr_first_value ( attrs, &sval );
  1369. if ( i == -1 ) {
  1370. /* Attr val not there
  1371. * so it's value cannot equal other one */
  1372. matched = ACL_FALSE;
  1373. continue; /* try next level */
  1374. }
  1375. } else {
  1376. /* Not there so it cannot equal another one */
  1377. matched = ACL_FALSE;
  1378. continue; /* try next level */
  1379. }
  1380. while ( matched != ACL_TRUE && (sval != NULL)) {
  1381. attrVal = slapi_value_get_berval ( sval );
  1382. matched = acllas__client_match_URL ( lasinfo.aclpb,
  1383. lasinfo.clientDn,
  1384. attrVal->bv_val);
  1385. if ( matched != ACL_TRUE )
  1386. i = slapi_attr_next_value ( attrs, i, &sval );
  1387. if ( matched == ACL_DONT_KNOW ) {
  1388. got_undefined = 1;
  1389. }
  1390. }
  1391. } else {
  1392. char *p_dn; /* parent dn */
  1393. Slapi_PBlock *aPb = NULL;
  1394. p_dn = acllas__dn_parent (n_currEntryDn, levels[i]);
  1395. if (p_dn == NULL) continue;
  1396. /* use new search internal API */
  1397. aPb = slapi_pblock_new ();
  1398. /*
  1399. * This search may be chained if chaining for ACL is
  1400. * is enabled in the backend and the entry is in
  1401. * a chained backend.
  1402. */
  1403. slapi_search_internal_set_pb ( aPb,
  1404. p_dn,
  1405. LDAP_SCOPE_BASE,
  1406. "objectclass=*",
  1407. &attrs[0],
  1408. 0,
  1409. NULL /* controls */,
  1410. NULL /* uniqueid */,
  1411. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  1412. 0 /* actions */);
  1413. slapi_search_internal_callback_pb(aPb,
  1414. &info /* callback_data */,
  1415. NULL/* result_callback */,
  1416. acllas__verify_ldapurl,
  1417. NULL /* referral_callback */);
  1418. slapi_pblock_destroy(aPb);
  1419. /*
  1420. * Currently info.result is boolean so
  1421. * we do not need to check for ACL_DONT_KNOW
  1422. */
  1423. if (info.result) {
  1424. matched = ACL_TRUE;
  1425. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1426. "userdnAttr matches at level (%d)\n", levels[i]);
  1427. }
  1428. }
  1429. if (matched == ACL_TRUE) {
  1430. break;
  1431. }
  1432. }
  1433. slapi_ch_free ( (void **) &s_attrName);
  1434. /*
  1435. * If no terms were undefined, then evaluate as normal.
  1436. * If there was an undefined term, but another one was TRUE,
  1437. * then we also evaluate as normal.
  1438. * Otherwise, the whole expression is UNDEFINED.
  1439. */
  1440. if ( matched == ACL_TRUE || !got_undefined ) {
  1441. if (comparator == CMP_OP_EQ) {
  1442. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  1443. } else {
  1444. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  1445. }
  1446. } else {
  1447. rc = LAS_EVAL_FAIL;
  1448. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1449. "Returning UNDEFINED for userdnattr evaluation.\n");
  1450. }
  1451. return rc;
  1452. }
  1453. /***************************************************************************
  1454. *
  1455. * DS_LASAuthMethodEval
  1456. *
  1457. *
  1458. * Input:
  1459. * attr_name The string "authmethod" - in lower case.
  1460. * comparator CMP_OP_EQ or CMP_OP_NE only
  1461. * attr_pattern A comma-separated list of users
  1462. * cachable Always set to FALSE.
  1463. * subject Subject property list
  1464. * resource Resource property list
  1465. * auth_info Authentication info, if any
  1466. *
  1467. * Returns:
  1468. * retcode The usual LAS return codes.
  1469. *
  1470. * Error Handling:
  1471. * None.
  1472. *
  1473. **************************************************************************/
  1474. int
  1475. DS_LASAuthMethodEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  1476. char *attr_pattern, int *cachable, void **LAS_cookie,
  1477. PList_t subject, PList_t resource, PList_t auth_info,
  1478. PList_t global_auth)
  1479. {
  1480. char *attr;
  1481. char *ptr;
  1482. int len;
  1483. int matched;
  1484. int rc;
  1485. char *s = NULL;
  1486. lasInfo lasinfo;
  1487. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  1488. attr_pattern,cachable,LAS_cookie,
  1489. subject, resource, auth_info,global_auth,
  1490. DS_LAS_AUTHMETHOD, "DS_LASAuthMethodEval",
  1491. &lasinfo )) ) {
  1492. return LAS_EVAL_FAIL;
  1493. }
  1494. attr = attr_pattern;
  1495. matched = ACL_FALSE;
  1496. /* ignore leading whitespace */
  1497. s = strstr (attr, SLAPD_AUTH_SASL);
  1498. if ( s) {
  1499. s +=4;
  1500. attr = s;
  1501. }
  1502. while(ldap_utf8isspace(attr)) LDAP_UTF8INC(attr);
  1503. len = strlen(attr);
  1504. ptr = attr+len-1;
  1505. while(ptr >= attr && ldap_utf8isspace(ptr)) {
  1506. *ptr = '\0';
  1507. LDAP_UTF8DEC(ptr);
  1508. }
  1509. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1510. "DS_LASAuthMethodEval:authtype:%s authmethod:%s\n",
  1511. lasinfo.authType, attr);
  1512. /* None method means, we don't care -- otherwise we care */
  1513. if ((strcasecmp(attr, "none") == 0) ||
  1514. (strcasecmp(attr, lasinfo.authType) == 0) ||
  1515. (lasinfo.ldapi && strcasecmp(attr, DS_ATTR_LDAPI) == 0))
  1516. {
  1517. matched = ACL_TRUE;
  1518. }
  1519. if ( matched == ACL_TRUE || matched == ACL_FALSE) {
  1520. if (comparator == CMP_OP_EQ) {
  1521. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  1522. } else {
  1523. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  1524. }
  1525. }
  1526. return rc;
  1527. }
  1528. /***************************************************************************
  1529. *
  1530. * DS_LASSSFEval
  1531. *
  1532. *
  1533. * Input:
  1534. * attr_name The string "ssf" - in lower case.
  1535. * comparator CMP_OP_EQ, CMP_OP_NE, CMP_OP_GT, CMP_OP_LT, CMP_OP_GE, CMP_OP_LE
  1536. * attr_pattern An integer representing the SSF
  1537. * cachable Always set to FALSE.
  1538. * subject Subject property list
  1539. * resource Resource property list
  1540. * auth_info Authentication info, if any
  1541. *
  1542. * Returns:
  1543. * retcode The usual LAS return codes.
  1544. *
  1545. * Error Handling:
  1546. * None.
  1547. *
  1548. **************************************************************************/
  1549. int
  1550. DS_LASSSFEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  1551. char *attr_pattern, int *cachable, void **LAS_cookie,
  1552. PList_t subject, PList_t resource, PList_t auth_info,
  1553. PList_t global_auth)
  1554. {
  1555. char *attr;
  1556. char *ptr;
  1557. int len;
  1558. int rc;
  1559. lasInfo lasinfo;
  1560. int aclssf;
  1561. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 1, /* Allow range comparators */
  1562. attr_pattern,cachable,LAS_cookie,
  1563. subject, resource, auth_info,global_auth,
  1564. DS_LAS_SSF, "DS_LASSSFEval",
  1565. &lasinfo )) ) {
  1566. return LAS_EVAL_FAIL;
  1567. }
  1568. attr = attr_pattern;
  1569. /* ignore leading and trailing whitespace */
  1570. while(ldap_utf8isspace(attr)) LDAP_UTF8INC(attr);
  1571. len = strlen(attr);
  1572. ptr = attr+len-1;
  1573. while(ptr >= attr && ldap_utf8isspace(ptr)) {
  1574. *ptr = '\0';
  1575. LDAP_UTF8DEC(ptr);
  1576. }
  1577. /* Convert SSF from bind rule to an int. */
  1578. aclssf = (int) strtol(attr, &ptr, 10);
  1579. if (*ptr != '\0') {
  1580. rc = LAS_EVAL_FAIL;
  1581. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1582. "Error parsing numeric SSF from bind rule.\n");
  1583. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1584. "Returning UNDEFINED for ssf evaluation.\n");
  1585. }
  1586. /* Check for negative values or a value overflow. */
  1587. if ((aclssf < 0) || (((aclssf == INT_MAX) || (aclssf == INT_MIN)) && (errno == ERANGE))){
  1588. rc = LAS_EVAL_FAIL;
  1589. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1590. "SSF \"%s\" is invalid. Value must range from 0 to %d",
  1591. attr, INT_MAX);
  1592. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1593. "Returning UNDEFINED for ssf evaluation.\n");
  1594. }
  1595. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1596. "DS_LASSSFEval: aclssf:%d, ssf:%d\n",
  1597. aclssf, lasinfo.ssf);
  1598. switch ((int)comparator) {
  1599. case CMP_OP_EQ:
  1600. if (lasinfo.ssf == aclssf) {
  1601. rc = LAS_EVAL_TRUE;
  1602. } else {
  1603. rc = LAS_EVAL_FALSE;
  1604. }
  1605. break;
  1606. case CMP_OP_NE:
  1607. if (lasinfo.ssf != aclssf) {
  1608. rc = LAS_EVAL_TRUE;
  1609. } else {
  1610. rc = LAS_EVAL_FALSE;
  1611. }
  1612. break;
  1613. case CMP_OP_GT:
  1614. if (lasinfo.ssf > aclssf) {
  1615. rc = LAS_EVAL_TRUE;
  1616. } else {
  1617. rc = LAS_EVAL_FALSE;
  1618. }
  1619. break;
  1620. case CMP_OP_LT:
  1621. if (lasinfo.ssf < aclssf) {
  1622. rc = LAS_EVAL_TRUE;
  1623. } else {
  1624. rc = LAS_EVAL_FALSE;
  1625. }
  1626. break;
  1627. case CMP_OP_GE:
  1628. if (lasinfo.ssf >= aclssf) {
  1629. rc = LAS_EVAL_TRUE;
  1630. } else {
  1631. rc = LAS_EVAL_FALSE;
  1632. }
  1633. break;
  1634. case CMP_OP_LE:
  1635. if (lasinfo.ssf <= aclssf) {
  1636. rc = LAS_EVAL_TRUE;
  1637. } else {
  1638. rc = LAS_EVAL_FALSE;
  1639. }
  1640. break;
  1641. default:
  1642. /* This should never happen since the comparator is
  1643. * validated by __acllas_setup(), but better safe
  1644. * than sorry. */
  1645. rc = LAS_EVAL_FAIL;
  1646. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1647. "Invalid comparator \"%d\" evaluating SSF.\n",
  1648. (int)comparator);
  1649. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1650. "Returning UNDEFINED for ssf evaluation.\n");
  1651. }
  1652. return rc;
  1653. }
  1654. /****************************************************************************
  1655. * Struct to evaluate and keep the current members being evaluated
  1656. *
  1657. * 0 1 2 3 4 5
  1658. * member: [a,b,c,d,e,f]
  1659. * c_idx may point to 2 i.e to "c" if "c" is being evaluated to
  1660. * see if any of "c" members is the clientDN.
  1661. * lu_idx points to the last used spot i.e 5.
  1662. * lu_idx++ is the next free spot.
  1663. *
  1664. * We allocate ACLLAS_MAX_GRP_MEMBER ptr first and then we add if it
  1665. * is required.
  1666. *
  1667. ***************************************************************************/
  1668. #define ACLLAS_MAX_GRP_MEMBER 50
  1669. struct member_info
  1670. {
  1671. char *member; /* member DN */
  1672. int parentId; /* parent of this member */
  1673. };
  1674. struct eval_info
  1675. {
  1676. int result; /* result status */
  1677. char *userDN; /* client's normalized DN */
  1678. int c_idx; /* Index to the current member being processed */
  1679. int lu_idx; /* Index to the slot where the last member is stored */
  1680. char **member; /* mmebers list */
  1681. struct member_info **memberInfo;/* array of memberInfo */
  1682. CERTCertificate *clientCert; /* ptr to cert */
  1683. struct acl_pblock *aclpb; /*aclpblock */
  1684. };
  1685. #ifdef FOR_DEBUGGING
  1686. static void
  1687. dump_member_info ( struct eval_info *info, struct member_info *minfo, char *buf )
  1688. {
  1689. if ( minfo )
  1690. {
  1691. if ( minfo->parentId >= 0 )
  1692. {
  1693. dump_member_info ( info, minfo->parentId, buf );
  1694. }
  1695. else
  1696. {
  1697. strcat ( buf, "<nil>" );
  1698. }
  1699. strcat ( buf, "->" );
  1700. strcat ( buf, minfo->member );
  1701. }
  1702. }
  1703. static void
  1704. dump_eval_info (char *caller, struct eval_info *info, int idx)
  1705. {
  1706. char buf[1024];
  1707. int len;
  1708. int i;
  1709. if ( idx < 0 )
  1710. {
  1711. sprintf ( buf, "\nuserDN=\"%s\"\nmember=", info->userDN);
  1712. if (info->member && *info->member)
  1713. {
  1714. len = strlen (buf);
  1715. /* member is a char ** */
  1716. sprintf ( &(buf[len]), "\"%s\"", *info->member );
  1717. }
  1718. len = strlen (buf);
  1719. sprintf ( &(buf[len]), "\nmemberinfo[%d]-[%d]:", info->c_idx, info->lu_idx );
  1720. if ( info->memberInfo )
  1721. for (i = 0; i <= info->lu_idx; i++)
  1722. {
  1723. len = strlen(buf);
  1724. sprintf ( &buf[len], "\n [%d]: ", i );
  1725. dump_member_info ( info, info->memberInfo[i], buf );
  1726. }
  1727. slapi_log_error ( SLAPI_LOG_FATAL, NULL, "\n======== candidate member info in eval_info ========%s\n\n", buf );
  1728. }
  1729. else
  1730. {
  1731. sprintf (buf, "evaluated candidate [%d]=", idx);
  1732. switch (info->result)
  1733. {
  1734. case ACL_TRUE:
  1735. strcat (buf, "ACL_TRUE\n");
  1736. break;
  1737. case ACL_FALSE:
  1738. strcat (buf, "ACL_FALSE\n");
  1739. break;
  1740. case ACL_DONT_KNOW:
  1741. strcat (buf, "ACL_DONT_KNOW\n");
  1742. break;
  1743. default:
  1744. len = strlen (buf);
  1745. sprintf ( &(buf[len]), "%d\n", info->result );
  1746. break;
  1747. }
  1748. dump_member_info ( info, info->memberInfo[idx], buf );
  1749. slapi_log_error ( SLAPI_LOG_FATAL, NULL, "%s\n", buf );
  1750. }
  1751. }
  1752. #endif
  1753. /***************************************************************************
  1754. *
  1755. * acllas__user_ismember_of_group
  1756. *
  1757. * Check if the user is a member of the group and nested groups..
  1758. *
  1759. * Input:
  1760. * char *groupdn - DN of the group
  1761. * char *clientDN - Dn of the client
  1762. *
  1763. * Returns:
  1764. * ACL_TRUE - the user is a member of the group.
  1765. * ACL_FALSE - Not a member
  1766. * ACL_DONT_KNOW - Any errors eg. resource limits exceeded and we could
  1767. * not compelte the evaluation.
  1768. *
  1769. * Error Handling:
  1770. * None.
  1771. *
  1772. **************************************************************************/
  1773. static int
  1774. acllas__user_ismember_of_group( struct acl_pblock *aclpb,
  1775. char* groupDN,
  1776. char* clientDN,
  1777. int cache_status,
  1778. CERTCertificate *clientCert)
  1779. {
  1780. char *attrs[5];
  1781. char *currDN;
  1782. int i,j;
  1783. int result = ACL_FALSE;
  1784. struct eval_info info = {0};
  1785. int nesting_level;
  1786. int numOfMembersAtCurrentLevel;
  1787. int numOfMembersVisited;
  1788. int totalMembersVisited;
  1789. int numOfMembers;
  1790. int max_nestlevel;
  1791. int max_memberlimit;
  1792. aclUserGroup *u_group;
  1793. struct member_info *groupMember = NULL;
  1794. struct member_info *parentGroup = NULL;
  1795. /*
  1796. ** First, Let's look thru the cached list and determine if the client is
  1797. ** a member of the cached list of groups.
  1798. */
  1799. if ( (u_group = aclg_get_usersGroup ( aclpb , clientDN )) == NULL) {
  1800. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1801. "Failed to find/allocate a usergroup--aborting evaluation\n");
  1802. return(ACL_DONT_KNOW);
  1803. }
  1804. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "Evaluating user %s in group %s?\n",
  1805. clientDN, groupDN );
  1806. /* Before I start using, get a reader lock on the group cache */
  1807. aclg_lock_groupCache ( 1 /* reader */ );
  1808. for ( i= 0; i < u_group->aclug_numof_member_group; i++) {
  1809. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "-- In %s\n",
  1810. u_group->aclug_member_groups[i] );
  1811. if ( slapi_utf8casecmp((ACLUCHP)groupDN, (ACLUCHP)u_group->aclug_member_groups[i]) == 0){
  1812. aclg_unlock_groupCache ( 1 /* reader */ );
  1813. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "Evaluated ACL_TRUE\n");
  1814. return ACL_TRUE;
  1815. }
  1816. }
  1817. /* see if we know the client is not a member of a group. */
  1818. for ( i= 0; i < u_group->aclug_numof_notmember_group; i++) {
  1819. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "-- Not in %s\n",
  1820. u_group->aclug_notmember_groups[i] );
  1821. if ( slapi_utf8casecmp((ACLUCHP)groupDN, (ACLUCHP)u_group->aclug_notmember_groups[i]) == 0){
  1822. aclg_unlock_groupCache ( 1 /* reader */ );
  1823. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "Evaluated ACL_FALSE\n");
  1824. return ACL_FALSE;
  1825. }
  1826. }
  1827. /*
  1828. ** That means we didn't find the the group in the cache. -- we have to add it
  1829. ** so no need for READ lock - need to get a WRITE lock. We will get it just before
  1830. ** modifying it.
  1831. */
  1832. aclg_unlock_groupCache ( 1 /* reader */ );
  1833. /* Indicate the initialization handler -- this module will be
  1834. ** called by the backend to evaluate the entry.
  1835. */
  1836. info.result = ACL_FALSE;
  1837. if (clientDN && *clientDN != '\0')
  1838. info.userDN = clientDN;
  1839. else
  1840. info.userDN = NULL;
  1841. info.c_idx = 0;
  1842. info.memberInfo = (struct member_info **) slapi_ch_malloc (ACLLAS_MAX_GRP_MEMBER * sizeof(struct member_info *));
  1843. groupMember = (struct member_info *) slapi_ch_malloc ( sizeof (struct member_info) );
  1844. groupMember->member = slapi_ch_strdup(groupDN);
  1845. groupMember->parentId = -1;
  1846. info.memberInfo[0] = groupMember;
  1847. info.lu_idx = 0;
  1848. attrs[0] = type_member;
  1849. attrs[1] = type_uniquemember;
  1850. attrs[2] = type_memberURL;
  1851. attrs[3] = type_memberCert;
  1852. attrs[4] = NULL;
  1853. currDN = groupMember->member;
  1854. /* nesting level is 0 to begin with */
  1855. nesting_level = 0;
  1856. numOfMembersVisited = 0;
  1857. totalMembersVisited = 0;
  1858. numOfMembersAtCurrentLevel = 1;
  1859. if (clientCert)
  1860. info.clientCert = clientCert;
  1861. else
  1862. info.clientCert = NULL;
  1863. info.aclpb = aclpb;
  1864. max_memberlimit = aclpb->aclpb_max_member_sizelimit;
  1865. max_nestlevel = aclpb->aclpb_max_nesting_level;
  1866. #ifdef FOR_DEBUGGING
  1867. dump_eval_info ( "acllas__user_ismember_of_group", &info, -1 );
  1868. #endif
  1869. eval_another_member:
  1870. numOfMembers = info.lu_idx - info.c_idx;
  1871. /* Use new search internal API */
  1872. {
  1873. Slapi_PBlock * aPb = slapi_pblock_new ();
  1874. /*
  1875. * This search may NOT be chained--we demand that group
  1876. * definition be local.
  1877. */
  1878. slapi_search_internal_set_pb ( aPb,
  1879. currDN,
  1880. LDAP_SCOPE_BASE,
  1881. filter_groups,
  1882. &attrs[0],
  1883. 0,
  1884. NULL /* controls */,
  1885. NULL /* uniqueid */,
  1886. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  1887. SLAPI_OP_FLAG_NEVER_CHAIN /* actions */);
  1888. slapi_search_internal_callback_pb(aPb,
  1889. &info /* callback_data */,
  1890. NULL/* result_callback */,
  1891. acllas__handle_group_entry,
  1892. NULL /* referral_callback */);
  1893. if ( info.result == ACL_TRUE )
  1894. slapi_log_error( SLAPI_LOG_ACL, plugin_name,"-- In %s\n", info.memberInfo[info.c_idx]->member );
  1895. else if ( info.result == ACL_FALSE )
  1896. slapi_log_error( SLAPI_LOG_ACL, plugin_name,"-- Not in %s\n", info.memberInfo[info.c_idx]->member );
  1897. slapi_pblock_destroy (aPb);
  1898. }
  1899. if (info.result == ACL_TRUE) {
  1900. /*
  1901. ** that means the client is a member of the
  1902. ** group or one of the nested groups. We are done.
  1903. */
  1904. result = ACL_TRUE;
  1905. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "Evaluated ACL_TRUE\n");
  1906. goto free_and_return;
  1907. }
  1908. numOfMembersVisited++;
  1909. if (numOfMembersVisited == numOfMembersAtCurrentLevel) {
  1910. /* This means we have looked at all the members for this level */
  1911. numOfMembersVisited = 0;
  1912. /* Now we are ready to look at the next level */
  1913. nesting_level++;
  1914. /* So, far we have visited ... */
  1915. totalMembersVisited += numOfMembersAtCurrentLevel;
  1916. /* How many members in the next level ? */
  1917. numOfMembersAtCurrentLevel =
  1918. info.lu_idx - totalMembersVisited +1;
  1919. }
  1920. if ((nesting_level > max_nestlevel)) {
  1921. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1922. "GroupEval:Member not found within the allowed nesting level (Allowed:%d Looked at:%d)\n",
  1923. max_nestlevel, nesting_level);
  1924. result = ACL_DONT_KNOW; /* don't try to cache info based on this result */
  1925. goto free_and_return;
  1926. }
  1927. /* limit of -1 means "no limit */
  1928. if (info.c_idx > max_memberlimit &&
  1929. max_memberlimit != -1 ) {
  1930. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  1931. "GroupEval:Looked at too many entries:(%d, %d)\n",
  1932. info.c_idx, info.lu_idx);
  1933. result = ACL_DONT_KNOW; /* don't try to cache info based on this result */
  1934. goto free_and_return;
  1935. }
  1936. if (info.lu_idx > info.c_idx) {
  1937. if (numOfMembers == (info.lu_idx - info.c_idx)) {
  1938. /* That means it's not a GROUP. It is just another
  1939. ** useless member which doesn't match. Remove the BAD dude.
  1940. */
  1941. groupMember = info.memberInfo[info.c_idx];
  1942. if (groupMember ) {
  1943. if ( groupMember->member ) slapi_ch_free ( (void **) &groupMember->member );
  1944. slapi_ch_free ( (void **) &groupMember );
  1945. info.memberInfo[info.c_idx] = NULL;
  1946. }
  1947. }
  1948. info.c_idx++;
  1949. /* Go thru the stack and see if we have already
  1950. ** evaluated this group. If we have, then skip it.
  1951. */
  1952. while (1) {
  1953. int evalNext=0;
  1954. int j;
  1955. if (info.c_idx > info.lu_idx) {
  1956. /* That means we have crossed the limit. We
  1957. ** may end of in this situation if we
  1958. ** have circular groups
  1959. */
  1960. info.c_idx = info.lu_idx;
  1961. goto free_and_return;
  1962. }
  1963. /* Break out of the loop if we have searched to the end */
  1964. groupMember = info.memberInfo[info.c_idx];
  1965. if ( (NULL == groupMember) || ((currDN = groupMember->member)!= NULL))
  1966. break;
  1967. for (j = 0; j < info.c_idx; j++) {
  1968. groupMember = info.memberInfo[j];
  1969. if (groupMember->member &&
  1970. (slapi_utf8casecmp((ACLUCHP)currDN, (ACLUCHP)groupMember->member) == 0)) {
  1971. /* Don't need the duplicate */
  1972. groupMember = info.memberInfo[info.c_idx];
  1973. slapi_ch_free ( (void **) &groupMember->member );
  1974. slapi_ch_free ( (void **) &groupMember );
  1975. info.memberInfo[info.c_idx] = NULL;
  1976. info.c_idx++;
  1977. evalNext=1;
  1978. break;
  1979. }
  1980. }
  1981. if (!evalNext) break;
  1982. }
  1983. /* Make sure that we have a valid DN to chug along */
  1984. groupMember = info.memberInfo[info.c_idx];
  1985. if ((info.c_idx <= info.lu_idx) && ((currDN = groupMember->member) != NULL))
  1986. goto eval_another_member;
  1987. }
  1988. free_and_return:
  1989. /* Remove the unnecessary members from the list which
  1990. ** we might have accumulated during the last execution
  1991. ** and we don't need to look at them.
  1992. */
  1993. i = info.c_idx;
  1994. i++;
  1995. while (i <= info.lu_idx) {
  1996. groupMember = info.memberInfo[i];
  1997. slapi_ch_free ( (void **) &groupMember->member );
  1998. slapi_ch_free ( (void **) &groupMember );
  1999. info.memberInfo[i] = NULL;
  2000. i++;
  2001. }
  2002. /*
  2003. ** Now we have a list which has all the groups
  2004. ** which we need to cache
  2005. */
  2006. info.lu_idx = info.c_idx;
  2007. /* since we are updating the groupcache, get a write lock */
  2008. aclg_lock_groupCache ( 2 /* writer */ );
  2009. /*
  2010. ** Keep the result of the evaluation in the cache.
  2011. ** We have 2 lists: member_of and not_member_of. We can use this
  2012. ** cached information next time we evaluate groups.
  2013. */
  2014. if (result == ACL_TRUE &&
  2015. (cache_status & ACLLAS_CACHE_MEMBER_GROUPS)) {
  2016. int ngr = 0;
  2017. /* get the last group which the user is a member of */
  2018. groupMember = info.memberInfo[info.c_idx];
  2019. while ( groupMember ) {
  2020. int already_cached = 0;
  2021. parentGroup = (groupMember->parentId<0)?NULL:info.memberInfo[groupMember->parentId];
  2022. for (j=0; j < u_group->aclug_numof_member_group;j++){
  2023. if (slapi_utf8casecmp( (ACLUCHP)groupMember->member,
  2024. (ACLUCHP)u_group->aclug_member_groups[j]) == 0) {
  2025. already_cached = 1;
  2026. break;
  2027. }
  2028. }
  2029. if (already_cached) {
  2030. groupMember = parentGroup;
  2031. parentGroup = NULL;
  2032. continue;
  2033. }
  2034. ngr = u_group->aclug_numof_member_group++;
  2035. if (u_group->aclug_numof_member_group >=
  2036. u_group->aclug_member_group_size){
  2037. u_group->aclug_member_groups =
  2038. (char **) slapi_ch_realloc (
  2039. (void *) u_group->aclug_member_groups,
  2040. (u_group->aclug_member_group_size +
  2041. ACLUG_INCR_GROUPS_LIST) *
  2042. sizeof (char *));
  2043. u_group->aclug_member_group_size +=
  2044. ACLUG_INCR_GROUPS_LIST;
  2045. }
  2046. u_group->aclug_member_groups[ngr] = slapi_ch_strdup ( groupMember->member );
  2047. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  2048. "Adding Group (%s) ParentGroup (%s) to the IN GROUP List\n",
  2049. groupMember->member , parentGroup ? parentGroup->member: "NULL");
  2050. groupMember = parentGroup;
  2051. parentGroup = NULL;
  2052. }
  2053. } else if (result == ACL_FALSE &&
  2054. (cache_status & ACLLAS_CACHE_NOT_MEMBER_GROUPS)) {
  2055. int ngr = 0;
  2056. /* NOT IN THE GROUP LIST */
  2057. /* get the last group which the user is a member of */
  2058. groupMember = info.memberInfo[info.c_idx];
  2059. while ( groupMember ) {
  2060. int already_cached = 0;
  2061. parentGroup = (groupMember->parentId<0)?NULL:info.memberInfo[groupMember->parentId];
  2062. for (j=0; j < u_group->aclug_numof_notmember_group;j++){
  2063. if (slapi_utf8casecmp( (ACLUCHP)groupMember->member,
  2064. (ACLUCHP)u_group->aclug_notmember_groups[j]) == 0) {
  2065. already_cached = 1;
  2066. break;
  2067. }
  2068. }
  2069. if (already_cached) {
  2070. groupMember = parentGroup;
  2071. parentGroup = NULL;
  2072. continue;
  2073. }
  2074. ngr = u_group->aclug_numof_notmember_group++;
  2075. if (u_group->aclug_numof_notmember_group >=
  2076. u_group->aclug_notmember_group_size){
  2077. u_group->aclug_notmember_groups =
  2078. (char **) slapi_ch_realloc (
  2079. (void *) u_group->aclug_notmember_groups,
  2080. (u_group->aclug_notmember_group_size +
  2081. ACLUG_INCR_GROUPS_LIST) *
  2082. sizeof (char *));
  2083. u_group->aclug_notmember_group_size +=
  2084. ACLUG_INCR_GROUPS_LIST;
  2085. }
  2086. u_group->aclug_notmember_groups[ngr] = slapi_ch_strdup ( groupMember->member );
  2087. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  2088. "Adding Group (%s) ParentGroup (%s) to the NOT IN GROUP List\n",
  2089. groupMember->member , parentGroup ? parentGroup->member: "NULL");
  2090. groupMember = parentGroup;
  2091. parentGroup = NULL;
  2092. }
  2093. } else if ( result == ACL_DONT_KNOW ) {
  2094. /*
  2095. * We terminated the search without reaching a conclusion--so
  2096. * don't cache any info based on this evaluation.
  2097. */
  2098. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "Evaluated ACL_DONT_KNOW\n");
  2099. }
  2100. /* Unlock the group cache, we are done with updating */
  2101. aclg_unlock_groupCache ( 2 /* writer */ );
  2102. for (i=0; i <= info.lu_idx; i++) {
  2103. groupMember = info.memberInfo[i];
  2104. if ( NULL == groupMember ) continue;
  2105. slapi_ch_free ( (void **) &groupMember->member );
  2106. slapi_ch_free ( (void **) &groupMember );
  2107. }
  2108. /* free the pointer array.*/
  2109. slapi_ch_free ( (void **) &info.memberInfo);
  2110. return result;
  2111. }
  2112. /***************************************************************************
  2113. *
  2114. * acllas__handle_group_entry
  2115. *
  2116. * handler called. Compares the userdn value and determines if it's
  2117. * a member of not.
  2118. *
  2119. * Input:
  2120. *
  2121. *
  2122. * Returns:
  2123. *
  2124. * Error Handling:
  2125. *
  2126. **************************************************************************/
  2127. static int
  2128. acllas__handle_group_entry (Slapi_Entry* e, void *callback_data)
  2129. {
  2130. struct eval_info *info;
  2131. Slapi_Attr *currAttr, *nextAttr;
  2132. char *n_dn = NULL, *attrType;
  2133. int n;
  2134. int i;
  2135. info = (struct eval_info *) callback_data;
  2136. info->result = ACL_FALSE;
  2137. if (e == NULL) {
  2138. return 0;
  2139. }
  2140. slapi_entry_first_attr ( e, &currAttr);
  2141. if ( NULL == currAttr ) return 0;
  2142. slapi_attr_get_type ( currAttr, &attrType );
  2143. if (NULL == attrType ) return 0;
  2144. do {
  2145. Slapi_Value *sval = NULL;
  2146. const struct berval *attrVal;
  2147. if ((strcasecmp (attrType, type_member) == 0) ||
  2148. (strcasecmp (attrType, type_uniquemember) == 0 )) {
  2149. i = slapi_attr_first_value ( currAttr,&sval );
  2150. while ( i != -1 ) {
  2151. struct member_info *groupMember = NULL;
  2152. attrVal = slapi_value_get_berval ( sval );
  2153. n_dn = slapi_create_dn_string( "%s", attrVal->bv_val );
  2154. if (NULL == n_dn) {
  2155. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2156. "acllas__handle_group_entry: Invalid syntax: %s\n",
  2157. attrVal->bv_val );
  2158. return 0;
  2159. }
  2160. n = ++info->lu_idx;
  2161. if (n < 0) {
  2162. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2163. "acllas__handle_group_entry: last member index lu_idx is overflown:%d: Too many group ACL members\n", n);
  2164. slapi_ch_free_string(&n_dn);
  2165. return 0;
  2166. }
  2167. if (!(n % ACLLAS_MAX_GRP_MEMBER)) {
  2168. struct member_info **orig_memberInfo = info->memberInfo;
  2169. info->memberInfo = (struct member_info **)slapi_ch_realloc(
  2170. (char *)info->memberInfo,
  2171. (n + ACLLAS_MAX_GRP_MEMBER) *
  2172. sizeof(struct member_info *));
  2173. if (!info->memberInfo) {
  2174. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2175. "acllas__handle_group_entry: out of memory - could not allocate space for %d group members\n",
  2176. n + ACLLAS_MAX_GRP_MEMBER );
  2177. info->memberInfo = orig_memberInfo;
  2178. slapi_ch_free_string(&n_dn);
  2179. return 0;
  2180. }
  2181. }
  2182. /* allocate the space for the member and attch it to the list */
  2183. groupMember = (struct member_info *)slapi_ch_malloc(
  2184. sizeof ( struct member_info ) );
  2185. groupMember->member = n_dn;
  2186. groupMember->parentId = info->c_idx;
  2187. info->memberInfo[n] = groupMember;
  2188. if (info->userDN &&
  2189. slapi_utf8casecmp((ACLUCHP)n_dn, (ACLUCHP)info->userDN) == 0) {
  2190. info->result = ACL_TRUE;
  2191. return 0;
  2192. }
  2193. i = slapi_attr_next_value ( currAttr, i, &sval );
  2194. }
  2195. /* Evaluate Dynamic groups */
  2196. } else if (strcasecmp ( attrType, type_memberURL) == 0) {
  2197. char *memberURL, *savURL;
  2198. if (!info->userDN) {
  2199. goto nextattr; /* cannot evaulate memberURL with no userDN - go to next group attribute */
  2200. }
  2201. i= slapi_attr_first_value ( currAttr,&sval );
  2202. while ( i != -1 ) {
  2203. attrVal = slapi_value_get_berval ( sval );
  2204. /*
  2205. * memberURL may start with "ldap:///" or "ldap://host:port"
  2206. * ldap://localhost:11000/o=ace industry,c=us??
  2207. * or
  2208. * ldap:///o=ace industry,c=us??
  2209. */
  2210. if (strncasecmp( attrVal->bv_val, "ldap://",7) == 0 ||
  2211. strncasecmp( attrVal->bv_val, "ldaps://",8) == 0) {
  2212. savURL = memberURL =
  2213. slapi_create_dn_string("%s", attrVal->bv_val);
  2214. if (NULL == savURL) {
  2215. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2216. "acllas__handle_group_entry: Invalid syntax: %s\n",
  2217. attrVal->bv_val );
  2218. return 0;
  2219. }
  2220. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2221. "ACL Group Eval:MemberURL:%s\n", memberURL);
  2222. info->result = acllas__client_match_URL (
  2223. info->aclpb,
  2224. info->userDN,
  2225. memberURL);
  2226. slapi_ch_free ( (void**) &savURL);
  2227. if (info->result == ACL_TRUE)
  2228. return 0;
  2229. } else {
  2230. /* This means that the URL is ill-formed */
  2231. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2232. "ACL Group Eval:Badly Formed MemberURL:%s\n", attrVal->bv_val);
  2233. }
  2234. i = slapi_attr_next_value ( currAttr, i, &sval );
  2235. }
  2236. /* Evaluate Certificate groups */
  2237. } else if ((strcasecmp (attrType, type_memberCert) == 0) ) {
  2238. /* Do we have the certificate around */
  2239. if (!info->clientCert) {
  2240. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2241. " acllas__handle_group_entry:Client Cert missing\n" );
  2242. /* cannot evaulate cert membership without cert - go to next attribute */
  2243. goto nextattr;
  2244. }
  2245. i = slapi_attr_first_value ( currAttr,&sval );
  2246. while ( i != -1 ) {
  2247. attrVal = slapi_value_get_berval ( sval );
  2248. if (ldapu_member_certificate_match (
  2249. info->clientCert,
  2250. attrVal->bv_val) == LDAP_SUCCESS) {
  2251. info->result = ACL_TRUE;
  2252. return 0;
  2253. }
  2254. i = slapi_attr_next_value ( currAttr, i, &sval );
  2255. }
  2256. }
  2257. nextattr:
  2258. attrType = NULL;
  2259. /* get the next attr */
  2260. slapi_entry_next_attr ( e, currAttr, &nextAttr );
  2261. if ( NULL == nextAttr ) break;
  2262. currAttr = nextAttr;
  2263. slapi_attr_get_type ( currAttr, &attrType );
  2264. } while ( NULL != attrType );
  2265. return 0;
  2266. }
  2267. /***************************************************************************
  2268. *
  2269. * DS_LASGroupDnAttrEval
  2270. *
  2271. *
  2272. * Input:
  2273. * attr_name The string "groupdnattr" - in lower case.
  2274. * comparator CMP_OP_EQ or CMP_OP_NE only
  2275. * attr_pattern A comma-separated list of users
  2276. * cachable Always set to FALSE.
  2277. * subject Subject property list
  2278. * resource Resource property list
  2279. * auth_info Authentication info, if any
  2280. *
  2281. * Returns:
  2282. * retcode The usual LAS return codes.
  2283. *
  2284. * Error Handling:
  2285. * None.
  2286. *
  2287. **************************************************************************/
  2288. struct groupdnattr_info
  2289. {
  2290. char *attrName; /* name of the attribute */
  2291. int numofGroups; /* number of groups */
  2292. char **member;
  2293. };
  2294. int
  2295. DS_LASGroupDnAttrEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  2296. char *attr_pattern, int *cachable, void **LAS_cookie,
  2297. PList_t subject, PList_t resource, PList_t auth_info,
  2298. PList_t global_auth)
  2299. {
  2300. char *s_attrName = NULL;
  2301. char *attrName;
  2302. char *ptr;
  2303. int matched;
  2304. int rc;
  2305. int len;
  2306. Slapi_Attr *attr;
  2307. int levels[ACLLAS_MAX_LEVELS];
  2308. int numOflevels = 0;
  2309. char *n_currEntryDn = NULL;
  2310. lasInfo lasinfo;
  2311. int got_undefined = 0;
  2312. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  2313. attr_pattern,cachable,LAS_cookie,
  2314. subject, resource, auth_info,global_auth,
  2315. DS_LAS_GROUPDNATTR, "DS_LASGroupDnAttrEval",
  2316. &lasinfo )) ) {
  2317. return LAS_EVAL_FAIL;
  2318. }
  2319. /* For anonymous client, the answer is XXX come back to this */
  2320. if ( lasinfo.anomUser )
  2321. return LAS_EVAL_FALSE;
  2322. /*
  2323. ** The groupdnAttr syntax is
  2324. ** groupdnattr = <attribute>
  2325. ** Ex:
  2326. ** groupdnattr = SIEmanager;
  2327. **
  2328. ** The function of this LAS is to find out if the client belongs
  2329. ** to any group that is specified in the attr.
  2330. */
  2331. attrName = attr_pattern;
  2332. if (strstr(attrName, LDAP_URL_prefix)) {
  2333. /* In this case "grppupdnattr="ldap:///base??attr" */
  2334. if ((PL_strcasestr (attrName, ACL_RULE_MACRO_DN_KEY) != NULL) ||
  2335. (PL_strcasestr (attrName, ACL_RULE_MACRO_DN_LEVELS_KEY) != NULL) ||
  2336. (PL_strcasestr (attrName, ACL_RULE_MACRO_ATTR_KEY) != NULL)) {
  2337. matched = aclutil_evaluate_macro( attrName, &lasinfo,
  2338. ACL_EVAL_GROUPDNATTR);
  2339. } else{
  2340. matched = acllas__eval_memberGroupDnAttr(attrName,
  2341. lasinfo.resourceEntry,
  2342. lasinfo.clientDn,
  2343. lasinfo.aclpb);
  2344. }
  2345. if ( matched == ACL_DONT_KNOW) {
  2346. got_undefined = 1;
  2347. }
  2348. } else {
  2349. int i;
  2350. char *n_groupdn;
  2351. /* ignore leading/trailing whitespace */
  2352. while(ldap_utf8isspace(attrName)) LDAP_UTF8INC(attrName);
  2353. len = strlen(attrName);
  2354. ptr = attrName+len-1;
  2355. while(ptr >= attrName && ldap_utf8isspace(ptr)) {
  2356. *ptr = '\0';
  2357. LDAP_UTF8DEC(ptr);
  2358. }
  2359. slapi_log_error( SLAPI_LOG_ACL, plugin_name,"Attr:%s\n" , attrName);
  2360. /* See if we have a parent[2].attr" rule */
  2361. if (strstr(attrName, "parent[") != NULL) {
  2362. char *word, *str, *next = NULL;
  2363. numOflevels = 0;
  2364. n_currEntryDn = slapi_entry_get_ndn ( lasinfo.resourceEntry ) ;
  2365. s_attrName = attrName = slapi_ch_strdup ( attr_pattern );
  2366. str = attrName;
  2367. ldap_utf8strtok_r(str, "[],. ",&next);
  2368. /* The first word is "parent[" and so it's not important */
  2369. while ((word= ldap_utf8strtok_r(NULL, "[],.", &next)) != NULL) {
  2370. if (ldap_utf8isdigit(word)) {
  2371. while (word && ldap_utf8isspace(word)) LDAP_UTF8INC(word);
  2372. if (numOflevels < ACLLAS_MAX_LEVELS)
  2373. levels[numOflevels++] = atoi (word);
  2374. else {
  2375. /*
  2376. * Here, ignore the extra levels..it's really
  2377. * a syntax error which should have been ruled out at parse time
  2378. */
  2379. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2380. "DS_LASGroupDnattr: Exceeded the ATTR LIMIT:%d: Ignoring extra levels\n",
  2381. ACLLAS_MAX_LEVELS);
  2382. }
  2383. } else {
  2384. /* Must be the attr name. We can goof of by
  2385. ** having parent[1,2,a] but then you have to be
  2386. ** stupid to do that.
  2387. */
  2388. char *p = word;
  2389. if (*--p == '.') {
  2390. attrName = word;
  2391. break;
  2392. }
  2393. }
  2394. }
  2395. } else {
  2396. levels[0] = 0;
  2397. numOflevels = 1;
  2398. }
  2399. matched = ACL_FALSE;
  2400. for (i=0; i < numOflevels; i++) {
  2401. if ( levels[i] == 0 ) {
  2402. Slapi_Value *sval=NULL;
  2403. const struct berval *attrVal;
  2404. int attr_i;
  2405. /*
  2406. * For the add operation, the resource itself (level 0)
  2407. * must never be allowed to grant access--
  2408. * This is because access would be granted based on a value
  2409. * of an attribute in the new entry--security hole.
  2410. * XXX is this therefore FALSE or DONT_KNOW ?
  2411. */
  2412. if ( lasinfo.aclpb->aclpb_optype == SLAPI_OPERATION_ADD) {
  2413. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2414. "ACL info: groupdnAttr does not allow ADD permission at level 0.\n");
  2415. got_undefined = 1;
  2416. continue;
  2417. }
  2418. slapi_entry_attr_find ( lasinfo.resourceEntry, attrName, &attr);
  2419. if ( !attr) continue;
  2420. attr_i= slapi_attr_first_value ( attr,&sval );
  2421. while ( attr_i != -1 ) {
  2422. attrVal = slapi_value_get_berval ( sval );
  2423. n_groupdn = slapi_create_dn_string("%s", attrVal->bv_val);
  2424. if (NULL == n_groupdn) {
  2425. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2426. "DS_LASGroupDnAttrEval: Invalid syntax: %s\n",
  2427. attrVal->bv_val );
  2428. slapi_ch_free_string(&s_attrName);
  2429. return 0;
  2430. }
  2431. matched = acllas__user_ismember_of_group (
  2432. lasinfo.aclpb, n_groupdn, lasinfo.clientDn,
  2433. ACLLAS_CACHE_MEMBER_GROUPS,
  2434. lasinfo.aclpb->aclpb_clientcert);
  2435. slapi_ch_free ( (void **) &n_groupdn);
  2436. if (matched == ACL_TRUE ) {
  2437. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2438. "groupdnattr matches at level (%d)\n", levels[i]);
  2439. break;
  2440. } else if ( matched == ACL_DONT_KNOW ) {
  2441. /* record this but keep going--maybe another group will evaluate to TRUE */
  2442. got_undefined = 1;
  2443. }
  2444. attr_i= slapi_attr_next_value ( attr, attr_i, &sval );
  2445. }
  2446. } else {
  2447. char *p_dn;
  2448. struct groupdnattr_info info;
  2449. char *attrs[2];
  2450. int j;
  2451. info.numofGroups = 0;
  2452. attrs[0] = info.attrName = attrName;
  2453. attrs[1] = NULL;
  2454. p_dn = acllas__dn_parent (n_currEntryDn, levels[i]);
  2455. if (p_dn == NULL) continue;
  2456. /* Use new search internal API */
  2457. {
  2458. Slapi_PBlock *aPb = slapi_pblock_new ();
  2459. /*
  2460. * This search may NOT be chained--if the user's definition is
  2461. * remote and the group is dynamic and the user entry
  2462. * changes then we would not notice--so don't go
  2463. * find the user entry in the first place.
  2464. */
  2465. slapi_search_internal_set_pb ( aPb,
  2466. p_dn,
  2467. LDAP_SCOPE_BASE,
  2468. "objectclass=*",
  2469. &attrs[0],
  2470. 0,
  2471. NULL /* controls */,
  2472. NULL /* uniqueid */,
  2473. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  2474. SLAPI_OP_FLAG_NEVER_CHAIN /* actions */);
  2475. slapi_search_internal_callback_pb(aPb,
  2476. &info /* callback_data */,
  2477. NULL/* result_callback */,
  2478. acllas__get_members,
  2479. NULL /* referral_callback */);
  2480. slapi_pblock_destroy (aPb);
  2481. }
  2482. if (info.numofGroups <= 0) {
  2483. continue;
  2484. }
  2485. for (j=0; j <info.numofGroups; j++) {
  2486. if (slapi_utf8casecmp((ACLUCHP)info.member[j],
  2487. (ACLUCHP)lasinfo.clientDn) == 0) {
  2488. matched = ACL_TRUE;
  2489. break;
  2490. }
  2491. matched = acllas__user_ismember_of_group (
  2492. lasinfo.aclpb, info.member[j],
  2493. lasinfo.clientDn, ACLLAS_CACHE_ALL_GROUPS,
  2494. lasinfo.aclpb->aclpb_clientcert);
  2495. if (matched == ACL_TRUE) {
  2496. break;
  2497. } else if ( matched == ACL_DONT_KNOW ) {
  2498. /* record this but keep going--maybe another group will evaluate to TRUE */
  2499. got_undefined = 1;
  2500. }
  2501. }
  2502. /* Deallocate the member array and the member struct */
  2503. for (j=0; j < info.numofGroups; j++)
  2504. slapi_ch_free ((void **) &info.member[j]);
  2505. slapi_ch_free ((void **) &info.member);
  2506. }
  2507. if (matched == ACL_TRUE) {
  2508. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2509. "groupdnattr matches at level (%d)\n", levels[i]);
  2510. break;
  2511. } else if ( matched == ACL_DONT_KNOW ) {
  2512. /* record this but keep going--maybe another group at another level
  2513. * will evaluate to TRUE.
  2514. */
  2515. got_undefined = 1;
  2516. }
  2517. } /* NumofLevels */
  2518. }
  2519. slapi_ch_free_string(&s_attrName);
  2520. /*
  2521. * If no terms were undefined, then evaluate as normal.
  2522. * If there was an undefined term, but another one was TRUE, then we also evaluate
  2523. * as normal. Otherwise, the whole expression is UNDEFINED.
  2524. */
  2525. if ( matched == ACL_TRUE || !got_undefined ) {
  2526. if (comparator == CMP_OP_EQ) {
  2527. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  2528. } else {
  2529. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  2530. }
  2531. } else {
  2532. rc = LAS_EVAL_FAIL;
  2533. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2534. "Returning UNDEFINED for groupdnattr evaluation.\n");
  2535. }
  2536. return rc;
  2537. }
  2538. /*
  2539. * acllas__eval_memberGroupDnAttr
  2540. *
  2541. * return ACL_TRUE, ACL_FALSE or ACL_DONT_KNOW
  2542. *
  2543. * Inverse group evaluation. Find all the groups that the user is a
  2544. * member of. Find all teh groups that contain those groups. Do an
  2545. * upward nested level search. By the end of it, we will know all the
  2546. * groups that the clinet is a member of under that search scope.
  2547. *
  2548. * This model seems to be very fast if we have few groups at the
  2549. * leaf level.
  2550. *
  2551. */
  2552. static int
  2553. acllas__eval_memberGroupDnAttr (char *attrName, Slapi_Entry *e,
  2554. char *n_clientdn, struct acl_pblock *aclpb)
  2555. {
  2556. Slapi_Attr *attr;
  2557. char *s, *p;
  2558. char *str, *s_str, *base, *groupattr = NULL;
  2559. int i,j,k,matched, enumerate_groups;
  2560. aclUserGroup *u_group;
  2561. char ebuf [ BUFSIZ ];
  2562. Slapi_Value *sval=NULL;
  2563. const struct berval *attrVal;
  2564. /* Parse the URL -- getting the group attr and counting up '?'s.
  2565. * If there is no group attr and there are 3 '?' marks,
  2566. * we parse the URL with ldap_url_parse to get base dn and filter.
  2567. */
  2568. s_str = str = slapi_ch_strdup(attrName);
  2569. while (str && ldap_utf8isspace(str)) LDAP_UTF8INC( str );
  2570. str +=8;
  2571. s = strchr (str, '?');
  2572. if (s) {
  2573. p = s;
  2574. p++;
  2575. *s = '\0';
  2576. base = str;
  2577. s = strchr (p, '?');
  2578. if (s) *s = '\0';
  2579. groupattr = p;
  2580. } else {
  2581. slapi_ch_free ( (void **)&s_str );
  2582. return ACL_FALSE;
  2583. }
  2584. if ( (u_group = aclg_get_usersGroup ( aclpb , n_clientdn )) == NULL) {
  2585. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2586. "Failed to find/allocate a usergroup--aborting evaluation\n");
  2587. slapi_ch_free ( (void **)&s_str );
  2588. return(ACL_DONT_KNOW);
  2589. }
  2590. /*
  2591. ** First find out if we have already searched this base or
  2592. ** if we are searching a subtree to an already enumerated base.
  2593. */
  2594. enumerate_groups = 1;
  2595. for (j=0; j < aclpb->aclpb_numof_bases; j++) {
  2596. if (slapi_dn_issuffix(aclpb->aclpb_grpsearchbase[j], base)) {
  2597. enumerate_groups = 0;
  2598. break;
  2599. }
  2600. }
  2601. /* See if we have already enumerated all the groups which the
  2602. ** client is a member of.
  2603. */
  2604. if (enumerate_groups) {
  2605. char *attrs[3];
  2606. struct eval_info info = {0};
  2607. char *curMemberDn;
  2608. int Done = 0;
  2609. int ngr, tt;
  2610. char *normed = NULL;
  2611. /* Add the scope to the list of scopes */
  2612. if (aclpb->aclpb_numof_bases >= (aclpb->aclpb_grpsearchbase_size-1)) {
  2613. aclpb->aclpb_grpsearchbase = (char **)
  2614. slapi_ch_realloc (
  2615. (void *) aclpb->aclpb_grpsearchbase,
  2616. (aclpb->aclpb_grpsearchbase_size +
  2617. ACLPB_INCR_BASES) *
  2618. sizeof (char *));
  2619. aclpb->aclpb_grpsearchbase_size += ACLPB_INCR_BASES;
  2620. }
  2621. normed = slapi_create_dn_string("%s", base);
  2622. if (NULL == normed) {
  2623. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2624. "acllas__eval_memberGroupDnAttr: Invalid syntax: %s\n",
  2625. base );
  2626. slapi_ch_free ( (void **)&s_str );
  2627. return ACL_FALSE;
  2628. }
  2629. aclpb->aclpb_grpsearchbase[aclpb->aclpb_numof_bases++] = normed;
  2630. /* Set up info to do a search */
  2631. attrs[0] = type_member;
  2632. attrs[1] = type_uniquemember;
  2633. attrs[2] = NULL;
  2634. info.c_idx = info.lu_idx = 0;
  2635. info.member =
  2636. (char **) slapi_ch_malloc (ACLLAS_MAX_GRP_MEMBER * sizeof(char *));
  2637. curMemberDn = n_clientdn;
  2638. while (!Done) {
  2639. char *filter_str_ptr;
  2640. /*
  2641. ** Search the db for groups that the client is a member of.
  2642. ** Once found cache it. cache only unique groups.
  2643. */
  2644. tt = info.lu_idx;
  2645. filter_str_ptr = slapi_filter_sprintf("(|(uniquemember=%s%s)(member=%s%s))",
  2646. ESC_AND_NORM_NEXT_VAL, curMemberDn, ESC_AND_NORM_NEXT_VAL ,curMemberDn);
  2647. /* Use new search internal API */
  2648. {
  2649. Slapi_PBlock *aPb = slapi_pblock_new ();
  2650. /*
  2651. * This search may NOT be chained--we demand that group
  2652. * definition be local.
  2653. */
  2654. slapi_search_internal_set_pb ( aPb,
  2655. base,
  2656. LDAP_SCOPE_SUBTREE,
  2657. filter_str_ptr,
  2658. &attrs[0],
  2659. 0,
  2660. NULL /* controls */,
  2661. NULL /* uniqueid */,
  2662. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  2663. SLAPI_OP_FLAG_NEVER_CHAIN /* actions */);
  2664. slapi_search_internal_callback_pb(aPb,
  2665. &info /* callback_data */,
  2666. NULL/* result_callback */,
  2667. acllas__add_allgroups,
  2668. NULL /* referral_callback */);
  2669. slapi_pblock_destroy (aPb);
  2670. }
  2671. slapi_ch_free_string(&filter_str_ptr);
  2672. if (tt == info.lu_idx) {
  2673. slapi_log_error( SLAPI_LOG_ACL, plugin_name, "currDn:(%s) \n\tNO MEMBER ADDED\n",
  2674. ACL_ESCAPE_STRING_WITH_PUNCTUATION (curMemberDn, ebuf));
  2675. } else {
  2676. for (i=tt; i < info.lu_idx; i++)
  2677. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2678. "currDn:(%s) \n\tADDED MEMBER[%d]=%s\n",
  2679. ACL_ESCAPE_STRING_WITH_PUNCTUATION (curMemberDn, ebuf), i, info.member[i]);
  2680. }
  2681. if (info.c_idx >= info.lu_idx) {
  2682. for (i=0; i < info.lu_idx; i++) {
  2683. int already_cached = 0;
  2684. for (j=0; j < u_group->aclug_numof_member_group;
  2685. j++){
  2686. if (slapi_utf8casecmp(
  2687. (ACLUCHP)info.member[i],
  2688. (ACLUCHP)u_group->aclug_member_groups[j]) == 0) {
  2689. slapi_ch_free ((void **) &info.member[i] );
  2690. info.member[i] = NULL;
  2691. already_cached = 1;
  2692. break;
  2693. }
  2694. }
  2695. if (already_cached) continue;
  2696. ngr = u_group->aclug_numof_member_group++;
  2697. if (u_group->aclug_numof_member_group >=
  2698. u_group->aclug_member_group_size){
  2699. u_group->aclug_member_groups =
  2700. (char **) slapi_ch_realloc (
  2701. (void *) u_group->aclug_member_groups,
  2702. (u_group->aclug_member_group_size +
  2703. ACLUG_INCR_GROUPS_LIST) * sizeof(char *));
  2704. u_group->aclug_member_group_size +=
  2705. ACLUG_INCR_GROUPS_LIST;
  2706. }
  2707. u_group->aclug_member_groups[ngr] = info.member[i];
  2708. info.member[i] = NULL;
  2709. }
  2710. slapi_ch_free ((void **) &info.member);
  2711. Done = 1;
  2712. } else {
  2713. curMemberDn = info.member[info.c_idx];
  2714. info.c_idx++;
  2715. }
  2716. }
  2717. }
  2718. for (j=0; j < u_group->aclug_numof_member_group; j++)
  2719. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  2720. "acllas__eval_memberGroupDnAttr:GROUP[%d] IN CACHE:%s\n",
  2721. j, ACL_ESCAPE_STRING_WITH_PUNCTUATION (u_group->aclug_member_groups[j], ebuf));
  2722. matched = ACL_FALSE;
  2723. slapi_entry_attr_find( e, groupattr, &attr);
  2724. if (attr == NULL) {
  2725. slapi_ch_free ( (void **)&s_str );
  2726. return ACL_FALSE;
  2727. }
  2728. k = slapi_attr_first_value ( attr,&sval );
  2729. while ( k != -1 ) {
  2730. char *n_attrval;
  2731. attrVal = slapi_value_get_berval ( sval );
  2732. n_attrval = slapi_create_dn_string("%s", attrVal->bv_val);
  2733. if (NULL == n_attrval) {
  2734. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2735. "acllas__eval_memberGroupDnAttr: Invalid syntax: %s\n",
  2736. attrVal->bv_val );
  2737. slapi_ch_free ( (void **)&s_str );
  2738. return ACL_FALSE;
  2739. }
  2740. /* We support: The attribute value can be a USER or a GROUP.
  2741. ** Let's compare with the client, thi might be just an user. If it is not
  2742. ** then we test it against the list of groups.
  2743. */
  2744. if (slapi_utf8casecmp ((ACLUCHP)n_attrval, (ACLUCHP)n_clientdn) == 0 ) {
  2745. matched = ACL_TRUE;
  2746. slapi_ch_free ( (void **)&n_attrval );
  2747. break;
  2748. }
  2749. for (j=0; j <u_group->aclug_numof_member_group; j++) {
  2750. if ( slapi_utf8casecmp((ACLUCHP)n_attrval,
  2751. (ACLUCHP)u_group->aclug_member_groups[j]) == 0) {
  2752. matched = ACL_TRUE;
  2753. break;
  2754. }
  2755. }
  2756. slapi_ch_free ( (void **)&n_attrval );
  2757. if (matched == ACL_TRUE) break;
  2758. k= slapi_attr_next_value ( attr, k, &sval );
  2759. }
  2760. slapi_ch_free ( (void **)&s_str );
  2761. return matched;
  2762. }
  2763. static int
  2764. acllas__add_allgroups (Slapi_Entry* e, void *callback_data)
  2765. {
  2766. int i, n, m;
  2767. struct eval_info *info;
  2768. char *n_dn;
  2769. info = (struct eval_info *) callback_data;
  2770. /*
  2771. ** Once we are here means this is a valid group. First see
  2772. ** If we have already seen this group. If not, add it to the
  2773. ** member list.
  2774. */
  2775. n_dn = slapi_ch_strdup ( slapi_entry_get_ndn ( e ) );
  2776. for (i=0; i < info->lu_idx; i++) {
  2777. if (slapi_utf8casecmp((ACLUCHP)n_dn, (ACLUCHP)info->member[i]) == 0) {
  2778. slapi_ch_free ( (void **) &n_dn);
  2779. return 0;
  2780. }
  2781. }
  2782. m = info->lu_idx;
  2783. n = ++info->lu_idx;
  2784. if (!(n % ACLLAS_MAX_GRP_MEMBER)) {
  2785. info->member = (char **) slapi_ch_realloc (
  2786. (void *) info->member,
  2787. (n+ACLLAS_MAX_GRP_MEMBER) * sizeof(char *));
  2788. }
  2789. info->member[m] = n_dn;
  2790. return 0;
  2791. }
  2792. /*
  2793. *
  2794. * acllas__dn_parent
  2795. *
  2796. * This code should belong to dn.c. However this is specific to acl and I had
  2797. * 2 choices 1) create a new API or 2) reuse the slapi_dN_parent
  2798. *
  2799. * Returns a ptr to the parent based on the level.
  2800. *
  2801. */
  2802. #define DNSEPARATOR(c) (c == ',' || c == ';')
  2803. static char*
  2804. acllas__dn_parent( char *dn, int level)
  2805. {
  2806. char *s, *dnstr;
  2807. int inquote;
  2808. int curLevel;
  2809. int lastLoop = 0;
  2810. if ( dn == NULL || *dn == '\0' ) {
  2811. return( NULL );
  2812. }
  2813. /* An X.500-style name, which looks like foo=bar,sha=baz,... */
  2814. /* Do we have any dn seprator or not */
  2815. if ((strchr(dn,',') == NULL) && (strchr(dn,';') == NULL))
  2816. return (NULL);
  2817. inquote = 0;
  2818. curLevel = 1;
  2819. dnstr = dn;
  2820. while ( curLevel <= level) {
  2821. if (lastLoop) break;
  2822. if (curLevel == level) lastLoop = 1;
  2823. for ( s = dnstr; *s; s++ ) {
  2824. if ( *s == '\\' ) {
  2825. if ( *(s + 1) )
  2826. s++;
  2827. continue;
  2828. }
  2829. if ( inquote ) {
  2830. if ( *s == '"' )
  2831. inquote = 0;
  2832. } else {
  2833. if ( *s == '"' )
  2834. inquote = 1;
  2835. else if ( DNSEPARATOR( *s ) ) {
  2836. if (curLevel == level)
  2837. return( s + 1 );
  2838. dnstr = s + 1;
  2839. curLevel++;
  2840. break;
  2841. }
  2842. }
  2843. }
  2844. if ( *s == '\0') {
  2845. /* Got to the end of the string without reaching level,
  2846. * so return NULL.
  2847. */
  2848. return(NULL);
  2849. }
  2850. }
  2851. return( NULL );
  2852. }
  2853. /*
  2854. * acllas__verify_client
  2855. *
  2856. * returns 1 if the attribute exists in the entry and
  2857. * it's value is equal to the client Dn.
  2858. * If the attribute is not in the entry, or it is and the
  2859. * value differs from the clientDn then returns FALSE.
  2860. *
  2861. * Verify if client's DN is stored in the attrbute or not.
  2862. * This is a handler from a search being done at
  2863. * DS_LASUserDnAttrEval().
  2864. *
  2865. */
  2866. static int
  2867. acllas__verify_client (Slapi_Entry* e, void *callback_data)
  2868. {
  2869. Slapi_Attr *attr;
  2870. char *val;
  2871. struct userdnattr_info *info;
  2872. Slapi_Value *sval;
  2873. const struct berval *attrVal;
  2874. int i;
  2875. info = (struct userdnattr_info *) callback_data;
  2876. slapi_entry_attr_find( e, info->attr, &attr);
  2877. if (attr == NULL) return 0;
  2878. i = slapi_attr_first_value ( attr,&sval );
  2879. while ( i != -1 ) {
  2880. attrVal = slapi_value_get_berval ( sval );
  2881. val = slapi_create_dn_string("%s", attrVal->bv_val);
  2882. if (NULL == val) {
  2883. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2884. "acllas__verify_client: Invalid syntax: %s\n",
  2885. attrVal->bv_val );
  2886. return 0;
  2887. }
  2888. if (slapi_utf8casecmp((ACLUCHP)val, (ACLUCHP)info->clientdn ) == 0) {
  2889. info->result = 1;
  2890. slapi_ch_free ( (void **) &val);
  2891. return 0;
  2892. }
  2893. slapi_ch_free ( (void **) &val);
  2894. i = slapi_attr_next_value ( attr, i, &sval );
  2895. }
  2896. return 0;
  2897. }
  2898. /*
  2899. * acllas__verify_ldapurl
  2900. *
  2901. * returns 1 if the attribute exists in the entry and
  2902. * it's value is equal to the client Dn.
  2903. * If the attribute is not in the entry, or it is and the
  2904. * value differs from the clientDn then returns FALSE.
  2905. *
  2906. * Verify if client's entry includes the attribute value that
  2907. * matches the filter in LDAPURL
  2908. * This is a handler from a search being done at DS_LASLdapUrlAttrEval().
  2909. *
  2910. */
  2911. static int
  2912. acllas__verify_ldapurl(Slapi_Entry* e, void *callback_data)
  2913. {
  2914. Slapi_Attr *attr;
  2915. struct userdnattr_info *info;
  2916. Slapi_Value *sval;
  2917. const struct berval *attrVal;
  2918. int rc;
  2919. info = (struct userdnattr_info *) callback_data;
  2920. info->result = ACL_FALSE;
  2921. rc = slapi_entry_attr_find( e, info->attr, &attr);
  2922. if (rc != 0 || attr == NULL) {
  2923. return 0;
  2924. }
  2925. rc = slapi_attr_first_value ( attr, &sval );
  2926. if ( rc == -1 ) {
  2927. return 0;
  2928. }
  2929. while (rc != -1 && sval != NULL) {
  2930. attrVal = slapi_value_get_berval ( sval );
  2931. info->result = acllas__client_match_URL ( info->aclpb,
  2932. info->clientdn,
  2933. attrVal->bv_val);
  2934. if ( info->result == ACL_TRUE ) {
  2935. return 0;
  2936. }
  2937. rc = slapi_attr_next_value ( attr, rc, &sval );
  2938. }
  2939. return 0;
  2940. }
  2941. /*
  2942. *
  2943. * acllas__get_members
  2944. *
  2945. * Collects all the values of the specified attribute which should be group names.
  2946. */
  2947. static int
  2948. acllas__get_members (Slapi_Entry* e, void *callback_data)
  2949. {
  2950. Slapi_Attr *attr;
  2951. struct groupdnattr_info *info;
  2952. Slapi_Value *sval=NULL;
  2953. const struct berval *attrVal;
  2954. int i;
  2955. info = (struct groupdnattr_info *) callback_data;
  2956. slapi_entry_attr_find (e, info->attrName, &attr);
  2957. if ( !attr ) return 0;
  2958. slapi_attr_get_numvalues ( attr, &info->numofGroups );
  2959. info->member = (char **) slapi_ch_malloc (info->numofGroups * sizeof(char *));
  2960. i = slapi_attr_first_value ( attr,&sval );
  2961. while ( i != -1 ) {
  2962. attrVal =slapi_value_get_berval ( sval );
  2963. info->member[i] = slapi_create_dn_string ("%s", attrVal->bv_val);
  2964. if (NULL == info->member[i]) {
  2965. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  2966. "acllas__get_members: Invalid syntax: %s\n",
  2967. attrVal->bv_val );
  2968. }
  2969. i = slapi_attr_next_value ( attr, i, &sval );
  2970. }
  2971. return 0;
  2972. }
  2973. /*
  2974. * DS_LASUserAttrEval
  2975. * LAS to evaluate the userattr rule
  2976. *
  2977. * userAttr = "attrName#Type"
  2978. *
  2979. * <Type> ::= "USERDN" | "GROUPDN" | "ROLEDN" | "LDAPURL" | <value>
  2980. * <value>::== <any printable String>
  2981. *
  2982. * Example:
  2983. * userAttr = "manager#USERDN" --- same as userdnattr
  2984. * userAttr = "owner#GROUPDN" --- same as groupdnattr
  2985. * = "ldap:///o=sun.com?owner#GROUPDN
  2986. * userAttr = "attr#ROLEDN" --- The value of attr contains a roledn
  2987. * userAttr = "myattr#LDAPURL" --- The value contains a LDAP URL
  2988. * which can have scope and filter
  2989. * bits.
  2990. * userAttr = "OU#Directory Server"
  2991. * --- In this case the client's OU and the
  2992. * resource entry's OU must have
  2993. * "Directory Server" value.
  2994. *
  2995. * Returns:
  2996. * retcode The usual LAS return codes.
  2997. */
  2998. int
  2999. DS_LASUserAttrEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  3000. char *attr_pattern, int *cachable, void **LAS_cookie,
  3001. PList_t subject, PList_t resource, PList_t auth_info,
  3002. PList_t global_auth)
  3003. {
  3004. char *attrName;
  3005. char *attrValue = NULL;
  3006. int rc;
  3007. int matched = ACL_FALSE;
  3008. char *p;
  3009. lasInfo lasinfo;
  3010. int got_undefined = 0;
  3011. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  3012. attr_pattern,cachable,LAS_cookie,
  3013. subject, resource, auth_info,global_auth,
  3014. DS_LAS_USERATTR, "DS_LASUserAttrEval",
  3015. &lasinfo )) ) {
  3016. return LAS_EVAL_FAIL;
  3017. }
  3018. /* Which rule are we evaluating ? */
  3019. attrName = slapi_ch_strdup (attr_pattern );
  3020. if ( NULL == (p = strchr ( attrName, '#' ))) {
  3021. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3022. "DS_LASUserAttrEval:Invalid value(%s)\n", attr_pattern);
  3023. slapi_ch_free ( (void **) &attrName );
  3024. return LAS_EVAL_FAIL;
  3025. }
  3026. attrValue = p;
  3027. attrValue++; /* skip the # */
  3028. *p = '\0'; /* null terminate the attr name */
  3029. if ( 0 == strncasecmp ( attrValue, "USERDN", 6)) {
  3030. matched = DS_LASUserDnAttrEval (errp,DS_LAS_USERDNATTR, comparator,
  3031. attrName, cachable, LAS_cookie,
  3032. subject, resource, auth_info, global_auth);
  3033. goto done_las;
  3034. } else if ( 0 == strncasecmp ( attrValue, "GROUPDN", 7)) {
  3035. matched = DS_LASGroupDnAttrEval (errp,DS_LAS_GROUPDNATTR, comparator,
  3036. attrName, cachable, LAS_cookie,
  3037. subject, resource, auth_info, global_auth);
  3038. goto done_las;
  3039. } else if ( 0 == strncasecmp ( attrValue, "LDAPURL", 7) ) {
  3040. matched = DS_LASLdapUrlAttrEval(errp, DS_LAS_USERATTR, comparator,
  3041. attrName, cachable, LAS_cookie,
  3042. subject, resource, auth_info, global_auth, lasinfo);
  3043. goto done_las;
  3044. } else if ( 0 == strncasecmp ( attrValue, "ROLEDN", 6)) {
  3045. matched = DS_LASRoleDnAttrEval (errp,DS_LAS_ROLEDN, comparator,
  3046. attrName, cachable, LAS_cookie,
  3047. subject, resource, auth_info, global_auth);
  3048. goto done_las;
  3049. } else if (0 == strncasecmp ( attrValue, "SELFDN", 6)) {
  3050. matched = DS_LASUserDnAttrEval (errp,DS_LAS_SELFDNATTR, comparator,
  3051. attrName, cachable, LAS_cookie,
  3052. subject, resource, auth_info, global_auth);
  3053. goto done_las;
  3054. }
  3055. if ( lasinfo.aclpb && ( NULL == lasinfo.aclpb->aclpb_client_entry )) {
  3056. /* SD 00/16/03 pass NULL in case the req is chained */
  3057. char **attrs=NULL;
  3058. /* Use new search internal API */
  3059. Slapi_PBlock *aPb = slapi_pblock_new ();
  3060. /*
  3061. * This search may be chained if chaining for ACL is
  3062. * is enabled in the backend and the entry is in
  3063. * a chained backend.
  3064. */
  3065. slapi_search_internal_set_pb ( aPb,
  3066. lasinfo.clientDn,
  3067. LDAP_SCOPE_BASE,
  3068. "objectclass=*",
  3069. attrs,
  3070. 0,
  3071. NULL /* controls */,
  3072. NULL /* uniqueid */,
  3073. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  3074. 0 /* actions */);
  3075. slapi_search_internal_callback_pb(aPb,
  3076. lasinfo.aclpb /* callback_data */,
  3077. NULL/* result_callback */,
  3078. acllas__handle_client_search,
  3079. NULL /* referral_callback */);
  3080. slapi_pblock_destroy (aPb);
  3081. }
  3082. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  3083. "DS_LASUserAttrEval: AttrName:%s, attrVal:%s\n", attrName, attrValue );
  3084. /*
  3085. * Here it's the userAttr = "OU#Directory Server" case.
  3086. * Allocate the Slapi_Value on the stack and init it by reference
  3087. * to avoid having to malloc and free memory.
  3088. */
  3089. Slapi_Value v;
  3090. slapi_value_init_string_passin(&v, attrValue);
  3091. rc = slapi_entry_attr_has_syntax_value ( lasinfo.resourceEntry, attrName,
  3092. &v );
  3093. if (rc) {
  3094. rc = slapi_entry_attr_has_syntax_value (
  3095. lasinfo.aclpb->aclpb_client_entry,
  3096. attrName, &v );
  3097. if (rc) matched = ACL_TRUE;
  3098. }
  3099. /* Nothing to free--cool */
  3100. /*
  3101. * Find out what the result is, in
  3102. * this case matched is one of ACL_TRUE, ACL_FALSE or ACL_DONT_KNOW
  3103. * and got_undefined says whether a logical term evaluated to ACL_DONT_KNOW.
  3104. *
  3105. */
  3106. if ( matched == ACL_TRUE || !got_undefined) {
  3107. if (comparator == CMP_OP_EQ) {
  3108. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  3109. } else {
  3110. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  3111. }
  3112. } else {
  3113. rc = LAS_EVAL_FAIL;
  3114. }
  3115. slapi_ch_free ( (void **) &attrName );
  3116. return rc;
  3117. done_las:
  3118. /*
  3119. * In this case matched is already LAS_EVAL_TRUE or LAS_EVAL_FALSE or
  3120. * LAS_EVAL_FAIL.
  3121. */
  3122. if ( matched != LAS_EVAL_FAIL ) {
  3123. if (comparator == CMP_OP_EQ) {
  3124. rc = matched;
  3125. } else {
  3126. rc = (matched == LAS_EVAL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  3127. }
  3128. }
  3129. slapi_ch_free ( (void **) &attrName );
  3130. return rc;
  3131. }
  3132. /*
  3133. * acllas__client_match_URL
  3134. * Match a client to a URL.
  3135. *
  3136. * Returns:
  3137. * ACL_TRUE - matched the URL
  3138. * ACL_FALSE - Sorry; no match
  3139. *
  3140. */
  3141. static int
  3142. acllas__client_match_URL (struct acl_pblock *aclpb, char *n_clientdn, char *url )
  3143. {
  3144. LDAPURLDesc *ludp = NULL;
  3145. int rc = 0;
  3146. Slapi_Filter *f = NULL;
  3147. char *rawdn = NULL;
  3148. char *dn = NULL;
  3149. char *p = NULL;
  3150. char *normed = NULL;
  3151. /* ldap(s)://host:port/suffix?attrs?scope?filter */
  3152. const size_t LDAP_URL_prefix_len = strlen(LDAP_URL_prefix_core);
  3153. const size_t LDAPS_URL_prefix_len = strlen(LDAPS_URL_prefix_core);
  3154. size_t prefix_len = 0;
  3155. char Q = '?';
  3156. char *hostport = NULL;
  3157. int result = ACL_FALSE;
  3158. if ( NULL == aclpb ) {
  3159. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  3160. "acllas__client_match_URL: NULL acl pblock\n");
  3161. return ACL_FALSE;
  3162. }
  3163. /* Get the client's entry if we don't have already */
  3164. if ( NULL == aclpb->aclpb_client_entry ) {
  3165. /* SD 00/16/03 Get every attr in case req chained */
  3166. char **attrs=NULL;
  3167. /* Use new search internal API */
  3168. Slapi_PBlock * aPb = slapi_pblock_new ();
  3169. /*
  3170. * This search may be chained if chaining for ACL is
  3171. * is enabled in the backend and the entry is in
  3172. * a chained backend.
  3173. */
  3174. slapi_search_internal_set_pb ( aPb,
  3175. n_clientdn,
  3176. LDAP_SCOPE_BASE,
  3177. "objectclass=*",
  3178. attrs,
  3179. 0,
  3180. NULL /* controls */,
  3181. NULL /* uniqueid */,
  3182. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  3183. 0 /* actions */);
  3184. slapi_search_internal_callback_pb(aPb,
  3185. aclpb /* callback_data */,
  3186. NULL/* result_callback */,
  3187. acllas__handle_client_search,
  3188. NULL /* referral_callback */);
  3189. slapi_pblock_destroy (aPb);
  3190. }
  3191. if ( NULL == aclpb->aclpb_client_entry ) {
  3192. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  3193. "acllas__client_match_URL: Unable to get client's entry\n");
  3194. goto done;
  3195. }
  3196. /* DN potion of URL must be normalized before calling ldap_url_parse.
  3197. * lud_dn is pointing at the middle of lud_string.
  3198. * lud_dn won't be freed in ldap_free_urldesc.
  3199. */
  3200. /* remove the "ldap{s}:///" part */
  3201. if (strncasecmp (url, LDAP_URL_prefix, LDAP_URL_prefix_len) == 0) {
  3202. prefix_len = LDAP_URL_prefix_len;
  3203. } else if (strncasecmp (url, LDAPS_URL_prefix, LDAPS_URL_prefix_len) == 0) {
  3204. prefix_len = LDAPS_URL_prefix_len;
  3205. } else {
  3206. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  3207. "acllas__client_match_URL: url %s does not have a recognized ldap protocol prefix\n", url);
  3208. goto done;
  3209. }
  3210. rawdn = url + prefix_len; /* ldap(s)://host:port/... or ldap(s):///... */
  3211. /* rawdn at ^ or ^ */
  3212. /* let rawdn point the suffix */
  3213. if ('/' == *(rawdn+1)) { /* ldap(s):/// */
  3214. rawdn += 2;
  3215. } else {
  3216. char *tmpp = rawdn;
  3217. rawdn = strchr(tmpp, '/');
  3218. size_t hostport_len = 0;
  3219. if (NULL == rawdn) {
  3220. slapi_log_error (SLAPI_LOG_ACL, plugin_name,
  3221. "acllas__client_match_URL: url %s does not have a valid ldap protocol prefix\n", url);
  3222. goto done;
  3223. }
  3224. hostport_len = ++rawdn - tmpp; /* ldap(s)://host:port/... */
  3225. /* <--------> */
  3226. hostport = (char *)slapi_ch_malloc(hostport_len + 1);
  3227. memcpy(hostport, tmpp, hostport_len);
  3228. *(hostport+hostport_len) = '\0';
  3229. }
  3230. p = strchr(rawdn, Q);
  3231. if (p) {
  3232. /* url has scope and/or filter: ldap(s):///suffix?attr?scope?filter */
  3233. *p = '\0'; /* null terminate the dn part of rawdn */
  3234. }
  3235. dn = slapi_create_dn_string("%s", rawdn);
  3236. if (NULL == dn) {
  3237. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  3238. "acllas__client_match_URL: error normalizing dn [%s] part of URL [%s]\n",
  3239. rawdn, url);
  3240. goto done;
  3241. }
  3242. normed = slapi_ch_smprintf("%s%s%s%s%s",
  3243. (prefix_len==LDAP_URL_prefix_len)?
  3244. LDAP_URL_prefix_core:LDAPS_URL_prefix_core,
  3245. hostport?hostport:"", dn, p?"?":"",p?p+1:"");
  3246. if (p) {
  3247. *p = Q; /* put the Q back in rawdn which will un-null terminate the DN part */
  3248. }
  3249. slapi_ch_free_string(&dn);
  3250. rc = slapi_ldap_url_parse(normed, &ludp, 1, NULL);
  3251. if (rc) {
  3252. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  3253. "acllas__client_match_URL: url [%s] is invalid: %d (%s)\n",
  3254. normed, rc, slapi_urlparse_err2string(rc));
  3255. goto done;
  3256. }
  3257. if ( ( NULL == ludp->lud_dn) || ( NULL == ludp->lud_filter) ) {
  3258. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  3259. "acllas__client_match_URL: url [%s] has no base dn [%s] or filter [%s]\n",
  3260. normed,
  3261. NULL == ludp->lud_dn ? "null" : ludp->lud_dn,
  3262. NULL == ludp->lud_filter ? "null" : ludp->lud_filter );
  3263. goto done;
  3264. }
  3265. /* Check the scope */
  3266. if ( ludp->lud_scope == LDAP_SCOPE_SUBTREE ) {
  3267. if (!slapi_dn_issuffix(n_clientdn, ludp->lud_dn)) {
  3268. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3269. "acllas__client_match_URL: url [%s] scope is subtree but dn [%s] "
  3270. "is not a suffix of [%s]\n",
  3271. normed, ludp->lud_dn, n_clientdn );
  3272. goto done;
  3273. }
  3274. } else if ( ludp->lud_scope == LDAP_SCOPE_ONELEVEL ) {
  3275. char *parent = slapi_dn_parent (n_clientdn);
  3276. if (slapi_utf8casecmp ((ACLUCHP)parent, (ACLUCHP)ludp->lud_dn) != 0 ) {
  3277. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3278. "acllas__client_match_URL: url [%s] scope is onelevel but dn [%s] "
  3279. "is not a direct child of [%s]\n",
  3280. normed, ludp->lud_dn, parent );
  3281. slapi_ch_free_string(&parent);
  3282. goto done;
  3283. }
  3284. slapi_ch_free_string(&parent);
  3285. } else { /* default */
  3286. if (slapi_utf8casecmp ( (ACLUCHP)n_clientdn, (ACLUCHP)ludp->lud_dn) != 0 ) {
  3287. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3288. "acllas__client_match_URL: url [%s] scope is base but dn [%s] "
  3289. "does not match [%s]\n",
  3290. normed, ludp->lud_dn, n_clientdn );
  3291. goto done;
  3292. }
  3293. }
  3294. /* Convert the filter string */
  3295. f = slapi_str2filter ( ludp->lud_filter );
  3296. if (ludp->lud_filter && (f == NULL)) { /* bogus filter */
  3297. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  3298. "DS_LASUserAttrEval: The member URL [%s] search filter in entry [%s] is not valid: [%s]\n",
  3299. normed, n_clientdn, ludp->lud_filter);
  3300. goto done;
  3301. }
  3302. result = ACL_TRUE;
  3303. if (f && (0 != slapi_vattr_filter_test ( aclpb->aclpb_pblock,
  3304. aclpb->aclpb_client_entry, f, 0 /* no acces chk */ )))
  3305. result = ACL_FALSE;
  3306. done:
  3307. slapi_ch_free_string(&hostport);
  3308. ldap_free_urldesc( ludp );
  3309. slapi_ch_free_string(&normed);
  3310. slapi_filter_free ( f, 1 ) ;
  3311. return result;
  3312. }
  3313. static int
  3314. acllas__handle_client_search ( Slapi_Entry *e, void *callback_data )
  3315. {
  3316. struct acl_pblock *aclpb = (struct acl_pblock *) callback_data;
  3317. /* If we are here means we have found the entry */
  3318. if ( NULL == aclpb-> aclpb_client_entry)
  3319. aclpb->aclpb_client_entry = slapi_entry_dup ( e );
  3320. return 0;
  3321. }
  3322. /*
  3323. *
  3324. * Do all the necessary setup for all the
  3325. * LASes.
  3326. * It will only fail if it's passed garbage (which should not happen) or
  3327. * if the data it needs to stock the lasinfo is not available, which
  3328. * also should not happen.
  3329. *
  3330. *
  3331. * Return value: 0 or one of these
  3332. * #define LAS_EVAL_TRUE -1
  3333. * #define LAS_EVAL_FALSE -2
  3334. * #define LAS_EVAL_DECLINE -3
  3335. * #define LAS_EVAL_FAIL -4
  3336. * #define LAS_EVAL_INVALID -5
  3337. */
  3338. static int
  3339. __acllas_setup ( NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  3340. int allow_range, char *attr_pattern, int *cachable, void **LAS_cookie,
  3341. PList_t subject, PList_t resource, PList_t auth_info,
  3342. PList_t global_auth, char *lasType, char*lasName, lasInfo *linfo)
  3343. {
  3344. int rc;
  3345. memset ( linfo, 0, sizeof ( lasInfo) );
  3346. *cachable = 0;
  3347. *LAS_cookie = (void *)0;
  3348. if (strcmp(attr_name, lasType) != 0) {
  3349. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3350. "%s:Invalid LAS(%s)\n", lasName, attr_name);
  3351. return LAS_EVAL_INVALID;
  3352. }
  3353. /* Validate the comparator */
  3354. if (allow_range && (comparator != CMP_OP_EQ) && (comparator != CMP_OP_NE) &&
  3355. (comparator != CMP_OP_GT) && (comparator != CMP_OP_LT) &&
  3356. (comparator != CMP_OP_GE) && (comparator != CMP_OP_LE)) {
  3357. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3358. "%s:Invalid comparator(%d)\n", lasName, (int)comparator);
  3359. return LAS_EVAL_INVALID;
  3360. } else if (!allow_range && (comparator != CMP_OP_EQ) && (comparator != CMP_OP_NE)) {
  3361. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3362. "%s:Invalid comparator(%d)\n", lasName, (int)comparator);
  3363. return LAS_EVAL_INVALID;
  3364. }
  3365. /* Get the client DN */
  3366. rc = ACL_GetAttribute(errp, DS_ATTR_USERDN, (void **)&linfo->clientDn,
  3367. subject, resource, auth_info, global_auth);
  3368. if ( rc != LAS_EVAL_TRUE ) {
  3369. acl_print_acllib_err(errp, NULL);
  3370. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3371. "%s:Unable to get the clientdn attribute(%d)\n",lasName, rc);
  3372. return LAS_EVAL_FAIL;
  3373. }
  3374. /* Check if we have a user or not */
  3375. if (linfo->clientDn) {
  3376. /* See if it's a anonymous user */
  3377. if (*(linfo->clientDn) == '\0')
  3378. linfo->anomUser = ACL_TRUE;
  3379. } else {
  3380. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3381. "%s: No user\n",lasName);
  3382. return LAS_EVAL_FAIL;
  3383. }
  3384. if ((rc = PListFindValue(subject, DS_ATTR_ENTRY,
  3385. (void **)&linfo->resourceEntry, NULL)) < 0){
  3386. acl_print_acllib_err(errp, NULL);
  3387. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3388. "%s:Unable to get the Slapi_Entry attr(%d)\n",lasName, rc);
  3389. return LAS_EVAL_FAIL;
  3390. }
  3391. /* Get ACLPB */
  3392. rc = ACL_GetAttribute(errp, DS_PROP_ACLPB, (void **)&linfo->aclpb,
  3393. subject, resource, auth_info, global_auth);
  3394. if ( rc != LAS_EVAL_TRUE ) {
  3395. acl_print_acllib_err(errp, NULL);
  3396. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3397. "%s:Unable to get the ACLPB(%d)\n", lasName, rc);
  3398. return LAS_EVAL_FAIL;
  3399. }
  3400. /* LDAPI? */
  3401. if ((rc = PListFindValue(subject, DS_ATTR_LDAPI, (void **)&linfo->ldapi, NULL)) < 0){
  3402. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3403. "%s:Unable to get LDAPI value(%d)\n", lasName, rc);
  3404. return LAS_EVAL_FAIL;
  3405. }
  3406. if (NULL == attr_pattern ) {
  3407. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3408. "%s:No rule value in the ACL\n", lasName);
  3409. return LAS_EVAL_FAIL;
  3410. }
  3411. /* get the authentication type */
  3412. if ((rc = PListFindValue(subject, DS_ATTR_AUTHTYPE,
  3413. (void **)&linfo->authType, NULL)) < 0) {
  3414. acl_print_acllib_err(errp, NULL);
  3415. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3416. "%s:Unable to get the auth type(%d)\n", lasName, rc);
  3417. return LAS_EVAL_FAIL;
  3418. }
  3419. /* get the SSF */
  3420. if ((rc = PListFindValue(subject, DS_ATTR_SSF,
  3421. (void **)&linfo->ssf, NULL)) < 0) {
  3422. acl_print_acllib_err(errp, NULL);
  3423. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3424. "%s:Unable to get the ssf(%d)\n", lasName, rc);
  3425. }
  3426. return 0;
  3427. }
  3428. /*
  3429. * See if clientDN has role roleDN.
  3430. * Here we know the user is not anon and that the role
  3431. * is not the anyone role ie. it's actually worth invoking the roles code.
  3432. */
  3433. static int acllas__user_has_role( struct acl_pblock *aclpb,
  3434. Slapi_DN *roleDN, Slapi_DN *clientDn) {
  3435. int present = 0;
  3436. if ( NULL == aclpb ) {
  3437. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  3438. "acllas__user_has_role: NULL acl pblock\n");
  3439. return ACL_FALSE;
  3440. }
  3441. /* Get the client's entry if we don't have already */
  3442. if ( NULL == aclpb->aclpb_client_entry ) {
  3443. /* SD 00/16/03 Get every attr in case req chained */
  3444. char **attrs=NULL;
  3445. /* Use new search internal API */
  3446. Slapi_PBlock * aPb = slapi_pblock_new ();
  3447. /*
  3448. * This search may NOT be chained--the user and the role definition
  3449. * must be co-located (chaining is not supported for the roles
  3450. * plugin in 5.0
  3451. */
  3452. slapi_search_internal_set_pb ( aPb,
  3453. slapi_sdn_get_ndn(clientDn),
  3454. LDAP_SCOPE_BASE,
  3455. "objectclass=*",
  3456. attrs,
  3457. 0,
  3458. NULL /* controls */,
  3459. NULL /* uniqueid */,
  3460. aclplugin_get_identity (ACL_PLUGIN_IDENTITY),
  3461. SLAPI_OP_FLAG_NEVER_CHAIN /* actions */);
  3462. slapi_search_internal_callback_pb(aPb,
  3463. aclpb /* callback_data */,
  3464. NULL/* result_callback */,
  3465. acllas__handle_client_search,
  3466. NULL /* referral_callback */);
  3467. slapi_pblock_destroy (aPb);
  3468. }
  3469. if ( NULL == aclpb->aclpb_client_entry ) {
  3470. slapi_log_error ( SLAPI_LOG_ACL, plugin_name,
  3471. "acllas__user_has_role: Unable to get client's entry\n");
  3472. return ACL_FALSE;
  3473. }
  3474. /* If the client has the role then it's a match, otherwise no */
  3475. slapi_role_check( aclpb->aclpb_client_entry, roleDN, &present);
  3476. if ( present ) {
  3477. return(ACL_TRUE);
  3478. }
  3479. return(ACL_FALSE);
  3480. }
  3481. int
  3482. DS_LASRoleDnAttrEval(NSErr_t *errp, char *attr_name, CmpOp_t comparator,
  3483. char *attr_pattern, int *cachable, void **LAS_cookie,
  3484. PList_t subject, PList_t resource, PList_t auth_info,
  3485. PList_t global_auth)
  3486. {
  3487. char *attrName;
  3488. int matched;
  3489. int rc;
  3490. Slapi_Attr *attr;
  3491. lasInfo lasinfo;
  3492. Slapi_Value *sval=NULL;
  3493. const struct berval *attrVal;
  3494. int k=0;
  3495. int got_undefined = 0;
  3496. if ( 0 != (rc = __acllas_setup (errp, attr_name, comparator, 0, /* Don't allow range comparators */
  3497. attr_pattern,cachable,LAS_cookie,
  3498. subject, resource, auth_info,global_auth,
  3499. DS_LAS_ROLEDN, "DS_LASRoleDnAttrEval",
  3500. &lasinfo )) ) {
  3501. return LAS_EVAL_FAIL;
  3502. }
  3503. /* For anonymous client, they have no roles so the match is false. */
  3504. if ( lasinfo.anomUser )
  3505. return LAS_EVAL_FALSE;
  3506. /*
  3507. **
  3508. ** The function of this LAS is to find out if the client has
  3509. ** the role specified in the attr.
  3510. ** attr_pattern looks like: "ROLEDN cn=role1,o=sun.com"
  3511. */
  3512. attrName = attr_pattern;
  3513. matched = ACL_FALSE;
  3514. slapi_entry_attr_find( lasinfo.resourceEntry, attrName, &attr);
  3515. if (attr == NULL) {
  3516. /*
  3517. * Here the entry does not contain the attribute so the user
  3518. * cannot have this "null" role
  3519. */
  3520. return LAS_EVAL_FALSE;
  3521. }
  3522. if (lasinfo.aclpb->aclpb_optype == SLAPI_OPERATION_ADD) {
  3523. /*
  3524. * Here the entry does not contain the attribute so the user
  3525. * cannot have this "null" role or
  3526. * For the add operation, the resource itself
  3527. * must never be allowed to grant access--
  3528. * This is because access would be granted based on a value
  3529. * of an attribute in the new entry--security hole.
  3530. * XXX is this therefore FALSE or DONT_KNOW ?
  3531. *
  3532. *
  3533. */
  3534. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  3535. "ACL info: userattr=XXX#ROLEDN does not allow ADD permission.\n");
  3536. got_undefined = 1;
  3537. } else {
  3538. /*
  3539. * Got the first value.
  3540. * Test all the values of this attribute--if the client has _any_
  3541. * of the roles then it's a match.
  3542. */
  3543. k = slapi_attr_first_value ( attr,&sval );
  3544. while ( k != -1 ) {
  3545. char *n_attrval;
  3546. Slapi_DN *roleDN;
  3547. attrVal = slapi_value_get_berval ( sval );
  3548. n_attrval = slapi_create_dn_string("%s", attrVal->bv_val);
  3549. if (NULL == n_attrval) {
  3550. slapi_log_error( SLAPI_LOG_FATAL, plugin_name,
  3551. "DS_LASRoleDnAttrEval: Invalid syntax: %s\n",
  3552. attrVal->bv_val );
  3553. return LAS_EVAL_FAIL;
  3554. }
  3555. roleDN = slapi_sdn_new_dn_byval(n_attrval);
  3556. /* We support: The attribute value can be a USER or a GROUP.
  3557. ** Let's compare with the client, thi might be just an user. If it is not
  3558. ** then we test it against the list of groups.
  3559. */
  3560. matched = acllas__user_has_role(lasinfo.aclpb,
  3561. roleDN, lasinfo.aclpb->aclpb_authorization_sdn);
  3562. slapi_ch_free ( (void **)&n_attrval );
  3563. slapi_sdn_free(&roleDN);
  3564. if (matched == ACL_TRUE) {
  3565. break;
  3566. } else if ( matched == ACL_DONT_KNOW ) {
  3567. /* record this but keep going--maybe another group will evaluate to TRUE */
  3568. got_undefined = 1;
  3569. }
  3570. k= slapi_attr_next_value ( attr, k, &sval );
  3571. }/* while */
  3572. }
  3573. /*
  3574. * If no terms were undefined, then evaluate as normal.
  3575. * If there was an undefined term, but another one was TRUE, then we also evaluate
  3576. * as normal. Otherwise, the whole expression is UNDEFINED.
  3577. */
  3578. if ( matched == ACL_TRUE || !got_undefined ) {
  3579. if (comparator == CMP_OP_EQ) {
  3580. rc = (matched == ACL_TRUE ? LAS_EVAL_TRUE : LAS_EVAL_FALSE);
  3581. } else {
  3582. rc = (matched == ACL_TRUE ? LAS_EVAL_FALSE : LAS_EVAL_TRUE);
  3583. }
  3584. } else {
  3585. rc = LAS_EVAL_FAIL;
  3586. }
  3587. return (rc);
  3588. }
  3589. /*
  3590. * Here, determine if lasinfo->clientDn matches user (which contains
  3591. * a ($dn) or a $attr component or both.) As defined in the aci
  3592. * lasinfo->aclpb->aclpb_curr_aci,
  3593. * which is the current aci being evaluated.
  3594. *
  3595. * returns: ACL_TRUE for matched,
  3596. * ACL_FALSE for matched.
  3597. * ACL_DONT_KNOW otherwise.
  3598. */
  3599. int
  3600. aclutil_evaluate_macro( char * rule, lasInfo *lasinfo,
  3601. acl_eval_types evalType )
  3602. {
  3603. int matched = 0;
  3604. aci_t *aci;
  3605. char *matched_val = NULL;
  3606. char **candidate_list = NULL;
  3607. char **inner_list = NULL;
  3608. char **sptr = NULL;
  3609. char **tptr = NULL;
  3610. char *t = NULL;
  3611. char *s = NULL;
  3612. struct acl_pblock *aclpb = lasinfo->aclpb;
  3613. aci = lasinfo->aclpb->aclpb_curr_aci;
  3614. /* Get a pointer to the ndn in the resouirce */
  3615. slapi_entry_get_ndn ( lasinfo->resourceEntry );
  3616. /*
  3617. * First, get the matched value from the target resource.
  3618. * We have alredy done this matching once beofer at tasrget match time.
  3619. */
  3620. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  3621. "aclutil_evaluate_macro for aci '%s' index '%d'\n",
  3622. aci->aclName, aci->aci_index );
  3623. if ( aci->aci_macro == NULL ) {
  3624. /* No $dn in the target, it's a $attr type subject rule */
  3625. matched_val = NULL;
  3626. } else {
  3627. /*
  3628. * Look up the matched_val value calculated
  3629. * from the target and stored judiciously there for us.
  3630. */
  3631. if ( (matched_val = (char *)acl_ht_lookup( aclpb->aclpb_macro_ht,
  3632. (PLHashNumber)aci->aci_index)) == NULL) {
  3633. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  3634. "ACL info: failed to locate the calculated target"
  3635. "macro for aci '%s' index '%d'\n",
  3636. aci->aclName, aci->aci_index );
  3637. return(ACL_FALSE); /* Not a match */
  3638. } else {
  3639. slapi_log_error(SLAPI_LOG_ACL, plugin_name,
  3640. "ACL info: found matched_val (%s) for aci index %d"
  3641. "in macro ht\n",
  3642. aci->aclName, aci->aci_index );
  3643. }
  3644. }
  3645. /*
  3646. * Now, make a candidate
  3647. * list of strings to match against the client.
  3648. * This involves replacing ($dn) or [$dn] by either the matched
  3649. * value, or all the suffix substrings of matched_val.
  3650. * If there is no $dn then the candidate list is just
  3651. * user itself.
  3652. *
  3653. */
  3654. candidate_list = acllas_replace_dn_macro( rule, matched_val, lasinfo);
  3655. sptr= candidate_list;
  3656. while( *sptr != NULL && !matched) {
  3657. s = *sptr;
  3658. /*
  3659. * Now s may contain some $attr macros.
  3660. * So, make a candidate list, got by replacing each occurence
  3661. * of $attr with all the values that attribute has in
  3662. * the resource entry.
  3663. */
  3664. inner_list = acllas_replace_attr_macro( s, lasinfo);
  3665. tptr = inner_list;
  3666. while( tptr && *tptr != NULL && (matched != ACL_TRUE) ){
  3667. t = *tptr;
  3668. /*
  3669. * Now, at last t is a candidate string we can
  3670. * match agains the client.
  3671. *
  3672. * $dn and $attr can appear in userdn, graoupdn and roledn
  3673. * rules, so we we need to decide which type we
  3674. * currently evaluating and evaluate that.
  3675. *
  3676. * If the string generated was undefined, eg it contained
  3677. * ($attr.ou) and the entry did not have an ou attribute,then
  3678. * the empty string is returned for this. So it we find
  3679. * an empty string in the list, skip it--it does not match.
  3680. */
  3681. if ( *t != '\0') {
  3682. if ( evalType == ACL_EVAL_USER ) {
  3683. matched = acllas_eval_one_user( lasinfo->aclpb,
  3684. lasinfo->clientDn, t);
  3685. } else if (evalType == ACL_EVAL_GROUP) {
  3686. matched = acllas_eval_one_group(t, lasinfo);
  3687. } else if (evalType == ACL_EVAL_ROLE) {
  3688. matched = acllas_eval_one_role(t, lasinfo);
  3689. } else if (evalType == ACL_EVAL_GROUPDNATTR) {
  3690. matched = acllas__eval_memberGroupDnAttr(t,
  3691. lasinfo->resourceEntry,
  3692. lasinfo->clientDn,
  3693. lasinfo->aclpb);
  3694. } else if ( evalType == ACL_EVAL_TARGET_FILTER) {
  3695. matched = acllas_eval_one_target_filter(t,
  3696. lasinfo->resourceEntry);
  3697. }
  3698. }
  3699. tptr++;
  3700. }/*inner while*/
  3701. charray_free(inner_list);
  3702. sptr++;
  3703. }/* outer while */
  3704. charray_free(candidate_list);
  3705. return(matched);
  3706. }
  3707. /*
  3708. * Here, replace the first occurrence of $(dn) with matched_val.
  3709. * replace any occurrence of $[dn] with each of the suffix substrings
  3710. * of matched_val.
  3711. * Each of these strings is returned in a NULL terminated list of strings.
  3712. *
  3713. * If there is no $dn thing then the returned list just contains rule itself.
  3714. *
  3715. * eg. rule: cn=fred,ou=*, ($dn), o=sun.com
  3716. * matched_val: ou=People,o=icnc
  3717. *
  3718. * Then we return the list
  3719. * cn=fred,ou=*,ou=People,o=icnc,o=sun.com NULL
  3720. *
  3721. * eg. rule: cn=fred,ou=*,[$dn], o=sun.com
  3722. * matched_val: ou=People,o=icnc
  3723. *
  3724. * Then we return the list
  3725. * cn=fred,ou=*,ou=People,o=icnc,o=sun.com
  3726. * cn=fred,ou=*,o=icnc,o=sun.com
  3727. * NULL
  3728. *
  3729. *
  3730. */
  3731. static char **
  3732. acllas_replace_dn_macro( char *rule, char *matched_val, lasInfo *lasinfo) {
  3733. char **a = NULL;
  3734. char *patched_rule = NULL;
  3735. char *rule_to_use = NULL;
  3736. char *new_patched_rule = NULL;
  3737. int matched_val_len = 0;
  3738. int j = 0;
  3739. int has_macro_dn = 0;
  3740. int has_macro_levels = 0;
  3741. /* Determine what the rule's got once */
  3742. if ( PL_strcasestr(rule, ACL_RULE_MACRO_DN_KEY) != NULL) {
  3743. /* ($dn) exists */
  3744. has_macro_dn = 1;
  3745. }
  3746. if ( PL_strcasestr(rule, ACL_RULE_MACRO_DN_LEVELS_KEY) != NULL) {
  3747. /* [$dn] exists */
  3748. has_macro_levels = 1;
  3749. }
  3750. if ( (!has_macro_dn && !has_macro_levels) || !matched_val ) { /* No ($dn) and no [$dn] ... */
  3751. /* ... or no value to replace */
  3752. /*
  3753. * No $dn thing, just return a list with two elements, rule and NULL.
  3754. * charray_add will create the list and null terminate it.
  3755. */
  3756. charray_add( &a, slapi_ch_strdup(rule));
  3757. return(a);
  3758. } else {
  3759. /*
  3760. * Have an occurrence of the macro rules
  3761. *
  3762. * First, replace all occurrencers of ($dn) with the matched_val
  3763. */
  3764. if ( has_macro_dn) {
  3765. patched_rule =
  3766. acl_replace_str(rule, ACL_RULE_MACRO_DN_KEY, matched_val);
  3767. }
  3768. /* If there are no [$dn] we're done */
  3769. if ( !has_macro_levels ) {
  3770. charray_add( &a, patched_rule);
  3771. return(a);
  3772. } else {
  3773. /*
  3774. * It's a [$dn] type, so walk matched_val, splicing in all
  3775. * the suffix substrings and adding each such string to
  3776. * to the returned list.
  3777. * get_next_component() does not return the commas--the
  3778. * prefix and suffix should come with their commas.
  3779. *
  3780. * All occurrences of each [$dn] are replaced with each level.
  3781. *
  3782. * If has_macro_dn then patched_rule is the rule to strart with,
  3783. * and this needs to be freed at the end, otherwise
  3784. * just use rule.
  3785. */
  3786. if (patched_rule) {
  3787. rule_to_use = patched_rule;
  3788. } else {
  3789. rule_to_use = rule;
  3790. }
  3791. matched_val_len = strlen(matched_val);
  3792. j = 0;
  3793. while( j < matched_val_len) {
  3794. new_patched_rule =
  3795. acl_replace_str(rule_to_use, ACL_RULE_MACRO_DN_LEVELS_KEY,
  3796. &matched_val[j]);
  3797. charray_add( &a, new_patched_rule);
  3798. j += acl_find_comp_end(&matched_val[j]);
  3799. }
  3800. if (patched_rule) {
  3801. slapi_ch_free((void**)&patched_rule);
  3802. }
  3803. return(a);
  3804. }
  3805. }
  3806. }
  3807. /*
  3808. * Here, replace any occurrence of $attr.attrname with the
  3809. * value of attrname from lasinfo->resourceEntry.
  3810. *
  3811. *
  3812. * If there is no $attr thing then the returned list just contains rule
  3813. * itself.
  3814. *
  3815. * eg. rule: cn=fred,ou=*,ou=$attr.ou,o=sun.com
  3816. * ou: People
  3817. * ou: icnc
  3818. *
  3819. * Then we return the list
  3820. * cn=fred,ou=*,ou=People,o=sun.com
  3821. * cn=fred,ou=*,ou=icnc,o=sun.com
  3822. *
  3823. */
  3824. static char **
  3825. acllas_replace_attr_macro( char *rule, lasInfo *lasinfo)
  3826. {
  3827. char **a = NULL;
  3828. char **working_list = NULL;
  3829. Slapi_Entry *e = lasinfo->resourceEntry;
  3830. char *str, *working_rule;
  3831. char *macro_str, *macro_attr_name;
  3832. int l;
  3833. Slapi_Attr *attr = NULL;
  3834. str = PL_strcasestr(rule, ACL_RULE_MACRO_ATTR_KEY);
  3835. if ( str == NULL ) {
  3836. charray_add(&a, slapi_ch_strdup(rule));
  3837. return(a);
  3838. } else {
  3839. working_rule = slapi_ch_strdup(rule);
  3840. str = PL_strcasestr(working_rule, ACL_RULE_MACRO_ATTR_KEY);
  3841. charray_add(&working_list, working_rule );
  3842. while( str != NULL) {
  3843. /*
  3844. * working_rule is the first member of working_list.
  3845. * str points to the next $attr.attrName in working_rule.
  3846. * each member of working_list needs to have each occurence of
  3847. * $attr.atrName replaced with the value of attrName in e.
  3848. * If attrName is multi valued then this generates another
  3849. * list which replaces the old one.
  3850. */
  3851. l = acl_strstr(&str[0], ")");
  3852. macro_str = slapi_ch_malloc(l+2);
  3853. strncpy( macro_str, &str[0], l+1);
  3854. macro_str[l+1] = '\0';
  3855. str = strstr(macro_str, ".");
  3856. if (!str) {
  3857. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  3858. "acllas_replace_attr_macro: Invalid macro \"%s\".",
  3859. macro_str);
  3860. slapi_ch_free_string(&macro_str);
  3861. charray_free(working_list);
  3862. return NULL;
  3863. }
  3864. str++; /* skip the . */
  3865. l = acl_strstr(&str[0], ")");
  3866. macro_attr_name = slapi_ch_malloc(l+1);
  3867. strncpy( macro_attr_name, &str[0], l);
  3868. macro_attr_name[l] = '\0';
  3869. slapi_entry_attr_find ( e, macro_attr_name, &attr );
  3870. if ( NULL == attr ) {
  3871. /*
  3872. * Here, if a $attr.attrName is such that the attrName
  3873. * does not occur in the entry then return a ""--
  3874. * this will go back to the matching code in
  3875. * aclutil_evaluate_macro() where "" will
  3876. * be taken as the candidate.
  3877. */
  3878. slapi_ch_free_string(&macro_str);
  3879. slapi_ch_free_string(&macro_attr_name);
  3880. charray_free(working_list);
  3881. return NULL;
  3882. } else{
  3883. const struct berval *attrValue;
  3884. Slapi_Value *sval;
  3885. int i, j;
  3886. char *patched_rule;
  3887. i= slapi_attr_first_value ( attr, &sval );
  3888. while(i != -1) {
  3889. attrValue = slapi_value_get_berval(sval);
  3890. j = 0;
  3891. while( working_list[j] != NULL) {
  3892. patched_rule =
  3893. acl_replace_str(working_list[j],
  3894. macro_str, attrValue->bv_val);
  3895. charray_add(&a, patched_rule);
  3896. j++;
  3897. }
  3898. i= slapi_attr_next_value( attr, i, &sval );
  3899. }/* while */
  3900. /*
  3901. * Here, a is working_list, where each member has had
  3902. * macro_str replaced with attrVal. We hand a over,
  3903. * so we must set it to NULL since the working list
  3904. * may be free'd later. */
  3905. charray_free(working_list);
  3906. if (a == NULL) {
  3907. /* This shouldn't happen, but we play
  3908. * if safe to avoid any problems. */
  3909. slapi_ch_free_string(&macro_str);
  3910. slapi_ch_free_string(&macro_attr_name);
  3911. charray_add(&a, slapi_ch_strdup(""));
  3912. return(a);
  3913. } else {
  3914. working_list = a;
  3915. working_rule = a[0];
  3916. a = NULL;
  3917. }
  3918. }
  3919. slapi_ch_free_string(&macro_str);
  3920. slapi_ch_free_string(&macro_attr_name);
  3921. str = PL_strcasestr(working_rule, ACL_RULE_MACRO_ATTR_KEY);
  3922. }/* while */
  3923. return(working_list);
  3924. }
  3925. }
  3926. /*
  3927. * returns ACL_TRUE, ACL_FALSE or ACL_DONT_KNOW.
  3928. *
  3929. * user is a string from the userdn keyword which may contain
  3930. * * components. This routine does the compare component by component, so
  3931. * that * behaves differently to "normal".
  3932. * Any ($dn) or $attr must have been removed from user before this is called.
  3933. */
  3934. static int
  3935. acllas_eval_one_user( struct acl_pblock *aclpb, char * clientDN, char *rule) {
  3936. int exact_match = 0;
  3937. const size_t LDAP_URL_prefix_len = strlen(LDAP_URL_prefix);
  3938. /* URL format */
  3939. if (strchr (rule, '?') != NULL) {
  3940. /* URL format */
  3941. if (acllas__client_match_URL ( aclpb, clientDN,
  3942. rule) == ACL_TRUE) {
  3943. exact_match = 1;
  3944. }
  3945. } else if ( strstr(rule, "=*") == NULL ) {
  3946. /* Just a straight compare */
  3947. /* skip the ldap:/// part */
  3948. rule += LDAP_URL_prefix_len;
  3949. exact_match = !slapi_utf8casecmp((ACLUCHP)clientDN,
  3950. (ACLUCHP)rule);
  3951. } else{
  3952. /* Here, contains a =*, so need to match comp by comp */
  3953. /* skip the ldap:/// part */
  3954. rule += LDAP_URL_prefix_len;
  3955. acl_match_prefix( rule, clientDN, &exact_match);
  3956. }
  3957. if ( exact_match) {
  3958. return( ACL_TRUE);
  3959. } else {
  3960. return(ACL_FALSE);
  3961. }
  3962. }
  3963. /*
  3964. * returns ACL_TRUE, ACL_FALSE and ACL_DONT_KNOW.
  3965. *
  3966. * The user string has had all ($dn) and $attr replaced
  3967. * so the only dodgy thing left is a *.
  3968. *
  3969. * If * appears in such a user string, then it matches only that
  3970. * component, not .*, like it would otherwise.
  3971. *
  3972. */
  3973. static int
  3974. acllas_eval_one_group(char *groupbuf, lasInfo *lasinfo) {
  3975. if (groupbuf) {
  3976. return( acllas__user_ismember_of_group (
  3977. lasinfo->aclpb,
  3978. groupbuf,
  3979. lasinfo->clientDn,
  3980. ACLLAS_CACHE_ALL_GROUPS,
  3981. lasinfo->aclpb->aclpb_clientcert
  3982. ));
  3983. } else {
  3984. return(ACL_FALSE); /* not in the empty group */
  3985. }
  3986. }
  3987. /*
  3988. * returns ACL_TRUE for match, ACL_FALSE for not a match, ACL_DONT_KNOW otherwise.
  3989. */
  3990. static int
  3991. acllas_eval_one_role(char *role, lasInfo *lasinfo) {
  3992. Slapi_DN *roleDN = NULL;
  3993. int rc = ACL_FALSE;
  3994. char ebuf [ BUFSIZ ];
  3995. /*
  3996. * See if lasinfo.clientDn has role rolebuf.
  3997. * Here we know it's not an anom user nor
  3998. * a an anyone user--the client dn must be matched against
  3999. * a real role.
  4000. */
  4001. roleDN = slapi_sdn_new_dn_byval(role);
  4002. if (role) {
  4003. rc = acllas__user_has_role(
  4004. lasinfo->aclpb,
  4005. roleDN,
  4006. lasinfo->aclpb->aclpb_authorization_sdn);
  4007. } else { /* The user does not have the empty role */
  4008. rc = ACL_FALSE;
  4009. }
  4010. slapi_sdn_free(&roleDN );
  4011. /* Some useful logging */
  4012. if (rc == ACL_TRUE ) {
  4013. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  4014. "role evaluation: user '%s' does have role '%s'\n",
  4015. ACL_ESCAPE_STRING_WITH_PUNCTUATION (lasinfo->clientDn, ebuf),
  4016. role);
  4017. } else {
  4018. slapi_log_error( SLAPI_LOG_ACL, plugin_name,
  4019. "role evaluation: user '%s' does NOT have role '%s'\n",
  4020. ACL_ESCAPE_STRING_WITH_PUNCTUATION (lasinfo->clientDn, ebuf),
  4021. role);
  4022. }
  4023. return(rc);
  4024. }
  4025. /*
  4026. * returns ACL_TRUE if e matches the filter str, ACL_FALSE if not,
  4027. * ACL_DONT_KNOW otherwise.
  4028. */
  4029. static int acllas_eval_one_target_filter( char * str, Slapi_Entry *e) {
  4030. int rc = ACL_FALSE;
  4031. Slapi_Filter *f = NULL;
  4032. PR_ASSERT(str);
  4033. if ((f = slapi_str2filter(str)) == NULL) {
  4034. slapi_log_error(SLAPI_LOG_FATAL, plugin_name,
  4035. "Warning: Bad targetfilter(%s) in aci: does not match\n", str);
  4036. return(ACL_DONT_KNOW);
  4037. }
  4038. if (slapi_vattr_filter_test(NULL, e, f, 0 /*don't do acess chk*/)!= 0) {
  4039. rc = ACL_FALSE; /* Filter does not match */
  4040. } else {
  4041. rc = ACL_TRUE; /* filter does match */
  4042. }
  4043. slapi_filter_free(f, 1);
  4044. return(rc);
  4045. }
  4046. /***************************************************************************/
  4047. /* E N D */
  4048. /***************************************************************************/