summaryrefslogtreecommitdiffstats
path: root/server/tools
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2009-07-03 14:34:47 +0200
committerSimo Sorce <ssorce@redhat.com>2009-07-06 13:02:29 -0400
commite1fdffdf9e94dee7de479c155188b80fd41dbcc8 (patch)
tree59e266c1a5cfc879f2badb983e0a8bc4ed74033c /server/tools
parentbc1352717c7354005b4e6f70b6a51ed6b5146796 (diff)
downloadsssd-e1fdffdf9e94dee7de479c155188b80fd41dbcc8.tar.gz
sssd-e1fdffdf9e94dee7de479c155188b80fd41dbcc8.tar.xz
sssd-e1fdffdf9e94dee7de479c155188b80fd41dbcc8.zip
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.
Diffstat (limited to 'server/tools')
-rw-r--r--server/tools/sss_groupadd.c10
-rw-r--r--server/tools/sss_groupdel.c10
-rw-r--r--server/tools/sss_groupmod.c10
-rw-r--r--server/tools/sss_useradd.c10
-rw-r--r--server/tools/sss_userdel.c10
-rw-r--r--server/tools/sss_usermod.c10
-rw-r--r--server/tools/tools_util.c30
-rw-r--r--server/tools/tools_util.h12
8 files changed, 98 insertions, 4 deletions
diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c
index ea73201..7050567 100644
--- a/server/tools/sss_groupadd.c
+++ b/server/tools/sss_groupadd.c
@@ -24,6 +24,7 @@
#include <talloc.h>
#include <popt.h>
#include <errno.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -176,6 +177,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if(ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/sss_groupdel.c b/server/tools/sss_groupdel.c
index 194285c..50ed112 100644
--- a/server/tools/sss_groupdel.c
+++ b/server/tools/sss_groupdel.c
@@ -26,6 +26,7 @@
#include <grp.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "db/sysdb.h"
#include "util/util.h"
@@ -171,6 +172,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if(ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/sss_groupmod.c b/server/tools/sss_groupmod.c
index cc7665d..30f8e54 100644
--- a/server/tools/sss_groupmod.c
+++ b/server/tools/sss_groupmod.c
@@ -27,6 +27,7 @@
#include <grp.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "util/util.h"
#include "db/sysdb.h"
@@ -349,6 +350,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if (ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/sss_useradd.c b/server/tools/sss_useradd.c
index ed9974f..e78e11c 100644
--- a/server/tools/sss_useradd.c
+++ b/server/tools/sss_useradd.c
@@ -27,6 +27,7 @@
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "util/util.h"
#include "db/sysdb.h"
@@ -391,6 +392,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if (ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c
index bb0673b..857057f 100644
--- a/server/tools/sss_userdel.c
+++ b/server/tools/sss_userdel.c
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <pwd.h>
+#include <unistd.h>
#include "db/sysdb.h"
#include "util/util.h"
@@ -172,6 +173,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if(ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/sss_usermod.c b/server/tools/sss_usermod.c
index 521c526..1b1478a 100644
--- a/server/tools/sss_usermod.c
+++ b/server/tools/sss_usermod.c
@@ -27,6 +27,7 @@
#include <pwd.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <unistd.h>
#include "util/util.h"
#include "db/sysdb.h"
@@ -406,6 +407,15 @@ int main(int argc, const char **argv)
debug_prg_name = argv[0];
+ ret = set_locale();
+ if (ret != EOK) {
+ DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
+ ERROR("Error setting the locale\n");
+ ret = EXIT_FAILURE;
+ goto fini;
+ }
+ CHECK_ROOT(ret, debug_prg_name);
+
ret = init_sss_tools(&ctx);
if (ret != EOK) {
DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c
index d15a1a7..0d3220e 100644
--- a/server/tools/tools_util.c
+++ b/server/tools/tools_util.c
@@ -22,6 +22,7 @@
#include <talloc.h>
#include <tevent.h>
#include <popt.h>
+#include <errno.h>
#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;
}
+
diff --git a/server/tools/tools_util.h b/server/tools/tools_util.h
index 7c66c11..0520731 100644
--- a/server/tools/tools_util.h
+++ b/server/tools/tools_util.h
@@ -22,6 +22,16 @@
} \
} while(0)
+#define CHECK_ROOT(val, prg_name) do { \
+ val = getuid(); \
+ if (val != 0) { \
+ DEBUG(1, ("Running under %d, must be root\n", val)); \
+ ERROR("%s must be run as root\n", prg_name); \
+ val = EXIT_FAILURE; \
+ goto fini; \
+ } \
+} while(0)
+
enum id_domain {
ID_IN_LOCAL = 0,
ID_IN_LEGACY_LOCAL,
@@ -50,4 +60,6 @@ enum id_domain find_domain_for_id(struct tools_ctx *ctx,
uint32_t id,
struct sss_domain_info **dom_ret);
+int set_locale(void);
+
#endif /* __TOOLS_UTIL_H__ */