e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina Pavel Březina <pbrezina@redhat.com>
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina Copyright (C) 2016 Red Hat
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina This program is free software; you can redistribute it and/or modify
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina it under the terms of the GNU General Public License as published by
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina the Free Software Foundation; either version 3 of the License, or
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina (at your option) any later version.
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina This program is distributed in the hope that it will be useful,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina GNU General Public License for more details.
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina You should have received a copy of the GNU General Public License
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#define SSS_BACKUP_USER_OVERRIDES SSS_BACKUP_DIR "/sssd_user_overrides.bak"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#define SSS_BACKUP_GROUP_OVERRIDES SSS_BACKUP_DIR "/sssd_group_overrides.bak"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastatic errno_t sssctl_create_backup_dir(const char *path)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Unable to create backup directory "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastatic bool sssctl_backup_file_exists(const char *file)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastatic bool sssctl_backup_exist(const char **files)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return false;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina const char *files[] = {SSS_BACKUP_USER_OVERRIDES,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_create_backup_dir(SSS_BACKUP_DIR);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to create backup directory [%d]: %s"),
9be0fce9bc1f48241425726ddd612ffd64556715Fabiano Fidêncio prompt = sssctl_prompt(_("SSSD backup of local data already exists, "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* continue */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_run_command("sss_override user-export "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to export user overrides\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_run_command("sss_override group-export "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to export group overrides\n"));
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_client_data_backup(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"override", 'o', POPT_ARG_NONE, &opts.override, 0, _("Override existing backup"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sss_tool_popt(cmdline, options, SSS_TOOL_OPT_OPTIONAL, NULL, NULL);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březinastatic errno_t sssctl_restore(bool force_start, bool force_restart)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (sssctl_backup_file_exists(SSS_BACKUP_USER_OVERRIDES)) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_run_command("sss_override user-import "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to import user overrides\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (sssctl_backup_file_exists(SSS_BACKUP_USER_OVERRIDES)) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_run_command("sss_override group-import "
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to import group overrides\n"));
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_client_data_restore(struct sss_cmdline *cmdline,
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina /* Parse command line. */
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina {"start", 's', POPT_ARG_NONE, &opts.start, 0, _("Start SSSD if it is not running"), NULL },
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina {"restart", 'r', POPT_ARG_NONE, &opts.restart, 0, _("Restart SSSD after data import"), NULL },
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina ret = sss_tool_popt(cmdline, options, SSS_TOOL_OPT_OPTIONAL, NULL, NULL);
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina return sssctl_restore(opts.start, opts.restart);
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_cache_remove(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"override", 'o', POPT_ARG_NONE, &opts.override, 0, _("Override existing backup"), NULL },
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina {"restore", 'r', POPT_ARG_NONE, &opts.restore, 0, _("Create clean cache files and import local data"), NULL },
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina {"stop", 'p', POPT_ARG_NONE, &opts.stop, 0, _("Stop SSSD before removing the cache"), NULL },
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina {"start", 's', POPT_ARG_NONE, &opts.start, 0, _("Start SSSD when the cache is removed"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sss_tool_popt(cmdline, options, SSS_TOOL_OPT_OPTIONAL, NULL, NULL);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
b6cc93b259b96408a827a4349a98600c0b2f6660Pavel Březina fprintf(stderr, "Unable to remove the cache unless SSSD is stopped.\n");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina printf(_("Creating backup of local data...\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to create backup of local data,"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina " can not remove the cache.\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to remove cache files\n"));
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_cache_upgrade(struct sss_cmdline *cmdline,
55857e924977dbc66958f8033c6b38d6262ee631Michal Židek ret = sss_tool_popt(cmdline, NULL, SSS_TOOL_OPT_OPTIONAL, NULL, NULL);
55857e924977dbc66958f8033c6b38d6262ee631Michal Židek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
552390afcc81af96ca201fa6c25ddefbbecbeb4eJakub Hrozek ret = confdb_get_domains(tool_ctx->confdb, &tool_ctx->domains);
552390afcc81af96ca201fa6c25ddefbbecbeb4eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "No domains configured.\n");
552390afcc81af96ca201fa6c25ddefbbecbeb4eJakub Hrozek ret = sysdb_init_ext(tool_ctx, tool_ctx->domains, &db_up_ctx,
552390afcc81af96ca201fa6c25ddefbbecbeb4eJakub Hrozek true, 0, 0);
f74408e37a3007aa41b19ab2afb693a91694da42Justin Stephensonerrno_t sssctl_cache_expire(struct sss_cmdline *cmdline,
f74408e37a3007aa41b19ab2afb693a91694da42Justin Stephenson cmd_args = talloc_strdup_append(cmd_args, cmdline->argv[i]);
f74408e37a3007aa41b19ab2afb693a91694da42Justin Stephenson cmd_args = talloc_strdup_append(cmd_args, " ");