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*b3700b07SGordon Ross * Copyright 2014 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 434edd44c5Sjp151216 init_mapping_system() 444edd44c5Sjp151216 { 458edda628Sbaban int rc = 0; 468edda628Sbaban 47e8c27ec8Sbaban if ((rc = load_config()) < 0) 48e8c27ec8Sbaban return (rc); 498edda628Sbaban 508edda628Sbaban (void) setegid(DAEMON_GID); 518edda628Sbaban (void) seteuid(DAEMON_UID); 52c5c4113dSnw141292 if (init_dbs() < 0) { 538edda628Sbaban rc = -1; 54c5c4113dSnw141292 fini_mapping_system(); 55c5c4113dSnw141292 } 568edda628Sbaban (void) seteuid(0); 578edda628Sbaban (void) setegid(0); 588edda628Sbaban 598edda628Sbaban return (rc); 60c5c4113dSnw141292 } 61c5c4113dSnw141292 62c5c4113dSnw141292 void 634edd44c5Sjp151216 fini_mapping_system() 644edd44c5Sjp151216 { 65c5c4113dSnw141292 fini_dbs(); 66c5c4113dSnw141292 } 67c5c4113dSnw141292 68c5c4113dSnw141292 int 694edd44c5Sjp151216 load_config() 704edd44c5Sjp151216 { 71e3c2d6aaSnw141292 int rc; 72c5c4113dSnw141292 if ((_idmapdstate.cfg = idmap_cfg_init()) == NULL) { 73349d5d8fSnw141292 degrade_svc(0, "failed to initialize config"); 74c5c4113dSnw141292 return (-1); 75c5c4113dSnw141292 } 76c8e26105Sjp151216 77e3f2c991SKeyur Desai rc = idmap_cfg_upgrade(_idmapdstate.cfg); 78e3f2c991SKeyur Desai if (rc != 0) { 79e3f2c991SKeyur Desai degrade_svc(0, "fatal error while upgrading configuration"); 80e3f2c991SKeyur Desai return (rc); 81e3f2c991SKeyur Desai } 82e3f2c991SKeyur Desai 83349d5d8fSnw141292 rc = idmap_cfg_load(_idmapdstate.cfg, 0); 84e3c2d6aaSnw141292 if (rc < -1) { 85e3c2d6aaSnw141292 /* Total failure */ 86349d5d8fSnw141292 degrade_svc(0, "fatal error while loading configuration"); 87e8c27ec8Sbaban return (rc); 88c5c4113dSnw141292 } 89c8e26105Sjp151216 90e3c2d6aaSnw141292 if (rc != 0) 91e3c2d6aaSnw141292 /* Partial failure */ 9271590c90Snw141292 idmapdlog(LOG_ERR, "Various errors occurred while loading " 9371590c90Snw141292 "the configuration; check the logs"); 94e3c2d6aaSnw141292 950dcc7149Snw141292 if ((rc = idmap_cfg_start_updates()) < 0) { 960dcc7149Snw141292 /* Total failure */ 97349d5d8fSnw141292 degrade_svc(0, "could not start config updater"); 980dcc7149Snw141292 return (rc); 990dcc7149Snw141292 } 100e3c2d6aaSnw141292 101148c5f43SAlan Wright if (DBG(CONFIG, 1)) 10271590c90Snw141292 idmapdlog(LOG_DEBUG, "Initial configuration loaded"); 103e3c2d6aaSnw141292 104c5c4113dSnw141292 return (0); 105c5c4113dSnw141292 } 106c5c4113dSnw141292 107c8e26105Sjp151216 108349d5d8fSnw141292 void 109e3f2c991SKeyur Desai reload_gcs() 1104edd44c5Sjp151216 { 1114d61c878SJulian Pullen int i, j; 112e3f2c991SKeyur Desai adutils_ad_t **new_gcs; 113148c5f43SAlan Wright adutils_ad_t **old_gcs = _idmapdstate.gcs; 114e3f2c991SKeyur Desai int new_num_gcs; 115148c5f43SAlan Wright int old_num_gcs = _idmapdstate.num_gcs; 116c8e26105Sjp151216 idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg; 1174d61c878SJulian Pullen idmap_trustedforest_t *trustfor = pgcfg->trusted_forests; 1184d61c878SJulian Pullen int num_trustfor = pgcfg->num_trusted_forests; 1194d61c878SJulian Pullen ad_disc_domainsinforest_t *domain_in_forest; 120c8e26105Sjp151216 1211ed6b69aSGordon Ross if (pgcfg->use_ads == B_FALSE || 1221ed6b69aSGordon Ross pgcfg->domain_name == NULL) { 1231ed6b69aSGordon Ross /* 1241ed6b69aSGordon Ross * ADS disabled, or no domain name specified. 1251ed6b69aSGordon Ross * Not using adutils. (but still can use lsa) 1261ed6b69aSGordon Ross */ 127148c5f43SAlan Wright new_gcs = NULL; 128148c5f43SAlan Wright new_num_gcs = 0; 129148c5f43SAlan Wright goto out; 130148c5f43SAlan Wright } 131148c5f43SAlan Wright 132349d5d8fSnw141292 if (pgcfg->global_catalog == NULL || 133349d5d8fSnw141292 pgcfg->global_catalog[0].host[0] == '\0') { 134349d5d8fSnw141292 /* 135349d5d8fSnw141292 * No GCs. Continue to use the previous AD config in case 136349d5d8fSnw141292 * that's still good but auto-discovery had a transient failure. 137349d5d8fSnw141292 * If that stops working we'll go into degraded mode anyways 138349d5d8fSnw141292 * when it does. 139349d5d8fSnw141292 */ 140*b3700b07SGordon Ross idmapdlog(LOG_INFO, 141349d5d8fSnw141292 "Global Catalog servers not configured/discoverable"); 142349d5d8fSnw141292 return; 143c8e26105Sjp151216 } 144c8e26105Sjp151216 145e3f2c991SKeyur Desai new_num_gcs = 1 + num_trustfor; 146e3f2c991SKeyur Desai new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *)); 147e3f2c991SKeyur Desai if (new_gcs == NULL) { 1484d61c878SJulian Pullen degrade_svc(0, "could not allocate AD context array " 1494d61c878SJulian Pullen "(out of memory)"); 1504d61c878SJulian Pullen return; 1514d61c878SJulian Pullen } 1524d61c878SJulian Pullen 153e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) != 154e3f2c991SKeyur Desai ADUTILS_SUCCESS) { 155e3f2c991SKeyur Desai free(new_gcs); 1564d61c878SJulian Pullen degrade_svc(0, "could not initialize AD context " 1574d61c878SJulian Pullen "(out of memory)"); 158349d5d8fSnw141292 return; 159c8e26105Sjp151216 } 160c8e26105Sjp151216 161c8e26105Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) { 162e3f2c991SKeyur Desai if (idmap_add_ds(new_gcs[0], 163c8e26105Sjp151216 pgcfg->global_catalog[i].host, 164c8e26105Sjp151216 pgcfg->global_catalog[i].port) != 0) { 165e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[0]); 166e3f2c991SKeyur Desai free(new_gcs); 1674d61c878SJulian Pullen degrade_svc(0, "could not set AD hosts " 1684d61c878SJulian Pullen "(out of memory)"); 169349d5d8fSnw141292 return; 170c8e26105Sjp151216 } 171c8e26105Sjp151216 } 172c8e26105Sjp151216 1734d61c878SJulian Pullen if (pgcfg->domains_in_forest != NULL) { 1744d61c878SJulian Pullen for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; 1754d61c878SJulian Pullen i++) { 176e3f2c991SKeyur Desai if (adutils_add_domain(new_gcs[0], 1774d61c878SJulian Pullen pgcfg->domains_in_forest[i].domain, 1784d61c878SJulian Pullen pgcfg->domains_in_forest[i].sid) != 0) { 179e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[0]); 180e3f2c991SKeyur Desai free(new_gcs); 1814d61c878SJulian Pullen degrade_svc(0, "could not set AD domains " 1824d61c878SJulian Pullen "(out of memory)"); 1834d61c878SJulian Pullen return; 1844d61c878SJulian Pullen } 1854d61c878SJulian Pullen } 1864d61c878SJulian Pullen } 187c8e26105Sjp151216 1884d61c878SJulian Pullen for (i = 0; i < num_trustfor; i++) { 189e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_gcs[i + 1], NULL, 1904d61c878SJulian Pullen ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) { 1914d61c878SJulian Pullen degrade_svc(0, "could not initialize trusted AD " 1924d61c878SJulian Pullen "context (out of memory)"); 193e3f2c991SKeyur Desai new_num_gcs = i + 1; 1944d61c878SJulian Pullen goto out; 1954d61c878SJulian Pullen } 1964d61c878SJulian Pullen for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0'; 1974d61c878SJulian Pullen j++) { 198e3f2c991SKeyur Desai if (idmap_add_ds(new_gcs[i + 1], 1994d61c878SJulian Pullen trustfor[i].global_catalog[j].host, 2004d61c878SJulian Pullen trustfor[i].global_catalog[j].port) != 0) { 201e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[i + 1]); 2024d61c878SJulian Pullen degrade_svc(0, "could not set trusted " 2034d61c878SJulian Pullen "AD hosts (out of memory)"); 204e3f2c991SKeyur Desai new_num_gcs = i + 1; 2054d61c878SJulian Pullen goto out; 2064d61c878SJulian Pullen } 2074d61c878SJulian Pullen } 2084d61c878SJulian Pullen for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0'; 2094d61c878SJulian Pullen j++) { 2104d61c878SJulian Pullen domain_in_forest = &trustfor[i].domains_in_forest[j]; 2114d61c878SJulian Pullen /* Only add domains which are marked */ 2124d61c878SJulian Pullen if (domain_in_forest->trusted) { 213e3f2c991SKeyur Desai if (adutils_add_domain(new_gcs[i + 1], 2144d61c878SJulian Pullen domain_in_forest->domain, 2154d61c878SJulian Pullen domain_in_forest->sid) != 0) { 216e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[i + 1]); 2174d61c878SJulian Pullen degrade_svc(0, "could not set trusted " 2184d61c878SJulian Pullen "AD domains (out of memory)"); 219e3f2c991SKeyur Desai new_num_gcs = i + 1; 2204d61c878SJulian Pullen goto out; 2214d61c878SJulian Pullen } 2224d61c878SJulian Pullen } 2234d61c878SJulian Pullen } 2244d61c878SJulian Pullen } 2254d61c878SJulian Pullen 2264d61c878SJulian Pullen out: 227e3f2c991SKeyur Desai _idmapdstate.gcs = new_gcs; 228e3f2c991SKeyur Desai _idmapdstate.num_gcs = new_num_gcs; 2294d61c878SJulian Pullen 230e3f2c991SKeyur Desai if (old_gcs != NULL) { 231e3f2c991SKeyur Desai for (i = 0; i < old_num_gcs; i++) 232e3f2c991SKeyur Desai adutils_ad_free(&old_gcs[i]); 233e3f2c991SKeyur Desai free(old_gcs); 2344d61c878SJulian Pullen } 235c8e26105Sjp151216 } 236c8e26105Sjp151216 237e3f2c991SKeyur Desai /* 238e3f2c991SKeyur Desai * NEEDSWORK: This should load entries for domain servers for all known 239e3f2c991SKeyur Desai * domains - the joined domain, other domains in the forest, and trusted 240e3f2c991SKeyur Desai * domains in other forests. However, we don't yet discover any DCs other 241e3f2c991SKeyur Desai * than the DCs for the joined domain. 242e3f2c991SKeyur Desai */ 243e3f2c991SKeyur Desai static 244e3f2c991SKeyur Desai void 245e3f2c991SKeyur Desai reload_dcs(void) 246e3f2c991SKeyur Desai { 247e3f2c991SKeyur Desai int i; 248e3f2c991SKeyur Desai adutils_ad_t **new_dcs; 249148c5f43SAlan Wright adutils_ad_t **old_dcs = _idmapdstate.dcs; 250e3f2c991SKeyur Desai int new_num_dcs; 251148c5f43SAlan Wright int old_num_dcs = _idmapdstate.num_dcs; 252e3f2c991SKeyur Desai idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg; 253e3f2c991SKeyur Desai 2541ed6b69aSGordon Ross if (pgcfg->use_ads == B_FALSE || 2551ed6b69aSGordon Ross pgcfg->domain_name == NULL) { 2561ed6b69aSGordon Ross /* 2571ed6b69aSGordon Ross * ADS disabled, or no domain name specified. 2581ed6b69aSGordon Ross * Not using adutils. (but still can use lsa) 2591ed6b69aSGordon Ross */ 260148c5f43SAlan Wright new_dcs = NULL; 261148c5f43SAlan Wright new_num_dcs = 0; 262148c5f43SAlan Wright goto out; 263148c5f43SAlan Wright } 264148c5f43SAlan Wright 265e3f2c991SKeyur Desai if (pgcfg->domain_controller == NULL || 266e3f2c991SKeyur Desai pgcfg->domain_controller[0].host[0] == '\0') { 267e3f2c991SKeyur Desai /* 268e3f2c991SKeyur Desai * No DCs. Continue to use the previous AD config in case 269e3f2c991SKeyur Desai * that's still good but auto-discovery had a transient failure. 270e3f2c991SKeyur Desai * If that stops working we'll go into degraded mode anyways 271e3f2c991SKeyur Desai * when it does. 272e3f2c991SKeyur Desai */ 273*b3700b07SGordon Ross idmapdlog(LOG_INFO, 274e3f2c991SKeyur Desai "Domain controller servers not configured/discoverable"); 275e3f2c991SKeyur Desai return; 276e3f2c991SKeyur Desai } 277e3f2c991SKeyur Desai 278e3f2c991SKeyur Desai new_num_dcs = 1; 279e3f2c991SKeyur Desai new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *)); 280e3f2c991SKeyur Desai if (new_dcs == NULL) 281e3f2c991SKeyur Desai goto nomem; 282e3f2c991SKeyur Desai 283e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name, 284e3f2c991SKeyur Desai ADUTILS_AD_DATA) != ADUTILS_SUCCESS) 285e3f2c991SKeyur Desai goto nomem; 286e3f2c991SKeyur Desai 287e3f2c991SKeyur Desai for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) { 288e3f2c991SKeyur Desai if (idmap_add_ds(new_dcs[0], 289e3f2c991SKeyur Desai pgcfg->domain_controller[i].host, 290e3f2c991SKeyur Desai pgcfg->domain_controller[i].port) != 0) 291e3f2c991SKeyur Desai goto nomem; 292e3f2c991SKeyur Desai } 293e3f2c991SKeyur Desai 29446cf8a39SJordan Brown /* 29546cf8a39SJordan Brown * NEEDSWORK: All we need here is to add the domain and SID for 29646cf8a39SJordan Brown * this DC to the list of domains supported by this entry. Isn't 29746cf8a39SJordan Brown * there an easier way to find the SID than to walk through the list 29846cf8a39SJordan Brown * of all of the domains in the forest? 29946cf8a39SJordan Brown */ 30046cf8a39SJordan Brown ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest; 30146cf8a39SJordan Brown if (dif != NULL) { 30246cf8a39SJordan Brown for (; dif->domain[0] != '\0'; dif++) { 30346cf8a39SJordan Brown if (domain_eq(pgcfg->domain_name, dif->domain)) { 30446cf8a39SJordan Brown if (adutils_add_domain(new_dcs[0], 30546cf8a39SJordan Brown dif->domain, dif->sid) != 0) 306e3f2c991SKeyur Desai goto nomem; 307e3f2c991SKeyur Desai break; 308e3f2c991SKeyur Desai } 309e3f2c991SKeyur Desai } 31046cf8a39SJordan Brown } 311e3f2c991SKeyur Desai 312148c5f43SAlan Wright out: 313e3f2c991SKeyur Desai _idmapdstate.dcs = new_dcs; 314e3f2c991SKeyur Desai _idmapdstate.num_dcs = new_num_dcs; 315e3f2c991SKeyur Desai 316e3f2c991SKeyur Desai if (old_dcs != NULL) { 317e3f2c991SKeyur Desai for (i = 0; i < old_num_dcs; i++) 318e3f2c991SKeyur Desai adutils_ad_free(&old_dcs[i]); 319e3f2c991SKeyur Desai free(old_dcs); 320e3f2c991SKeyur Desai } 321e3f2c991SKeyur Desai 322e3f2c991SKeyur Desai return; 323e3f2c991SKeyur Desai 324e3f2c991SKeyur Desai nomem: 325e3f2c991SKeyur Desai degrade_svc(0, "out of memory"); 326e3f2c991SKeyur Desai 327e3f2c991SKeyur Desai if (new_dcs != NULL) { 328e3f2c991SKeyur Desai if (new_dcs[0] != NULL) 329e3f2c991SKeyur Desai adutils_ad_free(&new_dcs[0]); 330e3f2c991SKeyur Desai free(new_dcs); 331e3f2c991SKeyur Desai } 332e3f2c991SKeyur Desai } 333e3f2c991SKeyur Desai 334e3f2c991SKeyur Desai 335e3f2c991SKeyur Desai void 336e3f2c991SKeyur Desai reload_ad(void) 337e3f2c991SKeyur Desai { 338e3f2c991SKeyur Desai reload_gcs(); 339e3f2c991SKeyur Desai reload_dcs(); 340e3f2c991SKeyur Desai } 341c8e26105Sjp151216 342c5c4113dSnw141292 void 343148c5f43SAlan Wright print_idmapdstate(void) 3444edd44c5Sjp151216 { 3454d61c878SJulian Pullen int i, j; 346e8c27ec8Sbaban idmap_pg_config_t *pgcfg; 3474d61c878SJulian Pullen idmap_trustedforest_t *tf; 348c8e26105Sjp151216 349c5c4113dSnw141292 RDLOCK_CONFIG(); 350c5c4113dSnw141292 351c8e26105Sjp151216 if (_idmapdstate.cfg == NULL) { 35271590c90Snw141292 idmapdlog(LOG_INFO, "Null configuration"); 353c8e26105Sjp151216 UNLOCK_CONFIG(); 354c8e26105Sjp151216 return; 355c5c4113dSnw141292 } 356c8e26105Sjp151216 357e8c27ec8Sbaban pgcfg = &_idmapdstate.cfg->pgcfg; 358e8c27ec8Sbaban 35971590c90Snw141292 idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit); 36071590c90Snw141292 idmapdlog(LOG_DEBUG, "default_domain=%s", 361c8e26105Sjp151216 CHECK_NULL(pgcfg->default_domain)); 36271590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name)); 36371590c90Snw141292 idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid)); 364c8e26105Sjp151216 if (pgcfg->domain_controller == NULL || 365c8e26105Sjp151216 pgcfg->domain_controller[0].host[0] == '\0') { 36671590c90Snw141292 idmapdlog(LOG_DEBUG, "No domain controllers known"); 367c8e26105Sjp151216 } else { 368c8e26105Sjp151216 for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) 36971590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d", 37071590c90Snw141292 pgcfg->domain_controller[i].host, 371c8e26105Sjp151216 pgcfg->domain_controller[i].port); 372c8e26105Sjp151216 } 37371590c90Snw141292 idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name)); 37471590c90Snw141292 idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name)); 375c8e26105Sjp151216 if (pgcfg->global_catalog == NULL || 376c8e26105Sjp151216 pgcfg->global_catalog[0].host[0] == '\0') { 37771590c90Snw141292 idmapdlog(LOG_DEBUG, "No global catalog servers known"); 378c8e26105Sjp151216 } else { 379c8e26105Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) 38071590c90Snw141292 idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d", 381c8e26105Sjp151216 pgcfg->global_catalog[i].host, 382c8e26105Sjp151216 pgcfg->global_catalog[i].port); 383c8e26105Sjp151216 } 3844d61c878SJulian Pullen if (pgcfg->domains_in_forest == NULL || 3854d61c878SJulian Pullen pgcfg->domains_in_forest[0].domain[0] == '\0') { 3864d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No domains in forest %s known", 3874d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name)); 3884d61c878SJulian Pullen } else { 3894d61c878SJulian Pullen for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++) 3904d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "domains in forest %s = %s", 3914d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name), 3924d61c878SJulian Pullen pgcfg->domains_in_forest[i].domain); 3934d61c878SJulian Pullen } 3944d61c878SJulian Pullen if (pgcfg->trusted_domains == NULL || 3954d61c878SJulian Pullen pgcfg->trusted_domains[0].domain[0] == '\0') { 3964d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No trusted domains known"); 3974d61c878SJulian Pullen } else { 3984d61c878SJulian Pullen for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++) 3994d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "trusted domain = %s", 4004d61c878SJulian Pullen pgcfg->trusted_domains[i].domain); 4014d61c878SJulian Pullen } 4024d61c878SJulian Pullen 4034d61c878SJulian Pullen for (i = 0; i < pgcfg->num_trusted_forests; i++) { 4044d61c878SJulian Pullen tf = &pgcfg->trusted_forests[i]; 4054d61c878SJulian Pullen for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++) 4064d61c878SJulian Pullen idmapdlog(LOG_DEBUG, 4074d61c878SJulian Pullen "trusted forest %s global_catalog=%s port=%d", 4084d61c878SJulian Pullen tf->forest_name, 4094d61c878SJulian Pullen tf->global_catalog[j].host, 4104d61c878SJulian Pullen tf->global_catalog[j].port); 4114d61c878SJulian Pullen for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) { 4124d61c878SJulian Pullen if (tf->domains_in_forest[j].trusted) { 4134d61c878SJulian Pullen idmapdlog(LOG_DEBUG, 4144d61c878SJulian Pullen "trusted forest %s domain=%s", 4154d61c878SJulian Pullen tf->forest_name, 4164d61c878SJulian Pullen tf->domains_in_forest[j].domain); 4174d61c878SJulian Pullen } 4184d61c878SJulian Pullen } 4194d61c878SJulian Pullen } 4204d61c878SJulian Pullen 421e3f2c991SKeyur Desai idmapdlog(LOG_DEBUG, "directory_based_mapping=%s", 422e3f2c991SKeyur Desai enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map)); 42371590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s", 424e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixuser_attr)); 42571590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s", 426e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixgroup_attr)); 42771590c90Snw141292 idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s", 428e8c27ec8Sbaban CHECK_NULL(pgcfg->nldap_winname_attr)); 429c8e26105Sjp151216 430c5c4113dSnw141292 UNLOCK_CONFIG(); 431c5c4113dSnw141292 } 432c5c4113dSnw141292 433c5c4113dSnw141292 int 4344edd44c5Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid) 4354edd44c5Sjp151216 { 436c5c4113dSnw141292 int rc; 437c5c4113dSnw141292 438c5c4113dSnw141292 if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) { 43971590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)", 44071590c90Snw141292 path, strerror(errno)); 441c5c4113dSnw141292 return (-1); 442c5c4113dSnw141292 } 443c5c4113dSnw141292 444c5c4113dSnw141292 if (lchown(path, uid, gid) < 0) { 44571590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)", 44671590c90Snw141292 path, strerror(errno)); 447c5c4113dSnw141292 if (rc == 0) 448c5c4113dSnw141292 (void) rmdir(path); 449c5c4113dSnw141292 return (-1); 450c5c4113dSnw141292 } 451c5c4113dSnw141292 return (0); 452c5c4113dSnw141292 } 453