xref: /onnv-gate/usr/src/cmd/idmap/idmapd/init.c (revision 10749:b871274b236d)
14520Snw141292 /*
24520Snw141292  * CDDL HEADER START
34520Snw141292  *
44520Snw141292  * The contents of this file are subject to the terms of the
54520Snw141292  * Common Development and Distribution License (the "License").
64520Snw141292  * You may not use this file except in compliance with the License.
74520Snw141292  *
84520Snw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
94520Snw141292  * or http://www.opensolaris.org/os/licensing.
104520Snw141292  * See the License for the specific language governing permissions
114520Snw141292  * and limitations under the License.
124520Snw141292  *
134520Snw141292  * When distributing Covered Code, include this CDDL HEADER in each
144520Snw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
154520Snw141292  * If applicable, add the following below this CDDL HEADER, with the
164520Snw141292  * fields enclosed by brackets "[]" replaced with your own identifying
174520Snw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
184520Snw141292  *
194520Snw141292  * CDDL HEADER END
204520Snw141292  */
214520Snw141292 /*
228671SJulian.Pullen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
234520Snw141292  * Use is subject to license terms.
244520Snw141292  */
254520Snw141292 
264520Snw141292 /*
274520Snw141292  * Initialization routines
284520Snw141292  */
294520Snw141292 
304520Snw141292 #include "idmapd.h"
314520Snw141292 #include <signal.h>
324520Snw141292 #include <thread.h>
334520Snw141292 #include <string.h>
344520Snw141292 #include <errno.h>
354520Snw141292 #include <assert.h>
364520Snw141292 #include <unistd.h>
374520Snw141292 #include <sys/types.h>
384520Snw141292 #include <sys/stat.h>
394695Sbaban #include <rpcsvc/daemon_utils.h>
404520Snw141292 
414520Snw141292 
424520Snw141292 int
435908Sjp151216 init_mapping_system()
445908Sjp151216 {
454695Sbaban 	int rc = 0;
464695Sbaban 
474520Snw141292 	if (rwlock_init(&_idmapdstate.rwlk_cfg, USYNC_THREAD, NULL) != 0)
484520Snw141292 		return (-1);
495731Sbaban 	if ((rc = load_config()) < 0)
505731Sbaban 		return (rc);
514695Sbaban 
524695Sbaban 	(void) setegid(DAEMON_GID);
534695Sbaban 	(void) seteuid(DAEMON_UID);
544520Snw141292 	if (init_dbs() < 0) {
554695Sbaban 		rc = -1;
564520Snw141292 		fini_mapping_system();
574520Snw141292 	}
584695Sbaban 	(void) seteuid(0);
594695Sbaban 	(void) setegid(0);
604695Sbaban 
614695Sbaban 	return (rc);
624520Snw141292 }
634520Snw141292 
644520Snw141292 void
655908Sjp151216 fini_mapping_system()
665908Sjp151216 {
674520Snw141292 	fini_dbs();
684520Snw141292 }
694520Snw141292 
704520Snw141292 int
715908Sjp151216 load_config()
725908Sjp151216 {
735447Snw141292 	int rc;
744520Snw141292 	if ((_idmapdstate.cfg = idmap_cfg_init()) == NULL) {
756097Snw141292 		degrade_svc(0, "failed to initialize config");
764520Snw141292 		return (-1);
774520Snw141292 	}
785317Sjp151216 
7910504SKeyur.Desai@Sun.COM 	rc = idmap_cfg_upgrade(_idmapdstate.cfg);
8010504SKeyur.Desai@Sun.COM 	if (rc != 0) {
8110504SKeyur.Desai@Sun.COM 		degrade_svc(0, "fatal error while upgrading configuration");
8210504SKeyur.Desai@Sun.COM 		return (rc);
8310504SKeyur.Desai@Sun.COM 	}
8410504SKeyur.Desai@Sun.COM 
856097Snw141292 	rc = idmap_cfg_load(_idmapdstate.cfg, 0);
865447Snw141292 	if (rc < -1) {
875447Snw141292 		/* Total failure */
886097Snw141292 		degrade_svc(0, "fatal error while loading configuration");
895731Sbaban 		return (rc);
904520Snw141292 	}
915317Sjp151216 
925447Snw141292 	if (rc != 0)
935447Snw141292 		/* Partial failure */
946017Snw141292 		idmapdlog(LOG_ERR, "Various errors occurred while loading "
956017Snw141292 		    "the configuration; check the logs");
965447Snw141292 
975968Snw141292 	if ((rc = idmap_cfg_start_updates()) < 0) {
985968Snw141292 		/* Total failure */
996097Snw141292 		degrade_svc(0, "could not start config updater");
1005968Snw141292 		return (rc);
1015968Snw141292 	}
1025447Snw141292 
1036017Snw141292 	idmapdlog(LOG_DEBUG, "Initial configuration loaded");
1045447Snw141292 
1055317Sjp151216 	return (0);
1065317Sjp151216 }
1075317Sjp151216 
1085317Sjp151216 
1096097Snw141292 void
11010504SKeyur.Desai@Sun.COM reload_gcs()
1115908Sjp151216 {
1128361SJulian.Pullen@Sun.COM 	int		i, j;
11310504SKeyur.Desai@Sun.COM 	adutils_ad_t	**new_gcs;
11410504SKeyur.Desai@Sun.COM 	adutils_ad_t	**old_gcs;
11510504SKeyur.Desai@Sun.COM 	int		new_num_gcs;
11610504SKeyur.Desai@Sun.COM 	int		old_num_gcs;
1175317Sjp151216 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
1188361SJulian.Pullen@Sun.COM 	idmap_trustedforest_t *trustfor = pgcfg->trusted_forests;
1198361SJulian.Pullen@Sun.COM 	int		num_trustfor = pgcfg->num_trusted_forests;
1208361SJulian.Pullen@Sun.COM 	ad_disc_domainsinforest_t *domain_in_forest;
1215317Sjp151216 
1226097Snw141292 	if (pgcfg->global_catalog == NULL ||
1236097Snw141292 	    pgcfg->global_catalog[0].host[0] == '\0') {
1246097Snw141292 		/*
1256097Snw141292 		 * No GCs.  Continue to use the previous AD config in case
1266097Snw141292 		 * that's still good but auto-discovery had a transient failure.
1276097Snw141292 		 * If that stops working we'll go into degraded mode anyways
1286097Snw141292 		 * when it does.
1296097Snw141292 		 */
1306097Snw141292 		degrade_svc(0,
1316097Snw141292 		    "Global Catalog servers not configured/discoverable");
1326097Snw141292 		return;
1334520Snw141292 	}
1345317Sjp151216 
13510504SKeyur.Desai@Sun.COM 	old_gcs = _idmapdstate.gcs;
13610504SKeyur.Desai@Sun.COM 	old_num_gcs = _idmapdstate.num_gcs;
1375317Sjp151216 
13810504SKeyur.Desai@Sun.COM 	new_num_gcs = 1 + num_trustfor;
13910504SKeyur.Desai@Sun.COM 	new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *));
14010504SKeyur.Desai@Sun.COM 	if (new_gcs == NULL) {
1418361SJulian.Pullen@Sun.COM 		degrade_svc(0, "could not allocate AD context array "
1428361SJulian.Pullen@Sun.COM 		    "(out of memory)");
1438361SJulian.Pullen@Sun.COM 		return;
1448361SJulian.Pullen@Sun.COM 	}
1458361SJulian.Pullen@Sun.COM 
14610504SKeyur.Desai@Sun.COM 	if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) !=
14710504SKeyur.Desai@Sun.COM 	    ADUTILS_SUCCESS) {
14810504SKeyur.Desai@Sun.COM 		free(new_gcs);
1498361SJulian.Pullen@Sun.COM 		degrade_svc(0, "could not initialize AD context "
1508361SJulian.Pullen@Sun.COM 		    "(out of memory)");
1516097Snw141292 		return;
1524520Snw141292 	}
1535317Sjp151216 
1545317Sjp151216 	for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) {
15510504SKeyur.Desai@Sun.COM 		if (idmap_add_ds(new_gcs[0],
1565317Sjp151216 		    pgcfg->global_catalog[i].host,
1575317Sjp151216 		    pgcfg->global_catalog[i].port) != 0) {
15810504SKeyur.Desai@Sun.COM 			adutils_ad_free(&new_gcs[0]);
15910504SKeyur.Desai@Sun.COM 			free(new_gcs);
1608361SJulian.Pullen@Sun.COM 			degrade_svc(0, "could not set AD hosts "
1618361SJulian.Pullen@Sun.COM 			    "(out of memory)");
1626097Snw141292 			return;
1635317Sjp151216 		}
1645317Sjp151216 	}
1655317Sjp151216 
1668361SJulian.Pullen@Sun.COM 	if (pgcfg->domains_in_forest != NULL) {
1678361SJulian.Pullen@Sun.COM 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0';
1688361SJulian.Pullen@Sun.COM 		    i++) {
16910504SKeyur.Desai@Sun.COM 			if (adutils_add_domain(new_gcs[0],
1708361SJulian.Pullen@Sun.COM 			    pgcfg->domains_in_forest[i].domain,
1718361SJulian.Pullen@Sun.COM 			    pgcfg->domains_in_forest[i].sid) != 0) {
17210504SKeyur.Desai@Sun.COM 				adutils_ad_free(&new_gcs[0]);
17310504SKeyur.Desai@Sun.COM 				free(new_gcs);
1748361SJulian.Pullen@Sun.COM 				degrade_svc(0, "could not set AD domains "
1758361SJulian.Pullen@Sun.COM 				    "(out of memory)");
1768361SJulian.Pullen@Sun.COM 				return;
1778361SJulian.Pullen@Sun.COM 			}
1788361SJulian.Pullen@Sun.COM 		}
1798361SJulian.Pullen@Sun.COM 	}
1805317Sjp151216 
1818361SJulian.Pullen@Sun.COM 	for (i = 0; i < num_trustfor; i++) {
18210504SKeyur.Desai@Sun.COM 		if (adutils_ad_alloc(&new_gcs[i + 1], NULL,
1838361SJulian.Pullen@Sun.COM 		    ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) {
1848361SJulian.Pullen@Sun.COM 			degrade_svc(0, "could not initialize trusted AD "
1858361SJulian.Pullen@Sun.COM 			    "context (out of memory)");
18610504SKeyur.Desai@Sun.COM 				new_num_gcs = i + 1;
1878361SJulian.Pullen@Sun.COM 				goto out;
1888361SJulian.Pullen@Sun.COM 		}
1898361SJulian.Pullen@Sun.COM 		for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0';
1908361SJulian.Pullen@Sun.COM 		    j++) {
19110504SKeyur.Desai@Sun.COM 			if (idmap_add_ds(new_gcs[i + 1],
1928361SJulian.Pullen@Sun.COM 			    trustfor[i].global_catalog[j].host,
1938361SJulian.Pullen@Sun.COM 			    trustfor[i].global_catalog[j].port) != 0) {
19410504SKeyur.Desai@Sun.COM 				adutils_ad_free(&new_gcs[i + 1]);
1958361SJulian.Pullen@Sun.COM 				degrade_svc(0, "could not set trusted "
1968361SJulian.Pullen@Sun.COM 				    "AD hosts (out of memory)");
19710504SKeyur.Desai@Sun.COM 				new_num_gcs = i + 1;
1988361SJulian.Pullen@Sun.COM 				goto out;
1998361SJulian.Pullen@Sun.COM 			}
2008361SJulian.Pullen@Sun.COM 		}
2018361SJulian.Pullen@Sun.COM 		for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0';
2028361SJulian.Pullen@Sun.COM 		    j++) {
2038361SJulian.Pullen@Sun.COM 			domain_in_forest = &trustfor[i].domains_in_forest[j];
2048361SJulian.Pullen@Sun.COM 			/* Only add domains which are marked */
2058361SJulian.Pullen@Sun.COM 			if (domain_in_forest->trusted) {
20610504SKeyur.Desai@Sun.COM 				if (adutils_add_domain(new_gcs[i + 1],
2078361SJulian.Pullen@Sun.COM 				    domain_in_forest->domain,
2088361SJulian.Pullen@Sun.COM 				    domain_in_forest->sid) != 0) {
20910504SKeyur.Desai@Sun.COM 					adutils_ad_free(&new_gcs[i + 1]);
2108361SJulian.Pullen@Sun.COM 					degrade_svc(0, "could not set trusted "
2118361SJulian.Pullen@Sun.COM 					    "AD domains (out of memory)");
21210504SKeyur.Desai@Sun.COM 					new_num_gcs = i + 1;
2138361SJulian.Pullen@Sun.COM 					goto out;
2148361SJulian.Pullen@Sun.COM 				}
2158361SJulian.Pullen@Sun.COM 			}
2168361SJulian.Pullen@Sun.COM 		}
2178361SJulian.Pullen@Sun.COM 	}
2188361SJulian.Pullen@Sun.COM 
2198361SJulian.Pullen@Sun.COM out:
22010504SKeyur.Desai@Sun.COM 	_idmapdstate.gcs = new_gcs;
22110504SKeyur.Desai@Sun.COM 	_idmapdstate.num_gcs = new_num_gcs;
2228361SJulian.Pullen@Sun.COM 
2238361SJulian.Pullen@Sun.COM 
22410504SKeyur.Desai@Sun.COM 	if (old_gcs != NULL) {
22510504SKeyur.Desai@Sun.COM 		for (i = 0; i < old_num_gcs; i++)
22610504SKeyur.Desai@Sun.COM 			adutils_ad_free(&old_gcs[i]);
22710504SKeyur.Desai@Sun.COM 		free(old_gcs);
2288361SJulian.Pullen@Sun.COM 	}
2294520Snw141292 }
2304520Snw141292 
23110504SKeyur.Desai@Sun.COM /*
23210504SKeyur.Desai@Sun.COM  * NEEDSWORK:  This should load entries for domain servers for all known
23310504SKeyur.Desai@Sun.COM  * domains - the joined domain, other domains in the forest, and trusted
23410504SKeyur.Desai@Sun.COM  * domains in other forests.  However, we don't yet discover any DCs other
23510504SKeyur.Desai@Sun.COM  * than the DCs for the joined domain.
23610504SKeyur.Desai@Sun.COM  */
23710504SKeyur.Desai@Sun.COM static
23810504SKeyur.Desai@Sun.COM void
23910504SKeyur.Desai@Sun.COM reload_dcs(void)
24010504SKeyur.Desai@Sun.COM {
24110504SKeyur.Desai@Sun.COM 	int		i;
24210504SKeyur.Desai@Sun.COM 	adutils_ad_t	**new_dcs;
24310504SKeyur.Desai@Sun.COM 	adutils_ad_t	**old_dcs;
24410504SKeyur.Desai@Sun.COM 	int		new_num_dcs;
24510504SKeyur.Desai@Sun.COM 	int		old_num_dcs;
24610504SKeyur.Desai@Sun.COM 	idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
24710504SKeyur.Desai@Sun.COM 
24810504SKeyur.Desai@Sun.COM 	if (pgcfg->domain_controller == NULL ||
24910504SKeyur.Desai@Sun.COM 	    pgcfg->domain_controller[0].host[0] == '\0') {
25010504SKeyur.Desai@Sun.COM 		/*
25110504SKeyur.Desai@Sun.COM 		 * No DCs.  Continue to use the previous AD config in case
25210504SKeyur.Desai@Sun.COM 		 * that's still good but auto-discovery had a transient failure.
25310504SKeyur.Desai@Sun.COM 		 * If that stops working we'll go into degraded mode anyways
25410504SKeyur.Desai@Sun.COM 		 * when it does.
25510504SKeyur.Desai@Sun.COM 		 */
25610504SKeyur.Desai@Sun.COM 		degrade_svc(0,
25710504SKeyur.Desai@Sun.COM 		    "Domain controller servers not configured/discoverable");
25810504SKeyur.Desai@Sun.COM 		return;
25910504SKeyur.Desai@Sun.COM 	}
26010504SKeyur.Desai@Sun.COM 
26110504SKeyur.Desai@Sun.COM 	old_dcs = _idmapdstate.dcs;
26210504SKeyur.Desai@Sun.COM 	old_num_dcs = _idmapdstate.num_dcs;
26310504SKeyur.Desai@Sun.COM 
26410504SKeyur.Desai@Sun.COM 	new_num_dcs = 1;
26510504SKeyur.Desai@Sun.COM 	new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *));
26610504SKeyur.Desai@Sun.COM 	if (new_dcs == NULL)
26710504SKeyur.Desai@Sun.COM 		goto nomem;
26810504SKeyur.Desai@Sun.COM 
26910504SKeyur.Desai@Sun.COM 	if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name,
27010504SKeyur.Desai@Sun.COM 	    ADUTILS_AD_DATA) != ADUTILS_SUCCESS)
27110504SKeyur.Desai@Sun.COM 		goto nomem;
27210504SKeyur.Desai@Sun.COM 
27310504SKeyur.Desai@Sun.COM 	for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) {
27410504SKeyur.Desai@Sun.COM 		if (idmap_add_ds(new_dcs[0],
27510504SKeyur.Desai@Sun.COM 		    pgcfg->domain_controller[i].host,
27610504SKeyur.Desai@Sun.COM 		    pgcfg->domain_controller[i].port) != 0)
27710504SKeyur.Desai@Sun.COM 			goto nomem;
27810504SKeyur.Desai@Sun.COM 	}
27910504SKeyur.Desai@Sun.COM 
280*10749SJordan.Brown@Sun.COM 	/*
281*10749SJordan.Brown@Sun.COM 	 * NEEDSWORK:  All we need here is to add the domain and SID for
282*10749SJordan.Brown@Sun.COM 	 * this DC to the list of domains supported by this entry.  Isn't
283*10749SJordan.Brown@Sun.COM 	 * there an easier way to find the SID than to walk through the list
284*10749SJordan.Brown@Sun.COM 	 * of all of the domains in the forest?
285*10749SJordan.Brown@Sun.COM 	 */
286*10749SJordan.Brown@Sun.COM 	ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest;
287*10749SJordan.Brown@Sun.COM 	if (dif != NULL) {
288*10749SJordan.Brown@Sun.COM 		for (; dif->domain[0] != '\0'; dif++) {
289*10749SJordan.Brown@Sun.COM 			if (domain_eq(pgcfg->domain_name, dif->domain)) {
290*10749SJordan.Brown@Sun.COM 				if (adutils_add_domain(new_dcs[0],
291*10749SJordan.Brown@Sun.COM 				    dif->domain, dif->sid) != 0)
292*10749SJordan.Brown@Sun.COM 					goto nomem;
293*10749SJordan.Brown@Sun.COM 				break;
294*10749SJordan.Brown@Sun.COM 			}
29510504SKeyur.Desai@Sun.COM 		}
29610504SKeyur.Desai@Sun.COM 	}
29710504SKeyur.Desai@Sun.COM 
29810504SKeyur.Desai@Sun.COM 	_idmapdstate.dcs = new_dcs;
29910504SKeyur.Desai@Sun.COM 	_idmapdstate.num_dcs = new_num_dcs;
30010504SKeyur.Desai@Sun.COM 
30110504SKeyur.Desai@Sun.COM 	if (old_dcs != NULL) {
30210504SKeyur.Desai@Sun.COM 		for (i = 0; i < old_num_dcs; i++)
30310504SKeyur.Desai@Sun.COM 			adutils_ad_free(&old_dcs[i]);
30410504SKeyur.Desai@Sun.COM 		free(old_dcs);
30510504SKeyur.Desai@Sun.COM 	}
30610504SKeyur.Desai@Sun.COM 
30710504SKeyur.Desai@Sun.COM 	return;
30810504SKeyur.Desai@Sun.COM 
30910504SKeyur.Desai@Sun.COM nomem:
31010504SKeyur.Desai@Sun.COM 	degrade_svc(0, "out of memory");
31110504SKeyur.Desai@Sun.COM 
31210504SKeyur.Desai@Sun.COM 	if (new_dcs != NULL) {
31310504SKeyur.Desai@Sun.COM 		if (new_dcs[0] != NULL)
31410504SKeyur.Desai@Sun.COM 			adutils_ad_free(&new_dcs[0]);
31510504SKeyur.Desai@Sun.COM 		free(new_dcs);
31610504SKeyur.Desai@Sun.COM 	}
31710504SKeyur.Desai@Sun.COM }
31810504SKeyur.Desai@Sun.COM 
31910504SKeyur.Desai@Sun.COM 
32010504SKeyur.Desai@Sun.COM void
32110504SKeyur.Desai@Sun.COM reload_ad(void)
32210504SKeyur.Desai@Sun.COM {
32310504SKeyur.Desai@Sun.COM 	reload_gcs();
32410504SKeyur.Desai@Sun.COM 	reload_dcs();
32510504SKeyur.Desai@Sun.COM }
3265317Sjp151216 
3274520Snw141292 void
3285908Sjp151216 print_idmapdstate()
3295908Sjp151216 {
3308361SJulian.Pullen@Sun.COM 	int i, j;
3315731Sbaban 	idmap_pg_config_t *pgcfg;
3328361SJulian.Pullen@Sun.COM 	idmap_trustedforest_t *tf;
3335317Sjp151216 
3344520Snw141292 	RDLOCK_CONFIG();
3354520Snw141292 
3365317Sjp151216 	if (_idmapdstate.cfg == NULL) {
3376017Snw141292 		idmapdlog(LOG_INFO, "Null configuration");
3385317Sjp151216 		UNLOCK_CONFIG();
3395317Sjp151216 		return;
3404520Snw141292 	}
3415317Sjp151216 
3425731Sbaban 	pgcfg = &_idmapdstate.cfg->pgcfg;
3435731Sbaban 
3446017Snw141292 	idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
3456017Snw141292 	idmapdlog(LOG_DEBUG, "default_domain=%s",
3465317Sjp151216 	    CHECK_NULL(pgcfg->default_domain));
3476017Snw141292 	idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
3486017Snw141292 	idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid));
3495317Sjp151216 	if (pgcfg->domain_controller == NULL ||
3505317Sjp151216 	    pgcfg->domain_controller[0].host[0] == '\0') {
3516017Snw141292 		idmapdlog(LOG_DEBUG, "No domain controllers known");
3525317Sjp151216 	} else {
3535317Sjp151216 		for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++)
3546017Snw141292 			idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d",
3556017Snw141292 			    pgcfg->domain_controller[i].host,
3565317Sjp151216 			    pgcfg->domain_controller[i].port);
3575317Sjp151216 	}
3586017Snw141292 	idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name));
3596017Snw141292 	idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name));
3605317Sjp151216 	if (pgcfg->global_catalog == NULL ||
3615317Sjp151216 	    pgcfg->global_catalog[0].host[0] == '\0') {
3626017Snw141292 		idmapdlog(LOG_DEBUG, "No global catalog servers known");
3635317Sjp151216 	} else {
3645317Sjp151216 		for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++)
3656017Snw141292 			idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d",
3665317Sjp151216 			    pgcfg->global_catalog[i].host,
3675317Sjp151216 			    pgcfg->global_catalog[i].port);
3685317Sjp151216 	}
3698361SJulian.Pullen@Sun.COM 	if (pgcfg->domains_in_forest == NULL ||
3708361SJulian.Pullen@Sun.COM 	    pgcfg->domains_in_forest[0].domain[0] == '\0') {
3718361SJulian.Pullen@Sun.COM 		idmapdlog(LOG_DEBUG, "No domains in forest %s known",
3728361SJulian.Pullen@Sun.COM 		    CHECK_NULL(pgcfg->forest_name));
3738361SJulian.Pullen@Sun.COM 	} else {
3748361SJulian.Pullen@Sun.COM 		for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++)
3758361SJulian.Pullen@Sun.COM 			idmapdlog(LOG_DEBUG, "domains in forest %s = %s",
3768361SJulian.Pullen@Sun.COM 			    CHECK_NULL(pgcfg->forest_name),
3778361SJulian.Pullen@Sun.COM 			    pgcfg->domains_in_forest[i].domain);
3788361SJulian.Pullen@Sun.COM 	}
3798361SJulian.Pullen@Sun.COM 	if (pgcfg->trusted_domains == NULL ||
3808361SJulian.Pullen@Sun.COM 	    pgcfg->trusted_domains[0].domain[0] == '\0') {
3818361SJulian.Pullen@Sun.COM 		idmapdlog(LOG_DEBUG, "No trusted domains known");
3828361SJulian.Pullen@Sun.COM 	} else {
3838361SJulian.Pullen@Sun.COM 		for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++)
3848361SJulian.Pullen@Sun.COM 			idmapdlog(LOG_DEBUG, "trusted domain = %s",
3858361SJulian.Pullen@Sun.COM 			    pgcfg->trusted_domains[i].domain);
3868361SJulian.Pullen@Sun.COM 	}
3878361SJulian.Pullen@Sun.COM 
3888361SJulian.Pullen@Sun.COM 	for (i = 0; i < pgcfg->num_trusted_forests; i++) {
3898361SJulian.Pullen@Sun.COM 		tf = &pgcfg->trusted_forests[i];
3908361SJulian.Pullen@Sun.COM 		for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++)
3918361SJulian.Pullen@Sun.COM 			idmapdlog(LOG_DEBUG,
3928361SJulian.Pullen@Sun.COM 			    "trusted forest %s global_catalog=%s port=%d",
3938361SJulian.Pullen@Sun.COM 			    tf->forest_name,
3948361SJulian.Pullen@Sun.COM 			    tf->global_catalog[j].host,
3958361SJulian.Pullen@Sun.COM 			    tf->global_catalog[j].port);
3968361SJulian.Pullen@Sun.COM 		for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) {
3978361SJulian.Pullen@Sun.COM 			if (tf->domains_in_forest[j].trusted) {
3988361SJulian.Pullen@Sun.COM 				idmapdlog(LOG_DEBUG,
3998361SJulian.Pullen@Sun.COM 				    "trusted forest %s domain=%s",
4008361SJulian.Pullen@Sun.COM 				    tf->forest_name,
4018361SJulian.Pullen@Sun.COM 				    tf->domains_in_forest[j].domain);
4028361SJulian.Pullen@Sun.COM 			}
4038361SJulian.Pullen@Sun.COM 		}
4048361SJulian.Pullen@Sun.COM 	}
4058361SJulian.Pullen@Sun.COM 
40610504SKeyur.Desai@Sun.COM 	idmapdlog(LOG_DEBUG, "directory_based_mapping=%s",
40710504SKeyur.Desai@Sun.COM 	    enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map));
4086017Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s",
4095731Sbaban 	    CHECK_NULL(pgcfg->ad_unixuser_attr));
4106017Snw141292 	idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s",
4115731Sbaban 	    CHECK_NULL(pgcfg->ad_unixgroup_attr));
4126017Snw141292 	idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s",
4135731Sbaban 	    CHECK_NULL(pgcfg->nldap_winname_attr));
4145317Sjp151216 
4154520Snw141292 	UNLOCK_CONFIG();
4164520Snw141292 }
4174520Snw141292 
4184520Snw141292 int
4195908Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid)
4205908Sjp151216 {
4214520Snw141292 	int	rc;
4224520Snw141292 
4234520Snw141292 	if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) {
4246017Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
4256017Snw141292 		    path, strerror(errno));
4264520Snw141292 		return (-1);
4274520Snw141292 	}
4284520Snw141292 
4294520Snw141292 	if (lchown(path, uid, gid) < 0) {
4306017Snw141292 		idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
4316017Snw141292 		    path, strerror(errno));
4324520Snw141292 		if (rc == 0)
4334520Snw141292 			(void) rmdir(path);
4344520Snw141292 		return (-1);
4354520Snw141292 	}
4364520Snw141292 	return (0);
4374520Snw141292 }
438