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 /*
22*12508Samw@Sun.COM * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
234520Snw141292 */
244520Snw141292
254520Snw141292 /*
264520Snw141292 * Initialization routines
274520Snw141292 */
284520Snw141292
294520Snw141292 #include "idmapd.h"
304520Snw141292 #include <signal.h>
314520Snw141292 #include <thread.h>
324520Snw141292 #include <string.h>
334520Snw141292 #include <errno.h>
344520Snw141292 #include <assert.h>
354520Snw141292 #include <unistd.h>
364520Snw141292 #include <sys/types.h>
374520Snw141292 #include <sys/stat.h>
384695Sbaban #include <rpcsvc/daemon_utils.h>
394520Snw141292
404520Snw141292
414520Snw141292 int
init_mapping_system()425908Sjp151216 init_mapping_system()
435908Sjp151216 {
444695Sbaban int rc = 0;
454695Sbaban
464520Snw141292 if (rwlock_init(&_idmapdstate.rwlk_cfg, USYNC_THREAD, NULL) != 0)
474520Snw141292 return (-1);
485731Sbaban if ((rc = load_config()) < 0)
495731Sbaban return (rc);
504695Sbaban
514695Sbaban (void) setegid(DAEMON_GID);
524695Sbaban (void) seteuid(DAEMON_UID);
534520Snw141292 if (init_dbs() < 0) {
544695Sbaban rc = -1;
554520Snw141292 fini_mapping_system();
564520Snw141292 }
574695Sbaban (void) seteuid(0);
584695Sbaban (void) setegid(0);
594695Sbaban
604695Sbaban return (rc);
614520Snw141292 }
624520Snw141292
634520Snw141292 void
fini_mapping_system()645908Sjp151216 fini_mapping_system()
655908Sjp151216 {
664520Snw141292 fini_dbs();
674520Snw141292 }
684520Snw141292
694520Snw141292 int
load_config()705908Sjp151216 load_config()
715908Sjp151216 {
725447Snw141292 int rc;
734520Snw141292 if ((_idmapdstate.cfg = idmap_cfg_init()) == NULL) {
746097Snw141292 degrade_svc(0, "failed to initialize config");
754520Snw141292 return (-1);
764520Snw141292 }
775317Sjp151216
7810504SKeyur.Desai@Sun.COM rc = idmap_cfg_upgrade(_idmapdstate.cfg);
7910504SKeyur.Desai@Sun.COM if (rc != 0) {
8010504SKeyur.Desai@Sun.COM degrade_svc(0, "fatal error while upgrading configuration");
8110504SKeyur.Desai@Sun.COM return (rc);
8210504SKeyur.Desai@Sun.COM }
8310504SKeyur.Desai@Sun.COM
846097Snw141292 rc = idmap_cfg_load(_idmapdstate.cfg, 0);
855447Snw141292 if (rc < -1) {
865447Snw141292 /* Total failure */
876097Snw141292 degrade_svc(0, "fatal error while loading configuration");
885731Sbaban return (rc);
894520Snw141292 }
905317Sjp151216
915447Snw141292 if (rc != 0)
925447Snw141292 /* Partial failure */
936017Snw141292 idmapdlog(LOG_ERR, "Various errors occurred while loading "
946017Snw141292 "the configuration; check the logs");
955447Snw141292
965968Snw141292 if ((rc = idmap_cfg_start_updates()) < 0) {
975968Snw141292 /* Total failure */
986097Snw141292 degrade_svc(0, "could not start config updater");
995968Snw141292 return (rc);
1005968Snw141292 }
1015447Snw141292
102*12508Samw@Sun.COM if (DBG(CONFIG, 1))
103*12508Samw@Sun.COM idmapdlog(LOG_DEBUG, "Initial configuration loaded");
1045447Snw141292
1055317Sjp151216 return (0);
1065317Sjp151216 }
1075317Sjp151216
1085317Sjp151216
1096097Snw141292 void
reload_gcs()11010504SKeyur.Desai@Sun.COM reload_gcs()
1115908Sjp151216 {
1128361SJulian.Pullen@Sun.COM int i, j;
11310504SKeyur.Desai@Sun.COM adutils_ad_t **new_gcs;
114*12508Samw@Sun.COM adutils_ad_t **old_gcs = _idmapdstate.gcs;
11510504SKeyur.Desai@Sun.COM int new_num_gcs;
116*12508Samw@Sun.COM int old_num_gcs = _idmapdstate.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
122*12508Samw@Sun.COM if (pgcfg->domain_name == NULL) {
123*12508Samw@Sun.COM /* No domain name specified - workgroup mode. */
124*12508Samw@Sun.COM new_gcs = NULL;
125*12508Samw@Sun.COM new_num_gcs = 0;
126*12508Samw@Sun.COM goto out;
127*12508Samw@Sun.COM }
128*12508Samw@Sun.COM
1296097Snw141292 if (pgcfg->global_catalog == NULL ||
1306097Snw141292 pgcfg->global_catalog[0].host[0] == '\0') {
1316097Snw141292 /*
1326097Snw141292 * No GCs. Continue to use the previous AD config in case
1336097Snw141292 * that's still good but auto-discovery had a transient failure.
1346097Snw141292 * If that stops working we'll go into degraded mode anyways
1356097Snw141292 * when it does.
1366097Snw141292 */
1376097Snw141292 degrade_svc(0,
1386097Snw141292 "Global Catalog servers not configured/discoverable");
1396097Snw141292 return;
1404520Snw141292 }
1415317Sjp151216
14210504SKeyur.Desai@Sun.COM new_num_gcs = 1 + num_trustfor;
14310504SKeyur.Desai@Sun.COM new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *));
14410504SKeyur.Desai@Sun.COM if (new_gcs == NULL) {
1458361SJulian.Pullen@Sun.COM degrade_svc(0, "could not allocate AD context array "
1468361SJulian.Pullen@Sun.COM "(out of memory)");
1478361SJulian.Pullen@Sun.COM return;
1488361SJulian.Pullen@Sun.COM }
1498361SJulian.Pullen@Sun.COM
15010504SKeyur.Desai@Sun.COM if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) !=
15110504SKeyur.Desai@Sun.COM ADUTILS_SUCCESS) {
15210504SKeyur.Desai@Sun.COM free(new_gcs);
1538361SJulian.Pullen@Sun.COM degrade_svc(0, "could not initialize AD context "
1548361SJulian.Pullen@Sun.COM "(out of memory)");
1556097Snw141292 return;
1564520Snw141292 }
1575317Sjp151216
1585317Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) {
15910504SKeyur.Desai@Sun.COM if (idmap_add_ds(new_gcs[0],
1605317Sjp151216 pgcfg->global_catalog[i].host,
1615317Sjp151216 pgcfg->global_catalog[i].port) != 0) {
16210504SKeyur.Desai@Sun.COM adutils_ad_free(&new_gcs[0]);
16310504SKeyur.Desai@Sun.COM free(new_gcs);
1648361SJulian.Pullen@Sun.COM degrade_svc(0, "could not set AD hosts "
1658361SJulian.Pullen@Sun.COM "(out of memory)");
1666097Snw141292 return;
1675317Sjp151216 }
1685317Sjp151216 }
1695317Sjp151216
1708361SJulian.Pullen@Sun.COM if (pgcfg->domains_in_forest != NULL) {
1718361SJulian.Pullen@Sun.COM for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0';
1728361SJulian.Pullen@Sun.COM i++) {
17310504SKeyur.Desai@Sun.COM if (adutils_add_domain(new_gcs[0],
1748361SJulian.Pullen@Sun.COM pgcfg->domains_in_forest[i].domain,
1758361SJulian.Pullen@Sun.COM pgcfg->domains_in_forest[i].sid) != 0) {
17610504SKeyur.Desai@Sun.COM adutils_ad_free(&new_gcs[0]);
17710504SKeyur.Desai@Sun.COM free(new_gcs);
1788361SJulian.Pullen@Sun.COM degrade_svc(0, "could not set AD domains "
1798361SJulian.Pullen@Sun.COM "(out of memory)");
1808361SJulian.Pullen@Sun.COM return;
1818361SJulian.Pullen@Sun.COM }
1828361SJulian.Pullen@Sun.COM }
1838361SJulian.Pullen@Sun.COM }
1845317Sjp151216
1858361SJulian.Pullen@Sun.COM for (i = 0; i < num_trustfor; i++) {
18610504SKeyur.Desai@Sun.COM if (adutils_ad_alloc(&new_gcs[i + 1], NULL,
1878361SJulian.Pullen@Sun.COM ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) {
1888361SJulian.Pullen@Sun.COM degrade_svc(0, "could not initialize trusted AD "
1898361SJulian.Pullen@Sun.COM "context (out of memory)");
19010504SKeyur.Desai@Sun.COM new_num_gcs = i + 1;
1918361SJulian.Pullen@Sun.COM goto out;
1928361SJulian.Pullen@Sun.COM }
1938361SJulian.Pullen@Sun.COM for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0';
1948361SJulian.Pullen@Sun.COM j++) {
19510504SKeyur.Desai@Sun.COM if (idmap_add_ds(new_gcs[i + 1],
1968361SJulian.Pullen@Sun.COM trustfor[i].global_catalog[j].host,
1978361SJulian.Pullen@Sun.COM trustfor[i].global_catalog[j].port) != 0) {
19810504SKeyur.Desai@Sun.COM adutils_ad_free(&new_gcs[i + 1]);
1998361SJulian.Pullen@Sun.COM degrade_svc(0, "could not set trusted "
2008361SJulian.Pullen@Sun.COM "AD hosts (out of memory)");
20110504SKeyur.Desai@Sun.COM new_num_gcs = i + 1;
2028361SJulian.Pullen@Sun.COM goto out;
2038361SJulian.Pullen@Sun.COM }
2048361SJulian.Pullen@Sun.COM }
2058361SJulian.Pullen@Sun.COM for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0';
2068361SJulian.Pullen@Sun.COM j++) {
2078361SJulian.Pullen@Sun.COM domain_in_forest = &trustfor[i].domains_in_forest[j];
2088361SJulian.Pullen@Sun.COM /* Only add domains which are marked */
2098361SJulian.Pullen@Sun.COM if (domain_in_forest->trusted) {
21010504SKeyur.Desai@Sun.COM if (adutils_add_domain(new_gcs[i + 1],
2118361SJulian.Pullen@Sun.COM domain_in_forest->domain,
2128361SJulian.Pullen@Sun.COM domain_in_forest->sid) != 0) {
21310504SKeyur.Desai@Sun.COM adutils_ad_free(&new_gcs[i + 1]);
2148361SJulian.Pullen@Sun.COM degrade_svc(0, "could not set trusted "
2158361SJulian.Pullen@Sun.COM "AD domains (out of memory)");
21610504SKeyur.Desai@Sun.COM new_num_gcs = i + 1;
2178361SJulian.Pullen@Sun.COM goto out;
2188361SJulian.Pullen@Sun.COM }
2198361SJulian.Pullen@Sun.COM }
2208361SJulian.Pullen@Sun.COM }
2218361SJulian.Pullen@Sun.COM }
2228361SJulian.Pullen@Sun.COM
2238361SJulian.Pullen@Sun.COM out:
22410504SKeyur.Desai@Sun.COM _idmapdstate.gcs = new_gcs;
22510504SKeyur.Desai@Sun.COM _idmapdstate.num_gcs = new_num_gcs;
2268361SJulian.Pullen@Sun.COM
22710504SKeyur.Desai@Sun.COM if (old_gcs != NULL) {
22810504SKeyur.Desai@Sun.COM for (i = 0; i < old_num_gcs; i++)
22910504SKeyur.Desai@Sun.COM adutils_ad_free(&old_gcs[i]);
23010504SKeyur.Desai@Sun.COM free(old_gcs);
2318361SJulian.Pullen@Sun.COM }
2324520Snw141292 }
2334520Snw141292
23410504SKeyur.Desai@Sun.COM /*
23510504SKeyur.Desai@Sun.COM * NEEDSWORK: This should load entries for domain servers for all known
23610504SKeyur.Desai@Sun.COM * domains - the joined domain, other domains in the forest, and trusted
23710504SKeyur.Desai@Sun.COM * domains in other forests. However, we don't yet discover any DCs other
23810504SKeyur.Desai@Sun.COM * than the DCs for the joined domain.
23910504SKeyur.Desai@Sun.COM */
24010504SKeyur.Desai@Sun.COM static
24110504SKeyur.Desai@Sun.COM void
reload_dcs(void)24210504SKeyur.Desai@Sun.COM reload_dcs(void)
24310504SKeyur.Desai@Sun.COM {
24410504SKeyur.Desai@Sun.COM int i;
24510504SKeyur.Desai@Sun.COM adutils_ad_t **new_dcs;
246*12508Samw@Sun.COM adutils_ad_t **old_dcs = _idmapdstate.dcs;
24710504SKeyur.Desai@Sun.COM int new_num_dcs;
248*12508Samw@Sun.COM int old_num_dcs = _idmapdstate.num_dcs;
24910504SKeyur.Desai@Sun.COM idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
25010504SKeyur.Desai@Sun.COM
251*12508Samw@Sun.COM if (pgcfg->domain_name == NULL) {
252*12508Samw@Sun.COM /* No domain name specified - workgroup mode. */
253*12508Samw@Sun.COM new_dcs = NULL;
254*12508Samw@Sun.COM new_num_dcs = 0;
255*12508Samw@Sun.COM goto out;
256*12508Samw@Sun.COM }
257*12508Samw@Sun.COM
25810504SKeyur.Desai@Sun.COM if (pgcfg->domain_controller == NULL ||
25910504SKeyur.Desai@Sun.COM pgcfg->domain_controller[0].host[0] == '\0') {
26010504SKeyur.Desai@Sun.COM /*
26110504SKeyur.Desai@Sun.COM * No DCs. Continue to use the previous AD config in case
26210504SKeyur.Desai@Sun.COM * that's still good but auto-discovery had a transient failure.
26310504SKeyur.Desai@Sun.COM * If that stops working we'll go into degraded mode anyways
26410504SKeyur.Desai@Sun.COM * when it does.
26510504SKeyur.Desai@Sun.COM */
26610504SKeyur.Desai@Sun.COM degrade_svc(0,
26710504SKeyur.Desai@Sun.COM "Domain controller servers not configured/discoverable");
26810504SKeyur.Desai@Sun.COM return;
26910504SKeyur.Desai@Sun.COM }
27010504SKeyur.Desai@Sun.COM
27110504SKeyur.Desai@Sun.COM new_num_dcs = 1;
27210504SKeyur.Desai@Sun.COM new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *));
27310504SKeyur.Desai@Sun.COM if (new_dcs == NULL)
27410504SKeyur.Desai@Sun.COM goto nomem;
27510504SKeyur.Desai@Sun.COM
27610504SKeyur.Desai@Sun.COM if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name,
27710504SKeyur.Desai@Sun.COM ADUTILS_AD_DATA) != ADUTILS_SUCCESS)
27810504SKeyur.Desai@Sun.COM goto nomem;
27910504SKeyur.Desai@Sun.COM
28010504SKeyur.Desai@Sun.COM for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) {
28110504SKeyur.Desai@Sun.COM if (idmap_add_ds(new_dcs[0],
28210504SKeyur.Desai@Sun.COM pgcfg->domain_controller[i].host,
28310504SKeyur.Desai@Sun.COM pgcfg->domain_controller[i].port) != 0)
28410504SKeyur.Desai@Sun.COM goto nomem;
28510504SKeyur.Desai@Sun.COM }
28610504SKeyur.Desai@Sun.COM
28710749SJordan.Brown@Sun.COM /*
28810749SJordan.Brown@Sun.COM * NEEDSWORK: All we need here is to add the domain and SID for
28910749SJordan.Brown@Sun.COM * this DC to the list of domains supported by this entry. Isn't
29010749SJordan.Brown@Sun.COM * there an easier way to find the SID than to walk through the list
29110749SJordan.Brown@Sun.COM * of all of the domains in the forest?
29210749SJordan.Brown@Sun.COM */
29310749SJordan.Brown@Sun.COM ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest;
29410749SJordan.Brown@Sun.COM if (dif != NULL) {
29510749SJordan.Brown@Sun.COM for (; dif->domain[0] != '\0'; dif++) {
29610749SJordan.Brown@Sun.COM if (domain_eq(pgcfg->domain_name, dif->domain)) {
29710749SJordan.Brown@Sun.COM if (adutils_add_domain(new_dcs[0],
29810749SJordan.Brown@Sun.COM dif->domain, dif->sid) != 0)
29910749SJordan.Brown@Sun.COM goto nomem;
30010749SJordan.Brown@Sun.COM break;
30110749SJordan.Brown@Sun.COM }
30210504SKeyur.Desai@Sun.COM }
30310504SKeyur.Desai@Sun.COM }
30410504SKeyur.Desai@Sun.COM
305*12508Samw@Sun.COM out:
30610504SKeyur.Desai@Sun.COM _idmapdstate.dcs = new_dcs;
30710504SKeyur.Desai@Sun.COM _idmapdstate.num_dcs = new_num_dcs;
30810504SKeyur.Desai@Sun.COM
30910504SKeyur.Desai@Sun.COM if (old_dcs != NULL) {
31010504SKeyur.Desai@Sun.COM for (i = 0; i < old_num_dcs; i++)
31110504SKeyur.Desai@Sun.COM adutils_ad_free(&old_dcs[i]);
31210504SKeyur.Desai@Sun.COM free(old_dcs);
31310504SKeyur.Desai@Sun.COM }
31410504SKeyur.Desai@Sun.COM
31510504SKeyur.Desai@Sun.COM return;
31610504SKeyur.Desai@Sun.COM
31710504SKeyur.Desai@Sun.COM nomem:
31810504SKeyur.Desai@Sun.COM degrade_svc(0, "out of memory");
31910504SKeyur.Desai@Sun.COM
32010504SKeyur.Desai@Sun.COM if (new_dcs != NULL) {
32110504SKeyur.Desai@Sun.COM if (new_dcs[0] != NULL)
32210504SKeyur.Desai@Sun.COM adutils_ad_free(&new_dcs[0]);
32310504SKeyur.Desai@Sun.COM free(new_dcs);
32410504SKeyur.Desai@Sun.COM }
32510504SKeyur.Desai@Sun.COM }
32610504SKeyur.Desai@Sun.COM
32710504SKeyur.Desai@Sun.COM
32810504SKeyur.Desai@Sun.COM void
reload_ad(void)32910504SKeyur.Desai@Sun.COM reload_ad(void)
33010504SKeyur.Desai@Sun.COM {
33110504SKeyur.Desai@Sun.COM reload_gcs();
33210504SKeyur.Desai@Sun.COM reload_dcs();
33310504SKeyur.Desai@Sun.COM }
3345317Sjp151216
3354520Snw141292 void
print_idmapdstate(void)336*12508Samw@Sun.COM print_idmapdstate(void)
3375908Sjp151216 {
3388361SJulian.Pullen@Sun.COM int i, j;
3395731Sbaban idmap_pg_config_t *pgcfg;
3408361SJulian.Pullen@Sun.COM idmap_trustedforest_t *tf;
3415317Sjp151216
3424520Snw141292 RDLOCK_CONFIG();
3434520Snw141292
3445317Sjp151216 if (_idmapdstate.cfg == NULL) {
3456017Snw141292 idmapdlog(LOG_INFO, "Null configuration");
3465317Sjp151216 UNLOCK_CONFIG();
3475317Sjp151216 return;
3484520Snw141292 }
3495317Sjp151216
3505731Sbaban pgcfg = &_idmapdstate.cfg->pgcfg;
3515731Sbaban
3526017Snw141292 idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
3536017Snw141292 idmapdlog(LOG_DEBUG, "default_domain=%s",
3545317Sjp151216 CHECK_NULL(pgcfg->default_domain));
3556017Snw141292 idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
3566017Snw141292 idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid));
3575317Sjp151216 if (pgcfg->domain_controller == NULL ||
3585317Sjp151216 pgcfg->domain_controller[0].host[0] == '\0') {
3596017Snw141292 idmapdlog(LOG_DEBUG, "No domain controllers known");
3605317Sjp151216 } else {
3615317Sjp151216 for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++)
3626017Snw141292 idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d",
3636017Snw141292 pgcfg->domain_controller[i].host,
3645317Sjp151216 pgcfg->domain_controller[i].port);
3655317Sjp151216 }
3666017Snw141292 idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name));
3676017Snw141292 idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name));
3685317Sjp151216 if (pgcfg->global_catalog == NULL ||
3695317Sjp151216 pgcfg->global_catalog[0].host[0] == '\0') {
3706017Snw141292 idmapdlog(LOG_DEBUG, "No global catalog servers known");
3715317Sjp151216 } else {
3725317Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++)
3736017Snw141292 idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d",
3745317Sjp151216 pgcfg->global_catalog[i].host,
3755317Sjp151216 pgcfg->global_catalog[i].port);
3765317Sjp151216 }
3778361SJulian.Pullen@Sun.COM if (pgcfg->domains_in_forest == NULL ||
3788361SJulian.Pullen@Sun.COM pgcfg->domains_in_forest[0].domain[0] == '\0') {
3798361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG, "No domains in forest %s known",
3808361SJulian.Pullen@Sun.COM CHECK_NULL(pgcfg->forest_name));
3818361SJulian.Pullen@Sun.COM } else {
3828361SJulian.Pullen@Sun.COM for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++)
3838361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG, "domains in forest %s = %s",
3848361SJulian.Pullen@Sun.COM CHECK_NULL(pgcfg->forest_name),
3858361SJulian.Pullen@Sun.COM pgcfg->domains_in_forest[i].domain);
3868361SJulian.Pullen@Sun.COM }
3878361SJulian.Pullen@Sun.COM if (pgcfg->trusted_domains == NULL ||
3888361SJulian.Pullen@Sun.COM pgcfg->trusted_domains[0].domain[0] == '\0') {
3898361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG, "No trusted domains known");
3908361SJulian.Pullen@Sun.COM } else {
3918361SJulian.Pullen@Sun.COM for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++)
3928361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG, "trusted domain = %s",
3938361SJulian.Pullen@Sun.COM pgcfg->trusted_domains[i].domain);
3948361SJulian.Pullen@Sun.COM }
3958361SJulian.Pullen@Sun.COM
3968361SJulian.Pullen@Sun.COM for (i = 0; i < pgcfg->num_trusted_forests; i++) {
3978361SJulian.Pullen@Sun.COM tf = &pgcfg->trusted_forests[i];
3988361SJulian.Pullen@Sun.COM for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++)
3998361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG,
4008361SJulian.Pullen@Sun.COM "trusted forest %s global_catalog=%s port=%d",
4018361SJulian.Pullen@Sun.COM tf->forest_name,
4028361SJulian.Pullen@Sun.COM tf->global_catalog[j].host,
4038361SJulian.Pullen@Sun.COM tf->global_catalog[j].port);
4048361SJulian.Pullen@Sun.COM for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) {
4058361SJulian.Pullen@Sun.COM if (tf->domains_in_forest[j].trusted) {
4068361SJulian.Pullen@Sun.COM idmapdlog(LOG_DEBUG,
4078361SJulian.Pullen@Sun.COM "trusted forest %s domain=%s",
4088361SJulian.Pullen@Sun.COM tf->forest_name,
4098361SJulian.Pullen@Sun.COM tf->domains_in_forest[j].domain);
4108361SJulian.Pullen@Sun.COM }
4118361SJulian.Pullen@Sun.COM }
4128361SJulian.Pullen@Sun.COM }
4138361SJulian.Pullen@Sun.COM
41410504SKeyur.Desai@Sun.COM idmapdlog(LOG_DEBUG, "directory_based_mapping=%s",
41510504SKeyur.Desai@Sun.COM enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map));
4166017Snw141292 idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s",
4175731Sbaban CHECK_NULL(pgcfg->ad_unixuser_attr));
4186017Snw141292 idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s",
4195731Sbaban CHECK_NULL(pgcfg->ad_unixgroup_attr));
4206017Snw141292 idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s",
4215731Sbaban CHECK_NULL(pgcfg->nldap_winname_attr));
4225317Sjp151216
4234520Snw141292 UNLOCK_CONFIG();
4244520Snw141292 }
4254520Snw141292
4264520Snw141292 int
create_directory(const char * path,uid_t uid,gid_t gid)4275908Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid)
4285908Sjp151216 {
4294520Snw141292 int rc;
4304520Snw141292
4314520Snw141292 if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) {
4326017Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
4336017Snw141292 path, strerror(errno));
4344520Snw141292 return (-1);
4354520Snw141292 }
4364520Snw141292
4374520Snw141292 if (lchown(path, uid, gid) < 0) {
4386017Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
4396017Snw141292 path, strerror(errno));
4404520Snw141292 if (rc == 0)
4414520Snw141292 (void) rmdir(path);
4424520Snw141292 return (-1);
4434520Snw141292 }
4444520Snw141292 return (0);
4454520Snw141292 }
446