From e2510cf01e323aa33ec17c7b79b90aa6918bccc8 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 19 Jun 2009 14:55:34 +0200 Subject: [PATCH 2/2] Gettextize the sss_ tools --- server/tools/sss_groupadd.c | 35 +++++++++++------- server/tools/sss_groupdel.c | 32 +++++++++++----- server/tools/sss_groupmod.c | 47 +++++++++++++----------- server/tools/sss_useradd.c | 52 +++++++++++++++++---------- server/tools/sss_userdel.c | 32 +++++++++++----- server/tools/sss_usermod.c | 83 ++++++++++++++++++++++++++----------------- server/tools/tools_util.c | 4 +- 7 files changed, 176 insertions(+), 109 deletions(-) diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c index eb7b3d8..685de6f 100644 --- a/server/tools/sss_groupadd.c +++ b/server/tools/sss_groupadd.c @@ -95,6 +95,7 @@ static int groupadd_legacy(struct group_add_ctx *ctx) command = talloc_asprintf(ctx, "%s ", GROUPADD); if (command == NULL) { + DEBUG(1, ("Cannot allocate memory for command string\n")); return ENOMEM; } @@ -104,9 +105,9 @@ static int groupadd_legacy(struct group_add_ctx *ctx) ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -122,8 +123,8 @@ int main(int argc, const char **argv) int pc_debug = 0; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug",'\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, - { "gid", 'g', POPT_ARG_INT, &pc_gid, 0, "The GID of the group", NULL }, + { "debug",'\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, + { "gid", 'g', POPT_ARG_INT, &pc_gid, 0, _("The GID of the group"), NULL }, POPT_TABLEEND }; struct sss_domain_info *dom; @@ -136,14 +137,16 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if(ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } group_ctx = talloc_zero(NULL, struct group_add_ctx); if (group_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for group_ctx context\n")); + DEBUG(1, ("Could not allocate memory for group_ctx context\n")); + ERROR("Out of memory.\n"); return ENOMEM; } group_ctx->ctx = ctx; @@ -162,7 +165,7 @@ int main(int argc, const char **argv) /* groupname is an argument, not option */ group_ctx->groupname = poptGetArg(pc); if(group_ctx->groupname == NULL) { - usage(pc, "Specify group to add\n"); + usage(pc, _("Specify group to add\n")); ret = EXIT_FAILURE; goto fini; } @@ -180,15 +183,20 @@ int main(int argc, const char **argv) group_ctx->domain = dom; case ID_OUTSIDE: ret = groupadd_legacy(group_ctx); + if(ret != EOK) { + ERROR("Cannot add group to domain using the legacy tools\n"); + } goto fini; case ID_IN_OTHER: - DEBUG(0, ("Cannot add group to domain %s\n", dom->name)); + DEBUG(1, ("Cannot add group to domain %s\n", dom->name)); + ERROR("Unsupported domain type"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } @@ -196,8 +204,8 @@ int main(int argc, const char **argv) /* add_group */ ret = sysdb_transaction(ctx, ctx->sysdb, add_group, group_ctx); if(ret != EOK) { - DEBUG(1, ("Could not start transaction (%d)[%s]\n", - ret, strerror(ret))); + DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not add group.\n"); ret = EXIT_FAILURE; goto fini; } @@ -210,11 +218,12 @@ int main(int argc, const char **argv) ret = group_ctx->error; switch (ret) { case EEXIST: - DEBUG(0, ("The group %s already exists\n", group_ctx->groupname)); + ERROR("The group %s already exists\n", group_ctx->groupname); break; default: - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not add group.\n"); break; } ret = EXIT_FAILURE; diff --git a/server/tools/sss_groupdel.c b/server/tools/sss_groupdel.c index 3158710..fa23ea8 100644 --- a/server/tools/sss_groupdel.c +++ b/server/tools/sss_groupdel.c @@ -97,9 +97,9 @@ static int groupdel_legacy(struct group_del_ctx *ctx) ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -121,7 +121,7 @@ int main(int argc, const char **argv) poptContext pc = NULL; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, + { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, POPT_TABLEEND }; @@ -129,14 +129,16 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if(ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } group_ctx = talloc_zero(NULL, struct group_del_ctx); if (group_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for group_ctx context\n")); + DEBUG(1, ("Could not allocate memory for group_ctx context\n")); + ERROR("Out of memory\n"); return ENOMEM; } group_ctx->ctx = ctx; @@ -154,7 +156,7 @@ int main(int argc, const char **argv) group_ctx->groupname = poptGetArg(pc); if(group_ctx->groupname == NULL) { - usage(pc, "Specify group to delete\n"); + usage(pc, _("Specify group to delete\n")); ret = EXIT_FAILURE; goto fini; } @@ -175,15 +177,22 @@ int main(int argc, const char **argv) group_ctx->domain = dom; case ID_OUTSIDE: ret = groupdel_legacy(group_ctx); + if(ret != EOK) { + ERROR("Cannot delete group from domain using the legacy tools\n"); + ret = EXIT_FAILURE; + goto fini; + } break; /* Also delete possible cached entries in sysdb */ case ID_IN_OTHER: - DEBUG(0, ("Cannot delete group from domain %s\n", dom->name)); + DEBUG(1, ("Cannot remove group from domain %s\n", dom->name)); + ERROR("Unsupported domain type\n"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } @@ -192,7 +201,8 @@ int main(int argc, const char **argv) group_ctx->domain->name, group_ctx->groupname); if(group_ctx->group_dn == NULL) { - DEBUG(0, ("Could not construct a group DN\n")); + DEBUG(1, ("Could not construct a group DN\n")); + ERROR("Internal database error. Could not remove group.\n"); ret = EXIT_FAILURE; goto fini; } @@ -201,6 +211,7 @@ int main(int argc, const char **argv) ret = sysdb_transaction(ctx, ctx->sysdb, group_del, group_ctx); if(ret != EOK) { DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not remove group.\n"); ret = EXIT_FAILURE; goto fini; } @@ -211,7 +222,8 @@ int main(int argc, const char **argv) if (group_ctx->error) { ret = group_ctx->error; - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not remove group.\n"); ret = EXIT_FAILURE; goto fini; } diff --git a/server/tools/sss_groupmod.c b/server/tools/sss_groupmod.c index d6c1915..9bc3ef6 100644 --- a/server/tools/sss_groupmod.c +++ b/server/tools/sss_groupmod.c @@ -198,7 +198,7 @@ static int groupmod_legacy(struct tools_ctx *tools_ctx, struct group_mod_ctx *ct APPEND_STRING(command, GROUPMOD); if (ctx->addgroups || ctx->rmgroups) { - DEBUG(0, ("Groups nesting is not supported in this domain\n")); + ERROR("Group nesting is not supported in this domain\n"); talloc_free(command); return EINVAL; } @@ -208,7 +208,7 @@ static int groupmod_legacy(struct tools_ctx *tools_ctx, struct group_mod_ctx *ct if (ret == old_domain) { APPEND_PARAM(command, GROUPMOD_GID, ctx->gid); } else { - DEBUG(0, ("Changing gid only allowed inside the same domain\n")); + ERROR("Changing gid only allowed inside the same domain\n"); talloc_free(command); return EINVAL; } @@ -219,9 +219,9 @@ static int groupmod_legacy(struct tools_ctx *tools_ctx, struct group_mod_ctx *ct ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -237,10 +237,10 @@ int main(int argc, const char **argv) int pc_debug = 0; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, - { "append-group", 'a', POPT_ARG_STRING, NULL, 'a', "Groups to add this group to", NULL }, - { "remove-group", 'r', POPT_ARG_STRING, NULL, 'r', "Groups to remove this group from", NULL }, - { "gid", 'g', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_gid, 0, "The GID of the group", NULL }, + { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, + { "append-group", 'a', POPT_ARG_STRING, NULL, 'a', _("Groups to add this group to"), NULL }, + { "remove-group", 'r', POPT_ARG_STRING, NULL, 'r', _("Groups to remove this group from"), NULL }, + { "gid", 'g', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_gid, 0, _("The GID of the group"), NULL }, POPT_TABLEEND }; poptContext pc = NULL; @@ -256,14 +256,16 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if (ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } group_ctx = talloc_zero(ctx, struct group_mod_ctx); if (group_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for group_ctx context\n")); + DEBUG(1, ("Could not allocate memory for group_ctx context\n")); + ERROR("Out of memory\n"); return ENOMEM; } group_ctx->ctx = ctx; @@ -301,7 +303,7 @@ int main(int argc, const char **argv) /* groupname is an argument without --option */ group_ctx->groupname = poptGetArg(pc); if (group_ctx->groupname == NULL) { - usage(pc, "Specify group to modify\n"); + usage(pc, _("Specify group to modify\n")); ret = EXIT_FAILURE; goto fini; } @@ -320,32 +322,32 @@ int main(int argc, const char **argv) group_ctx->domain = dom; break; - case ID_OUTSIDE: - DEBUG(5, ("Group ID outside range\n")); - ret = groupmod_legacy(ctx, group_ctx, ret); - goto fini; - case ID_IN_LEGACY_LOCAL: - DEBUG(5, ("group ID in legacy domain\n")); group_ctx->domain = dom; + case ID_OUTSIDE: ret = groupmod_legacy(ctx, group_ctx, ret); + if(ret != EOK) { + ERROR("Cannot delete group from domain using the legacy tools\n"); + } goto fini; case ID_IN_OTHER: - DEBUG(0, ("Cannot modify group from domain %s\n", dom->name)); + DEBUG(1, ("Cannot modify group from domain %s\n", dom->name)); + ERROR("Unsupported domain type\n"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } ret = sysdb_transaction(ctx, ctx->sysdb, mod_group, group_ctx); if (ret != EOK) { - DEBUG(0, ("Could not start transaction (%d)[%s]\n", - ret, strerror(ret))); + DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify group.\n"); ret = EXIT_FAILURE; goto fini; } @@ -356,7 +358,8 @@ int main(int argc, const char **argv) if (group_ctx->error) { ret = group_ctx->error; - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify group.\n"); ret = EXIT_FAILURE; goto fini; } diff --git a/server/tools/sss_useradd.c b/server/tools/sss_useradd.c index 84f38fa..5ee0116 100644 --- a/server/tools/sss_useradd.c +++ b/server/tools/sss_useradd.c @@ -159,7 +159,7 @@ static int get_gid(struct user_add_ctx *user_ctx, const char *groupname) user_ctx->domain, groupname, get_gid_callback, data); if (ret != EOK) { - DEBUG(0, ("sysdb_getgrnam failed: %d\n", ret)); + DEBUG(1, ("sysdb_getgrnam failed: %d\n", ret)); goto done; } @@ -168,6 +168,7 @@ static int get_gid(struct user_add_ctx *user_ctx, const char *groupname) } if (data->error) { + DEBUG(1, ("sysdb_getgrnam failed: %d\n", ret)); ret = data->error; goto done; } @@ -295,9 +296,9 @@ static int useradd_legacy(struct user_add_ctx *ctx, char *grouplist) ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -318,13 +319,13 @@ int main(int argc, const char **argv) int pc_debug = 0; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, - { "uid", 'u', POPT_ARG_INT, &pc_uid, 0, "The UID of the user", NULL }, - { "gid", 'g', POPT_ARG_STRING, &pc_group, 0, "The GID or group name of the user", NULL }, - { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, "The comment string", NULL }, - { "home", 'h', POPT_ARG_STRING, &pc_home, 0, "Home directory", NULL }, - { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, "Login shell", NULL }, - { "groups", 'G', POPT_ARG_STRING, NULL, 'G', "Groups", NULL }, + { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, + { "uid", 'u', POPT_ARG_INT, &pc_uid, 0, _("The UID of the user"), NULL }, + { "gid", 'g', POPT_ARG_STRING, &pc_group, 0, _("The GID or group name of the user"), NULL }, + { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, _("The comment string"), NULL }, + { "home", 'h', POPT_ARG_STRING, &pc_home, 0, _("Home directory"), NULL }, + { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login shell"), NULL }, + { "groups", 'G', POPT_ARG_STRING, NULL, 'G', _("Groups"), NULL }, POPT_TABLEEND }; poptContext pc = NULL; @@ -338,14 +339,16 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if (ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } user_ctx = talloc_zero(ctx, struct user_add_ctx); if (user_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for user_ctx context\n")); + DEBUG(1, ("Could not allocate memory for user_ctx context\n")); + ERROR("Out of memory\n"); return ENOMEM; } user_ctx->ctx = ctx; @@ -379,7 +382,7 @@ int main(int argc, const char **argv) /* username is an argument without --option */ user_ctx->username = poptGetArg(pc); if (user_ctx->username == NULL) { - usage(pc, "Specify user to add\n"); + usage(pc, (_("Specify user to add\n"))); ret = EXIT_FAILURE; goto fini; } @@ -388,6 +391,7 @@ int main(int argc, const char **argv) if (pc_group != NULL) { ret = get_gid(user_ctx, pc_group); if (ret != EOK) { + ERROR("Cannot get group information for the user\n"); ret = EXIT_FAILURE; goto fini; } @@ -419,6 +423,10 @@ int main(int argc, const char **argv) goto fini; } user_ctx->home = talloc_asprintf(user_ctx, "%s/%s", basedir, user_ctx->username); + if (!user_ctx->home) { + ret = EXIT_FAILURE; + goto fini; + } } if (!user_ctx->home) { ret = EXIT_FAILURE; @@ -451,15 +459,20 @@ int main(int argc, const char **argv) user_ctx->domain = dom; case ID_OUTSIDE: ret = useradd_legacy(user_ctx, groups); + if(ret != EOK) { + ERROR("Cannot add user to domain using the legacy tools\n"); + } goto fini; case ID_IN_OTHER: - DEBUG(0, ("Cannot add user to domain %s\n", dom->name)); + DEBUG(1, ("Cannot add user to domain %s\n", dom->name)); + ERROR("Unsupported domain type\n"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } @@ -467,8 +480,8 @@ int main(int argc, const char **argv) /* useradd */ ret = sysdb_transaction(ctx, ctx->sysdb, add_user, user_ctx); if (ret != EOK) { - DEBUG(0, ("Could not start transaction (%d)[%s]\n", - ret, strerror(ret))); + DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify user.\n"); ret = EXIT_FAILURE; goto fini; } @@ -481,11 +494,12 @@ int main(int argc, const char **argv) ret = user_ctx->error; switch (ret) { case EEXIST: - DEBUG(0, (_("The user %s already exists\n"), user_ctx->username)); + ERROR("The user %s already exists\n", user_ctx->username); break; default: - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify user.\n"); break; } ret = EXIT_FAILURE; diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c index e374b14..90dfdaf 100644 --- a/server/tools/sss_userdel.c +++ b/server/tools/sss_userdel.c @@ -96,9 +96,9 @@ static int userdel_legacy(struct user_del_ctx *ctx) ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -120,7 +120,7 @@ int main(int argc, const char **argv) poptContext pc = NULL; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, + { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, POPT_TABLEEND }; @@ -128,14 +128,16 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if(ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } user_ctx = talloc_zero(NULL, struct user_del_ctx); if (user_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for user_ctx context\n")); + DEBUG(1, ("Could not allocate memory for user_ctx context\n")); + ERROR("Out of memory\n"); return ENOMEM; } user_ctx->ctx = ctx; @@ -153,7 +155,7 @@ int main(int argc, const char **argv) user_ctx->username = poptGetArg(pc); if(user_ctx->username == NULL) { - usage(pc, "Specify user to delete\n"); + usage(pc, _("Specify user to delete\n")); ret = EXIT_FAILURE; goto fini; } @@ -174,15 +176,22 @@ int main(int argc, const char **argv) user_ctx->domain = dom; case ID_OUTSIDE: ret = userdel_legacy(user_ctx); + if(ret != EOK) { + ERROR("Cannot delete user from domain using the legacy tools\n"); + ret = EXIT_FAILURE; + goto fini; + } break; /* Also delete possible cached entries in sysdb */ case ID_IN_OTHER: - DEBUG(0, ("Cannot delete user from domain %s\n", dom->name)); + DEBUG(1, ("Cannot remove user from domain %s\n", dom->name)); + ERROR("Unsupported domain type\n"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } @@ -191,7 +200,8 @@ int main(int argc, const char **argv) user_ctx->domain->name, user_ctx->username); if(user_ctx->user_dn == NULL) { - DEBUG(0, ("Could not construct an user DN\n")); + DEBUG(1, ("Could not construct a user DN\n")); + ERROR("Internal database error. Could not remove user.\n"); ret = EXIT_FAILURE; goto fini; } @@ -201,6 +211,7 @@ int main(int argc, const char **argv) ret = sysdb_transaction(ctx, ctx->sysdb, user_del, user_ctx); if(ret != EOK) { DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not remove user.\n"); ret = EXIT_FAILURE; goto fini; } @@ -211,7 +222,8 @@ int main(int argc, const char **argv) if (user_ctx->error) { ret = user_ctx->error; - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not remove user.\n"); ret = EXIT_FAILURE; goto fini; } diff --git a/server/tools/sss_usermod.c b/server/tools/sss_usermod.c index a5eadce..d34a6c7 100644 --- a/server/tools/sss_usermod.c +++ b/server/tools/sss_usermod.c @@ -35,9 +35,10 @@ #define DO_LOCK 1 #define DO_UNLOCK 2 -#define VAR_CHECK(var, val, msg) do { \ +#define VAR_CHECK(var, val, attr, msg) do { \ if (var != (val)) { \ - DEBUG(0, (msg)); \ + DEBUG(1, (msg" attribute: %s", attr)); \ + ERROR(msg); \ var = EXIT_FAILURE; \ goto fini; \ } \ @@ -242,7 +243,7 @@ static int usermod_legacy(struct tools_ctx *tools_ctx, struct user_mod_ctx *ctx, if (ret == old_domain) { APPEND_PARAM(command, USERMOD_UID, uid); } else { - DEBUG(0, ("Changing uid only allowed inside the same domain\n")); + ERROR("Changing uid only allowed inside the same domain\n"); talloc_free(command); return EINVAL; } @@ -253,7 +254,7 @@ static int usermod_legacy(struct tools_ctx *tools_ctx, struct user_mod_ctx *ctx, if (ret == old_domain) { APPEND_PARAM(command, USERMOD_GID, gid); } else { - DEBUG(0, ("Changing gid only allowed inside the same domain\n")); + ERROR("Changing gid only allowed inside the same domain\n"); talloc_free(command); return EINVAL; } @@ -276,9 +277,9 @@ static int usermod_legacy(struct tools_ctx *tools_ctx, struct user_mod_ctx *ctx, ret = system(command); if (ret) { if (ret == -1) { - DEBUG(0, ("system(3) failed\n")); + DEBUG(1, ("system(3) failed\n")); } else { - DEBUG(0,("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); + DEBUG(1, ("Could not exec '%s', return code: %d\n", command, WEXITSTATUS(ret))); } talloc_free(command); return EFAULT; @@ -299,16 +300,16 @@ int main(int argc, const char **argv) int pc_debug = 0; struct poptOption long_options[] = { POPT_AUTOHELP - { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, "The debug level to run with", NULL }, - { "uid", 'u', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_uid, 0, "The UID of the user", NULL }, - { "gid", 'g', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_gid, 0, "The GID of the user", NULL }, - { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, "The comment string", NULL }, - { "home", 'h', POPT_ARG_STRING, &pc_home, 0, "Home directory", NULL }, - { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, "Login shell", NULL }, - { "append-group", 'a', POPT_ARG_STRING, NULL, 'a', "Groups to add this user to", NULL }, - { "remove-group", 'r', POPT_ARG_STRING, NULL, 'r', "Groups to remove this user from", NULL }, - { "lock", 'L', POPT_ARG_NONE, NULL, 'L', "Lock the account", NULL }, - { "unlock", 'U', POPT_ARG_NONE, NULL, 'U', "Unlock the account", NULL }, + { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug, 0, _("The debug level to run with"), NULL }, + { "uid", 'u', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_uid, 0, _("The UID of the user"), NULL }, + { "gid", 'g', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_gid, 0, _("The GID of the user"), NULL }, + { "gecos", 'c', POPT_ARG_STRING, &pc_gecos, 0, _("The comment string"), NULL }, + { "home", 'h', POPT_ARG_STRING, &pc_home, 0, _("Home directory"), NULL }, + { "shell", 's', POPT_ARG_STRING, &pc_shell, 0, _("Login shell"), NULL }, + { "append-group", 'a', POPT_ARG_STRING, NULL, 'a', _("Groups to add this user to"), NULL }, + { "remove-group", 'r', POPT_ARG_STRING, NULL, 'r', _("Groups to remove this user from"), NULL }, + { "lock", 'L', POPT_ARG_NONE, NULL, 'L', _("Lock the account"), NULL }, + { "unlock", 'U', POPT_ARG_NONE, NULL, 'U', _("Unlock the account"), NULL }, POPT_TABLEEND }; poptContext pc = NULL; @@ -324,21 +325,24 @@ int main(int argc, const char **argv) ret = init_sss_tools(&ctx); if (ret != EOK) { - DEBUG(0, ("Could not set up tools\n")); + DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret))); + ERROR("Error initializing the tools\n"); ret = EXIT_FAILURE; goto fini; } user_ctx = talloc_zero(ctx, struct user_mod_ctx); if (user_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for user_ctx context\n")); + DEBUG(1, ("Could not allocate memory for user_ctx context\n")); + ERROR("Out of memory\n"); return ENOMEM; } user_ctx->ctx = ctx; user_ctx->attrs = sysdb_new_attrs(ctx); if (user_ctx->attrs == NULL) { - DEBUG(0, ("Could not allocate memory for sysdb_attrs\n")); + DEBUG(1, ("Could not allocate memory for sysdb_attrs context\n")); + ERROR("Out of memory\n"); return ENOMEM; } @@ -379,7 +383,7 @@ int main(int argc, const char **argv) /* username is an argument without --option */ user_ctx->username = poptGetArg(pc); if (user_ctx->username == NULL) { - usage(pc, "Specify user to modify\n"); + usage(pc, _("Specify user to modify\n")); ret = EXIT_FAILURE; goto fini; } @@ -400,15 +404,20 @@ int main(int argc, const char **argv) case ID_OUTSIDE: ret = usermod_legacy(ctx, user_ctx, pc_uid, pc_gid, pc_gecos, pc_home, pc_shell, pc_lock, ret); + if(ret != EOK) { + ERROR("Cannot delete user from domain using the legacy tools\n"); + } goto fini; case ID_IN_OTHER: - DEBUG(0, ("Cannot delete user from domain %s\n", dom->name)); + DEBUG(1, ("Cannot modify user from domain %s\n", dom->name)); + ERROR("Unsupported domain type\n"); ret = EXIT_FAILURE; goto fini; default: - DEBUG(0, ("Unknown return code from find_domain_for_id")); + DEBUG(1, ("Unknown return code %d from find_domain_for_id\n", ret)); + ERROR("Error looking up domain\n"); ret = EXIT_FAILURE; goto fini; } @@ -420,42 +429,48 @@ int main(int argc, const char **argv) ret = sysdb_attrs_add_string(user_ctx->attrs, SYSDB_SHELL, pc_shell); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_SHELL, + "Could not add attribute to changeset\n"); } if(pc_home) { ret = sysdb_attrs_add_string(user_ctx->attrs, SYSDB_HOMEDIR, pc_home); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_HOMEDIR, + "Could not add attribute to changeset\n"); } if(pc_gecos) { ret = sysdb_attrs_add_string(user_ctx->attrs, SYSDB_GECOS, pc_gecos); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_GECOS, + "Could not add attribute to changeset\n"); } if(pc_uid) { ret = sysdb_attrs_add_long(user_ctx->attrs, SYSDB_UIDNUM, pc_uid); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_UIDNUM, + "Could not add attribute to changeset\n"); } if(pc_gid) { ret = sysdb_attrs_add_long(user_ctx->attrs, SYSDB_GIDNUM, pc_gid); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_GIDNUM, + "Could not add attribute to changeset\n"); } if(pc_lock == DO_LOCK) { ret = sysdb_attrs_add_string(user_ctx->attrs, SYSDB_DISABLED, "true"); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_DISABLED, + "Could not add attribute to changeset\n"); } if(pc_lock == DO_UNLOCK) { @@ -463,7 +478,8 @@ int main(int argc, const char **argv) ret = sysdb_attrs_add_string(user_ctx->attrs, SYSDB_DISABLED, "false"); - VAR_CHECK(ret, EOK, "Could not add attribute to changeset\n"); + VAR_CHECK(ret, EOK, SYSDB_DISABLED, + "Could not add attribute to changeset\n"); } @@ -472,7 +488,7 @@ int main(int argc, const char **argv) if (strcasecmp(dom->name, "LOCAL") == 0) break; } if (dom == NULL) { - DEBUG(0, ("Could not get domain info\n")); + ERROR("Could not get LOCAL domain info\n"); ret = EXIT_FAILURE; goto fini; } @@ -480,8 +496,8 @@ int main(int argc, const char **argv) ret = sysdb_transaction(ctx, ctx->sysdb, mod_user, user_ctx); if (ret != EOK) { - DEBUG(0, ("Could not start transaction (%d)[%s]\n", - ret, strerror(ret))); + DEBUG(1, ("Could not start transaction (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify user.\n"); ret = EXIT_FAILURE; goto fini; } @@ -492,7 +508,8 @@ int main(int argc, const char **argv) if (user_ctx->error) { ret = user_ctx->error; - DEBUG(0, ("Operation failed (%d)[%s]\n", ret, strerror(ret))); + DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret))); + ERROR("Transaction error. Could not modify user.\n"); ret = EXIT_FAILURE; goto fini; } diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c index 15665d3..d15a1a7 100644 --- a/server/tools/tools_util.c +++ b/server/tools/tools_util.c @@ -105,7 +105,7 @@ enum id_domain find_domain_for_id(struct tools_ctx *ctx, } } if (dom == NULL) { - DEBUG(0, ("Could not get LOCAL domain info\n")); + DEBUG(1, ("Could not get LOCAL domain info\n")); *dom_ret = dom; return ID_ERROR; } @@ -239,7 +239,7 @@ int init_sss_tools(struct tools_ctx **ctx) /* Connect to the database */ ret = setup_db(ctx); if (ret != EOK) { - DEBUG(0, ("Could not set up database\n")); + DEBUG(1, ("Could not set up database\n")); ret = EXIT_FAILURE; goto fini; } -- 1.6.2.5