From aa80e585f843b754b6c0b4945472ebd6cfab0cf3 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Thu, 20 Aug 2009 14:02:26 +0200 Subject: 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 ac19dcc62..64a07fe78 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 e62711a2e..2853ba1e7 100644 --- a/server/db/sysdb_ops.c +++ b/server/db/sysdb_ops.c @@ -2495,6 +2495,23 @@ struct tevent_req *sysdb_store_user_send(TALLOC_CTX *mem_ctx, const char *gecos, 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; @@ -2512,7 +2529,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); @@ -2677,6 +2694,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 b71b61f29..7c6cd2c2a 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); -- cgit