summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2010-09-29 22:15:20 +0200
committerStephen Gallagher <sgallagh@redhat.com>2010-10-15 09:03:07 -0400
commit7e15d2ed3c01ab3c1f5f882fe8fa974058097bc6 (patch)
tree860f60d776890cf2b4c100053832b552cdef54d1 /src
parent8c08a5e11f19cfe39695ee80793b72e2034c5aa4 (diff)
downloadsssd-7e15d2ed3c01ab3c1f5f882fe8fa974058097bc6.tar.gz
sssd-7e15d2ed3c01ab3c1f5f882fe8fa974058097bc6.tar.bz2
sssd-7e15d2ed3c01ab3c1f5f882fe8fa974058097bc6.zip
sysdb interface for adding incomplete groups
Useful for optimizing the initgroups operation.
Diffstat (limited to 'src')
-rw-r--r--src/db/sysdb.h5
-rw-r--r--src/db/sysdb_ops.c44
-rw-r--r--src/responder/nss/nsssrv_cmd.c2
-rw-r--r--src/tests/sysdb-tests.c40
4 files changed, 90 insertions, 1 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 76e1715d..7db1a6ea 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -479,6 +479,11 @@ int sysdb_add_group(TALLOC_CTX *mem_ctx,
struct sysdb_attrs *attrs,
int cache_timeout);
+int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ gid_t gid);
+
/* Add netgroup (only basic attrs and w/o checks) */
int sysdb_add_basic_netgroup(struct sysdb_ctx *ctx,
struct sss_domain_info *domain,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 68f4e88b..f8e1fbd5 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1075,6 +1075,50 @@ done:
return ret;
}
+int sysdb_add_incomplete_group(struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ gid_t gid)
+{
+ TALLOC_CTX *tmpctx;
+ time_t now;
+ int ret;
+ struct sysdb_attrs *attrs;
+
+ tmpctx = talloc_new(NULL);
+ if (!tmpctx) {
+ return ENOMEM;
+ }
+
+ /* try to add the group */
+ ret = sysdb_add_basic_group(tmpctx, ctx, domain, name, gid);
+ if (ret) goto done;
+
+ attrs = sysdb_new_attrs(tmpctx);
+ if (!attrs) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ now = time(NULL);
+
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
+ if (ret) goto done;
+
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
+ now-1);
+ if (ret) goto done;
+
+ ret = sysdb_set_group_attr(tmpctx, ctx,
+ domain, name, attrs, SYSDB_MOD_REP);
+
+done:
+ if (ret != EOK) {
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
+ }
+ talloc_zfree(tmpctx);
+ return ret;
+}
/* =Add-Or-Remove-Group-Memeber=========================================== */
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index d0db2ef8..c82f891e 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -1538,7 +1538,7 @@ static int fill_grent(struct sss_packet *packet,
name = ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
gid = ldb_msg_find_attr_as_uint64(msg, SYSDB_GIDNUM, 0);
if (!name || !gid) {
- DEBUG(1, ("Incomplete group object for %s[%llu]! Skipping\n",
+ DEBUG(2, ("Incomplete group object for %s[%llu]! Skipping\n",
name?name:"<NULL>", (unsigned long long int)gid));
continue;
}
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 51eda8fd..b874544c 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -263,6 +263,15 @@ static int test_add_group(struct test_data *data)
return ret;
}
+static int test_add_incomplete_group(struct test_data *data)
+{
+ int ret;
+
+ ret = sysdb_add_incomplete_group(data->ctx->sysdb, data->ctx->domain,
+ data->groupname, data->gid);
+ return ret;
+}
+
static int test_store_group(struct test_data *data)
{
int ret;
@@ -717,6 +726,33 @@ START_TEST (test_sysdb_add_group)
}
END_TEST
+START_TEST (test_sysdb_add_incomplete_group)
+{
+ struct sysdb_test_ctx *test_ctx;
+ struct test_data *data;
+ int ret;
+
+ /* Setup */
+ ret = setup_sysdb_tests(&test_ctx);
+ if (ret != EOK) {
+ fail("Could not set up the test");
+ return;
+ }
+
+ data = talloc_zero(test_ctx, struct test_data);
+ data->ctx = test_ctx;
+ data->ev = test_ctx->ev;
+ data->uid = _i;
+ data->gid = _i;
+ data->groupname = talloc_asprintf(data, "testgroup%d", _i);
+
+ ret = test_add_incomplete_group(data);
+
+ fail_if(ret != EOK, "Could not add incomplete group %s", data->groupname);
+ talloc_free(test_ctx);
+}
+END_TEST
+
START_TEST (test_sysdb_getpwnam)
{
struct sysdb_test_ctx *test_ctx;
@@ -2776,6 +2812,10 @@ Suite *create_sysdb_suite(void)
/* test the ignore_not_found parameter for groups */
tcase_add_test(tc_sysdb, test_sysdb_remove_nonexistent_group);
+ /* Create incomplete groups - remove will fail if the LDB objects don't exist */
+ tcase_add_loop_test(tc_sysdb, test_sysdb_add_incomplete_group, 28000, 28010);
+ tcase_add_loop_test(tc_sysdb, test_sysdb_remove_local_group_by_gid, 28000, 28010);
+
/* test custom operations */
tcase_add_loop_test(tc_sysdb, test_sysdb_store_custom, 29010, 29020);
tcase_add_test(tc_sysdb, test_sysdb_search_custom_by_name);