diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/sss_groupdel.c | 2 | ||||
-rw-r--r-- | src/tools/sss_groupmod.c | 2 | ||||
-rw-r--r-- | src/tools/sss_sync_ops.c | 81 | ||||
-rw-r--r-- | src/tools/sss_sync_ops.h | 2 | ||||
-rw-r--r-- | src/tools/sss_useradd.c | 57 | ||||
-rw-r--r-- | src/tools/tools_util.c | 2 |
6 files changed, 45 insertions, 101 deletions
diff --git a/src/tools/sss_groupdel.c b/src/tools/sss_groupdel.c index 32335571d..fe7e73096 100644 --- a/src/tools/sss_groupdel.c +++ b/src/tools/sss_groupdel.c @@ -96,7 +96,7 @@ int main(int argc, const char **argv) ret = sysdb_getgrnam_sync(tctx, tctx->ev, tctx->sysdb, tctx->octx->name, tctx->local, - &tctx->octx); + tctx->octx); if (ret != EOK) { /* Error message will be printed in the switch */ goto done; diff --git a/src/tools/sss_groupmod.c b/src/tools/sss_groupmod.c index 6c784240f..14ae68684 100644 --- a/src/tools/sss_groupmod.c +++ b/src/tools/sss_groupmod.c @@ -125,7 +125,7 @@ int main(int argc, const char **argv) /* check the username to be able to give sensible error message */ ret = sysdb_getgrnam_sync(tctx, tctx->ev, tctx->sysdb, tctx->octx->name, tctx->local, - &tctx->octx); + tctx->octx); if (ret != EOK) { ERROR("Cannot find group in local domain, " "modifying groups is allowed only in local domain\n"); diff --git a/src/tools/sss_sync_ops.c b/src/tools/sss_sync_ops.c index 70203cf2f..f3721a018 100644 --- a/src/tools/sss_sync_ops.c +++ b/src/tools/sss_sync_ops.c @@ -666,75 +666,42 @@ int sysdb_getpwnam_sync(TALLOC_CTX *mem_ctx, return EOK; } -static void sss_getgrnam_done(void *ptr, int status, - struct ldb_result *lrs); - int sysdb_getgrnam_sync(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct sysdb_ctx *sysdb, const char *name, struct sss_domain_info *domain, - struct ops_ctx **out) + struct ops_ctx *out) { + struct ldb_result *res; + const char *str; int ret; - struct sync_op_res *res = NULL; - res = talloc_zero(mem_ctx, struct sync_op_res); - if (!res) { - return ENOMEM; - } - - if (out == NULL) { - DEBUG(1, ("NULL passed for storage pointer\n")); - return EINVAL; + ret = sysdb_getgrnam(mem_ctx, sysdb, domain, name, &res); + if (ret) { + return ret; } - res->data = *out; - - ret = sysdb_getgrnam(mem_ctx, - sysdb, - domain, - name, - sss_getgrnam_done, - res); - SYNC_LOOP(res, ret); - - return ret; -} + switch (res->count) { + case 0: + DEBUG(1, ("No result for sysdb_getgrnam call\n")); + return ENOENT; -static void sss_getgrnam_done(void *ptr, int status, - struct ldb_result *lrs) -{ - struct sync_op_res *res = talloc_get_type(ptr, struct sync_op_res ); - const char *str; + case 1: + /* fill ops_ctx */ + out->gid = ldb_msg_find_attr_as_uint64(res->msgs[0], SYSDB_GIDNUM, 0); + str = ldb_msg_find_attr_as_string(res->msgs[0], SYSDB_NAME, NULL); + out->name = talloc_strdup(out, str); + if (out->name == NULL) { + return ENOMEM; + } + break; - res->done = true; - - if (status != LDB_SUCCESS) { - res->error = status; - return; - } - - switch (lrs->count) { - case 0: - DEBUG(1, ("No result for sysdb_getgrnam call\n")); - res->error = ENOENT; - break; - - /* sysdb_getgrnam also returns members */ - default: - res->error = EOK; - /* fill ops_ctx */ - res->data->gid = ldb_msg_find_attr_as_uint64(lrs->msgs[0], - SYSDB_GIDNUM, 0); - str = ldb_msg_find_attr_as_string(lrs->msgs[0], - SYSDB_NAME, NULL); - res->data->name = talloc_strdup(res, str); - if (res->data->name == NULL) { - res->error = ENOMEM; - return; - } - break; + default: + DEBUG(1, ("More than one result for sysdb_getgrnam call\n")); + return EIO; } + + return EOK; } diff --git a/src/tools/sss_sync_ops.h b/src/tools/sss_sync_ops.h index 98fbc47f2..e5ba5beec 100644 --- a/src/tools/sss_sync_ops.h +++ b/src/tools/sss_sync_ops.h @@ -104,7 +104,7 @@ int sysdb_getgrnam_sync(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, const char *name, struct sss_domain_info *domain, - struct ops_ctx **out); + struct ops_ctx *out); #endif /* __SSS_OPS_H__ */ diff --git a/src/tools/sss_useradd.c b/src/tools/sss_useradd.c index 0dc1993e5..620c3b2f0 100644 --- a/src/tools/sss_useradd.c +++ b/src/tools/sss_useradd.c @@ -32,39 +32,13 @@ #include "tools/tools_util.h" #include "tools/sss_sync_ops.h" -static void get_gid_callback(void *ptr, int error, struct ldb_result *res) -{ - struct tools_ctx *tctx = talloc_get_type(ptr, struct tools_ctx); - - if (error) { - tctx->error = error; - return; - } - - switch (res->count) { - case 0: - tctx->error = ENOENT; - break; - - case 1: - tctx->octx->gid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_GIDNUM, 0); - if (tctx->octx->gid == 0) { - tctx->error = ERANGE; - } - break; - - default: - tctx->error = EFAULT; - break; - } -} - /* Returns a gid for a given groupname. If a numerical gid * is given, returns that as integer (rationale: shadow-utils) * On error, returns -EINVAL */ static int get_gid(struct tools_ctx *tctx, const char *groupname) { + struct ldb_result *res; char *end_ptr; int ret; @@ -75,27 +49,30 @@ static int get_gid(struct tools_ctx *tctx, const char *groupname) /* Does not look like a gid - find the group name */ ret = sysdb_getgrnam(tctx->octx, tctx->sysdb, - tctx->octx->domain, groupname, - get_gid_callback, tctx); + tctx->octx->domain, groupname, &res); if (ret != EOK) { DEBUG(1, ("sysdb_getgrnam failed: %d\n", ret)); - goto done; + return ret; } - tctx->error = EOK; - tctx->octx->gid = 0; - while ((tctx->error == EOK) && (tctx->octx->gid == 0)) { - tevent_loop_once(tctx->ev); - } + switch (res->count) { + case 0: + return ENOENT; - if (tctx->error) { - DEBUG(1, ("sysdb_getgrnam failed: %d\n", ret)); - goto done; + case 1: + tctx->octx->gid = ldb_msg_find_attr_as_uint(res->msgs[0], + SYSDB_GIDNUM, 0); + if (tctx->octx->gid == 0) { + return ERANGE; + } + break; + + default: + return EFAULT; } } -done: - return ret; + return EOK; } int main(int argc, const char **argv) diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c index 9f9382a60..cae6f5c11 100644 --- a/src/tools/tools_util.c +++ b/src/tools/tools_util.c @@ -215,7 +215,7 @@ int check_group_names(struct tools_ctx *tctx, tctx->sysdb, grouplist[i], tctx->local, - &groupinfo); + groupinfo); if (ret) { DEBUG(6, ("Cannot find group %s, ret: %d\n", grouplist[i], ret)); break; |