⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slapover.txt

📁 ldap服务器源码
💻 TXT
字号:
slapd internal APIsIntroductionFrontend, backend, database, callback, overlay - what does it all mean?The "frontend" refers to all the code that deals with the actual interactionwith an LDAP client. This includes the code to read requests from the networkand parse them into C data structures, all of the session management, and theformatting of responses for transmission onto the network. It also includes theaccess control engine and other features that are generic to LDAP processing,features which are not dependent on a particular database implementation.Because the frontend serves as the framework that ties everything together,it should not change much over time.The terms "backend" and "database" have historically been used interchangeablyand/or in combination as if they are the same thing, but the code has a cleardistinction between the two. A "backend" is a type of module, and a "database"is an instance of a backend type. Together they work with the frontend tomanage the actual data that are operated on by LDAP requests. Originally thebackend interface was relatively compact, with individual functionscorresponding to each LDAP operation type, plus functions for init, config, andshutdown. The number of entry points has grown to allow greater flexibility,but the concept is much the same as before.The language here can get a bit confusing. A backend in slapd is embodied in aBackendInfo data structure, and a database is held in a BackendDB structure.Originally it was all just a single Backend data structure, but things havegrown and the concept was split into these two parts. The idea behind thedistinct BackendInfo is to allow for any initialization and configuration thatmay be needed by every instance of a type of database, as opposed to items thatare specific to just one instance. For example, you might have a databaselibrary that requires an initialization routine to be called exactly once atprogram startup. Then there may be a "open" function that must be called oncefor each database instance. The BackendInfo.bi_open function provides theone-time startup, while the BackendInfo.bi_db_open function provides theper-database startup. The main feature of the BackendInfo structure is itstable of entry points for all of the database functions that it implements.There's also a bi_private pointer that can be used to carry any configurationstate needed by the backend. (Note that this is state that applies to thebackend type, and thus to all database instances of the backend as well.) TheBackendDB structure carries all of the per-instance state for a backenddatabase. This includes the database suffix, ACLs, flags, various DNs, etc. Italso has a pointer to its BackendInfo, and a be_private pointer for use by theparticular backend instance. In practice, the per-type features are seldomused, and all of the work is done in the per-instance data structures.Ordinarily an LDAP request is received by the slapd frontend, parsed into arequest structure, and then passed to the backend for processing. The backendmay call various utility functions in the frontend to assist in processing, andthen it eventually calls some send_ldap_result function in the frontend to sendresults back to the client. The processing flow is pretty rigidly defined; eventhough slapd is capable of dynamically loading new code modules, it wasdifficult to add extensions that changed the basic protocol operations. If youwanted to extend the server with special behaviors you would need to modify thefrontend or the backend or both, and generally you would need to write anentire new backend to get some set of special features working. With OpenLDAP2.1 we added the notion of a callback, which can intercept the results sentfrom a backend before they are sent to a client. Using callbacks makes itpossible to modify the results if desired, or to simply discard the resultsinstead of sending them to any client. This callback feature is usedextensively in the SASL support to perform internal searches of slapd databaseswhen mapping authentication IDs into regular DNs. The callback mechanism isalso the basis of backglue, which allows separate databases to be searched asif they were a single naming context.Very often, one needs to add just a tiny feature onto an otherwise "normal"database. The usual way to achieve this was to use a programmable backend (likeback-perl) to preprocess various requests and then forward them back into slapdto be handled by the real database. While this technique works, it is fairlyinefficient because it involves many transitions from network to slapd and backagain. The overlay concept introduced in OpenLDAP 2.2 allows code to beinserted between the slapd frontend and any backend, so that incoming requestscan be intercepted before reaching the backend database. (There is also a SLAPIplugin framework in OpenLDAP 2.2; it offers a lot of flexibility as well but isnot discussed here.) The overlay framework also uses the callback mechanism, sooutgoing results can also be intercepted by external code. All of this couldget unwieldy if a lot of overlays were being used, but there was also anothersignificant API change in OpenLDAP 2.2 to streamline internal processing. (Seethe document "Refactoring the slapd ABI"...)OK, enough generalities... You should probably have a copy of slap.h in frontof you to continue here.What is an overlay? The structure defining it includes a BackendInfo structureplus a few additional fields. It gets inserted into the usual frontend->backendcall chain by replacing the BackendDB's BackendInfo pointer with its own. Theframework to accomplish this is in backover.c. For a given backend, theBackendInfo will point to a slap_overinfo structure. The slap_overinfo has aBackendInfo that points to all of the overlay framework's entry points. It alsoholds a copy of the original BackendInfo pointer, and  a linked list ofslap_overinst structures. There is one slap_overinst per configured overlay,and the set of overlays configured on a backend are treated like a stack; i.e.,the last one configured is at the top of the stack, and it executes first.Continuing with the stack notion - a request enters the frontend, is directedto a backend by select_backend, and then intercepted by the top of the overlaystack. This first overlay may do something with the request, and then returnSLAP_CB_CONTINUE, which will then cause processing to fall into the nextoverlay, and so on down the stack until finally the request is handed to theactual backend database. Likewise, when the database finishes processing andsends a result, the overlay callback intercepts this and the topmost overlaygets to process the result. If it returns SLAP_CB_CONTINUE then processing willcontinue in the next overlay, and then any other callbacks, then finally theresult reaches the frontend for sending back to the client. At any step alongthe way, a module may choose to fully process the request or result and notallow it to propagate any further down the stack. Whenever a module returnsanything other than SLAP_CB_CONTINUE the processing stops.An overlay can call most frontend functions without any special consideration.However, if a call is going to result in any backend code being invoked, thenthe backend environment must be correct. During a normal backend invocation,op->o_bd points to the BackendDB structure for the backend, andop->o_bd->bd_info points to the BackendInfo for the backend. All of theinformation a specific backend instance needs is in op->o_bd->be_private andall of its entry points are in the BackendInfo structure. When overlays are inuse on a backend, op->o_bd->bd_info points to the BackendInfo (actually aslap_overinfo) that contains the overlay framework. When a particular overlayinstance is executing, op->o_bd points to a copy of the original op->o_bd, andop->o_bd->bd_info points to a slap_overinst which carries the information aboutthe current overlay. The slap_overinst contains an on_private pointer which canbe used to carry any configuration or state information the overlay needs. Thenormal way to invoke a backend function is through the op->o_bd->bd_info tableof entry points, but obviously this must be set to the backend's originalBackendInfo in order to get to the right function.There are two approaches here. The slap_overinst also contains a on_info fieldthat points to the top slap_overinfo that wraps the current backend. Thesimplest thing is for the overlay to set op->o_bd->bd_info to this on_infovalue before invoking a backend function. This will cause processing of thatparticular operation to begin at the top of the overlay stack, so all the otheroverlays on the backend will also get a chance to handle this internal request.The other possibility is to invoke the underlying backend directly, bypassingthe rest of the overlays, by calling through on_info->oi_orig. You should becareful in choosing this approach, since it precludes other overlays from doingtheir jobs.One of the more interesting uses for an overlay is to attach two (or more)different database backends into a single execution stack. Assuming that thebasic frontend-managed information (suffix, rootdn, ACLs, etc.) will be thesame for all of the backends, the only thing the overlay needs to maintain is abe_private and bd_info pointer for the added backends. The chain and proxycacheoverlays are two complementary examples of this usage. The chain overlayattaches a back-ldap backend to a local database backend, and allows referralsto remote servers generated by the database to be processed by slapd instead ofbeing returned to the client. The proxycache overlay attaches a local databaseto a back-ldap (or back-meta) backend and allows search results from remoteservers to be cached locally. In both cases the overlays must provide a bit ofglue to swap in the appropriate be_private and bd_info pointers before invokingthe attached backend, which can then be invoked as usual.---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -