diff options
-rw-r--r-- | src/db/sysdb_ops.c | 19 | ||||
-rw-r--r-- | src/tests/sysdb-tests.c | 23 |
2 files changed, 36 insertions, 6 deletions
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 710a23b0..ff8fb008 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -248,6 +248,8 @@ int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx, struct ldb_message **msgs = NULL; struct ldb_dn *basedn; size_t msgs_count = 0; + char *sanitized_name; + char *filter; int ret; tmp_ctx = talloc_new(NULL); @@ -255,13 +257,26 @@ int sysdb_search_user_by_name(TALLOC_CTX *mem_ctx, return ENOMEM; } - basedn = sysdb_user_dn(sysdb, tmp_ctx, domain, name); + basedn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, + SYSDB_TMPL_USER_BASE, domain->name); if (!basedn) { ret = ENOMEM; goto done; } - ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_BASE, NULL, + ret = sss_filter_sanitize(tmp_ctx, name, &sanitized_name); + if (ret != EOK) { + goto done; + } + + filter = talloc_asprintf(tmp_ctx, SYSDB_PWNAM_FILTER, sanitized_name, + sanitized_name); + if (!filter) { + ret = ENOMEM; + goto done; + } + + ret = sysdb_search_entry(tmp_ctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter, attrs?attrs:def_attrs, &msgs_count, &msgs); if (ret) { goto done; diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index 308230f8..a4ca92a6 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -4535,6 +4535,9 @@ START_TEST(test_sysdb_subdomain_store_user) struct ldb_result *results = NULL; struct ldb_dn *base_dn = NULL; struct ldb_dn *check_dn = NULL; + const char *attrs[] = { SYSDB_NAME, SYSDB_NAME_ALIAS, NULL }; + struct sysdb_attrs *user_attrs; + struct ldb_message *msg; ret = setup_sysdb_tests(&test_ctx); fail_if(ret != EOK, "Could not set up the test"); @@ -4552,21 +4555,27 @@ START_TEST(test_sysdb_subdomain_store_user) fail_unless(ret == EOK, "sysdb_update_subdomains failed with [%d][%s]", ret, strerror(ret)); - ret = sysdb_store_user(subdomain->sysdb, subdomain, "subdomuser", + user_attrs = sysdb_new_attrs(test_ctx); + fail_unless(user_attrs != NULL, "sysdb_new_attrs failed"); + + ret = sysdb_attrs_add_string(user_attrs, SYSDB_NAME_ALIAS, "subdomuser"); + fail_unless(ret == EOK, "sysdb_store_user failed."); + + ret = sysdb_store_user(subdomain->sysdb, subdomain, "SubDomUser", NULL, 12345, 0, "Sub Domain User", "/home/subdomuser", "/bin/bash", - NULL, NULL, NULL, -1, 0); + NULL, user_attrs, NULL, -1, 0); fail_unless(ret == EOK, "sysdb_store_user failed."); base_dn =ldb_dn_new(test_ctx, test_ctx->sysdb->ldb, "cn=sysdb"); fail_unless(base_dn != NULL); check_dn = ldb_dn_new(test_ctx, test_ctx->sysdb->ldb, - "name=subdomuser,cn=users,cn=test.sub,cn=sysdb"); + "name=SubDomUser,cn=users,cn=test.sub,cn=sysdb"); fail_unless(check_dn != NULL); ret = ldb_search(test_ctx->sysdb->ldb, test_ctx, &results, base_dn, - LDB_SCOPE_SUBTREE, NULL, "name=subdomuser"); + LDB_SCOPE_SUBTREE, NULL, "name=SubDomUser"); fail_unless(ret == EOK, "ldb_search failed."); fail_unless(results->count == 1, "Unexpected number of results, " "expected [%d], got [%d]", @@ -4574,6 +4583,12 @@ START_TEST(test_sysdb_subdomain_store_user) fail_unless(ldb_dn_compare(results->msgs[0]->dn, check_dn) == 0, "Unexpedted DN returned"); + /* Subdomains are case-insensitive. Test that the lowercased name + * can be found, too */ + ret = sysdb_search_user_by_name(test_ctx, test_ctx->sysdb, subdomain, + "subdomuser", attrs, &msg); + fail_unless(ret == EOK, "sysdb_search_user_by_name failed."); + ret = sysdb_delete_user(subdomain->sysdb, subdomain, "subdomuser", 0); fail_unless(ret == EOK, "sysdb_delete_user failed [%d][%s].", ret, strerror(ret)); |