sssctl.c revision a0b824ac01c6b58fe6055d48aa6e29e94219646d
/*
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"
#ifdef HAVE_SYSTEMD
#else
#endif
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
sssctl_prompt(const char *message,
enum sssctl_prompt_result defval)
{
char answer[255] = {0};
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;
}
{
#if defined(HAVE_SYSTEMD) || defined(HAVE_SERVICE)
switch (action) {
case SSSCTL_SVC_START:
case SSSCTL_SVC_STOP:
case SSSCTL_SVC_RESTART:
}
#endif
return ENOSYS;
}
bool sssctl_start_sssd(bool force)
{
enum sssctl_prompt_result prompt;
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;
}
bool sssctl_stop_sssd(bool force)
{
enum sssctl_prompt_result prompt;
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;
}
bool sssctl_restart_sssd(bool force)
{
enum sssctl_prompt_result prompt;
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;
}
{
struct sss_route_cmd commands[] = {
SSS_TOOL_DELIMITER("SSSD Status:"),
SSS_TOOL_DELIMITER("Information about cached content:"),
SSS_TOOL_DELIMITER("Local data tools:"),
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:"),
};
}