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 /* 22*148c5f43SAlan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 23c5c4113dSnw141292 */ 24c5c4113dSnw141292 25c5c4113dSnw141292 /* 26c5c4113dSnw141292 * Initialization routines 27c5c4113dSnw141292 */ 28c5c4113dSnw141292 29c5c4113dSnw141292 #include "idmapd.h" 30c5c4113dSnw141292 #include <signal.h> 31c5c4113dSnw141292 #include <thread.h> 32c5c4113dSnw141292 #include <string.h> 33c5c4113dSnw141292 #include <errno.h> 34c5c4113dSnw141292 #include <assert.h> 35c5c4113dSnw141292 #include <unistd.h> 36c5c4113dSnw141292 #include <sys/types.h> 37c5c4113dSnw141292 #include <sys/stat.h> 388edda628Sbaban #include <rpcsvc/daemon_utils.h> 39c5c4113dSnw141292 40c5c4113dSnw141292 41c5c4113dSnw141292 int 424edd44c5Sjp151216 init_mapping_system() 434edd44c5Sjp151216 { 448edda628Sbaban int rc = 0; 458edda628Sbaban 46c5c4113dSnw141292 if (rwlock_init(&_idmapdstate.rwlk_cfg, USYNC_THREAD, NULL) != 0) 47c5c4113dSnw141292 return (-1); 48e8c27ec8Sbaban if ((rc = load_config()) < 0) 49e8c27ec8Sbaban return (rc); 508edda628Sbaban 518edda628Sbaban (void) setegid(DAEMON_GID); 528edda628Sbaban (void) seteuid(DAEMON_UID); 53c5c4113dSnw141292 if (init_dbs() < 0) { 548edda628Sbaban rc = -1; 55c5c4113dSnw141292 fini_mapping_system(); 56c5c4113dSnw141292 } 578edda628Sbaban (void) seteuid(0); 588edda628Sbaban (void) setegid(0); 598edda628Sbaban 608edda628Sbaban return (rc); 61c5c4113dSnw141292 } 62c5c4113dSnw141292 63c5c4113dSnw141292 void 644edd44c5Sjp151216 fini_mapping_system() 654edd44c5Sjp151216 { 66c5c4113dSnw141292 fini_dbs(); 67c5c4113dSnw141292 } 68c5c4113dSnw141292 69c5c4113dSnw141292 int 704edd44c5Sjp151216 load_config() 714edd44c5Sjp151216 { 72e3c2d6aaSnw141292 int rc; 73c5c4113dSnw141292 if ((_idmapdstate.cfg = idmap_cfg_init()) == NULL) { 74349d5d8fSnw141292 degrade_svc(0, "failed to initialize config"); 75c5c4113dSnw141292 return (-1); 76c5c4113dSnw141292 } 77c8e26105Sjp151216 78e3f2c991SKeyur Desai rc = idmap_cfg_upgrade(_idmapdstate.cfg); 79e3f2c991SKeyur Desai if (rc != 0) { 80e3f2c991SKeyur Desai degrade_svc(0, "fatal error while upgrading configuration"); 81e3f2c991SKeyur Desai return (rc); 82e3f2c991SKeyur Desai } 83e3f2c991SKeyur Desai 84349d5d8fSnw141292 rc = idmap_cfg_load(_idmapdstate.cfg, 0); 85e3c2d6aaSnw141292 if (rc < -1) { 86e3c2d6aaSnw141292 /* Total failure */ 87349d5d8fSnw141292 degrade_svc(0, "fatal error while loading configuration"); 88e8c27ec8Sbaban return (rc); 89c5c4113dSnw141292 } 90c8e26105Sjp151216 91e3c2d6aaSnw141292 if (rc != 0) 92e3c2d6aaSnw141292 /* Partial failure */ 9371590c90Snw141292 idmapdlog(LOG_ERR, "Various errors occurred while loading " 9471590c90Snw141292 "the configuration; check the logs"); 95e3c2d6aaSnw141292 960dcc7149Snw141292 if ((rc = idmap_cfg_start_updates()) < 0) { 970dcc7149Snw141292 /* Total failure */ 98349d5d8fSnw141292 degrade_svc(0, "could not start config updater"); 990dcc7149Snw141292 return (rc); 1000dcc7149Snw141292 } 101e3c2d6aaSnw141292 102*148c5f43SAlan Wright if (DBG(CONFIG, 1)) 10371590c90Snw141292 idmapdlog(LOG_DEBUG, "Initial configuration loaded"); 104e3c2d6aaSnw141292 105c5c4113dSnw141292 return (0); 106c5c4113dSnw141292 } 107c5c4113dSnw141292 108c8e26105Sjp151216 109349d5d8fSnw141292 void 110e3f2c991SKeyur Desai reload_gcs() 1114edd44c5Sjp151216 { 1124d61c878SJulian Pullen int i, j; 113e3f2c991SKeyur Desai adutils_ad_t **new_gcs; 114*148c5f43SAlan Wright adutils_ad_t **old_gcs = _idmapdstate.gcs; 115e3f2c991SKeyur Desai int new_num_gcs; 116*148c5f43SAlan Wright int old_num_gcs = _idmapdstate.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 122*148c5f43SAlan Wright if (pgcfg->domain_name == NULL) { 123*148c5f43SAlan Wright /* No domain name specified - workgroup mode. */ 124*148c5f43SAlan Wright new_gcs = NULL; 125*148c5f43SAlan Wright new_num_gcs = 0; 126*148c5f43SAlan Wright goto out; 127*148c5f43SAlan Wright } 128*148c5f43SAlan Wright 129349d5d8fSnw141292 if (pgcfg->global_catalog == NULL || 130349d5d8fSnw141292 pgcfg->global_catalog[0].host[0] == '\0') { 131349d5d8fSnw141292 /* 132349d5d8fSnw141292 * No GCs. Continue to use the previous AD config in case 133349d5d8fSnw141292 * that's still good but auto-discovery had a transient failure. 134349d5d8fSnw141292 * If that stops working we'll go into degraded mode anyways 135349d5d8fSnw141292 * when it does. 136349d5d8fSnw141292 */ 137349d5d8fSnw141292 degrade_svc(0, 138349d5d8fSnw141292 "Global Catalog servers not configured/discoverable"); 139349d5d8fSnw141292 return; 140c8e26105Sjp151216 } 141c8e26105Sjp151216 142e3f2c991SKeyur Desai new_num_gcs = 1 + num_trustfor; 143e3f2c991SKeyur Desai new_gcs = calloc(new_num_gcs, sizeof (adutils_ad_t *)); 144e3f2c991SKeyur Desai if (new_gcs == NULL) { 1454d61c878SJulian Pullen degrade_svc(0, "could not allocate AD context array " 1464d61c878SJulian Pullen "(out of memory)"); 1474d61c878SJulian Pullen return; 1484d61c878SJulian Pullen } 1494d61c878SJulian Pullen 150e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_gcs[0], NULL, ADUTILS_AD_GLOBAL_CATALOG) != 151e3f2c991SKeyur Desai ADUTILS_SUCCESS) { 152e3f2c991SKeyur Desai free(new_gcs); 1534d61c878SJulian Pullen degrade_svc(0, "could not initialize AD context " 1544d61c878SJulian Pullen "(out of memory)"); 155349d5d8fSnw141292 return; 156c8e26105Sjp151216 } 157c8e26105Sjp151216 158c8e26105Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) { 159e3f2c991SKeyur Desai if (idmap_add_ds(new_gcs[0], 160c8e26105Sjp151216 pgcfg->global_catalog[i].host, 161c8e26105Sjp151216 pgcfg->global_catalog[i].port) != 0) { 162e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[0]); 163e3f2c991SKeyur Desai free(new_gcs); 1644d61c878SJulian Pullen degrade_svc(0, "could not set AD hosts " 1654d61c878SJulian Pullen "(out of memory)"); 166349d5d8fSnw141292 return; 167c8e26105Sjp151216 } 168c8e26105Sjp151216 } 169c8e26105Sjp151216 1704d61c878SJulian Pullen if (pgcfg->domains_in_forest != NULL) { 1714d61c878SJulian Pullen for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; 1724d61c878SJulian Pullen i++) { 173e3f2c991SKeyur Desai if (adutils_add_domain(new_gcs[0], 1744d61c878SJulian Pullen pgcfg->domains_in_forest[i].domain, 1754d61c878SJulian Pullen pgcfg->domains_in_forest[i].sid) != 0) { 176e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[0]); 177e3f2c991SKeyur Desai free(new_gcs); 1784d61c878SJulian Pullen degrade_svc(0, "could not set AD domains " 1794d61c878SJulian Pullen "(out of memory)"); 1804d61c878SJulian Pullen return; 1814d61c878SJulian Pullen } 1824d61c878SJulian Pullen } 1834d61c878SJulian Pullen } 184c8e26105Sjp151216 1854d61c878SJulian Pullen for (i = 0; i < num_trustfor; i++) { 186e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_gcs[i + 1], NULL, 1874d61c878SJulian Pullen ADUTILS_AD_GLOBAL_CATALOG) != ADUTILS_SUCCESS) { 1884d61c878SJulian Pullen degrade_svc(0, "could not initialize trusted AD " 1894d61c878SJulian Pullen "context (out of memory)"); 190e3f2c991SKeyur Desai new_num_gcs = i + 1; 1914d61c878SJulian Pullen goto out; 1924d61c878SJulian Pullen } 1934d61c878SJulian Pullen for (j = 0; trustfor[i].global_catalog[j].host[0] != '\0'; 1944d61c878SJulian Pullen j++) { 195e3f2c991SKeyur Desai if (idmap_add_ds(new_gcs[i + 1], 1964d61c878SJulian Pullen trustfor[i].global_catalog[j].host, 1974d61c878SJulian Pullen trustfor[i].global_catalog[j].port) != 0) { 198e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[i + 1]); 1994d61c878SJulian Pullen degrade_svc(0, "could not set trusted " 2004d61c878SJulian Pullen "AD hosts (out of memory)"); 201e3f2c991SKeyur Desai new_num_gcs = i + 1; 2024d61c878SJulian Pullen goto out; 2034d61c878SJulian Pullen } 2044d61c878SJulian Pullen } 2054d61c878SJulian Pullen for (j = 0; trustfor[i].domains_in_forest[j].domain[0] != '\0'; 2064d61c878SJulian Pullen j++) { 2074d61c878SJulian Pullen domain_in_forest = &trustfor[i].domains_in_forest[j]; 2084d61c878SJulian Pullen /* Only add domains which are marked */ 2094d61c878SJulian Pullen if (domain_in_forest->trusted) { 210e3f2c991SKeyur Desai if (adutils_add_domain(new_gcs[i + 1], 2114d61c878SJulian Pullen domain_in_forest->domain, 2124d61c878SJulian Pullen domain_in_forest->sid) != 0) { 213e3f2c991SKeyur Desai adutils_ad_free(&new_gcs[i + 1]); 2144d61c878SJulian Pullen degrade_svc(0, "could not set trusted " 2154d61c878SJulian Pullen "AD domains (out of memory)"); 216e3f2c991SKeyur Desai new_num_gcs = i + 1; 2174d61c878SJulian Pullen goto out; 2184d61c878SJulian Pullen } 2194d61c878SJulian Pullen } 2204d61c878SJulian Pullen } 2214d61c878SJulian Pullen } 2224d61c878SJulian Pullen 2234d61c878SJulian Pullen out: 224e3f2c991SKeyur Desai _idmapdstate.gcs = new_gcs; 225e3f2c991SKeyur Desai _idmapdstate.num_gcs = new_num_gcs; 2264d61c878SJulian Pullen 227e3f2c991SKeyur Desai if (old_gcs != NULL) { 228e3f2c991SKeyur Desai for (i = 0; i < old_num_gcs; i++) 229e3f2c991SKeyur Desai adutils_ad_free(&old_gcs[i]); 230e3f2c991SKeyur Desai free(old_gcs); 2314d61c878SJulian Pullen } 232c8e26105Sjp151216 } 233c8e26105Sjp151216 234e3f2c991SKeyur Desai /* 235e3f2c991SKeyur Desai * NEEDSWORK: This should load entries for domain servers for all known 236e3f2c991SKeyur Desai * domains - the joined domain, other domains in the forest, and trusted 237e3f2c991SKeyur Desai * domains in other forests. However, we don't yet discover any DCs other 238e3f2c991SKeyur Desai * than the DCs for the joined domain. 239e3f2c991SKeyur Desai */ 240e3f2c991SKeyur Desai static 241e3f2c991SKeyur Desai void 242e3f2c991SKeyur Desai reload_dcs(void) 243e3f2c991SKeyur Desai { 244e3f2c991SKeyur Desai int i; 245e3f2c991SKeyur Desai adutils_ad_t **new_dcs; 246*148c5f43SAlan Wright adutils_ad_t **old_dcs = _idmapdstate.dcs; 247e3f2c991SKeyur Desai int new_num_dcs; 248*148c5f43SAlan Wright int old_num_dcs = _idmapdstate.num_dcs; 249e3f2c991SKeyur Desai idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg; 250e3f2c991SKeyur Desai 251*148c5f43SAlan Wright if (pgcfg->domain_name == NULL) { 252*148c5f43SAlan Wright /* No domain name specified - workgroup mode. */ 253*148c5f43SAlan Wright new_dcs = NULL; 254*148c5f43SAlan Wright new_num_dcs = 0; 255*148c5f43SAlan Wright goto out; 256*148c5f43SAlan Wright } 257*148c5f43SAlan Wright 258e3f2c991SKeyur Desai if (pgcfg->domain_controller == NULL || 259e3f2c991SKeyur Desai pgcfg->domain_controller[0].host[0] == '\0') { 260e3f2c991SKeyur Desai /* 261e3f2c991SKeyur Desai * No DCs. Continue to use the previous AD config in case 262e3f2c991SKeyur Desai * that's still good but auto-discovery had a transient failure. 263e3f2c991SKeyur Desai * If that stops working we'll go into degraded mode anyways 264e3f2c991SKeyur Desai * when it does. 265e3f2c991SKeyur Desai */ 266e3f2c991SKeyur Desai degrade_svc(0, 267e3f2c991SKeyur Desai "Domain controller servers not configured/discoverable"); 268e3f2c991SKeyur Desai return; 269e3f2c991SKeyur Desai } 270e3f2c991SKeyur Desai 271e3f2c991SKeyur Desai new_num_dcs = 1; 272e3f2c991SKeyur Desai new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *)); 273e3f2c991SKeyur Desai if (new_dcs == NULL) 274e3f2c991SKeyur Desai goto nomem; 275e3f2c991SKeyur Desai 276e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name, 277e3f2c991SKeyur Desai ADUTILS_AD_DATA) != ADUTILS_SUCCESS) 278e3f2c991SKeyur Desai goto nomem; 279e3f2c991SKeyur Desai 280e3f2c991SKeyur Desai for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) { 281e3f2c991SKeyur Desai if (idmap_add_ds(new_dcs[0], 282e3f2c991SKeyur Desai pgcfg->domain_controller[i].host, 283e3f2c991SKeyur Desai pgcfg->domain_controller[i].port) != 0) 284e3f2c991SKeyur Desai goto nomem; 285e3f2c991SKeyur Desai } 286e3f2c991SKeyur Desai 28746cf8a39SJordan Brown /* 28846cf8a39SJordan Brown * NEEDSWORK: All we need here is to add the domain and SID for 28946cf8a39SJordan Brown * this DC to the list of domains supported by this entry. Isn't 29046cf8a39SJordan Brown * there an easier way to find the SID than to walk through the list 29146cf8a39SJordan Brown * of all of the domains in the forest? 29246cf8a39SJordan Brown */ 29346cf8a39SJordan Brown ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest; 29446cf8a39SJordan Brown if (dif != NULL) { 29546cf8a39SJordan Brown for (; dif->domain[0] != '\0'; dif++) { 29646cf8a39SJordan Brown if (domain_eq(pgcfg->domain_name, dif->domain)) { 29746cf8a39SJordan Brown if (adutils_add_domain(new_dcs[0], 29846cf8a39SJordan Brown dif->domain, dif->sid) != 0) 299e3f2c991SKeyur Desai goto nomem; 300e3f2c991SKeyur Desai break; 301e3f2c991SKeyur Desai } 302e3f2c991SKeyur Desai } 30346cf8a39SJordan Brown } 304e3f2c991SKeyur Desai 305*148c5f43SAlan Wright out: 306e3f2c991SKeyur Desai _idmapdstate.dcs = new_dcs; 307e3f2c991SKeyur Desai _idmapdstate.num_dcs = new_num_dcs; 308e3f2c991SKeyur Desai 309e3f2c991SKeyur Desai if (old_dcs != NULL) { 310e3f2c991SKeyur Desai for (i = 0; i < old_num_dcs; i++) 311e3f2c991SKeyur Desai adutils_ad_free(&old_dcs[i]); 312e3f2c991SKeyur Desai free(old_dcs); 313e3f2c991SKeyur Desai } 314e3f2c991SKeyur Desai 315e3f2c991SKeyur Desai return; 316e3f2c991SKeyur Desai 317e3f2c991SKeyur Desai nomem: 318e3f2c991SKeyur Desai degrade_svc(0, "out of memory"); 319e3f2c991SKeyur Desai 320e3f2c991SKeyur Desai if (new_dcs != NULL) { 321e3f2c991SKeyur Desai if (new_dcs[0] != NULL) 322e3f2c991SKeyur Desai adutils_ad_free(&new_dcs[0]); 323e3f2c991SKeyur Desai free(new_dcs); 324e3f2c991SKeyur Desai } 325e3f2c991SKeyur Desai } 326e3f2c991SKeyur Desai 327e3f2c991SKeyur Desai 328e3f2c991SKeyur Desai void 329e3f2c991SKeyur Desai reload_ad(void) 330e3f2c991SKeyur Desai { 331e3f2c991SKeyur Desai reload_gcs(); 332e3f2c991SKeyur Desai reload_dcs(); 333e3f2c991SKeyur Desai } 334c8e26105Sjp151216 335c5c4113dSnw141292 void 336*148c5f43SAlan Wright print_idmapdstate(void) 3374edd44c5Sjp151216 { 3384d61c878SJulian Pullen int i, j; 339e8c27ec8Sbaban idmap_pg_config_t *pgcfg; 3404d61c878SJulian Pullen idmap_trustedforest_t *tf; 341c8e26105Sjp151216 342c5c4113dSnw141292 RDLOCK_CONFIG(); 343c5c4113dSnw141292 344c8e26105Sjp151216 if (_idmapdstate.cfg == NULL) { 34571590c90Snw141292 idmapdlog(LOG_INFO, "Null configuration"); 346c8e26105Sjp151216 UNLOCK_CONFIG(); 347c8e26105Sjp151216 return; 348c5c4113dSnw141292 } 349c8e26105Sjp151216 350e8c27ec8Sbaban pgcfg = &_idmapdstate.cfg->pgcfg; 351e8c27ec8Sbaban 35271590c90Snw141292 idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit); 35371590c90Snw141292 idmapdlog(LOG_DEBUG, "default_domain=%s", 354c8e26105Sjp151216 CHECK_NULL(pgcfg->default_domain)); 35571590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name)); 35671590c90Snw141292 idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid)); 357c8e26105Sjp151216 if (pgcfg->domain_controller == NULL || 358c8e26105Sjp151216 pgcfg->domain_controller[0].host[0] == '\0') { 35971590c90Snw141292 idmapdlog(LOG_DEBUG, "No domain controllers known"); 360c8e26105Sjp151216 } else { 361c8e26105Sjp151216 for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) 36271590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d", 36371590c90Snw141292 pgcfg->domain_controller[i].host, 364c8e26105Sjp151216 pgcfg->domain_controller[i].port); 365c8e26105Sjp151216 } 36671590c90Snw141292 idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name)); 36771590c90Snw141292 idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name)); 368c8e26105Sjp151216 if (pgcfg->global_catalog == NULL || 369c8e26105Sjp151216 pgcfg->global_catalog[0].host[0] == '\0') { 37071590c90Snw141292 idmapdlog(LOG_DEBUG, "No global catalog servers known"); 371c8e26105Sjp151216 } else { 372c8e26105Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++) 37371590c90Snw141292 idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d", 374c8e26105Sjp151216 pgcfg->global_catalog[i].host, 375c8e26105Sjp151216 pgcfg->global_catalog[i].port); 376c8e26105Sjp151216 } 3774d61c878SJulian Pullen if (pgcfg->domains_in_forest == NULL || 3784d61c878SJulian Pullen pgcfg->domains_in_forest[0].domain[0] == '\0') { 3794d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No domains in forest %s known", 3804d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name)); 3814d61c878SJulian Pullen } else { 3824d61c878SJulian Pullen for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++) 3834d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "domains in forest %s = %s", 3844d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name), 3854d61c878SJulian Pullen pgcfg->domains_in_forest[i].domain); 3864d61c878SJulian Pullen } 3874d61c878SJulian Pullen if (pgcfg->trusted_domains == NULL || 3884d61c878SJulian Pullen pgcfg->trusted_domains[0].domain[0] == '\0') { 3894d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No trusted domains known"); 3904d61c878SJulian Pullen } else { 3914d61c878SJulian Pullen for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++) 3924d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "trusted domain = %s", 3934d61c878SJulian Pullen pgcfg->trusted_domains[i].domain); 3944d61c878SJulian Pullen } 3954d61c878SJulian Pullen 3964d61c878SJulian Pullen for (i = 0; i < pgcfg->num_trusted_forests; i++) { 3974d61c878SJulian Pullen tf = &pgcfg->trusted_forests[i]; 3984d61c878SJulian Pullen for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++) 3994d61c878SJulian Pullen idmapdlog(LOG_DEBUG, 4004d61c878SJulian Pullen "trusted forest %s global_catalog=%s port=%d", 4014d61c878SJulian Pullen tf->forest_name, 4024d61c878SJulian Pullen tf->global_catalog[j].host, 4034d61c878SJulian Pullen tf->global_catalog[j].port); 4044d61c878SJulian Pullen for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) { 4054d61c878SJulian Pullen if (tf->domains_in_forest[j].trusted) { 4064d61c878SJulian Pullen idmapdlog(LOG_DEBUG, 4074d61c878SJulian Pullen "trusted forest %s domain=%s", 4084d61c878SJulian Pullen tf->forest_name, 4094d61c878SJulian Pullen tf->domains_in_forest[j].domain); 4104d61c878SJulian Pullen } 4114d61c878SJulian Pullen } 4124d61c878SJulian Pullen } 4134d61c878SJulian Pullen 414e3f2c991SKeyur Desai idmapdlog(LOG_DEBUG, "directory_based_mapping=%s", 415e3f2c991SKeyur Desai enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map)); 41671590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s", 417e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixuser_attr)); 41871590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s", 419e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixgroup_attr)); 42071590c90Snw141292 idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s", 421e8c27ec8Sbaban CHECK_NULL(pgcfg->nldap_winname_attr)); 422c8e26105Sjp151216 423c5c4113dSnw141292 UNLOCK_CONFIG(); 424c5c4113dSnw141292 } 425c5c4113dSnw141292 426c5c4113dSnw141292 int 4274edd44c5Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid) 4284edd44c5Sjp151216 { 429c5c4113dSnw141292 int rc; 430c5c4113dSnw141292 431c5c4113dSnw141292 if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) { 43271590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)", 43371590c90Snw141292 path, strerror(errno)); 434c5c4113dSnw141292 return (-1); 435c5c4113dSnw141292 } 436c5c4113dSnw141292 437c5c4113dSnw141292 if (lchown(path, uid, gid) < 0) { 43871590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)", 43971590c90Snw141292 path, strerror(errno)); 440c5c4113dSnw141292 if (rc == 0) 441c5c4113dSnw141292 (void) rmdir(path); 442c5c4113dSnw141292 return (-1); 443c5c4113dSnw141292 } 444c5c4113dSnw141292 return (0); 445c5c4113dSnw141292 } 446