|
|
905b4d |
From 68f94d995142fc1aadf278be2f6816566208e189 Mon Sep 17 00:00:00 2001
|
|
|
905b4d |
From: Sumit Bose <sbose@redhat.com>
|
|
|
905b4d |
Date: Wed, 12 Nov 2014 12:43:23 +0100
|
|
|
905b4d |
Subject: [PATCH 113/115] sysdb: add sysdb_delete_view_tree()
|
|
|
905b4d |
|
|
|
905b4d |
---
|
|
|
905b4d |
src/db/sysdb.h | 2 +
|
|
|
905b4d |
src/db/sysdb_views.c | 34 +++++++++++++++++
|
|
|
905b4d |
src/tests/cmocka/test_sysdb_views.c | 74 +++++++++++++++++++++++++++++++++++++
|
|
|
905b4d |
3 files changed, 110 insertions(+)
|
|
|
905b4d |
|
|
|
905b4d |
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
|
|
|
905b4d |
index 7a51117f439dc54ded3433c230d2d262a4d660dc..a3ffa7b759e8aa16fc8a60cb01c6f0cb49278cc0 100644
|
|
|
905b4d |
--- a/src/db/sysdb.h
|
|
|
905b4d |
+++ b/src/db/sysdb.h
|
|
|
905b4d |
@@ -444,6 +444,8 @@ errno_t sysdb_update_view_name(struct sysdb_ctx *sysdb, const char *view_name);
|
|
|
905b4d |
errno_t sysdb_get_view_name(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
|
|
|
905b4d |
char **view_name);
|
|
|
905b4d |
|
|
|
905b4d |
+errno_t sysdb_delete_view_tree(struct sysdb_ctx *sysdb, const char *view_name);
|
|
|
905b4d |
+
|
|
|
905b4d |
errno_t sysdb_apply_default_override(struct sss_domain_info *domain,
|
|
|
905b4d |
struct sysdb_attrs *override_attrs,
|
|
|
905b4d |
struct ldb_dn *obj_dn);
|
|
|
905b4d |
diff --git a/src/db/sysdb_views.c b/src/db/sysdb_views.c
|
|
|
905b4d |
index 27b58701fe0f9a4f545df5e4bfb884c04517d0d3..e17321455ad2ac4e4f17094f83c482d95bb00d8b 100644
|
|
|
905b4d |
--- a/src/db/sysdb_views.c
|
|
|
905b4d |
+++ b/src/db/sysdb_views.c
|
|
|
905b4d |
@@ -180,6 +180,40 @@ done:
|
|
|
905b4d |
return ret;
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+errno_t sysdb_delete_view_tree(struct sysdb_ctx *sysdb, const char *view_name)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ struct ldb_dn *dn;
|
|
|
905b4d |
+ TALLOC_CTX *tmp_ctx;
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ tmp_ctx = talloc_new(NULL);
|
|
|
905b4d |
+ if (tmp_ctx == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
|
|
|
905b4d |
+ return ENOMEM;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_VIEW_SEARCH_BASE,
|
|
|
905b4d |
+ view_name);
|
|
|
905b4d |
+ if (dn == NULL) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_new_fmt failed.\n");
|
|
|
905b4d |
+ ret = EIO;
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_delete_recursive(sysdb, dn, true);
|
|
|
905b4d |
+ if (ret != EOK) {
|
|
|
905b4d |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_delete_recursive failed.\n");
|
|
|
905b4d |
+ goto done;
|
|
|
905b4d |
+ }
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = EOK;
|
|
|
905b4d |
+
|
|
|
905b4d |
+done:
|
|
|
905b4d |
+ talloc_free(tmp_ctx);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ return ret;
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
static errno_t
|
|
|
905b4d |
add_name_and_aliases_for_name_override(struct sss_domain_info *domain,
|
|
|
905b4d |
struct sysdb_attrs *attrs,
|
|
|
905b4d |
diff --git a/src/tests/cmocka/test_sysdb_views.c b/src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
index 0dc51443b406673f131cc69be4d781f7c49e538c..6be28e624d102060121f9afa91b282f7e8620676 100644
|
|
|
905b4d |
--- a/src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
+++ b/src/tests/cmocka/test_sysdb_views.c
|
|
|
905b4d |
@@ -30,10 +30,22 @@
|
|
|
905b4d |
|
|
|
905b4d |
#include "tests/cmocka/common_mock.h"
|
|
|
905b4d |
#include "providers/ipa/ipa_id.h"
|
|
|
905b4d |
+#include "db/sysdb_private.h" /* for sysdb->ldb member */
|
|
|
905b4d |
|
|
|
905b4d |
#define TESTS_PATH "tests_sysdb_views"
|
|
|
905b4d |
#define TEST_CONF_FILE "tests_conf.ldb"
|
|
|
905b4d |
|
|
|
905b4d |
+#define TEST_ANCHOR_PREFIX ":ANCHOR:"
|
|
|
905b4d |
+#define TEST_VIEW_NAME "test view"
|
|
|
905b4d |
+#define TEST_VIEW_CONTAINER "cn=" TEST_VIEW_NAME ",cn=views,cn=sysdb"
|
|
|
905b4d |
+#define TEST_USER_NAME "test_user"
|
|
|
905b4d |
+#define TEST_USER_UID 1234
|
|
|
905b4d |
+#define TEST_USER_GID 5678
|
|
|
905b4d |
+#define TEST_USER_GECOS "Gecos field"
|
|
|
905b4d |
+#define TEST_USER_HOMEDIR "/home/home"
|
|
|
905b4d |
+#define TEST_USER_SHELL "/bin/shell"
|
|
|
905b4d |
+#define TEST_USER_SID "S-1-2-3-4"
|
|
|
905b4d |
+
|
|
|
905b4d |
struct sysdb_test_ctx {
|
|
|
905b4d |
struct sysdb_ctx *sysdb;
|
|
|
905b4d |
struct confdb_ctx *confdb;
|
|
|
905b4d |
@@ -219,6 +231,66 @@ void test_split_ipa_anchor(void **state)
|
|
|
905b4d |
assert_string_equal(uuid, "def");
|
|
|
905b4d |
}
|
|
|
905b4d |
|
|
|
905b4d |
+void test_sysdb_delete_view_tree(void **state)
|
|
|
905b4d |
+{
|
|
|
905b4d |
+ int ret;
|
|
|
905b4d |
+ struct ldb_message *msg;
|
|
|
905b4d |
+ struct ldb_message **msgs = NULL;
|
|
|
905b4d |
+ struct sysdb_attrs *attrs;
|
|
|
905b4d |
+ size_t count;
|
|
|
905b4d |
+ struct ldb_dn *views_dn;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ struct sysdb_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
905b4d |
+ struct sysdb_test_ctx);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ test_ctx->domain->mpg = false;
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_update_view_name(test_ctx->domain->sysdb, TEST_VIEW_NAME);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_store_user(test_ctx->domain, TEST_USER_NAME, NULL,
|
|
|
905b4d |
+ TEST_USER_UID, TEST_USER_GID, TEST_USER_GECOS,
|
|
|
905b4d |
+ TEST_USER_HOMEDIR, TEST_USER_SHELL, NULL, NULL, NULL,
|
|
|
905b4d |
+ 0,0);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_search_user_by_name(test_ctx, test_ctx->domain, TEST_USER_NAME,
|
|
|
905b4d |
+ NULL, &msg;;
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+ assert_non_null(msg);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ attrs = sysdb_new_attrs(test_ctx);
|
|
|
905b4d |
+ assert_non_null(attrs);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_attrs_add_string(attrs, SYSDB_OVERRIDE_ANCHOR_UUID,
|
|
|
905b4d |
+ TEST_ANCHOR_PREFIX TEST_USER_SID);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_store_override(test_ctx->domain, TEST_VIEW_NAME,
|
|
|
905b4d |
+ SYSDB_MEMBER_USER, attrs, msg->dn);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ views_dn = ldb_dn_new(test_ctx, test_ctx->domain->sysdb->ldb,
|
|
|
905b4d |
+ SYSDB_TMPL_VIEW_BASE);
|
|
|
905b4d |
+ assert_non_null(views_dn);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
|
|
|
905b4d |
+ LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+ assert_true(count > 1);
|
|
|
905b4d |
+ assert_non_null(msgs);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_delete_view_tree(test_ctx->domain->sysdb, TEST_VIEW_NAME);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+
|
|
|
905b4d |
+ ret = sysdb_search_entry(test_ctx, test_ctx->domain->sysdb, views_dn,
|
|
|
905b4d |
+ LDB_SCOPE_SUBTREE, NULL, NULL, &count, &msgs);
|
|
|
905b4d |
+ assert_int_equal(ret, EOK);
|
|
|
905b4d |
+ assert_int_equal(count, 1);
|
|
|
905b4d |
+ assert_true(ldb_dn_compare(views_dn, msgs[0]->dn) == 0);
|
|
|
905b4d |
+
|
|
|
905b4d |
+}
|
|
|
905b4d |
+
|
|
|
905b4d |
int main(int argc, const char *argv[])
|
|
|
905b4d |
{
|
|
|
905b4d |
int rv;
|
|
|
905b4d |
@@ -238,6 +310,8 @@ int main(int argc, const char *argv[])
|
|
|
905b4d |
test_sysdb_setup, test_sysdb_teardown),
|
|
|
905b4d |
unit_test_setup_teardown(test_split_ipa_anchor,
|
|
|
905b4d |
test_sysdb_setup, test_sysdb_teardown),
|
|
|
905b4d |
+ unit_test_setup_teardown(test_sysdb_delete_view_tree,
|
|
|
905b4d |
+ test_sysdb_setup, test_sysdb_teardown),
|
|
|
905b4d |
};
|
|
|
905b4d |
|
|
|
905b4d |
/* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
905b4d |
--
|
|
|
905b4d |
1.9.3
|
|
|
905b4d |
|