summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-02-02 00:48:35 +0100
committerStephen Gallagher <sgallagh@redhat.com>2012-02-05 19:16:16 -0500
commit232b73185893a42e545b20caa9e59880e8a8a901 (patch)
treea98eef985ebdfca7ebecdbddd06645e5d267ec87 /src/db
parentf36078af138f052cd9a30360867b0ebd0805af5e (diff)
downloadsssd-232b73185893a42e545b20caa9e59880e8a8a901.tar.gz
sssd-232b73185893a42e545b20caa9e59880e8a8a901.tar.xz
sssd-232b73185893a42e545b20caa9e59880e8a8a901.zip
SYSDB: Remove code duplication between member_add and member_del
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb_ops.c53
1 files changed, 14 insertions, 39 deletions
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 6573dcf9d..8eb81938f 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1653,12 +1653,12 @@ done:
/* =Add-User-to-Group(Native/Legacy)====================================== */
-
-
-int sysdb_add_group_member(struct sysdb_ctx *sysdb,
+static int
+sysdb_group_membership_mod(struct sysdb_ctx *sysdb,
const char *group,
const char *member,
- enum sysdb_member_type type)
+ enum sysdb_member_type type,
+ int modify_op)
{
struct ldb_dn *group_dn;
struct ldb_dn *member_dn;
@@ -1691,13 +1691,21 @@ int sysdb_add_group_member(struct sysdb_ctx *sysdb,
goto done;
}
- ret = sysdb_mod_group_member(sysdb, member_dn, group_dn, SYSDB_MOD_ADD);
+ ret = sysdb_mod_group_member(sysdb, member_dn, group_dn, modify_op);
done:
talloc_free(tmp_ctx);
return ret;
}
+int sysdb_add_group_member(struct sysdb_ctx *sysdb,
+ const char *group,
+ const char *member,
+ enum sysdb_member_type type)
+{
+ return sysdb_group_membership_mod(sysdb, group, member, type, SYSDB_MOD_ADD);
+}
+
/* =Remove-member-from-Group(Native/Legacy)=============================== */
@@ -1706,40 +1714,7 @@ int sysdb_remove_group_member(struct sysdb_ctx *sysdb,
const char *member,
enum sysdb_member_type type)
{
- struct ldb_dn *group_dn;
- struct ldb_dn *member_dn;
- int ret;
- TALLOC_CTX *tmp_ctx = talloc_new(NULL);
- if (!tmp_ctx) {
- return ENOMEM;
- }
-
- group_dn = sysdb_group_dn(sysdb, tmp_ctx, sysdb->domain->name, group);
- if (!group_dn) {
- ret = ENOMEM;
- goto done;
- }
-
- if (type == SYSDB_MEMBER_USER) {
- member_dn = sysdb_user_dn(sysdb, tmp_ctx, sysdb->domain->name, member);
- if (!member_dn) {
- ret = ENOMEM;
- goto done;
- }
- } else if (type == SYSDB_MEMBER_GROUP) {
- member_dn = sysdb_group_dn(sysdb, tmp_ctx, sysdb->domain->name, member);
- if (!member_dn) {
- ret = ENOMEM;
- goto done;
- }
- } else {
- ret = EINVAL;
- goto done;
- }
- ret = sysdb_mod_group_member(sysdb, member_dn, group_dn, SYSDB_MOD_DEL);
-done:
- talloc_free(tmp_ctx);
- return ret;
+ return sysdb_group_membership_mod(sysdb, group, member, type, SYSDB_MOD_DEL);
}