diff options
author | Simo Sorce <ssorce@redhat.com> | 2009-02-28 18:54:10 -0500 |
---|---|---|
committer | Simo Sorce <ssorce@redhat.com> | 2009-02-28 18:55:49 -0500 |
commit | 996553cb421bddc32b27e1457dde9749adcf2a31 (patch) | |
tree | 8f914e5e20e6d5e2a5c147e9b612afa0137deb0d /server/db | |
parent | f0cefca80767664b876d10126f7f79fc36dc1993 (diff) | |
download | sssd-996553cb421bddc32b27e1457dde9749adcf2a31.tar.gz sssd-996553cb421bddc32b27e1457dde9749adcf2a31.tar.xz sssd-996553cb421bddc32b27e1457dde9749adcf2a31.zip |
Expose some more functions needed by the tests
Diffstat (limited to 'server/db')
-rw-r--r-- | server/db/sysdb.c | 4 | ||||
-rw-r--r-- | server/db/sysdb.h | 13 | ||||
-rw-r--r-- | server/db/sysdb_ops.c | 98 |
3 files changed, 114 insertions, 1 deletions
diff --git a/server/db/sysdb.c b/server/db/sysdb.c index 84d580a84..f4cbd569f 100644 --- a/server/db/sysdb.c +++ b/server/db/sysdb.c @@ -36,6 +36,10 @@ struct ldb_dn *sysdb_group_dn(struct sysdb_ctx *ctx, void *memctx, return ldb_dn_new_fmt(memctx, ctx->ldb, SYSDB_TMPL_GROUP, name, domain); } +struct ldb_context *sysdb_ctx_get_ldb(struct sysdb_ctx *ctx) +{ + return ctx->ldb; +} /************************************************ * Initialiazation stuff diff --git a/server/db/sysdb.h b/server/db/sysdb.h index b8393ffef..a112d65b5 100644 --- a/server/db/sysdb.h +++ b/server/db/sysdb.h @@ -142,7 +142,7 @@ int sysdb_initgroups(TALLOC_CTX *mem_ctx, bool legacy, sysdb_callback_t fn, void *ptr); - +struct ldb_context *sysdb_ctx_get_ldb(struct sysdb_ctx *ctx); struct sysdb_ctx *sysdb_req_get_ctx(struct sysdb_req *req); int sysdb_transaction(TALLOC_CTX *mem_ctx, @@ -198,4 +198,15 @@ int sysdb_legacy_store_group(struct sysdb_req *sysreq, const char **members, sysdb_callback_t fn, void *pvt); +int sysdb_legacy_add_group_member(struct sysdb_req *sysreq, + const char *domain, + const char *group, + const char *member, + sysdb_callback_t fn, void *pvt); + +int sysdb_legacy_remove_group_member(struct sysdb_req *sysreq, + const char *domain, + const char *group, + const char *member, + sysdb_callback_t fn, void *pvt); #endif /* __SYS_DB_H__ */ diff --git a/server/db/sysdb_ops.c b/server/db/sysdb_ops.c index 267771b5a..ffcf1cd7d 100644 --- a/server/db/sysdb_ops.c +++ b/server/db/sysdb_ops.c @@ -936,3 +936,101 @@ static int legacy_group_callback(struct ldb_request *req, return LDB_SUCCESS; } +int sysdb_legacy_add_group_member(struct sysdb_req *sysreq, + const char *domain, + const char *group, + const char *member, + sysdb_callback_t fn, void *pvt) +{ + struct sysdb_ctx *ctx; + struct sysdb_cb_ctx *cbctx; + struct ldb_request *req; + struct ldb_message *msg; + int ret; + + if (!sysdb_req_check_running(sysreq)) { + DEBUG(2, ("Invalid request! Not running at this time.\n")); + return EINVAL; + } + + ctx = sysdb_req_get_ctx(sysreq); + + cbctx = talloc_zero(sysreq, struct sysdb_cb_ctx); + if (!cbctx) return ENOMEM; + + cbctx->fn = fn; + cbctx->pvt = pvt; + + /* Add the member_dn as a member of the group */ + msg = ldb_msg_new(cbctx); + if(msg == NULL) return ENOMEM; + + msg->dn = sysdb_group_dn(ctx, cbctx, domain, group); + if (!msg->dn) return ENOMEM; + + ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_LEGACY_MEMBER, member); + if (ret != LDB_SUCCESS) return ENOMEM; + + ret = ldb_build_mod_req(&req, ctx->ldb, cbctx, msg, + NULL, cbctx, sysdb_op_callback, NULL); + if (ret != LDB_SUCCESS) { + DEBUG(1, ("Failed to build modify request: %s(%d)[%s]\n", + ldb_strerror(ret), ret, ldb_errstring(ctx->ldb))); + return sysdb_error_to_errno(ret); + } + + ret = ldb_request(ctx->ldb, req); + if (ret != LDB_SUCCESS) return sysdb_error_to_errno(ret); + + return EOK; +} + +int sysdb_legacy_remove_group_member(struct sysdb_req *sysreq, + const char *domain, + const char *group, + const char *member, + sysdb_callback_t fn, void *pvt) +{ + struct sysdb_ctx *ctx; + struct sysdb_cb_ctx *cbctx; + struct ldb_request *req; + struct ldb_message *msg; + int ret; + + if (!sysdb_req_check_running(sysreq)) { + DEBUG(2, ("Invalid request! Not running at this time.\n")); + return EINVAL; + } + + ctx = sysdb_req_get_ctx(sysreq); + + cbctx = talloc_zero(sysreq, struct sysdb_cb_ctx); + if (!cbctx) return ENOMEM; + + cbctx->fn = fn; + cbctx->pvt = pvt; + + /* Add the member_dn as a member of the group */ + msg = ldb_msg_new(cbctx); + if(msg == NULL) return ENOMEM; + + msg->dn = sysdb_group_dn(ctx, cbctx, domain, group); + if (!msg->dn) return ENOMEM; + + ret = add_string(msg, LDB_FLAG_MOD_DELETE, SYSDB_LEGACY_MEMBER, member); + if (ret != LDB_SUCCESS) return ENOMEM; + + ret = ldb_build_mod_req(&req, ctx->ldb, cbctx, msg, + NULL, cbctx, sysdb_op_callback, NULL); + if (ret != LDB_SUCCESS) { + DEBUG(1, ("Failed to build modify request: %s(%d)[%s]\n", + ldb_strerror(ret), ret, ldb_errstring(ctx->ldb))); + return sysdb_error_to_errno(ret); + } + + ret = ldb_request(ctx->ldb, req); + if (ret != LDB_SUCCESS) return sysdb_error_to_errno(ret); + + return EOK; +} + |