From 7e15d2ed3c01ab3c1f5f882fe8fa974058097bc6 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 29 Sep 2010 22:15:20 +0200 Subject: sysdb interface for adding incomplete groups Useful for optimizing the initgroups operation. --- src/db/sysdb.h | 5 +++++ src/db/sysdb_ops.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'src/db') diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 76e1715d9..7db1a6ea4 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 68f4e88b1..f8e1fbd52 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=========================================== */ -- cgit