|
|
905b4d |
From 1f5796f2ab0a848712a7f5bc85c9f7c2f22a8a0f Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
Date: Wed, 5 Nov 2014 21:01:08 +0100
|
|
|
905b4d |
Subject: [PATCH 095/104] sysdb: add sysdb_search_object_by_uuid()
|
|
|
905b4d |
|
|
|
905b4d |
Related to https://fedorahosted.org/sssd/ticket/2481
|
|
|
905b4d |
|
|
|
905b4d |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
905b4d |
---
|
|
|
905b4d |
src/db/sysdb.h | 7 +++++
|
|
|
905b4d |
src/db/sysdb_ops.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
905b4d |
src/tests/sysdb-tests.c | 51 ++++++++++++++++++++++++++++++++
|
|
|
905b4d |
3 files changed, 135 insertions(+)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
|
|
|
905b4d |
index f582f6a516e43a453741acacbe3ca6957e23fc37..7a51117f439dc54ded3433c230d2d262a4d660dc 100644
|
|
|
905b4d |
--- a/src/db/sysdb.h
|
|
|
905b4d |
+++ b/src/db/sysdb.h
|
|
|
905b4d |
@@ -185,6 +185,7 @@
|
|
|
905b4d |
#define SYSDB_NETGR_TRIPLES_FILTER "(|("SYSDB_NAME_ALIAS"=%s)("SYSDB_NAME"=%s)("SYSDB_NAME_ALIAS"=%s)("SYSDB_MEMBEROF"=%s))"
|
|
|
905b4d |
|
|
|
905b4d |
#define SYSDB_SID_FILTER "(&(|("SYSDB_UC")("SYSDB_GC"))("SYSDB_SID_STR"=%s))"
|
|
|
905b4d |
+#define SYSDB_UUID_FILTER "(&(|("SYSDB_UC")("SYSDB_GC"))("SYSDB_UUID"=%s))"
|
|
|
905b4d |
|
|
|
905b4d |
#define SYSDB_HAS_ENUMERATED "has_enumerated"
|
|
|
905b4d |
|
|
|
905b4d |
@@ -1030,6 +1031,12 @@ errno_t sysdb_search_object_by_sid(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
const char **attrs,
|
|
|
905b4d |
struct ldb_result **msg);
|
|
|
905b4d |
|
|
|
905b4d |
+errno_t sysdb_search_object_by_uuid(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
+ struct sss_domain_info *domain,
|
|
|
905b4d |
+ const char *uuid_str,
|
|
|
905b4d |
+ const char **attrs,
|
|
|
905b4d |
+ struct ldb_result **res);
|
|
|
905b4d |
+
|
|
|
905b4d |
/* === Functions related to GPOs === */
|
|
|
905b4d |
|
|
|
905b4d |
#define SYSDB_GPO_CONTAINER "cn=gpos,cn=ad,cn=custom"
|
|
|
905b4d |
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
|
|
|
905b4d |
index c88ff9b4bf39c649bc7993f3ed56729b7bfde310..998046a2ca1c746b2032f430e5f9c4a7151e1dbc 100644
|
|
|
905b4d |
--- a/src/db/sysdb_ops.c
|
|
|
905b4d |
+++ b/src/db/sysdb_ops.c
|
|
|
905b4d |
@@ -3499,12 +3499,79 @@ done:
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+static errno_t sysdb_search_object_by_str_attr(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
+ struct sss_domain_info *domain,
|
|
|
905b4d |
+ const char *filter_tmpl,
|
|
|
905b4d |
+ const char *str,
|
|
|
905b4d |
+ const char **attrs,
|
|
|
905b4d |
+ struct ldb_result **_res)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
+ const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, SYSDB_GIDNUM,
|
|
|
905b4d |
+ ORIGINALAD_PREFIX SYSDB_NAME,
|
|
|
905b4d |
+ SYSDB_OBJECTCLASS, NULL };
|
|
|
905b4d |
+ struct ldb_dn *basedn;
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+ struct ldb_result *res = NULL;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_ctx = talloc_new(NULL);
|
|
|
905b4d |
+ if (!tmp_ctx) {
|
|
|
905b4d |
+ return ENOMEM;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb, SYSDB_DOM_BASE,
|
|
|
905b4d |
+ domain->name);
|
|
|
905b4d |
+ if (basedn == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
|
|
|
905b4d |
+ ret = ENOMEM;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = ldb_search(domain->sysdb->ldb, tmp_ctx, &res,
|
|
|
905b4d |
+ basedn, LDB_SCOPE_SUBTREE, attrs?attrs:def_attrs,
|
|
|
905b4d |
+ filter_tmpl, str);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ ret = sysdb_error_to_errno(ret);
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "ldb_search failed.\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ if (res->count > 1) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_CRIT_FAILURE, "Search for [%s] with filter [%s] " \
|
|
|
905b4d |
+ "returned more than one object.\n",
|
|
|
905b4d |
+ str, filter_tmpl);
|
|
|
905b4d |
+ ret = EINVAL;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ } else if (res->count == 0) {
|
|
|
905b4d |
+ ret = ENOENT;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ *_res = talloc_steal(mem_ctx, res);
|
|
|
905b4d |
+
|
|
|
905b4d |
+done:
|
|
|
905b4d |
+ if (ret == ENOENT) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_TRACE_FUNC, "No such entry.\n");
|
|
|
905b4d |
+ } else if (ret) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "Error: %d (%s)\n", ret, strerror(ret));
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ talloc_zfree(tmp_ctx);
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
errno_t sysdb_search_object_by_sid(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
struct sss_domain_info *domain,
|
|
|
905b4d |
const char *sid_str,
|
|
|
905b4d |
const char **attrs,
|
|
|
905b4d |
struct ldb_result **msg)
|
|
|
905b4d |
{
|
|
|
905b4d |
+/* TODO: use
|
|
|
905b4d |
+ return sysdb_search_object_by_str_attr(mem_ctx, domain, SYSDB_SID_FILTER,
|
|
|
905b4d |
+ sid_str, attrs, res);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ when verified that all callers can handle ENOENT correctly. */
|
|
|
905b4d |
+
|
|
|
905b4d |
TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
const char *def_attrs[] = { SYSDB_NAME, SYSDB_UIDNUM, SYSDB_GIDNUM,
|
|
|
905b4d |
ORIGINALAD_PREFIX SYSDB_NAME,
|
|
|
905b4d |
@@ -3553,3 +3620,13 @@ done:
|
|
|
905b4d |
talloc_zfree(tmp_ctx);
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
+
|
|
|
905b4d |
+errno_t sysdb_search_object_by_uuid(TALLOC_CTX *mem_ctx,
|
|
|
905b4d |
+ struct sss_domain_info *domain,
|
|
|
905b4d |
+ const char *uuid_str,
|
|
|
905b4d |
+ const char **attrs,
|
|
|
905b4d |
+ struct ldb_result **res)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ return sysdb_search_object_by_str_attr(mem_ctx, domain, SYSDB_UUID_FILTER,
|
|
|
905b4d |
+ uuid_str, attrs, res);
|
|
|
905b4d |
+}
|
|
|
905b4d |
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
|
|
|
905b4d |
index e01ddf4782c0a5a557f39d1adc2efd74b6234461..e9618727d4f8f4c544b28cce9d98b82000de3aad 100644
|
|
|
905b4d |
--- a/src/tests/sysdb-tests.c
|
|
|
905b4d |
+++ b/src/tests/sysdb-tests.c
|
|
|
905b4d |
@@ -5026,6 +5026,54 @@ START_TEST(test_sysdb_search_sid_str)
|
|
|
905b4d |
}
|
|
|
905b4d |
END_TEST
|
|
|
905b4d |
|
|
|
905b4d |
+START_TEST(test_sysdb_search_object_by_uuid)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ errno_t ret;
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx;
|
|
|
905b4d |
+ struct ldb_result *res;
|
|
|
905b4d |
+ struct sysdb_attrs *attrs = NULL;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ /* Setup */
|
|
|
905b4d |
+ ret = setup_sysdb_tests(&test_ctx);
|
|
|
905b4d |
+ fail_if(ret != EOK, "Could not set up the test");
|
|
|
905b4d |
+
|
|
|
905b4d |
+ attrs = sysdb_new_attrs(test_ctx);
|
|
|
905b4d |
+ fail_unless(attrs != NULL, "sysdb_new_attrs failed");
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_UUID,
|
|
|
905b4d |
+ "11111111-2222-3333-4444-555555555555");
|
|
|
905b4d |
+ fail_unless(ret == EOK, "sysdb_attrs_add_string failed with [%d][%s].",
|
|
|
905b4d |
+ ret, strerror(ret));
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_add_user(test_ctx->domain, "UUIDuser",
|
|
|
905b4d |
+ 123456, 0, "UUID user", "/home/uuiduser", "/bin/bash",
|
|
|
905b4d |
+ NULL, attrs, 0, 0);
|
|
|
905b4d |
+ fail_unless(ret == EOK, "sysdb_add_user failed with [%d][%s].",
|
|
|
905b4d |
+ ret, strerror(ret));
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_search_object_by_uuid(test_ctx, test_ctx->domain,
|
|
|
905b4d |
+ "11111111-2222-3333-4444-555555555556",
|
|
|
905b4d |
+ NULL, &res;;
|
|
|
905b4d |
+ fail_unless(ret == ENOENT,
|
|
|
905b4d |
+ "Unexpected return code from sysdb_search_object_by_uuid for "
|
|
|
905b4d |
+ "missing object, expected [%d], got [%d].", ENOENT, ret);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_search_object_by_uuid(test_ctx, test_ctx->domain,
|
|
|
905b4d |
+ "11111111-2222-3333-4444-555555555555",
|
|
|
905b4d |
+ NULL, &res;;
|
|
|
905b4d |
+ fail_unless(ret == EOK, "sysdb_search_object_by_uuid failed with [%d][%s].",
|
|
|
905b4d |
+ ret, strerror(ret));
|
|
|
905b4d |
+ fail_unless(res->count == 1, "Unexpected number of results, " \
|
|
|
905b4d |
+ "expected [%u], get [%u].", 1, res->count);
|
|
|
905b4d |
+ fail_unless(strcmp(ldb_msg_find_attr_as_string(res->msgs[0],
|
|
|
905b4d |
+ SYSDB_NAME, ""),
|
|
|
905b4d |
+ "UUIDuser") == 0, "Unexpected object found, " \
|
|
|
905b4d |
+ "expected [%s], got [%s].", "UUIDuser",
|
|
|
905b4d |
+ ldb_msg_find_attr_as_string(res->msgs[0],SYSDB_NAME, ""));
|
|
|
905b4d |
+
|
|
|
905b4d |
+ talloc_free(test_ctx);
|
|
|
905b4d |
+}
|
|
|
905b4d |
+END_TEST
|
|
|
905b4d |
|
|
|
905b4d |
START_TEST(test_sysdb_subdomain_create)
|
|
|
905b4d |
{
|
|
|
905b4d |
@@ -6090,6 +6138,9 @@ Suite *create_sysdb_suite(void)
|
|
|
905b4d |
/* Test SID string searches */
|
|
|
905b4d |
tcase_add_test(tc_sysdb, test_sysdb_search_sid_str);
|
|
|
905b4d |
|
|
|
905b4d |
+ /* Test UUID string searches */
|
|
|
905b4d |
+ tcase_add_test(tc_sysdb, test_sysdb_search_object_by_uuid);
|
|
|
905b4d |
+
|
|
|
905b4d |
/* Test canonicalizing names */
|
|
|
905b4d |
tcase_add_test(tc_sysdb, test_sysdb_get_real_name);
|
|
|
905b4d |
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|