18334SJose.Borrego@Sun.COM /*
28334SJose.Borrego@Sun.COM * CDDL HEADER START
38334SJose.Borrego@Sun.COM *
48334SJose.Borrego@Sun.COM * The contents of this file are subject to the terms of the
58334SJose.Borrego@Sun.COM * Common Development and Distribution License (the "License").
68334SJose.Borrego@Sun.COM * You may not use this file except in compliance with the License.
78334SJose.Borrego@Sun.COM *
88334SJose.Borrego@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98334SJose.Borrego@Sun.COM * or http://www.opensolaris.org/os/licensing.
108334SJose.Borrego@Sun.COM * See the License for the specific language governing permissions
118334SJose.Borrego@Sun.COM * and limitations under the License.
128334SJose.Borrego@Sun.COM *
138334SJose.Borrego@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
148334SJose.Borrego@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
158334SJose.Borrego@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
168334SJose.Borrego@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
178334SJose.Borrego@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
188334SJose.Borrego@Sun.COM *
198334SJose.Borrego@Sun.COM * CDDL HEADER END
208334SJose.Borrego@Sun.COM */
21*12508Samw@Sun.COM
228334SJose.Borrego@Sun.COM /*
23*12508Samw@Sun.COM * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
248334SJose.Borrego@Sun.COM */
258334SJose.Borrego@Sun.COM
268334SJose.Borrego@Sun.COM #include <syslog.h>
278334SJose.Borrego@Sun.COM #include <synch.h>
288334SJose.Borrego@Sun.COM #include <pthread.h>
298334SJose.Borrego@Sun.COM #include <unistd.h>
308334SJose.Borrego@Sun.COM #include <string.h>
318334SJose.Borrego@Sun.COM #include <strings.h>
328334SJose.Borrego@Sun.COM #include <sys/errno.h>
338334SJose.Borrego@Sun.COM #include <sys/types.h>
348334SJose.Borrego@Sun.COM #include <netinet/in.h>
358334SJose.Borrego@Sun.COM #include <arpa/nameser.h>
368334SJose.Borrego@Sun.COM #include <resolv.h>
378334SJose.Borrego@Sun.COM #include <netdb.h>
388334SJose.Borrego@Sun.COM #include <assert.h>
398334SJose.Borrego@Sun.COM
408334SJose.Borrego@Sun.COM #include <smbsrv/libsmb.h>
418334SJose.Borrego@Sun.COM #include <smbsrv/libsmbns.h>
428334SJose.Borrego@Sun.COM #include <smbsrv/libmlsvc.h>
438334SJose.Borrego@Sun.COM
448334SJose.Borrego@Sun.COM #include <smbsrv/smbinfo.h>
458334SJose.Borrego@Sun.COM #include <lsalib.h>
468334SJose.Borrego@Sun.COM
478334SJose.Borrego@Sun.COM /*
488334SJose.Borrego@Sun.COM * DC Locator
498334SJose.Borrego@Sun.COM */
5010717Samw@Sun.COM #define SMB_DCLOCATOR_TIMEOUT 45 /* seconds */
518334SJose.Borrego@Sun.COM #define SMB_IS_FQDN(domain) (strchr(domain, '.') != NULL)
528334SJose.Borrego@Sun.COM
538334SJose.Borrego@Sun.COM typedef struct smb_dclocator {
549832Samw@Sun.COM char sdl_domain[SMB_PI_MAX_DOMAIN];
559832Samw@Sun.COM char sdl_dc[MAXHOSTNAMELEN];
569832Samw@Sun.COM boolean_t sdl_locate;
579832Samw@Sun.COM mutex_t sdl_mtx;
589832Samw@Sun.COM cond_t sdl_cv;
599832Samw@Sun.COM uint32_t sdl_status;
608334SJose.Borrego@Sun.COM } smb_dclocator_t;
618334SJose.Borrego@Sun.COM
628334SJose.Borrego@Sun.COM static smb_dclocator_t smb_dclocator;
638334SJose.Borrego@Sun.COM static pthread_t smb_dclocator_thr;
648334SJose.Borrego@Sun.COM
6510717Samw@Sun.COM static void *smb_ddiscover_service(void *);
6610717Samw@Sun.COM static void smb_ddiscover_main(char *, char *);
6710717Samw@Sun.COM static boolean_t smb_ddiscover_dns(char *, char *, smb_domainex_t *);
6810717Samw@Sun.COM static boolean_t smb_ddiscover_nbt(char *, char *, smb_domainex_t *);
6910717Samw@Sun.COM static boolean_t smb_ddiscover_domain_match(char *, char *, uint32_t);
7010717Samw@Sun.COM static uint32_t smb_ddiscover_qinfo(char *, char *, smb_domainex_t *);
7110717Samw@Sun.COM static void smb_ddiscover_enum_trusted(char *, char *, smb_domainex_t *);
7210717Samw@Sun.COM static uint32_t smb_ddiscover_use_config(char *, smb_domainex_t *);
7310717Samw@Sun.COM static void smb_domainex_free(smb_domainex_t *);
748334SJose.Borrego@Sun.COM
758334SJose.Borrego@Sun.COM /*
768334SJose.Borrego@Sun.COM * ===================================================================
778334SJose.Borrego@Sun.COM * API to initialize DC locator thread, trigger DC discovery, and
788334SJose.Borrego@Sun.COM * get the discovered DC and/or domain information.
798334SJose.Borrego@Sun.COM * ===================================================================
808334SJose.Borrego@Sun.COM */
818334SJose.Borrego@Sun.COM
828334SJose.Borrego@Sun.COM /*
838334SJose.Borrego@Sun.COM * Initialization of the DC locator thread.
848334SJose.Borrego@Sun.COM * Returns 0 on success, an error number if thread creation fails.
858334SJose.Borrego@Sun.COM */
868334SJose.Borrego@Sun.COM int
smb_dclocator_init(void)878334SJose.Borrego@Sun.COM smb_dclocator_init(void)
888334SJose.Borrego@Sun.COM {
898334SJose.Borrego@Sun.COM pthread_attr_t tattr;
908334SJose.Borrego@Sun.COM int rc;
918334SJose.Borrego@Sun.COM
928334SJose.Borrego@Sun.COM (void) pthread_attr_init(&tattr);
938334SJose.Borrego@Sun.COM (void) pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
948334SJose.Borrego@Sun.COM rc = pthread_create(&smb_dclocator_thr, &tattr,
9510717Samw@Sun.COM smb_ddiscover_service, 0);
968334SJose.Borrego@Sun.COM (void) pthread_attr_destroy(&tattr);
978334SJose.Borrego@Sun.COM return (rc);
988334SJose.Borrego@Sun.COM }
998334SJose.Borrego@Sun.COM
1008334SJose.Borrego@Sun.COM /*
1018334SJose.Borrego@Sun.COM * This is the entry point for discovering a domain controller for the
1028334SJose.Borrego@Sun.COM * specified domain.
1038334SJose.Borrego@Sun.COM *
1048334SJose.Borrego@Sun.COM * The actual work of discovering a DC is handled by DC locator thread.
1058334SJose.Borrego@Sun.COM * All we do here is signal the request and wait for a DC or a timeout.
1068334SJose.Borrego@Sun.COM *
1078334SJose.Borrego@Sun.COM * Input parameters:
1088334SJose.Borrego@Sun.COM * domain - domain to be discovered (can either be NetBIOS or DNS domain)
1098334SJose.Borrego@Sun.COM * dc - preferred DC. If the preferred DC is set to empty string, it
1108334SJose.Borrego@Sun.COM * will attempt to discover any DC in the specified domain.
1118334SJose.Borrego@Sun.COM *
1128334SJose.Borrego@Sun.COM * Output parameter:
1138334SJose.Borrego@Sun.COM * dp - on success, dp will be filled with the discovered DC and domain
1148334SJose.Borrego@Sun.COM * information.
1158334SJose.Borrego@Sun.COM * Returns B_TRUE if the DC/domain info is available.
1168334SJose.Borrego@Sun.COM */
1178334SJose.Borrego@Sun.COM boolean_t
smb_locate_dc(char * domain,char * dc,smb_domainex_t * dp)11810717Samw@Sun.COM smb_locate_dc(char *domain, char *dc, smb_domainex_t *dp)
1198334SJose.Borrego@Sun.COM {
1208334SJose.Borrego@Sun.COM int rc;
1218334SJose.Borrego@Sun.COM timestruc_t to;
12210717Samw@Sun.COM smb_domainex_t domain_info;
1238334SJose.Borrego@Sun.COM
1248334SJose.Borrego@Sun.COM if (domain == NULL || *domain == '\0')
1258334SJose.Borrego@Sun.COM return (B_FALSE);
1268334SJose.Borrego@Sun.COM
1278334SJose.Borrego@Sun.COM (void) mutex_lock(&smb_dclocator.sdl_mtx);
1288334SJose.Borrego@Sun.COM
1298334SJose.Borrego@Sun.COM if (!smb_dclocator.sdl_locate) {
1308334SJose.Borrego@Sun.COM smb_dclocator.sdl_locate = B_TRUE;
1318334SJose.Borrego@Sun.COM (void) strlcpy(smb_dclocator.sdl_domain, domain,
1328334SJose.Borrego@Sun.COM SMB_PI_MAX_DOMAIN);
1339832Samw@Sun.COM (void) strlcpy(smb_dclocator.sdl_dc, dc, MAXHOSTNAMELEN);
1348334SJose.Borrego@Sun.COM (void) cond_broadcast(&smb_dclocator.sdl_cv);
1358334SJose.Borrego@Sun.COM }
1368334SJose.Borrego@Sun.COM
1378334SJose.Borrego@Sun.COM while (smb_dclocator.sdl_locate) {
1388334SJose.Borrego@Sun.COM to.tv_sec = SMB_DCLOCATOR_TIMEOUT;
1398334SJose.Borrego@Sun.COM to.tv_nsec = 0;
1408334SJose.Borrego@Sun.COM rc = cond_reltimedwait(&smb_dclocator.sdl_cv,
1418334SJose.Borrego@Sun.COM &smb_dclocator.sdl_mtx, &to);
1428334SJose.Borrego@Sun.COM
1438334SJose.Borrego@Sun.COM if (rc == ETIME)
1448334SJose.Borrego@Sun.COM break;
1458334SJose.Borrego@Sun.COM }
1468334SJose.Borrego@Sun.COM
1478334SJose.Borrego@Sun.COM if (dp == NULL)
1488334SJose.Borrego@Sun.COM dp = &domain_info;
1498334SJose.Borrego@Sun.COM rc = smb_domain_getinfo(dp);
1509832Samw@Sun.COM
1518334SJose.Borrego@Sun.COM (void) mutex_unlock(&smb_dclocator.sdl_mtx);
1528334SJose.Borrego@Sun.COM
1538334SJose.Borrego@Sun.COM return (rc);
1548334SJose.Borrego@Sun.COM }
1558334SJose.Borrego@Sun.COM
1568334SJose.Borrego@Sun.COM /*
1578334SJose.Borrego@Sun.COM * ==========================================================
1588334SJose.Borrego@Sun.COM * DC discovery functions
1598334SJose.Borrego@Sun.COM * ==========================================================
1608334SJose.Borrego@Sun.COM */
1618334SJose.Borrego@Sun.COM
1628334SJose.Borrego@Sun.COM /*
16310717Samw@Sun.COM * This is the domain and DC discovery service: it gets woken up whenever
16410717Samw@Sun.COM * there is need to locate a domain controller.
1658334SJose.Borrego@Sun.COM *
1669832Samw@Sun.COM * Upon success, the SMB domain cache will be populated with the discovered
1679832Samw@Sun.COM * DC and domain info.
1688334SJose.Borrego@Sun.COM */
1698334SJose.Borrego@Sun.COM /*ARGSUSED*/
1708334SJose.Borrego@Sun.COM static void *
smb_ddiscover_service(void * arg)17110717Samw@Sun.COM smb_ddiscover_service(void *arg)
1728334SJose.Borrego@Sun.COM {
1738334SJose.Borrego@Sun.COM char domain[SMB_PI_MAX_DOMAIN];
1748334SJose.Borrego@Sun.COM char sought_dc[MAXHOSTNAMELEN];
1758334SJose.Borrego@Sun.COM
1768334SJose.Borrego@Sun.COM for (;;) {
1778334SJose.Borrego@Sun.COM (void) mutex_lock(&smb_dclocator.sdl_mtx);
1788334SJose.Borrego@Sun.COM
1798334SJose.Borrego@Sun.COM while (!smb_dclocator.sdl_locate)
1808334SJose.Borrego@Sun.COM (void) cond_wait(&smb_dclocator.sdl_cv,
1818334SJose.Borrego@Sun.COM &smb_dclocator.sdl_mtx);
1828334SJose.Borrego@Sun.COM
1838334SJose.Borrego@Sun.COM (void) strlcpy(domain, smb_dclocator.sdl_domain,
1848334SJose.Borrego@Sun.COM SMB_PI_MAX_DOMAIN);
1858334SJose.Borrego@Sun.COM (void) strlcpy(sought_dc, smb_dclocator.sdl_dc, MAXHOSTNAMELEN);
1868334SJose.Borrego@Sun.COM (void) mutex_unlock(&smb_dclocator.sdl_mtx);
1878334SJose.Borrego@Sun.COM
18810717Samw@Sun.COM smb_ddiscover_main(domain, sought_dc);
1898334SJose.Borrego@Sun.COM
1908334SJose.Borrego@Sun.COM (void) mutex_lock(&smb_dclocator.sdl_mtx);
1918334SJose.Borrego@Sun.COM smb_dclocator.sdl_locate = B_FALSE;
1928334SJose.Borrego@Sun.COM (void) cond_broadcast(&smb_dclocator.sdl_cv);
1938334SJose.Borrego@Sun.COM (void) mutex_unlock(&smb_dclocator.sdl_mtx);
1948334SJose.Borrego@Sun.COM }
1958334SJose.Borrego@Sun.COM
1968334SJose.Borrego@Sun.COM /*NOTREACHED*/
1978334SJose.Borrego@Sun.COM return (NULL);
1988334SJose.Borrego@Sun.COM }
1998334SJose.Borrego@Sun.COM
2008334SJose.Borrego@Sun.COM /*
2019832Samw@Sun.COM * Discovers a domain controller for the specified domain either via
2029832Samw@Sun.COM * DNS or NetBIOS. After the domain controller is discovered successfully
2039832Samw@Sun.COM * primary and trusted domain infromation will be queried using RPC queries.
2049832Samw@Sun.COM * If the RPC queries fail, the domain information stored in SMF might be used
2059832Samw@Sun.COM * if the the discovered domain is the same as the previously joined domain.
2069832Samw@Sun.COM * If everything is successful domain cache will be updated with all the
2079832Samw@Sun.COM * obtained information.
2089832Samw@Sun.COM */
2099832Samw@Sun.COM static void
smb_ddiscover_main(char * domain,char * server)21010717Samw@Sun.COM smb_ddiscover_main(char *domain, char *server)
2119832Samw@Sun.COM {
21210717Samw@Sun.COM smb_domainex_t dxi;
21310717Samw@Sun.COM boolean_t discovered;
2149832Samw@Sun.COM
21510717Samw@Sun.COM bzero(&dxi, sizeof (smb_domainex_t));
2169832Samw@Sun.COM
21710717Samw@Sun.COM if (smb_domain_start_update() != SMB_DOMAIN_SUCCESS)
21810717Samw@Sun.COM return;
2199832Samw@Sun.COM
2209832Samw@Sun.COM if (SMB_IS_FQDN(domain))
22110717Samw@Sun.COM discovered = smb_ddiscover_dns(domain, server, &dxi);
2229832Samw@Sun.COM else
22310717Samw@Sun.COM discovered = smb_ddiscover_nbt(domain, server, &dxi);
2249832Samw@Sun.COM
22510717Samw@Sun.COM if (discovered)
22610717Samw@Sun.COM smb_domain_update(&dxi);
2279832Samw@Sun.COM
22810717Samw@Sun.COM smb_domain_end_update();
2299832Samw@Sun.COM
23010717Samw@Sun.COM smb_domainex_free(&dxi);
2319832Samw@Sun.COM
23210717Samw@Sun.COM if (discovered)
23310717Samw@Sun.COM smb_domain_save();
2349832Samw@Sun.COM }
2359832Samw@Sun.COM
2369832Samw@Sun.COM /*
2379832Samw@Sun.COM * Discovers a DC for the specified domain via DNS. If a DC is found
2389832Samw@Sun.COM * primary and trusted domains information will be queried.
2399832Samw@Sun.COM */
2409832Samw@Sun.COM static boolean_t
smb_ddiscover_dns(char * domain,char * server,smb_domainex_t * dxi)24110717Samw@Sun.COM smb_ddiscover_dns(char *domain, char *server, smb_domainex_t *dxi)
2429832Samw@Sun.COM {
2439832Samw@Sun.COM uint32_t status;
24410717Samw@Sun.COM
24510717Samw@Sun.COM if (!smb_ads_lookup_msdcs(domain, server, dxi->d_dc, MAXHOSTNAMELEN))
2469832Samw@Sun.COM return (B_FALSE);
2479832Samw@Sun.COM
24810717Samw@Sun.COM status = smb_ddiscover_qinfo(domain, dxi->d_dc, dxi);
2499832Samw@Sun.COM return (status == NT_STATUS_SUCCESS);
2509832Samw@Sun.COM }
2519832Samw@Sun.COM
2529832Samw@Sun.COM /*
2539832Samw@Sun.COM * Discovers a DC for the specified domain using NETLOGON protocol.
2549832Samw@Sun.COM * If a DC cannot be found using NETLOGON then it will
2558334SJose.Borrego@Sun.COM * try to resolve it via DNS, i.e. find out if it is the first label
2568334SJose.Borrego@Sun.COM * of a DNS domain name. If the corresponding DNS name is found, DC
2578334SJose.Borrego@Sun.COM * discovery will be done via DNS query.
2588334SJose.Borrego@Sun.COM *
2598334SJose.Borrego@Sun.COM * If the fully-qualified domain name is derived from the DNS config
2608334SJose.Borrego@Sun.COM * file, the NetBIOS domain name specified by the user will be compared
2618334SJose.Borrego@Sun.COM * against the NetBIOS domain name obtained via LSA query. If there is
2628334SJose.Borrego@Sun.COM * a mismatch, the DC discovery will fail since the discovered DC is
2638334SJose.Borrego@Sun.COM * actually for another domain, whose first label of its FQDN somehow
2648334SJose.Borrego@Sun.COM * matches with the NetBIOS name of the domain we're interested in.
2658334SJose.Borrego@Sun.COM */
2668334SJose.Borrego@Sun.COM static boolean_t
smb_ddiscover_nbt(char * domain,char * server,smb_domainex_t * dxi)26710717Samw@Sun.COM smb_ddiscover_nbt(char *domain, char *server, smb_domainex_t *dxi)
2688334SJose.Borrego@Sun.COM {
2699832Samw@Sun.COM char dnsdomain[MAXHOSTNAMELEN];
2709832Samw@Sun.COM uint32_t status;
2718334SJose.Borrego@Sun.COM
2729832Samw@Sun.COM *dnsdomain = '\0';
2739832Samw@Sun.COM
27410717Samw@Sun.COM if (!smb_browser_netlogon(domain, dxi->d_dc, MAXHOSTNAMELEN)) {
27510717Samw@Sun.COM if (!smb_ddiscover_domain_match(domain, dnsdomain,
27610717Samw@Sun.COM MAXHOSTNAMELEN))
2779832Samw@Sun.COM return (B_FALSE);
2789832Samw@Sun.COM
27910717Samw@Sun.COM if (!smb_ads_lookup_msdcs(dnsdomain, server, dxi->d_dc,
2808334SJose.Borrego@Sun.COM MAXHOSTNAMELEN))
2818334SJose.Borrego@Sun.COM return (B_FALSE);
2828334SJose.Borrego@Sun.COM }
2838334SJose.Borrego@Sun.COM
28410717Samw@Sun.COM status = smb_ddiscover_qinfo(domain, dxi->d_dc, dxi);
2859832Samw@Sun.COM if (status != NT_STATUS_SUCCESS)
2868334SJose.Borrego@Sun.COM return (B_FALSE);
2878334SJose.Borrego@Sun.COM
2889832Samw@Sun.COM if ((*dnsdomain != '\0') &&
28910966SJordan.Brown@Sun.COM smb_strcasecmp(domain, dxi->d_primary.di_nbname, 0))
2908334SJose.Borrego@Sun.COM return (B_FALSE);
2918334SJose.Borrego@Sun.COM
2928334SJose.Borrego@Sun.COM /*
2938334SJose.Borrego@Sun.COM * Now that we get the fully-qualified DNS name of the
2948334SJose.Borrego@Sun.COM * domain via LSA query. Verifies ADS configuration
2958334SJose.Borrego@Sun.COM * if we previously locate a DC via NetBIOS. On success,
2968334SJose.Borrego@Sun.COM * ADS cache will be populated.
2978334SJose.Borrego@Sun.COM */
29810717Samw@Sun.COM if (smb_ads_lookup_msdcs(dxi->d_primary.di_fqname, server,
29910717Samw@Sun.COM dxi->d_dc, MAXHOSTNAMELEN) == 0)
3009832Samw@Sun.COM return (B_FALSE);
3018334SJose.Borrego@Sun.COM
3028334SJose.Borrego@Sun.COM return (B_TRUE);
3038334SJose.Borrego@Sun.COM }
3048334SJose.Borrego@Sun.COM
3058334SJose.Borrego@Sun.COM /*
3068334SJose.Borrego@Sun.COM * Tries to find a matching DNS domain for the given NetBIOS domain
3078334SJose.Borrego@Sun.COM * name by checking the first label of system's configured DNS domains.
3088334SJose.Borrego@Sun.COM * If a match is found, it'll be returned in the passed buffer.
3098334SJose.Borrego@Sun.COM */
3108334SJose.Borrego@Sun.COM static boolean_t
smb_ddiscover_domain_match(char * nb_domain,char * buf,uint32_t len)31110717Samw@Sun.COM smb_ddiscover_domain_match(char *nb_domain, char *buf, uint32_t len)
3128334SJose.Borrego@Sun.COM {
3138334SJose.Borrego@Sun.COM struct __res_state res_state;
3148334SJose.Borrego@Sun.COM int i;
3158334SJose.Borrego@Sun.COM char *entry, *p;
3168334SJose.Borrego@Sun.COM char first_label[MAXHOSTNAMELEN];
3178334SJose.Borrego@Sun.COM boolean_t found;
3188334SJose.Borrego@Sun.COM
3198334SJose.Borrego@Sun.COM if (!nb_domain || !buf)
3208334SJose.Borrego@Sun.COM return (B_FALSE);
3218334SJose.Borrego@Sun.COM
3228334SJose.Borrego@Sun.COM *buf = '\0';
3238334SJose.Borrego@Sun.COM bzero(&res_state, sizeof (struct __res_state));
3248334SJose.Borrego@Sun.COM if (res_ninit(&res_state))
3258334SJose.Borrego@Sun.COM return (B_FALSE);
3268334SJose.Borrego@Sun.COM
3278334SJose.Borrego@Sun.COM found = B_FALSE;
3288334SJose.Borrego@Sun.COM entry = res_state.defdname;
3298334SJose.Borrego@Sun.COM for (i = 0; entry != NULL; i++) {
3308334SJose.Borrego@Sun.COM (void) strlcpy(first_label, entry, MAXHOSTNAMELEN);
3318334SJose.Borrego@Sun.COM if ((p = strchr(first_label, '.')) != NULL) {
3328334SJose.Borrego@Sun.COM *p = '\0';
3338334SJose.Borrego@Sun.COM if (strlen(first_label) > 15)
3348334SJose.Borrego@Sun.COM first_label[15] = '\0';
3358334SJose.Borrego@Sun.COM }
3368334SJose.Borrego@Sun.COM
33710966SJordan.Brown@Sun.COM if (smb_strcasecmp(nb_domain, first_label, 0) == 0) {
3388334SJose.Borrego@Sun.COM found = B_TRUE;
3398334SJose.Borrego@Sun.COM (void) strlcpy(buf, entry, len);
3408334SJose.Borrego@Sun.COM break;
3418334SJose.Borrego@Sun.COM }
3428334SJose.Borrego@Sun.COM
3438334SJose.Borrego@Sun.COM entry = res_state.dnsrch[i];
3448334SJose.Borrego@Sun.COM }
3458334SJose.Borrego@Sun.COM
3468334SJose.Borrego@Sun.COM
3478334SJose.Borrego@Sun.COM res_ndestroy(&res_state);
3488334SJose.Borrego@Sun.COM return (found);
3498334SJose.Borrego@Sun.COM }
3508334SJose.Borrego@Sun.COM
3518334SJose.Borrego@Sun.COM /*
3529832Samw@Sun.COM * Obtain primary and trusted domain information using LSA queries.
3538334SJose.Borrego@Sun.COM *
3549832Samw@Sun.COM * Disconnect any existing connection with the domain controller.
3559832Samw@Sun.COM * This will ensure that no stale connection will be used, it will
3569832Samw@Sun.COM * also pickup any configuration changes in either side by trying
3579832Samw@Sun.COM * to establish a new connection.
3588334SJose.Borrego@Sun.COM *
3598334SJose.Borrego@Sun.COM * domain - either NetBIOS or fully-qualified domain name
3608334SJose.Borrego@Sun.COM */
3618334SJose.Borrego@Sun.COM static uint32_t
smb_ddiscover_qinfo(char * domain,char * server,smb_domainex_t * dxi)36210717Samw@Sun.COM smb_ddiscover_qinfo(char *domain, char *server, smb_domainex_t *dxi)
3638334SJose.Borrego@Sun.COM {
3649832Samw@Sun.COM uint32_t status;
3659832Samw@Sun.COM
3669832Samw@Sun.COM mlsvc_disconnect(server);
3678334SJose.Borrego@Sun.COM
36810717Samw@Sun.COM status = lsa_query_dns_domain_info(server, domain, &dxi->d_primary);
3699832Samw@Sun.COM if (status != NT_STATUS_SUCCESS) {
37010717Samw@Sun.COM status = smb_ddiscover_use_config(domain, dxi);
3719832Samw@Sun.COM if (status != NT_STATUS_SUCCESS)
3729832Samw@Sun.COM status = lsa_query_primary_domain_info(server, domain,
37310717Samw@Sun.COM &dxi->d_primary);
3748334SJose.Borrego@Sun.COM }
3758334SJose.Borrego@Sun.COM
3769832Samw@Sun.COM if (status == NT_STATUS_SUCCESS)
37710717Samw@Sun.COM smb_ddiscover_enum_trusted(domain, server, dxi);
3789832Samw@Sun.COM
3799832Samw@Sun.COM return (status);
3808334SJose.Borrego@Sun.COM }
3818334SJose.Borrego@Sun.COM
3828334SJose.Borrego@Sun.COM /*
3839832Samw@Sun.COM * Obtain trusted domains information using LSA queries.
3848334SJose.Borrego@Sun.COM *
3858334SJose.Borrego@Sun.COM * domain - either NetBIOS or fully-qualified domain name.
3868334SJose.Borrego@Sun.COM */
3878334SJose.Borrego@Sun.COM static void
smb_ddiscover_enum_trusted(char * domain,char * server,smb_domainex_t * dxi)38810717Samw@Sun.COM smb_ddiscover_enum_trusted(char *domain, char *server, smb_domainex_t *dxi)
3898334SJose.Borrego@Sun.COM {
39010717Samw@Sun.COM smb_trusted_domains_t *list;
3919832Samw@Sun.COM uint32_t status;
3928334SJose.Borrego@Sun.COM
39310717Samw@Sun.COM list = &dxi->d_trusted;
3949832Samw@Sun.COM status = lsa_enum_trusted_domains_ex(server, domain, list);
3959832Samw@Sun.COM if (status != NT_STATUS_SUCCESS)
3969832Samw@Sun.COM (void) lsa_enum_trusted_domains(server, domain, list);
3978334SJose.Borrego@Sun.COM }
3988334SJose.Borrego@Sun.COM
3998334SJose.Borrego@Sun.COM /*
4008334SJose.Borrego@Sun.COM * If the domain to be discovered matches the current domain (i.e the
40110717Samw@Sun.COM * value of either domain or fqdn configuration), then get the primary
40210717Samw@Sun.COM * domain information from SMF.
4038334SJose.Borrego@Sun.COM */
4049832Samw@Sun.COM static uint32_t
smb_ddiscover_use_config(char * domain,smb_domainex_t * dxi)40510717Samw@Sun.COM smb_ddiscover_use_config(char *domain, smb_domainex_t *dxi)
4068334SJose.Borrego@Sun.COM {
4078334SJose.Borrego@Sun.COM boolean_t use;
40810717Samw@Sun.COM smb_domain_t *dinfo;
4098334SJose.Borrego@Sun.COM
41010717Samw@Sun.COM dinfo = &dxi->d_primary;
41110717Samw@Sun.COM bzero(dinfo, sizeof (smb_domain_t));
4129832Samw@Sun.COM
4138334SJose.Borrego@Sun.COM if (smb_config_get_secmode() != SMB_SECMODE_DOMAIN)
4149832Samw@Sun.COM return (NT_STATUS_UNSUCCESSFUL);
4158334SJose.Borrego@Sun.COM
4169832Samw@Sun.COM smb_config_getdomaininfo(dinfo->di_nbname, dinfo->di_fqname,
4179832Samw@Sun.COM NULL, NULL, NULL);
4188334SJose.Borrego@Sun.COM
4199832Samw@Sun.COM if (SMB_IS_FQDN(domain))
42010966SJordan.Brown@Sun.COM use = (smb_strcasecmp(dinfo->di_fqname, domain, 0) == 0);
4219832Samw@Sun.COM else
42210966SJordan.Brown@Sun.COM use = (smb_strcasecmp(dinfo->di_nbname, domain, 0) == 0);
4238334SJose.Borrego@Sun.COM
4249832Samw@Sun.COM if (use)
4259832Samw@Sun.COM smb_config_getdomaininfo(NULL, NULL, dinfo->di_sid,
4269832Samw@Sun.COM dinfo->di_u.di_dns.ddi_forest,
4279832Samw@Sun.COM dinfo->di_u.di_dns.ddi_guid);
4288334SJose.Borrego@Sun.COM
4299832Samw@Sun.COM return ((use) ? NT_STATUS_SUCCESS : NT_STATUS_UNSUCCESSFUL);
4308334SJose.Borrego@Sun.COM }
4319832Samw@Sun.COM
4329832Samw@Sun.COM static void
smb_domainex_free(smb_domainex_t * dxi)43310717Samw@Sun.COM smb_domainex_free(smb_domainex_t *dxi)
4349832Samw@Sun.COM {
43510717Samw@Sun.COM free(dxi->d_trusted.td_domains);
4369832Samw@Sun.COM }
437