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.
23fea136a0SMatt Barden * Copyright 2018 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(void)43*9bf5f78fSMatt Barden init_mapping_system(void)
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
fini_mapping_system(void)63*9bf5f78fSMatt Barden fini_mapping_system(void)
644edd44c5Sjp151216 {
65c5c4113dSnw141292 fini_dbs();
66c5c4113dSnw141292 }
67c5c4113dSnw141292
68c5c4113dSnw141292 int
load_config(void)69*9bf5f78fSMatt Barden load_config(void)
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
reload_gcs(void)109*9bf5f78fSMatt Barden reload_gcs(void)
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 */
140b3700b07SGordon 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 void
reload_dcs(void)244e3f2c991SKeyur Desai reload_dcs(void)
245e3f2c991SKeyur Desai {
246e3f2c991SKeyur Desai int i;
247e3f2c991SKeyur Desai adutils_ad_t **new_dcs;
248148c5f43SAlan Wright adutils_ad_t **old_dcs = _idmapdstate.dcs;
249e3f2c991SKeyur Desai int new_num_dcs;
250148c5f43SAlan Wright int old_num_dcs = _idmapdstate.num_dcs;
251e3f2c991SKeyur Desai idmap_pg_config_t *pgcfg = &_idmapdstate.cfg->pgcfg;
252e3f2c991SKeyur Desai
2531ed6b69aSGordon Ross if (pgcfg->use_ads == B_FALSE ||
2541ed6b69aSGordon Ross pgcfg->domain_name == NULL) {
2551ed6b69aSGordon Ross /*
2561ed6b69aSGordon Ross * ADS disabled, or no domain name specified.
2571ed6b69aSGordon Ross * Not using adutils. (but still can use lsa)
2581ed6b69aSGordon Ross */
259148c5f43SAlan Wright new_dcs = NULL;
260148c5f43SAlan Wright new_num_dcs = 0;
261148c5f43SAlan Wright goto out;
262148c5f43SAlan Wright }
263148c5f43SAlan Wright
264e3f2c991SKeyur Desai if (pgcfg->domain_controller == NULL ||
265e3f2c991SKeyur Desai pgcfg->domain_controller[0].host[0] == '\0') {
266e3f2c991SKeyur Desai /*
267e3f2c991SKeyur Desai * No DCs. Continue to use the previous AD config in case
268e3f2c991SKeyur Desai * that's still good but auto-discovery had a transient failure.
269e3f2c991SKeyur Desai * If that stops working we'll go into degraded mode anyways
270e3f2c991SKeyur Desai * when it does.
271e3f2c991SKeyur Desai */
272b3700b07SGordon Ross idmapdlog(LOG_INFO,
273e3f2c991SKeyur Desai "Domain controller servers not configured/discoverable");
274e3f2c991SKeyur Desai return;
275e3f2c991SKeyur Desai }
276e3f2c991SKeyur Desai
277e3f2c991SKeyur Desai new_num_dcs = 1;
278e3f2c991SKeyur Desai new_dcs = calloc(new_num_dcs, sizeof (adutils_ad_t *));
279e3f2c991SKeyur Desai if (new_dcs == NULL)
280e3f2c991SKeyur Desai goto nomem;
281e3f2c991SKeyur Desai
282e3f2c991SKeyur Desai if (adutils_ad_alloc(&new_dcs[0], pgcfg->domain_name,
283e3f2c991SKeyur Desai ADUTILS_AD_DATA) != ADUTILS_SUCCESS)
284e3f2c991SKeyur Desai goto nomem;
285e3f2c991SKeyur Desai
286e3f2c991SKeyur Desai for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++) {
287e3f2c991SKeyur Desai if (idmap_add_ds(new_dcs[0],
288e3f2c991SKeyur Desai pgcfg->domain_controller[i].host,
289e3f2c991SKeyur Desai pgcfg->domain_controller[i].port) != 0)
290e3f2c991SKeyur Desai goto nomem;
291e3f2c991SKeyur Desai }
292e3f2c991SKeyur Desai
29346cf8a39SJordan Brown /*
29446cf8a39SJordan Brown * NEEDSWORK: All we need here is to add the domain and SID for
29546cf8a39SJordan Brown * this DC to the list of domains supported by this entry. Isn't
29646cf8a39SJordan Brown * there an easier way to find the SID than to walk through the list
29746cf8a39SJordan Brown * of all of the domains in the forest?
29846cf8a39SJordan Brown */
29946cf8a39SJordan Brown ad_disc_domainsinforest_t *dif = pgcfg->domains_in_forest;
30046cf8a39SJordan Brown if (dif != NULL) {
30146cf8a39SJordan Brown for (; dif->domain[0] != '\0'; dif++) {
30246cf8a39SJordan Brown if (domain_eq(pgcfg->domain_name, dif->domain)) {
30346cf8a39SJordan Brown if (adutils_add_domain(new_dcs[0],
30446cf8a39SJordan Brown dif->domain, dif->sid) != 0)
305e3f2c991SKeyur Desai goto nomem;
306e3f2c991SKeyur Desai break;
307e3f2c991SKeyur Desai }
308e3f2c991SKeyur Desai }
30946cf8a39SJordan Brown }
310e3f2c991SKeyur Desai
311148c5f43SAlan Wright out:
312e3f2c991SKeyur Desai _idmapdstate.dcs = new_dcs;
313e3f2c991SKeyur Desai _idmapdstate.num_dcs = new_num_dcs;
314e3f2c991SKeyur Desai
315e3f2c991SKeyur Desai if (old_dcs != NULL) {
316e3f2c991SKeyur Desai for (i = 0; i < old_num_dcs; i++)
317e3f2c991SKeyur Desai adutils_ad_free(&old_dcs[i]);
318e3f2c991SKeyur Desai free(old_dcs);
319e3f2c991SKeyur Desai }
320e3f2c991SKeyur Desai
321e3f2c991SKeyur Desai return;
322e3f2c991SKeyur Desai
323e3f2c991SKeyur Desai nomem:
324e3f2c991SKeyur Desai degrade_svc(0, "out of memory");
325e3f2c991SKeyur Desai
326e3f2c991SKeyur Desai if (new_dcs != NULL) {
327e3f2c991SKeyur Desai if (new_dcs[0] != NULL)
328e3f2c991SKeyur Desai adutils_ad_free(&new_dcs[0]);
329e3f2c991SKeyur Desai free(new_dcs);
330e3f2c991SKeyur Desai }
331e3f2c991SKeyur Desai }
332e3f2c991SKeyur Desai
333c5c4113dSnw141292 void
print_idmapdstate(void)334148c5f43SAlan Wright print_idmapdstate(void)
3354edd44c5Sjp151216 {
3364d61c878SJulian Pullen int i, j;
337e8c27ec8Sbaban idmap_pg_config_t *pgcfg;
3384d61c878SJulian Pullen idmap_trustedforest_t *tf;
339c8e26105Sjp151216
340c5c4113dSnw141292 RDLOCK_CONFIG();
341c5c4113dSnw141292
342c8e26105Sjp151216 if (_idmapdstate.cfg == NULL) {
34371590c90Snw141292 idmapdlog(LOG_INFO, "Null configuration");
344c8e26105Sjp151216 UNLOCK_CONFIG();
345c8e26105Sjp151216 return;
346c5c4113dSnw141292 }
347c8e26105Sjp151216
348e8c27ec8Sbaban pgcfg = &_idmapdstate.cfg->pgcfg;
349e8c27ec8Sbaban
35071590c90Snw141292 idmapdlog(LOG_DEBUG, "list_size_limit=%llu", pgcfg->list_size_limit);
351fea136a0SMatt Barden idmapdlog(LOG_DEBUG, "max_threads=%llu", pgcfg->max_threads);
35271590c90Snw141292 idmapdlog(LOG_DEBUG, "default_domain=%s",
353c8e26105Sjp151216 CHECK_NULL(pgcfg->default_domain));
35471590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_name=%s", CHECK_NULL(pgcfg->domain_name));
35571590c90Snw141292 idmapdlog(LOG_DEBUG, "machine_sid=%s", CHECK_NULL(pgcfg->machine_sid));
356c8e26105Sjp151216 if (pgcfg->domain_controller == NULL ||
357c8e26105Sjp151216 pgcfg->domain_controller[0].host[0] == '\0') {
35871590c90Snw141292 idmapdlog(LOG_DEBUG, "No domain controllers known");
359c8e26105Sjp151216 } else {
360c8e26105Sjp151216 for (i = 0; pgcfg->domain_controller[i].host[0] != '\0'; i++)
36171590c90Snw141292 idmapdlog(LOG_DEBUG, "domain_controller=%s port=%d",
36271590c90Snw141292 pgcfg->domain_controller[i].host,
363c8e26105Sjp151216 pgcfg->domain_controller[i].port);
364c8e26105Sjp151216 }
36571590c90Snw141292 idmapdlog(LOG_DEBUG, "forest_name=%s", CHECK_NULL(pgcfg->forest_name));
36671590c90Snw141292 idmapdlog(LOG_DEBUG, "site_name=%s", CHECK_NULL(pgcfg->site_name));
367c8e26105Sjp151216 if (pgcfg->global_catalog == NULL ||
368c8e26105Sjp151216 pgcfg->global_catalog[0].host[0] == '\0') {
36971590c90Snw141292 idmapdlog(LOG_DEBUG, "No global catalog servers known");
370c8e26105Sjp151216 } else {
371c8e26105Sjp151216 for (i = 0; pgcfg->global_catalog[i].host[0] != '\0'; i++)
37271590c90Snw141292 idmapdlog(LOG_DEBUG, "global_catalog=%s port=%d",
373c8e26105Sjp151216 pgcfg->global_catalog[i].host,
374c8e26105Sjp151216 pgcfg->global_catalog[i].port);
375c8e26105Sjp151216 }
3764d61c878SJulian Pullen if (pgcfg->domains_in_forest == NULL ||
3774d61c878SJulian Pullen pgcfg->domains_in_forest[0].domain[0] == '\0') {
3784d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No domains in forest %s known",
3794d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name));
3804d61c878SJulian Pullen } else {
3814d61c878SJulian Pullen for (i = 0; pgcfg->domains_in_forest[i].domain[0] != '\0'; i++)
3824d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "domains in forest %s = %s",
3834d61c878SJulian Pullen CHECK_NULL(pgcfg->forest_name),
3844d61c878SJulian Pullen pgcfg->domains_in_forest[i].domain);
3854d61c878SJulian Pullen }
3864d61c878SJulian Pullen if (pgcfg->trusted_domains == NULL ||
3874d61c878SJulian Pullen pgcfg->trusted_domains[0].domain[0] == '\0') {
3884d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "No trusted domains known");
3894d61c878SJulian Pullen } else {
3904d61c878SJulian Pullen for (i = 0; pgcfg->trusted_domains[i].domain[0] != '\0'; i++)
3914d61c878SJulian Pullen idmapdlog(LOG_DEBUG, "trusted domain = %s",
3924d61c878SJulian Pullen pgcfg->trusted_domains[i].domain);
3934d61c878SJulian Pullen }
3944d61c878SJulian Pullen
3954d61c878SJulian Pullen for (i = 0; i < pgcfg->num_trusted_forests; i++) {
3964d61c878SJulian Pullen tf = &pgcfg->trusted_forests[i];
3974d61c878SJulian Pullen for (j = 0; tf->global_catalog[j].host[0] != '\0'; j++)
3984d61c878SJulian Pullen idmapdlog(LOG_DEBUG,
3994d61c878SJulian Pullen "trusted forest %s global_catalog=%s port=%d",
4004d61c878SJulian Pullen tf->forest_name,
4014d61c878SJulian Pullen tf->global_catalog[j].host,
4024d61c878SJulian Pullen tf->global_catalog[j].port);
4034d61c878SJulian Pullen for (j = 0; tf->domains_in_forest[j].domain[0] != '\0'; j++) {
4044d61c878SJulian Pullen if (tf->domains_in_forest[j].trusted) {
4054d61c878SJulian Pullen idmapdlog(LOG_DEBUG,
4064d61c878SJulian Pullen "trusted forest %s domain=%s",
4074d61c878SJulian Pullen tf->forest_name,
4084d61c878SJulian Pullen tf->domains_in_forest[j].domain);
4094d61c878SJulian Pullen }
4104d61c878SJulian Pullen }
4114d61c878SJulian Pullen }
4124d61c878SJulian Pullen
413e3f2c991SKeyur Desai idmapdlog(LOG_DEBUG, "directory_based_mapping=%s",
414e3f2c991SKeyur Desai enum_lookup(pgcfg->directory_based_mapping, directory_mapping_map));
41571590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixuser_attr=%s",
416e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixuser_attr));
41771590c90Snw141292 idmapdlog(LOG_DEBUG, "ad_unixgroup_attr=%s",
418e8c27ec8Sbaban CHECK_NULL(pgcfg->ad_unixgroup_attr));
41971590c90Snw141292 idmapdlog(LOG_DEBUG, "nldap_winname_attr=%s",
420e8c27ec8Sbaban CHECK_NULL(pgcfg->nldap_winname_attr));
421c8e26105Sjp151216
422c5c4113dSnw141292 UNLOCK_CONFIG();
423c5c4113dSnw141292 }
424c5c4113dSnw141292
425c5c4113dSnw141292 int
create_directory(const char * path,uid_t uid,gid_t gid)4264edd44c5Sjp151216 create_directory(const char *path, uid_t uid, gid_t gid)
4274edd44c5Sjp151216 {
428c5c4113dSnw141292 int rc;
429c5c4113dSnw141292
430c5c4113dSnw141292 if ((rc = mkdir(path, 0700)) < 0 && errno != EEXIST) {
43171590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
43271590c90Snw141292 path, strerror(errno));
433c5c4113dSnw141292 return (-1);
434c5c4113dSnw141292 }
435c5c4113dSnw141292
436c5c4113dSnw141292 if (lchown(path, uid, gid) < 0) {
43771590c90Snw141292 idmapdlog(LOG_ERR, "Error creating directory %s (%s)",
43871590c90Snw141292 path, strerror(errno));
439c5c4113dSnw141292 if (rc == 0)
440c5c4113dSnw141292 (void) rmdir(path);
441c5c4113dSnw141292 return (-1);
442c5c4113dSnw141292 }
443c5c4113dSnw141292 return (0);
444c5c4113dSnw141292 }
445