[SSSD] [PATCH] store additional LDAP attributes

Sumit Bose sbose at redhat.com
Thu Aug 20 12:15:26 UTC 2009


Hi,

with this patch the LDAP backend can store two additional attributes to
the sysdb if available. The original DN is used by the authentication
part of the LDAP backend to bind to the LDAP server. The user principle
name (UPN) can be used by the kerberos backend to get the TGT. Both are
necessary if the DN or UPN cannot be generated from the unix user name,
which is often the case if you are using AD.

bye,
Sumit
-------------- next part --------------
>From 3bd34d667d440dcf67120956d1f8ef9c05f8431c Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 20 Aug 2009 14:02:26 +0200
Subject: [PATCH] store additional LDAP attributes

If available the original DN and the user principle will be stored
in sysdb.
---
 server/db/sysdb.h                  |   13 +++++++++
 server/db/sysdb_ops.c              |   23 ++++++++++++++++-
 server/providers/ldap/sdap_async.c |   49 +++++++++++++++++++++++++++++++++---
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/server/db/sysdb.h b/server/db/sysdb.h
index ac19dcc..64a07fe 100644
--- a/server/db/sysdb.h
+++ b/server/db/sysdb.h
@@ -450,6 +450,19 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx,
                                          const char *shell);
 int sysdb_store_user_recv(struct tevent_req *req);
 
+struct tevent_req *sysdb_store_user_with_attrs_send(TALLOC_CTX *mem_ctx,
+                                                struct tevent_context *ev,
+                                                struct sysdb_handle *handle,
+                                                struct sss_domain_info *domain,
+                                                const char *name,
+                                                const char *pwd,
+                                                uid_t uid, gid_t gid,
+                                                const char *gecos,
+                                                const char *homedir,
+                                                const char *shell,
+                                                struct sysdb_attrs *attrs);
+int sysdb_store_user_with_attrs_recv(struct tevent_req *req);
+
 struct tevent_req *sysdb_store_group_send(TALLOC_CTX *mem_ctx,
                                           struct tevent_context *ev,
                                           struct sysdb_handle *handle,
diff --git a/server/db/sysdb_ops.c b/server/db/sysdb_ops.c
index 687c754..e8ee5bd 100644
--- a/server/db/sysdb_ops.c
+++ b/server/db/sysdb_ops.c
@@ -2484,6 +2484,23 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx,
                                          const char *homedir,
                                          const char *shell)
 {
+    return sysdb_store_user_with_attrs_send(mem_ctx, ev, handle, domain,
+                                            name, pwd, uid, gid, gecos,
+                                            homedir, shell, NULL);
+}
+
+struct tevent_req *sysdb_store_user_with_attrs_send(TALLOC_CTX *mem_ctx,
+                                                struct tevent_context *ev,
+                                                struct sysdb_handle *handle,
+                                                struct sss_domain_info *domain,
+                                                const char *name,
+                                                const char *pwd,
+                                                uid_t uid, gid_t gid,
+                                                const char *gecos,
+                                                const char *homedir,
+                                                const char *shell,
+                                                struct sysdb_attrs *attrs)
+{
     struct tevent_req *req, *subreq;
     struct sysdb_store_user_state *state;
     int ret;
@@ -2500,7 +2517,7 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx,
     state->gecos = gecos;
     state->homedir = homedir;
     state->shell = shell;
-    state->attrs = NULL;
+    state->attrs = attrs;
 
     if (pwd && (domain->legacy_passwords || !*pwd)) {
         ret = sysdb_attrs_add_string(state->attrs, SYSDB_PWD, pwd);
@@ -2665,6 +2682,10 @@ int sysdb_store_user_recv(struct tevent_req *req)
     return sysdb_op_default_recv(req);
 }
 
+int sysdb_store_user_with_attrs_recv(struct tevent_req *req)
+{
+    return sysdb_op_default_recv(req);
+}
 
 /* =Store-Group-(Native/Legacy)-(replaces-existing-data)================== */
 
diff --git a/server/providers/ldap/sdap_async.c b/server/providers/ldap/sdap_async.c
index b71b61f..7c6cd2c 100644
--- a/server/providers/ldap/sdap_async.c
+++ b/server/providers/ldap/sdap_async.c
@@ -840,6 +840,7 @@ static struct tevent_req *sdap_save_user_send(TALLOC_CTX *memctx,
     long int l;
     uid_t uid;
     gid_t gid;
+    struct sysdb_attrs *user_attrs;
 
     req = tevent_req_create(memctx, &state, struct sdap_save_user_state);
     if (!req) return NULL;
@@ -921,11 +922,51 @@ static struct tevent_req *sdap_save_user_send(TALLOC_CTX *memctx,
     }
     gid = l;
 
+    user_attrs = sysdb_new_attrs(state);
+    if (user_attrs == NULL) {
+        ret = ENOMEM;
+        goto fail;
+    }
+
+    ret = sysdb_attrs_get_el(state->attrs, SYSDB_ORIG_DN, &el);
+    if (ret) {
+        goto fail;
+    }
+    if (el->num_values == 0) {
+        DEBUG(7, ("Original DN is not available for user [%s].\n", name));
+    } else {
+        DEBUG(7, ("Adding original DN [%s] to attributes of user [%s].\n",
+                  el->values[0].data, name));
+        ret = sysdb_attrs_add_string(user_attrs, SYSDB_ORIG_DN,
+                                     (const char *) el->values[0].data);
+        if (ret) {
+            goto fail;
+        }
+    }
+
+    ret = sysdb_attrs_get_el(state->attrs,
+                             opts->user_map[SDAP_AT_USER_PRINC].sys_name, &el);
+    if (ret) {
+        goto fail;
+    }
+    if (el->num_values == 0) {
+        DEBUG(7, ("User principle is not available for user [%s].\n", name));
+    } else {
+        DEBUG(7, ("Adding user principle [%s] to attributes of user [%s].\n",
+                  el->values[0].data, name));
+        ret = sysdb_attrs_add_string(user_attrs, SYSDB_UPN,
+                                     (const char *) el->values[0].data);
+        if (ret) {
+            goto fail;
+        }
+    }
+
     DEBUG(6, ("Storing info for user %s\n", name));
 
-    subreq = sysdb_store_user_send(state, state->ev, state->handle,
-                                   state->dom, name, pwd, uid, gid,
-                                   gecos, homedir, shell);
+    subreq = sysdb_store_user_with_attrs_send(state, state->ev, state->handle,
+                                              state->dom, name, pwd, uid, gid,
+                                              gecos, homedir, shell,
+                                              user_attrs);
     if (!subreq) {
         ret = ENOMEM;
         goto fail;
@@ -946,7 +987,7 @@ static void sdap_save_user_done(struct tevent_req *subreq)
                                                       struct tevent_req);
     int ret;
 
-    ret = sysdb_store_user_recv(subreq);
+    ret = sysdb_store_user_with_attrs_recv(subreq);
     talloc_zfree(subreq);
     if (ret) {
         tevent_req_error(req, ret);
-- 
1.6.2.5



More information about the sssd-devel mailing list