summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/db/sysdb.h40
-rw-r--r--src/db/sysdb_ops.c372
-rw-r--r--src/providers/ldap/sdap_async_accounts.c395
-rw-r--r--src/providers/proxy.c166
-rw-r--r--src/tests/sysdb-tests.c65
-rw-r--r--src/tools/sss_sync_ops.c106
6 files changed, 294 insertions, 850 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 156dc0b8..6daad776 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -433,22 +433,18 @@ int sysdb_add_user(TALLOC_CTX *mem_ctx,
int cache_timeout);
/* Add group (only basic attrs and w/o checks) */
-struct tevent_req *sysdb_add_basic_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid);
-int sysdb_add_basic_group_recv(struct tevent_req *req);
+int sysdb_add_basic_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid);
/* Add group (all checks) */
-struct tevent_req *sysdb_add_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid,
- struct sysdb_attrs *attrs,
- int cache_timeout);
-int sysdb_add_group_recv(struct tevent_req *req);
+int sysdb_add_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid,
+ struct sysdb_attrs *attrs,
+ int cache_timeout);
/* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */
struct tevent_req *sysdb_mod_group_member_send(TALLOC_CTX *mem_ctx,
@@ -476,15 +472,13 @@ int sysdb_store_user(TALLOC_CTX *mem_ctx,
struct sysdb_attrs *attrs,
uint64_t cache_timeout);
-struct tevent_req *sysdb_store_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name,
- gid_t gid,
- struct sysdb_attrs *attrs,
- uint64_t cache_timeout);
-int sysdb_store_group_recv(struct tevent_req *req);
+int sysdb_store_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ gid_t gid,
+ struct sysdb_attrs *attrs,
+ uint64_t cache_timeout);
struct tevent_req *sysdb_add_group_member_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 6f8df5fe..87951700 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -994,252 +994,149 @@ done:
/* =Add-Basic-Group-NO-CHECKS============================================= */
-struct tevent_req *sysdb_add_basic_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid)
+int sysdb_add_basic_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid)
{
- struct tevent_req *req, *subreq;
- struct sysdb_op_state *state;
- struct ldb_request *ldbreq;
struct ldb_message *msg;
int ret;
- req = tevent_req_create(mem_ctx, &state, struct sysdb_op_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->ignore_not_found = false;
- state->ldbreply = NULL;
-
- msg = ldb_msg_new(state);
+ msg = ldb_msg_new(mem_ctx);
if (!msg) {
- ERROR_OUT(ret, ENOMEM, fail);
+ return ENOMEM;
}
/* user dn */
- msg->dn = sysdb_group_dn(handle->ctx, msg, domain->name, name);
+ msg->dn = sysdb_group_dn(ctx, msg, domain->name, name);
if (!msg->dn) {
- ERROR_OUT(ret, ENOMEM, fail);
+ ERROR_OUT(ret, ENOMEM, done);
}
ret = add_string(msg, LDB_FLAG_MOD_ADD, "objectClass", SYSDB_GROUP_CLASS);
- if (ret) goto fail;
+ if (ret) goto done;
ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_NAME, name);
- if (ret) goto fail;
+ if (ret) goto done;
ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_GIDNUM, (unsigned long)gid);
- if (ret) goto fail;
+ if (ret) goto done;
/* creation time */
ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME,
(unsigned long)time(NULL));
- if (ret) goto fail;
-
+ if (ret) goto done;
- ret = ldb_build_add_req(&ldbreq, handle->ctx->ldb, state, msg,
- NULL, NULL, NULL, NULL);
- if (ret != LDB_SUCCESS) {
- DEBUG(1, ("Failed to build modify request: %s(%d)[%s]\n",
- ldb_strerror(ret), ret, ldb_errstring(handle->ctx->ldb)));
- ERROR_OUT(ret, sysdb_error_to_errno(ret), fail);
- }
+ ret = ldb_add(ctx->ldb, msg);
+ ret = sysdb_error_to_errno(ret);
- subreq = sldb_request_send(state, ev, handle->ctx->ldb, ldbreq);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
+done:
+ if (ret) {
+ DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
}
- tevent_req_set_callback(subreq, sysdb_op_default_done, req);
-
- return req;
-
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-int sysdb_add_basic_group_recv(struct tevent_req *req)
-{
- return sysdb_op_default_recv(req);
+ talloc_zfree(msg);
+ return ret;
}
/* =Add-Group-Function==================================================== */
-struct sysdb_add_group_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
- struct sss_domain_info *domain;
-
- const char *name;
- gid_t gid;
- struct sysdb_attrs *attrs;
-
- int cache_timeout;
-};
-
-static void sysdb_add_group_basic_done(struct tevent_req *subreq);
-
-struct tevent_req *sysdb_add_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name, gid_t gid,
- struct sysdb_attrs *attrs,
- int cache_timeout)
+int sysdb_add_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name, gid_t gid,
+ struct sysdb_attrs *attrs,
+ int cache_timeout)
{
- struct tevent_req *req, *subreq;
- struct sysdb_add_group_state *state;
+ TALLOC_CTX *tmpctx;
struct ldb_message *msg;
+ uint32_t id;
+ time_t now;
int ret;
- req = tevent_req_create(mem_ctx, &state, struct sysdb_add_group_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->domain = domain;
- state->name = name;
- state->gid = gid;
- state->attrs = attrs;
- state->cache_timeout = cache_timeout;
-
if (domain->id_max != 0 && gid != 0 &&
(gid < domain->id_min || gid > domain->id_max)) {
DEBUG(2, ("Supplied gid [%d] is not in the allowed range [%d-%d].\n",
gid, domain->id_min, domain->id_max));
- ERROR_OUT(ret, ERANGE, fail);
+ return ERANGE;
+ }
+
+ tmpctx = talloc_new(mem_ctx);
+ if (!tmpctx) {
+ return ENOMEM;
}
- if (handle->ctx->mpg) {
+ if (ctx->mpg) {
/* In MPG domains you can't have groups with the same name as users,
* search if a group with the same name exists.
* Don't worry about users, if we try to add a user with the same
* name the operation will fail */
- ret = sysdb_search_user_by_name(state, handle->ctx,
+ ret = sysdb_search_user_by_name(tmpctx, ctx,
domain, name, NULL, &msg);
if (ret != ENOENT) {
if (ret == EOK) ret = EEXIST;
- goto fail;
+ goto done;
}
}
/* check no other groups with the same gid exist */
- if (state->gid != 0) {
- ret = sysdb_search_group_by_gid(state, handle->ctx,
+ if (gid != 0) {
+ ret = sysdb_search_group_by_gid(tmpctx, ctx,
domain, gid, NULL, &msg);
if (ret != ENOENT) {
if (ret == EOK) ret = EEXIST;
- goto fail;
+ goto done;
}
}
/* try to add the group */
- subreq = sysdb_add_basic_group_send(state, ev, handle,
- domain, name, gid);
- if (!subreq) {
- ERROR_OUT(ret, ENOMEM, fail);
- }
- tevent_req_set_callback(subreq, sysdb_add_group_basic_done, req);
- return req;
-
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sysdb_add_group_basic_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sysdb_add_group_state *state = tevent_req_data(req,
- struct sysdb_add_group_state);
- uint32_t id;
- time_t now;
- int ret;
-
- ret = sysdb_add_basic_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ ret = sysdb_add_basic_group(tmpctx, ctx, domain, name, gid);
+ if (ret) goto done;
- if (state->gid == 0) {
- ret = sysdb_get_new_id(state, state->handle->ctx, state->domain, &id);
- if (ret) {
- tevent_req_error(req, ret);
- return;
- }
+ if (gid == 0) {
+ ret = sysdb_get_new_id(tmpctx, ctx, domain, &id);
+ if (ret) goto done;
- if (!state->attrs) {
- state->attrs = sysdb_new_attrs(state);
- if (!state->attrs) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ if (!attrs) {
+ attrs = sysdb_new_attrs(tmpctx);
+ if (!attrs) {
+ ret = ENOMEM;
+ goto done;
}
}
- ret = sysdb_attrs_add_uint32(state->attrs, SYSDB_GIDNUM, id);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, id);
+ if (ret) goto done;
}
- if (!state->attrs) {
- state->attrs = sysdb_new_attrs(state);
- if (!state->attrs) {
- DEBUG(6, ("Error: Out of memory\n"));
- tevent_req_error(req, ENOMEM);
- return;
+ if (!attrs) {
+ attrs = sysdb_new_attrs(tmpctx);
+ if (!attrs) {
+ ret = ENOMEM;
+ goto done;
}
}
now = time(NULL);
- ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_LAST_UPDATE, now);
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
+ if (ret) goto done;
- ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_CACHE_EXPIRE,
- ((state->cache_timeout) ?
- (now + state->cache_timeout) : 0));
- if (ret) {
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
- }
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
+ ((cache_timeout) ?
+ (now + cache_timeout) : 0));
+ if (ret) goto done;
+
+ ret = sysdb_set_group_attr(tmpctx, ctx,
+ domain, name, attrs, SYSDB_MOD_REP);
- ret = sysdb_set_group_attr(state, state->handle->ctx,
- state->domain, state->name,
- state->attrs, SYSDB_MOD_REP);
+done:
if (ret) {
DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
}
-
- tevent_req_done(req);
-}
-
-int sysdb_add_group_recv(struct tevent_req *req)
-{
- return sysdb_op_default_recv(req);
+ talloc_zfree(tmpctx);
+ return ret;
}
@@ -1427,32 +1324,15 @@ done:
/* this function does not check that all user members are actually present */
-struct sysdb_store_group_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
- struct sss_domain_info *domain;
-
- const char *name;
- gid_t gid;
-
- struct sysdb_attrs *attrs;
-
- uint64_t cache_timeout;
-};
-
-static void sysdb_store_group_add_done(struct tevent_req *subreq);
-
-struct tevent_req *sysdb_store_group_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name,
- gid_t gid,
- struct sysdb_attrs *attrs,
- uint64_t cache_timeout)
+int sysdb_store_group(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ gid_t gid,
+ struct sysdb_attrs *attrs,
+ uint64_t cache_timeout)
{
- struct tevent_req *req, *subreq;
- struct sysdb_store_group_state *state;
+ TALLOC_CTX *tmpctx;
static const char *src_attrs[] = { SYSDB_NAME, SYSDB_GIDNUM,
SYSDB_ORIG_MODSTAMP, NULL };
struct ldb_message *msg;
@@ -1460,21 +1340,15 @@ struct tevent_req *sysdb_store_group_send(TALLOC_CTX *mem_ctx,
time_t now;
int ret;
- req = tevent_req_create(mem_ctx, &state, struct sysdb_store_group_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->domain = domain;
- state->name = name;
- state->gid = gid;
- state->attrs = attrs;
- state->cache_timeout = cache_timeout;
+ tmpctx = talloc_new(mem_ctx);
+ if (!tmpctx) {
+ return ENOMEM;
+ }
- ret = sysdb_search_group_by_name(state, handle->ctx,
+ ret = sysdb_search_group_by_name(tmpctx, ctx,
domain, name, src_attrs, &msg);
if (ret && ret != ENOENT) {
- goto fail;
+ goto done;
}
if (ret == ENOENT) {
new_group = true;
@@ -1485,82 +1359,46 @@ struct tevent_req *sysdb_store_group_send(TALLOC_CTX *mem_ctx,
if (new_group) {
/* group doesn't exist, turn into adding a group */
- subreq = sysdb_add_group_send(state, state->ev, state->handle,
- state->domain, state->name,
- state->gid, state->attrs,
- state->cache_timeout);
- if (!subreq) {
- ret = ENOMEM;
- goto fail;
- }
- tevent_req_set_callback(subreq, sysdb_store_group_add_done, req);
-
- return req;
+ ret = sysdb_add_group(tmpctx, ctx,
+ domain, name, gid, attrs, cache_timeout);
+ goto done;
}
/* the group exists, let's just replace attributes when set */
- if (!state->attrs) {
- state->attrs = sysdb_new_attrs(state);
- if (!state->attrs) {
+ if (!attrs) {
+ attrs = sysdb_new_attrs(tmpctx);
+ if (!attrs) {
ret = ENOMEM;
- goto fail;
+ goto done;
}
}
- if (state->gid) {
- ret = sysdb_attrs_add_uint32(state->attrs, SYSDB_GIDNUM, state->gid);
- if (ret) goto fail;
+ if (gid) {
+ ret = sysdb_attrs_add_uint32(attrs, SYSDB_GIDNUM, gid);
+ if (ret) goto done;
}
now = time(NULL);
- ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_LAST_UPDATE, now);
- if (ret) goto fail;
-
- ret = sysdb_attrs_add_time_t(state->attrs, SYSDB_CACHE_EXPIRE,
- ((state->cache_timeout) ?
- (now + state->cache_timeout) : 0));
- if (ret) goto fail;
-
- ret = sysdb_set_group_attr(state, state->handle->ctx,
- state->domain, state->name,
- state->attrs, SYSDB_MOD_REP);
- if (ret) {
- goto fail;
- }
-
- tevent_req_done(req);
- tevent_req_post(req, ev);
- return req;
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
+ if (ret) goto done;
-fail:
- DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
+ ((cache_timeout) ?
+ (now + cache_timeout) : 0));
+ if (ret) goto done;
-static void sysdb_store_group_add_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- int ret;
+ ret = sysdb_set_group_attr(tmpctx, ctx,
+ domain, name,
+ attrs, SYSDB_MOD_REP);
- ret = sysdb_add_group_recv(subreq);
- talloc_zfree(subreq);
+done:
if (ret) {
DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret)));
- tevent_req_error(req, ret);
- return;
}
-
- tevent_req_done(req);
-}
-
-int sysdb_store_group_recv(struct tevent_req *req)
-{
- return sysdb_op_default_recv(req);
+ talloc_zfree(tmpctx);
+ return ret;
}
diff --git a/src/providers/ldap/sdap_async_accounts.c b/src/providers/ldap/sdap_async_accounts.c
index 422e6a5d..0385c8f8 100644
--- a/src/providers/ldap/sdap_async_accounts.c
+++ b/src/providers/ldap/sdap_async_accounts.c
@@ -533,8 +533,7 @@ int sdap_get_users_recv(struct tevent_req *req,
/* ==Group-Parsing Routines=============================================== */
static int sdap_find_entry_by_origDN(TALLOC_CTX *memctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
+ struct sysdb_ctx *ctx,
struct sss_domain_info *domain,
const char *orig_dn,
char **localdn)
@@ -558,14 +557,13 @@ static int sdap_find_entry_by_origDN(TALLOC_CTX *memctx,
goto done;
}
- base_dn = sysdb_domain_dn(sysdb_handle_get_ctx(handle),
- tmpctx, domain->name);
+ base_dn = sysdb_domain_dn(ctx, tmpctx, domain->name);
if (!base_dn) {
ret = ENOMEM;
goto done;
}
- ret = sysdb_search_entry(tmpctx, sysdb_handle_get_ctx(handle),
+ ret = sysdb_search_entry(tmpctx, ctx,
base_dn, LDB_SCOPE_SUBTREE, filter, no_attrs,
&num_msgs, &msgs);
if (ret) {
@@ -590,8 +588,7 @@ done:
}
static int sdap_fill_memberships(struct sysdb_attrs *group_attrs,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
+ struct sysdb_ctx *ctx,
struct sdap_options *opts,
struct sss_domain_info *domain,
struct ldb_val *values,
@@ -635,8 +632,7 @@ static int sdap_fill_memberships(struct sysdb_attrs *group_attrs,
for (i = 0, j = el->num_values; i < num_values; i++) {
/* sync search entry with this as origDN */
- ret = sdap_find_entry_by_origDN(el->values, ev,
- handle, domain,
+ ret = sdap_find_entry_by_origDN(el->values, ctx, domain,
(char *)values[i].data,
(char **)&el->values[j].data);
if (ret != EOK) {
@@ -674,46 +670,24 @@ done:
/* ==Save-Group-Entry===================================================== */
-struct sdap_save_group_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
- struct sdap_options *opts;
-
- struct sss_domain_info *dom;
-
- const char *name;
- char *timestamp;
-};
-
-static void sdap_save_group_done(struct tevent_req *subreq);
-
/* FIXME: support non legacy */
/* FIXME: support storing additional attributes */
-static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sdap_options *opts,
- struct sss_domain_info *dom,
- struct sysdb_attrs *attrs,
- bool store_members)
+static int sdap_save_group(TALLOC_CTX *memctx,
+ struct sysdb_ctx *ctx,
+ struct sdap_options *opts,
+ struct sss_domain_info *dom,
+ struct sysdb_attrs *attrs,
+ bool store_members,
+ char **_timestamp)
{
- struct tevent_req *req, *subreq;
- struct sdap_save_group_state *state;
struct ldb_message_element *el;
struct sysdb_attrs *group_attrs;
+ const char *name;
long int l;
gid_t gid;
int ret;
-
- req = tevent_req_create(memctx, &state, struct sdap_save_group_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->dom = dom;
- state->opts = opts;
- state->timestamp = NULL;
+ char *timestamp = NULL;
ret = sysdb_attrs_get_el(attrs,
opts->group_map[SDAP_AT_GROUP_NAME].sys_name, &el);
@@ -722,14 +696,14 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
ret = EINVAL;
goto fail;
}
- state->name = (const char *)el->values[0].data;
+ name = (const char *)el->values[0].data;
ret = sysdb_attrs_get_el(attrs,
opts->group_map[SDAP_AT_GROUP_GID].sys_name, &el);
if (ret) goto fail;
if (el->num_values == 0) {
DEBUG(1, ("no gid provided for [%s] in domain [%s].\n",
- state->name, dom->name));
+ name, dom->name));
ret = EINVAL;
goto fail;
}
@@ -744,12 +718,12 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
/* check that the gid is valid for this domain */
if (OUT_OF_ID_RANGE(gid, dom->id_min, dom->id_max)) {
DEBUG(2, ("Group [%s] filtered out! (id out of range)\n",
- state->name));
+ name));
ret = EINVAL;
goto fail;
}
- group_attrs = sysdb_new_attrs(state);
+ group_attrs = sysdb_new_attrs(memctx);
if (!group_attrs) {
ret = ENOMEM;
goto fail;
@@ -760,10 +734,10 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
goto fail;
}
if (el->num_values == 0) {
- DEBUG(7, ("Original DN is not available for [%s].\n", state->name));
+ DEBUG(7, ("Original DN is not available for [%s].\n", name));
} else {
DEBUG(7, ("Adding original DN [%s] to attributes of [%s].\n",
- el->values[0].data, state->name));
+ el->values[0].data, name));
ret = sysdb_attrs_add_string(group_attrs, SYSDB_ORIG_DN,
(const char *)el->values[0].data);
if (ret) {
@@ -778,7 +752,7 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
}
if (el->num_values == 0) {
DEBUG(7, ("Original mod-Timestamp is not available for [%s].\n",
- state->name));
+ name));
} else {
ret = sysdb_attrs_add_string(group_attrs,
opts->group_map[SDAP_AT_GROUP_MODSTAMP].sys_name,
@@ -786,9 +760,8 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
if (ret) {
goto fail;
}
- state->timestamp = talloc_strdup(state,
- (const char*)el->values[0].data);
- if (!state->timestamp) {
+ timestamp = talloc_strdup(memctx, (const char*)el->values[0].data);
+ if (!timestamp) {
ret = ENOMEM;
goto fail;
}
@@ -801,12 +774,12 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
goto fail;
}
if (el->num_values == 0) {
- DEBUG(7, ("No members for group [%s]\n", state->name));
+ DEBUG(7, ("No members for group [%s]\n", name));
} else {
- DEBUG(7, ("Adding member users to group [%s]\n", state->name));
+ DEBUG(7, ("Adding member users to group [%s]\n", name));
- ret = sdap_fill_memberships(group_attrs, ev, handle, opts, dom,
+ ret = sdap_fill_memberships(group_attrs, ctx, opts, dom,
el->values, el->num_values);
if (ret) {
goto fail;
@@ -814,104 +787,45 @@ static struct tevent_req *sdap_save_group_send(TALLOC_CTX *memctx,
}
}
- DEBUG(6, ("Storing info for group %s\n", state->name));
-
- subreq = sysdb_store_group_send(state, state->ev,
- state->handle, state->dom,
- state->name, gid,
- group_attrs,
- dp_opt_get_int(opts->basic,
- SDAP_ENTRY_CACHE_TIMEOUT));
- if (!subreq) {
- ret = ENOMEM;
- goto fail;
- }
- tevent_req_set_callback(subreq, sdap_save_group_done, req);
-
- return req;
-
-fail:
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sdap_save_group_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sdap_save_group_state *state = tevent_req_data(req,
- struct sdap_save_group_state);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(2, ("Failed to save group %s [%d]\n", state->name, ret));
- tevent_req_error(req, ret);
- return;
- }
-
- tevent_req_done(req);
-}
-
-static int sdap_save_group_recv(struct tevent_req *req,
- TALLOC_CTX *mem_ctx, char **timestamp)
-{
- struct sdap_save_group_state *state = tevent_req_data(req,
- struct sdap_save_group_state);
+ DEBUG(6, ("Storing info for group %s\n", name));
- TEVENT_REQ_RETURN_ON_ERROR(req);
+ ret = sysdb_store_group(memctx, ctx, dom,
+ name, gid, group_attrs,
+ dp_opt_get_int(opts->basic,
+ SDAP_ENTRY_CACHE_TIMEOUT));
+ if (ret) goto fail;
- if ( timestamp ) {
- *timestamp = talloc_steal(mem_ctx, state->timestamp);
+ if (_timestamp) {
+ *_timestamp = timestamp;
}
return EOK;
+
+fail:
+ DEBUG(2, ("Failed to save user %s\n", name));
+ return ret;
}
/* ==Save-Group-Memebrs=================================================== */
-struct sdap_save_grpmem_state {
- struct tevent_context *ev;
- struct sysdb_handle *handle;
- struct sdap_options *opts;
-
- struct sss_domain_info *dom;
-
- const char *name;
-};
-
-static void sdap_save_grpmem_done(struct tevent_req *subreq);
-
/* FIXME: support non legacy */
/* FIXME: support storing additional attributes */
-static struct tevent_req *sdap_save_grpmem_send(TALLOC_CTX *memctx,
- struct tevent_context *ev,
- struct sysdb_handle *handle,
- struct sdap_options *opts,
- struct sss_domain_info *dom,
- struct sysdb_attrs *attrs)
+static int sdap_save_grpmem(TALLOC_CTX *memctx,
+ struct sysdb_ctx *ctx,
+ struct sdap_options *opts,
+ struct sss_domain_info *dom,
+ struct sysdb_attrs *attrs)
{
- struct tevent_req *req, *subreq;
- struct sdap_save_grpmem_state *state;
struct ldb_message_element *el;
struct sysdb_attrs *group_attrs = NULL;
+ const char *name;
int ret;
- req = tevent_req_create(memctx, &state, struct sdap_save_grpmem_state);
- if (!req) return NULL;
-
- state->ev = ev;
- state->handle = handle;
- state->dom = dom;
- state->opts = opts;
-
ret = sysdb_attrs_get_string(attrs,
opts->group_map[SDAP_AT_GROUP_NAME].sys_name,
- &state->name);
+ &name);
if (ret != EOK) {
goto fail;
}
@@ -922,71 +836,37 @@ static struct tevent_req *sdap_save_grpmem_send(TALLOC_CTX *memctx,
goto fail;
}
if (el->num_values == 0) {
- DEBUG(7, ("No members for group [%s]\n", state->name));
+ DEBUG(7, ("No members for group [%s]\n", name));
} else {
- DEBUG(7, ("Adding member users to group [%s]\n", state->name));
+ DEBUG(7, ("Adding member users to group [%s]\n", name));
- group_attrs = sysdb_new_attrs(state);
+ group_attrs = sysdb_new_attrs(memctx);
if (!group_attrs) {
ret = ENOMEM;
goto fail;
}
- ret = sdap_fill_memberships(group_attrs, ev, handle, opts, dom,
+ ret = sdap_fill_memberships(group_attrs, ctx, opts, dom,
el->values, el->num_values);
if (ret) {
goto fail;
}
}
- DEBUG(6, ("Storing members for group %s\n", state->name));
+ DEBUG(6, ("Storing members for group %s\n", name));
- subreq = sysdb_store_group_send(state, state->ev,
- state->handle, state->dom,
- state->name, 0,
- group_attrs,
- dp_opt_get_int(opts->basic,
- SDAP_ENTRY_CACHE_TIMEOUT));
- if (!subreq) {
- ret = ENOMEM;
- goto fail;
- }
- tevent_req_set_callback(subreq, sdap_save_grpmem_done, req);
+ ret = sysdb_store_group(memctx, ctx, dom,
+ name, 0, group_attrs,
+ dp_opt_get_int(opts->basic,
+ SDAP_ENTRY_CACHE_TIMEOUT));
+ if (ret) goto fail;
- return req;
+ return EOK;
fail:
- tevent_req_error(req, ret);
- tevent_req_post(req, ev);
- return req;
-}
-
-static void sdap_save_grpmem_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct sdap_save_grpmem_state *state = tevent_req_data(req,
- struct sdap_save_grpmem_state);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- DEBUG(2, ("Failed to save group members for %s [%d]\n",
- state->name, ret));
- tevent_req_error(req, ret);
- return;
- }
-
- tevent_req_done(req);
-}
-
-static int sdap_save_grpmem_recv(struct tevent_req *req)
-{
- TEVENT_REQ_RETURN_ON_ERROR(req);
-
- return EOK;
+ DEBUG(2, ("Failed to save user %s\n", name));
+ return ret;
}
@@ -1009,10 +889,6 @@ struct sdap_save_groups_state {
};
static void sdap_save_groups_trans(struct tevent_req *subreq);
-static void sdap_save_groups_save(struct tevent_req *req);
-static void sdap_save_groups_loop(struct tevent_req *subreq);
-static void sdap_save_groups_mem_save(struct tevent_req *req);
-static void sdap_save_groups_mem_loop(struct tevent_req *subreq);
struct tevent_req *sdap_save_groups_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
struct sss_domain_info *dom,
@@ -1069,7 +945,9 @@ static void sdap_save_groups_trans(struct tevent_req *subreq)
{
struct tevent_req *req;
struct sdap_save_groups_state *state;
+ char *timestamp;
int ret;
+ int i;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct sdap_save_groups_state);
@@ -1081,136 +959,63 @@ static void sdap_save_groups_trans(struct tevent_req *subreq)
return;
}
- sdap_save_groups_save(req);
-}
-
-static void sdap_save_groups_save(struct tevent_req *req)
-{
- struct tevent_req *subreq;
- struct sdap_save_groups_state *state;
-
- state = tevent_req_data(req, struct sdap_save_groups_state);
-
- /* if 2 pass savemembers = false */
- subreq = sdap_save_group_send(state, state->ev, state->handle,
- state->opts, state->dom,
- state->groups[state->cur],
- (!state->twopass));
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, sdap_save_groups_loop, req);
-}
-
-static void sdap_save_groups_loop(struct tevent_req *subreq)
-{
- struct tevent_req *req;
- struct sdap_save_groups_state *state;
- char *timestamp = NULL;
- int ret;
-
- req = tevent_req_callback_data(subreq, struct tevent_req);
- state = tevent_req_data(req, struct sdap_save_groups_state);
+ for (i = 0; i < state->count; i++) {
+ timestamp = NULL;
- ret = sdap_save_group_recv(subreq, state, &timestamp);
- talloc_zfree(subreq);
+ /* if 2 pass savemembers = false */
+ ret = sdap_save_group(state, sysdb_handle_get_ctx(state->handle),
+ state->opts, state->dom,
+ state->groups[i],
+ (!state->twopass), &timestamp);
- /* Do not fail completely on errors.
- * Just report the failure to save and go on */
- if (ret) {
- DEBUG(2, ("Failed to store group %d. Ignoring.\n", state->cur));
- } else {
- DEBUG(9, ("Group %d processed!\n", state->cur));
- }
+ /* Do not fail completely on errors.
+ * Just report the failure to save and go on */
+ if (ret) {
+ DEBUG(2, ("Failed to store group %d. Ignoring.\n", i));
+ } else {
+ DEBUG(9, ("Group %d processed!\n", i));
+ }
- if (timestamp) {
- if (state->higher_timestamp) {
- if (strcmp(timestamp, state->higher_timestamp) > 0) {
- talloc_zfree(state->higher_timestamp);
- state->higher_timestamp = timestamp;
+ if (timestamp) {
+ if (state->higher_timestamp) {
+ if (strcmp(timestamp, state->higher_timestamp) > 0) {
+ talloc_zfree(state->higher_timestamp);
+ state->higher_timestamp = timestamp;
+ } else {
+ talloc_zfree(timestamp);
+ }
} else {
- talloc_zfree(timestamp);
+ state->higher_timestamp = timestamp;
}
- } else {
- state->higher_timestamp = timestamp;
}
}
- state->cur++;
- if (state->cur < state->count) {
-
- sdap_save_groups_save(req);
-
- } else if (state->twopass) {
+ if (state->twopass) {
- state->cur = 0;
- sdap_save_groups_mem_save(req);
+ for (i = 0; i < state->count; i++) {
- } else {
-
- subreq = sysdb_transaction_commit_send(state, state->ev,
- state->handle);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
+ ret = sdap_save_grpmem(state,
+ sysdb_handle_get_ctx(state->handle),
+ state->opts, state->dom,
+ state->groups[i]);
+ /* Do not fail completely on errors.
+ * Just report the failure to save and go on */
+ if (ret) {
+ DEBUG(2, ("Failed to store group %d members.\n", i));
+ } else {
+ DEBUG(9, ("Group %d members processed!\n", i));
+ }
}
- /* sysdb_transaction_complete will call tevent_req_done(req) */
- tevent_req_set_callback(subreq, sysdb_transaction_complete, req);
}
-}
-
-static void sdap_save_groups_mem_save(struct tevent_req *req)
-{
- struct tevent_req *subreq;
- struct sdap_save_groups_state *state;
- state = tevent_req_data(req, struct sdap_save_groups_state);
-
- subreq = sdap_save_grpmem_send(state, state->ev, state->handle,
- state->opts, state->dom,
- state->groups[state->cur]);
+ subreq = sysdb_transaction_commit_send(state, state->ev,
+ state->handle);
if (!subreq) {
tevent_req_error(req, ENOMEM);
return;
}
- tevent_req_set_callback(subreq, sdap_save_groups_mem_loop, req);
-}
-
-static void sdap_save_groups_mem_loop(struct tevent_req *subreq)
-{
- struct tevent_req *req;
- struct sdap_save_groups_state *state;
- int ret;
-
- req = tevent_req_callback_data(subreq, struct tevent_req);
- state = tevent_req_data(req, struct sdap_save_groups_state);
-
- ret = sdap_save_grpmem_recv(subreq);
- talloc_zfree(subreq);
-
- /* Do not fail completely on errors.
- * Just report the failure to save and go on */
- if (ret) {
- DEBUG(2, ("Failed to store group %d. Ignoring.\n", state->cur));
- }
-
- state->cur++;
- if (state->cur < state->count) {
-
- sdap_save_groups_mem_save(req);
-
- } else {
-
- subreq = sysdb_transaction_commit_send(state, state->ev,
- state->handle);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
- }
- /* sysdb_transaction_complete will call tevent_req_done(req) */
- tevent_req_set_callback(subreq, sysdb_transaction_complete, req);
- }
+ /* sysdb_transaction_complete will call tevent_req_done(req) */
+ tevent_req_set_callback(subreq, sysdb_transaction_complete, req);
}
static int sdap_save_groups_recv(struct tevent_req *req,
diff --git a/src/providers/proxy.c b/src/providers/proxy.c
index 150639ce..b499a151 100644
--- a/src/providers/proxy.c
+++ b/src/providers/proxy.c
@@ -885,7 +885,6 @@ fail:
} while(0)
static void get_gr_name_process(struct tevent_req *subreq);
-static void get_gr_name_add_done(struct tevent_req *subreq);
static struct tevent_req *get_gr_name_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -1022,18 +1021,17 @@ again:
members = NULL;
}
- subreq = sysdb_store_group_send(state, state->ev, state->handle,
- state->domain,
- state->grp->gr_name,
- state->grp->gr_gid,
- members,
- ctx->entry_cache_timeout);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_store_group(state, state->sysdb,
+ state->domain,
+ state->grp->gr_name,
+ state->grp->gr_gid,
+ members,
+ ctx->entry_cache_timeout);
+ if (ret) {
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, get_gr_name_add_done, req);
- return;
+ break;
case NSS_STATUS_UNAVAIL:
/* "remote" backend unavailable. Enter offline mode */
@@ -1041,7 +1039,7 @@ again:
return;
default:
- break;
+ goto fail;
}
if (delete_group) {
@@ -1062,34 +1060,6 @@ again:
tevent_req_error(req, ret);
return;
}
-
- subreq = sysdb_transaction_commit_send(state, state->ev, state->handle);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
- }
- tevent_req_set_callback(subreq, proxy_default_done, req);
- return;
- }
-
- DEBUG(2, ("proxy -> getgrnam_r failed for '%s' <%d>\n",
- state->name, status));
- tevent_req_error(req, EIO);
-}
-
-static void get_gr_name_add_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct proxy_state *state = tevent_req_data(req,
- struct proxy_state);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- tevent_req_error(req, ret);
- return;
}
subreq = sysdb_transaction_commit_send(state, state->ev, state->handle);
@@ -1098,6 +1068,12 @@ static void get_gr_name_add_done(struct tevent_req *subreq)
return;
}
tevent_req_set_callback(subreq, proxy_default_done, req);
+ return;
+
+fail:
+ DEBUG(2, ("proxy -> getgrnam_r failed for '%s' <%d>\n",
+ state->name, status));
+ tevent_req_error(req, EIO);
}
/* =Getgrgid-wrapper======================================================*/
@@ -1238,18 +1214,17 @@ again:
members = NULL;
}
- subreq = sysdb_store_group_send(state, state->ev, state->handle,
- state->domain,
- state->grp->gr_name,
- state->grp->gr_gid,
- members,
- ctx->entry_cache_timeout);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_store_group(state, state->sysdb,
+ state->domain,
+ state->grp->gr_name,
+ state->grp->gr_gid,
+ members,
+ ctx->entry_cache_timeout);
+ if (ret) {
+ tevent_req_error(req, ret);
return;
}
- tevent_req_set_callback(subreq, get_gr_name_add_done, req);
- return;
+ break;
case NSS_STATUS_UNAVAIL:
/* "remote" backend unavailable. Enter offline mode */
@@ -1277,7 +1252,15 @@ again:
return;
}
tevent_req_set_callback(subreq, get_gr_gid_remove_done, req);
+ return;
}
+
+ subreq = sysdb_transaction_commit_send(state, state->ev, state->handle);
+ if (!subreq) {
+ tevent_req_error(req, ENOMEM);
+ return;
+ }
+ tevent_req_set_callback(subreq, proxy_default_done, req);
}
static void get_gr_gid_remove_done(struct tevent_req *subreq)
@@ -1316,8 +1299,6 @@ struct enum_groups_state {
size_t buflen;
char *buffer;
-
- bool in_transaction;
};
static void enum_groups_process(struct tevent_req *subreq);
@@ -1356,8 +1337,6 @@ static struct tevent_req *enum_groups_send(TALLOC_CTX *mem_ctx,
goto fail;
}
- state->in_transaction = false;
-
status = ctx->ops.setgrent();
if (status != NSS_STATUS_SUCCESS) {
tevent_req_error(req, EIO);
@@ -1391,24 +1370,12 @@ static void enum_groups_process(struct tevent_req *subreq)
char *newbuf;
int ret;
- if (!state->in_transaction) {
- ret = sysdb_transaction_recv(subreq, state, &state->handle);
- if (ret) {
- tevent_req_error(req, ret);
- return;
- }
- talloc_zfree(subreq);
-
- state->in_transaction = true;
- } else {
- ret = sysdb_store_group_recv(subreq);
- if (ret) {
- /* Do not fail completely on errors.
- * Just report the failure to save and go on */
- DEBUG(2, ("Failed to store group. Ignoring.\n"));
- }
- talloc_zfree(subreq);
+ ret = sysdb_transaction_recv(subreq, state, &state->handle);
+ if (ret) {
+ tevent_req_error(req, ret);
+ return;
}
+ talloc_zfree(subreq);
again:
/* always zero out the grp structure */
@@ -1484,18 +1451,18 @@ again:
members = NULL;
}
- subreq = sysdb_store_group_send(state, state->ev, state->handle,
- state->domain,
- state->grp->gr_name,
- state->grp->gr_gid,
- members,
- ctx->entry_cache_timeout);
- if (!subreq) {
- tevent_req_error(req, ENOMEM);
- return;
+ ret = sysdb_store_group(state, state->sysdb,
+ state->domain,
+ state->grp->gr_name,
+ state->grp->gr_gid,
+ members,
+ ctx->entry_cache_timeout);
+ if (ret) {
+ /* Do not fail completely on errors.
+ * Just report the failure to save and go on */
+ DEBUG(2, ("Failed to store group. Ignoring.\n"));
}
- tevent_req_set_callback(subreq, enum_groups_process, req);
- return;
+ goto again; /* next */
case NSS_STATUS_UNAVAIL:
/* "remote" backend unavailable. Enter offline mode */
@@ -1535,7 +1502,6 @@ static struct tevent_req *get_group_from_gid_send(TALLOC_CTX *mem_ctx,
gid_t gid);
static int get_group_from_gid_recv(struct tevent_req *req);
static void get_group_from_gid_send_del_done(struct tevent_req *subreq);
-static void get_group_from_gid_send_add_done(struct tevent_req *subreq);
static struct tevent_req *get_initgr_send(TALLOC_CTX *mem_ctx,
@@ -1953,17 +1919,17 @@ again:
members = NULL;
}
- subreq = sysdb_store_group_send(state, state->ev, state->handle,
- state->domain,
- state->grp->gr_name,
- state->grp->gr_gid,
- members,
- ctx->entry_cache_timeout);
- if (!subreq) {
- ret = ENOMEM;
+ ret = sysdb_store_group(state, state->sysdb,
+ state->domain,
+ state->grp->gr_name,
+ state->grp->gr_gid,
+ members,
+ ctx->entry_cache_timeout);
+ if (ret) {
goto fail;
}
- tevent_req_set_callback(subreq, get_group_from_gid_send_add_done, req);
+ tevent_req_done(req);
+ tevent_req_post(req, ev);
break;
case NSS_STATUS_UNAVAIL:
@@ -1998,22 +1964,6 @@ fail:
return req;
}
-static void get_group_from_gid_send_add_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- tevent_req_error(req, ret);
- return;
- }
-
- tevent_req_done(req);
-}
-
static void get_group_from_gid_send_del_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(subreq,
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index e75a415f..061858da 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -393,13 +393,10 @@ static void test_remove_nonexistent_user_done(struct tevent_req *subreq)
return test_return(data, ret);
}
-static void test_add_group_done(struct tevent_req *subreq);
-
static void test_add_group(struct tevent_req *req)
{
struct test_data *data = tevent_req_callback_data(req,
struct test_data);
- struct tevent_req *subreq;
int ret;
ret = sysdb_transaction_recv(req, data, &data->handle);
@@ -407,32 +404,16 @@ static void test_add_group(struct tevent_req *req)
return test_return(data, ret);
}
- subreq = sysdb_add_group_send(data, data->ev, data->handle,
- data->ctx->domain, data->groupname,
- data->gid, NULL, 0);
- if (!subreq) {
- test_return(data, ret);
- }
- tevent_req_set_callback(subreq, test_add_group_done, data);
-}
-
-static void test_add_group_done(struct tevent_req *subreq)
-{
- struct test_data *data = tevent_req_callback_data(subreq, struct test_data);
- int ret;
-
- ret = sysdb_add_group_recv(subreq);
- talloc_zfree(subreq);
+ ret = sysdb_add_group(data, data->handle->ctx,
+ data->ctx->domain, data->groupname,
+ data->gid, NULL, 0);
return test_return(data, ret);
}
-static void test_store_group_done(struct tevent_req *subreq);
-
static void test_store_group(struct tevent_req *req)
{
struct test_data *data = tevent_req_callback_data(req, struct test_data);
- struct tevent_req *subreq;
int ret;
ret = sysdb_transaction_recv(req, data, &data->handle);
@@ -440,22 +421,9 @@ static void test_store_group(struct tevent_req *req)
return test_return(data, ret);
}
- subreq = sysdb_store_group_send(data, data->ev, data->handle,
- data->ctx->domain, data->groupname,
- data->gid, NULL, -1);
- if (!subreq) {
- test_return(data, ret);
- }
- tevent_req_set_callback(subreq, test_store_group_done, data);
-}
-
-static void test_store_group_done(struct tevent_req *subreq)
-{
- struct test_data *data = tevent_req_callback_data(subreq, struct test_data);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
+ ret = sysdb_store_group(data, data->handle->ctx,
+ data->ctx->domain, data->groupname,
+ data->gid, NULL, -1);
return test_return(data, ret);
}
@@ -887,11 +855,9 @@ static void test_delete_recursive(struct tevent_req *subreq)
return test_return(data, ret);
}
-static void test_memberof_store_group_done(struct tevent_req *subreq);
static void test_memberof_store_group(struct tevent_req *req)
{
struct test_data *data = tevent_req_callback_data(req, struct test_data);
- struct tevent_req *subreq;
int ret;
struct sysdb_attrs *attrs = NULL;
char *member;
@@ -918,22 +884,9 @@ static void test_memberof_store_group(struct tevent_req *req)
}
}
- subreq = sysdb_store_group_send(data, data->ev, data->handle,
- data->ctx->domain, data->groupname,
- data->gid, attrs, -1);
- if (!subreq) {
- test_return(data, ret);
- }
- tevent_req_set_callback(subreq, test_memberof_store_group_done, data);
-}
-
-static void test_memberof_store_group_done(struct tevent_req *subreq)
-{
- struct test_data *data = tevent_req_callback_data(subreq, struct test_data);
- int ret;
-
- ret = sysdb_store_group_recv(subreq);
- talloc_zfree(subreq);
+ ret = sysdb_store_group(data, data->handle->ctx,
+ data->ctx->domain, data->groupname,
+ data->gid, attrs, -1);
return test_return(data, ret);
}
diff --git a/src/tools/sss_sync_ops.c b/src/tools/sss_sync_ops.c
index 86c17ce6..900edeaf 100644
--- a/src/tools/sss_sync_ops.c
+++ b/src/tools/sss_sync_ops.c
@@ -540,72 +540,6 @@ static int user_mod_recv(struct tevent_req *req)
}
/*
- * Add a group
- */
-struct group_add_state {
- struct tevent_context *ev;
- struct sysdb_ctx *sysdb;
- struct sysdb_handle *handle;
- struct sysdb_attrs *attrs;
-
- struct ops_ctx *data;
-};
-
-static void group_add_done(struct tevent_req *subreq);
-
-static struct tevent_req *group_add_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct ops_ctx *data)
-{
- struct group_add_state *state = NULL;
- struct tevent_req *req;
- struct tevent_req *subreq;
-
- req = tevent_req_create(mem_ctx, &state, struct group_add_state);
- if (req == NULL) {
- return NULL;
- }
- state->ev = ev;
- state->sysdb = sysdb;
- state->handle = handle;
- state->data = data;
-
- subreq = sysdb_add_group_send(state, state->ev, state->handle,
- state->data->domain, state->data->name,
- state->data->gid, NULL, 0);
- if (!subreq) {
- talloc_zfree(req);
- return NULL;
- }
-
- tevent_req_set_callback(subreq, group_add_done, req);
- return req;
-}
-
-static void group_add_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- int ret;
-
- ret = sysdb_add_group_recv(subreq);
- talloc_zfree(subreq);
- if (ret) {
- tevent_req_error(req, ret);
- return;
- }
-
- return tevent_req_done(req);
-}
-
-static int group_add_recv(struct tevent_req *req)
-{
- return sync_ops_recv(req);
-}
-
-/*
* Modify a group
*/
struct group_mod_state {
@@ -1083,8 +1017,6 @@ static void usermod_done(struct tevent_req *req)
/*
* Public interface for adding groups
*/
-static void groupadd_done(struct tevent_req *);
-
int groupadd(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct sysdb_ctx *sysdb,
@@ -1092,44 +1024,16 @@ int groupadd(TALLOC_CTX *mem_ctx,
struct ops_ctx *data)
{
int ret;
- struct tevent_req *req;
- struct sync_op_res *res = NULL;
- res = talloc_zero(mem_ctx, struct sync_op_res);
- if (!res) {
- return ENOMEM;
+ ret = sysdb_add_group(mem_ctx, sysdb,
+ data->domain, data->name,
+ data->gid, NULL, 0);
+ if (ret == EOK) {
+ flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
}
-
- req = group_add_send(res, ev, sysdb, handle, data);
- if (!req) {
- return ENOMEM;
- }
- tevent_req_set_callback(req, groupadd_done, res);
-
- SYNC_LOOP(res, ret);
-
- flush_nscd_cache(mem_ctx, NSCD_DB_GROUP);
-
- talloc_free(res);
return ret;
}
-static void groupadd_done(struct tevent_req *req)
-{
- int ret;
- struct sync_op_res *res = tevent_req_callback_data(req,
- struct sync_op_res);
-
- ret = group_add_recv(req);
- talloc_free(req);
- if (ret) {
- DEBUG(2, ("Adding group failed: %s (%d)\n", strerror(ret), ret));
- }
-
- res->done = true;
- res->error = ret;
-}
-
/*
* Public interface for deleting groups
*/