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/>.
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephensonerrno_t set_debug_level(struct debuglevel_tool_ctx *tool_ctx,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson int debug_to_set, const char *config_file)
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* convert debug_to_set to string */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson values[0] = talloc_asprintf(tmp_ctx, "0x%.4x", debug_to_set);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* write to confdb */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson for (section = tool_ctx->sections; *section != NULL; section++) {
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = confdb_add_param(tool_ctx->confdb, 1, *section,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson * Change atime and mtime of sssd.conf,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson * so the configuration can be restored on next start.
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_MINOR_FAILURE, "Unable to change mtime of \"%s\": %s\n",
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephensonerrno_t connect_to_confdb(TALLOC_CTX *ctx, struct confdb_ctx **cdb_ctx)
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Could not allocate memory for confdb path\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = confdb_init(ctx, cdb_ctx, confdb_path);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Could not initialize connection to the confdb\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephensonerrno_t get_confdb_sections(TALLOC_CTX *ctx, struct confdb_ctx *confdb,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson struct sss_domain_info *domain_list = NULL;
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson static const int known_services_count = sizeof(known_services)
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* get domains */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = confdb_get_domains(confdb, &domain_list);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get domain list\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* allocate output space */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Could not allocate memory for sections\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson for (i = 0; i < known_services_count; i++) {
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson sections[i] = talloc_strdup(tmp_ctx, known_services[i]);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson domain = get_next_domain(domain, 0), i++) {
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson sections[i] = talloc_asprintf(tmp_ctx, CONFDB_DOMAIN_PATH_TMPL,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf() failed\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* add NULL to the end */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson *output_sections = talloc_steal(ctx, sections);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephensonint parse_debug_level(const char *strlevel)
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson if ((errno != 0) || (endptr == strlevel) || (*endptr != '\0')) {
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_logs_remove(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"delete", 'd', POPT_ARG_NONE, &opts.delete, 0, _("Delete log files instead of truncating"), 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");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to remove log files\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sssctl_run_command("truncate --size 0 " LOG_FILES);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to truncate log files\n"));
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_logs_fetch(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sss_tool_popt_ex(cmdline, NULL, SSS_TOOL_OPT_OPTIONAL, NULL, NULL,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina cmd = talloc_asprintf(tool_ctx, "tar -czf %s %s", file, LOG_FILES);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina printf(_("Archiving log files into %s...\n"), file);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina fprintf(stderr, _("Unable to archive log files\n"));
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephensonerrno_t sssctl_debug_level(struct sss_cmdline *cmdline,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson {"config", 'c', POPT_ARG_STRING, &pc_config_file,
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson 0, _("Specify a non-default config file"), NULL},
40151421697db0910c454d1af441cce4962dfb0bLukas Slebodnik ret = sss_tool_popt_ex(cmdline, long_options, SSS_TOOL_OPT_OPTIONAL, NULL,
40151421697db0910c454d1af441cce4962dfb0bLukas Slebodnik _("Specify debug level you want to set"),
40151421697db0910c454d1af441cce4962dfb0bLukas Slebodnik DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* get config file */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson config_file = talloc_strdup(ctx, pc_config_file);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson config_file = talloc_strdup(ctx, SSSD_CONFIG_FILE);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strdup() failed\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* free pc_config_file? */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* free debug_as_string? */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson debug_to_set = parse_debug_level(debug_as_string);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson CHECK(debug_to_set == SSSDBG_INVALID, fini, "Invalid debug level.");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson /* allocate context */
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ctx = talloc_zero(NULL, struct debuglevel_tool_ctx);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Could not allocate memory for tools context\n");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = connect_to_confdb(ctx, &ctx->confdb);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson CHECK(ret != EOK, fini, "Could not connect to configuration database.");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = get_confdb_sections(ctx, ctx->confdb, &ctx->sections);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson CHECK(ret != EOK, fini, "Could not get all configuration sections.");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson ret = set_debug_level(ctx, debug_to_set, config_file);
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson CHECK(ret != EOK, fini, "Could not set debug level.");
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Could not force sssd processes to reload configuration. "
d2c614143870e6efd4b3ab20c3a55cf714595256Justin Stephenson "Is sssd running?");