From e1fdffdf9e94dee7de479c155188b80fd41dbcc8 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Fri, 3 Jul 2009 14:34:47 +0200 Subject: Check for root before initializing Also move setting locale to separate function to be called before anything else to make sure the "Not root" message would be localized. --- server/tools/tools_util.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'server/tools/tools_util.c') diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c index d15a1a78..0d3220ee 100644 --- a/server/tools/tools_util.c +++ b/server/tools/tools_util.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "util/util.h" #include "confdb/confdb.h" @@ -228,13 +229,33 @@ int parse_groups(TALLOC_CTX *mem_ctx, const char *optstr, char ***_out) return EOK; } +int set_locale(void) +{ + char *c; + + c = setlocale(LC_ALL, ""); + if (c == NULL) { + return EIO; + } + + errno = 0; + c = bindtextdomain(PACKAGE, LOCALEDIR); + if (c == NULL) { + return errno; + } + + errno = 0; + c = textdomain(PACKAGE); + if (c == NULL) { + return errno; + } + + return EOK; +} + int init_sss_tools(struct tools_ctx **ctx) { int ret; - /* Set up LOCALE */ - setlocale (LC_ALL, ""); - bindtextdomain (PACKAGE, LOCALEDIR); - textdomain (PACKAGE); /* Connect to the database */ ret = setup_db(ctx); @@ -248,3 +269,4 @@ int init_sss_tools(struct tools_ctx **ctx) fini: return ret; } + -- cgit