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

📄 slapd-sql.5

📁 OpenLdap是LDAP的开源项目
💻 5
📖 第 1 页 / 共 2 页
字号:
.LPThe easiest way is to create an objectClass for each entity you had inER-diagram when designing your relational schema.Any relational schema, no matter how normalized it is, was designedafter some model of your application's domain (for instance, accounts,services etc. in ISP), and is used in terms of its entities, not justtables of normalized schema.It means that for every attribute of every such instance there is aneffective SQL query that loads its values..LPAlso you might want your object classes to conform to some of the standardschemas like inetOrgPerson etc..LPNevertheless, when you think it out, we must define a way to translateLDAP operation requests to (a series of) SQL queries.Let us deal with the SEARCH operation..LPExample:Let's suppose that we store information about persons working in our organization in two tables:.LP.nf  PERSONS              PHONES  ----------           -------------  id integer           id integer  first_name varchar   pers_id integer references persons(id)  last_name varchar    phone  middle_name varchar  ....fi.LP(PHONES contains telephone numbers associated with persons).A person can have several numbers, then PHONES contains severalrecords with corresponding pers_id, or no numbers (and no records inPHONES with such pers_id).An LDAP objectclass to present such information could look like this:.LP.nf  person  -------  MUST cn  MAY telephoneNumber $ firstName $ lastName  ....fi.LPTo fetch all values for cn attribute given person ID, we construct thequery:.LP.nf  SELECT CONCAT(persons.first_name,' ',persons.last_name)      AS cn FROM persons WHERE persons.id=?.fi.LPfor telephoneNumber we can use:.LP.nf  SELECT phones.phone AS telephoneNumber FROM persons,phones      WHERE persons.id=phones.pers_id AND persons.id=?.fi.LPIf we wanted to service LDAP requests with filters like(telephoneNumber=123*), we would construct something like:.LP.nf  SELECT ... FROM persons,phones      WHERE persons.id=phones.pers_id          AND persons.id=?          AND phones.phone like '%1%2%3%'.fi.LP(note how the telephoneNumber match is expanded in multiple wildcardsto account for interspersed ininfluential chars like spaces, dashesand so; this occurs by design because telephoneNumber is defined after a specially recognized syntax).So, if we had information about what tables contain values for eachattribute, how to join these tables and arrange these values, we couldtry to automatically generate such statements, and translate searchfilters to SQL WHERE clauses..LPTo store such information, we add three more tables to our schemaand fill it with data (see samples):.LP.nf  ldap_oc_mappings (some columns are not listed for clarity)  ---------------  id=1  name="person"  keytbl="persons"  keycol="id".fi.LPThis table defines a mapping between objectclass (its name held in the"name" column), and a table that holds the primary key for correspondingentities.For instance, in our example, the person entity, which we are tryingto present as "person" objectclass, resides in two tables (persons andphones), and is identified by the persons.id column (that we will callthe primary key for this entity).Keytbl and keycol thus contain "persons" (name of the table), and "id"(name of the column)..LP.nf  ldap_attr_mappings (some columns are not listed for clarity)  -----------  id=1  oc_map_id=1  name="cn"  sel_expr="CONCAT(persons.first_name,' ',persons.last_name)"  from_tbls="persons"  join_where=NULL  ************  id=<n>  oc_map_id=1  name="telephoneNumber"  sel_expr="phones.phone"  from_tbls="persons,phones"  join_where="phones.pers_id=persons.id".fi.LPThis table defines mappings between LDAP attributes and SQL queriesthat load their values.Note that, unlike LDAP schema, these are not.B attribute types- the attribute "cn" for "person" objectclass canhave its values in different tables than "cn" for some other objectclass,so attribute mappings depend on objectclass mappings (unlike attributetypes in LDAP schema, which are indifferent to objectclasses).Thus, we have oc_map_id column with link to oc_mappings table..LPNow we cut the SQL query that loads values for a given attribute into 3 parts.First goes into sel_expr column - this is the expression we hadbetween SELECT and FROM keywords, which defines WHAT to load.Next is table list - text between FROM and WHERE keywords.It may contain aliases for convenience (see examples).The last is part of the where clause, which (if it exists at all) expresses thecondition for joining the table containing values with the tablecontaining the primary key (foreign key equality and such).If values are in the same table as the primary key, then this column isleft NULL (as for cn attribute above)..LPHaving this information in parts, we are able to not only constructqueries that load attribute values by id of entry (for this we couldstore SQL query as a whole), but to construct queries that load id'sof objects that correspond to a given search filter (or at least part ofit).See below for examples..LP.nf  ldap_entries  ------------  id=1  dn=<dn you choose>  oc_map_id=...  parent=<parent record id>  keyval=<value of primary key>.fi.LPThis table defines mappings between DNs of entries in your LDAP tree,and values of primary keys for corresponding relational data.It has recursive structure (parent column references id column of thesame table), which allows you to add any tree structure(s) to yourflat relational data.Having id of objectclass mapping, we can determine table and columnfor primary key, and keyval stores value of it, thus defining the exacttuple corresponding to the LDAP entry with this DN..LPNote that such design (see exact SQL table creation query) implies oneimportant constraint - the key must be an integer.But all that I know about well-designed schemas makes me think that it'snot very narrow ;) If anyone needs support for different types forkeys - he may want to write a patch, and submit it to OpenLDAP ITS,then I'll include it..LPAlso, several people complained that they don't really need verystructured trees, and they don't want to update one more table everytime they add or delete an instance in the relational schema.Those people can use a view instead of a real table for ldap_entries, somethinglike this (by Robin Elfrink):.LP.nf  CREATE VIEW ldap_entries (id, dn, oc_map_id, parent, keyval)      AS          SELECT 0, UPPER('o=MyCompany,c=NL'),              3, 0, 'baseObject' FROM unixusers WHERE userid='root'      UNION          SELECT (1000000000+userid),              UPPER(CONCAT(CONCAT('cn=',gecos),',o=MyCompany,c=NL')),              1, 0, userid FROM unixusers      UNION          SELECT (2000000000+groupnummer),              UPPER(CONCAT(CONCAT('cn=',groupnaam),',o=MyCompany,c=NL')),              2, 0, groupnummer FROM groups;.fi.LPIf your RDBMS does not support.B unionsin views, only one objectClass can be mapped in.BR ldap_entries ,and the baseObject cannot be created; in this case, see the .B baseObjectdirective for a possible workaround..LP.SH Typical SQL backend operationHaving metainformation loaded, the SQL backend uses these tables todetermine a set of primary keys of candidates (depending on searchscope and filter).It tries to do it for each objectclass registered in ldap_objclasses..LPExample:for our query with filter (telephoneNumber=123*) we would get the following query generated (which loads candidate IDs).LP.nf  SELECT ldap_entries.id,persons.id, 'person' AS objectClass,         ldap_entries.dn AS dn    FROM ldap_entries,persons,phones   WHERE persons.id=ldap_entries.keyval     AND ldap_entries.objclass=?     AND ldap_entries.parent=?     AND phones.pers_id=persons.id     AND (phones.phone LIKE '%1%2%3%').fi.LP(for ONELEVEL search)or "... AND dn=?" (for BASE search)or "... AND dn LIKE '%?'" (for SUBTREE).LPThen, for each candidate, we load the requested attributes usingper-attribute queries like.LP.nf  SELECT phones.phone AS telephoneNumber    FROM persons,phones   WHERE persons.id=? AND phones.pers_id=persons.id.fi.LPThen, we use test_filter() from the frontend API to test the entry for a fullLDAP search filter match (since we cannot effectively make sense ofSYNTAX of corresponding LDAP schema attribute, we translate the filterinto the most relaxed SQL condition to filter candidates), and send it tothe user..LPADD, DELETE, MODIFY and MODRDN operations are also performed on per-attributemetainformation (add_proc etc.).In those fields one can specify an SQL statement or stored procedurecall which can add, or delete given values of a given attribute, usingthe given entry keyval (see examples -- mostly PostgreSQL, ORACLE and MSSQL - since as of this writing there are no stored procs in MySQL)..LPWe just add more columns to ldap_oc_mappings and ldap_attr_mappings, holdingstatements to execute (like create_proc, add_proc, del_proc etc.), andflags governing the order of parameters passed to those statements.Please see samples to find out what are the parameters passed, and otherinformation on this matter - they are self-explanatory for those familiarwith the concepts expressed above..LP.SH Common techniques (referrals, multiclassing etc.)First of all, let's remember that among other major differences to thecomplete LDAP data model, the concept above does not directly supportsuch things as multiple objectclasses per entry, and referrals.Fortunately, they are easy to adopt in this scheme.The SQL backend suggests one more table being added to the schema:ldap_entry_objectclasses(entry_id,oc_name)..LPThe first contains any number of objectclass names that correspondingentries will be found by, in addition to that mentioned inmapping.The SQL backend automatically adds attribute mapping for the "objectclass"attribute to each objectclass mapping that loads values from this table.So, you may, for instance, have a mapping for inetOrgPerson, and use itfor queries for "person" objectclass....LPReferrals used to be implemented in a loose manner by adding an extratable that allowed any entry to host a "ref" attribute, along witha "referral" extra objectClass in table ldap_entry_objclasses.In the current implementation, referrals are treated like any otheruser-defined schema, since "referral" is a structural objectclass.The suggested practice is to define a "referral" entry in ldap_oc_mappings,holding a naming attribute, e.g. "ou" or "cn", a "ref" attribute,containing the url; in case multiple referrals per entry are needed,a separate table for urls can be created, where urls are mappedto the respective entries.The use of the naming attribute usually requires to add an "extensibleObject" value to ldap_entry_objclasses..LP.SH CaveatsAs previously stated, this backend should not be considereda replacement of other data storage backends, but rather a gatewayto existing RDBMS storages that need to be published in LDAP form..LPThe \fBhasSubordintes\fP operational attribute is honored by back-sqlin search results and in compare operations; it is partially honoredalso in filtering.  Owing to design limitations, a (brain-dead?) filterof the form\fB(!(hasSubordinates=TRUE))\fPwill give no results instead of returning all the leaf entries, becauseit actually expands into \fB... AND NOT (1=1)\fP.If you need to find all the leaf entries, please use\fB(hasSubordinates=FALSE)\fPinstead..LPA directoryString value of the form "__First___Last_"(where underscores should be replaced by spaces) correspondsto its prettified counterpart "First_Last"; this is not currentlyhonored by back-sql if non-prettified data is written via RDBMS;when non-prettified data is written thru back-sql, the prettified values are actually used instead..LP.SH BUGSWhen the.B ldap_entry_objclassestable is empty, filters on the .B objectClassattribute erroneously result in no candidates.A workaround consists in adding at least one row to that table,no matter if valid or not..LP.SH PROXY CACHE OVERLAYThe proxy cache overlay allows caching of LDAP search requests (queries) in a local database.See .BR slapo-pcache (5)for details..SH EXAMPLESThere are example SQL modules in the slapd/back-sql/rdbms_depend/directory in the OpenLDAP source tree..SH ACCESS CONTROLThe .B sqlbackend honors access control semantics as indicated in.BR slapd.access (5)(including the .B discloseaccess privilege when enabled at compile time)..SH FILES.TPETCDIR/slapd.confdefault slapd configuration file.SH SEE ALSO.BR slapd.conf (5),.BR slapd (8).

⌨️ 快捷键说明

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