xref: /titanic_51/usr/src/cmd/idmap/idmapd/init.c (revision e3f2c991a8548408db0a2787bd8b43d5124821d3)
1c5c4113dSnw141292 /*
2c5c4113dSnw141292  * CDDL HEADER START
3c5c4113dSnw141292  *
4c5c4113dSnw141292  * The contents of this file are subject to the terms of the
5c5c4113dSnw141292  * Common Development and Distribution License (the "License").
6c5c4113dSnw141292  * You may not use this file except in compliance with the License.
7c5c4113dSnw141292  *
8c5c4113dSnw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw141292  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw141292  * See the License for the specific language governing permissions
11c5c4113dSnw141292  * and limitations under the License.
12c5c4113dSnw141292  *
13c5c4113dSnw141292  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw141292  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw141292  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw141292  *
19c5c4113dSnw141292  * CDDL HEADER END
20c5c4113dSnw141292  */
21c5c4113dSnw141292 /*
227a8a68f5SJulian Pullen  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23c5c4113dSnw141292  * Use is subject to license terms.
24c5c4113dSnw141292  */
25c5c4113dSnw141292 
26c5c4113dSnw141292 /*
27c5c4113dSnw141292  * Initialization routines
28c5c4113dSnw141292  */
29c5c4113dSnw141292 
30c5c4113dSnw141292 #include "idmapd.h"
31c5c4113dSnw141292 #include <signal.h>
32c5c4113dSnw141292 #include <thread.h>
33c5c4113dSnw141292 #include <string.h>
34c5c4113dSnw141292 #include <errno.h>
35c5c4113dSnw141292 #include <assert.h>
36c5c4113dSnw141292 #include <unistd.h>
37c5c4113dSnw141292 #include <sys/types.h>
38c5c4113dSnw141292 #include <sys/stat.h>
398edda628Sbaban #include <rpcsvc/daemon_utils.h>
40c5c4113dSnw141292 
41c5c4113dSnw141292 
42c5c4113dSnw141292 int
434edd44c5Sjp151216 init_mapping_system()
444edd44c5Sjp151216 {
458edda628Sbaban 	int rc = 0;
468edda628Sbaban 
47c5c4113dSnw141292 	if (rwlock_init(&_idmapdstate.rwlk_cfg, USYNC_THREAD, NULL) != 0)
48c5c4113dSnw141292 		return (-1);
49e8c27ec8Sbaban 	if ((rc = load_config()) < 0)
50e8c27ec8Sbaban 		return (rc);
518edda628Sbaban 
528edda628Sbaban 	(void) setegid(DAEMON_GID);
538edda628Sbaban 	(void) seteuid(DAEMON_UID);
54c5c4113dSnw141292 	if (init_dbs() < 0) {
558edda628Sbaban 		rc = -1;
56c5c4113dSnw141292 		fini_mapping_system();
57c5c4113dSnw141292 	}
588edda628Sbaban 	(void) seteuid(0);
598edda628Sbaban 	(void) setegid(0);
608edda628Sbaban 
618edda628Sbaban 	return (rc);
62c5c4113dSnw141292 }
63c5c4113dSnw141292 
64c5c4113dSnw141292 void
654edd44c5Sjp151216 fini_mapping_system()
664edd44c5Sjp151216 {
67c5c4113dSnw141292 	fini_dbs();
68c5c4113dSnw141292 }
69c5c4113dSnw141292 
70c5c4113dSnw141292 int
714edd44c5Sjp151216 load_config()
724edd44c5Sjp151216 {
73e3c2d6aaSnw141292 	int rc;
74c5c4113dSnw141292 	if ((_idmapdstate.cfg = idmap_cfg_init()) == NULL) {
75349d5d8fSnw141292 		degrade_svc(0, "failed to initialize config");
76c5c4113dSnw141292 		return (-1);
77c5c4113dSnw141292 	}
78c8e26105Sjp151216 
79*e3f2c991SKeyur Desai 	rc = idmap_cfg_upgrade(_idmapdstate.cfg);
80*e3f2c991SKeyur Desai 	if (rc != 0) {
81*e3f2c991SKeyur Desai 		degrade_svc(0, "fatal error while upgrading configuration");
82*e3f2c991SKeyur Desai 		return (rc);
83*e3f2c991SKeyur Desai 	}
84*e3f2c991SKeyur Desai 
85349d5d8fSnw141292 	rc = idmap_cfg_load(_idmapdstate.cfg, 0);
86e3c2d6aaSnw141292 	if (rc < -1) {
87e3c2d6aaSnw141292 		/* Total failure */
88349d5d8fSnw141292 		degrade_svc(0, "fatal error while loading configuration");
89e8c27ec8Sbaban 		return (rc);
90c5c4113dSnw141292 	}
91c8e26105Sjp151216 
92e3c2d6aaSnw141292 	if (rc != 0)
93e3c2d6aaSnw141292 		/* Partial failure */
9471590c90Snw141292 		idmapdlog(LOG_ERR, "Various errors occurred while loading "
9571590c90Snw141292 		    "the configuration; check the logs");
96e3c2d6aaSnw141292 
970dcc7149Snw141292 	if ((rc = idmap_cfg_start_updates()) < 0) {
980dcc7149Snw141292 		/* Total failure */
99349d5d8fSnw141292 		degrade_svc(0, "could not start config updater");
1000dcc7149Snw141292 		return (rc);
1010dcc7149Snw141292 	}
102e3c2d6aaSnw141292 
10371590c90Snw141292 	idmapdlog(LOG_DEBUG, "Initial configuration loaded");
104e3c2d6aaSnw141292 
105c5c4113dSnw141292 	return (0);
106c5c4113dSnw141292 }
107c5c4113dSnw141292 
108c8e26105Sjp151216 
109349d5d8fSnw141292 void
110*e3f2c991SKeyur Desai reload_gcs()
1114edd44c5Sjp151216 {
1124d61c878SJulian Pullen 	int		i, j;
113*e3f2c991SKeyur Desai 	adutils_ad_t	**new_gcs;
114*e3f2c991SKeyur Desai 	adutils_ad_t	**old_gcs;
115*e3f2c991SKeyur Desai 	int		new_num_gcs;
116*e3f2c991SKeyur Desai 	int		old_num_gcs;
117c8e26105Sjp151216 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
1184d61c878SJulian Pullen 	idmap_trustedforest_t *trustfor = pgcfg->trusted_forests;
1194d61c878SJulian Pullen 	int		num_trustfor = pgcfg->num_trusted_forests;
1204d61c878SJulian Pullen 	ad_disc_domainsinforest_t *domain_in_forest;
121c8e26105Sjp151216 
122349d5d8fSnw141292 	if (pgcfg->global_catalog == NULL ||
123349d5d8fSnw141292 	    pgcfg->global_catalog[0].host[0] == '\0') {
124349d5d8fSnw141292 		/*
125349d5d8fSnw141292 		 * No GCs.  Continue to use the previous AD config in case
126349d5d8fSnw141292 		 * that's still good but auto-discovery had a transient failure.
127349d5d8fSnw141292 		 * If that stops working we'll go into degraded mode anyways
128349d5d8fSnw141292 		 * when it does.
129349d5d8fSnw141292 		 */
130349d5d8fSnw141292 		degrade_svc(0,
131349d5d8fSnw141292 		    "Global Catalog servers not configured/discoverable");
132349d5d8fSnw141292 		return;
133c8e26105Sjp151216 	}
134c8e26105Sjp151216 
135*e3f2c991SKeyur Desai 	old_gcs = _idmapdstate.gcs;
136*e3f2c991SKeyur Desai 	old_num_gcs = _idmapdstate.num_gcs;
137c8e26105Sjp151216 
138*e3f2c991SKeyur Desai 	new_num_gcs = 1 + num_trustfor;
139*e3f2c991SKeyur Desai 	new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *));
140*e3f2c991SKeyur Desai 	if (new_gcs == NULL) {
1414d61c878SJulian Pullen 		degrade_svc(0, "could not allocate AD context array "
1424d61c878SJulian Pullen 		    "(out of memory)");
1434d61c878SJulian Pullen 		return;
1444d61c878SJulian Pullen 	}
1454d61c878SJulian Pullen 
146*e3f2c991SKeyur Desai 	if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) !=
147*e3f2c991SKeyur Desai 	    ADUTILS_SUCCESS) {
148*e3f2c991SKeyur Desai 		free(new_gcs);
1494d61c878SJulian Pullen 		degrade_svc(0, "could not initialize AD context "
1504d61c878SJulian Pullen 		    "(out of memory)");
151349d5d8fSnw141292 		return;
152c8e26105Sjp151216 	}
153c8e26105Sjp151216 
154c8e26105Sjp151216 	for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) {
155*e3f2c991SKeyur Desai 		if (idmap_add_ds(new_gcs[0],
156c8e26105Sjp151216 		    pgcfg->global_catalog[i].host,
157c8e26105Sjp151216 		    pgcfg->global_catalog[i].port) != 0) {
158*e3f2c991SKeyur Desai 			adutils_ad_free(&new_gcs[0]);
159*e3f2c991SKeyur Desai 			free(new_gcs);
1604d61c878SJulian Pullen 			degrade_svc(0, "could not set AD hosts "
1614d61c878SJulian Pullen 			    "(out of memory)");
162349d5d8fSnw141292 			return;
163c8e26105Sjp151216 		}
164c8e26105Sjp151216 	}
165c8e26105Sjp151216 
1664d61c878SJulian Pullen 	if (pgcfg->domains_in_forest != NULL) {
1674d61c878SJulian Pullen 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0';
1684d61c878SJulian Pullen 		    i++) {
169*e3f2c991SKeyur Desai 			if (adutils_add_domain(new_gcs[0],
1704d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].domain,
1714d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].sid) != 0) {
172*e3f2c991SKeyur Desai 				adutils_ad_free(&new_gcs[0]);
173*e3f2c991SKeyur Desai 				free(new_gcs);
1744d61c878SJulian Pullen 				degrade_svc(0, "could not set AD domains "
1754d61c878SJulian Pullen 				    "(out of memory)");
1764d61c878SJulian Pullen 				return;
1774d61c878SJulian Pullen 			}
1784d61c878SJulian Pullen 		}
1794d61c878SJulian Pullen 	}
180c8e26105Sjp151216 
1814d61c878SJulian Pullen 	for (i = 0; i < num_trustfor; i++) {
182*e3f2c991SKeyur Desai 		if (adutils_ad_alloc(&new_gcs[i + 1], NULL,
1834d61c878SJulian Pullen 		    ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) {
1844d61c878SJulian Pullen 			degrade_svc(0, "could not initialize trusted AD "
1854d61c878SJulian Pullen 			    "context (out of memory)");
186*e3f2c991SKeyur Desai 				new_num_gcs = i + 1;
1874d61c878SJulian Pullen 				goto out;
1884d61c878SJulian Pullen 		}
1894d61c878SJulian Pullen 		for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0';
1904d61c878SJulian Pullen 		    j++) {
191*e3f2c991SKeyur Desai 			if (idmap_add_ds(new_gcs[i + 1],
1924d61c878SJulian Pullen 			    trustfor[i].global_catalog[j].host,
1934d61c878SJulian Pullen 			    trustfor[i].global_catalog[j].port) != 0) {
194*e3f2c991SKeyur Desai 				adutils_ad_free(&new_gcs[i + 1]);
1954d61c878SJulian Pullen 				degrade_svc(0, "could not set trusted "
1964d61c878SJulian Pullen 				    "AD hosts (out of memory)");
197*e3f2c991SKeyur Desai 				new_num_gcs = i + 1;
1984d61c878SJulian Pullen 				goto out;
1994d61c878SJulian Pullen 			}
2004d61c878SJulian Pullen 		}
2014d61c878SJulian Pullen 		for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0';
2024d61c878SJulian Pullen 		    j++) {
2034d61c878SJulian Pullen 			domain_in_forest = &trustfor[i].domains_in_forest[j];
2044d61c878SJulian Pullen 			/* Only add domains which are marked */
2054d61c878SJulian Pullen 			if (domain_in_forest->trusted) {
206*e3f2c991SKeyur Desai 				if (adutils_add_domain(new_gcs[i + 1],
2074d61c878SJulian Pullen 				    domain_in_forest->domain,
2084d61c878SJulian Pullen 				    domain_in_forest->sid) != 0) {
209*e3f2c991SKeyur Desai 					adutils_ad_free(&new_gcs[i + 1]);
2104d61c878SJulian Pullen 					degrade_svc(0, "could not set trusted "
2114d61c878SJulian Pullen 					    "AD domains (out of memory)");
212*e3f2c991SKeyur Desai 					new_num_gcs = i + 1;
2134d61c878SJulian Pullen 					goto out;
2144d61c878SJulian Pullen 				}
2154d61c878SJulian Pullen 			}
2164d61c878SJulian Pullen 		}
2174d61c878SJulian Pullen 	}
2184d61c878SJulian Pullen 
2194d61c878SJulian Pullen out:
220*e3f2c991SKeyur Desai 	_idmapdstate.gcs = new_gcs;
221*e3f2c991SKeyur Desai 	_idmapdstate.num_gcs = new_num_gcs;
2224d61c878SJulian Pullen 
2234d61c878SJulian Pullen 
224*e3f2c991SKeyur Desai 	if (old_gcs != NULL) {
225*e3f2c991SKeyur Desai 		for (i = 0; i < old_num_gcs; i++)
226*e3f2c991SKeyur Desai 			adutils_ad_free(&old_gcs[i]);
227*e3f2c991SKeyur Desai 		free(old_gcs);
2284d61c878SJulian Pullen 	}
229c8e26105Sjp151216 }
230c8e26105Sjp151216 
231*e3f2c991SKeyur Desai /*
232*e3f2c991SKeyur Desai  * NEEDSWORK:  This should load entries for domain servers for all known
233*e3f2c991SKeyur Desai  * domains - the joined domain, other domains in the forest, and trusted
234*e3f2c991SKeyur Desai  * domains in other forests.  However, we don't yet discover any DCs other
235*e3f2c991SKeyur Desai  * than the DCs for the joined domain.
236*e3f2c991SKeyur Desai  */
237*e3f2c991SKeyur Desai static
238*e3f2c991SKeyur Desai void
239*e3f2c991SKeyur Desai reload_dcs(void)
240*e3f2c991SKeyur Desai {
241*e3f2c991SKeyur Desai 	int		i;
242*e3f2c991SKeyur Desai 	adutils_ad_t	**new_dcs;
243*e3f2c991SKeyur Desai 	adutils_ad_t	**old_dcs;
244*e3f2c991SKeyur Desai 	int		new_num_dcs;
245*e3f2c991SKeyur Desai 	int		old_num_dcs;
246*e3f2c991SKeyur Desai 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
247*e3f2c991SKeyur Desai 
248*e3f2c991SKeyur Desai 	if (pgcfg->domain_controller == NULL ||
249*e3f2c991SKeyur Desai 	    pgcfg->domain_controller[0].host[0] == '\0') {
250*e3f2c991SKeyur Desai 		/*
251*e3f2c991SKeyur Desai 		 * No DCs.  Continue to use the previous AD config in case
252*e3f2c991SKeyur Desai 		 * that's still good but auto-discovery had a transient failure.
253*e3f2c991SKeyur Desai 		 * If that stops working we'll go into degraded mode anyways
254*e3f2c991SKeyur Desai 		 * when it does.
255*e3f2c991SKeyur Desai 		 */
256*e3f2c991SKeyur Desai 		degrade_svc(0,
257*e3f2c991SKeyur Desai 		    "Domain controller servers not configured/discoverable");
258*e3f2c991SKeyur Desai 		return;
259*e3f2c991SKeyur Desai 	}
260*e3f2c991SKeyur Desai 
261*e3f2c991SKeyur Desai 	old_dcs = _idmapdstate.dcs;
262*e3f2c991SKeyur Desai 	old_num_dcs = _idmapdstate.num_dcs;
263*e3f2c991SKeyur Desai 
264*e3f2c991SKeyur Desai 	new_num_dcs = 1;
265*e3f2c991SKeyur Desai 	new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *));
266*e3f2c991SKeyur Desai 	if (new_dcs == NULL)
267*e3f2c991SKeyur Desai 		goto nomem;
268*e3f2c991SKeyur Desai 
269*e3f2c991SKeyur Desai 	if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name,
270*e3f2c991SKeyur Desai 	    ADUTILS_AD_DATA) != ADUTILS_SUCCESS)
271*e3f2c991SKeyur Desai 		goto nomem;
272*e3f2c991SKeyur Desai 
273*e3f2c991SKeyur Desai 	for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) {
274*e3f2c991SKeyur Desai 		if (idmap_add_ds(new_dcs[0],
275*e3f2c991SKeyur Desai 		    pgcfg->domain_controller[i].host,
276*e3f2c991SKeyur Desai 		    pgcfg->domain_controller[i].port) != 0)
277*e3f2c991SKeyur Desai 			goto nomem;
278*e3f2c991SKeyur Desai 	}
279*e3f2c991SKeyur Desai 
280*e3f2c991SKeyur Desai 	/* NEEDSWORK:  isn't there an easier way to find the domain SID? */
281*e3f2c991SKeyur Desai 	for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++) {
282*e3f2c991SKeyur Desai 		if (domain_eq(pgcfg->domain_name,
283*e3f2c991SKeyur Desai 		    pgcfg->domains_in_forest[i].domain)) {
284*e3f2c991SKeyur Desai 			if (adutils_add_domain(new_dcs[0], pgcfg->domain_name,
285*e3f2c991SKeyur Desai 			    pgcfg->domains_in_forest[i].sid) != 0)
286*e3f2c991SKeyur Desai 				goto nomem;
287*e3f2c991SKeyur Desai 			break;
288*e3f2c991SKeyur Desai 		}
289*e3f2c991SKeyur Desai 	}
290*e3f2c991SKeyur Desai 
291*e3f2c991SKeyur Desai 	_idmapdstate.dcs = new_dcs;
292*e3f2c991SKeyur Desai 	_idmapdstate.num_dcs = new_num_dcs;
293*e3f2c991SKeyur Desai 
294*e3f2c991SKeyur Desai 	if (old_dcs != NULL) {
295*e3f2c991SKeyur Desai 		for (i = 0; i < old_num_dcs; i++)
296*e3f2c991SKeyur Desai 			adutils_ad_free(&old_dcs[i]);
297*e3f2c991SKeyur Desai 		free(old_dcs);
298*e3f2c991SKeyur Desai 	}
299*e3f2c991SKeyur Desai 
300*e3f2c991SKeyur Desai 	return;
301*e3f2c991SKeyur Desai 
302*e3f2c991SKeyur Desai nomem:
303*e3f2c991SKeyur Desai 	degrade_svc(0, "out of memory");
304*e3f2c991SKeyur Desai 
305*e3f2c991SKeyur Desai 	if (new_dcs != NULL) {
306*e3f2c991SKeyur Desai 		if (new_dcs[0] != NULL)
307*e3f2c991SKeyur Desai 			adutils_ad_free(&new_dcs[0]);
308*e3f2c991SKeyur Desai 		free(new_dcs);
309*e3f2c991SKeyur Desai 	}
310*e3f2c991SKeyur Desai }
311*e3f2c991SKeyur Desai 
312*e3f2c991SKeyur Desai 
313*e3f2c991SKeyur Desai void
314*e3f2c991SKeyur Desai reload_ad(void)
315*e3f2c991SKeyur Desai {
316*e3f2c991SKeyur Desai 	reload_gcs();
317*e3f2c991SKeyur Desai 	reload_dcs();
318*e3f2c991SKeyur Desai }
319c8e26105Sjp151216 
320c5c4113dSnw141292 void
3214edd44c5Sjp151216 print_idmapdstate()
3224edd44c5Sjp151216 {
3234d61c878SJulian Pullen 	int i, j;
324e8c27ec8Sbaban 	idmap_pg_config_t *pgcfg;
3254d61c878SJulian Pullen 	idmap_trustedforest_t *tf;
326c8e26105Sjp151216 
327c5c4113dSnw141292 	RDLOCK_CONFIG();
328c5c4113dSnw141292 
329c8e26105Sjp151216 	if (_idmapdstate.cfg == NULL) {
33071590c90Snw141292 		idmapdlog(LOG_INFO, "Null configuration");
331c8e26105Sjp151216 		UNLOCK_CONFIG();
332c8e26105Sjp151216 		return;
333c5c4113dSnw141292 	}
334c8e26105Sjp151216 
335e8c27ec8Sbaban 	pgcfg = &_idmapdstate.cfg->pgcfg;
336e8c27ec8Sbaban 
33771590c90Snw141292 	idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
33871590c90Snw141292 	idmapdlog(LOG_DEBUG, "default_domain=%s",
339c8e26105Sjp151216 	    CHECK_NULL(pgcfg->default_domain));
34071590c90Snw141292 	idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
34171590c90Snw141292 	idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid));
342c8e26105Sjp151216 	if (pgcfg->domain_controller == NULL ||
343c8e26105Sjp151216 	    pgcfg->domain_controller[0].host[0] == '\0') {
34471590c90Snw141292 		idmapdlog(LOG_DEBUG, "No domain controllers known");
345c8e26105Sjp151216 	} else {
346c8e26105Sjp151216 		for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++)
34771590c90Snw141292 			idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d",
34871590c90Snw141292 			    pgcfg->domain_controller[i].host,
349c8e26105Sjp151216 			    pgcfg->domain_controller[i].port);
350c8e26105Sjp151216 	}
35171590c90Snw141292 	idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name));
35271590c90Snw141292 	idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name));
353c8e26105Sjp151216 	if (pgcfg->global_catalog == NULL ||
354c8e26105Sjp151216 	    pgcfg->global_catalog[0].host[0] == '\0') {
35571590c90Snw141292 		idmapdlog(LOG_DEBUG, "No global catalog servers known");
356c8e26105Sjp151216 	} else {
357c8e26105Sjp151216 		for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++)
35871590c90Snw141292 			idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d",
359c8e26105Sjp151216 			    pgcfg->global_catalog[i].host,
360c8e26105Sjp151216 			    pgcfg->global_catalog[i].port);
361c8e26105Sjp151216 	}
3624d61c878SJulian Pullen 	if (pgcfg->domains_in_forest == NULL ||
3634d61c878SJulian Pullen 	    pgcfg->domains_in_forest[0].domain[0] == '\0') {
3644d61c878SJulian Pullen 		idmapdlog(LOG_DEBUG, "No domains in forest %s known",
3654d61c878SJulian Pullen 		    CHECK_NULL(pgcfg->forest_name));
3664d61c878SJulian Pullen 	} else {
3674d61c878SJulian Pullen 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++)
3684d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG, "domains in forest %s = %s",
3694d61c878SJulian Pullen 			    CHECK_NULL(pgcfg->forest_name),
3704d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].domain);
3714d61c878SJulian Pullen 	}
3724d61c878SJulian Pullen 	if (pgcfg->trusted_domains == NULL ||
3734d61c878SJulian Pullen 	    pgcfg->trusted_domains[0].domain[0] == '\0') {
3744d61c878SJulian Pullen 		idmapdlog(LOG_DEBUG, "No trusted domains known");
3754d61c878SJulian Pullen 	} else {
3764d61c878SJulian Pullen 		for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++)
3774d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG, "trusted domain = %s",
3784d61c878SJulian Pullen 			    pgcfg->trusted_domains[i].domain);
3794d61c878SJulian Pullen 	}
3804d61c878SJulian Pullen 
3814d61c878SJulian Pullen 	for (i = 0; i < pgcfg->num_trusted_forests; i++) {
3824d61c878SJulian Pullen 		tf = &pgcfg->trusted_forests[i];
3834d61c878SJulian Pullen 		for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++)
3844d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG,
3854d61c878SJulian Pullen 			    "trusted forest %s global_catalog=%s port=%d",
3864d61c878SJulian Pullen 			    tf->forest_name,
3874d61c878SJulian Pullen 			    tf->global_catalog[j].host,
3884d61c878SJulian Pullen 			    tf->global_catalog[j].port);
3894d61c878SJulian Pullen 		for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) {
3904d61c878SJulian Pullen 			if (tf->domains_in_forest[j].trusted) {
3914d61c878SJulian Pullen 				idmapdlog(LOG_DEBUG,
3924d61c878SJulian Pullen 				    "trusted forest %s domain=%s",
3934d61c878SJulian Pullen 				    tf->forest_name,
3944d61c878SJulian Pullen 				    tf->domains_in_forest[j].domain);
3954d61c878SJulian Pullen 			}
3964d61c878SJulian Pullen 		}
3974d61c878SJulian Pullen 	}
3984d61c878SJulian Pullen 
399*e3f2c991SKeyur Desai 	idmapdlog(LOG_DEBUG, "directory_based_mapping=%s",
400*e3f2c991SKeyur Desai 	    enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map));
40171590c90Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s",
402e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->ad_unixuser_attr));
40371590c90Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s",
404e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->ad_unixgroup_attr));
40571590c90Snw141292 	idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s",
406e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->nldap_winname_attr));
407c8e26105Sjp151216 
408c5c4113dSnw141292 	UNLOCK_CONFIG();
409c5c4113dSnw141292 }
410c5c4113dSnw141292 
411c5c4113dSnw141292 int
4124edd44c5Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid)
4134edd44c5Sjp151216 {
414c5c4113dSnw141292 	int	rc;
415c5c4113dSnw141292 
416c5c4113dSnw141292 	if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) {
41771590c90Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
41871590c90Snw141292 		    path, strerror(errno));
419c5c4113dSnw141292 		return (-1);
420c5c4113dSnw141292 	}
421c5c4113dSnw141292 
422c5c4113dSnw141292 	if (lchown(path, uid, gid) < 0) {
42371590c90Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
42471590c90Snw141292 		    path, strerror(errno));
425c5c4113dSnw141292 		if (rc == 0)
426c5c4113dSnw141292 			(void) rmdir(path);
427c5c4113dSnw141292 		return (-1);
428c5c4113dSnw141292 	}
429c5c4113dSnw141292 	return (0);
430c5c4113dSnw141292 }
431