3

So, I have downloaded the latest source of OpenLDAP, compiled with —-enable-sql, messed around with the slapd.conf, configured the odbc files, added the tables to my current DB, spend a week debugging slapd -d -1, and now MySQL users, have become LDAP users and are able to log in.

I need some help understanding the basic structure of an LDAP object. From everything that I read, I am assuming that each object needs to belong to a structuralObjectClass and then each object can belong to many other objectClasses?

The only thing I need this LDAP server to do is just to authenticate users. There is no need for the users to edit their info. So I first laid out the following structure:

Institute
dn: dc=example,dc=org
dc: example
structuralObjectClass: dcObject
objectClass: organization
o: example
description: Example Company

Groups

Dn: ou=Groups,dc=example,dc=org
Ou: Groups
structuralObjectClass: organizationalUnit

dn: ou=Users,dc=example,dc=org
ou: Users
structuralObjectClass: organizationalUnit

dn: ou=marketing,ou=Groups,dc=example,dc=org
cn: marketing
gidNumber: 1554
structuralObjectClass: posixGroup
memberUid: user1
memberUid: userN

dn: ou=administration,ou=Groups,dc=example,dc=org
cn: administration
gidNumber: 1555
structuralObjectClass: posixGroup
memberUid: user1
memberUid: userN

Users
Dn: uid=user1,ou=Users,dc=example,dc=org
structuralObjectClass: inetOrgPerson
givenName: 
displayName:
cn: 
uidNumber: 
homeDirectory: 
sn: 
gidNumber: 
objectClass: person
objectClass: organizationalPerson
objectClass: posixAccount
objectClass: shadowAccount

I believe OpenLDAP will add the missing top objectClass. Since I already have a DB with these users, and I am more comfortable with RDBMSes instead of schemas in LDAP I have a bit of an issue understanding why when I try to log in, the ldapsearch utility goes through all the object classes that I have in the ldap_oc_mappings table instead of just searching the objectClass inetOrgPerson. This way there would not be any unecessary queries. Anyway, these are the tables:

ldap_attr_mappings
+----+-----------+---------------+-----------------------------------------------------------+---------------+---------------------------------+-------------+
| id | oc_map_id | name          | sel_expr                                                  | from_tbls     | join_where                      | param_order |
+----+-----------+---------------+-----------------------------------------------------------+---------------+---------------------------------+-------------+
|  3 |         1 | sn            | users     .lName                                          | users         | NULL                            |           3 |
|  4 |         1 | userPassword  | concat('{MD5}',BASE64_ENCODE(unhex(users     .password))) | users    | NOT ISNULL(users     .password) |           3 |
|  5 |         1 | displayName   | concat(users     .fName,' ',users     .lName)             | users    | NULL                            |           3 |
|  6 |         1 | homeDirectory | users     .homeDirectory                                  | users    | NULL                            |           3 |
|  7 |         1 | loginShell    | users     .loginShell                                     | users    | NULL                            |           3 |
|  8 |         1 | uidNumber     | users     .uidNumber                                      | users    | NULL                            |           3 |
|  9 |         1 | gidNumber     | users     .gidNumber                                      | users    | NULL                            |           3 |
| 10 |         1 | cn            | users     .loginName                                      | users         | NULL                            |           3 |
| 11 |         1 | uid           | users     .loginName                                      | users         | NULL                            |           3 |
| 12 |         3 | ou            | ldap_groups.name                                          | ldap_groups   | NULL                            |           3 |
| 14 |         2 | o             | ldap_org_unit.o                                           | ldap_org_unit | NULL                            |           3 |
| 16 |         2 | dc            | ldap_org_unit.o                                           | ldap_org_unit | NULL                            |           3 |
| 17 |         2 | description   | ldap_org_unit.Description                                 | ldap_org_unit | NULL                            |           3 |
| 18 |         4 | gidNumber     | ldap_groups.gid                                           | ldap_groups   | NULL                            |           3 |
| 19 |         4 | cn            | ldap_groups.cn                                            | ldap_groups   | NULL                            |           3 |
+----+-----------+---------------+-----------------------------------------------------------+---------------+---------------------------------+-------------+


ldap_oc_mappings
+----+--------------------+---------------+--------------+
| id | name               | keytbl        | keycol       |
+----+--------------------+---------------+--------------+
|  1 | inetOrgperson      | users         | userID       |
|  2 | organization       | ldap_org_unit | id           |
|  3 | organizationalUnit | ldap_groups   | gid          |
|  4 | posixGroup         | ldap_groups   | gid          |
+----+--------------------+---------------+--------------+

ldap_entry_objclasses
+----------+---------------+
| entry_id | oc_name       |
+----------+---------------+
|    12216 | inetOrgPerson |
|    12216 | posixAccount  |
|    12216 | shadowAccount |
+----------+---------------+

The objclasses entries are just for one user. Each user has these objectClasses assigned to them. This is a view not a table

ldap_org_unit
+----+-------------+---------------------------------+--------+---------------------+-----------+
| id | o           | dn                              | parent | Description         | oc_map_id |
+----+-------------+---------------------------------+--------+---------------------+-----------+
|  1 | Example     | DC=Example,DC=org               |      0 | Example Co          |         2 |
|  2 | Users       | ou=Users,DC=example,DC=org      |      1 |                     |         3 |
|  3 | Groups      | ou=Groups,DC=example,DC=org     |      1 |                     |         3 |
+----+-------------+---------------------------------+--------+---------------------+-----------+

I think the parent values here might not be correct

ldap_groups
+------+----------------+----------------+-----------------------------------------------+
| gid  | name           | cn             | dn                                            |
+------+----------------+----------------+-----------------------------------------------+
| 1554 | Marketing      | marketing      | cn=marketing,ou=Groups,dc=example,dc=org      |
| 1155 | administration | administration | cn=administration,ou=Groups,dc=example,dc=org |
+------+----------------+----------------+-----------------------------------------------+

Lastly: ldap_entries
+-------+-----------------------------------------------+-----------+--------+--------+
| id    | dn                                            | oc_map_id | parent | keyval |
+-------+-----------------------------------------------+-----------+--------+--------+
|     1 | DC=EXAMPLE,DC=ORG                             |         2 |      0 |      1 |
|     2 | OU=USERS,DC=EXAMPLE,DC=ORG                    |         3 |      1 |      2 |
|     3 | OU=GROUPS,DC=EXAMPLE,DC=ORG                   |         3 |      1 |      3 |
|  1554 | CN=MARKETING,OU=GROUPS,DC=EXAMPLE,DC=ORG      |         4 |      3 |   1554 |
|  1155 | CN=ADMINISTRATION,OU=GROUPS,DC=EXAMPLE,DC=ORG |         4 |      3 |   1155 |
| 22963 | CN=ROOT,DC=EXAMPLE,DC=ORG                     |         1 |   1554 |  12963 |
| 12216 | CN=USER1,OU=USERS,DC=EXAMPLE,DC=ORG           |         1 |   1555 |   2216 |
+-------+-----------------------------------------------+-----------+--------+--------+

Are the parent values here correct?

As I said this works and users are able to log in. But when I run ldasearch -b "dc=example,dc=org" "(objectclass=*)" it takes a very long time. I have read numerous articles stating that the reason why RDBMSes cannot and should not be used for LDAP backends is because mainly of this issue. But it is excruciatingly slow, which leads me to believe that there are some unnecessary queries and my table "relations" are not correct. The first couple of result of the ldapsearch are:

# ROOT, EXAMPLE.ORG
dn: cn=ROOT,dc=EXAMPLE,dc=ORG
objectClass: inetOrgPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: root
sn: Admin
uid: root
gidNumber: 1554
uidNumber: 0
loginShell: /bin/bash
displayName: Domain Admin
userPassword:: *******
homeDirectory: /ldaphomes/root

# USER1, USERS, EXAMPLE.ORG
dn: cn=USER1,ou=USERS,dc=EXAMPLE,dc=ORG
objectClass: inetOrgPerson
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: user1
sn: User 1
uid: user1
gidNumber: 0
uidNumber: 0
displayName: User 1
userPassword:: ******

As you can see here, the objectClass inetOrgPerson appears twice. This is for all users.

When I execute this: ldapsearch -b "dc=example,dc=org" "(cn=user1)" the result is returned in milliseconds which leads me to believe that there should be a way to tell OpenLDAP server to always search based on CN.

Mm, this was a long post/question(s). So any comments on the schema, parent values, or why the objectClasses are displayed twice, or maybe some guidance into optimizing this are welcomed.

Thanks

6
  • To my understanding, it is not OpenLDAP server searching based on CN, but the application wanted to authenticate/authorise. So to change a search base (like you do with ldapsearch -b), you should check search base setting of that application, and not of OpenLDAP server. Aug 1, 2014 at 8:35
  • I'm sorry, which application? I did not mention anything about any other application in the post other than slapd and ldapsearch.
    – Nic
    Aug 1, 2014 at 22:11
  • As I understood, you have MySQL database, and MySQL database users are authenticated through OpenLDAP. So, when a user logins to MySQL, MySQL forwards the request to OpenLDAP. And for this MySQL probably uses PAM, which by default searches through the entire LDAP tree. However, this behaviour could be changed. For PAM, it could be changed in LDAP settings (if you use ldap.conf, there is pam_groupdn directive: freebsd.org/doc/en/articles/ldap-auth/article.html#client). For any other application (not MySQL), it often could be changed in the auth plugin settings of that application. Aug 3, 2014 at 19:49
  • Maybe I started the post a bit off. MySQL is used as a backend, hence the compiler option of --enable-sql. Open ldap checks the credentials against MySQL and not the other way around.
    – Nic
    Aug 3, 2014 at 20:29
  • Sorry, I cannot get your point. I checked what this option means here (wingfoss.com/content/…). As I understand, you indeed should have one MySQL user for LDAP to be able to write the data into MySQL. So, OpenLDAP stores the data in the MySQL database. However, if you add more users to the OpenLDAP directory, they do not become MySQL users automatically, OpenLDAP just stores information about that new users un the database. To allow these users to login, MySQL should be set up to check credentials through OpenLDAP, not vice versa. Aug 4, 2014 at 8:29

0

You must log in to answer this question.

Browse other questions tagged .