Skip to content

Commit

Permalink
Gettextize the sss_ tools
Browse files Browse the repository at this point in the history
  • Loading branch information
jhrozek authored and sgallagher committed Jul 2, 2009
1 parent 224c993 commit be22e71
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 109 deletions.
35 changes: 22 additions & 13 deletions server/tools/sss_groupadd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -180,24 +183,29 @@ 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;
}

/* 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;
}
Expand All @@ -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;
Expand Down
32 changes: 22 additions & 10 deletions server/tools/sss_groupdel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -121,22 +121,24 @@ 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
};

debug_prg_name = argv[0];

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;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
47 changes: 25 additions & 22 deletions server/tools/sss_groupmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit be22e71

Please sign in to comment.