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/>.
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson#define SSS_SIFP_ATTR_SUBDOMAIN "subdomain"
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephensonerrno_t domain_is_subdomain_check(sss_sifp_ctx *sifp_ctx,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson error = sss_sifp_fetch_domain_by_name(sifp_ctx, domain, &domain_obj);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sssctl_sifp_error(sifp_ctx, error, "Unable to fetch domain by name");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson error = sss_sifp_find_attr_as_bool(domain_obj->attrs,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sssctl_sifp_error(sifp_ctx, error, "Unable to find subdomain attr");
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_domain_list(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"start", 's', POPT_ARG_NONE, &start, 0, _("Start SSSD if it is not running"), NULL },
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, _("Show domain list including primary or trusted domain type"), 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 sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina error = sss_sifp_list_domains(sifp, &domains);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina sssctl_sifp_error(sifp, error, "Unable to get domains list");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson ret = domain_is_subdomain_check(sifp, domains[i], &is_subdom);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "Subdomain check failed\n");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson printf("Trusted domain: %s\n", domains[i]);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson printf("Primary domain: %s\n", domains[i]);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastatic errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get online status");
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_BOOLEAN, &is_online);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina printf(_("Online status: %s\n"), is_online ? _("Online") : _("Offline"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic const char *proper_service_name(const char *service)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return "AD Global Catalog";
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return "AD Domain Controller";
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina } else if (strncasecmp(service, "sd_gc_", strlen("sd_gc_")) == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return "AD Global Catalog";
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina } else if (strncasecmp(service, "sd_", strlen("sd_")) == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return "AD Domain Controller";
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic errno_t sssctl_domain_status_active_server(struct sss_tool_ctx *tool_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to list services");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina for (i = 0; i < num_services; i++) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get active server");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_STRING, &server);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina server = SBUS_IS_STRING_EMPTY(server) ? _("not connected") : server;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf("%s: %s\n", proper_service_name(services[i]), server);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic errno_t sssctl_domain_status_server_list(struct sss_tool_ctx *tool_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to list services");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina for (i = 0; i < num_services; i++) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf(_("Discovered %s servers:\n"), proper_service_name(services[i]));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get active server");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina for (j = 0; j < num_servers; j++) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinaerrno_t sssctl_domain_status(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"online", 'o', POPT_ARG_NONE , &opts.online, 0, _("Show online status"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"active-server", 'a', POPT_ARG_NONE, &opts.active, 0, _("Show information about active server"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"servers", 'r', POPT_ARG_NONE, &opts.servers, 0, _("Show list of discovered servers"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina {"start", 's', POPT_ARG_NONE, &opts.force_start, 0, _("Start SSSD if it is not running"), NULL },
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sss_tool_popt_ex(cmdline, options, SSS_TOOL_OPT_OPTIONAL,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina NULL, NULL, "DOMAIN", _("Specify domain name."),
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (opt_set == false) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina path = sbus_opath_compose(tool_ctx, IFP_PATH_DOMAINS, opts.domain);
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_online(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get online status\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_active_server(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get online status\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_server_list(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get server list\n"));