summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/po/POTFILES.in1
-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
9 files changed, 99 insertions, 4 deletions
diff --git a/server/po/POTFILES.in b/server/po/POTFILES.in
index 8de37f6b..3f3e10a5 100644
--- a/server/po/POTFILES.in
+++ b/server/po/POTFILES.in
@@ -4,6 +4,7 @@ tools/sss_groupdel.c
tools/sss_groupmod.c
tools/sss_userdel.c
tools/tools_util.c
+tools/tools_util.h
tools/sss_useradd.c
tools/sss_groupadd.c
tools/sss_usermod.c
diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c
index ea732016..70505671 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 194285c9..50ed112a 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 cc7665d9..30f8e54b 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 ed9974fe..e78e11cd 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 bb0673b0..857057fd 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 521c5264..1b1478af 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 d15a1a78..0d3220ee 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 7c66c119..0520731a 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__ */