acllas.c 133 KB

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