diff options
| author | Pavel Březina <pbrezina@redhat.com> | 2015-05-06 12:16:46 +0200 |
|---|---|---|
| committer | Jakub Hrozek <jhrozek@redhat.com> | 2015-10-08 19:56:26 +0200 |
| commit | 28ebfa4373d1e7ce45b5d70a3619df1c074a661e (patch) | |
| tree | 0aafa2697dfa3a29b9b1b3b4103fda964914ce03 /src/db/sysdb_ops.c | |
| parent | d8125f0e0d38c6939887a0849a44859d6c498c57 (diff) | |
| download | sssd-28ebfa4373d1e7ce45b5d70a3619df1c074a661e.tar.gz sssd-28ebfa4373d1e7ce45b5d70a3619df1c074a661e.tar.xz sssd-28ebfa4373d1e7ce45b5d70a3619df1c074a661e.zip | |
cache_req: add support for UPN
Reviewed-by: Sumit Bose <sbose@redhat.com>
Diffstat (limited to 'src/db/sysdb_ops.c')
| -rw-r--r-- | src/db/sysdb_ops.c | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 38e70219..aedf78d2 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -474,28 +474,28 @@ int sysdb_search_user_by_sid_str(TALLOC_CTX *mem_ctx, sid_str, attrs, msg); } -int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx, - struct sss_domain_info *domain, - const char *upn, - const char **attrs, - struct ldb_message **msg) +int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + const char *upn, + const char **attrs, + struct ldb_result **out_res) { TALLOC_CTX *tmp_ctx; - const char *def_attrs[] = { SYSDB_NAME, SYSDB_UPN, SYSDB_CANONICAL_UPN, - NULL }; - struct ldb_message **msgs = NULL; - struct ldb_dn *basedn; - size_t msgs_count = 0; + struct ldb_result *res; + struct ldb_dn *base_dn; char *filter; int ret; + const char *def_attrs[] = { SYSDB_NAME, SYSDB_UPN, SYSDB_CANONICAL_UPN, + NULL }; tmp_ctx = talloc_new(NULL); if (tmp_ctx == NULL) { - return ENOMEM; + ret = ENOMEM; + goto done; } - basedn = sysdb_user_base_dn(tmp_ctx, domain); - if (basedn == NULL) { + base_dn = sysdb_user_base_dn(tmp_ctx, domain); + if (base_dn == NULL) { ret = ENOMEM; goto done; } @@ -506,29 +506,64 @@ int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx, goto done; } - ret = sysdb_search_entry(tmp_ctx, domain->sysdb, basedn, LDB_SCOPE_SUBTREE, - filter, attrs?attrs:def_attrs, &msgs_count, - &msgs); + ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res, + base_dn, LDB_SCOPE_SUBTREE, attrs ? attrs : def_attrs, + filter); if (ret != EOK) { + ret = sysdb_error_to_errno(ret); goto done; } - if (msgs_count > 1) { + if (res->count == 0) { + /* set result anyway */ + *out_res = talloc_steal(mem_ctx, res); + ret = ENOENT; + goto done; + } else if (res->count > 1) { DEBUG(SSSDBG_OP_FAILURE, "Search for upn [%s] returns more than one result.\n", upn); ret = EINVAL; goto done; } - *msg = talloc_steal(mem_ctx, msgs[0]); + *out_res = talloc_steal(mem_ctx, res); + ret = EOK; done: + talloc_zfree(tmp_ctx); + return ret; +} + +int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx, + struct sss_domain_info *domain, + const char *upn, + const char **attrs, + struct ldb_message **msg) +{ + TALLOC_CTX *tmp_ctx; + struct ldb_result *res; + errno_t ret; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_search_user_by_upn_res(tmp_ctx, domain, upn, attrs, &res); if (ret == ENOENT) { DEBUG(SSSDBG_TRACE_FUNC, "No entry with upn [%s] found.\n", upn); + goto done; } else if (ret != EOK) { DEBUG(SSSDBG_OP_FAILURE, "Error: %d (%s)\n", ret, strerror(ret)); + goto done; } + *msg = talloc_steal(mem_ctx, res->msgs[0]); + + ret = EOK; + +done: talloc_zfree(tmp_ctx); return ret; } |
