sssd/0031-sssctl-move-check-for-version-error-to-correct-place.patch

91 lines
5.4 KiB
Diff
Raw Normal View History

From 08fced82ad1a8bc03c69f84bcfdb495a5f473165 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 3 Apr 2018 10:20:29 +0200
Subject: [PATCH] sssctl: move check for version error to correct place
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This check was added here:
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 490) int sss_tool_main(int argc, const char **argv,
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 491) struct sss_route_cmd *commands,
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 492) void *pvt)
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 493) {
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 494) struct sss_tool_ctx *tool_ctx;
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 495) uid_t uid;
e98ccef2 (Pavel Březina 2016-06-09 16:13:34 +0200 496) errno_t ret;
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 497)
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 498) uid = getuid();
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 499) if (uid != 0) {
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 500) DEBUG(SSSDBG_CRIT_FAILURE, "Running under %d, must be root\n", uid);
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 501) ERROR("%1$s must be run as root\n", argv[0]);
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 502) return EXIT_FAILURE;
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 503) }
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 504)
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 505) ret = sss_tool_init(NULL, &argc, argv, &tool_ctx);
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 506) if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 507) tool_ctx->init_err = ret;
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 508) } else if (ret != EOK) {
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 509) DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 510) return EXIT_FAILURE;
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 511) }
But then the initialization code was moved from sss_tool_init to tool_cmd_init which is called from sss_tool_route.
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 328) if (!sss_tools_handles_init_error(&commands[i], tool_ctx->init_err)) {
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 329) DEBUG(SSSDBG_FATAL_FAILURE,
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 330) "Command %s does not handle initialization error [%d] %s\n",
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 331) cmdline.command, tool_ctx->init_err,
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 332) sss_strerror(tool_ctx->init_err));
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 333) return tool_ctx->init_err;
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 334) }
a0b824ac (Jakub Hrozek 2016-07-01 13:26:38 +0200 335)
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 336) ret = tool_cmd_init(tool_ctx, &commands[i]);
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 337) if (ret != EOK) {
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 338) DEBUG(SSSDBG_FATAL_FAILURE,
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 339) "Command initialization failed [%d] %s\n",
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 340) ret, sss_strerror(ret));
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 341) return ret;
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 342) }
cbee11e9 (Michal Židek 2016-10-12 13:09:37 +0200 343)
284937e6 (Pavel Březina 2015-07-22 10:02:02 +0200 344) return commands[i].fn(&cmdline, tool_ctx, pvt);
This rendered the original change a dead code, because sss_tool_init only returns ENOMEM or EOK.
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
(cherry picked from commit fe58f0fbf34de5931ce3305396e5e4467796a325)
---
src/tools/common/sss_tools.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/tools/common/sss_tools.c b/src/tools/common/sss_tools.c
index d45584ce1..701db2d93 100644
--- a/src/tools/common/sss_tools.c
+++ b/src/tools/common/sss_tools.c
@@ -346,7 +346,9 @@ errno_t sss_tool_route(int argc, const char **argv,
if (!tool_ctx->print_help) {
ret = tool_cmd_init(tool_ctx, &commands[i]);
- if (ret != EOK) {
+ if (ret == ERR_SYSDB_VERSION_TOO_OLD) {
+ tool_ctx->init_err = ret;
+ } else if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE,
"Command initialization failed [%d] %s\n",
ret, sss_strerror(ret));
@@ -516,9 +518,7 @@ int sss_tool_main(int argc, const char **argv,
}
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) {
+ if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create tool context\n");
return EXIT_FAILURE;
}
--
2.14.3