1# OpenLDAP: pkg/openldap-guide/admin/backends.sdf,v 1.8.2.9 2010/04/15 18:25:42 quanah Exp 2# Copyright 2007-2010 The OpenLDAP Foundation, All Rights Reserved. 3# COPYING RESTRICTIONS APPLY, see COPYRIGHT. 4 5H1: Backends 6 7Backends do the actual work of storing or retrieving data in response 8to LDAP requests. Backends may be compiled statically into {{slapd}}, 9or when module support is enabled, they may be dynamically loaded. 10 11If your installation uses dynamic modules, you may need to add the 12relevant {{moduleload}} directives to the examples that follow. The 13name of the module for a backend is usually of the form: 14 15> back_<backend name>.la 16 17So for example, if you need to load the {{hdb}} backend, you would configure 18 19> moduleload back_hdb.la 20 21H2: Berkeley DB Backends 22 23 24H3: Overview 25 26The {{bdb}} backend to {{slapd}}(8) is the recommended primary backend for a 27normal {{slapd}} database. It uses the Oracle Berkeley DB ({{TERM:BDB}}) 28package to store data. It makes extensive use of indexing and caching 29(see the {{SECT:Tuning}} section) to speed data access. 30 31{{hdb}} is a variant of the {{bdb}} backend that uses a hierarchical database 32layout which supports subtree renames. It is otherwise identical to the {{bdb}} 33 behavior, and all the same configuration options apply. 34 35Note: An {{hdb}} database needs a large {{idlcachesize}} for good search performance, 36typically three times the {{cachesize}} (entry cache size) or larger. 37 38H3: back-bdb/back-hdb Configuration 39 40MORE LATER 41 42H3: Further Information 43 44{{slapd-bdb}}(5) 45 46H2: LDAP 47 48 49H3: Overview 50 51The LDAP backend to {{slapd}}(8) is not an actual database; instead it acts 52as a proxy to forward incoming requests to another LDAP server. While 53processing requests it will also chase referrals, so that referrals are fully 54processed instead of being returned to the {{slapd}} client. 55 56Sessions that explicitly {{Bind}} to the {{back-ldap}} database always create 57their own private connection to the remote LDAP server. Anonymous sessions 58will share a single anonymous connection to the remote server. For sessions 59bound through other mechanisms, all sessions with the same DN will share the 60same connection. This connection pooling strategy can enhance the proxy's 61efficiency by reducing the overhead of repeatedly making/breaking multiple 62connections. 63 64The ldap database can also act as an information service, i.e. the identity 65of locally authenticated clients is asserted to the remote server, possibly 66in some modified form. For this purpose, the proxy binds to the remote server 67with some administrative identity, and, if required, authorizes the asserted 68identity. 69 70It is heavily used by a lot of other {{SECT: Backends}} and {{SECT: Overlays}}. 71 72H3: back-ldap Configuration 73 74As previously mentioned, {{slapd-ldap(5)}} is used behind the scenes by many 75other {{SECT: Backends}} and {{SECT: Overlays}}. Some of them merely provide a 76few configuration directive themselves, but have available to the administrator 77the whole of the {{slapd-ldap(5)}} options. 78 79For example, the {{SECT: Translucent Proxy}}, which retrieves entries from a 80remote LDAP server that can be partially overridden by the defined database, has 81only four specific {{translucent-}} directives, but can be configured using any 82of the normal {{slapd-ldap(5)}} options. See {[slapo-translucent(5)}} for details. 83 84Other {{SECT: Overlays}} allow you to tag directives in front of a normal 85{{slapd-ldap(5)}} directive. For example, the {{slapo-chain(5)}} overlay does 86this: 87 88{{"There are very few chain overlay specific directives; however, directives 89related to the instances of the ldap backend that may be implicitly instantiated 90by the overlay may assume a special meaning when used in conjunction with this 91overlay. They are described in slapd-ldap(5), and they also need to be prefixed 92by chain-."}} 93 94You may have also seen the {{slapd-ldap(5)}} backend used and described in the 95{{SECT: Push Based}} {{SECT: Replication}} section of the guide. 96 97It should therefore be obvious that the {{slapd-ldap(5)}} backend is extremely 98flexible and heavily used throughout the OpenLDAP Suite. 99 100The following is a very simple example, but already the power of the {{slapd-ldap(5)}} 101backend is seen by use of a {{uri list}}: 102 103> database ldap 104> suffix "dc=suretecsystems,dc=com" 105> rootdn "cn=slapd-ldap" 106> uri ldap://localhost/ ldap://remotehost ldap://remotehost2 107 108The URI list is space or comma-separated. Whenever the server that responds 109is not the first one in the list, the list is rearranged and the responsive 110server is moved to the head, so that it will be first contacted the next time 111a connection needs be created. 112 113This feature can be used to provide a form of load balancing when using 114{{SECT: MirrorMode replication}}. 115 116H3: Further Information 117 118{{slapd-ldap}}(5) 119 120H2: LDIF 121 122 123H3: Overview 124 125The LDIF backend to {{slapd}}(8) is a basic storage backend that stores 126entries in text files in LDIF format, and exploits the filesystem to create 127the tree structure of the database. It is intended as a cheap, low performance 128easy to use backend. 129 130When using the {{cn=config}} dynamic configuration database with persistent 131storage, the configuration data is stored using this backend. See {{slapd-config}}(5) 132for more information 133 134H3: back-ldif Configuration 135 136Like many other backends, the LDIF backend can be instantiated with very few 137configuration lines: 138 139> include ./schema/core.schema 140> 141> database ldif 142> directory "./ldif" 143> suffix "dc=suretecsystems,dc=com" 144> rootdn "cn=LDIF,dc=suretecsystems,dc=com" 145> rootpw LDIF 146 147If we add the {{dcObject}} for {{dc=suretecsystems,dc=com}}, you can see how this 148is added behind the scenes on the file system: 149 150> dn: dc=suretecsystems,dc=com 151> objectClass: dcObject 152> objectClass: organization 153> dc: suretecsystems 154> o: Suretec Systems Ltd 155 156Now we add it to the directory: 157 158> ldapadd -x -H ldap://localhost:9011 -f suretec.ldif -D "cn=LDIF,dc=suretecsystems,dc=com" -w LDIF 159> adding new entry "dc=suretecsystems,dc=com" 160 161And inside {{F: ./ldif}} we have: 162 163> ls ./ldif 164> dc=suretecsystems,dc=com.ldif 165 166which again contains: 167 168> cat ldif/dc\=suretecsystems\,dc\=com.ldif 169> 170> dn: dc=suretecsystems 171> objectClass: dcObject 172> objectClass: organization 173> dc: suretecsystems 174> o: Suretec Systems Ltd. 175> structuralObjectClass: organization 176> entryUUID: 2134b714-e3a1-102c-9a15-f96ee263886d 177> creatorsName: cn=LDIF,dc=suretecsystems,dc=com 178> createTimestamp: 20080711142643Z 179> entryCSN: 20080711142643.661124Z#000000#000#000000 180> modifiersName: cn=LDIF,dc=suretecsystems,dc=com 181> modifyTimestamp: 20080711142643Z 182 183This is the complete format you would get when exporting your directory using 184{{F: slapcat}} etc. 185 186H3: Further Information 187 188{{slapd-ldif}}(5) 189 190H2: Metadirectory 191 192 193H3: Overview 194 195The meta backend to {{slapd}}(8) performs basic LDAP proxying with respect 196to a set of remote LDAP servers, called "targets". The information contained 197in these servers can be presented as belonging to a single Directory Information 198Tree ({{TERM:DIT}}). 199 200A basic knowledge of the functionality of the {{slapd-ldap}}(5) backend is 201recommended. This backend has been designed as an enhancement of the ldap 202backend. The two backends share many features (actually they also share portions 203 of code). While the ldap backend is intended to proxy operations directed 204 to a single server, the meta backend is mainly intended for proxying of 205 multiple servers and possibly naming context masquerading. 206 207These features, although useful in many scenarios, may result in excessive 208overhead for some applications, so its use should be carefully considered. 209 210 211H3: back-meta Configuration 212 213LATER 214 215H3: Further Information 216 217{{slapd-meta}}(5) 218 219H2: Monitor 220 221 222H3: Overview 223 224The monitor backend to {{slapd}}(8) is not an actual database; if enabled, 225it is automatically generated and dynamically maintained by slapd with 226information about the running status of the daemon. 227 228To inspect all monitor information, issue a subtree search with base {{cn=Monitor}}, 229requesting that attributes "+" and "*" are returned. The monitor backend produces 230mostly operational attributes, and LDAP only returns operational attributes 231that are explicitly requested. Requesting attribute "+" is an extension which 232requests all operational attributes. 233 234See the {{SECT:Monitoring}} section. 235 236H3: back-monitor Configuration 237 238The monitor database can be instantiated only once, i.e. only one occurrence 239of "database monitor" can occur in the {{slapd.conf(5)}} file. Also the suffix 240is automatically set to {{"cn=Monitor"}}. 241 242You can however set a {{rootdn}} and {{rootpw}}. The following is all that is 243needed to instantiate a monitor backend: 244 245> include ./schema/core.schema 246> 247> database monitor 248> rootdn "cn=monitoring,cn=Monitor" 249> rootpw monitoring 250 251You can also apply Access Control to this database like any other database, for 252example: 253 254> access to dn.subtree="cn=Monitor" 255> by dn.exact="uid=Admin,dc=my,dc=org" write 256> by users read 257> by * none 258 259Note: The {{F: core.schema}} must be loaded for the monitor database to work. 260 261A small example of the data returned via {{ldapsearch}} would be: 262 263> ldapsearch -x -H ldap://localhost:9011 -b 'cn=Monitor' 264> # extended LDIF 265> # 266> # LDAPv3 267> # base <cn=Monitor> with scope subtree 268> # filter: (objectclass=*) 269> # requesting: ALL 270> # 271> 272> # Monitor 273> dn: cn=Monitor 274> objectClass: monitorServer 275> cn: Monitor 276> description: This subtree contains monitoring/managing objects. 277> description: This object contains information about this server. 278> description: Most of the information is held in operational attributes, which 279> must be explicitly requested. 280> 281> # Backends, Monitor 282> dn: cn=Backends,cn=Monitor 283> objectClass: monitorContainer 284> cn: Backends 285> description: This subsystem contains information about available backends. 286 287Please see the {{SECT: Monitoring}} section for complete examples of information 288available via this backend. 289 290H3: Further Information 291 292{{slapd-monitor}}(5) 293 294H2: Null 295 296 297H3: Overview 298 299The Null backend to {{slapd}}(8) is surely the most useful part of slapd: 300 301* Searches return success but no entries. 302* Compares return compareFalse. 303* Updates return success (unless readonly is on) but do nothing. 304* Binds other than as the rootdn fail unless the database option "bind on" is given. 305* The slapadd(8) and slapcat(8) tools are equally exciting. 306 307Inspired by the {{F:/dev/null}} device. 308 309H3: back-null Configuration 310 311This has to be one of the shortest configurations you'll ever do. In order to 312test this, your {{F: slapd.conf}} file would look like: 313 314> database null 315> suffix "cn=Nothing" 316> bind on 317 318{{bind on}} means: 319 320{{"Allow binds as any DN in this backend's suffix, with any password. The default is "off"."}} 321 322To test this backend with {{ldapsearch}}: 323 324> ldapsearch -x -H ldap://localhost:9011 -D "uid=none,cn=Nothing" -w testing -b 'cn=Nothing' 325> # extended LDIF 326> # 327> # LDAPv3 328> # base <cn=Nothing> with scope subtree 329> # filter: (objectclass=*) 330> # requesting: ALL 331> # 332> 333> # search result 334> search: 2 335> result: 0 Success 336> 337> # numResponses: 1 338 339 340H3: Further Information 341 342{{slapd-null}}(5) 343 344H2: Passwd 345 346 347H3: Overview 348 349The PASSWD backend to {{slapd}}(8) serves up the user account information 350listed in the system {{passwd}}(5) file (defaulting to {{F: /etc/passwd}}). 351 352This backend is provided for demonstration purposes only. The DN of each entry 353is "uid=<username>,<suffix>". 354 355H3: back-passwd Configuration 356 357The configuration using {{F: slapd.conf}} a slightly longer, but not much. For 358example: 359 360> include ./schema/core.schema 361> 362> database passwd 363> suffix "cn=passwd" 364 365Again, testing this with {{ldapsearch}} would result in something like: 366 367> ldapsearch -x -H ldap://localhost:9011 -b 'cn=passwd' 368> # extended LDIF 369> # 370> # LDAPv3 371> # base <cn=passwd> with scope subtree 372> # filter: (objectclass=*) 373> # requesting: ALL 374> # 375> 376> # passwd 377> dn: cn=passwd 378> cn: passwd 379> objectClass: organizationalUnit 380> 381> # root, passwd 382> dn: uid=root,cn=passwd 383> objectClass: person 384> objectClass: uidObject 385> uid: root 386> cn: root 387> sn: root 388> description: root 389 390 391H3: Further Information 392 393{{slapd-passwd}}(5) 394 395H2: Perl/Shell 396 397H3: Overview 398 399The Perl backend to {{slapd}}(8) works by embedding a {{perl}}(1) interpreter 400into {{slapd}}(8). Any perl database section of the configuration file 401{{slapd.conf}}(5) must then specify what Perl module to use. Slapd then creates 402a new Perl object that handles all the requests for that particular instance of the backend. 403 404The Shell backend to {{slapd}}(8) executes external programs to implement 405operations, and is designed to make it easy to tie an existing database to the 406slapd front-end. This backend is is primarily intended to be used in prototypes. 407 408H3: back-perl/back-shell Configuration 409 410LATER 411 412H3: Further Information 413 414{{slapd-shell}}(5) and {{slapd-perl}}(5) 415 416H2: Relay 417 418 419H3: Overview 420 421The primary purpose of this {{slapd}}(8) backend is to map a naming context 422defined in a database running in the same {{slapd}}(8) instance into a 423virtual naming context, with attributeType and objectClass manipulation, if 424required. It requires the rwm overlay. 425 426This backend and the above mentioned overlay are experimental. 427 428H3: back-relay Configuration 429 430LATER 431 432H3: Further Information 433 434{{slapd-relay}}(5) 435 436H2: SQL 437 438 439H3: Overview 440 441The primary purpose of this {{slapd}}(8) backend is to PRESENT information 442stored in some RDBMS as an LDAP subtree without any programming (some SQL and 443maybe stored procedures can't be considered programming, anyway ;). 444 445That is, for example, when you (some ISP) have account information you use in 446an RDBMS, and want to use modern solutions that expect such information in LDAP 447(to authenticate users, make email lookups etc.). Or you want to synchronize or 448distribute information between different sites/applications that use RDBMSes 449and/or LDAP. Or whatever else... 450 451It is {{B:NOT}} designed as a general-purpose backend that uses RDBMS instead of 452BerkeleyDB (as the standard BDB backend does), though it can be used as such with 453several limitations. Please see {{SECT: LDAP vs RDBMS}} for discussion. 454 455The idea is to use some meta-information to translate LDAP queries to SQL queries, 456leaving relational schema untouched, so that old applications can continue using 457it without any modifications. This allows SQL and LDAP applications to interoperate 458without replication, and exchange data as needed. 459 460The SQL backend is designed to be tunable to virtually any relational schema without 461having to change source (through that meta-information mentioned). Also, it uses 462ODBC to connect to RDBMSes, and is highly configurable for SQL dialects RDBMSes 463may use, so it may be used for integration and distribution of data on different 464RDBMSes, OSes, hosts etc., in other words, in highly heterogeneous environments. 465 466This backend is experimental. 467 468H3: back-sql Configuration 469 470This backend has to be one of the most abused and complex backends there is. 471Therefore, we will go through a simple, small example that comes with the 472OpenLDAP source and can be found in {{F: servers/slapd/back-sql/rdbms_depend/README}} 473 474For this example we will be using PostgreSQL. 475 476First, we add to {{F: /etc/odbc.ini}} a block of the form: 477 478> [example] <=== 479> Description = Example for OpenLDAP's back-sql 480> Driver = PostgreSQL 481> Trace = No 482> Database = example <=== 483> Servername = localhost 484> UserName = manager <=== 485> Password = secret <=== 486> Port = 5432 487> ;Protocol = 6.4 488> ReadOnly = No 489> RowVersioning = No 490> ShowSystemTables = No 491> ShowOidColumn = No 492> FakeOidIndex = No 493> ConnSettings = 494 495The relevant information for our test setup is highlighted with '<===' on the 496right above. 497 498Next, we add to {{F: /etc/odbcinst.ini}} a block of the form: 499 500> [PostgreSQL] 501> Description = ODBC for PostgreSQL 502> Driver = /usr/lib/libodbcpsql.so 503> Setup = /usr/lib/libodbcpsqlS.so 504> FileUsage = 1 505 506 507We will presume you know how to create a database and user in PostgreSQL and 508how to set a password. Also, we'll presume you can populate the 'example' 509database you've just created with the following files, as found in {{F: servers/slapd/back-sql/rdbms_depend/pgsql }} 510 511> backsql_create.sql, testdb_create.sql, testdb_data.sql, testdb_metadata.sql 512 513Lastly, run the test: 514 515> [root@localhost]# cd $SOURCES/tests 516> [root@localhost]# SLAPD_USE_SQL=pgsql ./run sql-test000 517 518Briefly, you should see something like (cut short for space): 519 520> Cleaning up test run directory leftover from previous run. 521> Running ./scripts/sql-test000-read... 522> running defines.sh 523> Starting slapd on TCP/IP port 9011... 524> Testing SQL backend read operations... 525> Waiting 5 seconds for slapd to start... 526> Testing correct bind... dn:cn=Mitya Kovalev,dc=example,dc=com 527> Testing incorrect bind (should fail)... ldap_bind: Invalid credentials (49) 528> 529> ...... 530> 531> Filtering original ldif... 532> Comparing filter output... 533> >>>>> Test succeeded 534 535The test is basically readonly; this can be performed by all RDBMSes 536(listed above). 537 538There is another test, sql-test900-write, which is currently enabled 539only for PostgreSQL and IBM db2. 540 541Using {{F: sql-test000}}, files in {{F: servers/slapd/back-sql/rdbms_depend/pgsql/}} 542and the man page, you should be set. 543 544Note: This backend is experimental. 545 546H3: Further Information 547 548{{slapd-sql}}(5) and {{F: servers/slapd/back-sql/rdbms_depend/README}} 549