slapi-plugin.h 258 KB

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