xref: /titanic_44/usr/src/cmd/idmap/idmapd/init.c (revision 1ed6b69a5ca1ca3ee5e9a4931f74e2237c7e1c9f)
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 /*
22148c5f43SAlan Wright  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23*1ed6b69aSGordon Ross  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
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
init_mapping_system()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
fini_mapping_system()654edd44c5Sjp151216 fini_mapping_system()
664edd44c5Sjp151216 {
67c5c4113dSnw141292 	fini_dbs();
68c5c4113dSnw141292 }
69c5c4113dSnw141292 
70c5c4113dSnw141292 int
load_config()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 
79e3f2c991SKeyur Desai 	rc = idmap_cfg_upgrade(_idmapdstate.cfg);
80e3f2c991SKeyur Desai 	if (rc != 0) {
81e3f2c991SKeyur Desai 		degrade_svc(0, "fatal error while upgrading configuration");
82e3f2c991SKeyur Desai 		return (rc);
83e3f2c991SKeyur Desai 	}
84e3f2c991SKeyur 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 
103148c5f43SAlan Wright 	if (DBG(CONFIG, 1))
10471590c90Snw141292 		idmapdlog(LOG_DEBUG, "Initial configuration loaded");
105e3c2d6aaSnw141292 
106c5c4113dSnw141292 	return (0);
107c5c4113dSnw141292 }
108c5c4113dSnw141292 
109c8e26105Sjp151216 
110349d5d8fSnw141292 void
reload_gcs()111e3f2c991SKeyur Desai reload_gcs()
1124edd44c5Sjp151216 {
1134d61c878SJulian Pullen 	int		i, j;
114e3f2c991SKeyur Desai 	adutils_ad_t	**new_gcs;
115148c5f43SAlan Wright 	adutils_ad_t	**old_gcs = _idmapdstate.gcs;
116e3f2c991SKeyur Desai 	int		new_num_gcs;
117148c5f43SAlan Wright 	int		old_num_gcs = _idmapdstate.num_gcs;
118c8e26105Sjp151216 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
1194d61c878SJulian Pullen 	idmap_trustedforest_t *trustfor = pgcfg->trusted_forests;
1204d61c878SJulian Pullen 	int		num_trustfor = pgcfg->num_trusted_forests;
1214d61c878SJulian Pullen 	ad_disc_domainsinforest_t *domain_in_forest;
122c8e26105Sjp151216 
123*1ed6b69aSGordon Ross 	if (pgcfg->use_ads == B_FALSE ||
124*1ed6b69aSGordon Ross 	    pgcfg->domain_name == NULL) {
125*1ed6b69aSGordon Ross 		/*
126*1ed6b69aSGordon Ross 		 * ADS disabled, or no domain name specified.
127*1ed6b69aSGordon Ross 		 * Not using adutils. (but still can use lsa)
128*1ed6b69aSGordon Ross 		 */
129148c5f43SAlan Wright 		new_gcs = NULL;
130148c5f43SAlan Wright 		new_num_gcs = 0;
131148c5f43SAlan Wright 		goto out;
132148c5f43SAlan Wright 	}
133148c5f43SAlan Wright 
134349d5d8fSnw141292 	if (pgcfg->global_catalog == NULL ||
135349d5d8fSnw141292 	    pgcfg->global_catalog[0].host[0] == '\0') {
136349d5d8fSnw141292 		/*
137349d5d8fSnw141292 		 * No GCs.  Continue to use the previous AD config in case
138349d5d8fSnw141292 		 * that's still good but auto-discovery had a transient failure.
139349d5d8fSnw141292 		 * If that stops working we'll go into degraded mode anyways
140349d5d8fSnw141292 		 * when it does.
141349d5d8fSnw141292 		 */
142349d5d8fSnw141292 		degrade_svc(0,
143349d5d8fSnw141292 		    "Global Catalog servers not configured/discoverable");
144349d5d8fSnw141292 		return;
145c8e26105Sjp151216 	}
146c8e26105Sjp151216 
147e3f2c991SKeyur Desai 	new_num_gcs = 1 + num_trustfor;
148e3f2c991SKeyur Desai 	new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *));
149e3f2c991SKeyur Desai 	if (new_gcs == NULL) {
1504d61c878SJulian Pullen 		degrade_svc(0, "could not allocate AD context array "
1514d61c878SJulian Pullen 		    "(out of memory)");
1524d61c878SJulian Pullen 		return;
1534d61c878SJulian Pullen 	}
1544d61c878SJulian Pullen 
155e3f2c991SKeyur Desai 	if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) !=
156e3f2c991SKeyur Desai 	    ADUTILS_SUCCESS) {
157e3f2c991SKeyur Desai 		free(new_gcs);
1584d61c878SJulian Pullen 		degrade_svc(0, "could not initialize AD context "
1594d61c878SJulian Pullen 		    "(out of memory)");
160349d5d8fSnw141292 		return;
161c8e26105Sjp151216 	}
162c8e26105Sjp151216 
163c8e26105Sjp151216 	for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) {
164e3f2c991SKeyur Desai 		if (idmap_add_ds(new_gcs[0],
165c8e26105Sjp151216 		    pgcfg->global_catalog[i].host,
166c8e26105Sjp151216 		    pgcfg->global_catalog[i].port) != 0) {
167e3f2c991SKeyur Desai 			adutils_ad_free(&new_gcs[0]);
168e3f2c991SKeyur Desai 			free(new_gcs);
1694d61c878SJulian Pullen 			degrade_svc(0, "could not set AD hosts "
1704d61c878SJulian Pullen 			    "(out of memory)");
171349d5d8fSnw141292 			return;
172c8e26105Sjp151216 		}
173c8e26105Sjp151216 	}
174c8e26105Sjp151216 
1754d61c878SJulian Pullen 	if (pgcfg->domains_in_forest != NULL) {
1764d61c878SJulian Pullen 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0';
1774d61c878SJulian Pullen 		    i++) {
178e3f2c991SKeyur Desai 			if (adutils_add_domain(new_gcs[0],
1794d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].domain,
1804d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].sid) != 0) {
181e3f2c991SKeyur Desai 				adutils_ad_free(&new_gcs[0]);
182e3f2c991SKeyur Desai 				free(new_gcs);
1834d61c878SJulian Pullen 				degrade_svc(0, "could not set AD domains "
1844d61c878SJulian Pullen 				    "(out of memory)");
1854d61c878SJulian Pullen 				return;
1864d61c878SJulian Pullen 			}
1874d61c878SJulian Pullen 		}
1884d61c878SJulian Pullen 	}
189c8e26105Sjp151216 
1904d61c878SJulian Pullen 	for (i = 0; i < num_trustfor; i++) {
191e3f2c991SKeyur Desai 		if (adutils_ad_alloc(&new_gcs[i + 1], NULL,
1924d61c878SJulian Pullen 		    ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) {
1934d61c878SJulian Pullen 			degrade_svc(0, "could not initialize trusted AD "
1944d61c878SJulian Pullen 			    "context (out of memory)");
195e3f2c991SKeyur Desai 				new_num_gcs = i + 1;
1964d61c878SJulian Pullen 				goto out;
1974d61c878SJulian Pullen 		}
1984d61c878SJulian Pullen 		for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0';
1994d61c878SJulian Pullen 		    j++) {
200e3f2c991SKeyur Desai 			if (idmap_add_ds(new_gcs[i + 1],
2014d61c878SJulian Pullen 			    trustfor[i].global_catalog[j].host,
2024d61c878SJulian Pullen 			    trustfor[i].global_catalog[j].port) != 0) {
203e3f2c991SKeyur Desai 				adutils_ad_free(&new_gcs[i + 1]);
2044d61c878SJulian Pullen 				degrade_svc(0, "could not set trusted "
2054d61c878SJulian Pullen 				    "AD hosts (out of memory)");
206e3f2c991SKeyur Desai 				new_num_gcs = i + 1;
2074d61c878SJulian Pullen 				goto out;
2084d61c878SJulian Pullen 			}
2094d61c878SJulian Pullen 		}
2104d61c878SJulian Pullen 		for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0';
2114d61c878SJulian Pullen 		    j++) {
2124d61c878SJulian Pullen 			domain_in_forest = &trustfor[i].domains_in_forest[j];
2134d61c878SJulian Pullen 			/* Only add domains which are marked */
2144d61c878SJulian Pullen 			if (domain_in_forest->trusted) {
215e3f2c991SKeyur Desai 				if (adutils_add_domain(new_gcs[i + 1],
2164d61c878SJulian Pullen 				    domain_in_forest->domain,
2174d61c878SJulian Pullen 				    domain_in_forest->sid) != 0) {
218e3f2c991SKeyur Desai 					adutils_ad_free(&new_gcs[i + 1]);
2194d61c878SJulian Pullen 					degrade_svc(0, "could not set trusted "
2204d61c878SJulian Pullen 					    "AD domains (out of memory)");
221e3f2c991SKeyur Desai 					new_num_gcs = i + 1;
2224d61c878SJulian Pullen 					goto out;
2234d61c878SJulian Pullen 				}
2244d61c878SJulian Pullen 			}
2254d61c878SJulian Pullen 		}
2264d61c878SJulian Pullen 	}
2274d61c878SJulian Pullen 
2284d61c878SJulian Pullen out:
229e3f2c991SKeyur Desai 	_idmapdstate.gcs = new_gcs;
230e3f2c991SKeyur Desai 	_idmapdstate.num_gcs = new_num_gcs;
2314d61c878SJulian Pullen 
232e3f2c991SKeyur Desai 	if (old_gcs != NULL) {
233e3f2c991SKeyur Desai 		for (i = 0; i < old_num_gcs; i++)
234e3f2c991SKeyur Desai 			adutils_ad_free(&old_gcs[i]);
235e3f2c991SKeyur Desai 		free(old_gcs);
2364d61c878SJulian Pullen 	}
237c8e26105Sjp151216 }
238c8e26105Sjp151216 
239e3f2c991SKeyur Desai /*
240e3f2c991SKeyur Desai  * NEEDSWORK:  This should load entries for domain servers for all known
241e3f2c991SKeyur Desai  * domains - the joined domain, other domains in the forest, and trusted
242e3f2c991SKeyur Desai  * domains in other forests.  However, we don't yet discover any DCs other
243e3f2c991SKeyur Desai  * than the DCs for the joined domain.
244e3f2c991SKeyur Desai  */
245e3f2c991SKeyur Desai static
246e3f2c991SKeyur Desai void
reload_dcs(void)247e3f2c991SKeyur Desai reload_dcs(void)
248e3f2c991SKeyur Desai {
249e3f2c991SKeyur Desai 	int		i;
250e3f2c991SKeyur Desai 	adutils_ad_t	**new_dcs;
251148c5f43SAlan Wright 	adutils_ad_t	**old_dcs = _idmapdstate.dcs;
252e3f2c991SKeyur Desai 	int		new_num_dcs;
253148c5f43SAlan Wright 	int		old_num_dcs = _idmapdstate.num_dcs;
254e3f2c991SKeyur Desai 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
255e3f2c991SKeyur Desai 
256*1ed6b69aSGordon Ross 	if (pgcfg->use_ads == B_FALSE ||
257*1ed6b69aSGordon Ross 	    pgcfg->domain_name == NULL) {
258*1ed6b69aSGordon Ross 		/*
259*1ed6b69aSGordon Ross 		 * ADS disabled, or no domain name specified.
260*1ed6b69aSGordon Ross 		 * Not using adutils. (but still can use lsa)
261*1ed6b69aSGordon Ross 		 */
262148c5f43SAlan Wright 		new_dcs = NULL;
263148c5f43SAlan Wright 		new_num_dcs = 0;
264148c5f43SAlan Wright 		goto out;
265148c5f43SAlan Wright 	}
266148c5f43SAlan Wright 
267e3f2c991SKeyur Desai 	if (pgcfg->domain_controller == NULL ||
268e3f2c991SKeyur Desai 	    pgcfg->domain_controller[0].host[0] == '\0') {
269e3f2c991SKeyur Desai 		/*
270e3f2c991SKeyur Desai 		 * No DCs.  Continue to use the previous AD config in case
271e3f2c991SKeyur Desai 		 * that's still good but auto-discovery had a transient failure.
272e3f2c991SKeyur Desai 		 * If that stops working we'll go into degraded mode anyways
273e3f2c991SKeyur Desai 		 * when it does.
274e3f2c991SKeyur Desai 		 */
275e3f2c991SKeyur Desai 		degrade_svc(0,
276e3f2c991SKeyur Desai 		    "Domain controller servers not configured/discoverable");
277e3f2c991SKeyur Desai 		return;
278e3f2c991SKeyur Desai 	}
279e3f2c991SKeyur Desai 
280e3f2c991SKeyur Desai 	new_num_dcs = 1;
281e3f2c991SKeyur Desai 	new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *));
282e3f2c991SKeyur Desai 	if (new_dcs == NULL)
283e3f2c991SKeyur Desai 		goto nomem;
284e3f2c991SKeyur Desai 
285e3f2c991SKeyur Desai 	if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name,
286e3f2c991SKeyur Desai 	    ADUTILS_AD_DATA) != ADUTILS_SUCCESS)
287e3f2c991SKeyur Desai 		goto nomem;
288e3f2c991SKeyur Desai 
289e3f2c991SKeyur Desai 	for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) {
290e3f2c991SKeyur Desai 		if (idmap_add_ds(new_dcs[0],
291e3f2c991SKeyur Desai 		    pgcfg->domain_controller[i].host,
292e3f2c991SKeyur Desai 		    pgcfg->domain_controller[i].port) != 0)
293e3f2c991SKeyur Desai 			goto nomem;
294e3f2c991SKeyur Desai 	}
295e3f2c991SKeyur Desai 
29646cf8a39SJordan Brown 	/*
29746cf8a39SJordan Brown 	 * NEEDSWORK:  All we need here is to add the domain and SID for
29846cf8a39SJordan Brown 	 * this DC to the list of domains supported by this entry.  Isn't
29946cf8a39SJordan Brown 	 * there an easier way to find the SID than to walk through the list
30046cf8a39SJordan Brown 	 * of all of the domains in the forest?
30146cf8a39SJordan Brown 	 */
30246cf8a39SJordan Brown 	ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest;
30346cf8a39SJordan Brown 	if (dif != NULL) {
30446cf8a39SJordan Brown 		for (; dif->domain[0] != '\0'; dif++) {
30546cf8a39SJordan Brown 			if (domain_eq(pgcfg->domain_name, dif->domain)) {
30646cf8a39SJordan Brown 				if (adutils_add_domain(new_dcs[0],
30746cf8a39SJordan Brown 				    dif->domain, dif->sid) != 0)
308e3f2c991SKeyur Desai 					goto nomem;
309e3f2c991SKeyur Desai 				break;
310e3f2c991SKeyur Desai 			}
311e3f2c991SKeyur Desai 		}
31246cf8a39SJordan Brown 	}
313e3f2c991SKeyur Desai 
314148c5f43SAlan Wright out:
315e3f2c991SKeyur Desai 	_idmapdstate.dcs = new_dcs;
316e3f2c991SKeyur Desai 	_idmapdstate.num_dcs = new_num_dcs;
317e3f2c991SKeyur Desai 
318e3f2c991SKeyur Desai 	if (old_dcs != NULL) {
319e3f2c991SKeyur Desai 		for (i = 0; i < old_num_dcs; i++)
320e3f2c991SKeyur Desai 			adutils_ad_free(&old_dcs[i]);
321e3f2c991SKeyur Desai 		free(old_dcs);
322e3f2c991SKeyur Desai 	}
323e3f2c991SKeyur Desai 
324e3f2c991SKeyur Desai 	return;
325e3f2c991SKeyur Desai 
326e3f2c991SKeyur Desai nomem:
327e3f2c991SKeyur Desai 	degrade_svc(0, "out of memory");
328e3f2c991SKeyur Desai 
329e3f2c991SKeyur Desai 	if (new_dcs != NULL) {
330e3f2c991SKeyur Desai 		if (new_dcs[0] != NULL)
331e3f2c991SKeyur Desai 			adutils_ad_free(&new_dcs[0]);
332e3f2c991SKeyur Desai 		free(new_dcs);
333e3f2c991SKeyur Desai 	}
334e3f2c991SKeyur Desai }
335e3f2c991SKeyur Desai 
336e3f2c991SKeyur Desai 
337e3f2c991SKeyur Desai void
reload_ad(void)338e3f2c991SKeyur Desai reload_ad(void)
339e3f2c991SKeyur Desai {
340e3f2c991SKeyur Desai 	reload_gcs();
341e3f2c991SKeyur Desai 	reload_dcs();
342e3f2c991SKeyur Desai }
343c8e26105Sjp151216 
344c5c4113dSnw141292 void
print_idmapdstate(void)345148c5f43SAlan Wright print_idmapdstate(void)
3464edd44c5Sjp151216 {
3474d61c878SJulian Pullen 	int i, j;
348e8c27ec8Sbaban 	idmap_pg_config_t *pgcfg;
3494d61c878SJulian Pullen 	idmap_trustedforest_t *tf;
350c8e26105Sjp151216 
351c5c4113dSnw141292 	RDLOCK_CONFIG();
352c5c4113dSnw141292 
353c8e26105Sjp151216 	if (_idmapdstate.cfg == NULL) {
35471590c90Snw141292 		idmapdlog(LOG_INFO, "Null configuration");
355c8e26105Sjp151216 		UNLOCK_CONFIG();
356c8e26105Sjp151216 		return;
357c5c4113dSnw141292 	}
358c8e26105Sjp151216 
359e8c27ec8Sbaban 	pgcfg = &_idmapdstate.cfg->pgcfg;
360e8c27ec8Sbaban 
36171590c90Snw141292 	idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
36271590c90Snw141292 	idmapdlog(LOG_DEBUG, "default_domain=%s",
363c8e26105Sjp151216 	    CHECK_NULL(pgcfg->default_domain));
36471590c90Snw141292 	idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
36571590c90Snw141292 	idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid));
366c8e26105Sjp151216 	if (pgcfg->domain_controller == NULL ||
367c8e26105Sjp151216 	    pgcfg->domain_controller[0].host[0] == '\0') {
36871590c90Snw141292 		idmapdlog(LOG_DEBUG, "No domain controllers known");
369c8e26105Sjp151216 	} else {
370c8e26105Sjp151216 		for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++)
37171590c90Snw141292 			idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d",
37271590c90Snw141292 			    pgcfg->domain_controller[i].host,
373c8e26105Sjp151216 			    pgcfg->domain_controller[i].port);
374c8e26105Sjp151216 	}
37571590c90Snw141292 	idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name));
37671590c90Snw141292 	idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name));
377c8e26105Sjp151216 	if (pgcfg->global_catalog == NULL ||
378c8e26105Sjp151216 	    pgcfg->global_catalog[0].host[0] == '\0') {
37971590c90Snw141292 		idmapdlog(LOG_DEBUG, "No global catalog servers known");
380c8e26105Sjp151216 	} else {
381c8e26105Sjp151216 		for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++)
38271590c90Snw141292 			idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d",
383c8e26105Sjp151216 			    pgcfg->global_catalog[i].host,
384c8e26105Sjp151216 			    pgcfg->global_catalog[i].port);
385c8e26105Sjp151216 	}
3864d61c878SJulian Pullen 	if (pgcfg->domains_in_forest == NULL ||
3874d61c878SJulian Pullen 	    pgcfg->domains_in_forest[0].domain[0] == '\0') {
3884d61c878SJulian Pullen 		idmapdlog(LOG_DEBUG, "No domains in forest %s known",
3894d61c878SJulian Pullen 		    CHECK_NULL(pgcfg->forest_name));
3904d61c878SJulian Pullen 	} else {
3914d61c878SJulian Pullen 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++)
3924d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG, "domains in forest %s = %s",
3934d61c878SJulian Pullen 			    CHECK_NULL(pgcfg->forest_name),
3944d61c878SJulian Pullen 			    pgcfg->domains_in_forest[i].domain);
3954d61c878SJulian Pullen 	}
3964d61c878SJulian Pullen 	if (pgcfg->trusted_domains == NULL ||
3974d61c878SJulian Pullen 	    pgcfg->trusted_domains[0].domain[0] == '\0') {
3984d61c878SJulian Pullen 		idmapdlog(LOG_DEBUG, "No trusted domains known");
3994d61c878SJulian Pullen 	} else {
4004d61c878SJulian Pullen 		for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++)
4014d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG, "trusted domain = %s",
4024d61c878SJulian Pullen 			    pgcfg->trusted_domains[i].domain);
4034d61c878SJulian Pullen 	}
4044d61c878SJulian Pullen 
4054d61c878SJulian Pullen 	for (i = 0; i < pgcfg->num_trusted_forests; i++) {
4064d61c878SJulian Pullen 		tf = &pgcfg->trusted_forests[i];
4074d61c878SJulian Pullen 		for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++)
4084d61c878SJulian Pullen 			idmapdlog(LOG_DEBUG,
4094d61c878SJulian Pullen 			    "trusted forest %s global_catalog=%s port=%d",
4104d61c878SJulian Pullen 			    tf->forest_name,
4114d61c878SJulian Pullen 			    tf->global_catalog[j].host,
4124d61c878SJulian Pullen 			    tf->global_catalog[j].port);
4134d61c878SJulian Pullen 		for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) {
4144d61c878SJulian Pullen 			if (tf->domains_in_forest[j].trusted) {
4154d61c878SJulian Pullen 				idmapdlog(LOG_DEBUG,
4164d61c878SJulian Pullen 				    "trusted forest %s domain=%s",
4174d61c878SJulian Pullen 				    tf->forest_name,
4184d61c878SJulian Pullen 				    tf->domains_in_forest[j].domain);
4194d61c878SJulian Pullen 			}
4204d61c878SJulian Pullen 		}
4214d61c878SJulian Pullen 	}
4224d61c878SJulian Pullen 
423e3f2c991SKeyur Desai 	idmapdlog(LOG_DEBUG, "directory_based_mapping=%s",
424e3f2c991SKeyur Desai 	    enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map));
42571590c90Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s",
426e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->ad_unixuser_attr));
42771590c90Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s",
428e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->ad_unixgroup_attr));
42971590c90Snw141292 	idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s",
430e8c27ec8Sbaban 	    CHECK_NULL(pgcfg->nldap_winname_attr));
431c8e26105Sjp151216 
432c5c4113dSnw141292 	UNLOCK_CONFIG();
433c5c4113dSnw141292 }
434c5c4113dSnw141292 
435c5c4113dSnw141292 int
create_directory(const char * path,uid_t uid,gid_t gid)4364edd44c5Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid)
4374edd44c5Sjp151216 {
438c5c4113dSnw141292 	int	rc;
439c5c4113dSnw141292 
440c5c4113dSnw141292 	if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) {
44171590c90Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
44271590c90Snw141292 		    path, strerror(errno));
443c5c4113dSnw141292 		return (-1);
444c5c4113dSnw141292 	}
445c5c4113dSnw141292 
446c5c4113dSnw141292 	if (lchown(path, uid, gid) < 0) {
44771590c90Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
44871590c90Snw141292 		    path, strerror(errno));
449c5c4113dSnw141292 		if (rc == 0)
450c5c4113dSnw141292 			(void) rmdir(path);
451c5c4113dSnw141292 		return (-1);
452c5c4113dSnw141292 	}
453c5c4113dSnw141292 	return (0);
454c5c4113dSnw141292 }
455