/*
Authors:
Pavel Březina <pbrezina@redhat.com>
Copyright (C) 2016 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdio.h>
#include "tools/common/sss_tools.h"
#include "tools/common/sss_process.h"
static const char *
{
switch (result) {
case SSSCTL_PROMPT_YES:
return _("yes");
case SSSCTL_PROMPT_NO:
return _("no");
case SSSCTL_PROMPT_ERROR:
return _("error");
}
return _("Invalid result.");
}
enum sssctl_prompt_result
enum sssctl_prompt_result defval)
{
int c;
int attempts = 0;
int ret;
do {
if (defval != SSSCTL_PROMPT_ERROR) {
/* Detect empty line. */
c = getchar();
if (c == '\n') {
return defval;
} else {
}
} else {
}
/* Clear stdin. */
if (ret != 1) {
return SSSCTL_PROMPT_ERROR;
}
return SSSCTL_PROMPT_YES;
}
return SSSCTL_PROMPT_NO;
}
attempts++;
} while (attempts < 3);
return SSSCTL_PROMPT_ERROR;
}
{
int ret;
if (ret == -1) {
return EFAULT;
} else if (WEXITSTATUS(ret) != 0) {
return EIO;
}
return EOK;
}
{
#ifdef HAVE_SYSTEMD
switch (action) {
case SSSCTL_SVC_START:
return sssctl_systemd_start();
case SSSCTL_SVC_STOP:
return sssctl_systemd_stop();
case SSSCTL_SVC_RESTART:
return sssctl_systemd_restart();
}
#elif defined(HAVE_SERVICE)
switch (action) {
case SSSCTL_SVC_START:
case SSSCTL_SVC_STOP:
case SSSCTL_SVC_RESTART:
}
#endif
return ENOSYS;
}
{
if (sss_deamon_running()) {
return true;
}
if (!force) {
switch (prompt) {
case SSSCTL_PROMPT_YES:
/* continue */
break;
case SSSCTL_PROMPT_NO:
case SSSCTL_PROMPT_ERROR:
return false;
}
}
switch(ret) {
case EOK:
return true;
case ENOSYS:
"on this platform, please start the service "
"manually\n");
return false;
default:
return false;
}
return true;
}
{
if (!sss_deamon_running()) {
return true;
}
if (!force) {
switch (prompt) {
case SSSCTL_PROMPT_YES:
/* continue */
break;
case SSSCTL_PROMPT_NO:
case SSSCTL_PROMPT_ERROR:
return false;
}
}
switch(ret) {
case EOK:
return true;
case ENOSYS:
"on this platform, please stop the service "
"manually\n");
return false;
default:
return false;
}
return true;
}
{
if (!force) {
switch (prompt) {
case SSSCTL_PROMPT_YES:
/* continue */
break;
case SSSCTL_PROMPT_NO:
case SSSCTL_PROMPT_ERROR:
return false;
}
}
switch(ret) {
case EOK:
return true;
case ENOSYS:
"on this platform, please restart the service "
"manually\n");
return false;
default:
return false;
}
return true;
}
{
SSS_TOOL_DELIMITER("SSSD Status:"),
SSS_TOOL_DELIMITER("Information about cached content:"),
SSS_TOOL_DELIMITER("Local data tools:"),
SSS_TOOL_COMMAND("client-data-restore", "Restore local data from backup", 0, sssctl_client_data_restore),
SSS_TOOL_COMMAND("cache-remove", "Backup local data and remove cached content", 0, sssctl_cache_remove),
SSS_TOOL_COMMAND("cache-upgrade", "Perform cache upgrade", ERR_SYSDB_VERSION_TOO_OLD, sssctl_cache_upgrade),
SSS_TOOL_DELIMITER("Log files tools:"),
#ifdef HAVE_LIBINI_CONFIG_V1_3
SSS_TOOL_DELIMITER("Configuration files tools:"),
SSS_TOOL_COMMAND_FLAGS("config-check", "Perform static analysis of SSSD configuration", 0, sssctl_config_check, SSS_TOOL_FLAG_SKIP_CMD_INIT),
#endif
};
}