Blame tools/info.c

Packit 8586cb
/*
Packit 8586cb
 * adcli
Packit 8586cb
 *
Packit 8586cb
 * Copyright (C) 2013 Red Hat Inc.
Packit 8586cb
 *
Packit 8586cb
 * This program is free software; you can redistribute it and/or modify
Packit 8586cb
 * it under the terms of the GNU Lesser General Public License as
Packit 8586cb
 * published by the Free Software Foundation; either version 2.1 of
Packit 8586cb
 * the License, or (at your option) any later version.
Packit 8586cb
 *
Packit 8586cb
 * This program is distributed in the hope that it will be useful, but
Packit 8586cb
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 8586cb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 8586cb
 * Lesser General Public License for more details.
Packit 8586cb
 *
Packit 8586cb
 * You should have received a copy of the GNU Lesser General Public
Packit 8586cb
 * License along with this program; if not, write to the Free Software
Packit 8586cb
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Packit 8586cb
 * MA 02110-1301 USA
Packit 8586cb
 *
Packit 8586cb
 * Author: Stef Walter <stefw@redhat.com>
Packit 8586cb
 */
Packit 8586cb
Packit 8586cb
#include "config.h"
Packit 8586cb
Packit 8586cb
#include "adcli.h"
Packit 8586cb
#include "tools.h"
Packit 8586cb
Packit 8586cb
#include <assert.h>
Packit 8586cb
#include <err.h>
Packit 8586cb
#include <stdio.h>
Packit 8586cb
Packit 8586cb
typedef enum {
Packit 8586cb
	/* Have short equivalents */
Packit 8586cb
	opt_domain = 'D',
Packit 8586cb
	opt_domain_controller = 'S',
Packit 8586cb
	opt_verbose = 'v',
Packit 8586cb
} Option;
Packit 8586cb
Packit 8586cb
static adcli_tool_desc common_usages[] = {
Packit 8586cb
	{ opt_domain, "active directory domain name" },
Packit 8586cb
	{ opt_domain_controller, "domain controller to connect to" },
Packit 8586cb
	{ opt_verbose, "show verbose progress and failure messages", },
Packit 8586cb
	{ 0 },
Packit 8586cb
};
Packit 8586cb
Packit 8586cb
static void
Packit 8586cb
print_info (adcli_disco *disco,
Packit 8586cb
            int for_host)
Packit 8586cb
{
Packit 8586cb
	adcli_disco *other;
Packit 8586cb
Packit 8586cb
	printf ("[domain]\n");
Packit 8586cb
	if (disco->domain)
Packit 8586cb
		printf ("domain-name = %s\n", disco->domain);
Packit 8586cb
	if (disco->domain_short)
Packit 8586cb
		printf ("domain-short = %s\n", disco->domain_short);
Packit 8586cb
	if (disco->forest)
Packit 8586cb
		printf ("domain-forest = %s\n", disco->forest);
Packit 8586cb
	if (disco->host_name)
Packit 8586cb
		printf ("domain-controller = %s\n", disco->host_name);
Packit 8586cb
	if (disco->server_site)
Packit 8586cb
		printf ("domain-controller-site = %s\n", disco->server_site);
Packit 8586cb
	if (disco->flags) {
Packit 8586cb
		printf ("domain-controller-flags =");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_PDC) printf (" pdc");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_GC) printf (" gc");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_LDAP) printf (" ldap");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_DS) printf (" ds");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_KDC) printf (" kdc");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_TIMESERV) printf (" timeserv");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_CLOSEST) printf (" closest");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_WRITABLE) printf (" writable");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_GOOD_TIMESERV) printf (" good-timeserv");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_NDNC) printf (" ndnc");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_SELECT_SECRET_DOMAIN_6) printf (" select-secret");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_FULL_SECRET_DOMAIN_6) printf (" full-secret");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_ADS_WEB_SERVICE) printf (" ads-web");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_HAS_DNS_NAME) printf (" dns-name");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_IS_DEFAULT_NC) printf (" default-nc");
Packit 8586cb
		if (disco->flags & ADCLI_DISCO_FOREST_ROOT) printf (" forest-root");
Packit 8586cb
		printf ("\n");
Packit 8586cb
	}
Packit 8586cb
Packit 8586cb
	switch (adcli_disco_usable (disco)) {
Packit 8586cb
	case ADCLI_DISCO_UNUSABLE:
Packit 8586cb
		printf ("domain-controller-usable = no\n");
Packit 8586cb
		break;
Packit 8586cb
	case ADCLI_DISCO_MAYBE:
Packit 8586cb
		printf ("domain-controller-usable = maybe\n");
Packit 8586cb
		break;
Packit 8586cb
	case ADCLI_DISCO_USABLE:
Packit 8586cb
		printf ("domain-controller-usable = yes\n");
Packit 8586cb
		break;
Packit 8586cb
	default:
Packit 8586cb
		break;
Packit 8586cb
	}
Packit 8586cb
Packit 8586cb
	if (!for_host && disco->host_name) {
Packit 8586cb
		printf ("domain-controllers =");
Packit 8586cb
		for (other = disco; other != NULL; other = other->next) {
Packit 8586cb
			if (other->host_name)
Packit 8586cb
				printf (" %s", other->host_name);
Packit 8586cb
		}
Packit 8586cb
		printf ("\n");
Packit 8586cb
	}
Packit 8586cb
Packit 8586cb
	printf ("[computer]\n");
Packit 8586cb
	if (disco->client_site)
Packit 8586cb
		printf ("computer-site = %s\n", disco->client_site);
Packit 8586cb
Packit 8586cb
}
Packit 8586cb
Packit 8586cb
int
Packit 8586cb
adcli_tool_info (adcli_conn *unused,
Packit 8586cb
                 int argc,
Packit 8586cb
                 char *argv[])
Packit 8586cb
{
Packit 8586cb
	const char *domain = NULL;
Packit 8586cb
	const char *server = NULL;
Packit 8586cb
	adcli_disco *disco = NULL;
Packit 8586cb
	int for_host;
Packit 8586cb
	int opt;
Packit 8586cb
Packit 8586cb
	struct option options[] = {
Packit 8586cb
		{ "domain", required_argument, NULL, opt_domain },
Packit 8586cb
		{ "domain-controller", required_argument, NULL, opt_domain_controller },
Packit 8586cb
		{ "verbose", no_argument, NULL, opt_verbose },
Packit 8586cb
		{ "help", no_argument, NULL, 'h' },
Packit 8586cb
		{ 0 },
Packit 8586cb
	};
Packit 8586cb
Packit 8586cb
	static adcli_tool_desc usages[] = {
Packit 8586cb
		{ 0, "usage: adcli info <domain>" },
Packit 8586cb
		{ 0 },
Packit 8586cb
	};
Packit 8586cb
Packit 8586cb
	while ((opt = adcli_tool_getopt (argc, argv, options)) != -1) {
Packit 8586cb
		switch (opt) {
Packit 8586cb
		case opt_domain:
Packit 8586cb
			domain = optarg;
Packit 8586cb
			break;
Packit 8586cb
		case opt_domain_controller:
Packit 8586cb
			server = optarg;
Packit 8586cb
			break;
Packit 8586cb
		case opt_verbose:
Packit 8586cb
			break;
Packit 8586cb
		case 'h':
Packit 8586cb
		case '?':
Packit 8586cb
		case ':':
Packit 8586cb
			adcli_tool_usage (options, usages);
Packit 8586cb
			adcli_tool_usage (options, common_usages);
Packit 8586cb
			return opt == 'h' ? 0 : 2;
Packit 8586cb
		default:
Packit 8586cb
			assert (0 && "not reached");
Packit 8586cb
			break;
Packit 8586cb
		}
Packit 8586cb
	}
Packit 8586cb
Packit 8586cb
	argc -= optind;
Packit 8586cb
	argv += optind;
Packit 8586cb
Packit 8586cb
	if (argc == 1)
Packit 8586cb
		domain = argv[0];
Packit Service 959362
	else if (argc != 0)
Packit Service 959362
		errx (2, "specify one user name to create");
Packit 8586cb
Packit 8586cb
	if (server) {
Packit 8586cb
		adcli_disco_host (server, &disco);
Packit Service 959362
		if (disco == NULL)
Packit Service 959362
			errx (1, "couldn't discover domain controller: %s", server);
Packit 8586cb
		for_host = 1;
Packit 8586cb
	} else if (domain) {
Packit 8586cb
		adcli_disco_domain (domain, &disco);
Packit Service 959362
		if (disco == NULL)
Packit Service 959362
			errx (1, "couldn't discover domain: %s", domain);
Packit 8586cb
		for_host = 0;
Packit 8586cb
	} else {
Packit Service 959362
		errx (2, "specify a domain to discover");
Packit 8586cb
	}
Packit 8586cb
Packit 8586cb
	print_info (disco, for_host);
Packit 8586cb
	adcli_disco_free (disco);
Packit 8586cb
Packit 8586cb
	return 0;
Packit 8586cb
}