From 3ab98538eda694e1a88a951b6aa2312e653ff04c Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 24 Nov 2009 21:16:40 +0100
Subject: [PATCH] Better error message when there is no local domain configured

Fixes: #235
---
 server/tools/sss_groupadd.c |    6 +++++-
 server/tools/sss_groupdel.c |    6 +++++-
 server/tools/sss_groupmod.c |    6 +++++-
 server/tools/sss_useradd.c  |    6 +++++-
 server/tools/sss_userdel.c  |    6 +++++-
 server/tools/sss_usermod.c  |    6 +++++-
 server/tools/tools_util.c   |    2 +-
 7 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/server/tools/sss_groupadd.c b/server/tools/sss_groupadd.c
index 82d4573..15eed10 100644
--- a/server/tools/sss_groupadd.c
+++ b/server/tools/sss_groupadd.c
@@ -82,7 +82,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_groupdel.c b/server/tools/sss_groupdel.c
index 84ea0be..e5b043e 100644
--- a/server/tools/sss_groupdel.c
+++ b/server/tools/sss_groupdel.c
@@ -77,7 +77,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_groupmod.c b/server/tools/sss_groupmod.c
index d3a3598..b25a018 100644
--- a/server/tools/sss_groupmod.c
+++ b/server/tools/sss_groupmod.c
@@ -107,7 +107,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_useradd.c b/server/tools/sss_useradd.c
index 94de68f..077ac99 100644
--- a/server/tools/sss_useradd.c
+++ b/server/tools/sss_useradd.c
@@ -179,7 +179,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c
index d34466e..e84d78b 100644
--- a/server/tools/sss_userdel.c
+++ b/server/tools/sss_userdel.c
@@ -98,7 +98,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/sss_usermod.c b/server/tools/sss_usermod.c
index 733f998..a272bc5 100644
--- a/server/tools/sss_usermod.c
+++ b/server/tools/sss_usermod.c
@@ -122,7 +122,11 @@ int main(int argc, const char **argv)
     ret = init_sss_tools(&tctx);
     if (ret != EOK) {
         DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
-        ERROR("Error initializing the tools\n");
+        if (ret == ENOENT) {
+            ERROR("Error initializing the tools - no local domain\n");
+        } else {
+            ERROR("Error initializing the tools\n");
+        }
         ret = EXIT_FAILURE;
         goto fini;
     }
diff --git a/server/tools/tools_util.c b/server/tools/tools_util.c
index bcb8d5c..b509ccb 100644
--- a/server/tools/tools_util.c
+++ b/server/tools/tools_util.c
@@ -64,7 +64,7 @@ static int setup_db(struct tools_ctx *ctx)
 
     ret = confdb_get_domain(ctx->confdb, "local", &ctx->local);
     if (ret != EOK) {
-        DEBUG(1, ("Could not get 'local' domain\n"));
+        DEBUG(1, ("Could not get 'local' domain: [%d] [%s]\n", ret, strerror(ret)));
         return ret;
     }
 
-- 
1.6.2.5

