slapi-plugin.h 285 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604
  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) 2009 Red Hat, Inc.
  36. * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
  37. * All rights reserved.
  38. *
  39. * Contributors:
  40. * Hewlett-Packard Development Company, L.P.
  41. * Bugfix for bug #195302
  42. *
  43. * END COPYRIGHT BLOCK */
  44. /*! \file slapi-plugin.h
  45. * \brief Public Directory Server plugin interface.
  46. *
  47. * The SLAPI plugin interface allows complex plugins to be created
  48. * for Directory Server.
  49. */
  50. #ifndef _SLAPIPLUGIN
  51. #define _SLAPIPLUGIN
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. #include "prtypes.h"
  56. #include "ldap.h"
  57. #include "prprf.h"
  58. #include "nspr.h"
  59. NSPR_API(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt, ...)
  60. #ifdef __GNUC__
  61. __attribute__ ((format (printf, 3, 4)));
  62. #else
  63. ;
  64. #endif
  65. NSPR_API(char*) PR_smprintf(const char *fmt, ...)
  66. #ifdef __GNUC__
  67. __attribute__ ((format (printf, 1, 2)));
  68. #else
  69. ;
  70. #endif
  71. NSPR_API(char*) PR_sprintf_append(char *last, const char *fmt, ...)
  72. #ifdef __GNUC__
  73. __attribute__ ((format (printf, 2, 3)));
  74. #else
  75. ;
  76. #endif
  77. NSPR_API(PRUint32) PR_fprintf(struct PRFileDesc* fd, const char *fmt, ...)
  78. #ifdef __GNUC__
  79. __attribute__ ((format (printf, 2, 3)));
  80. #else
  81. ;
  82. #endif
  83. /* NSPR uses the print macros a bit differently than ANSI C. We
  84. * need to use ll for a 64-bit integer, even when a long is 64-bit.
  85. */
  86. #define NSPRIu64 "llu"
  87. #define NSPRI64 "ll"
  88. /* OpenLDAP uses unsigned long for ber_tag_t and ber_len_t but mozldap uses unsigned int */
  89. /* use this macro for printf statements for ber_tag_t and ber_len_t */
  90. #if defined(USE_OPENLDAP)
  91. #define BERTAG_T "lu"
  92. #define BERLEN_T "lu"
  93. #else
  94. #define BERTAG_T "u"
  95. #define BERLEN_T "u"
  96. #endif
  97. #define DEFINETOSTR(xxx) #xxx
  98. #define STRINGIFYDEFINE(xxx) DEFINETOSTR(xxx)
  99. /* Common check on berval before accessing the contents. */
  100. /* bv is a struct berval *bv */
  101. #define BV_HAS_DATA(bv) ((bv != NULL) && (bv->bv_len > 0) && (bv->bv_val != NULL))
  102. /*
  103. * The slapi_attr_get_flags() routine returns a bitmap that contains one or
  104. * more of these values.
  105. *
  106. * Note that the flag values 0x0010, 0x0020, 0x4000, and 0x8000 are reserved.
  107. */
  108. /**
  109. * Flag indicating that an attribtue is single-valued.
  110. *
  111. * \see slapi_attr_flag_is_set()
  112. * \see slapi_attr_set_flags()
  113. */
  114. #define SLAPI_ATTR_FLAG_SINGLE 0x0001 /* single-valued attribute */
  115. /**
  116. * Flag indicating than an attribute is operational.
  117. *
  118. * \see slapi_attr_flag_is_set()
  119. * \see slapi_attr_set_flags()
  120. */
  121. #define SLAPI_ATTR_FLAG_OPATTR 0x0002 /* operational attribute */
  122. /**
  123. * Flag indicating than an attribute is read-only.
  124. *
  125. * \see slapi_attr_flag_is_set()
  126. * \see slapi_attr_set_flags()
  127. */
  128. #define SLAPI_ATTR_FLAG_READONLY 0x0004 /* read from shipped config file */
  129. /**
  130. * Flag indicating than an attribute is read-only.
  131. *
  132. * This is an alias for #SLAPI_ATTR_FLAG_READONLY.
  133. * \see slapi_attr_flag_is_set()
  134. * \see slapi_attr_set_flags()
  135. */
  136. #define SLAPI_ATTR_FLAG_STD_ATTR SLAPI_ATTR_FLAG_READONLY /* alias for read only */
  137. /**
  138. * Flag indicating than an attribute is obsolete.
  139. *
  140. * \see slapi_attr_flag_is_set()
  141. * \see slapi_attr_set_flags()
  142. */
  143. #define SLAPI_ATTR_FLAG_OBSOLETE 0x0040 /* an outdated definition */
  144. /**
  145. * Flag indicating that an attribute is collective.
  146. *
  147. * \warning Collective attributes are not supported, so this
  148. * flag has no effect.
  149. * \see slapi_attr_flag_is_set()
  150. * \see slapi_attr_set_flags()
  151. */
  152. #define SLAPI_ATTR_FLAG_COLLECTIVE 0x0080 /* collective (not supported) */
  153. /**
  154. * Flag indicating that an attribute is not modifiable over LDAP.
  155. *
  156. * \see slapi_attr_flag_is_set()
  157. * \see slapi_attr_set_flags()
  158. */
  159. #define SLAPI_ATTR_FLAG_NOUSERMOD 0x0100 /* can't be modified over LDAP */
  160. /**
  161. * Flag to indicate that the attribute value is normalized.
  162. *
  163. * \see slapi_value_set_flags()
  164. * \see slapi_values_set_flags()
  165. */
  166. /* the attr value is normalized */
  167. #define SLAPI_ATTR_FLAG_NORMALIZED \
  168. (SLAPI_ATTR_FLAG_NORMALIZED_CES|SLAPI_ATTR_FLAG_NORMALIZED_CIS)
  169. #define SLAPI_ATTR_FLAG_NORMALIZED_CES 0x0200 /* the attr value is normalized,
  170. but not case-normalized.
  171. Used for DN. */
  172. #define SLAPI_ATTR_FLAG_NORMALIZED_CIS 0x0400 /* the attr value is normalized
  173. including case.
  174. Used for DN. */
  175. /**
  176. * Flag to indicate that the attribute value is not exposed if specified.
  177. *
  178. * \see slapi_value_set_flags()
  179. * \see slapi_values_set_flags()
  180. */
  181. #define SLAPI_ATTR_FLAG_NOEXPOSE 0x0800 /* the attr value is not exposed */
  182. /* operation flags */
  183. #define SLAPI_OP_FLAG_INTERNAL 0x00020 /* An operation generated by the core server or a plugin. */
  184. #define SLAPI_OP_FLAG_NEVER_CHAIN 0x00800 /* Do not chain the operation */
  185. #define SLAPI_OP_FLAG_NO_ACCESS_CHECK 0x10000 /* Do not check for access control - bypass them */
  186. #define SLAPI_OP_FLAG_BYPASS_REFERRALS 0x40000 /* Useful for performing internal operations on read-only replica */
  187. #define SLAPI_OC_FLAG_REQUIRED 0x0001
  188. #define SLAPI_OC_FLAG_ALLOWED 0x0002
  189. /*
  190. * access control levels
  191. */
  192. #define SLAPI_ACL_COMPARE 0x01
  193. #define SLAPI_ACL_SEARCH 0x02
  194. #define SLAPI_ACL_READ 0x04
  195. #define SLAPI_ACL_WRITE 0x08
  196. #define SLAPI_ACL_DELETE 0x10
  197. #define SLAPI_ACL_ADD 0x20
  198. #define SLAPI_ACL_SELF 0x40
  199. #define SLAPI_ACL_PROXY 0x80
  200. #define SLAPI_ACL_ALL 0x7f
  201. /*
  202. * filter types
  203. * openldap defines these, but not mozldap
  204. */
  205. #ifndef LDAP_FILTER_AND
  206. #define LDAP_FILTER_AND 0xa0L
  207. #endif
  208. #ifndef LDAP_FILTER_OR
  209. #define LDAP_FILTER_OR 0xa1L
  210. #endif
  211. #ifndef LDAP_FILTER_NOT
  212. #define LDAP_FILTER_NOT 0xa2L
  213. #endif
  214. #ifndef LDAP_FILTER_EQUALITY
  215. #define LDAP_FILTER_EQUALITY 0xa3L
  216. #endif
  217. #ifndef LDAP_FILTER_SUBSTRINGS
  218. #define LDAP_FILTER_SUBSTRINGS 0xa4L
  219. #endif
  220. #ifndef LDAP_FILTER_GE
  221. #define LDAP_FILTER_GE 0xa5L
  222. #endif
  223. #ifndef LDAP_FILTER_LE
  224. #define LDAP_FILTER_LE 0xa6L
  225. #endif
  226. #ifndef LDAP_FILTER_PRESENT
  227. #define LDAP_FILTER_PRESENT 0x87L
  228. #endif
  229. #ifndef LDAP_FILTER_APPROX
  230. #define LDAP_FILTER_APPROX 0xa8L
  231. #endif
  232. #ifndef LDAP_FILTER_EXTENDED
  233. #ifdef LDAP_FILTER_EXT
  234. #define LDAP_FILTER_EXTENDED LDAP_FILTER_EXT
  235. #else
  236. #define LDAP_FILTER_EXTENDED 0xa9L
  237. #endif
  238. #endif
  239. #ifndef LBER_END_OF_SEQORSET
  240. #define LBER_END_OF_SEQORSET ((ber_tag_t) -2) /* 0xfffffffeU */
  241. #endif
  242. #ifndef LDAP_CHANGETYPE_ADD
  243. #ifdef LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_ADD
  244. #define LDAP_CHANGETYPE_ADD LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_ADD
  245. #else
  246. #define LDAP_CHANGETYPE_ADD 1
  247. #endif
  248. #endif
  249. #ifndef LDAP_CHANGETYPE_DELETE
  250. #ifdef LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_DELETE
  251. #define LDAP_CHANGETYPE_DELETE LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_DELETE
  252. #else
  253. #define LDAP_CHANGETYPE_DELETE 2
  254. #endif
  255. #endif
  256. #ifndef LDAP_CHANGETYPE_MODIFY
  257. #ifdef LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_MODIFY
  258. #define LDAP_CHANGETYPE_MODIFY LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_MODIFY
  259. #else
  260. #define LDAP_CHANGETYPE_MODIFY 4
  261. #endif
  262. #endif
  263. #ifndef LDAP_CHANGETYPE_MODDN
  264. #ifdef LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_RENAME
  265. #define LDAP_CHANGETYPE_MODDN LDAP_CONTROL_PERSSIT_ENTRY_CHANGE_RENAME
  266. #else
  267. #define LDAP_CHANGETYPE_MODDN 8
  268. #endif
  269. #endif
  270. #ifndef LDAP_CHANGETYPE_ANY
  271. #define LDAP_CHANGETYPE_ANY (1|2|4|8)
  272. #endif
  273. #ifndef LDAP_CONTROL_PERSISTENTSEARCH
  274. #ifdef LDAP_CONTROL_PERSIST_REQUEST
  275. #define LDAP_CONTROL_PERSISTENTSEARCH LDAP_CONTROL_PERSIST_REQUEST
  276. #else
  277. #define LDAP_CONTROL_PERSISTENTSEARCH "2.16.840.1.113730.3.4.3"
  278. #endif
  279. #endif
  280. #ifndef LDAP_CONTROL_ENTRYCHANGE
  281. #ifdef LDAP_CONTROL_PERSIST_ENTRY_CHANGE_NOTICE
  282. #define LDAP_CONTROL_ENTRYCHANGE LDAP_CONTROL_PERSIST_ENTRY_CHANGE_NOTICE
  283. #else
  284. #define LDAP_CONTROL_ENTRYCHANGE "2.16.840.1.113730.3.4.7"
  285. #endif
  286. #endif
  287. #ifndef LDAP_CONTROL_PWEXPIRED
  288. #define LDAP_CONTROL_PWEXPIRED "2.16.840.1.113730.3.4.4"
  289. #endif
  290. #ifndef LDAP_CONTROL_PWEXPIRING
  291. #define LDAP_CONTROL_PWEXPIRING "2.16.840.1.113730.3.4.5"
  292. #endif
  293. #ifndef LDAP_X_CONTROL_PWPOLICY_REQUEST
  294. #ifdef LDAP_CONTROL_PASSWORDPOLICYREQUEST
  295. #define LDAP_X_CONTROL_PWPOLICY_REQUEST LDAP_CONTROL_PASSWORDPOLICYREQUEST
  296. #else
  297. #define LDAP_X_CONTROL_PWPOLICY_REQUEST "1.3.6.1.4.1.42.2.27.8.5.1"
  298. #endif
  299. #endif
  300. #ifndef LDAP_X_CONTROL_PWPOLICY_RESPONSE
  301. #ifdef LDAP_CONTROL_PASSWORDPOLICYRESPONSE
  302. #define LDAP_X_CONTROL_PWPOLICY_RESPONSE LDAP_CONTROL_PASSWORDPOLICYRESPONSE
  303. #else
  304. #define LDAP_X_CONTROL_PWPOLICY_RESPONSE "1.3.6.1.4.1.42.2.27.8.5.1"
  305. #endif
  306. #endif
  307. #ifndef LDAP_CONTROL_PROXYAUTH
  308. #define LDAP_CONTROL_PROXYAUTH "2.16.840.1.113730.3.4.12" /* version 1 */
  309. #endif
  310. #ifndef LDAP_CONTROL_PROXIEDAUTH
  311. #ifdef LDAP_CONTROL_PROXY_AUTHZ
  312. #define LDAP_CONTROL_PROXIEDAUTH LDAP_CONTROL_PROXY_AUTHZ
  313. #else
  314. #define LDAP_CONTROL_PROXIEDAUTH "2.16.840.1.113730.3.4.18" /* version 2 */
  315. #endif
  316. #endif
  317. #ifndef LDAP_CONTROL_AUTH_REQUEST
  318. #define LDAP_CONTROL_AUTH_REQUEST "2.16.840.1.113730.3.4.16"
  319. #endif
  320. /* Read Entry Controls - PRE & POST */
  321. #ifndef LDAP_CONTROL_PRE_READ_ENTRY
  322. #define LDAP_CONTROL_PRE_READ_ENTRY "1.3.6.1.1.13.1"
  323. #endif
  324. #ifndef LDAP_CONTROL_POST_READ_ENTRY
  325. #define LDAP_CONTROL_POST_READ_ENTRY "1.3.6.1.1.13.2"
  326. #endif
  327. #ifndef LDAP_SORT_CONTROL_MISSING
  328. #define LDAP_SORT_CONTROL_MISSING 0x3C /* 60 (server side sort extn) */
  329. #endif
  330. #ifndef LDAP_INDEX_RANGE_ERROR
  331. #define LDAP_INDEX_RANGE_ERROR 0x3D /* 61 (VLV extn) */
  332. #endif
  333. /* openldap does not use this */
  334. #ifndef LBER_OVERFLOW
  335. #define LBER_OVERFLOW ((ber_tag_t) -3) /* 0xfffffffdU */
  336. #endif
  337. #ifndef LDAP_MAXINT
  338. /* RFC 4511: maxInt INTEGER ::= 2147483647 -- (2^^31 - 1) -- */
  339. #define LDAP_MAXINT (2147483647)
  340. #endif
  341. /*
  342. * Sequential access types
  343. */
  344. #define SLAPI_SEQ_FIRST 1
  345. #define SLAPI_SEQ_LAST 2
  346. #define SLAPI_SEQ_PREV 3
  347. #define SLAPI_SEQ_NEXT 4
  348. /*
  349. * return codes from a backend API call
  350. */
  351. #define SLAPI_FAIL_GENERAL -1
  352. #define SLAPI_FAIL_DISKFULL -2
  353. /*
  354. * return codes used by BIND functions
  355. */
  356. #define SLAPI_BIND_SUCCESS 0 /* front end will send result */
  357. #define SLAPI_BIND_FAIL 2 /* back end should send result */
  358. #define SLAPI_BIND_ANONYMOUS 3 /* front end will send result */
  359. /* commonly used attributes names */
  360. #define SLAPI_ATTR_UNIQUEID "nsuniqueid"
  361. #define SLAPI_ATTR_OBJECTCLASS "objectclass"
  362. #define SLAPI_ATTR_VALUE_TOMBSTONE "nsTombstone"
  363. #define SLAPI_ATTR_VALUE_PARENT_UNIQUEID "nsParentUniqueID"
  364. #define SLAPI_ATTR_NSCP_ENTRYDN "nscpEntryDN"
  365. #define SLAPI_ATTR_ENTRYUSN "entryusn"
  366. #define SLAPI_ATTR_ENTRYDN "entrydn"
  367. /* opaque structures */
  368. /**
  369. * Contains name-value pairs, known as parameter blocks, that you can get or set for
  370. * each LDAP operation.
  371. *
  372. * #Slapi_PBlock contains name-value pairs that you can use to retrieve information
  373. * from the server and set information to be used by the server.
  374. *
  375. * For most types of plug-in functions, the server passes in a #Slapi_PBlock
  376. * structure that typically includes data relevant to the operation being processed.
  377. * You can get the value of a parameter by calling the slapi_pblock_get() function.
  378. *
  379. * For example, when the plug-in function for an LDAP bind operation is called, the
  380. * server puts the DN and credentials in the #SLAPI_BIND_TARGET and
  381. * #SLAPI_BIND_CREDENTIALS parameters of the Slapi_PBlock structure. You can
  382. * call slapi_pblock_get() to get the DN and credentials of the client requesting
  383. * authentication.
  384. *
  385. * For plug-in initialization functions, you can use the #Slapi_PBlock structure to
  386. * pass information to the server, such as the description of your plug-in and the
  387. * names of your plug-in functions. You can set the value of a parameter by calling
  388. * the slapi_pblock_set() function.
  389. *
  390. * For example, in order to register a pre-operation bind plug-in function, you need to
  391. * call slapi_pblock_set() to set the version number, description, and name of the
  392. * plug-in function as the #SLAPI_PLUGIN_VERSION, #SLAPI_PLUGIN_DESCRIPTION,
  393. * and #SLAPI_PLUGIN_PRE_BIND_FN parameters.
  394. *
  395. * The available parameters that you can use depends on the type of plug-in function
  396. * you are writing.
  397. */
  398. typedef struct slapi_pblock Slapi_PBlock;
  399. /**
  400. * Represents an entry in the directory.
  401. *
  402. * #Slapi_Entry is the data type for an opaque structure that represents an entry in
  403. * the directory. In certain cases, your server plug-in may need to work with an entry
  404. * in the directory.
  405. */
  406. typedef struct slapi_entry Slapi_Entry;
  407. /**
  408. * Represents an attribute in an entry.
  409. *
  410. * #Slapi_Attr is the data type for an opaque structure that represents an attribute
  411. * in a directory entry. In certain cases, your server plug-in may need to work with
  412. * an entry’s attributes.
  413. */
  414. typedef struct slapi_attr Slapi_Attr;
  415. /**
  416. * Represents the value of the attribute in a directory entry.
  417. *
  418. * #Slapi_Value is the data type for an opaque structure that represents the value of
  419. * an attribute in a directory entry.
  420. */
  421. typedef struct slapi_value Slapi_Value;
  422. /**
  423. * Represents a set of Slapi_Value (or a list of Slapi_Value).
  424. *
  425. * #Slapi_ValueSet is the data type for an opaque structure that represents set of
  426. * #Slapi_Value (or a list of #Slapi_Value).
  427. */
  428. typedef struct slapi_value_set Slapi_ValueSet;
  429. /**
  430. * Represents a search filter.
  431. *
  432. * #Slapi_Filter is the data type for an opaque structure that represents an search
  433. * filter.
  434. */
  435. typedef struct slapi_filter Slapi_Filter;
  436. /**
  437. * Represents a backend operation in the server plug-in.
  438. *
  439. * #Slapi_Backend is the data type for an opaque structure that represents a backend
  440. * operation.
  441. */
  442. typedef struct backend Slapi_Backend;
  443. /**
  444. * Represents the unique identifier of a directory entry.
  445. *
  446. * #Slapi_UniqueID is the data type for an opaque structure that represents the
  447. * unique identifier of a directory entry. All directory entries contain a unique
  448. * identifier. Unlike the distinguished name (DN), the unique identifier of an entry
  449. * never changes, providing a good way to refer unambiguously to an entry in a
  450. * distributed/replicated environment.
  451. */
  452. typedef struct _guid_t Slapi_UniqueID;
  453. /**
  454. * Represents an operation pending from an LDAP client.
  455. *
  456. * #Slapi_Operation is the data type for an opaque structure that represents an
  457. * operation pending from an LDAP client.
  458. */
  459. typedef struct op Slapi_Operation;
  460. /**
  461. * Represents a connection.
  462. *
  463. * #Slapi_Connection is the data type for an opaque structure that represents a
  464. * connection.
  465. */
  466. typedef struct conn Slapi_Connection;
  467. /**
  468. * Represents a distinguished name in a directory entry.
  469. *
  470. * #Slapi_DN is the data type for an opaque structure that represents a distinguished
  471. * name in the server plug-in.
  472. */
  473. typedef struct slapi_dn Slapi_DN;
  474. /**
  475. * Represents a relative distinguished name in a directory entry.
  476. *
  477. * #Slapi_RDN is the data type for an opaque structure that represents a relative
  478. * distinguished name in the server plug-in.
  479. */
  480. typedef struct slapi_rdn Slapi_RDN;
  481. /**
  482. * Represents a single LDAP modification to a directory entry.
  483. *
  484. * #Slapi_Mod is the data type for an opaque structure that represents LDAPMod
  485. * modifications to an attribute in a directory entry.
  486. */
  487. typedef struct slapi_mod Slapi_Mod;
  488. /**
  489. * Represents two or more LDAP modifications to a directory entry
  490. *
  491. * #Slapi_Mods is the data type for an opaque structure that represents LDAPMod
  492. * manipulations that can be made to a directory entry.
  493. */
  494. typedef struct slapi_mods Slapi_Mods;
  495. /**
  496. * Represents a the component ID in a directory entry.
  497. *
  498. * #Slapi_ComponentId is the data type for an opaque structure that represents the
  499. * component ID in a directory entry.
  500. */
  501. typedef struct slapi_componentid Slapi_ComponentId;
  502. /**
  503. * Represents an integral counter.
  504. *
  505. * Provides 64-bit integers with support for atomic operations, even on 32-bit
  506. * systems. This lets your plug-in have global integers that can be updated by
  507. * multiple worker threads in a thread-safe manner.
  508. *
  509. * The #Slapi_Counter structure is a wrapper around the actual counter value
  510. */
  511. typedef struct slapi_counter Slapi_Counter;
  512. /* Online tasks interface (to support import, export, etc) */
  513. #define SLAPI_TASK_PUBLIC 1 /* tell old plugins that the task api is now public */
  514. /**
  515. * An opaque structure that represents a task that has been initiated.
  516. *
  517. * Common Directory Server tasks, including importing, exporting, and indexing
  518. * databases, can be initiated through a special task configuration entry in
  519. * cn=tasks,cn=config. These task operations are managed using the #Slapi_Task
  520. * structure.
  521. */
  522. typedef struct slapi_task Slapi_Task;
  523. typedef struct passwordpolicyarray Slapi_PWPolicy;
  524. /**
  525. * Defines a callback used specifically by Slapi_Task structure cancel and
  526. * destructor functions.
  527. *
  528. * \param task The task that is being cancelled or destroyed.
  529. */
  530. typedef void (*TaskCallbackFn)(Slapi_Task *task);
  531. /*
  532. * The default thread stacksize for nspr21 is 64k (except on IRIX! It's 32k!).
  533. * For OSF, we require a larger stacksize as actual storage allocation is
  534. * higher i.e pointers are allocated 8 bytes but lower 4 bytes are used.
  535. * The value 0 means use the default stacksize.
  536. *
  537. * larger stacksize (256KB) is needed on IRIX due to its 4KB BUFSIZ.
  538. * (@ pthread IRIX porting -- 01/11/99)
  539. *
  540. * HP-UX on PA-RISC uses 64KB default stack size. Just set to 256K for all
  541. * HP-UX.
  542. */
  543. #if ( defined( irix ))
  544. #define SLAPD_DEFAULT_THREAD_STACKSIZE 262144L
  545. #elif ( defined ( OSF1 ))
  546. #define SLAPD_DEFAULT_THREAD_STACKSIZE 262144L
  547. #elif ( defined ( AIX ))
  548. #define SLAPD_DEFAULT_THREAD_STACKSIZE 262144L
  549. #elif ( defined ( hpux ))
  550. #define SLAPD_DEFAULT_THREAD_STACKSIZE 262144L
  551. #else
  552. /* All other platforms use the default stack size */
  553. #define SLAPD_DEFAULT_THREAD_STACKSIZE 0
  554. #endif
  555. /*---------------------------
  556. * parameter block routines
  557. *--------------------------*/
  558. /**
  559. * Creates a new parameter block.
  560. *
  561. * \return This function returns a pointer to the new parameter block.
  562. * \warning The pblock pointer allocated with this function must always be freed by
  563. * slapi_pblock_destroy(). The use of other memory deallocators (for example,
  564. * <tt>free()</tt>) is not supported and may lead to crashes or memory leaks.
  565. * \see slapi_pblock_destroy()
  566. */
  567. Slapi_PBlock *slapi_pblock_new( void ); /* allocate and initialize */
  568. /**
  569. * Initializes an existing parameter block for re-use.
  570. *
  571. * \param pb The parameter block to initialize.
  572. * \warning The parameter block that you wish to free must have been created using
  573. * slapi_pblock_new(). When you are finished with the parameter block, you
  574. * must free it using the slapi_pblock_destroy() function.
  575. *
  576. * \warning Note that search results will not be freed from the parameter block by
  577. * slapi_pblock_init(). You must free any internal search results with the
  578. * slapi_free_search_results_internal() function prior to calling
  579. * slapi_pblock_init(), otherwise the search results will be leaked.
  580. * \see slapi_pblock_new()
  581. * \see slapi_pblock_destroy()
  582. * \see slapi_free_search_results_internal()
  583. */
  584. void slapi_pblock_init( Slapi_PBlock *pb ); /* clear out for re-use */
  585. /**
  586. * Gets the value of a name-value pair from a parameter block.
  587. *
  588. * \param pb Parameter block.
  589. * \param arg ID of the name-value pair that you want to get.
  590. * \param value Pointer to the value retrieved from the parameter block.
  591. * \return \c 0 if successful.
  592. * \return \c -1 if an error occurs (for example, if an invalid ID is specified).
  593. * \todo Document valid values for the ID.
  594. * \warning The <tt>void *value</tt> argument should always be a pointer to the
  595. * type of value you are retrieving:
  596. * \code
  597. * int connid = 0;
  598. * ...
  599. * retval = slapi_pblock_get(pb, SLAPI_CONN_ID, &connid);
  600. * \endcode
  601. *
  602. * \warning #SLAPI_CONN_ID is an integer value, so you will pass in a pointer
  603. * to/address of an integer to get the value. Similarly, for a
  604. * <tt>char *</tt> value (a string), pass in a pointer to/address of the value.
  605. * For example:
  606. * \code
  607. * char *binddn = NULL;
  608. * ...
  609. * retval = slapi_pblock_get(pb, SLAPI_CONN_DN, &binddn);
  610. * \endcode
  611. *
  612. * \warning With certain compilers on some platforms, you may have to cast the
  613. * value to <tt>(void *)</tt>.
  614. *
  615. * \warning We recommend that you set the value to \c 0 or \c NULL before calling
  616. * slapi_pblock_get() to avoid reading from uninitialized memory, in
  617. * case the call to slapi_pblock_get() fails.
  618. *
  619. * \warning In most instances, the caller should not free the returned value.
  620. * The value will usually be freed internally or through the call to
  621. * slapi_pblock_destroy(). The exception is if the value is explicitly
  622. * set by the caller through slapi_pblock_set(). In this case, the caller
  623. * is responsible for memory management. If the value is freed, it is
  624. * strongly recommended that the free is followed by a call to
  625. * slapi_pblock_set() with a value of \c NULL. For example:
  626. * \code
  627. * char *someparam = NULL;
  628. * ...
  629. * someparam = slapi_ch_strdup(somestring);
  630. * slapi_pblock_set(pb, SOME_PARAM, someparam);
  631. * someparam = NULL;
  632. * ...
  633. * slapi_pblock_get(pb, SOME_PARAM, &someparam);
  634. * slapi_pblock_set(pb, SOME_PARAM, NULL);
  635. * slapi_ch_free_string(&someparam);
  636. * ...
  637. * \endcode
  638. *
  639. * \warning Some internal functions may change the value passed in, so it is
  640. * recommended to use slapi_pblock_get() to retrieve the value again,
  641. * rather than relying on a potential dangling pointer. This is shown
  642. * in the example above, which sets someparam to \c NULL after setting
  643. * it in the pblock.
  644. *
  645. * \see slapi_pblock_destroy()
  646. * \see slapi_pblock_set()
  647. */
  648. int slapi_pblock_get( Slapi_PBlock *pb, int arg, void *value );
  649. /**
  650. * Sets the value of a name-value pair in a parameter block.
  651. *
  652. * \param pb Parameter block.
  653. * \param arg ID of the name-value pair that you want to get.
  654. * \param value Pointer to the value you want to set in the parameter block.
  655. * \return \c 0 if successful.
  656. * \return \c -1 if an error occurs (for example, if an invalid ID is specified).
  657. * \warning The value to be passed in must always be a pointer, even for integer
  658. * arguments. For example, if you wanted to do a search with the
  659. * \c ManageDSAIT control:
  660. * \code
  661. * int managedsait = 1;
  662. * ...
  663. * slapi_pblock_set(pb, SLAPI_MANAGEDSAIT, &managedsait);
  664. * \endcode
  665. *
  666. * \warning A call similar to the following example will cause a crash:
  667. * \code
  668. * slapi_pblock_set(pb, SLAPI_MANAGEDSAIT, 1);
  669. * \endcode
  670. *
  671. * \warning However, for values which are already pointers, (<tt>char * string</tt>,
  672. * <tt>char **arrays</tt>, <tt>#Slapi_Backend *</tt>, etc.), you can pass
  673. * in the value directly. For example:
  674. * \code
  675. * Slapi_DN *target_sdn = slapi_sdn_dup(some_sdn);
  676. * slapi_pblock_set(pb, SLAPI_TARGET_SDN, target_sdn);
  677. * \endcode
  678. *
  679. * \warning or
  680. * \code
  681. * slapi_pblock_set(pb, SLAPI_TARGET_SDN, NULL);
  682. * \endcode
  683. *
  684. * \warning With some compilers, you will have to cast the value argument to
  685. * <tt>(void *)</tt>. If the caller allocates the memory passed in, the
  686. * caller is responsible for freeing that memory. Also, it is recommended
  687. * to use slapi_pblock_get() to retrieve the value to free, rather than
  688. * relying on a potentially dangling pointer. See the slapi_pblock_get()
  689. * example for more details.
  690. *
  691. * \warning When setting parameters to register a plug-in, the plug-in type must
  692. * always be set first, since many of the plug-in parameters depend on
  693. * the type. For example, set the #SLAPI_PLUGIN_TYPE to extended
  694. * operation before setting the list of extended operation OIDs for
  695. * the plug-in.
  696. *
  697. * \see slapi_pblock_get()
  698. */
  699. int slapi_pblock_set( Slapi_PBlock *pb, int arg, void *value );
  700. /**
  701. * Frees the specified parameter block from memory.
  702. *
  703. * \param pb Parameter block you want to free.
  704. * \warning The parameter block that you wish to free must have been created
  705. * using slapi_pblock_new(). Use of this function with parameter
  706. * blocks allocated on the stack (for example, <tt>#Slapi_PBlock pb;</tt>)
  707. * or using another memory allocator is not supported and may lead to
  708. * memory errors and memory leaks. For example:
  709. * \code
  710. * Slapi_PBlock *pb = malloc(sizeof(Slapi_PBlock));
  711. * \endcode
  712. *
  713. * \warning After calling this function, you should set the parameter block
  714. * pointer to \c NULL to avoid reusing freed memory in your function
  715. * context, as in the following:
  716. * \code
  717. * slapi_pblock_destroy(pb);
  718. * pb =NULL;
  719. * \endcode
  720. *
  721. * \warning If you reuse the pointer in this way, it makes it easier to
  722. * identify a Segmentation Fault, rather than using some difficult
  723. * method to detect memory leaks or other abnormal behavior.
  724. *
  725. * \warning It is safe to call this function with a \c NULL pointer. For
  726. * example:
  727. * \code
  728. * Slapi_PBlock *pb = NULL;
  729. * slapi_pblock_destroy(pb);
  730. * \endcode
  731. *
  732. * \warning This saves the trouble of checking for \c NULL before calling
  733. * slapi_pblock_destroy().
  734. *
  735. * \see slapi_pblock_new()
  736. */
  737. void slapi_pblock_destroy( Slapi_PBlock *pb );
  738. /*----------------
  739. * entry routines
  740. *---------------*/
  741. /**
  742. * Converts an LDIF description of a directory entry (a string value) into
  743. * an entry of the #Slapi_Entry type.
  744. *
  745. * A directory entry can be described by a string in LDIF format. Calling
  746. * the slapi_str2entry() function converts a string description in this
  747. * format to a #Slapi_Entry structure, which you can pass to other API
  748. * functions.
  749. *
  750. * \param s Description of an entry that you want to convert to a #Slapi_Entry.
  751. * \param flags One or more flags specifying how the entry should be generated.
  752. * The valid values of the \c flags argument are:
  753. * \arg #SLAPI_STR2ENTRY_REMOVEDUPVALS
  754. * \arg #SLAPI_STR2ENTRY_ADDRDNVALS
  755. * \arg #SLAPI_STR2ENTRY_BIGENTRY
  756. * \arg #SLAPI_STR2ENTRY_TOMBSTONE_CHECK
  757. * \arg #SLAPI_STR2ENTRY_IGNORE_STATE
  758. * \arg #SLAPI_STR2ENTRY_INCLUDE_VERSION_STR
  759. * \arg #SLAPI_STR2ENTRY_EXPAND_OBJECTCLASSES
  760. * \arg #SLAPI_STR2ENTRY_NOT_WELL_FORMED_LDIF
  761. * \arg #SLAPI_STR2ENTRY_NO_SCHEMA_LOCK
  762. * \arg #SLAPI_STR2ENTRY_USE_OBSOLETE_DNFORMAT
  763. * \arg #SLAPI_STR2ENTRY_NO_ENTRYDN
  764. * \arg #SLAPI_STR2ENTRY_DN_NORMALIZED
  765. *
  766. * \return A pointer to the #Slapi_Entry structure representing the entry.
  767. * \return \c NULL if the string cannot be converted; for example, if no DN is
  768. * specified in the string.
  769. * \warning This function modifies the string argument s. If you still need to
  770. * use this string value, you should make a copy of this string before
  771. * calling slapi_str2entry().
  772. *
  773. * \warning When you are done working with the entry, you should call the
  774. * slapi_entry_free() function.
  775. *
  776. * \note To convert an entry to a string description, call the slapi_entry2str()
  777. * function.
  778. *
  779. * \see slapi_entry_free()
  780. * \see slapi_entry2str()
  781. */
  782. Slapi_Entry *slapi_str2entry( char *s, int flags );
  783. /*
  784. * Same as slapi_str2entry except passing optional dn and rdn structure as argument
  785. */
  786. Slapi_Entry *slapi_str2entry_ext( const char *dn, const Slapi_RDN *srdn, char *s, int flags );
  787. /*-----------------------------
  788. * Flags for slapi_str2entry()
  789. *----------------------------*/
  790. /**
  791. * Removes any duplicate values in the attributes of the entry.
  792. *
  793. * \see slapi_str2entry()
  794. */
  795. #define SLAPI_STR2ENTRY_REMOVEDUPVALS 1
  796. /**
  797. * Adds the relative distinguished name (RDN) components (for example,
  798. * \c uid=bjensen) as attributes of the entry.
  799. *
  800. * \see slapi_str2entry()
  801. */
  802. #define SLAPI_STR2ENTRY_ADDRDNVALS 2
  803. /**
  804. * Provide a hint that the entry is large. This enables some optimizations
  805. * related to large entries.
  806. *
  807. * \see slapi_str2entry()
  808. */
  809. #define SLAPI_STR2ENTRY_BIGENTRY 4
  810. /**
  811. * Check to see if the entry is a tombstone. If so, set the tombstone flag
  812. * (#SLAPI_ENTRY_FLAG_TOMBSTONE).
  813. *
  814. * \see slapi_str2entry()
  815. */
  816. #define SLAPI_STR2ENTRY_TOMBSTONE_CHECK 8
  817. /**
  818. * Ignore entry state information if present.
  819. *
  820. * \see slapi_str2entry()
  821. */
  822. #define SLAPI_STR2ENTRY_IGNORE_STATE 16
  823. /**
  824. * Return entries that have a <tt>version: 1</tt> line as part of the LDIF
  825. * representation.
  826. *
  827. * \see slapi_str2entry()
  828. */
  829. #define SLAPI_STR2ENTRY_INCLUDE_VERSION_STR 32
  830. /**
  831. * Add any missing ancestor values based on the object class hierarchy.
  832. *
  833. * \see slapi_str2entry()
  834. */
  835. #define SLAPI_STR2ENTRY_EXPAND_OBJECTCLASSES 64
  836. /**
  837. * Inform slapi_str2entry() that the LDIF input is not well formed.
  838. *
  839. * Well formed LDIF has no duplicate attribute values, already has the RDN
  840. * as an attribute of the entry, and has all values for a given attribute
  841. * type listed contiguously.
  842. *
  843. * \see slapi_str2entry()
  844. */
  845. #define SLAPI_STR2ENTRY_NOT_WELL_FORMED_LDIF 128
  846. /**
  847. * Don't acquire the schema lock.
  848. *
  849. * You should use this flag if you are sure that the lock is already held,
  850. * or if the server has not started it's threads yet during startup.
  851. *
  852. * \see slapi_str2entry()
  853. */
  854. #define SLAPI_STR2ENTRY_NO_SCHEMA_LOCK 256
  855. /**
  856. * Normalize DN using obsolete DN normalizer.
  857. *
  858. * This marco is used only for the upgrading dn format tool.
  859. *
  860. * \see slapi_str2entry()
  861. */
  862. #define SLAPI_STR2ENTRY_USE_OBSOLETE_DNFORMAT 512
  863. /**
  864. * Do not include entrydn attribute value in the in-memory entry
  865. *
  866. * If this flag is set, entrydn in the source string is ignored.
  867. *
  868. * \see slapi_str2entry()
  869. */
  870. #define SLAPI_STR2ENTRY_NO_ENTRYDN 1024
  871. /**
  872. * Passed DN is already normalized.
  873. *
  874. * If this flag is set, str2entry assumes passed DN is already normalized.
  875. *
  876. * \see slapi_str2entry()
  877. */
  878. #define SLAPI_STR2ENTRY_DN_NORMALIZED 2048
  879. /**
  880. * Generates a description of an entry as an LDIF string.
  881. *
  882. * This function behaves much like slapi_entry2str(); however, you can specify
  883. * output options with this function.
  884. *
  885. * This function generates an LDIF string value conforming to the following syntax:
  886. * \code
  887. * dn: dn\n
  888. * [attr: value\n]*
  889. * \endcode
  890. *
  891. * For example:
  892. * \code
  893. * dn: uid=jdoe, ou=People, dc=example,dc=com
  894. * cn: Jane Doe
  895. * sn: Doe
  896. * ...
  897. * \endcode
  898. *
  899. * To convert an entry described in LDIF string format to an LDAP entry using
  900. * the #Slapi_Entry data type, call the slapi_str2entry() function.
  901. *
  902. * \param e Entry that you want to convert into an LDIF string.
  903. * \param len Length of the LDIF string returned by this function.
  904. * \param options An option set that specifies how you want the string
  905. * converted. You can \c OR together any of the following options
  906. * when you call this function:
  907. * \arg #SLAPI_DUMP_STATEINFO
  908. * \arg #SLAPI_DUMP_UNIQUEID
  909. * \arg #SLAPI_DUMP_NOOPATTRS
  910. * \arg #SLAPI_DUMP_NOWRAP
  911. * \arg #SLAPI_DUMP_MINIMAL_ENCODING
  912. * \return The LDIF string representation of the entry you specify.
  913. * \return \c NULL if an error occurs.
  914. * \warning When you no longer need to use the string, you should free it
  915. * from memory by calling the slapi_ch_free_string() function.
  916. *
  917. * \see slapi_entry2str()
  918. * \see slapi_str2entry()
  919. */
  920. char *slapi_entry2str_with_options( Slapi_Entry *e, int *len, int options );
  921. /*---------------------------------------------
  922. * Options for slapi_entry2str_with_options()
  923. *--------------------------------------------*/
  924. /**
  925. * Output entry with replication state info.
  926. *
  927. * This allows access to the internal data used by multi-master replication.
  928. *
  929. * \see slapi_entry2str_with_options()
  930. */
  931. #define SLAPI_DUMP_STATEINFO 1 /* replication state */
  932. /**
  933. * Output entry with uniqueid.
  934. *
  935. * This option is used when creating an LDIF file to be used to initialize
  936. * a replica. Each entry will contain the nsuniqueID operational attribute.
  937. *
  938. * \see slapi_entry2str_with_options()
  939. */
  940. #define SLAPI_DUMP_UNIQUEID 2 /* unique ID */
  941. /**
  942. * Output entry without operational attributes.
  943. *
  944. * By default, certain operational attributes (such as \c creatorsName,
  945. * \c modifiersName, \c createTimestamp, \c modifyTimestamp) may be
  946. * included in the output. With this option, no operational attributes
  947. * will be included.
  948. *
  949. * \see slapi_entry2str_with_options()
  950. */
  951. #define SLAPI_DUMP_NOOPATTRS 4 /* suppress operational attrs */
  952. /**
  953. * Output entry without LDIF line wrapping.
  954. *
  955. * By default, lines will be wrapped as defined in the LDIF specification.
  956. * With this option, line wrapping is disabled.
  957. *
  958. * \see slapi_entry2str_with_options()
  959. */
  960. #define SLAPI_DUMP_NOWRAP 8 /* no line breaks */
  961. /**
  962. * Output entry with less base64 encoding.
  963. *
  964. * Uses as little base64 encoding as possible in the output.
  965. *
  966. * \see slapi_entry2str_with_options()
  967. */
  968. #define SLAPI_DUMP_MINIMAL_ENCODING 16 /* use less base64 encoding */
  969. /**
  970. * Output rdn based entry instead of dn based. Introduced for subtree rename.
  971. *
  972. * \see slapi_entry2str_with_options()
  973. */
  974. #define SLAPI_DUMP_RDN_ENTRY 32 /* rdn based entry */
  975. /**
  976. * Generates an LDIF string description of an LDAP entry.
  977. *
  978. * This function generates an LDIF string value conforming to the following syntax:
  979. * \code
  980. * dn: dn\n
  981. * [attr: value\n]*
  982. * \endcode
  983. *
  984. * For example:
  985. * \code
  986. * dn: uid=jdoe, ou=People, dc=example,dc=com
  987. * cn: Jane Doe
  988. * sn: Doe
  989. * ...
  990. * \endcode
  991. *
  992. * To convert an entry described in LDIF string format to an LDAP entry using
  993. * the #Slapi_Entry data type, call the slapi_str2entry() function.
  994. *
  995. * \param e Entry that you want to convert into an LDIF string.
  996. * \param len Length of the LDIF string returned by this function.
  997. * \return The LDIF string representation of the entry you specify.
  998. * \return \c NULL if an error occurs.
  999. * \warning When you no longer need to use the string, you should free it
  1000. * from memory by calling the slapi_ch_free_string() function.
  1001. *
  1002. * \see slapi_entry2str_with_options()
  1003. * \see slapi_str2entry()
  1004. */
  1005. char *slapi_entry2str( Slapi_Entry *e, int *len );
  1006. /**
  1007. * Allocates memory for a new entry of the data type #Slapi_Entry.
  1008. *
  1009. * This function returns an empty #Slapi_Entry structure. You can call other
  1010. * front-end functions to set the DN and attributes of this entry.
  1011. *
  1012. * When you are no longer using the entry, you should free it from memory by
  1013. * calling the slapi_entry_free() function.
  1014. *
  1015. * \return This function returns a pointer to the newly allocated entry of the
  1016. * data type #Slapi_Entry. If space cannot be allocated, e.g., no more
  1017. * virtual memory exists, the \c ns-slapd program terminates.
  1018. * \warning When you no longer use the entry, free it from memory by calling the
  1019. * slapi_entry_free() function.
  1020. *
  1021. * \see slapi_entry_dup()
  1022. * \see slapi_entry_free()
  1023. */
  1024. Slapi_Entry *slapi_entry_alloc(void);
  1025. /**
  1026. * Initializes the values of an entry with the DN and attribute value pairs you
  1027. * supply.
  1028. *
  1029. * This function initializes the attributes and the corresponding attribute values
  1030. * of an entry. Also, during the course of processing, the unique ID of the entry
  1031. * is set to \c NULL, and the flag value is set to \c 0.
  1032. *
  1033. * Use this function to initialize a #Slapi_Entry pointer.
  1034. *
  1035. * \param e The entry you want to initialize.
  1036. * \param dn The DN of the entry you are initializing.
  1037. * \param a Initialization list of attribute value pairs, supplied as a
  1038. * #Slapi_Attr data value.
  1039. * \warning This function should always be used after slapi_entry_alloc() and
  1040. * never otherwise. For example:
  1041. * \code
  1042. * Slapi_Entry *e = slapi_entry_alloc();
  1043. * slapi_entry_init(e, NULL, NULL);
  1044. * \endcode
  1045. *
  1046. * \warning To set the DN in the entry:
  1047. * \code
  1048. * slapi_sdn_set_dn_passin(slapi_entry_get_sdn(e), dn);
  1049. * \endcode
  1050. *
  1051. * \warning In this case, the dn argument is not copied but is consumed by the
  1052. * function. To copy the argument, see the following example:
  1053. * \code
  1054. * char *dn = slapi_ch_strdup(some_dn);
  1055. * Slapi_Entry *e = slapi_entry_alloc();
  1056. * slapi_entry_init(e, dn, NULL);
  1057. * \endcode
  1058. *
  1059. * \warning The \c dn argument is not freed in this context but will eventually
  1060. * be freed when slapi_entry_free() is called.
  1061. *
  1062. * \see slapi_entry_free()
  1063. * \see slapi_entry_alloc()
  1064. */
  1065. void slapi_entry_init(Slapi_Entry *e, char *dn, Slapi_Attr *a);
  1066. /*
  1067. * Initializes the values of an entry with the Slapi_DN and attribute value
  1068. * pairs you supply.
  1069. */
  1070. void slapi_entry_init_ext(Slapi_Entry *e, Slapi_DN *sdn, Slapi_Attr *a);
  1071. /**
  1072. * Frees an entry, its DN, and its attributes from memory.
  1073. *
  1074. * Call this function to free an entry that you have allocated by using the
  1075. * slapi_entry_alloc() function or the slapi_entry_dup() function.
  1076. *
  1077. * \param e Entry that you want to free. If \c NULL, no action occurs.
  1078. * \warning To free entries, always use this function instead of using
  1079. * slapi_ch_free() or free().
  1080. *
  1081. * \see slapi_entry_alloc()
  1082. * \see slapi_entry_dup()
  1083. */
  1084. void slapi_entry_free( Slapi_Entry *e );
  1085. /**
  1086. * Makes a copy of an entry, its DN, and its attributes.
  1087. *
  1088. * This function returns a copy of an existing #Slapi_Entry structure. You can
  1089. * call other front-end functions to change the DN and attributes of this entry.
  1090. *
  1091. * \param e Entry that you want to copy.
  1092. * \return This function returns the new copy of the entry. If the structure
  1093. * cannot be duplicated, for example, if no more virtual memory exists,
  1094. * the \c ns-slapd program terminates.
  1095. * \warning When you are no longer using the entry, free it from memory by
  1096. * calling the slapi_entry_free() function.
  1097. * \see slapi_entry_alloc()
  1098. * \see slapi_entry_free()
  1099. */
  1100. Slapi_Entry *slapi_entry_dup( const Slapi_Entry *e );
  1101. /**
  1102. * Gets the distinguished name (DN) of the specified entry.
  1103. *
  1104. * \param e Entry from which you want to get the DN.
  1105. * \return This function returns the DN of the entry. This returns a pointer
  1106. * to the actual DN in the entry, not a copy of the DN. You should not
  1107. * free the DN unless you plan to replace it by calling slapi_entry_set_dn().
  1108. * \warning Use slapi_ch_free_string() if you are replacing the DN with
  1109. * slapi_entry_set_dn().
  1110. * \see slapi_ch_free_string()
  1111. * \see slapi_entry_set_dn()
  1112. */
  1113. char *slapi_entry_get_dn( Slapi_Entry *e );
  1114. /**
  1115. * Returns the normalized DN from the entry that you specify.
  1116. *
  1117. * \param e Entry from which you want to obtain the normalized DN.
  1118. * \return This function returns the normalized DN from the entry that you
  1119. * specify. If the entry you specify does not contain a normalized DN,
  1120. * one is created through the processing of this function.
  1121. * \warning Never free the returned value.
  1122. * \see slapi_entry_get_dn()
  1123. */
  1124. char *slapi_entry_get_ndn( Slapi_Entry *e );
  1125. /**
  1126. * Returns as a \c const the value of the #Slapi_DN object from the entry
  1127. * that you specify.
  1128. *
  1129. * \param e Entry from which you want to get the #Slapi_DN object.
  1130. * \return Returns as a \c const the #Slapi_DN object from the entry that you
  1131. * specify.
  1132. * \warning Never free the returned value. If you need a copy, use
  1133. * slapi_sdn_dup().
  1134. * \see slapi_sdn_dup()
  1135. * \see slapi_entry_get_sdn()
  1136. */
  1137. const Slapi_DN *slapi_entry_get_sdn_const( const Slapi_Entry *e );
  1138. /**
  1139. * Returns the #Slapi_DN object from the entry that you specify.
  1140. *
  1141. * \param e Entry from which you want to get the #Slapi_DN object.
  1142. * \return Returns the #Slapi_DN object from the entry that you specify.
  1143. * \warning Never free the returned value. If you need a copy, use
  1144. * slapi_sdn_dup().
  1145. * \see slapi_entry_get_sdn_const()
  1146. * \see slapi_sdn_dup()
  1147. */
  1148. Slapi_DN *slapi_entry_get_sdn( Slapi_Entry *e );
  1149. /**
  1150. * Returns as a \c const the value of the #Slapi_RDN from the entry
  1151. * that you specify.
  1152. *
  1153. * \param e Entry from which you want to get the #Slapi_RDN object.
  1154. * \return Returns as a \c const the #Slapi_RDN object from the entry that you
  1155. * specify.
  1156. * \warning Never free the returned value. If you need a copy, use
  1157. * slapi_sdn_dup().
  1158. * \see slapi_sdn_dup()
  1159. * \see slapi_entry_get_sdn()
  1160. */
  1161. const Slapi_RDN *slapi_entry_get_srdn_const( const Slapi_Entry *e );
  1162. /**
  1163. * Returns the #Slapi_RDN object from the entry that you specify.
  1164. *
  1165. * \param e Entry from which you want to get the #Slapi_RDN object.
  1166. * \return Returns the #Slapi_RDN object from the entry that you specify.
  1167. * \warning Never free the returned value. If you need a copy, use
  1168. * slapi_sdn_dup().
  1169. * \see slapi_entry_get_srdn_const()
  1170. * \see slapi_sdn_dup()
  1171. */
  1172. Slapi_RDN * slapi_entry_get_srdn( Slapi_Entry *e );
  1173. /**
  1174. * Returns as a \c const the DN value of the entry that you specify.
  1175. *
  1176. * \param e Entry from which you want to get the DN as a constant.
  1177. * \return This function returns one of the following values:
  1178. * \arg The DN of the entry that you specify. The DN is returned
  1179. * as a const; you are not able to modify the DN value.
  1180. * \arg The NDN value of Slapi_DN if the DN of the Slapi_DN object is NULL.
  1181. * \warning Never free the returned value.
  1182. * \see slapi_entry_set_sdn()
  1183. */
  1184. const char *slapi_entry_get_dn_const( const Slapi_Entry *e );
  1185. /**
  1186. * Returns as a \c const the RDN value of the entry that you specify.
  1187. *
  1188. * \param e Entry from which you want to get the RDN as a constant.
  1189. * \return This function returns one of the following values:
  1190. * \arg The RDN of the entry that you specify. The RDN is returned
  1191. * as a const; you are not able to modify the RDN value.
  1192. * \warning Never free the returned value.
  1193. * \see slapi_entry_set_srdn()
  1194. */
  1195. const char *slapi_entry_get_rdn_const( const Slapi_Entry *e );
  1196. /**
  1197. * Returns as a \c const the Normalized RDN value of the entry that you specify.
  1198. *
  1199. * \param e Entry from which you want to get the Normalized RDN as a constant.
  1200. * \return This function returns one of the following values:
  1201. * \arg The Normalized RDN of the entry that you specify.
  1202. * The Normalized RDN is returned as a const;
  1203. * you are not able to modify the Normalized RDN value.
  1204. * \warning Never free the returned value.
  1205. * \see slapi_entry_set_srdn()
  1206. */
  1207. const char *slapi_entry_get_nrdn_const( const Slapi_Entry *e );
  1208. /**
  1209. * Sets the distinguished name (DN) of an entry.
  1210. *
  1211. * This function sets the DN pointer in the specified entry to the DN that you supply.
  1212. *
  1213. * \param e Entry to which you want to assign the DN.
  1214. * \param dn Distinguished name you want assigned to the entry.
  1215. * \warning The dn will be freed eventually when slapi_entry_free() is called.
  1216. * \warning A copy of dn should be passed. For example:
  1217. * \code
  1218. * char *dn = slapi_ch_strdup(some_dn):
  1219. * slapi_entry_set_dn(e, dn);
  1220. * \endcode
  1221. *
  1222. * \warning The old dn will be freed as a result of this call. Do not pass in
  1223. * a \c NULL value.
  1224. * \see slapi_entry_free()
  1225. * \see slapi_entry_get_dn()
  1226. */
  1227. void slapi_entry_set_dn( Slapi_Entry *e, char *dn );
  1228. /**
  1229. * Sets the normalized distinguished name (DN) of an entry.
  1230. *
  1231. * This function sets the DN pointer in the specified entry to the DN that you supply. The DN should have been normalized.
  1232. *
  1233. * \param e Entry to which you want to assign the DN.
  1234. * \param dn Distinguished name you want assigned to the entry.
  1235. * \warning The dn will be freed eventually when slapi_entry_free() is called.
  1236. * \warning A copy of dn should be passed. For example:
  1237. *
  1238. * \warning The old dn will be freed as a result of this call. Do not pass in
  1239. * a \c NULL value.
  1240. * \see slapi_entry_free()
  1241. * \see slapi_entry_get_dn()
  1242. */
  1243. void slapi_entry_set_normdn( Slapi_Entry *e, char *normdn );
  1244. /**
  1245. * Sets the relative distinguished name (RDN) of an entry.
  1246. *
  1247. * This function sets the RDN pointer in the specified entry to the RDN that
  1248. * you supply.
  1249. *
  1250. * \param e Entry to which you want to assign the RDN.
  1251. * \param rdn Relatie distinguished name you want assigned to the entry.
  1252. * If dn is given here, the first rdn part is set to the RDN.
  1253. * \warning The rdn will be copied in slapi_entry_set_rdn.
  1254. */
  1255. void slapi_entry_set_rdn( Slapi_Entry *e, char *rdn );
  1256. /**
  1257. * Sets the Slapi_DN value in an entry.
  1258. *
  1259. * This function sets the value for the #Slapi_DN object in the entry you specify.
  1260. *
  1261. * \param e Entry to which you want to set the value of the #Slapi_DN.
  1262. * \param sdn The specified #Slapi_DN value that you want to set.
  1263. * \warning This function makes a copy of the \c sdn parameter.
  1264. * \see slapi_entry_get_sdn()
  1265. */
  1266. void slapi_entry_set_sdn( Slapi_Entry *e, const Slapi_DN *sdn );
  1267. /**
  1268. * Sets the Slapi_DN value containing RDN in an entry.
  1269. *
  1270. * This function sets the value for the #Slapi_DN object containing RDN in the entry you specify.
  1271. *
  1272. * \param e Entry to which you want to set the value of the #Slapi_DN.
  1273. * \param srdn The specified #Slapi_DN value that you want to set.
  1274. * \warning This function makes a copy of the \c srdn parameter.
  1275. * \see slapi_entry_get_srdn()
  1276. */
  1277. void slapi_entry_set_srdn( Slapi_Entry *e, const Slapi_RDN *srdn );
  1278. /**
  1279. * Determines if an entry contains the specified attribute.
  1280. *
  1281. * If the entry contains the attribute, the function returns a pointer to
  1282. * the attribute.
  1283. *
  1284. * \param e Entry that you want to check.
  1285. * \param type Name of the attribute that you want to check.
  1286. * \param attr Pointer to the attribute, if the attribute is found in the
  1287. * entry.
  1288. * \return \c 0 if the entry contains the specified attribute.
  1289. * \return \c -1 if the entry does not contain the specified attribute.
  1290. * \warning Do not free the returned \c attr. It is a pointer to the internal
  1291. * entry data structure. It is usually wise to make a copy of the
  1292. * returned attribute, using slapi_attr_dup(), to avoid dangling pointers
  1293. * if the entry is freed while the pointer to attr is still being used.
  1294. * \see slapi_attr_dup()
  1295. */
  1296. int slapi_entry_attr_find( const Slapi_Entry *e, const char *type, Slapi_Attr **attr );
  1297. /**
  1298. * Finds the first attribute in an entry.
  1299. *
  1300. * If you want to iterate through the attributes in an entry, use this function
  1301. * in conjunction with the slapi_entry_next_attr() function.
  1302. *
  1303. * \param e Entry from which you want to get the attribute.
  1304. * \param attr Pointer to the first attribute in the entry.
  1305. * \return Returns 0 when successful; any other value returned signals failure.
  1306. * \warning Do not free the returned \c attr. This is a pointer into the
  1307. * internal entry data structure. If you need a copy, use slapi_attr_dup().
  1308. * \see slapi_entry_next_attr()
  1309. * \see slapi_attr_dup()
  1310. */
  1311. int slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr );
  1312. /**
  1313. * Finds the next attribute after \c prevattr in an entry.
  1314. *
  1315. * To iterate through the attributes in an entry, use this function in conjunction
  1316. * with the slapi_entry_first_attr() function.
  1317. *
  1318. * \param e Entry from which you want to get the attribute.
  1319. * \param prevattr Previous attribute in the entry.
  1320. * \param attr Pointer to the next attribute after \c prevattr in the entry.
  1321. * \return \c 0 if successful.
  1322. * \return \c -1 if \c prevattr was the last attribute in the entry.
  1323. * \warning Do not free the returned \c attr. This is a pointer into the
  1324. * internal entry data structure. If you need a copy, use slapi_attr_dup().
  1325. * \see slapi_entry_first_attr()
  1326. * \see slapi_entry_dup()
  1327. */
  1328. int slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr );
  1329. /**
  1330. * Gets the unique ID value of the entry.
  1331. *
  1332. * \param e Entry from which you want to obtain the unique ID.
  1333. * \return This function returns the unique ID value of the entry specified.
  1334. * \warning Never free this value. If you need a copy, use slapi_ch_strdup().
  1335. * \see slapi_entry_set_uniqueid()
  1336. * \see slapi_ch_strdup()
  1337. */
  1338. const char *slapi_entry_get_uniqueid( const Slapi_Entry *e );
  1339. /**
  1340. * Replaces the unique ID value of an entry with the unique ID value that you
  1341. * supply.
  1342. *
  1343. * This function replaces the unique ID value of the entry with the \c uniqueid
  1344. * value that you specify. In addition, the function adds #SLAPI_ATTR_UNIQUEID to
  1345. * the attribute list and gives it the unique ID value supplied. If the entry
  1346. * already contains a #SLAPI_ATTR_UNIQUEID attribute, its value is updated with
  1347. * the new value supplied.
  1348. *
  1349. * \param e Entry for which you want to generate a unique ID.
  1350. * \param uniqueid The unique ID value that you want to assign to the entry.
  1351. * \warning Do not free the \c uniqueid after calling this function. The value
  1352. * will eventually be freed when slapi_entry_free() is called.
  1353. *
  1354. * \warning You should pass in a copy of the value because this function will
  1355. * consume the value passed in. For example:
  1356. * \code
  1357. * char *uniqueid = slapi_ch_strdup(some_uniqueid);
  1358. * slapi_entry_set_uniqueid(e, uniqueid);
  1359. * \endcode
  1360. *
  1361. * \warning Do not pass in a \c NULL for \c uniqueid.
  1362. * \see slapi_entry_get_uniqueid()
  1363. * \see slapi_entry_free()
  1364. */
  1365. void slapi_entry_set_uniqueid( Slapi_Entry *e, char *uniqueid );
  1366. /**
  1367. * Determines whether the specified entry complies with the schema for its object
  1368. * class.
  1369. *
  1370. * \param pb Parmeter block.
  1371. * \param e Entry that you want to check.
  1372. * \return \c 0 if the entry complies with the schema or if schema checking is
  1373. * turned off. The function also returns \c 0 if the entry has additional
  1374. * attributes not allowed by the schema and has the object class
  1375. * \c extensibleObject.
  1376. * \return \c 1 if the entry is missing the \c objectclass attribute, if it is missing
  1377. * any required attributes, if it has any attributes not allowed by the schema
  1378. * but does not have the object class \c extensibleObject, or if the entry has
  1379. * multiple values for a single-valued attribute.
  1380. * \warning The \c pb argument can be \c NULL. It is only used to get the
  1381. * #SLAPI_IS_REPLICATED_OPERATION flag. If that flag is present, no schema
  1382. * checking is done.
  1383. */
  1384. int slapi_entry_schema_check( Slapi_PBlock *pb, Slapi_Entry *e );
  1385. /**
  1386. * Determines whether the specified entry complies with the syntax rules imposed
  1387. * by it's attribute types.
  1388. *
  1389. * \param pb Parameter block.
  1390. * \param e Entry that you want to check.
  1391. * \param override Flag to override the server configuration and force syntax checking
  1392. * to be performed.
  1393. * \return \c 0 if the entry complies with the syntax rules or if syntax checking
  1394. * is disabled.
  1395. * \return \c 1 if the entry has any attribute values that violate the syntax rules
  1396. * imposed by the associated attribute type. If the \c pb parameter was
  1397. * passed in, an error message describing the syntax violations will be
  1398. * set in the #SLAPI_PB_RESULT_TEXT paramter.
  1399. * \warning The \c pb parameter can be \c NULL. It is used to store an error
  1400. * message with details of any syntax violations. The \c pb paramter
  1401. * is also used to check if the #SLAPI_IS_REPLICATED_OPERATION flag is
  1402. * set. If that flag is present, no syntax checking is performed.
  1403. */
  1404. int slapi_entry_syntax_check( Slapi_PBlock *pb, Slapi_Entry *e, int override );
  1405. /**
  1406. * Determines if the DN violates the Distinguished Name syntax rules.
  1407. *
  1408. * \param pb Parameter block.
  1409. * \param dn The dn string you want to check.
  1410. * \param override Flag to override the server configuration and force syntax checking
  1411. * to be performed.
  1412. * \return \c 0 if the DN complies with the Distinguished Name syntax rules or if
  1413. * syntax checking is disabled.
  1414. * \return \c 1 if the DN violates the Distinguished Name syntax rules. If the \c pb
  1415. * parameter was passed in, an error message will be set in the
  1416. * #SLAPI_PB_RESULT_TEXT parameter.
  1417. * \warning The \c pb parameter can be \c NULL. It is used to store an error
  1418. * message with details of any syntax violations. The \c pb paramter
  1419. * is also used to check if the #SLAPI_IS_REPLICATED_OPERATION flag is
  1420. * set. If that flag is present, no syntax checking is performed.
  1421. */
  1422. int slapi_dn_syntax_check( Slapi_PBlock *pb, const char *dn, int override );
  1423. /**
  1424. * Determines if any values being added to an entry violate the syntax rules
  1425. * imposed by the associated attribute type.
  1426. *
  1427. * \param pb Parameter block.
  1428. * \param mods Array of mods that you want to check.
  1429. * \param override Flag to override the server configuration and force syntax checking
  1430. * to be performed.
  1431. * \return \c 0 if the mods comply with the syntax rules or if syntax checking
  1432. * is disabled.
  1433. * \return \c 1 if the mods are adding any new attribute values that violate the
  1434. * syntax rules imposed by the associated attribute type. If the \c pb
  1435. * parameter was passed in, an error message describing the syntax violations
  1436. * will be set in the #SLAPI_PB_RESULT_TEXT paramter.
  1437. * \warning The \c pb parameter can be \c NULL. It is used to store an error
  1438. * message with details of any syntax violations. The \c pb paramter
  1439. * is also used to check if the #SLAPI_IS_REPLICATED_OPERATION flag is
  1440. * set. If that flag is present, no syntax checking is performed.
  1441. */
  1442. int slapi_mods_syntax_check( Slapi_PBlock *pb, LDAPMod **mods, int override );
  1443. /**
  1444. * Determines whether the values in an entry’s relative distinguished name (RDN)
  1445. * are also present as attribute values.
  1446. *
  1447. * For example, if the entry’s RDN is <tt>cn=Barbara Jensen</tt>, the function determines
  1448. * if the entry has the \c cn attribute with the value <tt>Barbara Jensen</tt>.
  1449. *
  1450. * \param e Entry that you want to check for RDN values.
  1451. * \return \c 1 if the values in the RDN are present in the attributes of the entry.
  1452. * \return \c 0 if the values are not present.
  1453. */
  1454. int slapi_entry_rdn_values_present( const Slapi_Entry *e );
  1455. /**
  1456. * Adds the components in an entry’s relative distinguished name (RDN) to the entry
  1457. * as attribute values.
  1458. *
  1459. * For example, if the entry’s RDN is <tt>uid=bjensen</tt>, the function adds
  1460. * <tt>uid=bjensen</tt> to the entry as an attribute value.
  1461. *
  1462. * \param e Entry to which you want to add the RDN attributes.
  1463. * \return \c LDAP_SUCCESS if the values were successfully added to the entry. The
  1464. * function also returns \c LDAP_SUCCESS if the entry is \c NULL, if the
  1465. * entry’s DN is \c NULL, or if the entry’s RDN is \c NULL.
  1466. * \return \c LDAP_INVALID_DN_SYNTAX if the DN of the entry cannot be parsed.
  1467. * \warning Free the entry from memory by using the slapi_entry_free() function, if the
  1468. * entry was allocated by the user.
  1469. * \see slapi_entry_free()
  1470. */
  1471. int slapi_entry_add_rdn_values( Slapi_Entry *e );
  1472. /**
  1473. * Deletes an attribute (and all its associated values) from an entry.
  1474. *
  1475. * \param e Entry from which you want to delete the attribute.
  1476. * \param type Attribute type that you want to delete.
  1477. * \return \c 0 if successful.
  1478. * \return \c 1 if the specified attribute is not part of the entry.
  1479. * \return \c -1 if an error occurred.
  1480. */
  1481. int slapi_entry_attr_delete( Slapi_Entry *e, const char *type );
  1482. /**
  1483. * Gets the values of a multi-valued attribute of an entry.
  1484. *
  1485. * This function is very similar to slapi_entry_attr_get_charptr(), except that it
  1486. * returns a <tt>char **</tt> array for multi-valued attributes. The array and all
  1487. * values are copies. Even if the attribute values are not strings, they will still
  1488. * be \c NULL terminated so that they can be used safely in a string context. If there
  1489. * are no values, \c NULL will be returned. Because the array is \c NULL terminated,
  1490. * the usage should be similar to the sample shown below:
  1491. *
  1492. * \code
  1493. * char **ary = slapi_entry_attr_get_charray(e, someattr);
  1494. * int ii;
  1495. * for (ii = 0; ary && ary[ii]; ++ii) {
  1496. * char *strval = ary[ii];
  1497. * ...
  1498. * }
  1499. * slapi_ch_array_free(ary);
  1500. * \endcode
  1501. *
  1502. * \param e Entry from which you want to get the values.
  1503. * \param type Attribute type from which you want to get the values.
  1504. * \return A copy of all the values of the attribute.
  1505. * \return \c NULL if the entry does not contain the attribute or if the attribute
  1506. * has no values.
  1507. * \warning When you are done working with the values, free them from memory by calling
  1508. * the slapi_ch_array_free() function.
  1509. * \see slapi_entry_attr_get_charptr()
  1510. */
  1511. char **slapi_entry_attr_get_charray(const Slapi_Entry* e, const char *type);
  1512. /**
  1513. * Gets the values of a multi-valued attribute of an entry.
  1514. *
  1515. * This function is very similar to slapi_entry_attr_get_charptr(), except that it
  1516. * returns a <tt>char **</tt> array for multi-valued attributes. The array and all
  1517. * values are copies. Even if the attribute values are not strings, they will still
  1518. * be \c NULL terminated so that they can be used safely in a string context. If there
  1519. * are no values, \c NULL will be returned. Because the array is \c NULL terminated,
  1520. * the usage should be similar to the sample shown below:
  1521. *
  1522. * \code
  1523. * char **ary = slapi_entry_attr_get_charray(e, someattr);
  1524. * int ii;
  1525. * for (ii = 0; ary && ary[ii]; ++ii) {
  1526. * char *strval = ary[ii];
  1527. * ...
  1528. * }
  1529. * slapi_ch_array_free(ary);
  1530. * \endcode
  1531. *
  1532. * \param e Entry from which you want to get the values.
  1533. * \param type Attribute type from which you want to get the values.
  1534. * \param numVals The number of attribute values will be stored in this variable.
  1535. * \return A copy of all the values of the attribute.
  1536. * \return \c NULL if the entry does not contain the attribute or if the attribute
  1537. * has no values.
  1538. * \warning When you are done working with the values, free them from memory by calling
  1539. * the slapi_ch_array_free() function.
  1540. * \see slapi_entry_attr_get_charptr()
  1541. */
  1542. char **slapi_entry_attr_get_charray_ext( const Slapi_Entry* e, const char *type, int *numVals);
  1543. /**
  1544. * Gets the first value of an attribute of an entry as a string.
  1545. *
  1546. * \param e Entry from which you want to get the string value.
  1547. * \param type Attribute type from which you want to get the value.
  1548. * \return A copy of the first value in the attribute.
  1549. * \return \c NULL if the entry does not contain the attribute.
  1550. * \warning When you are done working with this value, free it from memory by calling the
  1551. * slapi_ch_free_string() function.
  1552. * \see slapi_entry_attr_get_charray()
  1553. */
  1554. char *slapi_entry_attr_get_charptr(const Slapi_Entry* e, const char *type);
  1555. /**
  1556. * Gets the first value of an attribute in an entry as an integer.
  1557. *
  1558. * \param e Entry from which you want to get the integer value.
  1559. * \param type Attribute type from which you want to get the value.
  1560. * \return The first value of the attribute converted to an integer.
  1561. * \return \c 0 if the entry does not contain the attribute.
  1562. */
  1563. int slapi_entry_attr_get_int(const Slapi_Entry* e, const char *type);
  1564. /**
  1565. * Gets the first value of an attribute in an entry as an unsigned integer data type.
  1566. *
  1567. * \param e Entry from which you want to get the integer value.
  1568. * \param type Attribute type from which you want to get the value.
  1569. * \return The first value of the attribute converted to an unsigned integer.
  1570. * \return \c 0 if the entry does not contain the attribute.
  1571. */
  1572. unsigned int slapi_entry_attr_get_uint(const Slapi_Entry* e, const char *type);
  1573. /**
  1574. * Gets the first value of an attribute in an entry as a long data type.
  1575. *
  1576. * \param e Entry from which you want to get the long value.
  1577. * \param type Attribute type from which you want to get the value.
  1578. * \return The first value of the attribute converted to a \c long type.
  1579. * \return \c 0 if the entry does not contain the attribute.
  1580. */
  1581. long slapi_entry_attr_get_long( const Slapi_Entry* e, const char *type);
  1582. /**
  1583. * Gets the first value of an attribute in an entry as an unsigned long
  1584. * data type.
  1585. *
  1586. * \param e Entry from which you want to get the unsigned long value.
  1587. * \param type Attribute type from which you want to get the value.
  1588. * \return The first value of the attribute converted to an <tt>
  1589. * unsigned long</tt>.
  1590. * \return \c 0 if the entry does not contain the attribute.
  1591. */
  1592. unsigned long slapi_entry_attr_get_ulong( const Slapi_Entry* e, const char *type);
  1593. /**
  1594. * Gets the first value of an attribute in an entry as a long long data type.
  1595. *
  1596. * \param e Entry from which you want to get the long long value.
  1597. * \param type Attribute type from which you want to get the value.
  1598. * \return The first value of the attribute converted to a <tt>long long</tt>.
  1599. * \return \c 0 if the entry does not contain the attribute.
  1600. */
  1601. long long slapi_entry_attr_get_longlong( const Slapi_Entry* e, const char *type);
  1602. /**
  1603. * Gets the first value of an attribute in an entry as an unsigned
  1604. * long long data type.
  1605. *
  1606. * \param e Entry from which you want to get the unsigned long long value.
  1607. * \param type Attribute type from which you want to get the value.
  1608. * \return The first value of the attribute converted to an <tt>unsigned
  1609. * long long</tt>.
  1610. * \return \c 0 if the entry does not contain the attribute.
  1611. */
  1612. unsigned long long slapi_entry_attr_get_ulonglong( const Slapi_Entry* e, const char *type);
  1613. /**
  1614. * Gets the value of a given attribute of a given entry as a boolean value.
  1615. *
  1616. * Comparisons are case-insensitive (\c TRUE, \c trUe, and \c true are all the
  1617. * same), and unique substrings can be matched (\c t and \c tr will be interpreted
  1618. * as \c true). If the attribute value is a number, then non-zero numbers are
  1619. * interpreted as \c true, and \c 0 is interpreted as \c false.
  1620. *
  1621. * \param e Entry from which you want to get the boolean value.
  1622. * \param type Attribute type from which you want to get the value.
  1623. * \return \c PR_TRUE | \c PR_FALSE
  1624. */
  1625. PRBool slapi_entry_attr_get_bool( const Slapi_Entry* e, const char *type);
  1626. /**
  1627. * Replaces the value or values of an attribute in an entry with a specified string
  1628. * value.
  1629. *
  1630. * \param e Entry in which you want to set the value.
  1631. * \param type Attribute type in which you want to set the value.
  1632. * \param value String value that you want to assign to the attribute.
  1633. * \warning This function makes a copy of the parameter \c value. The \c value
  1634. * parameter can be \c NULL; if so, this function is roughly equivalent
  1635. * to slapi_entry_attr_delete().
  1636. * \see slapi_entry_attr_delete()
  1637. */
  1638. void slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value);
  1639. /**
  1640. * Replaces the value or values of an attribute in an entry with a specified integer
  1641. * data value.
  1642. *
  1643. * This function will replace the value or values of an attribute with the
  1644. * integer value that you specify. If the attribute does not exist, it is created
  1645. * with the integer value that you specify.
  1646. *
  1647. * \param e Entry in which you want to set the value.
  1648. * \param type Attribute type in which you want to set the value.
  1649. * \param l Integer value that you want to assign to the attribute.
  1650. */
  1651. void slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l);
  1652. /**
  1653. * Replaces the value or values of an attribute in an entry with a specified
  1654. * unsigned integer data type value.
  1655. *
  1656. * This function will replace the value or values of an attribute with the
  1657. * unsigned integer value that you specify. If the attribute does not exist,
  1658. * it is created with the unsigned integer value you specify.
  1659. *
  1660. * \param e Entry in which you want to set the value.
  1661. * \param type Attribute type in which you want to set the value.
  1662. * \param l Unsigned integer value that you want to assign to the attribute.
  1663. */
  1664. void slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l);
  1665. /**
  1666. * Replaces the value or values of an attribute in an entry with a specified long data
  1667. * type value.
  1668. *
  1669. * \param e Entry in which you want to set the value.
  1670. * \param type Attribute type in which you want to set the value.
  1671. * \param l Long integer value that you want to assign to the attribute.
  1672. */
  1673. void slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l);
  1674. /**
  1675. * Replaces the value or values of an attribute in an entry with a specified unsigned
  1676. * long data type value.
  1677. *
  1678. * This function will replace the value or values of an attribute with the unsigned
  1679. * long value that you specify. If the attribute does not exist, it is created with the
  1680. * unsigned long value that you specify.
  1681. *
  1682. * \param e Entry in which you want to set the value.
  1683. * \param type Attribute type in which you want to set the value.
  1684. * \param l Unsigned long value that you want to assign to the attribute.
  1685. */
  1686. void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
  1687. /**
  1688. * Determines if an attribute in an entry contains a specified value.
  1689. *
  1690. * The syntax of the attribute type is taken into account when checking
  1691. * for the specified value.
  1692. *
  1693. * \param e Entry that you want to check.
  1694. * \param type Attribute type that you want to test for the value specified.
  1695. * \param value Value that you want to find in the attribute.
  1696. * \return \c 1 if the attribute contains the specified value.
  1697. * \return \c 0 if the attribute does not contain the specified value.
  1698. * \warning \c value must not be \c NULL.
  1699. */
  1700. int slapi_entry_attr_has_syntax_value(const Slapi_Entry *e, const char *type, const Slapi_Value *value);
  1701. /**
  1702. * This function determines if the specified entry has child entries.
  1703. *
  1704. * \param e Entry that you want to test for child entries.
  1705. * \return \c 1 if the entry you supply has child entries.
  1706. * \return \c 0 if the entry you supply has child entries.
  1707. */
  1708. int slapi_entry_has_children(const Slapi_Entry *e);
  1709. /**
  1710. * This function determines if an entry is the root DSE.
  1711. *
  1712. * The root DSE is a special entry that contains information about the Directory
  1713. * Server, including its capabilities and configuration.
  1714. *
  1715. * \param dn The DN that you want to test to see if it is the root DSE entry.
  1716. * \return \c 1 if \c dn is the root DSE.
  1717. * \return \c 0 if \c dn is not the root DSE.
  1718. */
  1719. int slapi_is_rootdse( const char *dn );
  1720. /**
  1721. * This function returns the approximate size of an entry, rounded to the nearest 1k.
  1722. *
  1723. * This can be useful for checking cache sizes, estimating storage needs, and so on.
  1724. *
  1725. * When determining the size of an entry, only the sizes of the attribute values are
  1726. * counted; the size of other entry values (such as the size of attribute names,
  1727. * variously-normalized DNs, or any metadata) are not included in the size
  1728. * returned. It is assumed that the size of the metadata, et al., is well enough
  1729. * accounted for by the rounding of the size to the next largest 1k . This holds true
  1730. * especially in larger entries, where the actual size of the attribute values far
  1731. * outweighs the size of the metadata.
  1732. *
  1733. * When determining the size of the entry, both deleted values and deleted
  1734. * attributes are included in the count.
  1735. *
  1736. * \param e Entry from which you want the size returned.
  1737. * \return The size of the entry, rounded to the nearest 1k. The value returned is a
  1738. * size_t data type with a u_long value.
  1739. * \return A size of 1k if the entry is empty.
  1740. * \warning The \c e parameter must not be \c NULL.
  1741. */
  1742. size_t slapi_entry_size(Slapi_Entry *e);
  1743. /**
  1744. * Adds an array of #Slapi_Value data values to the existing attribute values in
  1745. * an entry.
  1746. *
  1747. * If the attribute does not exist, it is created with the #Slapi_Value specified.
  1748. *
  1749. * \param e Entry to which you want to add values.
  1750. * \param type Attribute type to which you want to add values.
  1751. * \param vals \c NULL terminated array of #Slapi_Value data values you want to add.
  1752. * \return This function returns \c 0 if successful; any other value returned
  1753. * signals failure.
  1754. * \warning This function makes a copy of the parameter \c vals. The \c vals
  1755. * parameter can be \c NULL.
  1756. */
  1757. int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
  1758. /**
  1759. * Adds and array of #Slapi_Value data values to the specified attribute in an entry.
  1760. *
  1761. * This function adds an array of #Slapi_Value data values to an attribute. If the
  1762. * attribute does not exist, it is created and given the value contained in the
  1763. * #Slapi_Value array.
  1764. *
  1765. * \param e Entry to which you want to add values.
  1766. * \param type Attribute type to which you want to add values.
  1767. * \param vals \c NULL terminated array of #Slapi_Value data values you want to add.
  1768. * \return \c LDAP_SUCCESS if the #Slapi_Value array if successfully added to the
  1769. * attribute.
  1770. * \return \c LDAP_TYPE_OR_VALUE_EXISTS if any values you are trying to add duplicate
  1771. * an existing value in the attribute.
  1772. * \return \c LDAP_OPERATIONS_ERROR if there are pre-existing duplicate values in the
  1773. * attribute.
  1774. * \warning This function makes a copy of the parameter \c vals. The \c vals
  1775. * parameter can be \c NULL.
  1776. */
  1777. int slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
  1778. /**
  1779. * Add a Slapi_ValueSet data value to the specified attribute in an entry.
  1780. *
  1781. * This function adds a set of values to an attribute in an entry. The values added
  1782. * are in the form of a #Slapi_ValueSet data type. If the entry does not contain the
  1783. * attribute specified, it is created with the specified #Slapi_ValueSet values.
  1784. *
  1785. * \param e Entry to which you want to add values.
  1786. * \param type Attribute type to which you want to add values.
  1787. * \param vs #Slapi_ValueSet data value that you want to add to the entry.
  1788. * \return \c 0 when successful; any other value returned signals failure.
  1789. * \warning This function makes a copy of the parameter \c vs. The \c vs
  1790. * parameter can be \c NULL.
  1791. */
  1792. int slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs);
  1793. /**
  1794. * Removes an array of Slapi_Value data values from an attribute in an entry.
  1795. *
  1796. * This function removes an attribute/valueset from an entry. Both the attribute
  1797. * and its #Slapi_Value data values are removed from the entry. If you supply a
  1798. * #Slapi_Value whose value is \c NULL, the function will delete the specified
  1799. * attribute from the entry. In either case, the function returns \c LDAP_SUCCESS.
  1800. *
  1801. * \param e Entry from which you want to delete values.
  1802. * \param type Attribute type from which you want to delete values.
  1803. * \param vals \c NULL terminated array of #Slapi_Value data values that you
  1804. * want to delete.
  1805. * \return \c LDAP_SUCCESS if the specified attribute and the array of #Slapi_Value
  1806. * data values are deleted from the entry.
  1807. * \return If the specified attribute contains a \c NULL value, the attribute is
  1808. * deleted from the attribute list, and the function returns
  1809. * \c LDAP_NO_SUCH_ATTRIBUTE. As well, if the attribute is not found in the
  1810. * list of attributes for the specified entry, the function returns
  1811. * \c LDAP_NO_SUCH_ATTRIBUTE.
  1812. * \return If there is an operational error during the processing of this call such
  1813. * as a duplicate value found, the function will return
  1814. * \c LDAP_OPERATIONS_ERROR.
  1815. * \warning The \c vals parameter can be \c NULL, in which case this function does
  1816. * nothing.
  1817. */
  1818. int slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
  1819. /**
  1820. * Merges (adds) and array of #Slapi_Value data values to a specified attribute in
  1821. * an entry.
  1822. *
  1823. * This function adds additional #Slapi_Value data values to the existing values
  1824. * contained in an attribute. If the attribute type does not exist, it is created.
  1825. *
  1826. * If the specified attribute exists in the entry, the function merges the value
  1827. * specified and returns \c LDAP_SUCCESS. If the attribute is not found in the entry,
  1828. * the function creates it with the #Slapi_Value specified and returns \c
  1829. * LDAP_NO_SUCH_ATTRIBUTE.
  1830. *
  1831. * If this function fails, it leaves the values for \c type within a pointer to
  1832. * \c e in an indeterminate state. The present valueset may be truncated.
  1833. *
  1834. * \param e Entry into which you want to merge values.
  1835. * \param type Attribute type that you want to merge the values into.
  1836. * \param vals \c NULL terminated array of #Slapi_Value values that you want to merge
  1837. * into the entry.
  1838. * \return \c LDAP_SUCCESS
  1839. * \return \c LDAP_NO_SUCH_ATTRIBUTE
  1840. * \warning This function makes a copy of \c vals. The \c vals parameter
  1841. * can be \c NULL.
  1842. */
  1843. int slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
  1844. /**
  1845. * Replaces the values of an attribute with the #Slapi_Value data value you specify.
  1846. *
  1847. * This function replaces existing attribute values in a specified entry with a single
  1848. * #Slapi_Value data value. The function first deletes the existing attribute from the
  1849. * entry, then replaces it with the new value specified.
  1850. *
  1851. * \param e Entry in which you want to replace values.
  1852. * \param type Attribute type which will receive the replaced values
  1853. * \param vals \c NULL terminated array of #Slapi_Value valyes that should replace
  1854. * the existing values of the attribute.
  1855. * \return \c 0 when successful; any other value returned signals failure.
  1856. * \warning This function makes a copy of \c vals. The \c vals parameter
  1857. * can be \c NULL.
  1858. */
  1859. int slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
  1860. /**
  1861. * Adds a specified #Slapi_Value data value to an attribute in an entry.
  1862. *
  1863. * This function adds a #Slapi_Value data value to the existing attribute values in an
  1864. * entry. If the specified attribute does not exist in the entry, the attribute is
  1865. * created with the #Slapi_Value specified. The function doesn’t check for duplicate
  1866. * values, meaning it does not check if the value being added is already there.
  1867. *
  1868. * \param e Entry to which you want to add a value.
  1869. * \param type Attribute to which you want to add a value.
  1870. * \param value The #Slapi_Value data value you want to add to the entry.
  1871. * \return \c 0 when successful; any other value returned signals failure.
  1872. * \warning This function makes a copy of \c value. The \c value parameter
  1873. * can be \c NULL.
  1874. */
  1875. int slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value);
  1876. /**
  1877. * Adds a string value to an attribute in an entry.
  1878. *
  1879. * This function adds a string value to the existing attribute values in an entry. If
  1880. * the specified attribute does not exist in the entry, the attribute is created with
  1881. * the string value specified. The function doesn’t check for duplicate values; it
  1882. * does not check if the string value being added is already there.
  1883. *
  1884. * \param e Entry to which you want to add a string value.
  1885. * \param type Attribute to which you want to add a string value.
  1886. * \param value String value you want to add.
  1887. * \return \c 0 when successful; any other value returned signals failure.
  1888. * \warning This function makes a copy of \c value. The \c value parameter
  1889. * can be \c NULL.
  1890. */
  1891. int slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value);
  1892. /**
  1893. * Deletes a string value from an attribute in an entry.
  1894. *
  1895. * \param e Entry from which you want the string deleted.
  1896. * \param type Attribute type from which you want the string deleted.
  1897. * \param value Value of string to delete.
  1898. * \return \c 0 when successful; any other value returned signals failure.
  1899. */
  1900. int slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value);
  1901. /**
  1902. * Find differences between two entries.
  1903. *
  1904. * Compares two #Slapi_Entry entries and determines the difference between them. The
  1905. * differences are returned as the modifications needed to the first entry to make it
  1906. * match the second entry.
  1907. *
  1908. * \param smods An empty #Slapi_Mods that will be filled in with the modifications
  1909. * needed to make \c e1 the same as \c e2.
  1910. * \param e1 The first entry you want to compare.
  1911. * \param e2 The second entry you want to compare.
  1912. * \param diff_ctrl Allows you to skip comparing operational attributes by passing
  1913. * #SLAPI_DUMP_NOOPATTRS. Pass \c 0 if you want to compare the
  1914. * operational attributes.
  1915. * \warning The caller must allocate the #Slapi_Mods that is passed in as \c smods.
  1916. * This must be an empty #Slapi_Mods, otherwise the contents will be leaked.
  1917. * \warning It is up to the caller to free \c smods when they are finished using them
  1918. * by calling slapi_mods_free() or slapi_mods_done() if \c smods was allocated
  1919. * on the stack.
  1920. */
  1921. void slapi_entry_diff(Slapi_Mods *smods, Slapi_Entry *e1, Slapi_Entry *e2, int diff_ctrl);
  1922. /**
  1923. * Applies an array of \c LDAPMod modifications to a Slapi_Entry.
  1924. *
  1925. * \param e Entry to which you want to apply the modifications.
  1926. * \param mods \c NULL terminated array of \c LDAPMod modifications that you
  1927. * want to apply to the specified entry.
  1928. * \return \c LDAP_SUCCESS if the mods applied to the entry cleanly, otherwise an
  1929. * LDAP error is returned.
  1930. * \warning It is up to the caller to free the \c LDAPMod array after the mods have
  1931. * been applied.
  1932. */
  1933. int slapi_entry_apply_mods(Slapi_Entry *e, LDAPMod **mods);
  1934. /**
  1935. * Applies a single \c LDAPMod modification to a Slapi_Entry.
  1936. *
  1937. * \param e Entry to which you want to apply the modification.
  1938. * \param mod A pointer to the \c LDAPMod modification that you
  1939. * want to apply to the specified entry.
  1940. * \return \c LDAP_SUCCESS if the mod applied to the entry cleanly, otherwise
  1941. * an LDAP error is returned.
  1942. * \warning It is up to the caller to free the \c LDAPMod after the mod has
  1943. * been applied.
  1944. */
  1945. int slapi_entry_apply_mod(Slapi_Entry *e, LDAPMod *mod);
  1946. /**
  1947. * Renames a Slapi_Entry.
  1948. *
  1949. * This function will rename an existing \c Slapi_Entry, similar to what
  1950. * would happen with a \c MODRDN operation. New RDN values will be added
  1951. * as attributes to the entry and old RDN values will be deleted if requested.
  1952. *
  1953. * \param e Entry that you want to rename.
  1954. * \param newrdn The new RDN value to be used for renaming the entry. This must
  1955. * not be \c NULL.
  1956. * \param deleteoldrdn Will delete the old RDN values from the entry if set to \c 1.
  1957. * \param newsuperior The new superior DN to use when renaming the entry. Set this
  1958. * to \c NULL if you do not want to move the entry.
  1959. * \return \c LDAP_SUCCESS if the rename was successful, otherwise an LDAP error
  1960. * is returned.
  1961. */
  1962. int slapi_entry_rename(Slapi_Entry *e, const char *newrdn, int deleteoldrdn, Slapi_DN *newsuperior);
  1963. /*------------------------
  1964. * Entry flags.
  1965. *-----------------------*/
  1966. /**
  1967. * Flag that signifies that an entry is a tombstone entry
  1968. *
  1969. * \see slapi_entry_flag_is_set()
  1970. * \see slapi_entry_set_flag()
  1971. * \see slapi_entry_clear_flag()
  1972. */
  1973. #define SLAPI_ENTRY_FLAG_TOMBSTONE 1
  1974. /**
  1975. * Determines if certain flags are set for a specified entry.
  1976. *
  1977. * \param e Entry for which you want to check for the specified flag.
  1978. * \param flag The flag whose presense you want to check for. Valid flags are:
  1979. * \arg #SLAPI_ENTRY_FLAG_TOMBSTONE
  1980. * \return \c 0 if the flag is not set.
  1981. * \return The value of the flag if it is set.
  1982. * \see slapi_entry_clear_flag()
  1983. * \see slapi_entry_set_flag()
  1984. */
  1985. int slapi_entry_flag_is_set( const Slapi_Entry *e, unsigned char flag );
  1986. /**
  1987. * Sets a flag for a specified entry.
  1988. *
  1989. * \param e Entry for which you want to set the flag.
  1990. * \param flag Flag that you want to set. Valid flags are:
  1991. * \arg #SLAPI_ENTRY_FLAG_TOMBSTONE
  1992. * \see slapi_entry_clear_flag()
  1993. * \see slapi_entry_flag_is_set()
  1994. */
  1995. void slapi_entry_set_flag( Slapi_Entry *e, unsigned char flag);
  1996. /**
  1997. * Clears a flag for a specified entry.
  1998. *
  1999. * \param e Entry for which you want to clear the flag.
  2000. * \param flag Flag that you want to clear. Valid flags are:
  2001. * \arg #SLAPI_ENTRY_FLAG_TOMBSTONE
  2002. * \see slapi_entry_flag_is_set()
  2003. * \see slapi_entry_set_flag()
  2004. */
  2005. void slapi_entry_clear_flag( Slapi_Entry *e, unsigned char flag);
  2006. /*------------------------------
  2007. * exported vattrcache routines
  2008. *------------------------------*/
  2009. /**
  2010. * Check if an entry is current in the virtual attribute cache.
  2011. *
  2012. * \param e The entry for which you want to check the virtual attribute cache
  2013. * validity.
  2014. * \return \c 1 if the entry is valid in the cache.
  2015. * \return \c 0 if the entry is invalid in the cache.
  2016. */
  2017. int slapi_entry_vattrcache_watermark_isvalid(const Slapi_Entry *e);
  2018. /**
  2019. * Mark an entry as valid in the virtual attribute cache.
  2020. *
  2021. * \param e The entry that you want to mark as valid.
  2022. */
  2023. void slapi_entry_vattrcache_watermark_set(Slapi_Entry *e);
  2024. /**
  2025. * Mark an entry as invalid in the virtual attribute cache.
  2026. *
  2027. * \param e The entry that you want to mark as invalid.
  2028. */
  2029. void slapi_entry_vattrcache_watermark_invalidate(Slapi_Entry *e);
  2030. /**
  2031. * Apply mod and store the result in the entry extension
  2032. *
  2033. * \param e The entry to apply mod.
  2034. * \param mod The mod to apply on entry.
  2035. * \param modcnt The count of values in mod.
  2036. *
  2037. * \return \c 1 if mod is applied and stored in extension.
  2038. * \return \c -1 if mod is applied and failed
  2039. * \return \c 0 if mod is nothing to do with extension
  2040. */
  2041. int slapi_entry_apply_mod_extension(Slapi_Entry *e, const LDAPMod *mod, int modcnt);
  2042. /**
  2043. * Invalidate all entries in the virtual attribute cache.
  2044. */
  2045. void slapi_entrycache_vattrcache_watermark_invalidate(void);
  2046. /*
  2047. * Slapi_DN routines
  2048. */
  2049. /**
  2050. * Creates a new \c Slapi_DN structure.
  2051. *
  2052. * This function will allocate the necessary memory for a \c Slapi_DN
  2053. * and initialize both the DN and normalized DN values to \c NULL.
  2054. *
  2055. * \return A pointer to the newly allocated, and still empty,
  2056. * \c Slapi_DN structure.
  2057. * \see slapi_sdn_free()
  2058. * \see slapi_sdn_copy()
  2059. * \see slapi_sdn_done()
  2060. */
  2061. Slapi_DN *slapi_sdn_new( void );
  2062. /**
  2063. * Creates a new \c Slapi_DN structure and intializes it's DN to a requested value.
  2064. *
  2065. * The DN of the new structure will point to a copy of the string pointed to by \c dn.
  2066. * The DN value is passed in to the parameter by value.
  2067. *
  2068. * \param dn The DN value to be set in the new \c Slapi_DN structure.
  2069. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2070. * a DN value set to the content of \c dn.
  2071. * \warning The \c dn value is copied by the function itself. The caller
  2072. * is still responsible for the memory used by \c dn.
  2073. * \see slapi_sdn_new_dn_byref()
  2074. * \see slapi_sdn_new_dn_passin()
  2075. * \see slapi_sdn_free()
  2076. * \see slapi_sdn_copy()
  2077. * \see slapi_sdn_done()
  2078. */
  2079. Slapi_DN *slapi_sdn_new_dn_byval(const char *dn);
  2080. /**
  2081. * Creates a new \c Slapi_DN structure and intializes it's normalized DN to a requested value.
  2082. *
  2083. * The normalized DN of the new structure will point to a copy of the string pointed to by
  2084. * \c ndn. The normalized DN value is passed in to the parameter by value.
  2085. *
  2086. * \param ndn The normalized DN value to be set in the new \c Slapi_DN structure.
  2087. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2088. * the normalized DN value set to the content of \c ndn.
  2089. * \warning The \c ndn value is copied by the function itself. The caller
  2090. * is still responsible for the memory used by \c ndn.
  2091. * \see slapi_sdn_new_ndn_byref()
  2092. * \see slapi_sdn_new_ndn_passin()
  2093. * \see slapi_sdn_free()
  2094. * \see slapi_sdn_copy()
  2095. * \see slapi_sdn_done()
  2096. */
  2097. Slapi_DN *slapi_sdn_new_ndn_byval(const char *ndn);
  2098. /**
  2099. * Creates a new \c Slapi_DN structure and intializes it's DN to a requested value.
  2100. *
  2101. * The DN of the new structure will point to the same string pointed to by \c dn.
  2102. * The DN value is passed in to the parameter by reference.
  2103. *
  2104. * \param dn The DN value to be set in the new \c Slapi_DN structure.
  2105. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2106. * a DN value set to the content of \c dn.
  2107. * \warning The caller is still responsible for the memory used by \c dn. This
  2108. * memory should not be freed until the returned \c Slapi_DN has been
  2109. * disposed of or reinitialized.
  2110. * \see slapi_sdn_new_dn_byval()
  2111. * \see slapi_sdn_new_dn_passin()
  2112. * \see slapi_sdn_free()
  2113. * \see slapi_sdn_copy()
  2114. * \see slapi_sdn_done()
  2115. */
  2116. Slapi_DN *slapi_sdn_new_dn_byref(const char *dn);
  2117. /**
  2118. * Creates a new \c Slapi_DN structure and intializes it's normalized and case ignored DN to a requested value.
  2119. *
  2120. * The normalized and case ignored DN of the new structure will point to the same string pointed to by \c ndn.
  2121. * The normalized and case ignored DN value is passed in to the parameter by reference.
  2122. *
  2123. * \param ndn The normalized and case ignored DN value to be set in the new \c Slapi_DN structure.
  2124. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2125. * the normalized and case ignored DN value set to the content of \c ndn.
  2126. * \warning The caller is still responsible for the memory used by \c ndn. This
  2127. * memory should not be freed until the returned \c Slapi_DN has been
  2128. * disposed of or reinitialized.
  2129. * \see slapi_sdn_new_ndn_byval()
  2130. * \see slapi_sdn_new_ndn_passin()
  2131. * \see slapi_sdn_free()
  2132. * \see slapi_sdn_copy()
  2133. * \see slapi_sdn_done()
  2134. */
  2135. Slapi_DN *slapi_sdn_new_ndn_byref(const char *ndn);
  2136. /**
  2137. * Creates a new \c Slapi_DN structure and intializes it's normalized and case ignored DN to a requested value.
  2138. *
  2139. * The normalized and case ignored DN of the new structure will point to the same string pointed to by \c ndn.
  2140. * Ownership of the memory pointed to by \c ndn is tranferred to the Slapi_DN.
  2141. *
  2142. * \param ndn The normalized and case ignored DN value to be set in the new \c Slapi_DN structure.
  2143. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2144. * the normalized and case ignored DN value set to the content of \c ndn.
  2145. * \see slapi_sdn_new_ndn_byval()
  2146. * \see slapi_sdn_new_ndn_byref()
  2147. * \see slapi_sdn_free()
  2148. * \see slapi_sdn_copy()
  2149. * \see slapi_sdn_done()
  2150. */
  2151. Slapi_DN *slapi_sdn_new_ndn_passin(const char *ndn);
  2152. /**
  2153. * Creates a new \c Slapi_DN structure and intializes it's DN to a requested value.
  2154. *
  2155. * The DN of the new structure will point to the same string pointed to by \c dn.
  2156. * Ownership of the memory pointed to by \c dn is tranferred to the Slapi_DN.
  2157. *
  2158. * \param dn The DN value to be set in the new \c Slapi_DN structure.
  2159. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2160. * a DN value set to the content of \c dn.
  2161. * \warning The caller is no longer responsible for the memory used by \c dn.
  2162. * This memory should not be freed directly. It will be freed when
  2163. * the \c Slapi_DN is properly disposed of.
  2164. * \see slapi_sdn_new_dn_byval()
  2165. * \see slapi_sdn_new_dn_byref()
  2166. * \see slapi_sdn_free()
  2167. * \see slapi_sdn_copy()
  2168. * \see slapi_sdn_done()
  2169. */
  2170. Slapi_DN *slapi_sdn_new_dn_passin(const char *dn);
  2171. /**
  2172. * Creates a new \c Slapi_DN structure and intializes it's normalized DN to a requested value.
  2173. *
  2174. * The DN of the new structure will point to the same string pointed to by \c normdn.
  2175. * The normalized DN value is passed in to the parameter by reference.
  2176. *
  2177. * \param normdn The normalized DN value to be set in the new \c Slapi_DN structure.
  2178. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2179. * the normalized DN value set to the content of \c normdn.
  2180. * \warning The caller is still responsible for the memory used by \c normdn.
  2181. * This memory should not be freed until the returned \c Slapi_DN
  2182. * has been disposed of or reinitialized.
  2183. * \see slapi_sdn_free()
  2184. * \see slapi_sdn_copy()
  2185. * \see slapi_sdn_done()
  2186. */
  2187. Slapi_DN *slapi_sdn_new_normdn_byref(const char *normdn);
  2188. /**
  2189. * Creates a new \c Slapi_DN structure and intializes it's normalized DN to a requested value.
  2190. *
  2191. * The DN of the new structure will point to the same string pointed to by \c normdn.
  2192. * Ownership of the memory pointed to by \c normdn is tranferred to the Slapi_DN.
  2193. *
  2194. * \param normdn The DN value to be set in the new \c Slapi_DN structure.
  2195. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2196. * a DN value set to the content of \c dn.
  2197. * \warning The caller is no longer responsible for the memory used by \c dn.
  2198. * This memory should not be freed directly. It will be freed when
  2199. * the \c Slapi_DN is properly disposed of.
  2200. * \see slapi_sdn_free()
  2201. * \see slapi_sdn_copy()
  2202. * \see slapi_sdn_done()
  2203. */
  2204. Slapi_DN *slapi_sdn_new_normdn_passin(const char *dn);
  2205. /**
  2206. * Creates a new \c Slapi_DN structure and intializes it's normalized DN to a requested value.
  2207. *
  2208. * The DN of the new structure will point to the duplicated string of \c normdn.
  2209. * Ownership of the memory pointed to by \c normdn is tranferred to the Slapi_DN.
  2210. *
  2211. * \param normdn The copy of the DN value to be set in the new \c Slapi_DN structure.
  2212. * \return A pointer to the newly allocated \c Slapi_DN structure with
  2213. * a DN value set to the content of \c dn.
  2214. * \warning The caller is no longer responsible for the memory used by \c dn.
  2215. * This memory should not be freed directly. It will be freed when
  2216. * the \c Slapi_DN is properly disposed of.
  2217. * \see slapi_sdn_free()
  2218. * \see slapi_sdn_copy()
  2219. * \see slapi_sdn_done()
  2220. */
  2221. Slapi_DN *slapi_sdn_new_normdn_byval(const char *dn);
  2222. /**
  2223. * Sets a DN value in a \c Slapi_DN structure.
  2224. *
  2225. * The DN of the structure will point to a copy of the string pointed to by
  2226. * \c dn. The DN value is passed in to the parameter by value.
  2227. *
  2228. * \param sdn The target \c Slapi_DN structure.
  2229. * \param dn The DN value to be set in \c sdn.
  2230. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2231. * \warning The \c dn value is copied by the function itself. The caller
  2232. * is still responsible for the memory used by \c dn.
  2233. * \see slapi_sdn_set_dn_byref()
  2234. * \see slapi_sdn_set_dn_passin()
  2235. */
  2236. Slapi_DN *slapi_sdn_set_dn_byval(Slapi_DN *sdn, const char *dn);
  2237. /**
  2238. * Sets a DN value in a \c Slapi_DN structure.
  2239. *
  2240. * The DN of the structure will point to the same string pointed to by \c dn.
  2241. * The DN value is passed in to the parameter by reference.
  2242. *
  2243. * \param sdn The target \c Slapi_DN structure.
  2244. * \param dn The DN value to be set in \c sdn.
  2245. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2246. * \warning The caller is still responsible for the memory used by \c dn. This
  2247. * memory should not be freed until the returned \c Slapi_DN has been
  2248. * disposed of or reinitialized.
  2249. * \see slapi_sdn_set_dn_byval()
  2250. * \see slapi_sdn_set_dn_passin()
  2251. */
  2252. Slapi_DN *slapi_sdn_set_dn_byref(Slapi_DN *sdn, const char *dn);
  2253. /**
  2254. * Sets a DN value in a \c Slapi_DN structure.
  2255. *
  2256. * The DN of the structure will point to the same string pointed to by \c dn.
  2257. * Ownership of the memory pointed to by \c dn is tranferred to the Slapi_DN.
  2258. *
  2259. * \param sdn The target \c Slapi_DN structure.
  2260. * \param dn The DN value to be set in \c sdn.
  2261. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2262. * \warning The caller is no longer responsible for the memory used by \c dn.
  2263. * This memory should not be freed directly. It will be freed when
  2264. * the \c Slapi_DN is properly disposed of.
  2265. * \see slapi_sdn_set_dn_byval()
  2266. * \see slapi_sdn_set_dn_byref()
  2267. */
  2268. Slapi_DN *slapi_sdn_set_dn_passin(Slapi_DN *sdn, const char *dn);
  2269. /**
  2270. * Sets a normalized DN value in a \c Slapi_DN structure.
  2271. *
  2272. * The DN of the structure will point to the same string pointed to by \c normdn.
  2273. * The normalized DN value is passed in to the parameter by reference.
  2274. *
  2275. * \param sdn The target \c Slapi_DN structure.
  2276. * \param normdn The normalized DN value to be set in \c sdn.
  2277. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2278. * \warning The caller is still responsible for the memory used by \c normdn.
  2279. * This memory should not be freed until the returned \c Slapi_DN
  2280. * has been disposed of or reinitialized.
  2281. * \see slapi_sdn_set_dn_byref()
  2282. */
  2283. Slapi_DN *slapi_sdn_set_normdn_byref(Slapi_DN *sdn, const char *normdn);
  2284. /**
  2285. * Sets a normalized DN value in a \c Slapi_DN structure.
  2286. *
  2287. * The DN of the structure will point to the same string pointed to by \c normdn.
  2288. * Ownership of the memory pointed to by \c normdn is tranferred to the Slapi_DN.
  2289. *
  2290. * \param sdn The target \c Slapi_DN structure.
  2291. * \param normdn The normalized DN value to be set in \c sdn.
  2292. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2293. * \warning The caller is no longer responsible for the memory used by \c normdn.
  2294. * This memory should not be freed directly. It will be freed when
  2295. * the \c Slapi_DN is properly disposed of.
  2296. * \see slapi_sdn_set_dn_passin()
  2297. */
  2298. Slapi_DN *slapi_sdn_set_normdn_passin(Slapi_DN *sdn, const char *dn);
  2299. /**
  2300. * Sets a normalized DN value in a \c Slapi_DN structure.
  2301. *
  2302. * The normalized DN of the structure will point to a copy of the string
  2303. * pointed to by \c dn. The normalized DN value is passed in to the parameter
  2304. * by value.
  2305. * Ownership of the memory pointed to by \c normdn is tranferred to the Slapi_DN.
  2306. *
  2307. * \param sdn The target \c Slapi_DN structure.
  2308. * \param normdn The normalized DN value to be set in \c sdn.
  2309. * \return A pointer to the \c Slapi_DN structure containing the new DN value.
  2310. * \warning The caller is no longer responsible for the memory used by \c normdn.
  2311. * This memory should not be freed directly. It will be freed when
  2312. * the \c Slapi_DN is properly disposed of.
  2313. * \see slapi_sdn_set_dn_passin()
  2314. */
  2315. Slapi_DN *slapi_sdn_set_normdn_byval(Slapi_DN *sdn, const char *dn);
  2316. /**
  2317. * Sets a normalized and case ignored DN value in a \c Slapi_DN structure.
  2318. *
  2319. * The normalized DN of the structure will point to a copy of the string
  2320. * pointed to by \c ndn. The normalized DN value is passed in to the parameter
  2321. * by value.
  2322. *
  2323. * \param sdn The target \c Slapi_DN structure.
  2324. * \param ndn The normalized DN value to be set in \c sdn.
  2325. * \return A pointer to the \c Slapi_DN structure containing the new normalized DN value.
  2326. * \warning The \c ndn value is copied by the function itself. The caller
  2327. * is still responsible for the memory used by \c ndn.
  2328. * \see slapi_sdn_set_ndn_byref()
  2329. * \see slapi_sdn_set_ndn_passin()
  2330. */
  2331. Slapi_DN *slapi_sdn_set_ndn_byval(Slapi_DN *sdn, const char *ndn);
  2332. /**
  2333. * Sets a normalized DN value in a \c Slapi_DN structure.
  2334. *
  2335. * The normalized DN of the structure will point to the same string pointed to
  2336. * by \c ndn. The normalized DN value is passed in to the parameter by reference.
  2337. *
  2338. * \param sdn The target \c Slapi_DN structure.
  2339. * \param ndn The normalized DN value to be set in \c sdn.
  2340. * \return A pointer to the \c Slapi_DN structure containing the new normalized DN value.
  2341. * \warning The caller is still responsible for the memory used by \c ndn. This
  2342. * memory should not be freed until the returned \c Slapi_DN has been
  2343. * disposed of or reinitialized.
  2344. * \see slapi_sdn_set_ndn_byval()
  2345. * \see slapi_sdn_set_ndn_passin()
  2346. */
  2347. Slapi_DN *slapi_sdn_set_ndn_byref(Slapi_DN *sdn, const char *ndn);
  2348. /**
  2349. * Sets a normalized DN value in a \c Slapi_DN structure.
  2350. *
  2351. * The normalized DN of the structure will point to the same string pointed to
  2352. * by \c ndn.
  2353. * Ownership of the memory pointed to by \c ndn is tranferred to the Slapi_DN.
  2354. *
  2355. * \param sdn The target \c Slapi_DN structure.
  2356. * \param ndn The normalized DN value to be set in \c sdn.
  2357. * \return A pointer to the \c Slapi_DN structure containing the new normalized DN value.
  2358. * \see slapi_sdn_set_ndn_byval()
  2359. * \see slapi_sdn_set_ndn_byref()
  2360. */
  2361. Slapi_DN *slapi_sdn_set_ndn_passin(Slapi_DN *sdn, const char *ndn);
  2362. /**
  2363. * Clears the contents of a Slapi_DN structure.
  2364. *
  2365. * Both the DN and the normalized DN are freed if the \c Slapi_DN structure
  2366. * owns the memory. Both pointers are then set to \c NULL.
  2367. *
  2368. * \param sdn Pointer to the \c Slapi_DN to clear.
  2369. * \see slapi_sdn_free()
  2370. */
  2371. void slapi_sdn_done(Slapi_DN *sdn);
  2372. /**
  2373. * Frees a \c Slapi_DN structure.
  2374. *
  2375. * Both the DN and the normalized DN are freed if the \c Slapi_DN structure
  2376. * owns the memory. The \c Slapi_DN structure itself is then freed.
  2377. *
  2378. * \param sdn Pointer to the pointer of the \c Slapi_DN structure to be freed.
  2379. * \see slapi_sdn_done()
  2380. * \see slapi_sdn_new()
  2381. */
  2382. void slapi_sdn_free(Slapi_DN **sdn);
  2383. /**
  2384. * Retrieves the normalized DN value of a \c Slapi_DN structure.
  2385. *
  2386. * If the structure does not contain a normalized DN yet, it will normalize
  2387. * the un-normalized DN and set it in the structure.
  2388. *
  2389. * \param sdn The \c Slapi_DN strucure containing the DN value.
  2390. * \return A pointer to the DN value if one is set.
  2391. * \return A pointer to the normalized and case ignored DN value if one is set and no
  2392. * DN value is set.
  2393. * \return \c NULL if no normalized DN or normalized and case ignored DN value is set.
  2394. * \warning The pointer returned is the actual value from the structure, not a copy.
  2395. * \see slapi_sdn_get_ndn()
  2396. * \see slapi_sdn_get_udn()
  2397. */
  2398. const char * slapi_sdn_get_dn(const Slapi_DN *sdn);
  2399. /**
  2400. * Retrieves the normalized and case ignored DN value of a \c Slapi_DN structure.
  2401. *
  2402. * If the structure does not contain a normalized and case ignored DN yet,
  2403. * it will normalize and case ignore the DN and set it in the structure.
  2404. *
  2405. * \param sdn The \c Slapi_DN strucure containing the normalized and case ignored DN value.
  2406. * \return The normalized DN value.
  2407. * \return \c NULL if no DN or normalized DN value is set.
  2408. * \warning The pointer returned is the actual value from the structure, not a copy.
  2409. * \see slapi_sdn_get_dn()
  2410. * \see slapi_sdn_get_udn()
  2411. */
  2412. const char * slapi_sdn_get_ndn(const Slapi_DN *sdn);
  2413. /**
  2414. * Retrieves the un-normalized DN value of a \c Slapi_DN structure.
  2415. *
  2416. * \param sdn The \c Slapi_DN strucure containing the DN value.
  2417. * \return A pointer to the DN value if one is set.
  2418. * \return A pointer to the normalized DN value if one is set and no
  2419. * DN value is set.
  2420. * \return \c NULL if no DN or normalized DN value is set.
  2421. * \warning The pointer returned is the actual value from the structure, not a copy.
  2422. * \see slapi_sdn_get_dn()
  2423. * \see slapi_sdn_get_ndn()
  2424. */
  2425. const char * slapi_sdn_get_udn(const Slapi_DN *sdn);
  2426. /**
  2427. * Fills in an existing \c Slapi_DN structure with the parent DN of the passed in \c Slapi_DN.
  2428. *
  2429. * \param sdn Pointer to the \c Slapi_DN structure containing the DN whose parent is desired.
  2430. * \param sdn_parent Pointer to the \c Slapi_DN structure where the parent DN is returned.
  2431. * The existing contents (if any) will be cleared before the new DN value is set.
  2432. * \warning A \c Slapi_DN structure for \c sdn_parent must be allocated before calling this function.
  2433. * \see slapi_sdn_get_backend_parent()
  2434. */
  2435. void slapi_sdn_get_parent(const Slapi_DN *sdn,Slapi_DN *sdn_parent);
  2436. /**
  2437. * Fills in an existing \c Slapi_DN structure with the parent DN of the passed in \c Slapi_DN.
  2438. *
  2439. * \param sdn Pointer to the \c Slapi_DN structure containing the DN whose parent is desired.
  2440. * \param sdn_parent Pointer to the \c Slapi_DN structure where the parent DN is returned.
  2441. * The existing contents (if any) will be cleared before the new DN value is set.
  2442. * \param is_tombstone If non-zero, the special leaf rdn "nsuniqueid=.." is ignored.
  2443. * \warning A \c Slapi_DN structure for \c sdn_parent must be allocated before calling this function.
  2444. * \see slapi_sdn_get_backend_parent()
  2445. */
  2446. void slapi_sdn_get_parent_ext(const Slapi_DN *sdn,Slapi_DN *sdn_parent,int is_tombstone);
  2447. /**
  2448. * Fills in an existing \c Slapi_DN structure with the parent DN of an entry within a specific backend.
  2449. *
  2450. * The parent DN is returned in \c sdn_parent, unless \c sdn is empty or is a suffix of the backend
  2451. * itself. In this case, \c sdn_parent is empty.
  2452. *
  2453. * \param sdn Pointer to the \c Slapi_DN structure containing the DN whose parent is desired.
  2454. * \param sdn_parent Pointer to the \c Slapi_DN structure where the parent DN is returned.
  2455. * The existing contents (if any) will be cleared before the new DN value is set.
  2456. * \param backend Backend to search for the parent of \c sdn.
  2457. * \warning A \c Slapi_DN structure for \c sdn_parent must be allocated before calling this function.
  2458. * \see slapi_sdn_get_parent()
  2459. */
  2460. void slapi_sdn_get_backend_parent(const Slapi_DN *sdn,Slapi_DN *sdn_parent,const Slapi_Backend *backend);
  2461. /**
  2462. * Fills in an existing \c Slapi_DN structure with the parent DN of an entry within a specific backend.
  2463. *
  2464. * The parent DN is returned in \c sdn_parent, unless \c sdn is empty or is a suffix of the backend
  2465. * itself. In this case, \c sdn_parent is empty.
  2466. *
  2467. * \param sdn Pointer to the \c Slapi_DN structure containing the DN whose parent is desired.
  2468. * \param sdn_parent Pointer to the \c Slapi_DN structure where the parent DN is returned.
  2469. * The existing contents (if any) will be cleared before the new DN value is set.
  2470. * \param backend Backend to search for the parent of \c sdn.
  2471. * \param is_tombstone If non-zero, the special leaf rdn "nsuniqueid=.." is ignored.
  2472. * \warning A \c Slapi_DN structure for \c sdn_parent must be allocated before calling this function.
  2473. * \see slapi_sdn_get_parent()
  2474. */
  2475. void slapi_sdn_get_backend_parent_ext(const Slapi_DN *sdn,Slapi_DN *sdn_parent,const Slapi_Backend *backend,int is_tombstone);
  2476. /**
  2477. * Return the size of a \c Slapi_DN structure.
  2478. *
  2479. * \param sdn Pointer to the \c Slapi_DN structure to get the size.
  2480. */
  2481. size_t slapi_sdn_get_size(const Slapi_DN *sdn);
  2482. /**
  2483. * Duplicates a \c Slapi_DN structure.
  2484. *
  2485. * \param sdn Pointer to the \c Slapi_DN structure to duplicate.
  2486. * \return A pointer to a duplicate of \c sdn.
  2487. * \see slapi_sdn_copy()
  2488. * \see slapi_sdn_new()
  2489. * \see slapi_sdn_free()
  2490. */
  2491. Slapi_DN * slapi_sdn_dup(const Slapi_DN *sdn);
  2492. /**
  2493. * Copies the contents of a \c Slapi_DN to another \c existing Slapi_DN.
  2494. *
  2495. * \param from A pointer to the \c Slapi_DN structure to copy from.
  2496. * \param to A pointer to the \c Slapi_DN structure to copy to.
  2497. * \warning You must allocate \c to before calling this function.
  2498. * \see slapi_sdn_dup()
  2499. */
  2500. void slapi_sdn_copy(const Slapi_DN *from, Slapi_DN *to);
  2501. /**
  2502. * Compares two \c Slapi_DN structures.
  2503. *
  2504. * Performs a case-sensitive comparison of two \c Slapi_DN structures.
  2505. *
  2506. * \param sdn1 A pointer to the first \c Slapi_DN structure to compare.
  2507. * \param sdn2 A pointer to the second \c Slapi_DN structure to compare.
  2508. * \return \c 0 if \c sdn1 is equal to \c sdn2.
  2509. * \return \c -1 if \c sdn1 is \c NULL.
  2510. * \return \c 1 if \c sdn2 is \c NULL and \c sdn1 is not \c NULL.
  2511. */
  2512. int slapi_sdn_compare( const Slapi_DN *sdn1, const Slapi_DN *sdn2 );
  2513. /**
  2514. * Checks if a DN or normalized DN is set in a \c Slapi_DN.
  2515. *
  2516. * \param sdn A pointer to the \c Slapi_DN structure to check.
  2517. * \return \c 1 if there is no DN or normalized DN set in \c sdn.
  2518. * \return \c 0 if \c sdn is not empty.
  2519. * \see slapi_sdn_done()
  2520. */
  2521. int slapi_sdn_isempty( const Slapi_DN *sdn);
  2522. /**
  2523. * Checks whether a \c Slapi_DN structure contains a suffix of another \c Slapi_DN structure.
  2524. *
  2525. * \param sdn A pointer to the \c Slapi_DN structure to check.
  2526. * \param suffixsdn A pointer to the \c Slapi_DN structure of the suffix.
  2527. * \return \c 1 if the DN in \c suffixsdn is a suffix of \c sdn.
  2528. * \return \c 0 if the DN in \c suffixsdn is not a suffix of \c sdn.
  2529. * \see slapi_sdn_isparent()
  2530. * \see slapi_sdn_isgrandparent()
  2531. */
  2532. int slapi_sdn_issuffix(const Slapi_DN *sdn, const Slapi_DN *suffixsdn);
  2533. /**
  2534. * Checks whether a DN is the parent of a given DN.
  2535. *
  2536. * \param parent A pointer to the \c Slapi_DN structure containing the DN
  2537. * which claims to be the parent of the DN in \c child.
  2538. * \param child A pointer to the Slapi_DN structure containing the DN of the
  2539. * supposed child of the DN in the structure pointed to by \c parent.
  2540. * \return \c 1 if the DN in \c parent is the parent of the DN in \c child.
  2541. * \return \c 0 if the DN in \c parent is not the parent of the DN in \c child.
  2542. * \see slapi_sdn_isgrandparent()
  2543. * \see slapi_sdn_issuffix()
  2544. * \see slapi_sdn_get_parent()
  2545. */
  2546. int slapi_sdn_isparent( const Slapi_DN *parent, const Slapi_DN *child );
  2547. /**
  2548. * Checks whether a DN is the grandparent of a given DN.
  2549. *
  2550. * \param parent A pointer to the \c Slapi_DN structure containing the DN
  2551. * which claims to be the grandparent of the DN in \c child.
  2552. * \param child A pointer to the Slapi_DN structure containing the DN of the
  2553. * supposed grandchild of the DN in the structure pointed to by \c parent.
  2554. * \return \c 1 if the DN in \c parent is the grandparent of the DN in \c child.
  2555. * \return \c 0 if the DN in \c parent is not the grandparent of the DN in \c child.
  2556. * \see slapi_sdn_isparent()
  2557. * \see slapi_sdn_issuffix()
  2558. * \see slapi_sdn_get_parent()
  2559. */
  2560. int slapi_sdn_isgrandparent( const Slapi_DN *parent, const Slapi_DN *child );
  2561. /**
  2562. * Gets the length of the normalized DN of a Slapi_DN structure.
  2563. *
  2564. * This function normalizes \c sdn if it has not already been normalized.
  2565. *
  2566. * \param sdn A pointer to the \c Slapi_DN structure containing the DN value.
  2567. * \return The length of the normalized DN.
  2568. */
  2569. int slapi_sdn_get_ndn_len(const Slapi_DN *sdn);
  2570. /**
  2571. * Checks if a DN is within a specified scope under a specified base DN.
  2572. *
  2573. * \param dn A pointer to the \c Slapi_DN structure to test.
  2574. * \param base The base DN against which \c dn is going to be tested.
  2575. * \param scope The scope tested. Valid scopes are:
  2576. * \arg \c LDAP_SCOPE_BASE
  2577. * \arg \c LDAP_SCOPE_ONELEVEL
  2578. * \arg \c LDAP_SCOPE_SUBTREE
  2579. * \return non-zero if \c dn matches the scoping criteria given by \c base and \c scope.
  2580. * \see slapi_sdn_compare()
  2581. * \see slapi_sdn_isparent()
  2582. * \see slapi_sdn_issuffix()
  2583. */
  2584. int slapi_sdn_scope_test( const Slapi_DN *dn, const Slapi_DN *base, int scope );
  2585. /**
  2586. * Checks if a DN is within a specified scope under a specified base DN.
  2587. * This api adjusts tombstoned DN when comparing with the base dn.
  2588. *
  2589. * \param dn A pointer to the \c Slapi_DN structure to test.
  2590. * \param base The base DN against which \c dn is going to be tested.
  2591. * \param scope The scope tested. Valid scopes are:
  2592. * \arg \c LDAP_SCOPE_BASE
  2593. * \arg \c LDAP_SCOPE_ONELEVEL
  2594. * \arg \c LDAP_SCOPE_SUBTREE
  2595. * \param flags 0 or SLAPI_ENTRY_FLAG_TOMBSTONE
  2596. * \return non-zero if \c dn matches the scoping criteria given by \c base and \c scope.
  2597. * \see slapi_sdn_compare()
  2598. * \see slapi_sdn_isparent()
  2599. * \see slapi_sdn_issuffix()
  2600. */
  2601. int slapi_sdn_scope_test_ext( const Slapi_DN *dn, const Slapi_DN *base, int scope, int flags );
  2602. /**
  2603. * Retreives the RDN from a given DN.
  2604. *
  2605. * This function takes the DN stored in the \c Slapi_DN structure pointed to
  2606. * by \c sdn and fills in it's RDN within the \c Slapi_RDN structure pointed
  2607. * to by \c rdn.
  2608. *
  2609. * \param sdn A pointer to the \c Slapi_DN structure containing the DN.
  2610. * \param rdn A pointer to the \c Slapi_RDN structure where the RDN is filled in.
  2611. * \warning The caller must allocate \c rdn before calling this function.
  2612. * \see slapi_sdn_get_dn()
  2613. * \see slapi_sdn_set_rdn()
  2614. * \see slapi_sdn_add_rdn()
  2615. * \see slapi_sdn_is_rdn_component()
  2616. */
  2617. void slapi_sdn_get_rdn(const Slapi_DN *sdn,Slapi_RDN *rdn);
  2618. /**
  2619. * Sets a new RDN for a given DN.
  2620. *
  2621. * This function changes the RDN of \c sdn by adding the value from
  2622. * \c rdn to the parent DN of \c sdn.
  2623. *
  2624. * \param sdn The DN that you want to rename.
  2625. * \param rdn The new RDN.
  2626. * \return A pointer to the \c Slapi_DN structure that has been renamed.
  2627. * \see slapi_sdn_get_rdn()
  2628. */
  2629. Slapi_DN *slapi_sdn_set_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn);
  2630. /**
  2631. * Sets a new parent for a given DN.
  2632. *
  2633. * This function keeps the RDN of the original DN and adds it to the
  2634. * specified parent DN.
  2635. *
  2636. * \param sdn The \c Slapi_DN structure containing the DN whose parent you want to change.
  2637. * \param parentdn The \c Slapi_DN structure containing the new parent DN.
  2638. * \return A pointer to the \c Slapi_DN structure that contains the new DN.
  2639. * \see slapi_sdn_isparent()
  2640. * \see slapi_sdn_get_parent()
  2641. */
  2642. Slapi_DN *slapi_sdn_set_parent(Slapi_DN *sdn, const Slapi_DN *parentdn);
  2643. /**
  2644. * Builds a new DN out of a new RDN and the DN of the new parent.
  2645. *
  2646. * The new DN is worked out by adding the new RDN in \c newrdn to a
  2647. * parent DN. The parent will be the value in \c newsuperiordn if different
  2648. * from \c NULL, and will otherwise be taken from \c dn_olddn by removing
  2649. * the old RDN (the parent of the entry will still be the same as the new DN).
  2650. *
  2651. * \param dn_olddn The old DN value.
  2652. * \param newrdn The new RDN value.
  2653. * \param newsuperiordn If not \c NULL, will be the DN of the future superior
  2654. * entry of the new DN, which will be worked out by adding the value
  2655. * in \c newrdn in front of the content of this parameter.
  2656. * \return The new DN for the entry whose previous DN was \c dn_olddn.
  2657. */
  2658. char * slapi_moddn_get_newdn(Slapi_DN *dn_olddn, const char *newrdn, const char *newsuperiordn);
  2659. Slapi_DN *slapi_sdn_add_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn);
  2660. /*
  2661. * Slapi_RDN functions
  2662. */
  2663. /**
  2664. * Creates a new \c Slapi_RDN structure.
  2665. *
  2666. * Allocates the necessary memory and initializes both the
  2667. * RDN value and the array of split RDNs to \c NULL.
  2668. *
  2669. * \return A pointer to the newly allocated, and still empty, \c Slapi_RDN structure.
  2670. * \warning You must free the returned \c Slapi_RDN structure by calling \c slapi_rdn_free()
  2671. * when you are finished using it.
  2672. * \see slapi_rdn_init()
  2673. * \see slapi_rdn_done()
  2674. * \see slapi_rdn_free()
  2675. */
  2676. Slapi_RDN *slapi_rdn_new( void );
  2677. /**
  2678. * Creates a new \c Slapi_RDN structure and initializes it from a string.
  2679. *
  2680. * \param dn The DN value whose RDN will be used to initialize the new
  2681. * \c Slapi_RDN structure.
  2682. * \return A pointer to the newly allocated and initialized \c Slapi_RDN structure.
  2683. * \warning You must free the returned \c Slapi_RDN structure by calling \c slapi_rdn_free()
  2684. * when you are finished using it.
  2685. * \see slapi_rdn_new_sdn()
  2686. * \see slapi_rdn_new_rdn()
  2687. * \see slapi_rdn_free()
  2688. */
  2689. Slapi_RDN *slapi_rdn_new_dn(const char *dn);
  2690. /**
  2691. * Creates a new \c Slapi_RDN structure and initializes it from a \c Slapi_DN.
  2692. *
  2693. * \param sdn The \c Slapi_DN structure whose RDN will be used to initialize
  2694. * the new \c Slapi_RDN structure.
  2695. * \return A pointer to the newly allocated and initialized \c Slapi_RDN structure.
  2696. * \warning You must free the returned \c Slapi_RDN structure by calling \c slapi_rdn_free()
  2697. * when you are finished using it.
  2698. * \see slapi_rdn_new_dn()
  2699. * \see slapi_rdn_new_rdn()
  2700. * \see slapi_rdn_free()
  2701. */
  2702. Slapi_RDN *slapi_rdn_new_sdn(const Slapi_DN *sdn);
  2703. /**
  2704. * Creates a new \c Slapi_RDN structure and initializes it from a \c Slapi_RDN.
  2705. *
  2706. * \param fromrdn The \c Slapi_RDN structure whose RDN will be used to initialize
  2707. * the new \c Slapi_RDN structure.
  2708. * \return A pointer to the newly allocated and initialized \c Slapi_RDN structure.
  2709. * \warning You must free the returned \c Slapi_RDN structure by calling \c slapi_rdn_free()
  2710. * when you are finished using it.
  2711. * \see slapi_rdn_new_dn()
  2712. * \see slapi_rdn_new_sdn()
  2713. * \see slapi_rdn_free()
  2714. */
  2715. Slapi_RDN *slapi_rdn_new_rdn(const Slapi_RDN *fromrdn);
  2716. /**
  2717. * Clears out a \c Slapi_RDN structure.
  2718. *
  2719. * Sets both the RDN value and the array of split RDNs to \c NULL.
  2720. *
  2721. * \param rdn The \c Slapi_RDN structure to be initialized.
  2722. * \warning The previous contents of \c rdn are not freed. It is
  2723. * up to the caller to do this first if necessary.
  2724. * \see slapi_rdn_new()
  2725. * \see slapi_rdn_free()
  2726. * \see slapi_rdn_done()
  2727. */
  2728. void slapi_rdn_init(Slapi_RDN *rdn);
  2729. /**
  2730. * Initializes a \c Slapi_RDN structure from a string.
  2731. *
  2732. * \param rdn The \c Slapi_RDN structure to be initialized.
  2733. * \param dn The DN value whose RDN will be used to initialize \c rdn.
  2734. * \warning The previous contents of \c rdn are not freed. It is
  2735. * up to the caller to do this first if necessary.
  2736. * \see slapi_rdn_done()
  2737. * \see slapi_rdn_init_sdn()
  2738. * \see slapi_rdn_init_rdn()
  2739. */
  2740. void slapi_rdn_init_dn(Slapi_RDN *rdn,const char *dn);
  2741. /**
  2742. * Initializes a \c Slapi_RDN structure from a \c Slapi_DN.
  2743. *
  2744. * \param rdn The \c Slapi_RDN structure to be initialized.
  2745. * \param sdn The \c Slapi_DN whose RDN will be used to initialize \c rdn.
  2746. * \warning The previous contents of \c rdn are not freed. It is
  2747. * up to the caller to do this first if necessary.
  2748. * \see slapi_rdn_done()
  2749. * \see slapi_rdn_init_dn()
  2750. * \see slapi_rdn_init_rdn()
  2751. */
  2752. void slapi_rdn_init_sdn(Slapi_RDN *rdn,const Slapi_DN *sdn);
  2753. /**
  2754. * Initializes a \c Slapi_RDN structure from another \c Slapi_RDN.
  2755. *
  2756. * \param rdn The \c Slapi_RDN structure to be initialized.
  2757. * \param fromrdn The \c Slapi_RDN structure that will be used to
  2758. * initialize \c rdn.
  2759. * \warning The previous contents of \c rdn are not freed. It is
  2760. * up to the caller to do this first if necessary.
  2761. * \see slapi_rdn_done()
  2762. * \see slapi_rdn_init_dn()
  2763. * \see slapi_rdn_init_sdn()
  2764. */
  2765. void slapi_rdn_init_rdn(Slapi_RDN *rdn,const Slapi_RDN *fromrdn);
  2766. /**
  2767. * Sets the RDN value in a \c Slapi_RDN structure from a string.
  2768. *
  2769. * The previous contents of the \c rdn are freed before
  2770. * the new RDN is set.
  2771. *
  2772. * \param rdn The target \c Slapi_RDN structure.
  2773. * \param dn The DN value whose RDN will be set in \c rdn.
  2774. * \see slapi_rdn_set_sdn()
  2775. * \see slapi_rdn_set_rdn()
  2776. */
  2777. void slapi_rdn_set_dn(Slapi_RDN *rdn,const char *dn);
  2778. Slapi_RDN *slapi_rdn_new_all_dn(const char *dn);
  2779. int slapi_rdn_init_all_dn(Slapi_RDN *rdn, const char *dn);
  2780. int slapi_rdn_init_all_sdn(Slapi_RDN *rdn, const Slapi_DN *sdn);
  2781. /**
  2782. * Sets the RDN value in a \c Slapi_RDN structure from a \c Slapi_DN.
  2783. *
  2784. * The previous contents of the \c rdn are freed before
  2785. * the new RDN is set.
  2786. *
  2787. * \param rdn The target \c Slapi_RDN structure.
  2788. * \param sdn The \c Slapi_DN value whose RDN will be set in \c rdn.
  2789. * \see slapi_rdn_set_dn()
  2790. * \see slapi_rdn_set_rdn()
  2791. */
  2792. void slapi_rdn_set_sdn(Slapi_RDN *rdn,const Slapi_DN *sdn);
  2793. /**
  2794. * Sets the RDN value in a \c Slapi_RDN structure from a \c Slapi_RDN.
  2795. *
  2796. * The previous contents of the \c rdn are freed before
  2797. * the new RDN is set.
  2798. *
  2799. * \param rdn The target \c Slapi_RDN structure.
  2800. * \param fromrdn The \c Slapi_RDN value whose RDN will be set in \c rdn.
  2801. * \see slapi_rdn_set_dn()
  2802. * \see slapi_rdn_set_sdn()
  2803. */
  2804. void slapi_rdn_set_rdn(Slapi_RDN *rdn,const Slapi_RDN *fromrdn);
  2805. /**
  2806. * Frees a \c Slapi_RDN structure and it's contents from memory.
  2807. *
  2808. * \param rdn A pointer to a pointer of the \c Slapi_RDN strucure to be freed.
  2809. * \see slapi_rdn_new()
  2810. * \see slapi_rdn_done()
  2811. */
  2812. void slapi_rdn_free(Slapi_RDN **rdn);
  2813. /**
  2814. * Checks if the value of ipAddress is a IPv6 address
  2815. *
  2816. * \param ipAddress is a string that is either an IPv4 or IPv6 address
  2817. * \return 1 if address is an IPv6 address
  2818. * \return 0 if address is an IPv4 address
  2819. */
  2820. int slapi_is_ipv6_addr( const char *ipAddress);
  2821. /**
  2822. * Returns the length of a ber-encoded ldap operation
  2823. *
  2824. * \param bv is the berval of the encoded ldap operation
  2825. * \param strict set to 0 if "bv" does not contain the entire LDAP encoding
  2826. * \return -1 if the length can not be determined
  2827. * \return length
  2828. */
  2829. ber_len_t slapi_berval_get_msg_len(struct berval *bv, int strict);
  2830. /**
  2831. * Frees and clears the contents of a \c Slapi_RDN structure from memory.
  2832. *
  2833. * Both the RDN value and the array of split RDNs are freed. Those pointers
  2834. * are then set to \c NULL.
  2835. *
  2836. * \param rdn A pointer to the \c Slapi_RDN strucure to clear.
  2837. * \see slapi_rdn_free()
  2838. * \see slapi_rdn_init()
  2839. */
  2840. void slapi_rdn_done(Slapi_RDN *rdn);
  2841. /**
  2842. * Gets the first RDN stored in a \c Slapi_RDN structure.
  2843. *
  2844. * The type and the value of the first RDN are retrieved.
  2845. *
  2846. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2847. * \param type Address to return a pointer to the type of the first RDN. If
  2848. * this is \c NULL at the return of the function, it means that \c rdn
  2849. * is empty.
  2850. * \param value Address to return a pointer to the value of the first RDN.
  2851. * If this is \c NULL at the return of the function, it means that
  2852. * \c rdn is empty.
  2853. * \return \c -1 if \c rdn is empty.
  2854. * \return \c 1 if the operation is successful.
  2855. * \warning Do not free the returned type or value.
  2856. * \see slapi_rdn_get_next()
  2857. * \see slapi_rdn_get_rdn()
  2858. */
  2859. int slapi_rdn_get_first(Slapi_RDN *rdn, char **type, char **value);
  2860. /**
  2861. * Gets the next RDN stored in a \c Slapi_RDN structure.
  2862. *
  2863. * The type/value pair for the RDN at the position following that indicated
  2864. * by \c index will be retrieved.
  2865. *
  2866. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2867. * \param index Indicates the position that precedes that of the desired RDN.
  2868. * For example, pass 1 if you would like the second RDN.
  2869. * \param type Address to return a pointer to the type of the next RDN. If
  2870. * this is \c NULL at the return of the function, it means that \c rdn
  2871. * is empty.
  2872. * \param value Address to return a pointer to the value of the next RDN.
  2873. * If this is \c NULL at the return of the function, it means that
  2874. * \c rdn is empty.
  2875. * \return \c -1 if no RDN exists at the index position.
  2876. * \return The position (\c index + \c 1) of the retrieved RDN if the operation is successful.
  2877. * \see slapi_rdn_get_first()
  2878. * \see slapi_rdn_get_rdn()
  2879. */
  2880. int slapi_rdn_get_next(Slapi_RDN *rdn, int index, char **type, char **value);
  2881. /**
  2882. * Finds a RDN in a \c Slapi_RDN structure and returns it's index.
  2883. *
  2884. * The \c Slapi_RDN structure will be searched for a RDN matching
  2885. * the given type and value.
  2886. *
  2887. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2888. * \param type Type (\c cn, \c o, \c ou, etc.) of the RDN that is searched for.
  2889. * \param value Value of the RDN that is searched for.
  2890. * \param length Gives the length of the value that should be taken into
  2891. * account for the string comparisons when searching for the RDN.
  2892. * \return The index of the RDN that matches \c type and \c value.
  2893. * \return \c -1 if no RDN stored in \c rdn matches \c type and \c value.
  2894. * \see slapi_rdn_get_index_attr()
  2895. * \see slapi_rdn_contains()
  2896. */
  2897. int slapi_rdn_get_index(Slapi_RDN *rdn, const char *type, const char *value,size_t length);
  2898. /**
  2899. * Finds a RDN for a given type in a \c Slapi_RDN structure and returns it's index.
  2900. *
  2901. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2902. * \param type Type (\c cn, \c o, \c ou, etc.) of the RDN that is searched for.
  2903. * \param value Address to return a pointer to the value of the next RDN.
  2904. * If this is \c NULL at the return of the function, it means that
  2905. * no matching RDN exist in \c rdn.
  2906. * \return The index of the RDN that matches \c type.
  2907. * \return \c -1 if no RDN stored in \c rdn matches \c type.
  2908. * \see slapi_rdn_get_index()
  2909. */
  2910. int slapi_rdn_get_index_attr(Slapi_RDN *rdn, const char *type, char **value);
  2911. /**
  2912. * Checks if a RDN exists in a \c Slapi_RDN structure.
  2913. *
  2914. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2915. * \param type Type (\c cn, \c o, \c ou, etc.) of the RDN that is searched for.
  2916. * \param value Value of the RDN that is searched for.
  2917. * \param length Gives the length of the value that should be taken into
  2918. * account for the string comparisons when searching for the RDN.
  2919. * \return \c 1 if \c rdn contains a RDN that matches \c type and \c value.
  2920. * \return \c 0 if no RDN stored in \c rdn matches \c type and \c value.
  2921. * \see slapi_rdn_get_index()
  2922. * \see slapi_rdn_contains_attr()
  2923. */
  2924. int slapi_rdn_contains(Slapi_RDN *rdn, const char *type, const char *value,size_t length);
  2925. /**
  2926. * Checks if a RDN for a given type exists in a \c Slapi_RDN structure.
  2927. *
  2928. * \param rdn The \c Slapi_RDN structure containing the RDN value(s).
  2929. * \param type Type (\c cn, \c o, \c ou, etc.) of the RDN that is searched for.
  2930. * \param value Address to return a pointer to the value of the next RDN.
  2931. * If this is \c NULL at the return of the function, it means that
  2932. * no matching RDN exist in \c rdn.
  2933. * \return \c 1 if \c rdn contains a RDN that matches \c type.
  2934. * \return \c 0 if no RDN stored in \c rdn matches \c type.
  2935. * \see slapi_rdn_get_index_attr()
  2936. * \see slapi_rdn_contains()
  2937. */
  2938. int slapi_rdn_contains_attr(Slapi_RDN *rdn, const char *type, char **value);
  2939. /**
  2940. * Adds a new RDN to a \c Slapi_RDN structure.
  2941. *
  2942. * A new type/value pair will be added to an existing RDN, or the type/value
  2943. * pair will be set as the new RDN if \c rdn is empty. This function resets the
  2944. * FLAG_RDNS flags, which means that the RDN array with-in the \c Slapi_RDN
  2945. * structure is no longer current with the new RDN.
  2946. *
  2947. * \param rdn The target \c Slapi_RDN structure.
  2948. * \param type The type (\c cn, \c o, \c ou, etc.) of the RDN to be added.
  2949. * This parameter cannot be \c NULL.
  2950. * \param value The value of the RDN to be added. This parameter cannot
  2951. * be \c NULL.
  2952. * \return Always returns 1.
  2953. * \see slapi_rdn_get_num_components()
  2954. */
  2955. int slapi_rdn_add(Slapi_RDN *rdn, const char *type, const char *value);
  2956. /**
  2957. * Removes a RDN from a \c Slapi_RDN structure at a given position.
  2958. *
  2959. * \param rdn The target \c Slapi_RDN structure.
  2960. * \param atindex The index of the RDN type/value pair to remove.
  2961. * \return \c 1 if the RDN is removed from \c rdn.
  2962. * \return \c 0 if no RDN is removed because either \c rdn is empty
  2963. * or \c atindex goes beyond the number of RDNs present.
  2964. * \see slapi_rdn_remove()
  2965. * \see slapi_rdn_remove_attr()
  2966. */
  2967. int slapi_rdn_remove_index(Slapi_RDN *rdn, int atindex);
  2968. /**
  2969. * Removes a RDN from a \c Slapi_RDN structure matching a given type/value pair.
  2970. *
  2971. * \param rdn The target \c Slapi_RDN structure.
  2972. * \param type The type (\c cn, \c o, \c ou, etc.) of the RDN to be removed.
  2973. * \param value The value of the RDN to be removed.
  2974. * \param length Gives the length of the value that should be taken into
  2975. * account for the string comparisons when searching for the RDN.
  2976. * \return \c 1 if the RDN is removed from \c rdn.
  2977. * \return \c 0 if no RDN is removed.
  2978. * \see slapi_rdn_remove_attr()
  2979. * \see slapi_rdn_remove_index()
  2980. */
  2981. int slapi_rdn_remove(Slapi_RDN *rdn, const char *type, const char *value, size_t length);
  2982. /**
  2983. * Removes a RDN from a \c Slapi_RDN structure matching a given type.
  2984. *
  2985. * \param rdn The target \c Slapi_RDN structure.
  2986. * \param type The type (\c cn, \c o, \c ou, etc.) of the RDN to be removed.
  2987. * \return \c 1 if the RDN is removed from \c rdn.
  2988. * \return \c 0 if no RDN is removed.
  2989. * \see slapi_rdn_remove()
  2990. * \see slapi_rdn_remove_index()
  2991. */
  2992. int slapi_rdn_remove_attr(Slapi_RDN *rdn, const char *type);
  2993. /**
  2994. * Checks whether a RDN value is stored in a \c Slapi_RDN structure.
  2995. *
  2996. * \param rdn The target \c Slapi_RDN structure.
  2997. * \return \c 1 if there is no RDN value present.
  2998. * \return \c 0 if rdn contains a value.
  2999. * \see slapi_rdn_init()
  3000. * \see slapi_rdn_done()
  3001. * \see slapi_rdn_free()
  3002. */
  3003. int slapi_rdn_isempty(const Slapi_RDN *rdn);
  3004. /**
  3005. * Gets the number of RDN type/value pairs present in a \c Slapi_RDN structure.
  3006. *
  3007. * \param rdn The target \c Slapi_RDN structure.
  3008. * \return The number of RDN type/value pairs present in \c rdn.
  3009. * \see slapi_rdn_add()
  3010. */
  3011. int slapi_rdn_get_num_components(Slapi_RDN *rdn);
  3012. /**
  3013. * Compares two \c Slapi_RDN structures.
  3014. *
  3015. * For RDNs to be considered equal, the order of their components
  3016. * do not have to be the same.
  3017. *
  3018. * \param rdn1 The first RDN to compare.
  3019. * \param rdn2 The second RDN to compare.
  3020. * \return \c 0 if \c rdn1 and \c rdn2 have the same RDN components.
  3021. * \return \c -1 if they do not have the same components.
  3022. */
  3023. int slapi_rdn_compare(Slapi_RDN *rdn1, Slapi_RDN *rdn2);
  3024. /**
  3025. * Gets the RDN from a \c Slapi_RDN structure.
  3026. *
  3027. * \param rdn The \c Slapi_RDN structure holding the RDN value.
  3028. * \return The RDN value.
  3029. * \warning Do not free the returned RDN value.
  3030. */
  3031. const char *slapi_rdn_get_rdn(const Slapi_RDN *rdn);
  3032. /**
  3033. * Adds a RDN from a \c Slapi_RDN structure to a DN in a \c Slapi_DN structure.
  3034. *
  3035. * The RDN in the \c Slapi_RDN structure will be appended to the DN
  3036. * value in \c sdn.
  3037. *
  3038. * \param sdn \c Slapi_DN structure containing the value to which
  3039. * a new RDN is to be added.
  3040. * \param rdn \c Slapi_RDN structure containing the RDN value
  3041. * that is to be added to the DN value.
  3042. * \return The \c Slapi_DN structure with the new DN.
  3043. * \see slapi_sdn_set_rdn()
  3044. */
  3045. Slapi_DN *slapi_sdn_add_rdn(Slapi_DN *sdn, const Slapi_RDN *rdn);
  3046. /* Function: slapi_rdn_set_all_dn
  3047. Description: this function sets exploded RDNs of DN to Slapi_RDN
  3048. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3049. dn - distinguished name which is to be exploded into RDNs and
  3050. set to Slapi_RDN
  3051. Return: none
  3052. */
  3053. void slapi_rdn_set_all_dn(Slapi_RDN *rdn,const char *dn);
  3054. /**
  3055. * Gets the normalized RDN from a \c Slapi_RDN structure
  3056. *
  3057. * \param rdn The \c Slapi_RDN structure holding the RDN value.
  3058. * \return The normalized RDN value.
  3059. */
  3060. const char *slapi_rdn_get_nrdn(Slapi_RDN *srdn);
  3061. /* Function: slapi_rdn_get_first_ext
  3062. Description: this function returns the first RDN in RDN array. The RDN
  3063. array is supposed to store all the RDNs of DN.
  3064. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3065. firstrdn - a container to store the address of the first RDN.
  3066. The caller should not free the returned address.
  3067. flag - type of the returned RDN. one of the followings:
  3068. FLAG_ALL_RDNS -- raw (not normalized)
  3069. FLAG_ALL_NRDNS -- normalized
  3070. Return: the index of the first rdn 0, if function succeeds.
  3071. -1, if it fails.
  3072. */
  3073. int slapi_rdn_get_first_ext(Slapi_RDN *srdn, const char **firstrdn, int flag);
  3074. /* Function: slapi_rdn_get_last_ext
  3075. Description: this function returns the last RDN in RDN array. The RDN
  3076. array is supposed to store all the RDNs of DN.
  3077. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3078. lastrdn - a container to store the address of the last RDN.
  3079. The caller should not free the returned address.
  3080. flag - type of the returned RDN. one of the followings:
  3081. FLAG_ALL_RDNS -- raw (not normalized)
  3082. FLAG_ALL_NRDNS -- normalized
  3083. Return: the index of the last rdn, if function succeeds.
  3084. -1, if it fails.
  3085. */
  3086. int slapi_rdn_get_last_ext(Slapi_RDN *srdn, const char **lastrdn, int flag);
  3087. /* Function: slapi_rdn_get_prev_ext
  3088. Description: this function returns the previous RDN of the given index (idx)
  3089. in RDN array.
  3090. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3091. idx - a return value of the previous slapi_rdn_get_last_ext
  3092. or slapi_rdn_get_prev_ext or slapi_rdn_get_next_ext call.
  3093. prevrdn - a container to store the address of the previous RDN.
  3094. The caller should not free the returned address.
  3095. flag - type of the returned RDN. one of the followings:
  3096. FLAG_ALL_RDNS -- raw (not normalized)
  3097. FLAG_ALL_NRDNS -- normalized
  3098. Return: the index of the returned rdn, if function succeeds.
  3099. -1, if it fails.
  3100. */
  3101. int slapi_rdn_get_prev_ext(Slapi_RDN *srdn, int idx, const char **prevrdn, int flag);
  3102. /* Function: slapi_rdn_get_next_ext
  3103. Description: this function returns the next RDN of the given index (idx)
  3104. in RDN array.
  3105. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3106. idx - a return value of the previous slapi_rdn_get_prev_ext
  3107. or slapi_rdn_get_next_ext call.
  3108. nextrdn - a container to store the address of the next RDN.
  3109. The caller should not free the returned address.
  3110. flag - type of the returned RDN. one of the followings:
  3111. FLAG_ALL_RDNS -- raw (not normalized)
  3112. FLAG_ALL_NRDNS -- normalized
  3113. Return: the index of the returned rdn, if function succeeds.
  3114. -1, if it fails.
  3115. */
  3116. int slapi_rdn_get_next_ext(Slapi_RDN *srdn, int idx, const char **nextrdn, int flag);
  3117. /* Function: slapi_rdn_add_rdn_to_all_rdns
  3118. Description: this function appends the given RDN to the RDN array in
  3119. Slapi_RDN.
  3120. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3121. addrdn - an RDN string to append.
  3122. byref - non 0, then the passed addrdn is put in the RDN array.
  3123. 0, then the duplicated addrdn is put in the RDN array.
  3124. Return: 0, if the function succeeds.
  3125. -1, if it fails.
  3126. */
  3127. int slapi_rdn_add_rdn_to_all_rdns(Slapi_RDN *srdn, char *addrdn, int byref);
  3128. /* Function: slapi_rdn_add_srdn_to_all_rdns
  3129. Description: this function appends the given Slapi_RDN to the RDN array in
  3130. Slapi_RDN.
  3131. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3132. addsrdn - Slapi_RDN to append.
  3133. Return: 0, if the function succeeds.
  3134. -1, if it fails.
  3135. */
  3136. int slapi_rdn_add_srdn_to_all_rdns(Slapi_RDN *srdn, Slapi_RDN *addsrdn);
  3137. /* Function: slapi_rdn_get_dn
  3138. Description: this function generates DN string if it stores RDNs in its
  3139. all_rdns field.
  3140. Parameters: srdn - a pointer to Slapi_RDN which stores RDN array
  3141. dn -- a container to store the address of DN; dn is allocated
  3142. in this function.
  3143. Return: 0, if the function succeeds.
  3144. -1, if it fails (e.g., srdn is NULL, dn is NULL, or srdn does not
  3145. have RDN array in it.
  3146. */
  3147. int slapi_rdn_get_dn(Slapi_RDN *srdn, char **dn);
  3148. /* Function: slapi_srdn_copy
  3149. Description: this function copies "from" Slapi_RDN structure to "to"
  3150. Parameters: from - a pointer to source Slapi_RDN
  3151. to -- an address to store the copied Slapi_RDN.
  3152. Return: 0, if the function succeeds.
  3153. -1, if it fails
  3154. */
  3155. int slapi_srdn_copy(const Slapi_RDN *from, Slapi_RDN *to);
  3156. /* Function: slapi_srdn_copy
  3157. Description: this function replaces the rdn in Slapi_RDN with new_rdn
  3158. Parameters: srdn - a pointer to Slapi_RDN
  3159. new_rdn -- new rdn set to Slapi_RDN
  3160. Return: 0, if the function succeeds.
  3161. -1, if it fails
  3162. */
  3163. int slapi_rdn_replace_rdn(Slapi_RDN *srdn, char *new_rdn);
  3164. /* Function: slapi_rdn_partial_dup
  3165. Description: this function partially duplicates "from" Slapi_RDN structure and set it to "to"
  3166. Parameters: from - a pointer to source Slapi_RDN
  3167. to -- an address to store the partially copied Slapi_RDN.
  3168. idx -- index from which the duplicate begins
  3169. Return: 0, if the function succeeds.
  3170. -1, if it fails
  3171. */
  3172. int slapi_rdn_partial_dup(Slapi_RDN *from, Slapi_RDN **to, int idx);
  3173. /**
  3174. * Return the size of the RDN
  3175. *
  3176. * \param srdn A pointer to Slapi_RDN to calculate the size
  3177. * \return The size of the given RDN.
  3178. */
  3179. size_t slapi_rdn_get_size(Slapi_RDN *srdn);
  3180. /**
  3181. * Return the value of the RDN
  3182. *
  3183. * \param rdn A pointer to rdn to get the value.
  3184. * \return The value of the given RDN.
  3185. */
  3186. char * slapi_rdn_get_value(const char *rdn);
  3187. /*
  3188. * utility routines for dealing with DNs
  3189. */
  3190. /**
  3191. * Does nothing. (DEPRECATED)
  3192. *
  3193. * \param dn The DN to normalize.
  3194. * \return The normalized DN.
  3195. * \deprecated Use slapi_dn_normalized_ext.
  3196. */
  3197. char *slapi_dn_normalize( char *dn );
  3198. /**
  3199. * Does nothing. (DEPRECATED)
  3200. *
  3201. * \param dn The DN value to normalize.
  3202. * \param end Pointer to the end of what will be normalized from the DN
  3203. * value in \c dn. If this parameter is \c NULL, the DN value
  3204. * will be wholly normalized.
  3205. * \return The normalized DN.
  3206. * \deprecated Use slapi_dn_normalized_ext.
  3207. */
  3208. char *slapi_dn_normalize_to_end( char *dn, char *end );
  3209. /**
  3210. * Normalizes a DN.
  3211. *
  3212. * \param src The DN to normalize.
  3213. * \param src_len The length of src DN to normalize. If 0 is given, strlen(src) is used.
  3214. * \param dest The normalized DN.
  3215. * \param dest The length of the normalized DN dest.
  3216. * \return \c 0 if successful. The dest DN is normalized in line. Caller must not free dest.
  3217. * \return \c 1 if successful. The dest DN is allocated. Caller must free dest.
  3218. * \return \c -1 if an error occurs (for example, if the src DN cannot be normalized)
  3219. */
  3220. int slapi_dn_normalize_ext(char *src, size_t src_len, char **dest, size_t *dest_len);
  3221. /**
  3222. * Normalizes a DN (in lower-case characters).
  3223. *
  3224. * \param src The DN to normalize.
  3225. * \param src_len The length of src DN to normalize. If 0 is given, strlen(src) is used internally.
  3226. * \param dest The normalized DN with the cases lowered.
  3227. * \param dest_len The length of the normalized DN dest.
  3228. * \return \c 0 if successful. The dest DN is normalized in line. Caller must not free dest. The string is NOT NULL terminated.
  3229. * \return \c 1 if successful. The dest DN is allocated. Caller must free dest.
  3230. * \return \c -1 if an error occurs (for example, if src DN cannot be normalized)
  3231. */
  3232. int slapi_dn_normalize_case_ext(char *src, size_t src_len, char **dest, size_t *dest_len);
  3233. /**
  3234. * Generate a valid DN string.
  3235. *
  3236. * \param fmt The format used to generate a DN string.
  3237. * \param ... The arguments to generate a DN string.
  3238. * \return A pointer to the generated DN.
  3239. * \return NULL if failed.
  3240. * \note When a DN needs to be internally created, this function is supposed to be called. This function allocates the enough memory for the normalized DN and returns it filled with the normalized DN.
  3241. */
  3242. char *slapi_create_dn_string(const char *fmt, ...);
  3243. /**
  3244. * Generates a valid DN string (in lower-case characters).
  3245. *
  3246. * \param fmt The format used to generate a DN string.
  3247. * \param ... The arguments to generate a DN string.
  3248. * \return A pointer to the generated DN.
  3249. * \return NULL if failed.
  3250. */
  3251. char *slapi_create_dn_string_case(const char *fmt, ...);
  3252. /**
  3253. * Generates a valid value of RDN string
  3254. *
  3255. * \param fmt The format used to generate a value of RDN string.
  3256. * \param ... The arguments to generate an RDN string.
  3257. * \return A pointer to the generated RDN value.
  3258. * \return NULL if failed.
  3259. */
  3260. char *slapi_create_rdn_value(const char *fmt, ...);
  3261. /**
  3262. * Converts a DN to lowercase.
  3263. *
  3264. * \param dn The DN to convert.
  3265. * \return A pointer to the converted DN.
  3266. * \deprecated Use slapi_sdn_get_ndn() instead to normalize the case,
  3267. * or use slapi_sdn_compare() to compare regardless of case.
  3268. */
  3269. char *slapi_dn_ignore_case( char *dn );
  3270. /**
  3271. * Converts a DN to canonical format and converts all characters to lowercase.
  3272. *
  3273. * \param dn DN that you want to normalize and convert to lowercase.
  3274. * \return The normalized and converted DN.
  3275. * \note The \c dn parameter is converted in place.
  3276. */
  3277. char *slapi_dn_normalize_case( char *dn );
  3278. /**
  3279. * Get a copy of the parent DN of a DN.
  3280. *
  3281. * \param pb A parameter block with the backend set.
  3282. * \param dn The DN whose parent is desired.
  3283. * \return A pointer to the parent DN of \c dn.
  3284. * \return \c NULL if the DN is a suffix of the backend.
  3285. * \warning The caller must free the returned DN when finished with it.
  3286. * \deprecated Use slapi_sdn_get_backend_parent() instead.
  3287. */
  3288. char *slapi_dn_beparent( Slapi_PBlock *pb, const char *dn );
  3289. /**
  3290. * Finds the parent DN of a DN within the same string.
  3291. *
  3292. * \param dn The DN whose parent DN is desired.
  3293. * \return A pointer to the parent DN within \c dn.
  3294. */
  3295. const char *slapi_dn_find_parent( const char *dn );
  3296. /**
  3297. * Finds the parent DN of a DN within the same string.
  3298. *
  3299. * \param dn The DN whose parent DN is desired.
  3300. * \param is_tombstone If non-zero, the special leaf rdn "nsuniqueid=.." is ignored.
  3301. * \return A pointer to the parent DN within \c dn.
  3302. */
  3303. const char *slapi_dn_find_parent_ext( const char *dn, int is_tombstone );
  3304. /**
  3305. * Gets the parent DN of a given DN.
  3306. *
  3307. * \param dn The DN whose parent is desired.
  3308. * \return A pointer to the parent DN of \c dn.
  3309. * \warning The caller must free the returned DN when finished with it.
  3310. * \deprecated Use slapi_sdn_get_parent() instead.
  3311. */
  3312. char *slapi_dn_parent( const char *dn );
  3313. /**
  3314. * Gets the parent DN of a given DN.
  3315. *
  3316. * \param dn The DN whose parent is desired.
  3317. * \param is_tombstone If non-zero, the special leaf rdn "nsuniqueid=.." is ignored.
  3318. * \return A pointer to the parent DN of \c dn.
  3319. * \warning The caller must free the returned DN when finished with it.
  3320. * \deprecated Use slapi_sdn_get_parent() instead.
  3321. */
  3322. char *slapi_dn_parent_ext( const char *dn, int is_tombstone );
  3323. /**
  3324. * Checks if a DN belongs to a suffix.
  3325. *
  3326. * \param dn The DN to check.
  3327. * \param suffix The suffix to check.
  3328. * \return \c 1 if \c dn belongs to \c suffix
  3329. * \return \c 0 if \c dn does not belong to \c suffix.
  3330. * \warning Both \c dn and \c suffix must be normalized before calling this function.
  3331. * \deprecated Use slapi_sdn_issuffix() instead.
  3332. */
  3333. int slapi_dn_issuffix( const char *dn, const char *suffix );
  3334. /**
  3335. * Checks if a DN is the parent of another DN.
  3336. *
  3337. * \param parentdn The DN of the supposed parent.
  3338. * \param childdn The DN of the supposed child.
  3339. * \return non-zero if \c parentdn is the parent of \c childdn.
  3340. * \return \c 0 if \c parentdn is not the paret of \c childdn.
  3341. * \deprecated Use slapi_sdn_isparent() instead.
  3342. */
  3343. int slapi_dn_isparent( const char *parentdn, const char *childdn );
  3344. /**
  3345. * Determines is a DN is the root DN.
  3346. *
  3347. * \param dn The DN to check
  3348. * \return \c 1 if the DN is the root DN.
  3349. * \return \c 0 if the DN is not the root DN.
  3350. * \warning You must normalize \c dn before calling this function.
  3351. */
  3352. int slapi_dn_isroot( const char *dn );
  3353. /**
  3354. * Checks if a DN is the backend suffix.
  3355. *
  3356. * \param pb A parameter block with the backend set.
  3357. * \param dn The DN to check.
  3358. * \return \c 1 if \c dn is the backend suffix.
  3359. * \return \c 0 if \c dn is not the backend suffix.
  3360. * \deprecated slapi_be_issuffix()
  3361. */
  3362. int slapi_dn_isbesuffix( Slapi_PBlock *pb, const char *dn );
  3363. /**
  3364. * Checks if writes to a particular DN need to send a referral.
  3365. *
  3366. * \param target_sdn The target DN that you want to check.
  3367. * \param referral The address of a pointer to receive a referral
  3368. * if one is needed.
  3369. * \return \c 1 if a referral needs to be sent.
  3370. * \return \c 0 if no referral is needed.
  3371. * \warning The referral entry must be freed when it is no longer
  3372. * being used.
  3373. */
  3374. int slapi_dn_write_needs_referral(Slapi_DN *target_sdn, Slapi_Entry **referral);
  3375. /**
  3376. * Converts the second RDN type value to the berval value.
  3377. *
  3378. * Returns the new RDN value as a berval value in \c bv. This function
  3379. * can be used for creating the RDN as an attribute value since it returns
  3380. * the value of the RDN in the berval structure.
  3381. *
  3382. * \param rdn Second RDN value.
  3383. * \param type Address of a pointer to receive the attribute type
  3384. * of the second RDN.
  3385. * \param bv A pointer to the berval structure to receive the value.
  3386. */
  3387. int slapi_rdn2typeval( char *rdn, char **type, struct berval *bv );
  3388. /**
  3389. * Adds a RDN to a DN.
  3390. *
  3391. * \param dn The DN to add the RDN to.
  3392. * \param rdn the new RDN to add to the DN.
  3393. * \return A pointer to the new DN.
  3394. * \warning The caller must free the returnd DN when finished with it.
  3395. * \deprecated Use slapi_sdn_add_rdn() instead.
  3396. */
  3397. char *slapi_dn_plus_rdn(const char *dn, const char *rdn);
  3398. /**
  3399. * Create an Slapi_DN that is a common ancestor of given 2 Slapi_DN's
  3400. *
  3401. * \param dn1 The first DN
  3402. * \param dn2 the second DN
  3403. * \return A pointer to the new Slapi_DN that is a common ancestor of dn1 and dn2
  3404. * \warning The caller must free the returnd Slapi_DN
  3405. */
  3406. Slapi_DN *slapi_sdn_common_ancestor(Slapi_DN *dn1, Slapi_DN *dn2);
  3407. /*
  3408. * thread safe random functions
  3409. */
  3410. /**
  3411. * Generate a pseudo-random integer with optional seed.
  3412. *
  3413. * \param seed A seed to use when generating the pseudo random number.
  3414. * \return A pseudo random number.
  3415. * \see slapi_rand()
  3416. * \see slapi_rand_array()
  3417. */
  3418. int slapi_rand_r(unsigned int * seed);
  3419. /* Generate a pseudo-random integer in an array.
  3420. *
  3421. * \param randx The array you want filled with the random number.
  3422. * \param len The length of the array you want filled with the random number.
  3423. * \see slapi_rand()
  3424. * \see slapi_rand_r()
  3425. */
  3426. void slapi_rand_array(void *randx, size_t len);
  3427. /**
  3428. * Generate a pseudo-random integer.
  3429. *
  3430. * \return A pseudo random number.
  3431. * \see slapi_rand_r()
  3432. * \see slapi_rand_array()
  3433. */
  3434. int slapi_rand(void);
  3435. /**
  3436. * Escape special characters in a search filter value
  3437. *
  3438. * \param filter_str A ldap search filter value (cn=VALUE_TO_BE_ESCAPED)
  3439. * \param len length of the search filter value. -1 indicates the string is null terminated
  3440. * \param buf the buffer to store the escaped filter value string
  3441. * \return the escaped filter value string
  3442. */
  3443. char* slapi_escape_filter_value(char* filter_str, int len);
  3444. #define ESC_NEXT_VAL "__ESC__NEXT__VAL__"
  3445. #define NORM_NEXT_VAL "__NORM__NEXT__VAL__"
  3446. #define ESC_AND_NORM_NEXT_VAL "__ESC__AND__NORM__NEXT__VAL__"
  3447. char* slapi_filter_sprintf(const char *fmt, ...);
  3448. /*
  3449. * attribute routines
  3450. */
  3451. /**
  3452. * Create a new empty attribute.
  3453. *
  3454. * \return A pointer to the newly created attribute.
  3455. * \warning You must free the returned attribute using slapi_attr_free().
  3456. * \see slapi_attr_init()
  3457. * \see slapi_attr_dup()
  3458. * \see slapi_attr_free()
  3459. */
  3460. Slapi_Attr *slapi_attr_new( void );
  3461. /**
  3462. * Initializes an attribute with an attribute type.
  3463. *
  3464. * \param a The attribute to initialize.
  3465. * \param type The attribute type to set.
  3466. * \return A pointer to the initialized attribute.
  3467. */
  3468. Slapi_Attr *slapi_attr_init(Slapi_Attr *a, const char *type);
  3469. /**
  3470. * Frees an attribute from memory.
  3471. *
  3472. * \param a Address of a pointer to the attribute to be freed.
  3473. * \see slapi_attr_init()
  3474. * \see slapi_attr_dup()
  3475. * \see slapi_attr_new()
  3476. */
  3477. void slapi_attr_free( Slapi_Attr **a );
  3478. /**
  3479. * Make a copy of an attribute.
  3480. *
  3481. * \param attr The attribute to be duplicated.
  3482. * \return The newly created copy of the attribute.
  3483. * \warning You must free the returned attribute using slapi_attr_free().
  3484. * \see slapi_attr_new()
  3485. * \see slapi_attr_init()
  3486. * \see slapi_attr_free()
  3487. */
  3488. Slapi_Attr *slapi_attr_dup(const Slapi_Attr *attr);
  3489. /**
  3490. * Adds a value to an attribute.
  3491. *
  3492. * \param a The attribute that will contain the values.
  3493. * \param v Value to be added to the attribute.
  3494. * \return Always returns 0.
  3495. * \see slapi_attr_first_value()
  3496. * \see slapi_attr_next_value()
  3497. * \see slapi_attr_get_numvalues()
  3498. * \see slapi_attr_value_cmp()
  3499. * \see slapi_attr_value_find()
  3500. */
  3501. int slapi_attr_add_value(Slapi_Attr *a, const Slapi_Value *v);
  3502. /**
  3503. * Find syntax plugin associated with an attribute type.
  3504. *
  3505. * \param type Type of attribute for which you want to get the plugin.
  3506. * \param pi Address to receive a pointer to the plugin structure.
  3507. * \return \c 0 if successful.
  3508. * \return \c -1 if the plugin is not found.
  3509. * \deprecated This function was necessary in order to call syntax plugin
  3510. * filter and indexing functions - there are new functions
  3511. * to use instead, such as slapi_attr_values2keys, etc.
  3512. * This function is still used by internal APIs, but new
  3513. * code should not use this function
  3514. * \see slapi_attr_get_type()
  3515. * \see slapi_attr_type_cmp()
  3516. * \see slapi_attr_types_equivalent()
  3517. * \see slapi_attr_basetype()
  3518. */
  3519. int slapi_attr_type2plugin( const char *type, void **pi );
  3520. /**
  3521. * Get the name of the attribute type from a specified attribute.
  3522. *
  3523. * \param attr Attribute for which you want to get the type.
  3524. * \param type Address to receive a pointer to the attribute type.
  3525. * \return Always returns \c 0.
  3526. * \warning Do not free the returned attribute type. The type is a part
  3527. * if the actual attribute data, not a copy.
  3528. * \see slapi_attr_type2plugin()
  3529. * \see slapi_attr_type_cmp()
  3530. * \see slapi_attr_types_equivalent()
  3531. * \see slapi_attr_basetype()
  3532. */
  3533. int slapi_attr_get_type( Slapi_Attr *attr, char **type );
  3534. /**
  3535. * Get the attribute type OID of a particular attribute.
  3536. *
  3537. * \param attr Attribute that contains the desired OID.
  3538. * \param oidp Address to receive a pointer to a copy of the
  3539. * attribute type OID.
  3540. * \return \c 0 if the attribute type is found.
  3541. * \return \c -1 if the attribute type is not found.
  3542. * \warning The returned OID should be freed by calling the
  3543. * slapi_ch_free_string() function.
  3544. * \see slapi_attr_get_syntax_oid_copy()
  3545. */
  3546. int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp );
  3547. /*
  3548. * Get the syntax OID of a particular attribute.
  3549. *
  3550. * \param a Attribute that contains the desired OID.
  3551. * \param oidp Address to receive a pointer to a copy of the
  3552. * syntax OID.
  3553. * \return \c 0 if the syntax OID is found.
  3554. * \return \c -1 if the syntax OID is not found.
  3555. * \warning The returned OID should be freed by calling the
  3556. * slapi_ch_free_string() function.
  3557. * \see slapi_attr_get_oid_copy()
  3558. */
  3559. int slapi_attr_get_syntax_oid_copy( const Slapi_Attr *a, char **oidp );
  3560. /**
  3561. * Checks if the attribute uses a DN syntax or not.
  3562. *
  3563. * \param attr The attribute to be checked.
  3564. * \return \c non 0 if the attribute uses a DN syntax.
  3565. * \return \c 0 if the attribute does not use a DN syntax.
  3566. */
  3567. int slapi_attr_is_dn_syntax_attr(Slapi_Attr *attr);
  3568. int slapi_attr_is_dn_syntax_type(char *type);
  3569. /**
  3570. * Get the flags associated with a particular attribute.
  3571. *
  3572. * Valid flags are:
  3573. * \arg #SLAPI_ATTR_FLAG_SINGLE
  3574. * \arg #SLAPI_ATTR_FLAG_OPATTR
  3575. * \arg #SLAPI_ATTR_FLAG_READONLY
  3576. * \arg #SLAPI_ATTR_FLAG_OBSOLETE
  3577. * \arg #SLAPI_ATTR_FLAG_COLLECTIVE
  3578. * \arg #SLAPI_ATTR_FLAG_NOUSERMOD
  3579. * \arg #SLAPI_ATTR_FLAG_NORMALIZED
  3580. * \arg #SLAPI_ATTR_FLAG_NOEXPOSE
  3581. *
  3582. * \param attr Attribute for which you want to get the flags.
  3583. * \param flags Address of an integer that you want to reveive the flags.
  3584. * \return \c Always returns 0.
  3585. * \see slapi_attr_flag_is_set()
  3586. */
  3587. int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags );
  3588. /**
  3589. * Checks if certain flags are set for a particular attribute.
  3590. *
  3591. * Valid flags are:
  3592. * \arg #SLAPI_ATTR_FLAG_SINGLE
  3593. * \arg #SLAPI_ATTR_FLAG_OPATTR
  3594. * \arg #SLAPI_ATTR_FLAG_READONLY
  3595. * \arg #SLAPI_ATTR_FLAG_OBSOLETE
  3596. * \arg #SLAPI_ATTR_FLAG_COLLECTIVE
  3597. * \arg #SLAPI_ATTR_FLAG_NOUSERMOD
  3598. * \arg #SLAPI_ATTR_FLAG_NORMALIZED
  3599. * \arg #SLAPI_ATTR_FLAG_NOEXPOSE
  3600. *
  3601. * \param attr Attribute that you want to check.
  3602. * \param flag Flags to check in the attribute.
  3603. * \return \c 1 if the specified flags are set.
  3604. * \return \c 0 if the specified flags are not set.
  3605. * \see slapi_attr_get_flags()
  3606. */
  3607. int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag );
  3608. /**
  3609. * Comare two bervals for a given attribute.
  3610. *
  3611. * \param attr Attribute used to determine how these values are compared; for
  3612. * example, the syntax of the attribute may perform case-insensitive
  3613. * comparisons.
  3614. * \param v1 Pointer to the \c berval structure containing the first value
  3615. * that you want to compare.
  3616. * \param v2 Pointer to the \c berval structure containing the second value
  3617. * that you want to compare.
  3618. * \return \c 0 if the values are equal.
  3619. * \return \c -1 if the values are not equal.
  3620. * \see slapi_attr_add_value()
  3621. * \see slapi_attr_first_value()
  3622. * \see slapi_attr_next_value()
  3623. * \see slapi_attr_get_numvalues()
  3624. * \see slapi_attr_value_find()
  3625. */
  3626. int slapi_attr_value_cmp( const Slapi_Attr *attr, const struct berval *v1, const struct berval *v2 );
  3627. /**
  3628. * Comare two values for a given attribute.
  3629. *
  3630. * \param attr Attribute used to determine how these values are compared; for
  3631. * example, the syntax of the attribute may perform case-insensitive
  3632. * comparisons.
  3633. * \param v1 Pointer to the \c Slapi_Value structure containing the first value
  3634. * that you want to compare.
  3635. * \param v2 Pointer to the \c Slapi_Value structure containing the second value
  3636. * that you want to compare.
  3637. * \return \c 0 if the values are equal.
  3638. * \return \c -1 if the values are not equal.
  3639. * \see slapi_attr_add_value()
  3640. * \see slapi_attr_first_value()
  3641. * \see slapi_attr_next_value()
  3642. * \see slapi_attr_get_numvalues()
  3643. * \see slapi_attr_value_find()
  3644. * \see slapi_attr_value_cmp()
  3645. */
  3646. int slapi_attr_value_cmp_ext(const Slapi_Attr *a, Slapi_Value *v1, Slapi_Value *v2);
  3647. /**
  3648. * Determine if an attribute contains a given value.
  3649. *
  3650. * \param a Attribute that you want to check.
  3651. * \param v Pointer to the \c berval structure containing the value for
  3652. * which you want to search.
  3653. * \return \c 0 if the attribute contains the specified value.
  3654. * \return \c -1 if the attribute does not contain the specified value.
  3655. * \see slapi_attr_add_value()
  3656. * \see slapi_attr_first_value()
  3657. * \see slapi_attr_next_value()
  3658. * \see slapi_attr_get_numvalues()
  3659. * \see slapi_attr_value_cmp()
  3660. */
  3661. int slapi_attr_value_find( const Slapi_Attr *a, const struct berval *v );
  3662. /**
  3663. * Compare two attribute types.
  3664. *
  3665. * \param t1 Name of the first attribute type to compare.
  3666. * \param t2 Name of the second attribute type to compare.
  3667. * \param opt One of the following options:
  3668. * \arg #SLAPI_TYPE_CMP_EXACT
  3669. * \arg #SLAPI_TYPE_CMP_BASE
  3670. * \arg #SLAPI_TYPE_CMP_SUBTYPE
  3671. * \return \c 0 if the type names are equal.
  3672. * \return A non-zero value if the type names are not equal.
  3673. * \see slapi_attr_type2plugin()
  3674. * \see slapi_attr_get_type()
  3675. * \see slapi_attr_types_equivalent()
  3676. * \see slapi_attr_basetype()
  3677. */
  3678. int slapi_attr_type_cmp( const char *t1, const char *t2, int opt );
  3679. /* Mode of operation (opt) values for slapi_attr_type_cmp() */
  3680. /**
  3681. * Compare the types as-is.
  3682. *
  3683. * \see slapi_attr_type_cmp()
  3684. */
  3685. #define SLAPI_TYPE_CMP_EXACT 0
  3686. /**
  3687. * Compare only the base names of the types.
  3688. *
  3689. * \see slapi_attr_type_cmp()
  3690. */
  3691. #define SLAPI_TYPE_CMP_BASE 1
  3692. /**
  3693. * Ignore any subtypes in the second type that are not in the first subtype.
  3694. *
  3695. * \see slapi_attr_type_cmp()
  3696. */
  3697. #define SLAPI_TYPE_CMP_SUBTYPE 2
  3698. /**
  3699. * Compare two attribute names to determine if they represent the same value.
  3700. *
  3701. * \param t1 Pointer to the first attribute you want to compare.
  3702. * \param t2 Pointer to the second attribute you want to compare.
  3703. * \return \c 1 if \c t1 and \c t2 represent the same attribute.
  3704. * \return \c 0 if \c t1 and \c t2 do not represent the same attribute.
  3705. * \see slapi_attr_type_cmp()
  3706. * \see slapi_attr_get_type()
  3707. * \see slapi_attr_basetype()
  3708. */
  3709. int slapi_attr_types_equivalent(const char *t1, const char *t2);
  3710. /**
  3711. * Get the base type of an attribute.
  3712. *
  3713. * For example, if given \c cn;lang-jp, returns \c cn.
  3714. *
  3715. * \param type Attribute type from which you want to get the base type.
  3716. * \param buf Buffer to hold the returned base type.
  3717. * \param bufsiz Size of the buffer.
  3718. * \return \c NULL if the base type fits in the buffer.
  3719. * \return A pointer to a newly allocated base type if the buffer is
  3720. * too small to hold it.
  3721. * \warning If a base type is returned, if should be freed by calling
  3722. * slapi_ch_free_string().
  3723. * \see slapi_attr_get_type()
  3724. * \see slapi_attr_type_cmp()
  3725. * \see slapi_attr_types_equivalent()
  3726. */
  3727. char *slapi_attr_basetype( const char *type, char *buf, size_t bufsiz );
  3728. /**
  3729. * Get the first value of an attribute.
  3730. *
  3731. * This is part of a set of functions to enumerate over a
  3732. * \c Slapi_Attr structure.
  3733. *
  3734. * \param a Attribute containing the desired value.
  3735. * \param v Holds the first value of the attribute.
  3736. * \return \c 0, which is the index of the first value.
  3737. * \return \c -1 if \c NULL or if the value is not found.
  3738. * \warning Do not free the returned value. It is a part
  3739. * of the attribute structure and not a copy.
  3740. * \see slapi_attr_next_value()
  3741. * \see slapi_attr_get_num_values()
  3742. */
  3743. int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v );
  3744. /**
  3745. * Get the next value of an attribute.
  3746. *
  3747. * The value of an attribute associated with an index is placed into
  3748. * a value. This is pare of a set of functions to enumerate over a
  3749. * \c Slapi_Attr structure.
  3750. *
  3751. * \param a Attribute containing the desired value.
  3752. * \param hint Index of the value to be returned.
  3753. * \param v Holds the value of the attribute.
  3754. * \return \c hint plus \c 1 if the value is found.
  3755. * \return \c -1 if \c NULL or if a value at \c hint is not found.
  3756. * \warning Do not free the returned value. It is a part
  3757. * of the attribute structure and not a copy.
  3758. * \see slapi_attr_first_value()
  3759. * \see slapi_attr_get_num_values()
  3760. */
  3761. int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v );
  3762. /**
  3763. * Get the number of values present in an attribute.
  3764. *
  3765. * Counts the number of values in an attribute and places that
  3766. * count in an integer.
  3767. *
  3768. * \param a Attribute containing the values to be counted.
  3769. * \param numValues Integer to hold the counted values.
  3770. * \see slapi_attr_first_value()
  3771. * \see slapi_attr_next_value()
  3772. */
  3773. int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues);
  3774. /**
  3775. * Copy existing values contained in an attribute into a valueset.
  3776. *
  3777. * \param a Attribute containing the values to be placed into
  3778. * a valueset.
  3779. * \param vs Receives the values from the attribute.
  3780. * \return Always returns \c 0.
  3781. * \warning Free the returned valueset with slapi_valueset_free()
  3782. * when finished using it.
  3783. * \see slapi_entry_add_valueset()
  3784. * \see slapi_valueset_new()
  3785. * \see slapi_valueset_free()
  3786. * \see slapi_valueset_init()
  3787. * \see slapi_valueset_done()
  3788. * \see slapi_valueset_add_value()
  3789. * \see slapi_valueset_first_value()
  3790. * \see slapi_valueset_next_value()
  3791. * \see slapi_valueset_count()
  3792. */
  3793. int slapi_attr_get_valueset(const Slapi_Attr *a, Slapi_ValueSet **vs);
  3794. /**
  3795. * Sets the valueset in an attribute.
  3796. *
  3797. * Intializes a valueset in a \c Slapi_Attr structure from a specified
  3798. * \c Slapi_ValueSet structure. The valueset in the \c Slapi_Attr
  3799. * will be \c vs, not a copy.
  3800. *
  3801. * \param a The attribute to set the valueset in.
  3802. * \param vs The valueset that you want to set in the attribute.
  3803. * \return Always returns \c 0.
  3804. * \warning Do not free \c vs. Ownership of \c vs is tranferred to
  3805. * the attribute.
  3806. * \see slapi_valueset_set_valueset()
  3807. */
  3808. int slapi_attr_set_valueset(Slapi_Attr *a, const Slapi_ValueSet *vs);
  3809. /**
  3810. * Set the attribute type of an attribute.
  3811. *
  3812. * \param a The attribute whose type you want to set.
  3813. * \param type The attribute type you want to set.
  3814. * \return \c 0 if the type was set.
  3815. * \return \c -1 if the type was not set.
  3816. * \warning The passed in type is copied, so ownership of \c type
  3817. * remains with the caller.
  3818. * \see slapi_attr_get_type()
  3819. */
  3820. int slapi_attr_set_type(Slapi_Attr *a, const char *type);
  3821. /**
  3822. * Copy the values from an attribute into a berval array.
  3823. *
  3824. * \param a Attribute that contains the desired values.
  3825. * \param vals Pointer to an array of berval structure pointers to
  3826. * hold the desired values.
  3827. * \return \c 0 if values are found.
  3828. * \return \c -1 if \c NULL.
  3829. * \warning You should free the array using ber_bvecfree() from the
  3830. * Mozilla LDAP C SDK.
  3831. */
  3832. int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals );
  3833. /**
  3834. * Normalize an attribute type.
  3835. *
  3836. * The attribute type will be looked up in the defined syntaxes to
  3837. * get the normalized form. If it is not found, the passed in type
  3838. * will be normalized.
  3839. *
  3840. * \param s The attribute type that you want to normalize.
  3841. * \return A normalized copy of the passed in attribute type.
  3842. * \warning You should free the returned string using slapi_ch_free_string().
  3843. * \see slapi_ch_free_string()
  3844. */
  3845. char * slapi_attr_syntax_normalize( const char *s );
  3846. /**
  3847. * Normalize an attribute type.
  3848. *
  3849. * The attribute type will be looked up in the defined syntaxes to
  3850. * get the normalized form. If it is not found, the passed in type
  3851. * will be normalized. If ATTR_SYNTAX_NORM_ORIG_ATTR is set to flags,
  3852. * the upper and lower cases are kept but trailing spaces are chopped
  3853. * from the original attribute type.
  3854. *
  3855. * \param s The attribute type that you want to normalize.
  3856. * \param flags 0 or ATTR_SYNTAX_NORM_ORIG_ATTR
  3857. * \return A normalized copy of the passed in attribute type.
  3858. * \warning You should free the returned string using slapi_ch_free_string().
  3859. * \see slapi_ch_free_string()
  3860. */
  3861. char * slapi_attr_syntax_normalize_ext( char *s, int flags );
  3862. /*
  3863. * value routines
  3864. */
  3865. /**
  3866. * Create a new empty \c Slapi_Value structure.
  3867. *
  3868. * \return A pointer to the newly allocated \c Slapi_Value structure.
  3869. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  3870. * \warning When you are no longer using the value, free it from memory
  3871. * by calling slapi_value_free()
  3872. * \see slapi_value_free()
  3873. * \see slapi_value_dup()
  3874. * \see slapi_value_new_berval()
  3875. * \see slapi_value_new_string()
  3876. * \see slapi_value_new_string_passin()
  3877. */
  3878. Slapi_Value *slapi_value_new( void );
  3879. /**
  3880. * Create a new \c Slapi_value structure and initialize it's value.
  3881. *
  3882. * \param bval Pointer to the \c berval structure used to initialize
  3883. * the newly allocated \c Slapi_value.
  3884. * \return A pointer to the newly allocated and initialized value.
  3885. * \warning The passed in \c berval structure will be copied. Ownership
  3886. * of \c bval remains with the caller.
  3887. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  3888. * \warning When you are no longer using the value, free it from memory
  3889. * by calling slapi_value_free()
  3890. * \see slapi_value_free()
  3891. * \see slapi_value_new()
  3892. * \see slapi_value_new_string()
  3893. * \see slapi_value_new_string_passin()
  3894. * \see slapi_value_dup()
  3895. */
  3896. Slapi_Value *slapi_value_new_berval(const struct berval *bval);
  3897. /**
  3898. * Duplicate a \c Slapi_Value structure.
  3899. *
  3900. * \param v The value to duplicate.
  3901. * \return A pointer to the copy of the value.
  3902. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  3903. * \warning When you are no longer using the value, free it from memory
  3904. * by calling slapi_value_free()
  3905. * \warning This function is identical to slapi_value_dup().
  3906. * \see slapi_value_dup()
  3907. * \see slapi_value_free()
  3908. */
  3909. Slapi_Value *slapi_value_new_value(const Slapi_Value *v);
  3910. /**
  3911. * Create a new \c Slapi_value structure and initialize it's value.
  3912. *
  3913. * \param s A \c NULL terminated string used to initialize
  3914. * the newly allocated \c Slapi_value.
  3915. * \return A pointer to the newly allocated and initialized value.
  3916. * \warning The passed in string will be copied. Ownership of \c s
  3917. * remains with the caller.
  3918. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  3919. * \warning When you are no longer using the value, free it from memory
  3920. * by calling slapi_value_free()
  3921. * \see slapi_value_free()
  3922. * \see slapi_value_new()
  3923. * \see slapi_value_new_berval()
  3924. \see slapi_value_new_string_passin()
  3925. * \see slapi_value_dup()
  3926. */
  3927. Slapi_Value *slapi_value_new_string(const char *s);
  3928. /**
  3929. * Create a new \c Slapi_value structure and initialize it's value.
  3930. *
  3931. * \param s A \c NULL terminated string used to initialize
  3932. * the newly allocated \c Slapi_value.
  3933. * \return A pointer to the newly allocated and initialized value.
  3934. * \warning The passed in string will be used directly as the value.
  3935. * It will not be copied. Ownership of \c s is transferred
  3936. * to the new \c Slapi_Value structure, so it should not be
  3937. * freed by the caller.
  3938. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  3939. * \warning When you are no longer using the value, free it from memory
  3940. * by calling slapi_value_free()
  3941. * \see slapi_value_free()
  3942. * \see slapi_value_new()
  3943. * \see slapi_value_new_berval()
  3944. * \see slapi_value_new_string()
  3945. * \see slapi_value_dup()
  3946. */
  3947. Slapi_Value *slapi_value_new_string_passin(char *s);
  3948. /**
  3949. * Initialize a \c Slapi_Value structure.
  3950. *
  3951. * All fields of the passed in \c Slapi_Value will be reset to zero.
  3952. *
  3953. * \param v The value to initialize.
  3954. * \return A pointer to the initialized value.
  3955. * \warning The passed in value must not be \c NULL.
  3956. * \see slapi_value_init_berval()
  3957. * \see slapi_value_init_string()
  3958. * \see slapi_value_init_string_passin()
  3959. */
  3960. Slapi_Value *slapi_value_init(Slapi_Value *v);
  3961. /**
  3962. * Initialize a \c Slapi_Value structure from the value contained in a \c berval structure.
  3963. *
  3964. * \param v The value to initialize.
  3965. * \param bval The \c berval structure to be used to intialize the value.
  3966. * \return A pointer to the initialized value.
  3967. * \warning The passed in \c Slapi_Value must not be \c NULL.
  3968. * \warning The content of the \c berval structure is duplicated. It is up
  3969. * to the caller to manage the memory used by the \c berval.
  3970. * \see slapi_value_init()
  3971. * \see slapi_value_init_string()
  3972. * \see slapi_value_init_string_passin()
  3973. */
  3974. Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval);
  3975. /**
  3976. * Initialize a \c Slapi_Value with a copy of the value contained in a string.
  3977. *
  3978. * \param v The value to initialize.
  3979. * \param s The null-terminated string to be used to initialize the value.
  3980. * \return A pointer to the initialized value.
  3981. * \warning The passed in \c Slapi_Value must not be \c NULL.
  3982. * \warning The passed in string is duplicated. It is up to the caller to
  3983. * manage the memory used by the passed in string.
  3984. * \see slapi_value_init()
  3985. * \see slapi_value_init_berval()
  3986. * \see slapi_value_init_string_passin()
  3987. */
  3988. Slapi_Value *slapi_value_init_string(Slapi_Value *v,const char *s);
  3989. /* Initialize a \c Slapi_Value with the value contained in a string.
  3990. *
  3991. * \param v The value to initialize.
  3992. * \param s The null-terminated string to be used to initialize the value.
  3993. * \return A pointer to the initialized value.
  3994. * \warning The passed in \c Slapi_Value must not be \c NULL.
  3995. * \warning The passed in string is not duplicated. Responsibility for the
  3996. * memory used by the string is handed over to the \c Slapi_Value
  3997. * structure.
  3998. * \warning The passed in string must not be freed. It will be freed when
  3999. * the \c Slapi_Value structure is freed by calling \c slapi_value_free().
  4000. * \see slapi_value_free()
  4001. * \see slapi_value_init()
  4002. * \see slapi_value_init_berval()
  4003. * \see slapi_value_init_string()
  4004. */
  4005. Slapi_Value *slapi_value_init_string_passin(Slapi_Value *v, char *s);
  4006. /**
  4007. * Duplicate a \c Slapi_Value structure.
  4008. *
  4009. * \param v The value to duplicate.
  4010. * \return A pointer to the copy of the value.
  4011. * \warning If space can not be allocated, the \c ns-slapd program terminates.
  4012. * \warning When you are no longer using the value, free it from memory
  4013. * by calling slapi_value_free()
  4014. * \warning This function is identical to slapi_value_new_value().
  4015. * \see slapi_value_new_value()
  4016. * \see slapi_value_free()
  4017. */
  4018. Slapi_Value *slapi_value_dup(const Slapi_Value *v);
  4019. /**
  4020. * Sets the flags in a \c Slapi_Value structure.
  4021. *
  4022. * Valid flags are:
  4023. * \arg #SLAPI_ATTR_FLAG_NORMALIZED
  4024. *
  4025. * \param v Pointer to the \c Slapi_Value structure for which to
  4026. * set the flags.
  4027. * \param flags The flags you want to set.
  4028. * \warning The flags support bit-wise operations.
  4029. * \see slapi_values_set_flags()
  4030. * \see slapi_value_get_flags()
  4031. */
  4032. void slapi_value_set_flags(Slapi_Value *v, unsigned long flags);
  4033. /**
  4034. * Sets the flags in an array of \c Slapi_Value structures.
  4035. *
  4036. * Valid flags are:
  4037. * \arg #SLAPI_ATTR_FLAG_NORMALIZED
  4038. *
  4039. * \param vs Pointer to the \c Slapi_Value array for which you
  4040. * want to set the flags.
  4041. * \param flags The flags you want to set.
  4042. * \warning The flags support bit-wise operations.
  4043. * \see slapi_value_set_flags()
  4044. * \see slapi_value_get_flags()
  4045. */
  4046. void slapi_values_set_flags(Slapi_Value **vs, unsigned long flags);
  4047. /**
  4048. * Retrieves the flags from a \c Slapi_Value structure.
  4049. *
  4050. * \param v Pointer to the \c Slapi_Value structure from which the
  4051. * flags are to be retrieved.
  4052. * \return The flags that are set in the value.
  4053. * \see slapi_value_set_flags()
  4054. * \see slapi_values_set_flags()
  4055. */
  4056. unsigned long slapi_value_get_flags(Slapi_Value *v);
  4057. /**
  4058. * Frees a \c Slapi_Value structure from memory.
  4059. *
  4060. * The contents of the value will be freed along with the \c Slapi_Value
  4061. * structure itself. The pointer will also be set to \c NULL.
  4062. *
  4063. * \param value Address of the pointer to the \c Slapi_Value structure
  4064. * you wish to free.
  4065. * \see slapi_value_new()
  4066. */
  4067. void slapi_value_free(Slapi_Value **value);
  4068. /**
  4069. * Gets the \c berval structure of the value.
  4070. *
  4071. * \param value Pointer to the \c Slapi_Value of which you wish
  4072. * to get the \c berval.
  4073. * \return A pointer to the \c berval structure contained in the
  4074. * \c Slapi_Value.
  4075. * \warning The returned pointer point to the actual \c berval structure
  4076. * inside of the value, not a copy.
  4077. * \warning You should not free the returned \c berval structure unless
  4078. * you plan to replace it by calling \c slapi_value_set_berval().
  4079. * \see slapi_value_set_berval()
  4080. */
  4081. const struct berval *slapi_value_get_berval( const Slapi_Value *value );
  4082. /**
  4083. * Sets the value of a \c Slapi_Value structure from a \c berval structure.
  4084. *
  4085. * The value is duplicated from the passed in \c berval structure.
  4086. *
  4087. * \param value Pointer to the \c Slapi_Value structure in which to
  4088. * set the value.
  4089. * \param bval Pointer to the \c berval value to be copied.
  4090. * \return Pointer to the \c Slapi_Value structure passed in as \c value.
  4091. * \return NULL if the passed in value was \c NULL.
  4092. * \warning If the pointer to the \c Slapi_Value structure is \c NULL,
  4093. * nothing is done, and the function returns \c NULL.
  4094. * \warning If the \c Slapi_Value structure already contains a value, it
  4095. * is freed from memory before the new one is set.
  4096. * \warning When you are no longer using the \c Slapi_Value structure, you
  4097. * should free it from memory by valling \c slapi_value_free().
  4098. * \see slapi_value_free()
  4099. * \see slapi_value_get_berval()
  4100. */
  4101. Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval );
  4102. /**
  4103. * Sets the value of a \c Slapi_Value structure from another \c Slapi_Value structure.
  4104. *
  4105. * The value is duplicated from the supplied \c Slapi_value structure.
  4106. *
  4107. * \param value Pointer to the \c Slapi_Value structure in which to set
  4108. * the value.
  4109. * \param vfrom Pointer to the \c Slapi_Value structure from which to
  4110. * get the value.
  4111. * \return Pointer to the \c Slapi_Value structure passed as the \c value paramter.
  4112. * \return \c NULL if the \c value parameter was \c NULL.
  4113. * \warning The \c vfrom parameter must not be \c NULL.
  4114. * \warning If the pointer to the \c Slapi_Value structure is \c NULL,
  4115. * nothing is done, and the function returns \c NULL.
  4116. * \warning If the \c Slapi_Value structure already contains a value, it
  4117. * is freed from memory before the new one is set.
  4118. * \warning When you are no longer using the \c Slapi_Value structure, you
  4119. * should free it from memory by valling \c slapi_value_free().
  4120. * \see slapi_value_free()
  4121. */
  4122. Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom);
  4123. /**
  4124. * Sets the value of a \c Slapi_Value structure.
  4125. *
  4126. * The value is a duplicate of the data pointed to by \c val and the
  4127. * length \c len.
  4128. *
  4129. * \param value Pointer to the \c Slapi_Value structure in which to set
  4130. * the value.
  4131. * \param val Pointer to the value.
  4132. * \param len Length of the value.
  4133. * \return Pointer to the \c Slapi_Value structure with the value set.
  4134. * \return \c NULL if the supplied \c Slapi_Value is \c NULL.
  4135. * \warning If the pointer to the \c Slapi_Value structure is \c NULL,
  4136. * nothing is done, and the function returns \c NULL.
  4137. * \warning If the \c Slapi_Value structure already contains a value, it
  4138. * is freed from memory before the new one is set.
  4139. * \warning When you are no longer using the \c Slapi_Value structure, you
  4140. * should free it from memory by valling \c slapi_value_free().
  4141. * \see slapi_value_free()
  4142. */
  4143. Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len);
  4144. /**
  4145. * Sets the value of a \c Slapi_Value structure from a string.
  4146. *
  4147. * The value is duplicated from a supplied string.
  4148. *
  4149. * \param value Pointer to the \c Slapi_Value structure in which to set
  4150. * the value.
  4151. * \param strVal The string containing the value to set.
  4152. * \return \c 0 if the value is set.
  4153. * \return \c -1 if the pointer to the \c Slapi_Value is \c NULL.
  4154. * \warning If the pointer to the \c Slapi_Value structure is \c NULL,
  4155. * nothing is done, and the function returns \c -1.
  4156. * \warning If the \c Slapi_Value structure already contains a value, it
  4157. * is freed from memory before the new one is set.
  4158. * \warning When you are no longer using the \c Slapi_Value structure, you
  4159. * should free it from memory by valling \c slapi_value_free().
  4160. * \see slapi_value_free()
  4161. * \see slapi_value_set_string_passin()
  4162. */
  4163. int slapi_value_set_string(Slapi_Value *value, const char *strVal);
  4164. /**
  4165. * Sets the value of a \c Slapi_Value structure from a string.
  4166. *
  4167. * The supplied string is used as the value within the \c Slapi_Value
  4168. * structure.
  4169. *
  4170. * \param value Pointer to the \c Slapi_Value structure in which to set
  4171. * the value.
  4172. * \param strVal The string containing the value to set.
  4173. * \return \c 0 if the value is set.
  4174. * \return \c -1 if the pointer to the \c Slapi_Value is \c NULL.
  4175. * \warning Do not free the passed in string pointer to by \c strVal.
  4176. * Responsibility for the memory used by the string is handed
  4177. * over to the \c Slapi_Value structure.
  4178. * \warning When you are no longer using the \c Slapi_Value structure, you
  4179. * should free it from memory by valling \c slapi_value_free().
  4180. * \see slapi_value_free()
  4181. * \see slapi_value_set_string()
  4182. */
  4183. int slapi_value_set_string_passin(Slapi_Value *value, char *strVal);
  4184. /**
  4185. * Sets the value of a \c Slapi_Value structure from an integer.
  4186. *
  4187. * \param value Pointer to the \c Slapi_Value structure in which to set
  4188. * the value.
  4189. * \param intVal The integer containing the value to set.
  4190. * \return \c 0 if the value is set.
  4191. * \return \c -1 if the pointer to the \c Slapi_Value is \c NULL.
  4192. * \warning If the pointer to the \c Slapi_Value structure is \c NULL,
  4193. * nothing is done, and the function returns \c -1.
  4194. * \warning If the \c Slapi_Value structure already contains a value, it
  4195. * is freed from memory before the new one is set.
  4196. * \warning When you are no longer using the \c Slapi_Value structure, you
  4197. * should free it from memory by valling \c slapi_value_free().
  4198. * \see slapi_value_free()
  4199. */
  4200. int slapi_value_set_int(Slapi_Value *value, int intVal);
  4201. /**
  4202. * Retrieves the value of a \c Slapi_Value structure as a string.
  4203. *
  4204. * \param value Pointer to the value you wish to get as a string.
  4205. * \return A string containing the value.
  4206. * \return \c NULL if there is no value.
  4207. * \warning The returned string is the actual value, not a copy. You
  4208. * should not free the returned string unless you plan to
  4209. * replace it by calling slapi_value_set_string().
  4210. * \see slapi_value_set_string()
  4211. */
  4212. const char*slapi_value_get_string(const Slapi_Value *value);
  4213. /**
  4214. * Retrieves the value of a \c Slapi_Value structure as an integer.
  4215. *
  4216. * \param value Pointer to the value you wish to get as an integer.
  4217. * \return An integer that corresponds to the value stored in the
  4218. * \c Slapi_Value structure.
  4219. * \return \c 0 if there is no value.
  4220. * \see slapi_value_get_uint()
  4221. * \see slapi_value_get_long()
  4222. * \see slapi_value_get_ulong()
  4223. * \see slapi_value_get_longlong()
  4224. * \see slapi_value_get_ulonglong()
  4225. */
  4226. int slapi_value_get_int(const Slapi_Value *value);
  4227. /**
  4228. * Retrieves the value of a \c Slapi_Value structure as an unsigned integer.
  4229. *
  4230. * \param value Pointer to the value you wish to get as an unsigned integer.
  4231. * \return An unsigned integer that corresponds to the value stored in
  4232. * the \c Slapi_Value structure.
  4233. * \return \c 0 if there is no value.
  4234. * \see slapi_value_get_int()
  4235. * \see slapi_value_get_long()
  4236. * \see slapi_value_get_ulong()
  4237. * \see slapi_value_get_longlong()
  4238. * \see slapi_value_get_ulonglong()
  4239. */
  4240. unsigned int slapi_value_get_uint(const Slapi_Value *value);
  4241. /**
  4242. * Retrieves the value of a \c Slapi_Value structure as a long integer.
  4243. *
  4244. * \param value Pointer to the value you wish to get as a long integer.
  4245. * \return A long integer that corresponds to the value stored in the
  4246. * \c Slapi_Value structure.
  4247. * \return \c 0 if there is no value.
  4248. * \see slapi_value_get_int()
  4249. * \see slapi_value_get_uint()
  4250. * \see slapi_value_get_ulong()
  4251. * \see slapi_value_get_longlong()
  4252. * \see slapi_value_get_ulonglong()
  4253. */
  4254. long slapi_value_get_long(const Slapi_Value *value);
  4255. /**
  4256. * Retrieves the value of a \c Slapi_Value structure as an unsigned long integer.
  4257. *
  4258. * \param value Pointer to the value you wish to get as an unsigned long integer.
  4259. * \return An unsigned long integer that corresponds to the value stored in the
  4260. * \c Slapi_Value structure.
  4261. * \return \c 0 if there is no value.
  4262. * \see slapi_value_get_int()
  4263. * \see slapi_value_get_uint()
  4264. * \see slapi_value_get_long()
  4265. * \see slapi_value_get_longlong()
  4266. * \see slapi_value_get_ulonglong()
  4267. */
  4268. unsigned long slapi_value_get_ulong(const Slapi_Value *value);
  4269. /**
  4270. * Retrieves the value of a \c Slapi_Value structure as a long long integer.
  4271. *
  4272. * \param value Pointer to the value you wish to get as a long long integer.
  4273. * \return A long long integer that corresponds to the value stored in the
  4274. * \c Slapi_Value structure.
  4275. * \return \c 0 if there is no value.
  4276. * \see slapi_value_get_int()
  4277. * \see slapi_value_get_uint()
  4278. * \see slapi_value_get_long()
  4279. * \see slapi_value_get_ulong()
  4280. * \see slapi_value_get_ulonglong()
  4281. */
  4282. long long slapi_value_get_longlong(const Slapi_Value *value);
  4283. /**
  4284. * Retrieves the value of a \c Slapi_Value structure as an unsigned long long integer.
  4285. *
  4286. * \param value Pointer to the value you wish to get as an unsigned long long integer.
  4287. * \return An unsigned long long integer that corresponds to the value stored in the
  4288. * \c Slapi_Value structure.
  4289. * \return \c 0 if there is no value.
  4290. * \see slapi_value_get_int()
  4291. * \see slapi_value_get_uint()
  4292. * \see slapi_value_get_long()
  4293. * \see slapi_value_get_ulong()
  4294. * \see slapi_value_get_longlong()
  4295. */
  4296. unsigned long long slapi_value_get_ulonglong(const Slapi_Value *value);
  4297. /**
  4298. * Retrieves the value of a \c Slapi_Value structure as a long integer.
  4299. *
  4300. * \param value Pointer to the value you wish to get as a long integer.
  4301. * The value could end with D or d for days, H or h for hours,
  4302. * M or m for minutes, S or s for seconds, or no extension.
  4303. * \return A long integer that corresponds to the value stored in the
  4304. * \c Slapi_Value structure.
  4305. * \return \c 0 if there is no value.
  4306. * \return \c -1 if the given value is invalid.
  4307. * \see slapi_value_get_int()
  4308. * \see slapi_value_get_uint()
  4309. * \see slapi_value_get_ulong()
  4310. * \see slapi_value_get_longlong()
  4311. * \see slapi_value_get_ulonglong()
  4312. */
  4313. long slapi_value_get_timelong(const Slapi_Value *value);
  4314. /**
  4315. * Gets the length of a value contained in a \c Slapi_Value structure.
  4316. *
  4317. * \param value Pointer to the value of which you wish to get the length.
  4318. * \return The length of the value.
  4319. * \return \c 0 if there is no value.
  4320. */
  4321. size_t slapi_value_get_length(const Slapi_Value *value);
  4322. /**
  4323. * Compares two \c Slapi_Value structures
  4324. *
  4325. * The matching rule associated with the supplied attribute \c a is used
  4326. * to compare the two values.
  4327. *
  4328. * \param a A pointer to an attribute used to determine how the
  4329. * two values will be compared.
  4330. * \param v1 Pointer to the \c Slapi_Value structure containing the first
  4331. * value to compare.
  4332. * \param v2 Pointer to the \c Slapi_Value structure containing the second
  4333. * value to compare.
  4334. * \return \c 0 if the two values are equal.
  4335. * \return \c -1 if \c v1 is smaller than \c v2.
  4336. * \return \c 1 if \c v1 is greater than \c v2.
  4337. */
  4338. int slapi_value_compare(const Slapi_Attr *a,const Slapi_Value *v1,const Slapi_Value *v2);
  4339. /**
  4340. * Free and initialize the contents of the berval without freeing the
  4341. * struct berval * itself. This is useful when you use struct berval
  4342. * which are allocated on the stack e.g.
  4343. * \code
  4344. * struct berval bv = {0, NULL};
  4345. * slapi_ber_bvcpy(&bv, someotherbvp);
  4346. * // use bv
  4347. * slapi_ber_bvdone(&bv);
  4348. * \endcode
  4349. * You must only call slapi_ber_bvdone() if the bv_val member has been
  4350. * allocated with malloc() or is NULL.
  4351. *
  4352. * \param bvp A struct berval * you want to free the contents of
  4353. * \return \c void
  4354. */
  4355. void slapi_ber_bvdone(struct berval *bvp);
  4356. /**
  4357. * Copy the contents of the berval without allocating a new struct berval*
  4358. * This is useful when you use struct berval which are allocated on the stack e.g.
  4359. * \code
  4360. * struct berval bv = {0, NULL};
  4361. * slapi_ber_bvcpy(&bv, someotherbvp);
  4362. * // use bv
  4363. * slapi_ber_bvdone(&bv);
  4364. * \endcode
  4365. * The bvs source berval to copy from can either be allocated on the heap
  4366. * or the stack.
  4367. *
  4368. * \param bvd A struct berval * you want copy to
  4369. * \param bvs A struct berval * you want to copy from
  4370. * \return \c void
  4371. */
  4372. void slapi_ber_bvcpy(struct berval *bvd, const struct berval *bvs);
  4373. /*
  4374. * Valueset functions.
  4375. */
  4376. /**
  4377. * Flag that indicates that the value should be used by reference.
  4378. *
  4379. * \see slapi_valueset_add_value_ext()
  4380. */
  4381. #define SLAPI_VALUE_FLAG_PASSIN 0x1
  4382. #define SLAPI_VALUE_FLAG_IGNOREERROR 0x2
  4383. #define SLAPI_VALUE_FLAG_PRESERVECSNSET 0x4
  4384. #define SLAPI_VALUE_FLAG_USENEWVALUE 0x8 /* see valueset_remove_valuearray */
  4385. #define SLAPI_VALUE_FLAG_DUPCHECK 0x10 /* used in valueset_add... */
  4386. /**
  4387. * Creates an empty \c Slapi_ValueSet structure.
  4388. *
  4389. * \return Pointer to the newly allocated \c Slapi_ValueSet structure.
  4390. * \warning If no space can be allocated (for example, if no more virtual
  4391. * memory exists), the \c ns-slapd program terminates.
  4392. * \warning When you are no longer using the valueset, you should free it
  4393. * from memory by calling \c slapi_valueset_free().
  4394. * \see slapi_valueset_free()
  4395. */
  4396. Slapi_ValueSet *slapi_valueset_new( void );
  4397. /**
  4398. * Free a \c Slapi_ValueSet structure from memory.
  4399. *
  4400. * Call this function when you are done working with the structure.
  4401. * All members of the valueset will be freed as well if they are not
  4402. * \c NULL.
  4403. *
  4404. * \param vs Pointer to the \c Slapi_ValueSet to free.
  4405. * \see slapi_valueset_done()
  4406. */
  4407. void slapi_valueset_free(Slapi_ValueSet *vs);
  4408. /**
  4409. * Initializes a \c Slapi_ValueSet structure.
  4410. *
  4411. * All values inside of the structure will be cleared (set to \c 0).
  4412. * The values will not be freed by this function. To free the values
  4413. * first, call \c slapi_valueset_done().
  4414. *
  4415. * \param vs Pointer to the \c Slapi_ValueSet to initialize.
  4416. * \warning When you are no longer using the \c Slapi_ValueSet structure,
  4417. * you should free it from memory by calling \c slapi_valueset_free().
  4418. * \see slapi_valueset_done()
  4419. * \see slapi_valueset_free()
  4420. */
  4421. void slapi_valueset_init(Slapi_ValueSet *vs);
  4422. /**
  4423. * Frees the values contained in a \c Slapi_ValueSet structure.
  4424. *
  4425. * \param vs Pointer to the \c Slapi_ValueSet structure from which
  4426. * you want to free its values.
  4427. * \warning Use this function when you are no longer using the values
  4428. * but you want to re-use the \c Slapi_ValueSet structure for
  4429. * a new set of values.
  4430. * \see slapi_valueset_init()
  4431. */
  4432. void slapi_valueset_done(Slapi_ValueSet *vs);
  4433. /**
  4434. * Adds a value to a \c Slapi_ValueSet structure.
  4435. *
  4436. * \param vs Pointer to the \c Slapi_ValueSet structure to which to
  4437. * add the value.
  4438. * \param addval Pointer to the \c Slapi_Value structure to add to
  4439. * the \c Slapi_ValueSet.
  4440. * \warning The value is duplicated from the \c Slapi_Value structure,
  4441. * which can be freed frmo memory without altering the
  4442. * \c Slapi_ValueSet structure.
  4443. * \warning This function does not verify if the value is already present
  4444. * in the \c Slapi_ValueSet structure. You can manually check
  4445. * this using \c slapi_valueset_first_value() and
  4446. * \c slapi_valueset_next_value().
  4447. * \see slapi_valueset_first_value()
  4448. * \see slapi_valueset_next_value()
  4449. */
  4450. void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
  4451. /**
  4452. * Adds a value to a \c Slapi_ValueSet structure with optional flags.
  4453. *
  4454. * This function is similar to \c slapi_valueset_add_value(), but it
  4455. * allows optional flags to be specified to allow the new value to be
  4456. * used by reference.
  4457. *
  4458. * \param vs Pointer to the \c Slapi_ValueSet structure to which to
  4459. * add the value.
  4460. * \param addval Pointer to the \c Slapi_Value structure to add to
  4461. * the \c Slapi_ValueSet.
  4462. * \param flags If #SLAPI_VALUE_FLAG_PASSIN bit is set in the flags,
  4463. * the function will take over the ownership of the new value
  4464. * to be added without duplicating it.
  4465. * \warning This function does not verify if the value is already present
  4466. * in the \c Slapi_ValueSet structure. You can manually check
  4467. * this using \c slapi_valueset_first_value() and
  4468. * \c slapi_valueset_next_value().
  4469. * \see slapi_valueset_add_value()
  4470. * \see slapi_valueset_first_value()
  4471. * \see slapi_valueset_next_value()
  4472. */
  4473. void slapi_valueset_add_value_ext(Slapi_ValueSet *vs, const Slapi_Value *addval, unsigned long flags);
  4474. int slapi_valueset_add_attr_value_ext(const Slapi_Attr *a, Slapi_ValueSet *vs, Slapi_Value *addval, unsigned long flags);
  4475. /**
  4476. * Gets the first value in a \c Slapi_ValueSet structure.
  4477. *
  4478. * This function can be used with \c slapi_valueset_next_value() to
  4479. * iterate through all values in a \c Slapi_ValueSet structure.
  4480. *
  4481. * \param vs Pointer to the \c Slapi_ValueSet structure from which
  4482. * you wish to get the value.
  4483. * \param v Address of the pointer to the \c Slapi_Value structure
  4484. * for the returned value.
  4485. * \return The index of the value in the Slapi_ValueSet structure.
  4486. * \return \c -1 if there was no value.
  4487. * \warning This function gives a pointer to the actual value within
  4488. * the \c Slapi_ValueSet structure. You should not free it
  4489. * from memory.
  4490. * \warning You will need to pass this index to slapi_valueset_next_value()
  4491. * if you wish to iterate through all values in the valueset.
  4492. * \see slapi_valueset_next_value().
  4493. */
  4494. int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v );
  4495. /**
  4496. * Gets the next value in a \c Slapi_ValueSet structure.
  4497. *
  4498. * This is part of a pair of iterator functions. It should be
  4499. * called after first calling \c slapi_valueset_first_value().
  4500. *
  4501. * \param vs Pointer to the \c Slapi_ValueSet structure from which
  4502. * you wish to get the value.
  4503. * \param index Value returned by the previous call to \c slapi_valueset_first_value()
  4504. * or \c slapi_valueset_next_value().
  4505. * \param v Address of the pointer to the \c Slapi_Value structure
  4506. * for the returned value.
  4507. * \return The index of the value in the Slapi_ValueSet structure.
  4508. * \return \c -1 if there was no value.
  4509. * \warning This function gives a pointer to the actual value within
  4510. * the \c Slapi_ValueSet structure. You should not free it
  4511. * from memory.
  4512. * \warning You will need to pass this index to slapi_valueset_next_value()
  4513. * if you wish to iterate through all values in the valueset.
  4514. * \see slapi_valueset_first_value()
  4515. */
  4516. int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
  4517. /**
  4518. * Returns the number of values contained in a \c Slapi_ValueSet structure.
  4519. *
  4520. * \param vs Pointer to the \c Slapi_ValueSet structure of which
  4521. * you wish to get the count.
  4522. * \return The number of values contained in the \c Slapi_ValueSet structure.
  4523. */
  4524. int slapi_valueset_count( const Slapi_ValueSet *vs);
  4525. /**
  4526. * Checks if a \c Slapi_ValueSet structure has values
  4527. *
  4528. * \param vs Pointer to the \c Slapi_ValueSet structure of which
  4529. * you wish to get the count.
  4530. * \return 1 if there are no values contained in the \c Slapi_ValueSet structure.
  4531. * \return 0 if there are values contained in the \c Slapi_ValueSet structure.
  4532. */
  4533. int slapi_valueset_isempty( const Slapi_ValueSet *vs);
  4534. /**
  4535. * Initializes a \c Slapi_ValueSet with copies of the values of a \c Slapi_Mod structure.
  4536. *
  4537. * \param vs Pointer to the \c Slapi_ValueSet structure into which
  4538. * you wish to copy the values.
  4539. * \param smod Pointer to the \c Slapi_Mod structure from which you
  4540. * want to copy the values.
  4541. * \warning This function does not verify that the \c Slapi_ValueSet
  4542. * structure already contains values, so it is your responsibility
  4543. * to verify that there are no values prior to calling this function.
  4544. * If you do not verify this, the allocated memory space will leak.
  4545. * You can free existing values by calling slapi_valueset_done().
  4546. * \see slapi_valueset_done()
  4547. */
  4548. void slapi_valueset_set_from_smod(Slapi_ValueSet *vs, Slapi_Mod *smod);
  4549. /**
  4550. * Initializes a \c Slapi_ValueSet with copies of the values of another \c Slapi_ValueSet.
  4551. *
  4552. * \param vs1 Pointer to the \c Slapi_ValueSet structure into which
  4553. * you wish to copy the values.
  4554. * \param vs2 Pointer to the \c Slapi_ValueSet structure from which
  4555. * you want to copy the values.
  4556. * \warning This function does not verify that the \c Slapi_ValueSet
  4557. * structure already contains values, so it is your responsibility
  4558. * to verify that there are no values prior to calling this function.
  4559. * If you do not verify this, the allocated memory space will leak.
  4560. * You can free existing values by calling slapi_valueset_done().
  4561. * \see slapi_valueset_done()
  4562. */
  4563. void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
  4564. void slapi_valueset_join_attr_valueset(const Slapi_Attr *a, Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
  4565. /**
  4566. * Finds a requested value in a valueset.
  4567. *
  4568. * The syntax of a supplied attribute will be used to compare the values.
  4569. * This function can be used to check for duplicate values in a valueset.
  4570. *
  4571. * \param a Pointer to the attribute. This is used to determine the
  4572. * syntax of the values and how to match them.
  4573. * \param vs Pointer to the \c Slapi_ValueSet structure from which
  4574. * you wish to find the value.
  4575. * \param v Pointer to the \c Slapi_Value structure containing the
  4576. * value that you wish to find.
  4577. * \return Pointer to the value in the valueset if the value was found.
  4578. * \return \c NULL if the value was not found.
  4579. * \warning The returned pointer points to the actual value in the
  4580. * \c Slapi_ValueSet structure. It should not be freed.
  4581. */
  4582. Slapi_Value *slapi_valueset_find(const Slapi_Attr *a, const Slapi_ValueSet *vs, const Slapi_Value *v);
  4583. /* TODO - Pickup Doxygen work here */
  4584. /*
  4585. * operation routines
  4586. */
  4587. int slapi_op_abandoned( Slapi_PBlock *pb );
  4588. unsigned long slapi_op_get_type(Slapi_Operation * op);
  4589. void slapi_operation_set_flag(Slapi_Operation *op, unsigned long flag);
  4590. void slapi_operation_clear_flag(Slapi_Operation *op, unsigned long flag);
  4591. int slapi_operation_is_flag_set(Slapi_Operation *op, unsigned long flag);
  4592. int slapi_op_reserved(Slapi_PBlock *pb);
  4593. void slapi_operation_set_csngen_handler ( Slapi_Operation *op, void *callback );
  4594. void slapi_operation_set_replica_attr_handler ( Slapi_Operation *op, void *callback );
  4595. int slapi_operation_get_replica_attr ( Slapi_PBlock *pb, Slapi_Operation *op, const char *type, void *value );
  4596. char *slapi_op_type_to_string(unsigned long type);
  4597. int slapi_op_internal( Slapi_PBlock *pb );
  4598. /*
  4599. * LDAPMod manipulation routines
  4600. */
  4601. Slapi_Mods* slapi_mods_new( void );
  4602. void slapi_mods_init(Slapi_Mods *smods, int initCount);
  4603. void slapi_mods_init_byref(Slapi_Mods *smods, LDAPMod **mods);
  4604. void slapi_mods_init_passin(Slapi_Mods *smods, LDAPMod **mods);
  4605. void slapi_mods_free(Slapi_Mods **smods);
  4606. void slapi_mods_done(Slapi_Mods *smods);
  4607. void slapi_mods_insert_at(Slapi_Mods *smods, LDAPMod *mod, int pos);
  4608. void slapi_mods_insert_smod_at(Slapi_Mods *smods, Slapi_Mod *smod, int pos);
  4609. void slapi_mods_insert_before(Slapi_Mods *smods, LDAPMod *mod);
  4610. void slapi_mods_insert_smod_before(Slapi_Mods *smods, Slapi_Mod *smod);
  4611. void slapi_mods_insert_after(Slapi_Mods *smods, LDAPMod *mod);
  4612. void slapi_mods_insert_after(Slapi_Mods *smods, LDAPMod *mod);
  4613. void slapi_mods_add( Slapi_Mods *smods, int modtype, const char *type, unsigned long len, const char *val);
  4614. void slapi_mods_add_ldapmod(Slapi_Mods *smods, LDAPMod *mod);
  4615. void slapi_mods_add_modbvps( Slapi_Mods *smods, int modtype, const char *type, struct berval **bvps );
  4616. void slapi_mods_add_mod_values( Slapi_Mods *smods, int modtype, const char *type, Slapi_Value **va );
  4617. void slapi_mods_add_smod(Slapi_Mods *smods, Slapi_Mod *smod);
  4618. void slapi_mods_add_string( Slapi_Mods *smods, int modtype, const char *type, const char *val);
  4619. void slapi_mods_remove(Slapi_Mods *smods);
  4620. LDAPMod *slapi_mods_get_first_mod(Slapi_Mods *smods);
  4621. LDAPMod *slapi_mods_get_next_mod(Slapi_Mods *smods);
  4622. Slapi_Mod *slapi_mods_get_first_smod(Slapi_Mods *smods, Slapi_Mod *smod);
  4623. Slapi_Mod *slapi_mods_get_next_smod(Slapi_Mods *smods, Slapi_Mod *smod);
  4624. void slapi_mods_iterator_backone(Slapi_Mods *smods);
  4625. LDAPMod **slapi_mods_get_ldapmods_byref(Slapi_Mods *smods);
  4626. LDAPMod **slapi_mods_get_ldapmods_passout(Slapi_Mods *smods);
  4627. int slapi_mods_get_num_mods(const Slapi_Mods *smods);
  4628. void slapi_mods_dump(const Slapi_Mods *smods, const char *text);
  4629. Slapi_Mod* slapi_mod_new( void );
  4630. void slapi_mod_init(Slapi_Mod *smod, int initCount);
  4631. void slapi_mod_init_byval(Slapi_Mod *smod, const LDAPMod *mod);
  4632. void slapi_mod_init_byref(Slapi_Mod *smod, LDAPMod *mod);
  4633. void slapi_mod_init_passin(Slapi_Mod *smod, LDAPMod *mod);
  4634. /* init a mod and set the mod values to be a copy of the given valueset */
  4635. void slapi_mod_init_valueset_byval(Slapi_Mod *smod, int op, const char *type, const Slapi_ValueSet *svs);
  4636. void slapi_mod_add_value(Slapi_Mod *smod, const struct berval *val);
  4637. void slapi_mod_remove_value(Slapi_Mod *smod);
  4638. struct berval *slapi_mod_get_first_value(Slapi_Mod *smod);
  4639. struct berval *slapi_mod_get_next_value(Slapi_Mod *smod);
  4640. const char *slapi_mod_get_type(const Slapi_Mod *smod);
  4641. int slapi_mod_get_operation(const Slapi_Mod *smod);
  4642. void slapi_mod_set_type(Slapi_Mod *smod, const char *type);
  4643. void slapi_mod_set_operation(Slapi_Mod *smod, int op);
  4644. int slapi_mod_get_num_values(const Slapi_Mod *smod);
  4645. const LDAPMod *slapi_mod_get_ldapmod_byref(const Slapi_Mod *smod);
  4646. LDAPMod *slapi_mod_get_ldapmod_passout(Slapi_Mod *smod);
  4647. void slapi_mod_free(Slapi_Mod **smod);
  4648. void slapi_mod_done(Slapi_Mod *mod);
  4649. int slapi_mod_isvalid(const Slapi_Mod *mod);
  4650. void slapi_mod_dump(LDAPMod *mod, int n);
  4651. /* helper functions to translate between entry and a set of mods */
  4652. int slapi_mods2entry(Slapi_Entry **e, const char *dn, LDAPMod **attrs);
  4653. int slapi_entry2mods(const Slapi_Entry *e, char **dn, LDAPMod ***attrs);
  4654. #if defined(USE_OLD_UNHASHED)
  4655. int is_type_forbidden(const char *type);
  4656. #endif
  4657. /*
  4658. * routines for dealing with filters
  4659. */
  4660. int slapi_filter_get_choice( Slapi_Filter *f );
  4661. int slapi_filter_get_ava( Slapi_Filter *f, char **type, struct berval **bval );
  4662. int slapi_filter_get_attribute_type( Slapi_Filter *f, char **type );
  4663. int slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
  4664. char ***any, char **final );
  4665. Slapi_Filter *slapi_filter_list_first( Slapi_Filter *f );
  4666. Slapi_Filter *slapi_filter_list_next( Slapi_Filter *f, Slapi_Filter *fprev );
  4667. Slapi_Filter *slapi_str2filter( char *str );
  4668. Slapi_Filter *slapi_filter_join( int ftype, Slapi_Filter *f1,
  4669. Slapi_Filter *f2 );
  4670. Slapi_Filter *slapi_filter_join_ex( int ftype, Slapi_Filter *f1,
  4671. Slapi_Filter *f2, int recurse_always );
  4672. void slapi_filter_free( Slapi_Filter *f, int recurse );
  4673. int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
  4674. int verify_access );
  4675. int slapi_vattr_filter_test( Slapi_PBlock *pb, Slapi_Entry *e,
  4676. struct slapi_filter *f, int verify_access);
  4677. int slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f);
  4678. char *slapi_find_matching_paren( const char *str );
  4679. int slapi_filter_test_ext( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
  4680. int verify_access , int only_test_access);
  4681. int slapi_vattr_filter_test_ext( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
  4682. int verify_access , int only_test_access);
  4683. int slapi_filter_compare(struct slapi_filter *f1, struct slapi_filter *f2);
  4684. Slapi_Filter *slapi_filter_dup(Slapi_Filter *f);
  4685. int slapi_filter_changetype(Slapi_Filter *f, const char *newtype);
  4686. /**
  4687. * Normalize in-place the given filter. Normalizes the attribute types always.
  4688. * If norm_values is true, will also normalize the values.
  4689. *
  4690. * \param f the filter to normalize
  4691. * \param norm_values if true, normalize the values in addition to the type names
  4692. */
  4693. void slapi_filter_normalize(Slapi_Filter *f, PRBool norm_values);
  4694. /**
  4695. * Check whether a given attribute type is defined in schema or not
  4696. *
  4697. * \param attribute type name to be checked
  4698. * \return \c 0 if the attribute type is not defined in schema
  4699. * \return non-0 if the attribute type is defined in schema
  4700. */
  4701. int slapi_attr_syntax_exists(const char *type);
  4702. /**
  4703. * Reload internally registered attribute syntaxes.
  4704. *
  4705. * \param none
  4706. * \return \c 0 if the reload was successful.
  4707. * \return non-0 if the reload failed.
  4708. */
  4709. int slapi_reload_internal_attr_syntax(void);
  4710. /*
  4711. * slapi_filter_apply() is used to apply a function to each simple filter
  4712. * component within a complex filter. A 'simple filter' is anything other
  4713. * than AND, OR or NOT.
  4714. */
  4715. typedef int (*FILTER_APPLY_FN)( Slapi_Filter *f, void *arg);
  4716. int slapi_filter_apply( struct slapi_filter *f, FILTER_APPLY_FN fn, void *arg,
  4717. int *error_code );
  4718. /*
  4719. * Possible return values for slapi_filter_apply() and FILTER_APPLY_FNs.
  4720. * Note that a FILTER_APPLY_FN should return _STOP or _CONTINUE only.
  4721. */
  4722. #define SLAPI_FILTER_SCAN_STOP -1 /* premature abort */
  4723. #define SLAPI_FILTER_SCAN_ERROR -2 /* an error occurred */
  4724. #define SLAPI_FILTER_SCAN_NOMORE 0 /* success */
  4725. #define SLAPI_FILTER_SCAN_CONTINUE 1 /* continue scanning */
  4726. /* Error codes that slapi_filter_apply() may set in *error_code */
  4727. #define SLAPI_FILTER_UNKNOWN_FILTER_TYPE 2
  4728. /*
  4729. * Bit-Twiddlers
  4730. */
  4731. unsigned char slapi_setbit_uchar(unsigned char f,unsigned char bitnum);
  4732. unsigned char slapi_unsetbit_uchar(unsigned char f,unsigned char bitnum);
  4733. int slapi_isbitset_uchar(unsigned char f,unsigned char bitnum);
  4734. unsigned int slapi_setbit_int(unsigned int f,unsigned int bitnum);
  4735. unsigned int slapi_unsetbit_int(unsigned int f,unsigned int bitnum);
  4736. int slapi_isbitset_int(unsigned int f,unsigned int bitnum);
  4737. /*
  4738. * routines for sending entries and results to the client
  4739. */
  4740. int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e,
  4741. LDAPControl **ectrls, char **attrs, int attrsonly );
  4742. void slapi_send_ldap_result( Slapi_PBlock *pb, int err, char *matched,
  4743. char *text, int nentries, struct berval **urls );
  4744. int slapi_send_ldap_referral( Slapi_PBlock *pb, Slapi_Entry *e,
  4745. struct berval **refs, struct berval ***urls );
  4746. typedef int (*send_ldap_search_entry_fn_ptr_t)( Slapi_PBlock *pb,
  4747. Slapi_Entry *e, LDAPControl **ectrls, char **attrs, int attrsonly );
  4748. typedef void (*send_ldap_result_fn_ptr_t)( Slapi_PBlock *pb, int err,
  4749. char *matched, char *text, int nentries, struct berval **urls );
  4750. typedef int (*send_ldap_referral_fn_ptr_t)( Slapi_PBlock *pb,
  4751. Slapi_Entry *e, struct berval **refs, struct berval ***urls );
  4752. /*
  4753. * matching rule
  4754. */
  4755. typedef int (*mrFilterMatchFn) (void* filter, Slapi_Entry*, Slapi_Attr* vals);
  4756. /* returns: 0 filter matched
  4757. * -1 filter did not match
  4758. * >0 an LDAP error code
  4759. */
  4760. int slapi_mr_indexer_create(Slapi_PBlock* opb);
  4761. int slapi_mr_filter_index(Slapi_Filter* f, Slapi_PBlock* pb);
  4762. int slapi_berval_cmp(const struct berval* L, const struct berval* R);
  4763. #define SLAPI_BERVAL_EQ(L,R) ((L)->bv_len == (R)->bv_len && \
  4764. ! memcmp ((L)->bv_val, (R)->bv_val, (L)->bv_len))
  4765. typedef struct slapi_matchingRuleEntry {
  4766. char *mr_oid; /* the official oid */
  4767. char *mr_oidalias; /* not currently used */
  4768. char *mr_name; /* the official name */
  4769. char *mr_desc; /* a description */
  4770. char *mr_syntax; /* the assertion syntax OID */
  4771. int mr_obsolete; /* is mr obsolete? */
  4772. char **mr_compat_syntax; /* list of OIDs of other syntaxes that can use this matching rule */
  4773. } slapi_matchingRuleEntry;
  4774. typedef struct slapi_matchingRuleEntry Slapi_MatchingRuleEntry;
  4775. Slapi_MatchingRuleEntry *slapi_matchingrule_new(void);
  4776. void slapi_matchingrule_free(Slapi_MatchingRuleEntry **mrEntry,
  4777. int freeMembers);
  4778. int slapi_matchingrule_get(Slapi_MatchingRuleEntry *mr, int arg, void *value);
  4779. int slapi_matchingrule_set(Slapi_MatchingRuleEntry *mr, int arg, void *value);
  4780. int slapi_matchingrule_register(Slapi_MatchingRuleEntry *mrEntry);
  4781. int slapi_matchingrule_unregister(char *oid);
  4782. /**
  4783. * Is the given matching rule an ordering matching rule and is it
  4784. * compatible with the given syntax?
  4785. *
  4786. * \param name_or_oid Name or OID of a matching rule
  4787. * \param syntax_oid OID of a syntax
  4788. * \return \c TRUE if the matching rule is an ordering rule and can be used by the given syntax
  4789. * \return \c FALSE otherwise
  4790. */
  4791. int slapi_matchingrule_is_ordering(const char *oid_or_name, const char *syntax_oid);
  4792. /**
  4793. * Can the given syntax OID use the given matching rule name/OID? A
  4794. * matching rule can apply to more than one syntax. Use this function
  4795. * to determine if the given syntax can use the given matching rule.
  4796. *
  4797. * \param mr_name_or_oid Name or OID of a matching rule
  4798. * \param syntax_oid OID of a syntax
  4799. * \return \c TRUE if the syntax can be used with the matching rule
  4800. * \return \c FALSE otherwise
  4801. */
  4802. int slapi_matchingrule_is_compat(const char *mr_oid_or_name, const char *syntax_oid);
  4803. /**
  4804. * In certain cases, we can just use a simple compare function to
  4805. * generate index keys. The compare function is usually provided
  4806. * by the syntax plugin. If this is the case, we can skip generating
  4807. * an indexer in the index config code.
  4808. *
  4809. * \param mr_name_or_oid Name or OID of a matching rule
  4810. * \return \c TRUE if the matching rule can use a simple compare function
  4811. * \return \c FALSE otherwise
  4812. */
  4813. int slapi_matchingrule_can_use_compare_fn(const char *mr_oid_or_name);
  4814. /*
  4815. * access control
  4816. */
  4817. int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
  4818. struct berval *val, int access );
  4819. int slapi_acl_check_mods( Slapi_PBlock *pb, Slapi_Entry *e,
  4820. LDAPMod **mods, char **errbuf );
  4821. int slapi_acl_verify_aci_syntax(Slapi_PBlock *pb, Slapi_Entry *e, char **errbuf);
  4822. /*
  4823. * attribute stuff
  4824. */
  4825. int slapi_value_find( void *plugin, struct berval **vals, struct berval *v );
  4826. /*
  4827. * password handling
  4828. */
  4829. #define SLAPI_USERPWD_ATTR "userpassword"
  4830. int slapi_pw_find_sv( Slapi_Value **vals, const Slapi_Value *v );
  4831. /* value encoding encoding */
  4832. /* checks if the value is encoded with any known algorithm*/
  4833. int slapi_is_encoded(char *value);
  4834. /* encode value with the specified algorithm */
  4835. char* slapi_encode(char *value, char *alg);
  4836. /* encode value with the specified algorithm, or with local algorithm if pb
  4837. * and sdn are specified instead, or global algorithm if pb and sdn are null */
  4838. char* slapi_encode_ext(Slapi_PBlock *pb, const Slapi_DN *sdn, char *value, char *alg);
  4839. /* UTF8 related */
  4840. int slapi_has8thBit(unsigned char *s);
  4841. unsigned char *slapi_utf8StrToLower(unsigned char *s);
  4842. void slapi_utf8ToLower(unsigned char *s, unsigned char *d, int *ssz, int *dsz);
  4843. int slapi_utf8isUpper(unsigned char *s);
  4844. unsigned char *slapi_utf8StrToUpper(unsigned char *s);
  4845. void slapi_utf8ToUpper(unsigned char *s, unsigned char *d, int *ssz, int *dsz);
  4846. int slapi_utf8isLower(unsigned char *s);
  4847. int slapi_utf8casecmp(unsigned char *s0, unsigned char *s1);
  4848. int slapi_utf8ncasecmp(unsigned char *s0, unsigned char *s1, int n);
  4849. unsigned char *slapi_UTF8STRTOLOWER(char *s);
  4850. void slapi_UTF8TOLOWER(char *s, char *d, int *ssz, int *dsz);
  4851. int slapi_UTF8ISUPPER(char *s);
  4852. unsigned char *slapi_UTF8STRTOUPPER(char *s);
  4853. void slapi_UTF8TOUPPER(char *s, char *d, int *ssz, int *dsz);
  4854. int slapi_UTF8ISLOWER(char *s);
  4855. int slapi_UTF8CASECMP(char *s0, char *s1);
  4856. int slapi_UTF8NCASECMP(char *s0, char *s1, int n);
  4857. /*
  4858. * Interface to the API broker service
  4859. *
  4860. * The API broker allows plugins to publish an API that may be discovered
  4861. * and used dynamically at run time by other subsystems e.g. other plugins.
  4862. */
  4863. /* Function: slapi_apib_register
  4864. Description: this function allows publication of an interface
  4865. Parameters: guid - a string constant that uniquely identifies the
  4866. interface (must exist for the life of the server)
  4867. api - a vtable for the published api (must exist for the
  4868. life of the server or until the reference count,
  4869. if it exists, reaches zero)
  4870. Return: 0 if function succeeds
  4871. non-zero otherwise
  4872. */
  4873. int slapi_apib_register(char *guid, void **api); /* publish an interface */
  4874. /* Function: slapi_apib_unregister
  4875. Description: this function allows removal of a published interface
  4876. Parameters: guid - a string constant that uniquely identifies the interface
  4877. Return: 0 if function succeeds
  4878. non-zero otherwise
  4879. */
  4880. int slapi_apib_unregister(char *guid); /* remove interface from published list */
  4881. /* Function: slapi_apib_get_interface
  4882. Description: this function allows retrieval of a published interface,
  4883. if the api reference counted, then the reference
  4884. count is incremented
  4885. Parameters: guid - a string constant that uniquely identifies the
  4886. interface requested
  4887. api - the retrieved vtable for the published api (must NOT
  4888. be freed)
  4889. Return: 0 if function succeeds
  4890. non-zero otherwise
  4891. */
  4892. int slapi_apib_get_interface(char *guid, void ***api); /* retrieve an interface for use */
  4893. /* Function: slapi_apib_get_interface_all
  4894. Description: this function allows retrieval of a published interface,
  4895. if the api reference counted, then the reference
  4896. count is incremented
  4897. This will return all published interfaces for a given guid
  4898. Parameters: guid - a string constant that uniquely identifies the
  4899. interface requested
  4900. apilist - the retrieved list of vtables for the published api - caller
  4901. must free the apilist, but not the apilist elements
  4902. Return: 0 if function succeeds
  4903. non-zero otherwise
  4904. */
  4905. int slapi_apib_get_interface_all(char *guid, void ****apilist); /* retrieve all interfaces for guid */
  4906. /* Function: slapi_apib_make_reference_counted
  4907. Description: this function makes an interface a reference counted interface
  4908. it must be called prior to registering the interface
  4909. Parameters: api - the api to make a reference counted api
  4910. callback - if non-zero, this must be a pointer to a function
  4911. which the api broker will call when the ref count for
  4912. the api reaches zero. This function must return 0 if
  4913. it deregisters the api, non-zero otherwise
  4914. api - the retrieved vtable for the published api (must NOT
  4915. be freed)
  4916. Return: 0 if function succeeds
  4917. non-zero otherwise
  4918. */
  4919. typedef int (*slapi_apib_callback_on_zero)(void **api);
  4920. int slapi_apib_make_reference_counted(void **api,
  4921. slapi_apib_callback_on_zero callback);
  4922. /* Function: slapi_apib_addref
  4923. Description: this function adds to the reference count of an api - a
  4924. call to this function should be paired with a call
  4925. to slapi_apib_release
  4926. - ONLY FOR REFERENCE COUNTED APIS
  4927. Parameters: api - the api to add a reference to
  4928. Return: the new reference count
  4929. */
  4930. int slapi_apib_addref(void **api);
  4931. /* Function: slapi_apib_release
  4932. Description: this function adds to the reference count of an api - a
  4933. call to this function should be paired with a prior call
  4934. to slapi_apib_addref or slapi_apib_get_interface
  4935. - ONLY FOR REFERENCE COUNTED APIS
  4936. Parameters: api - the api to add a reference to
  4937. Return: the new reference count
  4938. */
  4939. int slapi_apib_release(void **api);
  4940. /**** End of API broker interface. *******************************************/
  4941. /* thread_data.c */
  4942. int slapi_td_init(int indexType);
  4943. int slapi_td_set_val(int indexType, void *value);
  4944. void slapi_td_get_val(int indexType, void **value);
  4945. int slapi_td_dn_init(void);
  4946. int slapi_td_set_dn(char *dn);
  4947. void slapi_td_get_dn(char **dn);
  4948. /* Thread Local Storage Index Types */
  4949. #define SLAPI_TD_REQUESTOR_DN 1
  4950. /*
  4951. * routines for dealing with controls
  4952. */
  4953. int slapi_control_present( LDAPControl **controls, char *oid,
  4954. struct berval **val, int *iscritical );
  4955. void slapi_register_supported_control( char *controloid,
  4956. unsigned long controlops );
  4957. LDAPControl * slapi_dup_control( LDAPControl *ctrl );
  4958. #define SLAPI_OPERATION_BIND 0x00000001UL
  4959. #define SLAPI_OPERATION_UNBIND 0x00000002UL
  4960. #define SLAPI_OPERATION_SEARCH 0x00000004UL
  4961. #define SLAPI_OPERATION_MODIFY 0x00000008UL
  4962. #define SLAPI_OPERATION_ADD 0x00000010UL
  4963. #define SLAPI_OPERATION_DELETE 0x00000020UL
  4964. #define SLAPI_OPERATION_MODDN 0x00000040UL
  4965. #define SLAPI_OPERATION_MODRDN SLAPI_OPERATION_MODDN
  4966. #define SLAPI_OPERATION_COMPARE 0x00000080UL
  4967. #define SLAPI_OPERATION_ABANDON 0x00000100UL
  4968. #define SLAPI_OPERATION_EXTENDED 0x00000200UL
  4969. #define SLAPI_OPERATION_ANY 0xFFFFFFFFUL
  4970. #define SLAPI_OPERATION_NONE 0x00000000UL
  4971. int slapi_get_supported_controls_copy( char ***ctrloidsp,
  4972. unsigned long **ctrlopsp );
  4973. int slapi_build_control( char *oid, BerElement *ber,
  4974. char iscritical, LDAPControl **ctrlp );
  4975. int slapi_build_control_from_berval( char *oid, struct berval *bvp,
  4976. char iscritical, LDAPControl **ctrlp );
  4977. /* Given an array of controls e.g. LDAPControl **ctrls, add the given
  4978. control to the end of the array, growing the array with realloc
  4979. e.g. slapi_add_control_ext(&ctrls, newctrl, 1);
  4980. if ctrls is NULL, the array will be created with malloc
  4981. if copy is true, the given control will be copied
  4982. if copy is false, the given control will be used and owned by the array
  4983. if copy is false, make sure the control can be freed by ldap_controls_free
  4984. */
  4985. void slapi_add_control_ext( LDAPControl ***ctrlsp, LDAPControl *newctrl, int copy );
  4986. /* Given an array of controls e.g. LDAPControl **ctrls, add all of the given
  4987. controls in the newctrls array to the end of ctrls, growing the array with realloc
  4988. if ctrls is NULL, the array will be created with malloc
  4989. if copy is true, each given control will be copied
  4990. if copy is false, each given control will be used and owned by the array
  4991. if copy is false, make sure each control can be freed by ldap_controls_free
  4992. */
  4993. void slapi_add_controls( LDAPControl ***ctrlsp, LDAPControl **newctrls, int copy );
  4994. /*
  4995. * routines for dealing with extended operations
  4996. */
  4997. char **slapi_get_supported_extended_ops_copy( void );
  4998. /*
  4999. * bind, including SASL
  5000. */
  5001. void slapi_register_supported_saslmechanism( char *mechanism );
  5002. char ** slapi_get_supported_saslmechanisms_copy( void );
  5003. void slapi_add_auth_response_control( Slapi_PBlock *pb, const char *binddn );
  5004. int slapi_add_pwd_control( Slapi_PBlock *pb, char *arg, long time );
  5005. int slapi_pwpolicy_make_response_control (Slapi_PBlock *pb, int seconds, int logins, int error);
  5006. /* Password Policy Response Control stuff - the error argument above */
  5007. #define LDAP_PWPOLICY_PWDEXPIRED 0
  5008. #define LDAP_PWPOLICY_ACCTLOCKED 1
  5009. #define LDAP_PWPOLICY_CHGAFTERRESET 2
  5010. #define LDAP_PWPOLICY_PWDMODNOTALLOWED 3
  5011. #define LDAP_PWPOLICY_MUSTSUPPLYOLDPWD 4
  5012. #define LDAP_PWPOLICY_INVALIDPWDSYNTAX 5
  5013. #define LDAP_PWPOLICY_PWDTOOSHORT 6
  5014. #define LDAP_PWPOLICY_PWDTOOYOUNG 7
  5015. #define LDAP_PWPOLICY_PWDINHISTORY 8
  5016. /*
  5017. * Password Policy API
  5018. */
  5019. /**
  5020. * Gets the password policy object for a given entry
  5021. *
  5022. * \param dn The dn of the entry whose password policy object you
  5023. * want returned
  5024. *
  5025. * \return A pointer to an opaque password policy object
  5026. * \return \c NULL if there is a problem getting the policy object
  5027. * \warning The caller should free the returned password policy
  5028. * object when finished by calling the slapi_pwpolicy_free()
  5029. * function.
  5030. * \see slapi_pwpolicy_free()
  5031. */
  5032. Slapi_PWPolicy *slapi_get_pwpolicy(Slapi_DN *dn);
  5033. /**
  5034. * Free a password policy object from memory
  5035. *
  5036. * \param pwpolicy The password policy object that you want to free
  5037. * \see slapi_get_pwpolicy()
  5038. */
  5039. void slapi_pwpolicy_free(Slapi_PWPolicy *pwpolicy);
  5040. /**
  5041. * Checks a password policy object to see if the password is expired
  5042. *
  5043. * \param pwpolicy The password policy object that you want to check
  5044. * \param e The entry that you want to check
  5045. * \param expire_time Fills in the expiration time if the password has not expired yet.
  5046. * You can pass \c NULL if you are not interested in the expiration time.
  5047. * \param remaining_grace Fills in the number of grace logins remaining if the password
  5048. * has already expired. You can pass \c NULL if you are not interested in the
  5049. * number of remaining grace logins.
  5050. *
  5051. * \return \c 1 if the password has expired
  5052. * \return \c 0 if the password has not expired
  5053. */
  5054. int slapi_pwpolicy_is_expired(Slapi_PWPolicy *pwpolicy, Slapi_Entry *e, time_t *expire_time, int *remaining_grace);
  5055. /**
  5056. * Checks a password policy to see if an account is locked
  5057. *
  5058. * \param pwpolicy The password policy object that you want to check
  5059. * \param e The entry that you want to check
  5060. * \param unlock_time Fills in the time the account will be unlocked if the account
  5061. * is currently locked. You can pass \c NULL if you are not interested in the
  5062. * unlock time.
  5063. *
  5064. * \return \c 1 if the account is locked
  5065. * \return \c 0 if the account is not locked
  5066. */
  5067. int slapi_pwpolicy_is_locked(Slapi_PWPolicy *pwpolicy, Slapi_Entry *e, time_t *unlock_time);
  5068. /**
  5069. * Checks a password policy to see if a password has been reset
  5070. *
  5071. * \param pwpolicy The password policy object that you want to check
  5072. * \param e The entry that you want to check
  5073. *
  5074. * \return \c 1 if the password has been reset
  5075. * \return \c 0 if the password has not been reset
  5076. */
  5077. int slapi_pwpolicy_is_reset(Slapi_PWPolicy *pwpolicy, Slapi_Entry *e);
  5078. /**
  5079. * Free an array of strings from memory
  5080. *
  5081. * \param array The array that you want to free
  5082. * \see slapi_ch_array_add()
  5083. * \see slapi_ch_array_dup()
  5084. */
  5085. void slapi_ch_array_free( char **array );
  5086. /**
  5087. * Duplicate an array of strings
  5088. *
  5089. * \param array The array that you want to duplicate
  5090. * \return A newly allocated copy of \c array
  5091. * \return \c NULL if there is a problem duplicating the array
  5092. * \warning The caller should free the returned array when finished
  5093. * by calling the slapi_ch_array_free() function.
  5094. * \see slapi_ch_array_free()
  5095. */
  5096. char ** slapi_ch_array_dup( char **array );
  5097. /**
  5098. * Add a string to an array of strings
  5099. *
  5100. * \param array The array to add the string to
  5101. * \param string The string to add to the array
  5102. * \warning The \c string parameter is not copied. If you do not
  5103. * want to hand the memory used by \c string over to the
  5104. * array, you should duplicate it first by calling the
  5105. * slapi_ch_strdup() function.
  5106. * \warning If \c *a is \c NULL, a new array will be allocated.
  5107. * \see slapi_ch_array_free()
  5108. */
  5109. void slapi_ch_array_add( char ***array, char *string );
  5110. /**
  5111. * Add a string to an array of strings
  5112. *
  5113. * \param array The array to add the string to
  5114. * \param string The string to add to the array
  5115. * \warning The \c string parameter is not copied. If you do not
  5116. * want to hand the memory used by \c string over to the
  5117. * array, you should duplicate it first by calling the
  5118. * slapi_ch_strdup() function.
  5119. * \warning If \c *a is \c NULL, a new array will be allocated.
  5120. * \see slapi_ch_array_free()
  5121. * \return the total number of elements in the array.
  5122. */
  5123. int slapi_ch_array_add_ext(char ***array, char *string);
  5124. /**
  5125. * Find a string in an array of strings
  5126. *
  5127. * \param array The array of strings
  5128. * \param string The string to look for in the array
  5129. * \return NULL if there is no match
  5130. * \return 1 if there is a match
  5131. */
  5132. int slapi_ch_array_utf8_inlist(char **array, char *string);
  5133. /**
  5134. * Returns the error string of an ldap result code, but it can also handle
  5135. * library errors(negative result codes)
  5136. *
  5137. * \param result The result code
  5138. * \return The error text string of the result code
  5139. */
  5140. char *slapi_err2string(int result);
  5141. /**
  5142. * Check if the server has started shutting down
  5143. *
  5144. * \return 1 if the server is shutting down
  5145. */
  5146. int slapi_is_shutting_down(void);
  5147. /*
  5148. * checking routines for allocating and freeing memory
  5149. */
  5150. char * slapi_ch_malloc( unsigned long size );
  5151. char * slapi_ch_realloc( char *block, unsigned long size );
  5152. char * slapi_ch_calloc( unsigned long nelem, unsigned long size );
  5153. char * slapi_ch_strdup( const char *s );
  5154. void slapi_ch_free( void **ptr );
  5155. void slapi_ch_free_string( char **s );
  5156. struct berval* slapi_ch_bvdup(const struct berval*);
  5157. struct berval** slapi_ch_bvecdup(struct berval**);
  5158. void slapi_ch_bvfree(struct berval** v);
  5159. char * slapi_ch_smprintf(const char *fmt, ...)
  5160. #ifdef __GNUC__
  5161. __attribute__ ((format (printf, 1, 2)));
  5162. #else
  5163. ;
  5164. #endif
  5165. /*
  5166. * syntax plugin routines
  5167. * THESE ARE DEPRECATED - the first argument is the syntax plugin
  5168. * we do not support that style of call anymore - use the slapi_attr_
  5169. * versions below instead
  5170. */
  5171. int slapi_call_syntax_values2keys_sv( void *vpi, Slapi_Value **vals,
  5172. Slapi_Value ***ivals, int ftype );
  5173. int slapi_call_syntax_values2keys_sv_pb( void *vpi, Slapi_Value **vals,
  5174. Slapi_Value ***ivals, int ftype, Slapi_PBlock *pb );
  5175. int slapi_call_syntax_assertion2keys_ava_sv( void *vpi, Slapi_Value *val,
  5176. Slapi_Value ***ivals, int ftype );
  5177. int slapi_call_syntax_assertion2keys_sub_sv( void *vpi, char *initial,
  5178. char **any, char *final, Slapi_Value ***ivals );
  5179. int slapi_attr_values2keys_sv( const Slapi_Attr *sattr, Slapi_Value **vals,
  5180. Slapi_Value ***ivals, int ftype );
  5181. int slapi_attr_values2keys_sv_pb( const Slapi_Attr *sattr, Slapi_Value **vals,
  5182. Slapi_Value ***ivals, int ftype, Slapi_PBlock *pb );
  5183. int slapi_attr_assertion2keys_ava_sv( const Slapi_Attr *sattr, Slapi_Value *val,
  5184. Slapi_Value ***ivals, int ftype );
  5185. int slapi_attr_assertion2keys_sub_sv( const Slapi_Attr *sattr, char *initial,
  5186. char **any, char *final, Slapi_Value ***ivals );
  5187. /**
  5188. * Normalize the given value using the syntax associated with the
  5189. * given attribute. It will attempt to normalize the value in place.
  5190. * If it cannot, it will return the normalized value in retval. If
  5191. * trim_spaces is true, whitepace characters will be trimmed from the
  5192. * ends of the string. If sattr is NULL, the type will be used to look
  5193. * up the attribute syntax. If sattr is not NULL, type is ignored. If
  5194. * retval is set, the caller is responsible for freeing it.
  5195. *
  5196. * \param pb Slapi_PBlock to use
  5197. * \param sattr attribute to get the syntax from
  5198. * \param type attribute to get the syntax from if sattr is NULL
  5199. * \param val value to normalize in place - must be NULL terminated
  5200. * \param trim_spaces trim whitespace from ends of string
  5201. * \param retval if value could not be normalized in place, this is the malloc'd memory containg the new value - caller must free
  5202. */
  5203. void slapi_attr_value_normalize(
  5204. Slapi_PBlock *pb,
  5205. const Slapi_Attr *sattr, /* if sattr is NULL, type must be attr type name */
  5206. const char *type,
  5207. char *val,
  5208. int trim_spaces,
  5209. char **retval
  5210. );
  5211. /**
  5212. * Normalize the given value using the matching rule associated with the
  5213. * given attribute and given filter type. It will attempt to normalize
  5214. * the value in place. If it cannot, it will return the normalized value
  5215. * in retval. If trim_spaces is true, whitepace characters will be trimmed
  5216. * from the ends of the string. If sattr is NULL, the type will be used to look
  5217. * up the attribute syntax. If sattr is not NULL, type is ignored. If
  5218. * retval is set, the caller is responsible for freeing it. The filter_type
  5219. * corresponds to the matching rule to use - LDAP_FILTER_GE or LDAP_FILTER_LE
  5220. * will use the ORDERING matching rule normalization function - LDAP_FILTER_EQUALITY
  5221. * will use the EQUALITY matching rule normalization function - LDAP_FILTER_SUBSTRINGS
  5222. * will use the SUBSTRINGS matching rule normalization function. If the given
  5223. * filter_type is 0, or some other value other than specified above, or there is no
  5224. * matching rule corresponding to the given filter type, the default normalization
  5225. * function provided by the attribute syntax will be used.
  5226. *
  5227. * \param pb Slapi_PBlock to use
  5228. * \param sattr attribute to get the syntax from
  5229. * \param type attribute to get the syntax from if sattr is NULL
  5230. * \param val value to normalize in place - must be NULL terminated
  5231. * \param trim_spaces trim whitespace from ends of string
  5232. * \param retval if value could not be normalized in place, this is the malloc'd memory containg the new value - caller must free
  5233. * \param filter_type one of the values specified above, or 0
  5234. */
  5235. void slapi_attr_value_normalize_ext(
  5236. Slapi_PBlock *pb,
  5237. const Slapi_Attr *sattr, /* if sattr is NULL, type must be attr type name */
  5238. const char *type,
  5239. char *val,
  5240. int trim_spaces,
  5241. char **retval,
  5242. unsigned long filter_type
  5243. );
  5244. /*
  5245. * internal operation and plugin callback routines
  5246. */
  5247. typedef void (*plugin_result_callback)(int rc, void *callback_data);
  5248. typedef int (*plugin_referral_entry_callback)(char * referral,
  5249. void *callback_data);
  5250. typedef int (*plugin_search_entry_callback)(Slapi_Entry *e,
  5251. void *callback_data);
  5252. void slapi_free_search_results_internal(Slapi_PBlock *pb);
  5253. /*
  5254. * The following functions can be used for internal operations based on DN
  5255. * as well as on uniqueid. These functions should be used by all new plugins
  5256. * and preferrably old plugins should be changed to use them to take
  5257. * advantage of new plugin configuration capabilities and to use an
  5258. * extensible interface.
  5259. *
  5260. * These functions return -1 if pb is NULL and 0 otherwise.
  5261. * The SLAPI_PLUGIN_INTOP_RESULT pblock parameter should be checked to
  5262. * check if the operation was successful.
  5263. *
  5264. * Helper functions are provided to set up pblock parameters currently used
  5265. * by the functions, e.g., slapi_search_internal_set_pb().
  5266. * Additional parameters may be set directly in the pblock.
  5267. */
  5268. int slapi_search_internal_pb(Slapi_PBlock *pb);
  5269. int slapi_search_internal_callback_pb(Slapi_PBlock *pb, void *callback_data,
  5270. plugin_result_callback prc, plugin_search_entry_callback psec,
  5271. plugin_referral_entry_callback prec);
  5272. int slapi_add_internal_pb(Slapi_PBlock *pb);
  5273. int slapi_modify_internal_pb(Slapi_PBlock *pb);
  5274. int slapi_modrdn_internal_pb(Slapi_PBlock *pb);
  5275. int slapi_delete_internal_pb(Slapi_PBlock *pb);
  5276. int slapi_seq_internal_callback_pb(Slapi_PBlock *pb, void *callback_data,
  5277. plugin_result_callback res_callback,
  5278. plugin_search_entry_callback srch_callback,
  5279. plugin_referral_entry_callback ref_callback);
  5280. void slapi_search_internal_set_pb(Slapi_PBlock *pb, const char *base,
  5281. int scope, const char *filter, char **attrs, int attrsonly,
  5282. LDAPControl **controls, const char *uniqueid,
  5283. Slapi_ComponentId *plugin_identity, int operation_flags);
  5284. void slapi_search_internal_set_pb_ext(Slapi_PBlock *pb, Slapi_DN *sdn,
  5285. int scope, const char *filter, char **attrs, int attrsonly,
  5286. LDAPControl **controls, const char *uniqueid,
  5287. Slapi_ComponentId *plugin_identity, int operation_flags);
  5288. void slapi_add_entry_internal_set_pb(Slapi_PBlock *pb, Slapi_Entry *e,
  5289. LDAPControl **controls, Slapi_ComponentId *plugin_identity,
  5290. int operation_flags);
  5291. int slapi_add_internal_set_pb(Slapi_PBlock *pb, const char *dn,
  5292. LDAPMod **attrs, LDAPControl **controls,
  5293. Slapi_ComponentId *plugin_identity, int operation_flags);
  5294. void slapi_modify_internal_set_pb(Slapi_PBlock *pb, const char *dn,
  5295. LDAPMod **mods, LDAPControl **controls, const char *uniqueid,
  5296. Slapi_ComponentId *plugin_identity, int operation_flags);
  5297. void slapi_modify_internal_set_pb_ext(Slapi_PBlock *pb, const Slapi_DN *sdn,
  5298. LDAPMod **mods, LDAPControl **controls, const char *uniqueid,
  5299. Slapi_ComponentId *plugin_identity, int operation_flags);
  5300. /**
  5301. * Set \c Slapi_PBlock to perform modrdn/rename internally
  5302. *
  5303. * \param pblock - Slapi_PBlock to be set
  5304. * \param olddn - original dn to be renamed; it should have been normalized
  5305. * \param newrdn - new leaf rdn if any; it should have been normalized
  5306. * \param newsuperior - new parent dn if any; it should have been normalized
  5307. * \param deloldrdn \c 0 - keep original rdn \c non-zero - delete original rdn
  5308. * \param controls
  5309. * \param uniqueid
  5310. * \param plugin_identity
  5311. * \param operation_flags
  5312. */
  5313. void slapi_rename_internal_set_pb_ext(Slapi_PBlock *pb,
  5314. const Slapi_DN *olddn, const char *newrdn,
  5315. const Slapi_DN *newsuperior, int deloldrdn,
  5316. LDAPControl **controls, const char *uniqueid,
  5317. Slapi_ComponentId *plugin_identity, int operation_flags);
  5318. void slapi_delete_internal_set_pb(Slapi_PBlock *pb, const char *dn,
  5319. LDAPControl **controls, const char *uniqueid,
  5320. Slapi_ComponentId *plugin_identity, int operation_flags);
  5321. void slapi_seq_internal_set_pb(Slapi_PBlock *pb, char *ibase, int type,
  5322. char *attrname, char *val, char **attrs, int attrsonly,
  5323. LDAPControl **controls, Slapi_ComponentId *plugin_identity,
  5324. int operation_flags);
  5325. /*
  5326. * slapi_search_internal_get_entry() finds an entry given a dn. It returns
  5327. * an LDAP error code (LDAP_SUCCESS if all goes well).
  5328. */
  5329. int slapi_search_internal_get_entry( Slapi_DN *dn, char ** attrlist,
  5330. Slapi_Entry **ret_entry , void *caller_identity);
  5331. /*
  5332. * interface for registering object extensions.
  5333. */
  5334. typedef void *(*slapi_extension_constructor_fnptr)(void *object, void *parent);
  5335. typedef void (*slapi_extension_destructor_fnptr)(void *extension,
  5336. void *object, void *parent);
  5337. int slapi_register_object_extension( const char *pluginname,
  5338. const char *objectname, slapi_extension_constructor_fnptr constructor,
  5339. slapi_extension_destructor_fnptr destructor, int *objecttype,
  5340. int *extensionhandle);
  5341. /* objects that can be extended (possible values for the objectname param.) */
  5342. #define SLAPI_EXT_CONNECTION "Connection"
  5343. #define SLAPI_EXT_OPERATION "Operation"
  5344. #define SLAPI_EXT_ENTRY "Entry"
  5345. #define SLAPI_EXT_MTNODE "Mapping Tree Node"
  5346. /* Module names for SLAPI_EXT_ENTRY */
  5347. #define SLAPI_EXTMOD_PWPOLICY "Password Policy"
  5348. /* Object names in SLAPI_EXT_ENTRY */
  5349. #define SLAPI_EXTOBJ_ENTRY_PW "UnhashedPW"
  5350. void *slapi_get_object_extension(int objecttype, void *object,
  5351. int extensionhandle);
  5352. void slapi_set_object_extension(int objecttype, void *object,
  5353. int extensionhandle, void *extension);
  5354. /*
  5355. * interface to allow a plugin to register additional plugins.
  5356. */
  5357. typedef int (*slapi_plugin_init_fnptr)( Slapi_PBlock *pb );
  5358. int slapi_register_plugin( const char *plugintype, int enabled,
  5359. const char *initsymbol, slapi_plugin_init_fnptr initfunc,
  5360. const char *name, char **argv, void *group_identity);
  5361. int slapi_register_plugin_ext( const char *plugintype, int enabled,
  5362. const char *initsymbol, slapi_plugin_init_fnptr initfunc,
  5363. const char *name, char **argv, void *group_identity, int precedence);
  5364. /*
  5365. * logging
  5366. */
  5367. int slapi_log_error( int severity, char *subsystem, char *fmt, ... )
  5368. #ifdef __GNUC__
  5369. __attribute__ ((format (printf, 3, 4)));
  5370. #else
  5371. ;
  5372. #endif
  5373. int slapi_log_error_ext( int severity, char *subsystem, char *fmt, va_list varg1, va_list varg2);
  5374. /* allowed values for the "severity" parameter */
  5375. #define SLAPI_LOG_FATAL 0
  5376. #define SLAPI_LOG_TRACE 1
  5377. #define SLAPI_LOG_PACKETS 2
  5378. #define SLAPI_LOG_ARGS 3
  5379. #define SLAPI_LOG_CONNS 4
  5380. #define SLAPI_LOG_BER 5
  5381. #define SLAPI_LOG_FILTER 6
  5382. #define SLAPI_LOG_CONFIG 7
  5383. #define SLAPI_LOG_ACL 8
  5384. #define SLAPI_LOG_SHELL 9
  5385. #define SLAPI_LOG_PARSE 10
  5386. #define SLAPI_LOG_HOUSE 11
  5387. #define SLAPI_LOG_REPL 12
  5388. #define SLAPI_LOG_CACHE 13
  5389. #define SLAPI_LOG_PLUGIN 14
  5390. #define SLAPI_LOG_TIMING 15
  5391. #define SLAPI_LOG_BACKLDBM 16
  5392. #define SLAPI_LOG_ACLSUMMARY 17 /* ACLSUMMARY must be the last (log.c) */
  5393. int slapi_is_loglevel_set( const int loglevel );
  5394. /*
  5395. * locks and synchronization
  5396. */
  5397. typedef struct slapi_mutex Slapi_Mutex;
  5398. typedef struct slapi_condvar Slapi_CondVar;
  5399. #ifdef USE_POSIX_RWLOCKS
  5400. typedef pthread_rwlock_t Slapi_RWLock;
  5401. #else
  5402. typedef struct slapi_rwlock Slapi_RWLock;
  5403. #endif
  5404. Slapi_Mutex *slapi_new_mutex( void );
  5405. void slapi_destroy_mutex( Slapi_Mutex *mutex );
  5406. void slapi_lock_mutex( Slapi_Mutex *mutex );
  5407. int slapi_unlock_mutex( Slapi_Mutex *mutex );
  5408. Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex );
  5409. void slapi_destroy_condvar( Slapi_CondVar *cvar );
  5410. int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout );
  5411. int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all );
  5412. /**
  5413. * Creates a new read/write lock.
  5414. *
  5415. * \return A pointer to a \c Slapi_RWLock
  5416. *
  5417. * \note Free the returned lock by calling slapi_destroy_rwlock() when finished
  5418. *
  5419. * \see slapi_destroy_rwlock()
  5420. * \see slapi_rwlock_rdlock()
  5421. * \see slapi_rwlock_wrlock()
  5422. * \see slapi_rwlock_unlock()
  5423. */
  5424. Slapi_RWLock *slapi_new_rwlock( void );
  5425. /**
  5426. * Free a read/write lock
  5427. *
  5428. * \see slapi_new_rwlock()
  5429. */
  5430. void slapi_destroy_rwlock( Slapi_RWLock *rwlock );
  5431. /**
  5432. * Acquires a reader lock
  5433. *
  5434. * \return 0 if successful
  5435. * \return Non-zero if an error occurred
  5436. *
  5437. * \note Release the acquired lock by calling slapi_rwlock_unlock()
  5438. * \note It is safe for a thread to hold multiple reader locks, but
  5439. * you must call slapi_rwlock_unlock() for each aquired lock.
  5440. *
  5441. * \see slapi_rwlock_unlock()
  5442. */
  5443. int slapi_rwlock_rdlock( Slapi_RWLock *rwlock );
  5444. /**
  5445. * Acquires a writer lock
  5446. *
  5447. * \return 0 if successful
  5448. * \return Non-zero if an error occurred
  5449. *
  5450. * \note Release the acquired lock by calling slapi_rwlock_unlock()
  5451. *
  5452. * \see slapi_rwlock_unlock()
  5453. */
  5454. int slapi_rwlock_wrlock( Slapi_RWLock *rwlock );
  5455. /**
  5456. * Releases a reader or writer lock
  5457. *
  5458. * \return 0 if successful
  5459. * \return Non-zero if an error occurred
  5460. *
  5461. * \see slapi_rwlock_rdlock()
  5462. * \see slapi_rwlock_wrlock()
  5463. */
  5464. int slapi_rwlock_unlock( Slapi_RWLock *rwlock );
  5465. /*
  5466. * thread-safe LDAP connections
  5467. */
  5468. /**
  5469. * Initializes an LDAP connection, and returns a handle to the connection.
  5470. *
  5471. * \param ldaphost Hostname or IP address - NOTE: for TLS or GSSAPI, should be the FQDN
  5472. * \param ldapport LDAP server port number (default 389)
  5473. * \param secure \c 0 - LDAP \c 1 - LDAPS \c 2 - startTLS
  5474. * \param shared \c 0 - single thread access \c 1 - LDAP* will be shared among multiple threads
  5475. * \return A pointer to an LDAP* handle
  5476. *
  5477. * \note Use #slapi_ldap_unbind() to close and free the handle
  5478. *
  5479. * \see slapi_ldap_unbind()
  5480. * \see slapi_ldap_init_ext()
  5481. */
  5482. LDAP *slapi_ldap_init( char *ldaphost, int ldapport, int secure, int shared );
  5483. /**
  5484. * Closes an LDAP connection, and frees memory associated with the handle
  5485. *
  5486. * \param ld the LDAP connection handle
  5487. *
  5488. * \see slapi_ldap_init()
  5489. * \see slapi_ldap_init_ext()
  5490. */
  5491. void slapi_ldap_unbind( LDAP *ld );
  5492. /**
  5493. * Initializes an LDAP connection, and returns a handle to the connection.
  5494. *
  5495. * \param ldapurl A full LDAP url in the form ldap[s]://hostname:port or
  5496. * ldapi://path - if \c NULL, #hostname, #port, and #secure must be provided
  5497. * \param hostname Hostname or IP address - NOTE: for TLS or GSSAPI, should be the FQDN
  5498. * \param port LDAP server port number (default 389)
  5499. * \param secure \c 0 - LDAP \c 1 - LDAPS \c 2 - startTLS
  5500. * \param shared \c 0 - single thread access \c 1 - LDAP* will be shared among multiple threads
  5501. * \param filename - currently not supported
  5502. * \return A pointer to an LDAP* handle
  5503. *
  5504. * \note Use #slapi_ldap_unbind() to close and free the handle
  5505. *
  5506. * \see slapi_ldap_unbind()
  5507. * \see slapi_ldap_init()
  5508. */
  5509. LDAP *slapi_ldap_init_ext(
  5510. const char *ldapurl, /* full ldap url */
  5511. const char *hostname, /* can also use this to override
  5512. host in url */
  5513. int port, /* can also use this to override port in url */
  5514. int secure, /* 0 for ldap, 1 for ldaps, 2 for starttls -
  5515. override proto in url */
  5516. int shared, /* if true, LDAP* will be shared among multiple threads */
  5517. const char *filename /* for ldapi */
  5518. );
  5519. /**
  5520. * The LDAP bind request - this function handles all of the different types of mechanisms
  5521. * including simple, sasl, and external (client cert auth)
  5522. *
  5523. * \param ld the LDAP connection handle
  5524. * \param bindid Either a bind DN for simple bind or a SASL identity
  5525. * \param creds usually a password for simple bind or SASL credentials
  5526. * \param mech a valid mech that can be passed to ldap_sasl_bind (or NULL for simple)
  5527. * \param serverctrls optional controls to send (or NULL)
  5528. * \param returnedctrls optional controls returned by the server - use NULL if you just
  5529. * want to ignore them - if you pass in a variable for this, you
  5530. * are responsible for freeing the result (ldap_controls_free)
  5531. * \param timeout timeout or NULL for no timeout (wait forever)
  5532. * \param msgidp LDAP message ID \c NULL - call bind synchronously \c non-NULL -
  5533. * call bind asynchronously - you are responsible for calling ldap_result
  5534. * to read the response
  5535. * \return an LDAP error code
  5536. *
  5537. * \see ldap_sasl_bind()
  5538. * \see ldap_sasl_bind_s()
  5539. * \see ldap_controls_free()
  5540. * \see ldap_result()
  5541. */
  5542. int slapi_ldap_bind(
  5543. LDAP *ld, /* ldap connection */
  5544. const char *bindid, /* usually a bind DN for simple bind */
  5545. const char *creds, /* usually a password for simple bind */
  5546. const char *mech, /* name of mechanism */
  5547. LDAPControl **serverctrls, /* additional controls to send */
  5548. LDAPControl ***returnedctrls, /* returned controls */
  5549. struct timeval *timeout, /* timeout */
  5550. int *msgidp /* pass in non-NULL for async handling */
  5551. );
  5552. /**
  5553. * Create either a v1 Proxy Auth Control or a v2 Proxied Auth Control
  5554. *
  5555. * \param ld the LDAP connection handle
  5556. * \param dn The proxy DN
  5557. * \param creds usually a password for simple bind or SASL credentials
  5558. * \param ctl_iscritical \c 0 - not critical \c 1 - critical
  5559. * \param usev2 \c 0 - use the v1 Proxy Auth \c 1 - use the v2 Proxied Auth
  5560. * \param ctrlp the control to send - caller is responsible for freeing (ldap_control_free)
  5561. * \return an LDAP error code
  5562. *
  5563. * \see ldap_control_free()
  5564. */
  5565. int slapi_ldap_create_proxyauth_control (
  5566. LDAP *ld, /* only used to get current ber options */
  5567. const char *dn, /* proxy dn */
  5568. const char ctl_iscritical,
  5569. int usev2, /* use the v2 (.18) control instead */
  5570. LDAPControl **ctrlp /* value to return */
  5571. );
  5572. /**
  5573. * Parse a line from an LDIF record returned by ldif_getline() and return the LDAP
  5574. * attribute type and value from the line. ldif_getline() will encode the LDIF continuation
  5575. * lines, and slapi_ldif_parse_line() will take those into consideration when returning the
  5576. * value.
  5577. *
  5578. * \param line LDIF record line returned by ldif_getline()
  5579. * \param type The attribute type returned
  5580. * \param value The attribute value returned
  5581. * \param freeval \c NULL - use malloc for the value->bv_val - caller is responsible for freeing
  5582. * \c an int* - slapi_ldif_parse_line will usually return pointers into the line
  5583. * parameter that should not be freed - if slapi_ldif_parse_line needs to allocate
  5584. * memory for the value, *freeval will be set to 1 to indicate the caller must
  5585. * free value->bv_val
  5586. * \return \c 0 - success \c 1 - failure
  5587. *
  5588. * \note line is written to - you must pass in writable memory - line must be NULL terminated
  5589. *
  5590. * \see ldif_getline()
  5591. */
  5592. int slapi_ldif_parse_line(
  5593. char *line, /* line to parse */
  5594. struct berval *type, /* attribute type to return */
  5595. struct berval *value, /* attribute value to return */
  5596. int *freeval /* values will usually be returned in place as pointers into line - if the value is a url, the value will be malloced and must be freed by the caller */
  5597. );
  5598. /**
  5599. * Parse an LDAP DN string. Return an array of RDN strings, terminated by a NULL. This
  5600. * function differs from the standard openldap ldap_explode_dn, which will escape utf-8
  5601. * characters. In the directory server, we do not want to escape them. The caller
  5602. * should use slapi_ldap_value_free to free the returned memory when finished.
  5603. *
  5604. * \param dn The LDAP DN
  5605. * \param notypes set to true (1) to return only the attribute values with no attribute types
  5606. * \return \c An array of RDN strings - use slapi_ch_array_free to free
  5607. *
  5608. * \see slapi_ldap_value_free()
  5609. */
  5610. char **slapi_ldap_explode_dn(
  5611. const char *dn, /* dn to explode */
  5612. int notypes /* set to true to return only the values with no types */
  5613. );
  5614. /**
  5615. * Parse an LDAP RDN string. Return an array of AVA strings, terminated by a NULL. This
  5616. * function differs from the standard openldap ldap_explode_rdn, which will escape utf-8
  5617. * characters. In the directory server, we do not want to escape them. The caller
  5618. * should use slapi_ldap_value_free to free the returned memory when finished.
  5619. *
  5620. * \param dn The LDAP RDN
  5621. * \param notypes set to true (1) to return only the attribute values with no attribute types
  5622. * \return \c An array of AVA strings - use slapi_ch_array_free to free
  5623. *
  5624. * \see slapi_ldap_value_free()
  5625. */
  5626. char **slapi_ldap_explode_rdn(
  5627. const char *rdn, /* rdn to explode */
  5628. int notypes /* set to true to return only the values with no types */
  5629. );
  5630. /*
  5631. * computed attributes
  5632. */
  5633. struct _computed_attr_context;
  5634. typedef struct _computed_attr_context computed_attr_context;
  5635. typedef int (*slapi_compute_output_t)(computed_attr_context *c,Slapi_Attr *a , Slapi_Entry *e);
  5636. typedef int (*slapi_compute_callback_t)(computed_attr_context *c,char* type,Slapi_Entry *e,slapi_compute_output_t outputfn);
  5637. typedef int (*slapi_search_rewrite_callback_t)(Slapi_PBlock *pb);
  5638. int slapi_compute_add_evaluator(slapi_compute_callback_t function);
  5639. int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function);
  5640. int compute_rewrite_search_filter(Slapi_PBlock *pb);
  5641. /*
  5642. * routines for dealing with backends
  5643. */
  5644. Slapi_Backend *slapi_be_new( const char *type, const char *name,
  5645. int isprivate, int logchanges );
  5646. void slapi_be_free(Slapi_Backend **be);
  5647. Slapi_Backend *slapi_be_select( const Slapi_DN *sdn );
  5648. Slapi_Backend *slapi_be_select_by_instance_name( const char *name );
  5649. int slapi_be_exist(const Slapi_DN *sdn);
  5650. void slapi_be_delete_onexit(Slapi_Backend *be);
  5651. void slapi_be_set_readonly(Slapi_Backend *be, int readonly);
  5652. int slapi_be_get_readonly(Slapi_Backend *be);
  5653. int slapi_be_getentrypoint(Slapi_Backend *be, int entrypoint, void **ret_fnptr,
  5654. Slapi_PBlock *pb);
  5655. int slapi_be_setentrypoint(Slapi_Backend *be, int entrypoint, void *ret_fnptr,
  5656. Slapi_PBlock *pb);
  5657. int slapi_be_logchanges(Slapi_Backend *be);
  5658. int slapi_be_issuffix(const Slapi_Backend *be, const Slapi_DN *suffix );
  5659. void slapi_be_addsuffix(Slapi_Backend *be,const Slapi_DN *suffix);
  5660. char * slapi_be_get_name(Slapi_Backend * be);
  5661. const Slapi_DN *slapi_be_getsuffix(Slapi_Backend *be, int n);
  5662. Slapi_Backend* slapi_get_first_backend(char **cookie);
  5663. Slapi_Backend* slapi_get_next_backend(char *cookie);
  5664. int slapi_be_private( Slapi_Backend *be );
  5665. void * slapi_be_get_instance_info(Slapi_Backend * be);
  5666. void slapi_be_set_instance_info(Slapi_Backend * be, void * data);
  5667. Slapi_DN * slapi_get_first_suffix(void ** node, int show_private);
  5668. Slapi_DN * slapi_get_next_suffix(void ** node, int show_private);
  5669. Slapi_DN * slapi_get_next_suffix_ext(void ** node, int show_private);
  5670. int slapi_is_root_suffix(Slapi_DN * dn);
  5671. const Slapi_DN *slapi_get_suffix_by_dn(const Slapi_DN *dn);
  5672. const char * slapi_be_gettype(Slapi_Backend *be);
  5673. /**
  5674. * Start database transaction
  5675. *
  5676. * \param pb Pblock which is supposed to set (Slapi_Backend *) to SLAPI_BACKEND
  5677. * \return 0 if successful
  5678. * \return SLAPI_BACK_TRANSACTION_NOT_SUPPORTED if transaction support is not available for this backend
  5679. * \return Non-zero if an error occurred
  5680. *
  5681. * \see slapi_back_transaction_commit
  5682. * \see slapi_back_transaction_abort
  5683. */
  5684. int slapi_back_transaction_begin(Slapi_PBlock *pb);
  5685. /**
  5686. * Commit database transaction
  5687. *
  5688. * \param pb Pblock which is used to start transaction
  5689. * \return 0 if successful
  5690. * \return Non-zero if an error occurred
  5691. *
  5692. * \see slapi_back_transaction_start
  5693. * \see slapi_back_transaction_abort
  5694. */
  5695. int slapi_back_transaction_commit(Slapi_PBlock *pb);
  5696. /**
  5697. * Abort database transaction
  5698. *
  5699. * \param pb Pblock which is used to start transaction
  5700. * \return 0 if successful
  5701. * \return Non-zero if an error occurred
  5702. *
  5703. * \see slapi_back_transaction_commit
  5704. * \see slapi_back_transaction_abort
  5705. */
  5706. int slapi_back_transaction_abort(Slapi_PBlock *pb);
  5707. /**
  5708. * Checks if the connection type is LDAPI
  5709. *
  5710. * \param pb Parameter block.
  5711. *
  5712. * \return \c 1 if connection type is LDAPI
  5713. * \return \c 0 if connection is not LDAPI
  5714. */
  5715. int slapi_is_ldapi_conn(Slapi_PBlock *pb);
  5716. int slapi_be_is_flag_set(Slapi_Backend * be, int flag);
  5717. void slapi_be_set_flag(Slapi_Backend * be, int flag);
  5718. #define SLAPI_BE_FLAG_REMOTE_DATA 0x1 /* entries held by backend are remote */
  5719. #define SLAPI_BE_FLAG_DONT_BYPASS_FILTERTEST 0x10 /* force to call filter_test (search only) */
  5720. /* These functions allow a plugin to register for callback when
  5721. * a backend state change
  5722. */
  5723. typedef void (*slapi_backend_state_change_fnptr)(void *handle, char *be_name,
  5724. int old_be_state, int new_be_state);
  5725. void slapi_register_backend_state_change(void * handle, slapi_backend_state_change_fnptr funct);
  5726. int slapi_unregister_backend_state_change(void * handle);
  5727. #define SLAPI_BE_STATE_ON 1 /* backend is ON */
  5728. #define SLAPI_BE_STATE_OFFLINE 2 /* backend is OFFLINE (import process) */
  5729. #define SLAPI_BE_STATE_DELETE 3 /* backend has been deleted */
  5730. /*
  5731. * Distribution.
  5732. */
  5733. /* SLAPI_BE_ALL_BACKENDS is a special value that is returned by
  5734. * a distribution plugin function to indicate that all backends
  5735. * should be searched (it is only used for search operations).
  5736. *
  5737. * SLAPI_BE_NO_BACKEND indicates no more backend is available or allowed
  5738. * SLAPI_BE_REMOTE_BACKEND indicates that the are not locally available
  5739. */
  5740. #define SLAPI_BE_ALL_BACKENDS -1
  5741. #define SLAPI_BE_NO_BACKEND -2
  5742. #define SLAPI_BE_REMOTE_BACKEND -3
  5743. /*
  5744. * virtual attribute service
  5745. */
  5746. /* General flags (flags parameter) */
  5747. #define SLAPI_REALATTRS_ONLY 1
  5748. #define SLAPI_VIRTUALATTRS_ONLY 2
  5749. #define SLAPI_VIRTUALATTRS_REQUEST_POINTERS 4 /* I want to receive pointers into the entry, if possible */
  5750. #define SLAPI_VIRTUALATTRS_LIST_OPERATIONAL_ATTRS 8 /* Include operational attributes in attribute lists */
  5751. #define SLAPI_VIRTUALATTRS_SUPPRESS_SUBTYPES 16 /* I want only the requested attribute */
  5752. /* Buffer disposition flags (buffer_flags parameter) */
  5753. #define SLAPI_VIRTUALATTRS_RETURNED_POINTERS 1
  5754. #define SLAPI_VIRTUALATTRS_RETURNED_COPIES 2
  5755. #define SLAPI_VIRTUALATTRS_REALATTRS_ONLY 4
  5756. #define SLAPI_VIRTUALATTRS_VALUES_CACHEABLE 8
  5757. /* Attribute type name disposition values (type_name_disposition parameter) */
  5758. #define SLAPI_VIRTUALATTRS_TYPE_NAME_MATCHED_EXACTLY_OR_ALIAS 1
  5759. #define SLAPI_VIRTUALATTRS_TYPE_NAME_MATCHED_SUBTYPE 2
  5760. #define SLAPI_VIRTUALATTRS_NOT_FOUND -1
  5761. #define SLAPI_VIRTUALATTRS_LOOP_DETECTED -2
  5762. typedef struct _vattr_type_thang vattr_type_thang;
  5763. typedef struct _vattr_get_thang vattr_get_thang;
  5764. vattr_get_thang *slapi_vattr_getthang_first(vattr_get_thang *t);
  5765. vattr_get_thang *slapi_vattr_getthang_next(vattr_get_thang *t);
  5766. int slapi_vattr_values_type_thang_get(
  5767. /* Entry we're interested in */ Slapi_Entry *e,
  5768. /* attr type */ vattr_type_thang *type_thang,
  5769. /* pointer to result set */ Slapi_ValueSet** results,
  5770. int *type_name_disposition, char **actual_type_name, int flags,
  5771. int *buffer_flags);
  5772. int slapi_vattr_values_get(
  5773. /* Entry we're interested in */ Slapi_Entry *e,
  5774. /* attr type name */ char *type,
  5775. /* pointer to result set */ Slapi_ValueSet** results,
  5776. int *type_name_disposition, char **actual_type_name, int flags,
  5777. int *buffer_flags);
  5778. int slapi_vattr_values_get_ex(
  5779. /* Entry we're interested in */ Slapi_Entry *e,
  5780. /* attr type name */ char *type,
  5781. /* pointer to result set */ Slapi_ValueSet*** results,
  5782. int **type_name_disposition, char ***actual_type_name, int flags,
  5783. int *buffer_flags, int *subtype_count);
  5784. int slapi_vattr_namespace_values_get(
  5785. /* Entry we're interested in */ Slapi_Entry *e,
  5786. /* backend namespace dn */ Slapi_DN *namespace_dn,
  5787. /* attr type name */ char *type,
  5788. /* pointer to result set */ Slapi_ValueSet*** results,
  5789. int **type_name_disposition, char ***actual_type_name, int flags,
  5790. int *buffer_flags, int *subtype_count);
  5791. void slapi_vattr_values_free(Slapi_ValueSet **value, char **actual_type_name,
  5792. int flags);
  5793. int slapi_vattr_value_compare(
  5794. /* Entry we're interested in */ Slapi_Entry *e,
  5795. /* attr type name */ char *type,
  5796. Slapi_Value *test_this,/* pointer to result */ int *result,
  5797. int flags);
  5798. int slapi_vattr_namespace_value_compare(
  5799. /* Entry we're interested in */ Slapi_Entry *e,
  5800. /* backend namespace dn */ Slapi_DN *namespace_dn,
  5801. /* attr type name */ const char *type,
  5802. Slapi_Value *test_this,/* pointer to result */ int *result,
  5803. int flags);
  5804. int slapi_vattr_list_attrs(
  5805. /* Entry we're interested in */ Slapi_Entry *e,
  5806. /* pointer to receive the list */ vattr_type_thang **types,
  5807. int flags, int *buffer_flags);
  5808. void slapi_vattr_attrs_free(vattr_type_thang **types, int flags);
  5809. char *vattr_typethang_get_name(vattr_type_thang *t);
  5810. unsigned long vattr_typethang_get_flags(vattr_type_thang *t);
  5811. vattr_type_thang *vattr_typethang_next(vattr_type_thang *t);
  5812. vattr_type_thang *vattr_typethang_first(vattr_type_thang *t);
  5813. int slapi_vattr_schema_check_type(Slapi_Entry *e, char *type);
  5814. /* roles */
  5815. typedef int (*roles_check_fn_type)(Slapi_Entry *entry_to_check, Slapi_DN *role_dn, int *present);
  5816. int slapi_role_check(Slapi_Entry *entry_to_check, Slapi_DN *role_dn, int *present);
  5817. void slapi_register_role_check(roles_check_fn_type check_fn);
  5818. /* DSE */
  5819. /* Front end configuration */
  5820. typedef int (*dseCallbackFn)(Slapi_PBlock *, Slapi_Entry *, Slapi_Entry *,
  5821. int *, char*, void *);
  5822. /*
  5823. * Note: DSE callback functions MUST return one of these three values:
  5824. *
  5825. * SLAPI_DSE_CALLBACK_OK -- no errors occurred; apply changes.
  5826. * SLAPI_DSE_CALLBACK_ERROR -- an error occurred; don't apply changes.
  5827. * SLAPI_DSE_CALLBACK_DO_NOT_APPLY -- no error, but do not apply changes.
  5828. *
  5829. * SLAPI_DSE_CALLBACK_DO_NOT_APPLY should only be returned by modify
  5830. * callbacks (i.e., those registered with operation==SLAPI_OPERATION_MODIFY).
  5831. * A return value of SLAPI_DSE_CALLBACK_DO_NOT_APPLY is treated the same as
  5832. * SLAPI_DSE_CALLBACK_ERROR for all other operations.
  5833. */
  5834. #define SLAPI_DSE_CALLBACK_OK (1)
  5835. #define SLAPI_DSE_CALLBACK_ERROR (-1)
  5836. #define SLAPI_DSE_CALLBACK_DO_NOT_APPLY (0)
  5837. /*
  5838. * Flags for slapi_config_register_callback() and
  5839. * slapi_config_remove_callback()
  5840. */
  5841. #define DSE_FLAG_PREOP 0x0001
  5842. #define DSE_FLAG_POSTOP 0x0002
  5843. /* This is the size of the returntext parameter passed to the config callback function,
  5844. which is the "char *" argument to dseCallbackFn above */
  5845. #define SLAPI_DSE_RETURNTEXT_SIZE 512 /* for use by callback functions */
  5846. int slapi_config_register_callback(int operation, int flags, const char *base, int scope, const char *filter, dseCallbackFn fn, void *fn_arg);
  5847. int slapi_config_remove_callback(int operation, int flags, const char *base, int scope, const char *filter, dseCallbackFn fn);
  5848. /******************************************************************************
  5849. * Online tasks interface (to support import, export, etc)
  5850. * After some cleanup, we could consider making these public.
  5851. */
  5852. /* task states */
  5853. #define SLAPI_TASK_SETUP 0
  5854. #define SLAPI_TASK_RUNNING 1
  5855. #define SLAPI_TASK_FINISHED 2
  5856. #define SLAPI_TASK_CANCELLED 3
  5857. /* task flag (pb_task_flags)*/
  5858. #define SLAPI_TASK_RUNNING_AS_TASK 0x0
  5859. #define SLAPI_TASK_RUNNING_FROM_COMMANDLINE 0x1
  5860. /* task flags (set by the task-control code) */
  5861. #define SLAPI_TASK_DESTROYING 0x01 /* queued event for destruction */
  5862. int slapi_task_register_handler(const char *name, dseCallbackFn func);
  5863. void slapi_task_begin(Slapi_Task *task, int total_work);
  5864. void slapi_task_inc_progress(Slapi_Task *task);
  5865. void slapi_task_finish(Slapi_Task *task, int rc);
  5866. void slapi_task_cancel(Slapi_Task *task, int rc);
  5867. int slapi_task_get_state(Slapi_Task *task);
  5868. void slapi_task_set_data(Slapi_Task *task, void *data);
  5869. void * slapi_task_get_data(Slapi_Task *task);
  5870. void slapi_task_inc_refcount(Slapi_Task *task);
  5871. void slapi_task_dec_refcount(Slapi_Task *task);
  5872. int slapi_task_get_refcount(Slapi_Task *task);
  5873. void slapi_task_set_destructor_fn(Slapi_Task *task, TaskCallbackFn func);
  5874. void slapi_task_set_cancel_fn(Slapi_Task *task, TaskCallbackFn func);
  5875. void slapi_task_status_changed(Slapi_Task *task);
  5876. void slapi_task_log_status(Slapi_Task *task, char *format, ...)
  5877. #ifdef __GNUC__
  5878. __attribute__ ((format (printf, 2, 3)));
  5879. #else
  5880. ;
  5881. #endif
  5882. void slapi_task_log_notice(Slapi_Task *task, char *format, ...)
  5883. #ifdef __GNUC__
  5884. __attribute__ ((format (printf, 2, 3)));
  5885. #else
  5886. ;
  5887. #endif
  5888. void slapi_task_log_status_ext(Slapi_Task *task, char *format, va_list varg);
  5889. void slapi_task_log_notice_ext(Slapi_Task *task, char *format, va_list varg);
  5890. /*
  5891. * slapi_new_task: create new task, fill in DN, and setup modify callback
  5892. * argument:
  5893. * dn: task dn
  5894. * result:
  5895. * Success: Slapi_Task object
  5896. * Failure: NULL
  5897. */
  5898. Slapi_Task *slapi_new_task(const char *dn);
  5899. /* slapi_destroy_task: destroy a task
  5900. * argument:
  5901. * task: task to destroy
  5902. * result:
  5903. * none
  5904. */
  5905. void slapi_destroy_task(void *arg);
  5906. /* End of interface to support online tasks **********************************/
  5907. /* Slapi_Counter Interface */
  5908. Slapi_Counter *slapi_counter_new(void);
  5909. void slapi_counter_init(Slapi_Counter *counter);
  5910. void slapi_counter_destroy(Slapi_Counter **counter);
  5911. PRUint64 slapi_counter_increment(Slapi_Counter *counter);
  5912. PRUint64 slapi_counter_decrement(Slapi_Counter *counter);
  5913. PRUint64 slapi_counter_add(Slapi_Counter *counter, PRUint64 addvalue);
  5914. PRUint64 slapi_counter_subtract(Slapi_Counter *counter, PRUint64 subvalue);
  5915. PRUint64 slapi_counter_set_value(Slapi_Counter *counter, PRUint64 newvalue);
  5916. PRUint64 slapi_counter_get_value(Slapi_Counter *counter);
  5917. /* Binder-based (connection centric) resource limits */
  5918. /*
  5919. * Valid values for `type' parameter to slapi_reslimit_register().
  5920. */
  5921. #define SLAPI_RESLIMIT_TYPE_INT 0
  5922. /*
  5923. * Status codes returned by all functions.
  5924. */
  5925. #define SLAPI_RESLIMIT_STATUS_SUCCESS 0 /* goodness */
  5926. #define SLAPI_RESLIMIT_STATUS_NOVALUE 1 /* no value is available */
  5927. #define SLAPI_RESLIMIT_STATUS_INIT_FAILURE 2 /* initialization failed */
  5928. #define SLAPI_RESLIMIT_STATUS_PARAM_ERROR 3 /* bad parameter */
  5929. #define SLAPI_RESLIMIT_STATUS_UNKNOWN_HANDLE 4 /* unregistered handle */
  5930. #define SLAPI_RESLIMIT_STATUS_INTERNAL_ERROR 5 /* unexpected error */
  5931. /*
  5932. * Functions.
  5933. */
  5934. int slapi_reslimit_register( int type, const char *attrname, int *handlep );
  5935. int slapi_reslimit_get_integer_limit( Slapi_Connection *conn, int handle,
  5936. int *limitp );
  5937. /* END of Binder-based resource limits API */
  5938. /**
  5939. * Returns the current time
  5940. *
  5941. * \return The current time
  5942. */
  5943. time_t slapi_current_time( void );
  5944. /*
  5945. * Plugin and parameter block related macros (remainder of this file).
  5946. */
  5947. /*
  5948. * Plugin version. Note that the Directory Server will load version 01
  5949. * and 02 plugins, but some server features require 03 plugins.
  5950. */
  5951. #define SLAPI_PLUGIN_VERSION_01 "01"
  5952. #define SLAPI_PLUGIN_VERSION_02 "02"
  5953. #define SLAPI_PLUGIN_VERSION_03 "03"
  5954. #define SLAPI_PLUGIN_CURRENT_VERSION SLAPI_PLUGIN_VERSION_03
  5955. #define SLAPI_PLUGIN_IS_COMPAT(x) \
  5956. ((strcmp((x), SLAPI_PLUGIN_VERSION_01) == 0) || \
  5957. (strcmp((x), SLAPI_PLUGIN_VERSION_02) == 0) || \
  5958. (strcmp((x), SLAPI_PLUGIN_VERSION_03) == 0))
  5959. #define SLAPI_PLUGIN_IS_V2(x) \
  5960. ((strcmp((x)->plg_version, SLAPI_PLUGIN_VERSION_02) == 0) || \
  5961. (strcmp((x)->plg_version, SLAPI_PLUGIN_VERSION_03) == 0))
  5962. #define SLAPI_PLUGIN_IS_V3(x) \
  5963. (strcmp((x)->plg_version, SLAPI_PLUGIN_VERSION_03) == 0)
  5964. /* this one just has to be human readable */
  5965. #define SLAPI_PLUGIN_SUPPORTED_VERSIONS "01,02,03"
  5966. /*
  5967. * types of plugin interfaces
  5968. */
  5969. #define SLAPI_PLUGIN_EXTENDEDOP 2
  5970. #define SLAPI_PLUGIN_PREOPERATION 3
  5971. #define SLAPI_PLUGIN_POSTOPERATION 4
  5972. #define SLAPI_PLUGIN_MATCHINGRULE 5
  5973. #define SLAPI_PLUGIN_SYNTAX 6
  5974. #define SLAPI_PLUGIN_ACL 7
  5975. #define SLAPI_PLUGIN_BEPREOPERATION 8
  5976. #define SLAPI_PLUGIN_BEPOSTOPERATION 9
  5977. #define SLAPI_PLUGIN_ENTRY 10
  5978. #define SLAPI_PLUGIN_TYPE_OBJECT 11
  5979. #define SLAPI_PLUGIN_INTERNAL_PREOPERATION 12
  5980. #define SLAPI_PLUGIN_INTERNAL_POSTOPERATION 13
  5981. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME 14
  5982. #define SLAPI_PLUGIN_VATTR_SP 15
  5983. #define SLAPI_PLUGIN_REVER_PWD_STORAGE_SCHEME 16
  5984. #define SLAPI_PLUGIN_LDBM_ENTRY_FETCH_STORE 17
  5985. #define SLAPI_PLUGIN_INDEX 18
  5986. #define SLAPI_PLUGIN_BETXNPREOPERATION 19
  5987. #define SLAPI_PLUGIN_BETXNPOSTOPERATION 20
  5988. /*
  5989. * special return values for extended operation plugins (zero or positive
  5990. * return values should be LDAP error codes as defined in ldap.h)
  5991. */
  5992. #define SLAPI_PLUGIN_EXTENDED_SENT_RESULT -1
  5993. #define SLAPI_PLUGIN_EXTENDED_NOT_HANDLED -2
  5994. /*
  5995. * Return values of plugins:
  5996. */
  5997. #define SLAPI_PLUGIN_SUCCESS 0 /* 0 is treated as success implicitely */
  5998. #define SLAPI_PLUGIN_FAILURE -1 /* common failure */
  5999. #define SLAPI_PLUGIN_NOOP -2 /* Special in be_pre_op/be_txn_pre_op.
  6000. * Treat as SUCCESS, but skip the backend op.
  6001. * Also, return SUCCESS to the client/supplier.
  6002. * Necessary for the replication conflicts. */
  6003. /*
  6004. * the following can be used as the second argument to the
  6005. * slapi_pblock_get() and slapi_pblock_set() calls.
  6006. */
  6007. /* backend, connection, operation */
  6008. #define SLAPI_BACKEND 130
  6009. #define SLAPI_CONNECTION 131
  6010. #define SLAPI_OPERATION 132
  6011. #define SLAPI_REQUESTOR_ISROOT 133
  6012. #define SLAPI_BE_TYPE 135
  6013. #define SLAPI_BE_READONLY 136
  6014. #define SLAPI_BE_LASTMOD 137
  6015. #define SLAPI_CONN_ID 139
  6016. #define SLAPI_BACKEND_COUNT 860
  6017. /* operation */
  6018. #define SLAPI_OPINITIATED_TIME 140
  6019. #define SLAPI_REQUESTOR_DN 141
  6020. #define SLAPI_REQUESTOR_SDN 852
  6021. #define SLAPI_REQUESTOR_NDN 156
  6022. #define SLAPI_OPERATION_PARAMETERS 138
  6023. #define SLAPI_OPERATION_TYPE 590
  6024. #define SLAPI_OPERATION_AUTHTYPE 741
  6025. #define SLAPI_OPERATION_ID 744
  6026. #define SLAPI_OPERATION_SSF 750
  6027. #define SLAPI_IS_REPLICATED_OPERATION 142
  6028. #define SLAPI_IS_MMR_REPLICATED_OPERATION 153
  6029. #define SLAPI_IS_LEGACY_REPLICATED_OPERATION 154
  6030. #define SLAPI_SKIP_MODIFIED_ATTRS 155
  6031. /* connection */
  6032. #define SLAPI_CONN_DN 143
  6033. #define SLAPI_CONN_CLIENTNETADDR 850
  6034. #define SLAPI_CONN_SERVERNETADDR 851
  6035. #define SLAPI_CONN_IS_REPLICATION_SESSION 149
  6036. #define SLAPI_CONN_IS_SSL_SESSION 747
  6037. #define SLAPI_CONN_CERT 743
  6038. #define SLAPI_CONN_AUTHMETHOD 746
  6039. #define SLAPI_CONN_SASL_SSF 748
  6040. #define SLAPI_CONN_SSL_SSF 749
  6041. #define SLAPI_CONN_LOCAL_SSF 751
  6042. /*
  6043. * Types of authentication for SLAPI_CONN_AUTHMETHOD
  6044. * (and deprecated SLAPI_CONN_AUTHTYPE)
  6045. */
  6046. #define SLAPD_AUTH_NONE "none"
  6047. #define SLAPD_AUTH_SIMPLE "simple"
  6048. #define SLAPD_AUTH_SSL "SSL"
  6049. #define SLAPD_AUTH_SASL "SASL " /* followed by the mechanism name */
  6050. #define SLAPD_AUTH_OS "OS"
  6051. /* Command Line Arguments */
  6052. #define SLAPI_ARGC 147
  6053. #define SLAPI_ARGV 148
  6054. /* Slapd config file directory */
  6055. #define SLAPI_CONFIG_DIRECTORY 281
  6056. /* DSE flags */
  6057. #define SLAPI_DSE_DONT_WRITE_WHEN_ADDING 282
  6058. #define SLAPI_DSE_MERGE_WHEN_ADDING 283
  6059. #define SLAPI_DSE_DONT_CHECK_DUPS 284
  6060. #define SLAPI_DSE_REAPPLY_MODS 287
  6061. #define SLAPI_DSE_IS_PRIMARY_FILE 289
  6062. /* internal schema flags */
  6063. #define SLAPI_SCHEMA_FLAGS 285
  6064. /* urp flags */
  6065. #define SLAPI_URP_NAMING_COLLISION_DN 286
  6066. #define SLAPI_URP_TOMBSTONE_UNIQUEID 288
  6067. /* common to all plugins */
  6068. #define SLAPI_PLUGIN 3
  6069. #define SLAPI_PLUGIN_PRIVATE 4
  6070. #define SLAPI_PLUGIN_TYPE 5
  6071. #define SLAPI_PLUGIN_ARGV 6
  6072. #define SLAPI_PLUGIN_ARGC 7
  6073. #define SLAPI_PLUGIN_VERSION 8
  6074. #define SLAPI_PLUGIN_OPRETURN 9
  6075. #define SLAPI_PLUGIN_OBJECT 10
  6076. #define SLAPI_PLUGIN_DESTROY_FN 11
  6077. #define SLAPI_PLUGIN_DESCRIPTION 12
  6078. typedef struct slapi_plugindesc {
  6079. char *spd_id;
  6080. char *spd_vendor;
  6081. char *spd_version;
  6082. char *spd_description;
  6083. } Slapi_PluginDesc;
  6084. #define SLAPI_PLUGIN_IDENTITY 13
  6085. #define SLAPI_PLUGIN_PRECEDENCE 14
  6086. /* common for internal plugin_ops */
  6087. #define SLAPI_PLUGIN_INTOP_RESULT 15
  6088. #define SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES 16
  6089. #define SLAPI_PLUGIN_INTOP_SEARCH_REFERRALS 17
  6090. /* miscellaneous plugin functions */
  6091. #define SLAPI_PLUGIN_CLOSE_FN 210
  6092. #define SLAPI_PLUGIN_START_FN 212
  6093. #define SLAPI_PLUGIN_CLEANUP_FN 232
  6094. #define SLAPI_PLUGIN_POSTSTART_FN 233
  6095. /* extendedop plugin functions */
  6096. #define SLAPI_PLUGIN_EXT_OP_FN 300
  6097. #define SLAPI_PLUGIN_EXT_OP_OIDLIST 301
  6098. #define SLAPI_PLUGIN_EXT_OP_NAMELIST 302
  6099. /* preoperation plugin functions */
  6100. #define SLAPI_PLUGIN_PRE_BIND_FN 401
  6101. #define SLAPI_PLUGIN_PRE_UNBIND_FN 402
  6102. #define SLAPI_PLUGIN_PRE_SEARCH_FN 403
  6103. #define SLAPI_PLUGIN_PRE_COMPARE_FN 404
  6104. #define SLAPI_PLUGIN_PRE_MODIFY_FN 405
  6105. #define SLAPI_PLUGIN_PRE_MODRDN_FN 406
  6106. #define SLAPI_PLUGIN_PRE_ADD_FN 407
  6107. #define SLAPI_PLUGIN_PRE_DELETE_FN 408
  6108. #define SLAPI_PLUGIN_PRE_ABANDON_FN 409
  6109. #define SLAPI_PLUGIN_PRE_ENTRY_FN 410
  6110. #define SLAPI_PLUGIN_PRE_REFERRAL_FN 411
  6111. #define SLAPI_PLUGIN_PRE_RESULT_FN 412
  6112. /* internal preoperation plugin functions */
  6113. #define SLAPI_PLUGIN_INTERNAL_PRE_ADD_FN 420
  6114. #define SLAPI_PLUGIN_INTERNAL_PRE_MODIFY_FN 421
  6115. #define SLAPI_PLUGIN_INTERNAL_PRE_MODRDN_FN 422
  6116. #define SLAPI_PLUGIN_INTERNAL_PRE_DELETE_FN 423
  6117. #define SLAPI_PLUGIN_INTERNAL_PRE_BIND_FN 424
  6118. /* preoperation plugin to the backend */
  6119. #define SLAPI_PLUGIN_BE_PRE_ADD_FN 450
  6120. #define SLAPI_PLUGIN_BE_PRE_MODIFY_FN 451
  6121. #define SLAPI_PLUGIN_BE_PRE_MODRDN_FN 452
  6122. #define SLAPI_PLUGIN_BE_PRE_DELETE_FN 453
  6123. #define SLAPI_PLUGIN_BE_PRE_CLOSE_FN 454
  6124. #define SLAPI_PLUGIN_BE_PRE_BACKUP_FN 455
  6125. /* preoperation plugin to the backend - just after transaction creation */
  6126. #define SLAPI_PLUGIN_BE_TXN_PRE_ADD_FN 460
  6127. #define SLAPI_PLUGIN_BE_TXN_PRE_MODIFY_FN 461
  6128. #define SLAPI_PLUGIN_BE_TXN_PRE_MODRDN_FN 462
  6129. #define SLAPI_PLUGIN_BE_TXN_PRE_DELETE_FN 463
  6130. #define SLAPI_PLUGIN_BE_TXN_PRE_DELETE_TOMBSTONE_FN 464
  6131. /* postoperation plugin functions */
  6132. #define SLAPI_PLUGIN_POST_BIND_FN 501
  6133. #define SLAPI_PLUGIN_POST_UNBIND_FN 502
  6134. #define SLAPI_PLUGIN_POST_SEARCH_FN 503
  6135. #define SLAPI_PLUGIN_POST_COMPARE_FN 504
  6136. #define SLAPI_PLUGIN_POST_MODIFY_FN 505
  6137. #define SLAPI_PLUGIN_POST_MODRDN_FN 506
  6138. #define SLAPI_PLUGIN_POST_ADD_FN 507
  6139. #define SLAPI_PLUGIN_POST_DELETE_FN 508
  6140. #define SLAPI_PLUGIN_POST_ABANDON_FN 509
  6141. #define SLAPI_PLUGIN_POST_ENTRY_FN 510
  6142. #define SLAPI_PLUGIN_POST_REFERRAL_FN 511
  6143. #define SLAPI_PLUGIN_POST_RESULT_FN 512
  6144. #define SLAPI_PLUGIN_POST_SEARCH_FAIL_FN 513
  6145. /* internal preoperation plugin functions */
  6146. #define SLAPI_PLUGIN_INTERNAL_POST_ADD_FN 520
  6147. #define SLAPI_PLUGIN_INTERNAL_POST_MODIFY_FN 521
  6148. #define SLAPI_PLUGIN_INTERNAL_POST_MODRDN_FN 522
  6149. #define SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN 523
  6150. /* postoperation plugin to the backend */
  6151. #define SLAPI_PLUGIN_BE_POST_ADD_FN 550
  6152. #define SLAPI_PLUGIN_BE_POST_MODIFY_FN 551
  6153. #define SLAPI_PLUGIN_BE_POST_MODRDN_FN 552
  6154. #define SLAPI_PLUGIN_BE_POST_DELETE_FN 553
  6155. #define SLAPI_PLUGIN_BE_POST_OPEN_FN 554
  6156. #define SLAPI_PLUGIN_BE_POST_BACKUP_FN 555
  6157. /* postoperation plugin to the backend - just before transaction commit */
  6158. #define SLAPI_PLUGIN_BE_TXN_POST_ADD_FN 560
  6159. #define SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN 561
  6160. #define SLAPI_PLUGIN_BE_TXN_POST_MODRDN_FN 562
  6161. #define SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN 563
  6162. /* matching rule plugin functions */
  6163. #define SLAPI_PLUGIN_MR_FILTER_CREATE_FN 600
  6164. #define SLAPI_PLUGIN_MR_INDEXER_CREATE_FN 601
  6165. #define SLAPI_PLUGIN_MR_FILTER_MATCH_FN 602
  6166. #define SLAPI_PLUGIN_MR_FILTER_INDEX_FN 603
  6167. #define SLAPI_PLUGIN_MR_FILTER_RESET_FN 604
  6168. #define SLAPI_PLUGIN_MR_INDEX_FN 605
  6169. #define SLAPI_PLUGIN_MR_INDEX_SV_FN 606
  6170. /* matching rule plugin arguments */
  6171. #define SLAPI_PLUGIN_MR_OID 610
  6172. #define SLAPI_PLUGIN_MR_TYPE 611
  6173. #define SLAPI_PLUGIN_MR_VALUE 612
  6174. #define SLAPI_PLUGIN_MR_VALUES 613
  6175. #define SLAPI_PLUGIN_MR_KEYS 614
  6176. #define SLAPI_PLUGIN_MR_FILTER_REUSABLE 615
  6177. #define SLAPI_PLUGIN_MR_QUERY_OPERATOR 616
  6178. #define SLAPI_PLUGIN_MR_USAGE 617
  6179. /* new style matching rule syntax plugin functions */
  6180. #define SLAPI_PLUGIN_MR_FILTER_AVA 618
  6181. #define SLAPI_PLUGIN_MR_FILTER_SUB 619
  6182. #define SLAPI_PLUGIN_MR_VALUES2KEYS 620
  6183. #define SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA 621
  6184. #define SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB 622
  6185. #define SLAPI_PLUGIN_MR_FLAGS 623
  6186. #define SLAPI_PLUGIN_MR_NAMES 624
  6187. #define SLAPI_PLUGIN_MR_COMPARE 625
  6188. #define SLAPI_PLUGIN_MR_NORMALIZE 626
  6189. /* Defined values of SLAPI_PLUGIN_MR_QUERY_OPERATOR: */
  6190. #define SLAPI_OP_LESS 1
  6191. #define SLAPI_OP_LESS_OR_EQUAL 2
  6192. #define SLAPI_OP_EQUAL 3
  6193. #define SLAPI_OP_GREATER_OR_EQUAL 4
  6194. #define SLAPI_OP_GREATER 5
  6195. #define SLAPI_OP_SUBSTRING 6
  6196. /* Defined values of SLAPI_PLUGIN_MR_USAGE: */
  6197. #define SLAPI_PLUGIN_MR_USAGE_INDEX 0
  6198. #define SLAPI_PLUGIN_MR_USAGE_SORT 1
  6199. /* Defined values for matchingRuleEntry accessor functions */
  6200. #define SLAPI_MATCHINGRULE_NAME 1
  6201. #define SLAPI_MATCHINGRULE_OID 2
  6202. #define SLAPI_MATCHINGRULE_DESC 3
  6203. #define SLAPI_MATCHINGRULE_SYNTAX 4
  6204. #define SLAPI_MATCHINGRULE_OBSOLETE 5
  6205. /* syntax plugin functions and arguments */
  6206. #define SLAPI_PLUGIN_SYNTAX_FILTER_AVA 700
  6207. #define SLAPI_PLUGIN_SYNTAX_FILTER_SUB 701
  6208. #define SLAPI_PLUGIN_SYNTAX_VALUES2KEYS 702
  6209. #define SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_AVA 703
  6210. #define SLAPI_PLUGIN_SYNTAX_ASSERTION2KEYS_SUB 704
  6211. #define SLAPI_PLUGIN_SYNTAX_NAMES 705
  6212. #define SLAPI_PLUGIN_SYNTAX_OID 706
  6213. #define SLAPI_PLUGIN_SYNTAX_FLAGS 707
  6214. #define SLAPI_PLUGIN_SYNTAX_COMPARE 708
  6215. /* user defined substrlen; not stored in slapdplugin, but pblock itself */
  6216. #define SLAPI_SYNTAX_SUBSTRLENS 709
  6217. #define SLAPI_MR_SUBSTRLENS SLAPI_SYNTAX_SUBSTRLENS /* alias */
  6218. #define SLAPI_PLUGIN_SYNTAX_VALIDATE 710
  6219. #define SLAPI_PLUGIN_SYNTAX_NORMALIZE 711
  6220. #define SLAPI_PLUGIN_SYNTAX_FILTER_NORMALIZED 712
  6221. #define SLAPI_PLUGIN_SYNTAX_FILTER_DATA 713
  6222. /* ACL plugin functions and arguments */
  6223. #define SLAPI_PLUGIN_ACL_INIT 730
  6224. #define SLAPI_PLUGIN_ACL_SYNTAX_CHECK 731
  6225. #define SLAPI_PLUGIN_ACL_ALLOW_ACCESS 732
  6226. #define SLAPI_PLUGIN_ACL_MODS_ALLOWED 733
  6227. #define SLAPI_PLUGIN_ACL_MODS_UPDATE 734
  6228. #define ACLPLUGIN_ACCESS_DEFAULT 0
  6229. #define ACLPLUGIN_ACCESS_READ_ON_ENTRY 1
  6230. #define ACLPLUGIN_ACCESS_READ_ON_ATTR 2
  6231. #define ACLPLUGIN_ACCESS_READ_ON_VLV 3
  6232. #define ACLPLUGIN_ACCESS_MODRDN 4
  6233. #define ACLPLUGIN_ACCESS_GET_EFFECTIVE_RIGHTS 5
  6234. /* Authorization types */
  6235. #define SLAPI_BE_MAXNESTLEVEL 742
  6236. #define SLAPI_CLIENT_DNS 745
  6237. /* Password storage scheme functions and arguments */
  6238. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_ENC_FN 800
  6239. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DEC_FN 801 /* only meaningfull for reversible encryption */
  6240. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_CMP_FN 802
  6241. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_NAME 810 /* name of the method: SHA, SSHA... */
  6242. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_USER_PWD 811 /* value sent over LDAP */
  6243. #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME_DB_PWD 812 /* value from the DB */
  6244. /* entry fetch and entry store values */
  6245. #define SLAPI_PLUGIN_ENTRY_FETCH_FUNC 813
  6246. #define SLAPI_PLUGIN_ENTRY_STORE_FUNC 814
  6247. #define SLAPI_PLUGIN_ENABLED 815
  6248. #define SLAPI_PLUGIN_CONFIG_AREA 816
  6249. /*
  6250. * Defined values of SLAPI_PLUGIN_SYNTAX_FLAGS:
  6251. */
  6252. #define SLAPI_PLUGIN_SYNTAX_FLAG_ORKEYS 1
  6253. #define SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING 2
  6254. /* controls we know about */
  6255. #define SLAPI_MANAGEDSAIT 1000
  6256. #define SLAPI_PWPOLICY 1001
  6257. /* arguments that are common to all operation */
  6258. #define SLAPI_TARGET_ADDRESS 48 /* target address (dn + uniqueid) should be normalized */
  6259. #define SLAPI_TARGET_UNIQUEID 49 /* target uniqueid of the operation */
  6260. #define SLAPI_TARGET_DN 50 /* DEPRECATED. target dn of the operation.
  6261. It actually points DN in SLAPI_TARGET_SDN. */
  6262. #define SLAPI_TARGET_SDN 47 /* target sdn of the operation */
  6263. #define SLAPI_REQCONTROLS 51 /* request controls */
  6264. /* Copies of entry before and after add, mod, mod[r]dn operations */
  6265. #define SLAPI_ENTRY_PRE_OP 52
  6266. #define SLAPI_ENTRY_POST_OP 53
  6267. /* a PRE_ENTRY_FN may alter the entry to be returned to the client -
  6268. SLAPI_SEARCH_ORIG_ENTRY holds the original entry from
  6269. the database - this must not be changed
  6270. SLAPI_SEARCH_ENTRY_COPY holds a copy of the original entry that
  6271. has been modified by the plugin - this will be NULL by default -
  6272. if a plugin needs to modify the entry, it should first check to
  6273. see if there is already a SLAPI_SEARCH_ENTRY_COPY - if not, the
  6274. plugin must use slapi_entry_dup() or similar to make a copy, edit
  6275. the copy, then store it in SLAPI_SEARCH_ENTRY_COPY - the internal
  6276. server code will free SLAPI_SEARCH_ENTRY_COPY
  6277. */
  6278. #define SLAPI_SEARCH_ENTRY_ORIG SLAPI_ENTRY_PRE_OP
  6279. #define SLAPI_SEARCH_ENTRY_COPY SLAPI_ENTRY_POST_OP
  6280. /* for plugin init functions, this is the plugin config entry */
  6281. #define SLAPI_PLUGIN_CONFIG_ENTRY SLAPI_ENTRY_PRE_OP
  6282. /* LDAPv3 controls to be sent with the operation result */
  6283. #define SLAPI_RESCONTROLS 55
  6284. #define SLAPI_ADD_RESCONTROL 56 /* add result control */
  6285. /* Extra notes to be logged within access log RESULT lines */
  6286. #define SLAPI_OPERATION_NOTES 57
  6287. #define SLAPI_OP_NOTE_UNINDEXED 0x01
  6288. #define SLAPI_OP_NOTE_SIMPLEPAGED 0x02
  6289. #define SLAPI_OP_NOTE_FULL_UNINDEXED 0x04
  6290. /* Allows controls to be passed before operation object is created */
  6291. #define SLAPI_CONTROLS_ARG 58
  6292. /* specify whether pblock content should be destroyed when the pblock is destroyed */
  6293. #define SLAPI_DESTROY_CONTENT 59
  6294. /* add arguments */
  6295. #define SLAPI_ADD_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6296. #define SLAPI_ADD_TARGET_SDN SLAPI_TARGET_SDN
  6297. #define SLAPI_ADD_ENTRY 60
  6298. #define SLAPI_ADD_EXISTING_DN_ENTRY 61
  6299. #define SLAPI_ADD_PARENT_ENTRY 62
  6300. #define SLAPI_ADD_PARENT_UNIQUEID 63
  6301. #define SLAPI_ADD_EXISTING_UNIQUEID_ENTRY 64
  6302. /* bind arguments */
  6303. #define SLAPI_BIND_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6304. #define SLAPI_BIND_TARGET_SDN SLAPI_TARGET_SDN
  6305. #define SLAPI_BIND_METHOD 70
  6306. #define SLAPI_BIND_CREDENTIALS 71 /* v3 only */
  6307. #define SLAPI_BIND_SASLMECHANISM 72 /* v3 only */
  6308. /* bind return values */
  6309. #define SLAPI_BIND_RET_SASLCREDS 73 /* v3 only */
  6310. /* compare arguments */
  6311. #define SLAPI_COMPARE_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6312. #define SLAPI_COMPARE_TARGET_SDN SLAPI_TARGET_SDN
  6313. #define SLAPI_COMPARE_TYPE 80
  6314. #define SLAPI_COMPARE_VALUE 81
  6315. /* delete arguments */
  6316. #define SLAPI_DELETE_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6317. #define SLAPI_DELETE_TARGET_SDN SLAPI_TARGET_SDN
  6318. #define SLAPI_DELETE_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
  6319. #define SLAPI_DELETE_GLUE_PARENT_ENTRY SLAPI_ADD_PARENT_ENTRY
  6320. #define SLAPI_DELETE_BEPREOP_ENTRY SLAPI_ENTRY_PRE_OP
  6321. #define SLAPI_DELETE_BEPOSTOP_ENTRY SLAPI_ENTRY_POST_OP
  6322. /* modify arguments */
  6323. #define SLAPI_MODIFY_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6324. #define SLAPI_MODIFY_TARGET_SDN SLAPI_TARGET_SDN
  6325. #define SLAPI_MODIFY_MODS 90
  6326. #define SLAPI_MODIFY_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
  6327. /* modrdn arguments */
  6328. #define SLAPI_MODRDN_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6329. #define SLAPI_MODRDN_TARGET_SDN SLAPI_TARGET_SDN
  6330. #define SLAPI_MODRDN_NEWRDN 100
  6331. #define SLAPI_MODRDN_DELOLDRDN 101
  6332. #define SLAPI_MODRDN_NEWSUPERIOR 102 /* v3 only */
  6333. #define SLAPI_MODRDN_NEWSUPERIOR_SDN 103 /* v3 only */
  6334. #define SLAPI_MODRDN_EXISTING_ENTRY SLAPI_ADD_EXISTING_DN_ENTRY
  6335. #define SLAPI_MODRDN_PARENT_ENTRY 104
  6336. #define SLAPI_MODRDN_NEWPARENT_ENTRY 105
  6337. #define SLAPI_MODRDN_TARGET_ENTRY 106
  6338. #define SLAPI_MODRDN_NEWSUPERIOR_ADDRESS 107
  6339. /*
  6340. * unnormalized dn argument (useful for MOD, MODRDN and DEL operations to carry
  6341. * the original non-escaped dn as introduced by the client application)
  6342. */
  6343. #define SLAPI_ORIGINAL_TARGET_DN 109
  6344. #define SLAPI_ORIGINAL_TARGET SLAPI_ORIGINAL_TARGET_DN
  6345. /* search arguments */
  6346. #define SLAPI_SEARCH_TARGET SLAPI_TARGET_DN /* DEPRECATED */
  6347. #define SLAPI_SEARCH_TARGET_SDN SLAPI_TARGET_SDN
  6348. #define SLAPI_SEARCH_SCOPE 110
  6349. #define SLAPI_SEARCH_DEREF 111
  6350. #define SLAPI_SEARCH_SIZELIMIT 112
  6351. #define SLAPI_SEARCH_TIMELIMIT 113
  6352. #define SLAPI_SEARCH_FILTER 114
  6353. #define SLAPI_SEARCH_STRFILTER 115
  6354. #define SLAPI_SEARCH_ATTRS 116
  6355. #define SLAPI_SEARCH_GERATTRS 1160
  6356. #define SLAPI_SEARCH_ATTRSONLY 117
  6357. #define SLAPI_SEARCH_IS_AND 118
  6358. /* abandon arguments */
  6359. #define SLAPI_ABANDON_MSGID 120
  6360. /* seq access arguments */
  6361. #define SLAPI_SEQ_TYPE 150
  6362. #define SLAPI_SEQ_ATTRNAME 151
  6363. #define SLAPI_SEQ_VAL 152
  6364. /* extended operation arguments */
  6365. #define SLAPI_EXT_OP_REQ_OID 160 /* v3 only */
  6366. #define SLAPI_EXT_OP_REQ_VALUE 161 /* v3 only */
  6367. /* extended operation return values */
  6368. #define SLAPI_EXT_OP_RET_OID 162 /* v3 only */
  6369. #define SLAPI_EXT_OP_RET_VALUE 163 /* v3 only */
  6370. /* extended filter arguments */
  6371. #define SLAPI_MR_FILTER_ENTRY 170 /* v3 only */
  6372. #define SLAPI_MR_FILTER_TYPE 171 /* v3 only */
  6373. #define SLAPI_MR_FILTER_VALUE 172 /* v3 only */
  6374. #define SLAPI_MR_FILTER_OID 173 /* v3 only */
  6375. #define SLAPI_MR_FILTER_DNATTRS 174 /* v3 only */
  6376. /* ldif2db arguments */
  6377. /* ldif file to convert to db */
  6378. #define SLAPI_LDIF2DB_FILE 180
  6379. /* check for duplicate values or not */
  6380. #define SLAPI_LDIF2DB_REMOVEDUPVALS 185
  6381. /* index only this attribute from existing database */
  6382. #define SLAPI_DB2INDEX_ATTRS 186
  6383. /* do not generate attribute indexes */
  6384. #define SLAPI_LDIF2DB_NOATTRINDEXES 187
  6385. /* list if DNs to include */
  6386. #define SLAPI_LDIF2DB_INCLUDE 188
  6387. /* list of DNs to exclude */
  6388. #define SLAPI_LDIF2DB_EXCLUDE 189
  6389. /* generate uniqueid */
  6390. #define SLAPI_LDIF2DB_GENERATE_UNIQUEID 175
  6391. #define SLAPI_LDIF2DB_NAMESPACEID 177
  6392. #define SLAPI_LDIF2DB_ENCRYPT 303
  6393. #define SLAPI_DB2LDIF_DECRYPT 304
  6394. /* uniqueid generation options */
  6395. #define SLAPI_UNIQUEID_GENERATE_NONE 0 /* do not generate */
  6396. #define SLAPI_UNIQUEID_GENERATE_TIME_BASED 1 /* generate time based id */
  6397. #define SLAPI_UNIQUEID_GENERATE_NAME_BASED 2 /* generate name based id */
  6398. /* db2ldif arguments */
  6399. /* print keys or not in ldif */
  6400. #define SLAPI_DB2LDIF_PRINTKEY 183
  6401. /* filename to export */
  6402. #define SLAPI_DB2LDIF_FILE 184
  6403. /* dump uniqueid */
  6404. #define SLAPI_DB2LDIF_DUMP_UNIQUEID 176
  6405. #define SLAPI_DB2LDIF_SERVER_RUNNING 197
  6406. /* db2ldif/ldif2db/bak2db/db2bak arguments */
  6407. #define SLAPI_BACKEND_INSTANCE_NAME 178
  6408. #define SLAPI_BACKEND_TASK 179
  6409. #define SLAPI_TASK_FLAGS 181
  6410. /* bulk import (online wire import) */
  6411. #define SLAPI_BULK_IMPORT_ENTRY 182
  6412. #define SLAPI_BULK_IMPORT_STATE 192
  6413. /* the actual states (these are not pblock args) */
  6414. #define SLAPI_BI_STATE_START 1
  6415. #define SLAPI_BI_STATE_DONE 2
  6416. #define SLAPI_BI_STATE_ADD 3
  6417. /* possible error codes from a bulk import */
  6418. #define SLAPI_BI_ERR_BUSY -23 /* backend is busy; try later */
  6419. /* transaction arguments */
  6420. #define SLAPI_PARENT_TXN 190
  6421. #define SLAPI_TXN 191
  6422. #define SLAPI_TXN_RUV_MODS_FN 1901
  6423. #define SLAPI_BACK_TRANSACTION_NOT_SUPPORTED 1902
  6424. /*
  6425. * The following are used to pass information back and forth
  6426. * between the front end and the back end. The backend
  6427. * creates a search result set as an opaque structure and
  6428. * passes a reference to this back to the front end. The
  6429. * front end uses the backend's iterator entry point to
  6430. * step through the results. The entry, nentries, and
  6431. * referrals options, below, are set/read by both the
  6432. * front end and back end while stepping through the
  6433. * search results.
  6434. */
  6435. /* Search result set */
  6436. #define SLAPI_SEARCH_RESULT_SET 193
  6437. /* Estimated search result set size (for paged results) */
  6438. #define SLAPI_SEARCH_RESULT_SET_SIZE_ESTIMATE 1930
  6439. /* Search result - next entry returned from search result set */
  6440. #define SLAPI_SEARCH_RESULT_ENTRY 194
  6441. #define SLAPI_SEARCH_RESULT_ENTRY_EXT 1944
  6442. /* Number of entries returned from search */
  6443. #define SLAPI_NENTRIES 195
  6444. /* Any referrals encountered during the search */
  6445. #define SLAPI_SEARCH_REFERRALS 196
  6446. /* for search operations, allows plugins to provide
  6447. controls to pass for each entry or referral returned
  6448. corresponds to pb_search_ctrls */
  6449. #define SLAPI_SEARCH_CTRLS 198
  6450. #define SLAPI_RESULT_CODE 881
  6451. #define SLAPI_RESULT_TEXT 882
  6452. #define SLAPI_RESULT_MATCHED 883
  6453. #define SLAPI_PB_RESULT_TEXT 885
  6454. /* Size of the database, in kilobytes */
  6455. #define SLAPI_DBSIZE 199
  6456. /* Simple paged results index */
  6457. #define SLAPI_PAGED_RESULTS_INDEX 1945
  6458. /* ACI Target Check */
  6459. #define SLAPI_ACI_TARGET_CHECK 1946
  6460. /* convenience macros for checking modify operation types */
  6461. #define SLAPI_IS_MOD_ADD(x) (((x) & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD)
  6462. #define SLAPI_IS_MOD_DELETE(x) (((x) & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE)
  6463. #define SLAPI_IS_MOD_REPLACE(x) (((x) & ~LDAP_MOD_BVALUES) == LDAP_MOD_REPLACE)
  6464. /* regex.c */
  6465. typedef struct slapi_regex_handle Slapi_Regex;
  6466. /**
  6467. * Compiles a regular expression pattern. A thin wrapper of pcre_compile.
  6468. *
  6469. * \param pat Pattern to be compiled.
  6470. * \param error The error string is set if the compile fails.
  6471. * \return This function returns a pointer to the regex handler which stores
  6472. * the compiled pattern. NULL if the compile fails.
  6473. * \warning The regex handler should be released by slapi_re_free().
  6474. */
  6475. Slapi_Regex *slapi_re_comp( const char *pat, const char **error );
  6476. /**
  6477. * Matches a compiled regular expression pattern against a given string.
  6478. * A thin wrapper of pcre_exec.
  6479. *
  6480. * \param re_handle The regex handler returned from slapi_re_comp.
  6481. * \param subject A string to be checked against the compiled pattern.
  6482. * \param time_up If the current time is larger than the value, this function
  6483. * returns immediately. (-1) means no time limit.
  6484. * \return This function returns 0 if the string did not match.
  6485. * \return This function returns 1 if the string matched.
  6486. * \return This function returns other values if any error occurred.
  6487. * \warning The regex handler should be released by slapi_re_free().
  6488. */
  6489. int slapi_re_exec( Slapi_Regex *re_handle, const char *subject, time_t time_up );
  6490. /**
  6491. * Substitutes '&' or '\#' in the param src with the matched string.
  6492. *
  6493. * \param re_handle The regex handler returned from slapi_re_comp.
  6494. * \param subject A string checked against the compiled pattern.
  6495. * \param src A given string which could contain the substitution symbols.
  6496. * \param dst A pointer pointing to the memory which stores the output string.
  6497. * \param dstlen Size of the memory dst.
  6498. * \return This function returns 1 if the substitution was successful.
  6499. * \return This function returns 0 if the substitution failed.
  6500. * \warning The regex handler should be released by slapi_re_free().
  6501. */
  6502. int slapi_re_subs( Slapi_Regex *re_handle, const char *subject, const char *src, char **dst, unsigned long dstlen );
  6503. /**
  6504. * Substitutes '&' or '\#' in the param src with the matched string. If the 'src' is a search filter
  6505. * do not remove & if it is part of a compound filter.
  6506. *
  6507. * \param re_handle The regex handler returned from slapi_re_comp.
  6508. * \param subject A string checked against the compiled pattern.
  6509. * \param src A given string which could contain the substitution symbols.
  6510. * \param dst A pointer pointing to the memory which stores the output string.
  6511. * \param dstlen Size of the memory dst.
  6512. * \param filter Set to 1 if the src is a ldap search filter
  6513. * \return This function returns 1 if the substitution was successful.
  6514. * \return This function returns 0 if the substitution failed.
  6515. * \warning The regex handler should be released by slapi_re_free().
  6516. */
  6517. int slapi_re_subs_ext( Slapi_Regex *re_handle, const char *subject, const char *src, char **dst, unsigned long dstlen, int filter );
  6518. /**
  6519. * Releases the regex handler which was returned from slapi_re_comp.
  6520. *
  6521. * \param re_handle The regex handler to be released.
  6522. * \return nothing
  6523. */
  6524. void slapi_re_free(Slapi_Regex *re_handle);
  6525. /* wrap non-portable LDAP API functions */
  6526. void slapi_ldap_value_free(char **vals);
  6527. int slapi_ldap_count_values(char **vals);
  6528. int slapi_ldap_url_parse(const char *url, LDAPURLDesc **ludpp, int require_dn, int *secure);
  6529. const char *slapi_urlparse_err2string(int err);
  6530. int slapi_ldap_get_lderrno(LDAP *ld, char **m, char **s);
  6531. #ifndef LDIF_OPT_NOWRAP
  6532. #define LDIF_OPT_NOWRAP 0x01UL
  6533. #endif
  6534. #ifndef LDIF_OPT_VALUE_IS_URL
  6535. #define LDIF_OPT_VALUE_IS_URL 0x02UL
  6536. #endif
  6537. #ifndef LDIF_OPT_MINIMAL_ENCODING
  6538. #define LDIF_OPT_MINIMAL_ENCODING 0x04UL
  6539. #endif
  6540. void slapi_ldif_put_type_and_value_with_options( char **out, const char *t, const char *val, int vlen, unsigned long options );
  6541. /* ldif_read_record lineno argument type depends on openldap version */
  6542. #if defined(USE_OPENLDAP)
  6543. #if LDAP_VENDOR_VERSION >= 20434 /* changed in 2.4.34 */
  6544. typedef unsigned long int ldif_record_lineno_t;
  6545. #else
  6546. typedef int ldif_record_lineno_t;
  6547. #endif
  6548. #endif
  6549. #if defined(USE_OPENLDAP)
  6550. /*
  6551. * UTF-8 routines (should these move into libnls?)
  6552. */
  6553. /* number of bytes in character */
  6554. int ldap_utf8len( const char* );
  6555. /* find next character */
  6556. char *ldap_utf8next( char* );
  6557. /* find previous character */
  6558. char *ldap_utf8prev( char* );
  6559. /* copy one character */
  6560. int ldap_utf8copy( char* dst, const char* src );
  6561. /* total number of characters */
  6562. size_t ldap_utf8characters( const char* );
  6563. /* get one UCS-4 character, and move *src to the next character */
  6564. unsigned long ldap_utf8getcc( const char** src );
  6565. /* UTF-8 aware strtok_r() */
  6566. char *ldap_utf8strtok_r( char* src, const char* brk, char** next);
  6567. /* like isalnum(*s) in the C locale */
  6568. int ldap_utf8isalnum( char* s );
  6569. /* like isalpha(*s) in the C locale */
  6570. int ldap_utf8isalpha( char* s );
  6571. /* like isdigit(*s) in the C locale */
  6572. int ldap_utf8isdigit( char* s );
  6573. /* like isxdigit(*s) in the C locale */
  6574. int ldap_utf8isxdigit(char* s );
  6575. /* like isspace(*s) in the C locale */
  6576. int ldap_utf8isspace( char* s );
  6577. #define LDAP_UTF8LEN(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8len (s) : 1)
  6578. #define LDAP_UTF8NEXT(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8next(s) : ( s)+1)
  6579. #define LDAP_UTF8INC(s) ((0x80 & *(unsigned char*)(s)) ? s=ldap_utf8next(s) : ++s)
  6580. #define LDAP_UTF8PREV(s) ldap_utf8prev(s)
  6581. #define LDAP_UTF8DEC(s) (s=ldap_utf8prev(s))
  6582. #define LDAP_UTF8COPY(d,s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8copy(d,s) : ((*(d) = *(s)), 1))
  6583. #define LDAP_UTF8GETCC(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8getcc (&s) : *s++)
  6584. #define LDAP_UTF8GETC(s) ((0x80 & *(unsigned char*)(s)) ? ldap_utf8getcc ((const char**)&s) : *s++)
  6585. #endif /* USE_OPENLDAP */
  6586. /* by default will allow dups */
  6587. char **slapi_str2charray( char *str, char *brkstr );
  6588. /*
  6589. * extended version of str2charray lets you disallow
  6590. * duplicate values into the array.
  6591. */
  6592. char **slapi_str2charray_ext( char *str, char *brkstr, int allow_dups );
  6593. #ifndef LDAP_PORT_MAX
  6594. #define LDAP_PORT_MAX 65535 /* API extension */
  6595. #endif
  6596. #ifndef LDAP_ALL_USER_ATTRS
  6597. #ifdef LDAP_ALL_USER_ATTRIBUTES
  6598. #define LDAP_ALL_USER_ATTRS LDAP_ALL_USER_ATTRIBUTES
  6599. #else
  6600. #define LDAP_ALL_USER_ATTRS "*"
  6601. #endif
  6602. #endif
  6603. #ifndef LDAP_SASL_EXTERNAL
  6604. #define LDAP_SASL_EXTERNAL "EXTERNAL" /* TLS/SSL extension */
  6605. #endif
  6606. #ifndef LBER_SOCKET
  6607. #ifdef LBER_SOCKET_T
  6608. #define LBER_SOCKET LBER_SOCKET_T
  6609. #else
  6610. #define LBER_SOCKET int
  6611. #endif
  6612. #endif
  6613. /* Used to make unhashed passwords available to plugins. */
  6614. #define PSEUDO_ATTR_UNHASHEDUSERPASSWORD "unhashed#user#password"
  6615. /* Unhashed password */
  6616. #define SLAPD_UNHASHED_PW_OFF 0
  6617. #define SLAPD_UNHASHED_PW_ON 1
  6618. #define SLAPD_UNHASHED_PW_NOLOG 2
  6619. /**
  6620. * Set given "type: value" to the plugin default config entry
  6621. * (cn=plugin default config,cn=config) unless the same "type: value" pair
  6622. * already exists in the entry.
  6623. *
  6624. * \param type Attribute type to add to the default config entry
  6625. * \param value Attribute value to add to the default config entry
  6626. * \return \c 0 if the operation was successful
  6627. * \return non-0 if the operation was not successful
  6628. */
  6629. int slapi_set_plugin_default_config(const char *type, Slapi_Value *value);
  6630. /**
  6631. * Get attribute values of given type from the plugin default config entry
  6632. * (cn=plugin default config,cn=config).
  6633. *
  6634. * \param type Attribute type to get from the default config entry
  6635. * \param valueset Valueset holding the attribute values
  6636. * \return \c 0 if the operation was successful
  6637. * \return non-0 if the operation was not successful
  6638. * \warning Caller is responsible to free attrs by slapi_ch_array_free
  6639. */
  6640. int slapi_get_plugin_default_config(char *type, Slapi_ValueSet **valueset);
  6641. int slapi_check_account_lock( Slapi_PBlock *pb, Slapi_Entry *bind_target_entry, int pwresponse_req, int check_password_policy, int send_result);
  6642. /* backend get/set info */
  6643. /**
  6644. * Get backend info based upon cmd
  6645. *
  6646. * \param be Backend from which the infomation will be retrieved
  6647. * \param cmd macro to specify the information type
  6648. * \param info pointer to store the information
  6649. * \return \c 0 if the operation was successful
  6650. * \return non-0 if the operation was not successful
  6651. *
  6652. * \note Implemented cmd:
  6653. * BACK_INFO_DBENV - Get the dbenv
  6654. * BACK_INFO_DBENV_OPENFLAGS - Get the dbenv openflags
  6655. * BACK_INFO_INDEXPAGESIZE - Get the index page size
  6656. */
  6657. int slapi_back_get_info(Slapi_Backend *be, int cmd, void **info);
  6658. /**
  6659. * Set info to backend based upon cmd
  6660. *
  6661. * \param be Backend to which the infomation will be set
  6662. * \param cmd macro to specify the information type
  6663. * \param info pointer to the information
  6664. * \return \c 0 if the operation was successful
  6665. * \return non-0 if the operation was not successful
  6666. * \warning No cmd is defined yet.
  6667. */
  6668. int slapi_back_set_info(Slapi_Backend *be, int cmd, void *info);
  6669. /**
  6670. * Execute cmd in backend
  6671. *
  6672. * \param be Backend where the command is executed
  6673. * \param cmd macro to specify the execution type
  6674. * \param info pointer to the information
  6675. * \return \c 0 if the operation was successful
  6676. * \return non-0 if the operation was not successful
  6677. *
  6678. * \note Implemented cmd:
  6679. * BACK_INFO_CRYPT_INIT - Initialize cipher (info: back_info_crypt_init)
  6680. * BACK_INFO_CRYPT_ENCRYPT_VALUE - Encrypt the given value (info: back_info_crypt_value)
  6681. * BACK_INFO_CRYPT_DECRYPT_VALUE - Decrypt the given value (info: back_info_crypt_value)
  6682. */
  6683. int slapi_back_ctrl_info(Slapi_Backend *be, int cmd, void *info);
  6684. /* cmd */
  6685. enum
  6686. {
  6687. BACK_INFO_DBENV, /* Get the dbenv */
  6688. BACK_INFO_INDEXPAGESIZE, /* Get the index page size */
  6689. BACK_INFO_DBENV_OPENFLAGS, /* Get the dbenv openflags */
  6690. BACK_INFO_CRYPT_INIT, /* Ctrl: clcrypt_init */
  6691. BACK_INFO_CRYPT_ENCRYPT_VALUE, /* Ctrl: clcrypt_encrypt_value */
  6692. BACK_INFO_CRYPT_DECRYPT_VALUE, /* Ctrl: clcrypt_decrypt_value */
  6693. BACK_INFO_DIRECTORY, /* Get the directory path */
  6694. BACK_INFO_LOG_DIRECTORY /* Get the txn log directory */
  6695. };
  6696. struct _back_info_crypt_init {
  6697. char *dn; /* input -- entry to store nsSymmetricKey */
  6698. char *encryptionAlgorithm; /* input -- encryption althorithm */
  6699. Slapi_Backend *be; /* input -- backend to use */
  6700. void *state_priv; /* outout */
  6701. };
  6702. typedef struct _back_info_crypt_init back_info_crypt_init;
  6703. struct _back_info_crypt_value {
  6704. void *state_priv; /* input */
  6705. struct berval *in; /* input */
  6706. struct berval *out; /* output */
  6707. };
  6708. typedef struct _back_info_crypt_value back_info_crypt_value;
  6709. #define BACK_CRYPT_OUTBUFF_EXTLEN 16
  6710. /**
  6711. * Convert unsigned char (8 bit) value to a hex string. Writes to the string.
  6712. * The caller must ensure enough space to write 2 bytes. If the upper parameter
  6713. * is TRUE, will use upper case A-F instead of lower case a-f for hex numbers.
  6714. * Returns the address after the last byte written to encourage usage like this:
  6715. * \code
  6716. * char *ptr = slapi_u_to_hex(val, buf, 0);
  6717. * ptr = slapi_u_to_hex(val2, ptr, 0);
  6718. * ...
  6719. * ptr = slapi_u_to_hex(valN, ptr, 0);
  6720. * *ptr = 0;
  6721. * \endcode
  6722. *
  6723. * \param val unsigned value to convert to string
  6724. * \param s string to write hex value into
  6725. * \param upper if TRUE use A-F otherwise use a-f
  6726. * \return address of next char after writing value to s
  6727. *
  6728. * \note Does not null terminate s - caller is responsible for that
  6729. */
  6730. char *slapi_u8_to_hex(uint8_t val, char *s, uint8_t upper);
  6731. /**
  6732. * Convert unsigned short (16 bit) value to a hex string. Writes to the string.
  6733. * The caller must ensure enough space to write 4 bytes. If the upper parameter
  6734. * is TRUE, will use upper case A-F instead of lower case a-f for hex numbers.
  6735. * Returns the address after the last byte written to encourage usage like this:
  6736. * \code
  6737. * char *ptr = slapi_u_to_hex(val, buf, 0);
  6738. * ptr = slapi_u_to_hex(val2, ptr, 0);
  6739. * ...
  6740. * ptr = slapi_u_to_hex(valN, ptr, 0);
  6741. * *ptr = 0;
  6742. * \endcode
  6743. *
  6744. * \param val unsigned value to convert to string
  6745. * \param s string to write hex value into
  6746. * \param upper if TRUE use A-F otherwise use a-f
  6747. * \return address of next char after writing value to s
  6748. *
  6749. * \note Does not null terminate s - caller is responsible for that
  6750. */
  6751. char *slapi_u16_to_hex(uint16_t val, char *s, uint8_t upper);
  6752. /**
  6753. * Convert unsigned int (32 bit) value to a hex string. Writes to the string.
  6754. * The caller must ensure enough space to write 4 bytes. If the upper parameter
  6755. * is TRUE, will use upper case A-F instead of lower case a-f for hex numbers.
  6756. * Returns the address after the last byte written to encourage usage like this:
  6757. * \code
  6758. * char *ptr = slapi_u_to_hex(val, buf, 0);
  6759. * ptr = slapi_u_to_hex(val2, ptr, 0);
  6760. * ...
  6761. * ptr = slapi_u_to_hex(valN, ptr, 0);
  6762. * *ptr = 0;
  6763. * \endcode
  6764. *
  6765. * \param val unsigned value to convert to string
  6766. * \param s string to write hex value into
  6767. * \param upper if TRUE use A-F otherwise use a-f
  6768. * \return address of next char after writing value to s
  6769. *
  6770. * \note Does not null terminate s - caller is responsible for that
  6771. */
  6772. char *slapi_u32_to_hex(uint32_t val, char *s, uint8_t upper);
  6773. /**
  6774. * Convert unsigned long long (64 bit) value to a hex string. Writes to the string.
  6775. * The caller must ensure enough space to write 4 bytes. If the upper parameter
  6776. * is TRUE, will use upper case A-F instead of lower case a-f for hex numbers.
  6777. * Returns the address after the last byte written to encourage usage like this:
  6778. * \code
  6779. * char *ptr = slapi_u_to_hex(val, buf, 0);
  6780. * ptr = slapi_u_to_hex(val2, ptr, 0);
  6781. * ...
  6782. * ptr = slapi_u_to_hex(valN, ptr, 0);
  6783. * *ptr = 0;
  6784. * \endcode
  6785. *
  6786. * \param val unsigned value to convert to string
  6787. * \param s string to write hex value into
  6788. * \param upper if TRUE use A-F otherwise use a-f
  6789. * \return address of next char after writing value to s
  6790. *
  6791. * \note Does not null terminate s - caller is responsible for that
  6792. */
  6793. char *slapi_u64_to_hex(uint64_t val, char *s, uint8_t upper);
  6794. /**
  6795. * Convert a char to its integral hex value e.g. '0' -> 0 or 'a' -> 10.
  6796. * This only works on one caller at a time. If you want to convert a string
  6797. * of decimal/hex numbers to its integral value, see slapi_str_to_u8 et. al.
  6798. * This uses a lookup table so it should be extremely fast.
  6799. *
  6800. * \param c character value to convert
  6801. * \return integral value of the given char or -1 if not a valid decimal/hex digit
  6802. */
  6803. int slapi_hexchar2int(char c);
  6804. /**
  6805. * Convert a string of 2 decimal/hex characters to a 1 byte (8-bit) unsigned value.
  6806. * This function does no checking - it assumes s is non-NULL and well-formed.
  6807. *
  6808. * \param s convert the first 2 chars of this decimal/hex char string to its integral value
  6809. * \return the integral value
  6810. */
  6811. uint8_t slapi_str_to_u8(const char *s);
  6812. /**
  6813. * Convert a string of 4 decimal/hex characters to a 2 byte (16-bit) unsigned value.
  6814. * This function does no checking - it assumes s is non-NULL and well-formed.
  6815. *
  6816. * \param s convert the first 4 chars of this decimal/hex char string to its integral value
  6817. * \return the integral value
  6818. */
  6819. uint16_t slapi_str_to_u16(const char *s);
  6820. /**
  6821. * Convert a string of 8 decimal/hex characters to a 4 byte (32-bit) unsigned value.
  6822. * This function does no checking - it assumes s is non-NULL and well-formed.
  6823. *
  6824. * \param s convert the first 8 chars of this decimal/hex char string to its integral value
  6825. * \return the integral value
  6826. */
  6827. uint32_t slapi_str_to_u32(const char *s);
  6828. /**
  6829. * Convert a string of 16 decimal/hex characters to a 8 byte (64-bit) unsigned value.
  6830. * This function does no checking - it assumes s is non-NULL and well-formed.
  6831. *
  6832. * \param s convert the first 16 chars of this decimal/hex char string to its integral value
  6833. * \return the integral value
  6834. */
  6835. uint64_t slapi_str_to_u64(const char *s);
  6836. void slapi_set_plugin_open_rootdn_bind(Slapi_PBlock *pb);
  6837. PRBool slapi_disordely_shutdown(PRBool set);
  6838. /*
  6839. * Public entry extension getter/setter functions
  6840. *
  6841. * Currently, only slapi_pw_get/set_entry_ext is implemented.
  6842. * The functions are in pw.c. Detailed usage of the factory
  6843. * is found in the comments at the top of factory.c.
  6844. *
  6845. * When you plan to add other entry extension code AND
  6846. * the type-value pair is managed via ordinary mod,
  6847. * setter, getter and copy function having the same API
  6848. * are supposed to be implemented, then add the set to
  6849. * attrs_in_extension list in entry.c. The set is called
  6850. * in slapi_entry_apply_mod_extension.
  6851. *
  6852. * Note: setter and getter are public, but copy function
  6853. * is not. (for the copy function, see pw_copy_entry_ext in pw.c)
  6854. */
  6855. /* operation used in the entry extension setter */
  6856. #define SLAPI_EXT_SET_ADD 0
  6857. #define SLAPI_EXT_SET_REPLACE 1
  6858. /**
  6859. * Get entry extension
  6860. *
  6861. * \param entry is the entry to retrieve the extension from
  6862. * \param vals is the array of (Slapi_Value *), which directly refers the extension. Caller must duplicate it to use it for other than referring.
  6863. *
  6864. * \return LDAP_SUCCESS if successful.
  6865. * \return non-zero otherwise.
  6866. */
  6867. int slapi_pw_get_entry_ext(Slapi_Entry *entry, Slapi_Value ***vals);
  6868. /**
  6869. * Set entry extension
  6870. *
  6871. * \param entry is the entry to set the extension to
  6872. * \param vals is the array of (Slapi_Value *), which is consumed in slapi_pw_set_ext if the call is successful.
  6873. * \param flags: SLAPI_EXT_SET_ADD -- add vals to the existing extension if any.
  6874. * SLAPI_EXT_SET_REPLACE -- replace vals with the existing extension if any.
  6875. * No difference if there is no extension in the entry.
  6876. *
  6877. * \return LDAP_SUCCESS if successful.
  6878. * \return non-zero otherwise.
  6879. */
  6880. int slapi_pw_set_entry_ext(Slapi_Entry *entry, Slapi_Value **vals, int flags);
  6881. /**
  6882. * Get stashed clear password.
  6883. * If multiple of them are in the extension, the first one is returned.
  6884. *
  6885. * \param entry is the entry to retrieve the extension from
  6886. *
  6887. * \return a pointer to the clear password string. Caller is responsible to free the string.
  6888. */
  6889. char *slapi_get_first_clear_text_pw(Slapi_Entry *entry);
  6890. /**
  6891. * Return the string equivalent of an NSPR error
  6892. * *
  6893. * \param a NSPR error code
  6894. *
  6895. * \return a pointer to the error code string.
  6896. */
  6897. char *slapi_pr_strerror( const PRErrorCode prerrno );
  6898. /**
  6899. * Return the string equivalent of an OS error
  6900. *
  6901. * \param a OS error code
  6902. *
  6903. * \return a pointer to the system error code string.
  6904. */
  6905. const char *slapi_system_strerror( const int syserrno );
  6906. /* event queue routines and data types */
  6907. /**
  6908. * Represents a scheduled event object.
  6909. */
  6910. typedef void* Slapi_Eq_Context;
  6911. /**
  6912. * Represents the function that will be performed when an event is triggered.
  6913. */
  6914. typedef void (*slapi_eq_fn_t)(time_t when, void *arg);
  6915. /**
  6916. * Cause an event to happen exactly once.
  6917. *
  6918. * \param fn The function to call when the event is triggered.
  6919. * \param arg An argument to pass to the called function.
  6920. * \param when The time that the function should be called.
  6921. *
  6922. * \return slapi_eq_context
  6923. */
  6924. Slapi_Eq_Context slapi_eq_once(slapi_eq_fn_t fn, void *arg, time_t when);
  6925. /**
  6926. * Cause an event to happen repeatedly.
  6927. *
  6928. * \param fn The function to call when the vent is triggered.
  6929. * \param arg An argument to pass to the called function.
  6930. * \param when The time that the function should be called.
  6931. * \param interval The amount of time (in milliseconds) between
  6932. * successive calls to the function.
  6933. *
  6934. * \return slapi_eq_context
  6935. */
  6936. Slapi_Eq_Context slapi_eq_repeat(slapi_eq_fn_t fn, void *arg, time_t when, unsigned long interval);
  6937. /**
  6938. * Cause a scheduled event to be canceled.
  6939. *
  6940. * \param ctx The event object to cancel
  6941. *
  6942. * \return 1 If event was found and canceled.
  6943. * \return 0 If event was not found in the queue.
  6944. */
  6945. int slapi_eq_cancel(Slapi_Eq_Context ctx);
  6946. /**
  6947. * Return the event's argument.
  6948. *
  6949. * \param ctx The event object
  6950. *
  6951. * \return A pointer to the event argument.
  6952. */
  6953. void *slapi_eq_get_arg (Slapi_Eq_Context ctx);
  6954. /**
  6955. * Construct a full path and name of a plugin.
  6956. *
  6957. * \param dir The Directory where the plugin is located.
  6958. * \param name The name of the plugin.
  6959. *
  6960. * \return absolute path of the plugin. Caller is responsible to free it.
  6961. */
  6962. char *slapi_get_plugin_name(const char *dir, const char *name);
  6963. #ifdef __cplusplus
  6964. }
  6965. #endif
  6966. #endif /* _SLAPIPLUGIN */