e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina/*
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina Authors:
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina Pavel Březina <pbrezina@redhat.com>
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina Copyright (C) 2016 Red Hat
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
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
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
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*/
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include <popt.h>
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include <stdio.h>
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include "util/util.h"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include "tools/common/sss_tools.h"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include "tools/sssctl/sssctl.h"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include "sbus/sssd_dbus.h"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina#include "responder/ifp/ifp_iface.h"
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson#define SSS_SIFP_ATTR_SUBDOMAIN "subdomain"
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephensonerrno_t domain_is_subdomain_check(sss_sifp_ctx *sifp_ctx,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson char *domain,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson bool *_is_subdom)
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson{
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson bool is_subdom;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sss_sifp_error error;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sss_sifp_object *domain_obj;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson error = sss_sifp_fetch_domain_by_name(sifp_ctx, domain, &domain_obj);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson if (error != SSS_SIFP_OK) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sssctl_sifp_error(sifp_ctx, error, "Unable to fetch domain by name");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson return EIO;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson error = sss_sifp_find_attr_as_bool(domain_obj->attrs,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson SSS_SIFP_ATTR_SUBDOMAIN,
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson &is_subdom);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson if (error != SSS_SIFP_OK) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson sssctl_sifp_error(sifp_ctx, error, "Unable to find subdomain attr");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson return EIO;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson *_is_subdom = is_subdom;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson return EOK;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson}
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židekerrno_t sssctl_domain_list(struct sss_cmdline *cmdline,
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židek struct sss_tool_ctx *tool_ctx,
488b455f6b7881ec108a127840b1c1f1523d937fMichal Židek void *pvt)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina{
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina sss_sifp_ctx *sifp;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina sss_sifp_error error;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson bool is_subdom;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina char **domains;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int start = 0;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson int verbose = 0;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina errno_t ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int i;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina struct poptOption options[] = {
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 POPT_TABLEEND
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina };
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = sss_tool_popt(cmdline, options, SSS_TOOL_OPT_OPTIONAL, NULL, NULL);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (ret != EOK) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (!sssctl_start_sssd(start)) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return ERR_SSSD_NOT_RUNNING;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina error = sssctl_sifp_init(tool_ctx, &sifp);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (error != SSS_SIFP_OK) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return EFAULT;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina error = sss_sifp_list_domains(sifp, &domains);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (error != SSS_SIFP_OK) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina sssctl_sifp_error(sifp, error, "Unable to get domains list");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return EIO;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson if (verbose) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson for (i = 0; domains[i] != NULL; i++) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson ret = domain_is_subdomain_check(sifp, domains[i], &is_subdom);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson if (ret != EOK) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson DEBUG(SSSDBG_CRIT_FAILURE, "Subdomain check failed\n");
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson return ret;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson if (is_subdom) {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson printf("Trusted domain: %s\n", domains[i]);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson } else {
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson printf("Primary domain: %s\n", domains[i]);
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson return EOK;
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson }
a3f6d90c38c2ae8259df21ee2e4148b05759180bJustin Stephenson
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina for (i = 0; domains[i] != NULL; i++) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina puts(domains[i]);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return EOK;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina}
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastatic errno_t sssctl_domain_status_online(struct sss_tool_ctx *tool_ctx,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sss_sifp_ctx *sifp,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina const char *domain_path)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina{
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina TALLOC_CTX *tmp_ctx;
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sss_sifp_error error;
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina DBusMessage *reply;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina bool is_online;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina errno_t ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina tmp_ctx = talloc_new(NULL);
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina if (tmp_ctx == NULL) {
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina return ENOMEM;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina IFACE_IFP_DOMAINS_DOMAIN,
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina IFACE_IFP_DOMAINS_DOMAIN_ISONLINE);
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina if (error != SSS_SIFP_OK) {
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get online status");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = EIO;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina goto done;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_BOOLEAN, &is_online);
439e08cdc5c83b3e5835cb0435983f1da2ffbaf1Pavel Březina if (ret != EOK) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina goto done;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina printf(_("Online status: %s\n"), is_online ? _("Online") : _("Offline"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina ret = EOK;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinadone:
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina talloc_free(tmp_ctx);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina}
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic const char *proper_service_name(const char *service)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina{
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (strcasecmp(service, "AD_GC") == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return "AD Global Catalog";
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina } else if (strcasecmp(service, "AD") == 0) {
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řezina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return service;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina}
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic errno_t sssctl_domain_status_active_server(struct sss_tool_ctx *tool_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sss_sifp_ctx *sifp,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char *domain_path)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina{
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina TALLOC_CTX *tmp_ctx;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sss_sifp_error error;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DBusMessage *reply;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char *server;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char **services;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina int num_services;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina errno_t ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina int i;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina tmp_ctx = talloc_new(NULL);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (tmp_ctx == NULL) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ENOMEM;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN_LISTSERVICES);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (error != SSS_SIFP_OK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to list services");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EIO;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina &services, &num_services);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf(_("Active servers:\n"));
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 IFACE_IFP_DOMAINS_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN_ACTIVESERVER,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DBUS_TYPE_STRING, &services[i]);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (error != SSS_SIFP_OK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get active server");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EIO;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_STRING, &server);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
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řezina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EOK;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinadone:
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina talloc_free(tmp_ctx);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina}
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinastatic errno_t sssctl_domain_status_server_list(struct sss_tool_ctx *tool_ctx,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sss_sifp_ctx *sifp,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char *domain_path)
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina{
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina TALLOC_CTX *tmp_ctx;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sss_sifp_error error;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DBusMessage *reply;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char **servers;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina int num_servers;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina const char **services;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina int num_services;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina errno_t ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina int i, j;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina tmp_ctx = talloc_new(NULL);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (tmp_ctx == NULL) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ENOMEM;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina error = sssctl_sifp_send(tmp_ctx, sifp, &reply, domain_path,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN_LISTSERVICES);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (error != SSS_SIFP_OK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to list services");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EIO;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina &services, &num_services);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
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 IFACE_IFP_DOMAINS_DOMAIN,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina IFACE_IFP_DOMAINS_DOMAIN_LISTSERVERS,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina DBUS_TYPE_STRING, &services[i]);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (error != SSS_SIFP_OK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina sssctl_sifp_error(sifp, error, "Unable to get active server");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EIO;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sbus_parse_reply(reply, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina &servers, &num_servers);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina goto done;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (num_servers == 0) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina puts(_("None so far.\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina continue;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina for (j = 0; j < num_servers; j++) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf("- %s\n", servers[j]);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf("\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = EOK;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březinadone:
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina talloc_free(tmp_ctx);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina}
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinastruct sssctl_domain_status_opts {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina const char *domain;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int online;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int last;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int active;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int servers;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina int force_start;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina};
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březinaerrno_t sssctl_domain_status(struct sss_cmdline *cmdline,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina struct sss_tool_ctx *tool_ctx,
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina void *pvt)
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina{
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina struct sssctl_domain_status_opts opts = {0};
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sss_sifp_ctx *sifp;
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sss_sifp_error error;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina const char *path;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina bool opt_set;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina errno_t ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina /* Parse command line. */
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina struct poptOption options[] = {
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 POPT_TABLEEND
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina };
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
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 &opts.domain, &opt_set);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (ret != EOK) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to parse command arguments\n");
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return ret;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (opt_set == false) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina opts.online = true;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina opts.last = true;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina opts.active = true;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina opts.servers = true;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina path = sbus_opath_compose(tool_ctx, IFP_PATH_DOMAINS, opts.domain);
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina if (path == NULL) {
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina printf(_("Out of memory!\n"));
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return ENOMEM;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina if (!sssctl_start_sssd(opts.force_start)) {
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina return ERR_SSSD_NOT_RUNNING;
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina }
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina error = sssctl_sifp_init(tool_ctx, &sifp);
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina if (error != SSS_SIFP_OK) {
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina sssctl_sifp_error(sifp, error, "Unable to connect to the InfoPipe");
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina return EFAULT;
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina }
9b74009c1260e6f3b1031a6ae110bf1d957cba81Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (opts.online) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_online(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get online status\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf("\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (opts.active) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_active_server(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get online status\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina printf("\n");
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (opts.servers) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina ret = sssctl_domain_status_server_list(tool_ctx, sifp, path);
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina if (ret != EOK) {
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina fprintf(stderr, _("Unable to get server list\n"));
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina return ret;
bd4c2ed5aec7f57ea04500f0e43f151eedfdde45Pavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina }
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina return EOK;
e157b9f6cb370e1b94bcac2044d26ad66d640fbaPavel Březina}