|
|
96eb28 |
From f46dc8010a7d5fbb398e282d680703e1bd5963f4 Mon Sep 17 00:00:00 2001
|
|
|
96eb28 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
96eb28 |
Date: Tue, 29 May 2018 15:33:34 +0200
|
|
|
96eb28 |
Subject: [PATCH] sysdb: add sysdb_getgrgid_attrs()
|
|
|
96eb28 |
|
|
|
96eb28 |
sysdb_getgrgid() is the only MPG aware by GID request but only supports
|
|
|
96eb28 |
a fixes set of attributes. The new call allows to add additional
|
|
|
96eb28 |
arguments.
|
|
|
96eb28 |
|
|
|
96eb28 |
Related to https://pagure.io/SSSD/sssd/issue/3748
|
|
|
96eb28 |
|
|
|
96eb28 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
96eb28 |
(cherry picked from commit 8aa56a9e8744a7611fa26a254c4f9228e919c8ed)
|
|
|
96eb28 |
---
|
|
|
96eb28 |
src/db/sysdb.h | 6 ++++++
|
|
|
96eb28 |
src/db/sysdb_ops.c | 3 +++
|
|
|
96eb28 |
src/db/sysdb_search.c | 31 ++++++++++++++++++++++++++-----
|
|
|
96eb28 |
src/tests/sysdb-tests.c | 37 +++++++++++++++++++++++++++++++++++++
|
|
|
96eb28 |
4 files changed, 72 insertions(+), 5 deletions(-)
|
|
|
96eb28 |
|
|
|
96eb28 |
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
|
|
|
96eb28 |
index 2660314a75a574d7f5625c8672e5261587056d1a..affd1c9053e43ff24c98cc8fb23eec2c4b69f955 100644
|
|
|
96eb28 |
--- a/src/db/sysdb.h
|
|
|
96eb28 |
+++ b/src/db/sysdb.h
|
|
|
96eb28 |
@@ -779,6 +779,12 @@ int sysdb_getgrgid(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
gid_t gid,
|
|
|
96eb28 |
struct ldb_result **res);
|
|
|
96eb28 |
|
|
|
96eb28 |
+int sysdb_getgrgid_attrs(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
+ struct sss_domain_info *domain,
|
|
|
96eb28 |
+ gid_t gid,
|
|
|
96eb28 |
+ const char **attrs,
|
|
|
96eb28 |
+ struct ldb_result **res);
|
|
|
96eb28 |
+
|
|
|
96eb28 |
int sysdb_enumgrent(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
struct sss_domain_info *domain,
|
|
|
96eb28 |
struct ldb_result **res);
|
|
|
96eb28 |
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
|
|
|
96eb28 |
index 024683317cab99743681db804f7026c8dbb33a38..c0d343bdabd324cbe8b9745c65c2a6e5a56321e1 100644
|
|
|
96eb28 |
--- a/src/db/sysdb_ops.c
|
|
|
96eb28 |
+++ b/src/db/sysdb_ops.c
|
|
|
96eb28 |
@@ -709,6 +709,9 @@ int sysdb_search_group_by_name(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
return sysdb_search_by_name(mem_ctx, domain, name, SYSDB_GROUP, attrs, msg);
|
|
|
96eb28 |
}
|
|
|
96eb28 |
|
|
|
96eb28 |
+/* Please note that sysdb_search_group_by_gid() is not aware of MPGs. If MPG
|
|
|
96eb28 |
+ * support is needed either the caller must handle it or sysdb_getgrgid() or
|
|
|
96eb28 |
+ * sysdb_getgrgid_attrs() should be used. */
|
|
|
96eb28 |
int sysdb_search_group_by_gid(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
struct sss_domain_info *domain,
|
|
|
96eb28 |
gid_t gid,
|
|
|
96eb28 |
diff --git a/src/db/sysdb_search.c b/src/db/sysdb_search.c
|
|
|
96eb28 |
index 9f37cbcd50a778145518c15b6146ad812a5b4fa3..3d78a38b36e65febd50e41fc1d1be29eceeb7649 100644
|
|
|
96eb28 |
--- a/src/db/sysdb_search.c
|
|
|
96eb28 |
+++ b/src/db/sysdb_search.c
|
|
|
96eb28 |
@@ -1036,24 +1036,37 @@ done:
|
|
|
96eb28 |
return ret;
|
|
|
96eb28 |
}
|
|
|
96eb28 |
|
|
|
96eb28 |
-int sysdb_getgrgid(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
- struct sss_domain_info *domain,
|
|
|
96eb28 |
- gid_t gid,
|
|
|
96eb28 |
- struct ldb_result **_res)
|
|
|
96eb28 |
+int sysdb_getgrgid_attrs(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
+ struct sss_domain_info *domain,
|
|
|
96eb28 |
+ gid_t gid,
|
|
|
96eb28 |
+ const char **additional_attrs,
|
|
|
96eb28 |
+ struct ldb_result **_res)
|
|
|
96eb28 |
{
|
|
|
96eb28 |
TALLOC_CTX *tmp_ctx;
|
|
|
96eb28 |
unsigned long int ul_gid = gid;
|
|
|
96eb28 |
- static const char *attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
96eb28 |
const char *fmt_filter;
|
|
|
96eb28 |
struct ldb_dn *base_dn;
|
|
|
96eb28 |
struct ldb_result *res;
|
|
|
96eb28 |
int ret;
|
|
|
96eb28 |
+ static const char *default_attrs[] = SYSDB_GRSRC_ATTRS;
|
|
|
96eb28 |
+ const char **attrs = NULL;
|
|
|
96eb28 |
|
|
|
96eb28 |
tmp_ctx = talloc_new(NULL);
|
|
|
96eb28 |
if (!tmp_ctx) {
|
|
|
96eb28 |
return ENOMEM;
|
|
|
96eb28 |
}
|
|
|
96eb28 |
|
|
|
96eb28 |
+ if (additional_attrs == NULL) {
|
|
|
96eb28 |
+ attrs = default_attrs;
|
|
|
96eb28 |
+ } else {
|
|
|
96eb28 |
+ ret = add_strings_lists(tmp_ctx, additional_attrs, default_attrs,
|
|
|
96eb28 |
+ false, discard_const(&attrs));
|
|
|
96eb28 |
+ if (ret != EOK) {
|
|
|
96eb28 |
+ DEBUG(SSSDBG_OP_FAILURE, "add_strings_lists failed.\n");
|
|
|
96eb28 |
+ goto done;
|
|
|
96eb28 |
+ }
|
|
|
96eb28 |
+ }
|
|
|
96eb28 |
+
|
|
|
96eb28 |
if (domain->mpg) {
|
|
|
96eb28 |
fmt_filter = SYSDB_GRGID_MPG_FILTER;
|
|
|
96eb28 |
base_dn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
|
|
|
96eb28 |
@@ -1092,6 +1105,14 @@ done:
|
|
|
96eb28 |
return ret;
|
|
|
96eb28 |
}
|
|
|
96eb28 |
|
|
|
96eb28 |
+int sysdb_getgrgid(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
+ struct sss_domain_info *domain,
|
|
|
96eb28 |
+ gid_t gid,
|
|
|
96eb28 |
+ struct ldb_result **_res)
|
|
|
96eb28 |
+{
|
|
|
96eb28 |
+ return sysdb_getgrgid_attrs(mem_ctx, domain, gid, NULL, _res);
|
|
|
96eb28 |
+}
|
|
|
96eb28 |
+
|
|
|
96eb28 |
int sysdb_enumgrent_filter(TALLOC_CTX *mem_ctx,
|
|
|
96eb28 |
struct sss_domain_info *domain,
|
|
|
96eb28 |
const char *name_filter,
|
|
|
96eb28 |
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
|
|
|
96eb28 |
index fc9936968bcde8370c7054ba303de4463b35e15a..30574679f51362d03d7b9e3f8a1d55889817e4c1 100644
|
|
|
96eb28 |
--- a/src/tests/sysdb-tests.c
|
|
|
96eb28 |
+++ b/src/tests/sysdb-tests.c
|
|
|
96eb28 |
@@ -1114,6 +1114,42 @@ done:
|
|
|
96eb28 |
}
|
|
|
96eb28 |
END_TEST
|
|
|
96eb28 |
|
|
|
96eb28 |
+START_TEST (test_sysdb_getgrgid_attrs)
|
|
|
96eb28 |
+{
|
|
|
96eb28 |
+ struct sysdb_test_ctx *test_ctx;
|
|
|
96eb28 |
+ struct test_data *data;
|
|
|
96eb28 |
+ struct ldb_result *res;
|
|
|
96eb28 |
+ int ret;
|
|
|
96eb28 |
+ const char *attrs[] = { SYSDB_CREATE_TIME, NULL };
|
|
|
96eb28 |
+ uint64_t ctime;
|
|
|
96eb28 |
+
|
|
|
96eb28 |
+ /* Setup */
|
|
|
96eb28 |
+ ret = setup_sysdb_tests(&test_ctx);
|
|
|
96eb28 |
+ if (ret != EOK) {
|
|
|
96eb28 |
+ fail("Could not set up the test");
|
|
|
96eb28 |
+ return;
|
|
|
96eb28 |
+ }
|
|
|
96eb28 |
+
|
|
|
96eb28 |
+ data = test_data_new_group(test_ctx, _i);
|
|
|
96eb28 |
+ fail_if(data == NULL, "OOM");
|
|
|
96eb28 |
+
|
|
|
96eb28 |
+ ret = sysdb_getgrgid_attrs(test_ctx,
|
|
|
96eb28 |
+ test_ctx->domain,
|
|
|
96eb28 |
+ data->gid, attrs, &res;;
|
|
|
96eb28 |
+ if (ret) {
|
|
|
96eb28 |
+ fail("sysdb_getgrgid_attrs failed for gid %d (%d: %s)",
|
|
|
96eb28 |
+ data->gid, ret, strerror(ret));
|
|
|
96eb28 |
+ goto done;
|
|
|
96eb28 |
+ }
|
|
|
96eb28 |
+
|
|
|
96eb28 |
+ ctime = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_CREATE_TIME, 0);
|
|
|
96eb28 |
+ fail_unless(ctime != 0, "Missing create time");
|
|
|
96eb28 |
+
|
|
|
96eb28 |
+done:
|
|
|
96eb28 |
+ talloc_free(test_ctx);
|
|
|
96eb28 |
+}
|
|
|
96eb28 |
+END_TEST
|
|
|
96eb28 |
+
|
|
|
96eb28 |
START_TEST (test_sysdb_search_groups)
|
|
|
96eb28 |
{
|
|
|
96eb28 |
struct sysdb_test_ctx *test_ctx;
|
|
|
96eb28 |
@@ -7072,6 +7108,7 @@ Suite *create_sysdb_suite(void)
|
|
|
96eb28 |
|
|
|
96eb28 |
/* Verify the groups can be queried by GID */
|
|
|
96eb28 |
tcase_add_loop_test(tc_sysdb, test_sysdb_getgrgid, 28010, 28020);
|
|
|
96eb28 |
+ tcase_add_loop_test(tc_sysdb, test_sysdb_getgrgid_attrs, 28010, 28020);
|
|
|
96eb28 |
|
|
|
96eb28 |
/* Find the users by GID using a filter */
|
|
|
96eb28 |
tcase_add_loop_test(tc_sysdb, test_sysdb_search_groups, 28010, 28020);
|
|
|
96eb28 |
--
|
|
|
96eb28 |
2.14.4
|
|
|
96eb28 |
|