summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-07-01 13:26:38 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-07-07 10:30:18 +0200
commita0b824ac01c6b58fe6055d48aa6e29e94219646d (patch)
treeb9154d25cc54ef10e8ce46c58ab5e97dd368d497
parent1ea5a9c1930f531b21f8bc67c9c071d8ce533786 (diff)
downloadsssd-a0b824ac01c6b58fe6055d48aa6e29e94219646d.zip
sssd-a0b824ac01c6b58fe6055d48aa6e29e94219646d.tar.gz
sssd-a0b824ac01c6b58fe6055d48aa6e29e94219646d.tar.xz
TOOLS: Some tools command might not need initialization to succeed
Since we want to use the sssctl tool during upgrade, we need to amend the tools initialization code to not error out if sysdb can't be instantiated, but rather return errno and let the tool handle the error. Each tool command now has a 'allowed errno' the command is able to handle. In this patch iteration, only a single errno can be handled and only the upgrade command is able to do so. Reviewed-by: Sumit Bose <sbose@redhat.com>
-rw-r--r--src/tools/common/sss_tools.c45
-rw-r--r--src/tools/common/sss_tools.h11
-rw-r--r--src/tools/sss_override.c26
-rw-r--r--src/tools/sssctl/sssctl.c22
4 files changed, 66 insertions, 38 deletions
diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c
index a78a5ba..686b53a 100644
--- a/src/tools/common/sss_tools.c
+++ b/src/tools/common/sss_tools.c
@@ -136,7 +136,6 @@ static errno_t sss_tool_domains_init(TALLOC_CTX *mem_ctx,
}
ret = sysdb_init(mem_ctx, domains);
- SYSDB_VERSION_ERROR(ret);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Could not initialize connection to the sysdb\n");
@@ -178,8 +177,9 @@ static errno_t sss_tool_domains_init(TALLOC_CTX *mem_ctx,
return ret;
}
-struct sss_tool_ctx *sss_tool_init(TALLOC_CTX *mem_ctx,
- int *argc, const char **argv)
+errno_t sss_tool_init(TALLOC_CTX *mem_ctx,
+ int *argc, const char **argv,
+ struct sss_tool_ctx **_tool_ctx)
{
struct sss_tool_ctx *tool_ctx;
errno_t ret;
@@ -187,7 +187,7 @@ struct sss_tool_ctx *sss_tool_init(TALLOC_CTX *mem_ctx,
tool_ctx = talloc_zero(mem_ctx, struct sss_tool_ctx);
if (tool_ctx == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero() failed\n");
- return NULL;
+ return ENOMEM;
}
sss_tool_common_opts(tool_ctx, argc, argv);
@@ -221,11 +221,16 @@ struct sss_tool_ctx *sss_tool_init(TALLOC_CTX *mem_ctx,
ret = EOK;
done:
- if (ret != EOK) {
- talloc_zfree(tool_ctx);
+ switch (ret) {
+ case EOK:
+ case ERR_SYSDB_VERSION_TOO_OLD:
+ *_tool_ctx = tool_ctx;
+ break;
+ default:
+ break;
}
- return tool_ctx;
+ return ret;
}
static bool sss_tool_is_delimiter(struct sss_route_cmd *command)
@@ -237,6 +242,16 @@ static bool sss_tool_is_delimiter(struct sss_route_cmd *command)
return false;
}
+static bool sss_tools_handles_init_error(struct sss_route_cmd *command,
+ errno_t init_err)
+{
+ if (init_err == EOK) {
+ return true;
+ }
+
+ return command->handles_init_err == init_err;
+}
+
static size_t sss_tool_max_length(struct sss_route_cmd *commands)
{
size_t max = 0;
@@ -316,6 +331,14 @@ errno_t sss_tool_route(int argc, const char **argv,
cmdline.argc = argc - 2;
cmdline.argv = argv + 2;
+ if (!sss_tools_handles_init_error(&commands[i], tool_ctx->init_err)) {
+ DEBUG(SSSDBG_FATAL_FAILURE,
+ "Command %s does not handle initialization error [%d] %s\n",
+ cmdline.command, tool_ctx->init_err,
+ sss_strerror(tool_ctx->init_err));
+ return tool_ctx->init_err;
+ }
+
return commands[i].fn(&cmdline, tool_ctx, pvt);
}
}
@@ -477,15 +500,17 @@ int sss_tool_main(int argc, const char **argv,
return EXIT_FAILURE;
}
- tool_ctx = sss_tool_init(NULL, &argc, argv);
- if (tool_ctx == NULL) {
+ ret = sss_tool_init(NULL, &argc, argv, &tool_ctx);
+ if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
+ tool_ctx->init_err = ret;
+ } else if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
return EXIT_FAILURE;
}
ret = sss_tool_route(argc, argv, tool_ctx, commands, pvt);
+ SYSDB_VERSION_ERROR(ret);
talloc_free(tool_ctx);
-
if (ret != EOK) {
return EXIT_FAILURE;
}
diff --git a/src/tools/common/sss_tools.h b/src/tools/common/sss_tools.h
index 0dfd483..a9ebabe 100644
--- a/src/tools/common/sss_tools.h
+++ b/src/tools/common/sss_tools.h
@@ -29,12 +29,14 @@
struct sss_tool_ctx {
struct confdb_ctx *confdb;
+ errno_t init_err;
char *default_domain;
struct sss_domain_info *domains;
};
-struct sss_tool_ctx *sss_tool_init(TALLOC_CTX *mem_ctx,
- int *argc, const char **argv);
+errno_t sss_tool_init(TALLOC_CTX *mem_ctx,
+ int *argc, const char **argv,
+ struct sss_tool_ctx **_tool_ctx);
struct sss_cmdline;
@@ -43,12 +45,13 @@ typedef errno_t
struct sss_tool_ctx *tool_ctx,
void *pvt);
-#define SSS_TOOL_COMMAND(cmd, msg, fn) {cmd, _(msg), fn}
-#define SSS_TOOL_DELIMITER(message) {"", (message), NULL}
+#define SSS_TOOL_COMMAND(cmd, msg, err, fn) {cmd, _(msg), err, fn}
+#define SSS_TOOL_DELIMITER(message) {"", (message), 0, NULL}
struct sss_route_cmd {
const char *command;
const char *description;
+ errno_t handles_init_err;
sss_route_fn fn;
};
diff --git a/src/tools/sss_override.c b/src/tools/sss_override.c
index e497d12..45a28fd 100644
--- a/src/tools/sss_override.c
+++ b/src/tools/sss_override.c
@@ -1913,19 +1913,19 @@ static int override_group_export(struct sss_cmdline *cmdline,
int main(int argc, const char **argv)
{
struct sss_route_cmd commands[] = {
- {"user-add", NULL, override_user_add},
- {"user-del", NULL, override_user_del},
- {"user-find", NULL, override_user_find},
- {"user-show", NULL, override_user_show},
- {"user-import", NULL, override_user_import},
- {"user-export", NULL, override_user_export},
- {"group-add", NULL, override_group_add},
- {"group-del", NULL, override_group_del},
- {"group-find", NULL, override_group_find},
- {"group-show", NULL, override_group_show},
- {"group-import", NULL, override_group_import},
- {"group-export", NULL, override_group_export},
- {NULL, NULL, NULL}
+ {"user-add", NULL, 0, override_user_add},
+ {"user-del", NULL, 0, override_user_del},
+ {"user-find", NULL, 0, override_user_find},
+ {"user-show", NULL, 0, override_user_show},
+ {"user-import", NULL, 0, override_user_import},
+ {"user-export", NULL, 0, override_user_export},
+ {"group-add", NULL, 0, override_group_add},
+ {"group-del", NULL, 0, override_group_del},
+ {"group-find", NULL, 0, override_group_find},
+ {"group-show", NULL, 0, override_group_show},
+ {"group-import", NULL, 0, override_group_import},
+ {"group-export", NULL, 0, override_group_export},
+ {NULL, NULL, 0, NULL}
};
return sss_tool_main(argc, argv, commands, NULL);
diff --git a/src/tools/sssctl/sssctl.c b/src/tools/sssctl/sssctl.c
index 58bbbf2..8e18569 100644
--- a/src/tools/sssctl/sssctl.c
+++ b/src/tools/sssctl/sssctl.c
@@ -257,20 +257,20 @@ int main(int argc, const char **argv)
{
struct sss_route_cmd commands[] = {
SSS_TOOL_DELIMITER("SSSD Status:"),
- SSS_TOOL_COMMAND("list-domains", "List available domains", sssctl_list_domains),
- SSS_TOOL_COMMAND("domain-status", "Print information about domain", sssctl_domain_status),
+ SSS_TOOL_COMMAND("list-domains", "List available domains", 0, sssctl_list_domains),
+ SSS_TOOL_COMMAND("domain-status", "Print information about domain", 0, sssctl_domain_status),
SSS_TOOL_DELIMITER("Information about cached content:"),
- SSS_TOOL_COMMAND("user", "Information about cached user", sssctl_user),
- SSS_TOOL_COMMAND("group", "Information about cached group", sssctl_group),
- SSS_TOOL_COMMAND("netgroup", "Information about cached netgroup", sssctl_netgroup),
+ SSS_TOOL_COMMAND("user", "Information about cached user", 0, sssctl_user),
+ SSS_TOOL_COMMAND("group", "Information about cached group", 0, sssctl_group),
+ SSS_TOOL_COMMAND("netgroup", "Information about cached netgroup", 0, sssctl_netgroup),
SSS_TOOL_DELIMITER("Local data tools:"),
- SSS_TOOL_COMMAND("backup-local-data", "Backup local data", sssctl_backup_local_data),
- SSS_TOOL_COMMAND("restore-local-data", "Restore local data from backup", sssctl_restore_local_data),
- SSS_TOOL_COMMAND("remove-cache", "Backup local data and remove cached content", sssctl_remove_cache),
+ SSS_TOOL_COMMAND("backup-local-data", "Backup local data", 0, sssctl_backup_local_data),
+ SSS_TOOL_COMMAND("restore-local-data", "Restore local data from backup", 0, sssctl_restore_local_data),
+ SSS_TOOL_COMMAND("remove-cache", "Backup local data and remove cached content", 0, sssctl_remove_cache),
SSS_TOOL_DELIMITER("Log files tools:"),
- SSS_TOOL_COMMAND("remove-logs", "Remove existing SSSD log files", sssctl_remove_logs),
- SSS_TOOL_COMMAND("fetch-logs", "Archive SSSD log files in tarball", sssctl_fetch_logs),
- {NULL, NULL, NULL}
+ SSS_TOOL_COMMAND("remove-logs", "Remove existing SSSD log files", 0, sssctl_remove_logs),
+ SSS_TOOL_COMMAND("fetch-logs", "Archive SSSD log files in tarball", 0, sssctl_fetch_logs),
+ {NULL, NULL, 0, NULL}
};
return sss_tool_main(argc, argv, commands, NULL);