Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/db/sysdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,12 +875,6 @@ int sysdb_getpwuid(TALLOC_CTX *mem_ctx,
uid_t uid,
struct ldb_result **res);

int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
const char *upn,
struct ldb_result **res);

int sysdb_enumpwent(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result **res);
Expand Down Expand Up @@ -1070,6 +1064,13 @@ int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx,
const char **attrs,
struct ldb_result **out_res);

int sysdb_search_user_by_upn_with_view_res(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
const char *upn,
const char **attrs,
struct ldb_result **out_res);

int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
Expand Down
37 changes: 37 additions & 0 deletions src/db/sysdb_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,43 @@ int sysdb_search_user_by_upn_res(TALLOC_CTX *mem_ctx,
return ret;
}

int sysdb_search_user_by_upn_with_view_res(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
const char *upn,
const char **attrs,
struct ldb_result **out_res)
{
int ret;
struct ldb_result *orig_obj = NULL;

/* The UPN or the email address cannot be overwritten and we can search
* directly the original object. */
ret = sysdb_search_user_by_upn_res(mem_ctx, domain, domain_scope, upn,
attrs, &orig_obj);
if (ret != EOK) {
DEBUG(ret == ENOENT ? SSSDBG_MINOR_FAILURE : SSSDBG_OP_FAILURE,
"Failed to find UPN [%s] in cache [%d][%s].\n",
upn, ret, sss_strerror(ret));
return ret;
}

/* If there are views we have to check if override values must be added to
* the original object. */
if (DOM_HAS_VIEWS(domain)) {
ret = sysdb_add_overrides_to_object(domain, orig_obj->msgs[0], NULL,
attrs);
if (ret != EOK && ret != ENOENT) {
talloc_free(orig_obj);
DEBUG(SSSDBG_OP_FAILURE, "sysdb_add_overrides_to_object failed.\n");
return ret;
}
}

*out_res = orig_obj;
return ret;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The function may incorrectly return ENOENT if sysdb_add_overrides_to_object returns it, which happens when no override is found for a user. This would signal to the caller that the user was not found, even though the original user object was successfully retrieved. The function should return EOK if the user is found, regardless of whether overrides exist.

    return EOK;

}

int sysdb_search_user_by_upn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
Expand Down
30 changes: 0 additions & 30 deletions src/db/sysdb_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,36 +598,6 @@ static char *enum_filter(TALLOC_CTX *mem_ctx,
return filter;
}

int sysdb_getpwupn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
bool domain_scope,
const char *upn,
struct ldb_result **_res)
{
TALLOC_CTX *tmp_ctx;
struct ldb_result *res;
static const char *attrs[] = SYSDB_PW_ATTRS;
errno_t ret;

tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
return ENOMEM;
}

ret = sysdb_search_user_by_upn_res(tmp_ctx, domain, domain_scope, upn, attrs, &res);
if (ret != EOK && ret != ENOENT) {
DEBUG(SSSDBG_OP_FAILURE, "sysdb_search_user_by_upn_res() failed.\n");
goto done;
}

*_res = talloc_steal(mem_ctx, res);

done:
talloc_free(tmp_ctx);
return ret;
}

errno_t sysdb_search_ts_matches(TALLOC_CTX *mem_ctx,
struct sysdb_ctx *sysdb,
const char *attrs[],
Expand Down
15 changes: 8 additions & 7 deletions src/responder/common/cache_req/plugins/cache_req_user_by_upn.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ cache_req_user_by_upn_lookup(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
struct ldb_result **_result)
{
if (data->attrs == NULL) {
return sysdb_getpwupn(mem_ctx, domain, true, data->name.lookup, _result);
}

return sysdb_search_user_by_upn_res(mem_ctx, domain, true,
data->name.lookup, data->attrs,
_result);
static const char *def_attrs[] = SYSDB_PW_ATTRS;

return sysdb_search_user_by_upn_with_view_res(mem_ctx, domain, true,
data->name.lookup,
data->attrs == NULL
? def_attrs
: data->attrs,
_result);
}

static struct tevent_req *
Expand Down
6 changes: 0 additions & 6 deletions src/tests/cmocka/test_sysdb_ts_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,12 +1303,6 @@ static void test_user_byupn(void **state)
TEST_NOW_2);
assert_int_equal(ret, EOK);

ret = sysdb_getpwupn(test_ctx, test_ctx->tctx->dom, false, TEST_USER_UPN, &res);
assert_int_equal(ret, EOK);
assert_int_equal(res->count, 1);
assert_ts_attrs_res(res, TEST_NOW_2 + TEST_CACHE_TIMEOUT, TEST_NOW_2);
talloc_free(res);

ret = sysdb_search_user_by_upn_res(test_ctx, test_ctx->tctx->dom,
false, TEST_USER_UPN, pw_fetch_attrs,
&res);
Expand Down
Loading
Loading