smbd_join.c revision b819cea2f73f98c5662230cc9affc8cc84f77fcf
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <syslog.h>
#include <synch.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <smbsrv/libsmbns.h>
#include <smbsrv/libmlsvc.h>
#include "smbd.h"
#define SMBD_DC_MONITOR_ATTEMPTS 3
static mutex_t smbd_dc_mutex;
static cond_t smbd_dc_cv;
static void *smbd_dc_monitor(void *);
static void smbd_dc_update(void);
/* Todo: static boolean_t smbd_set_netlogon_cred(void); */
/*
* Launch the DC discovery and monitor thread.
*/
int
smbd_dc_monitor_init(void)
{
int rc;
smb_ads_init();
return (0);
(void) pthread_attr_init(&attr);
NULL);
(void) pthread_attr_destroy(&attr);
return (rc);
}
void
smbd_dc_monitor_refresh(void)
{
char site[MAXHOSTNAMELEN];
site[0] = '\0';
(void) mutex_lock(&smbd_dc_mutex);
(void) cond_signal(&smbd_dc_cv);
}
(void) mutex_unlock(&smbd_dc_mutex);
}
/*ARGSUSED*/
static void *
smbd_dc_monitor(void *arg)
{
int i;
smbd_online_wait("smbd_dc_monitor");
while (smbd_online()) {
(void) mutex_lock(&smbd_dc_mutex);
if (smbd.s_pdc_changed) {
}
(void) mutex_unlock(&smbd_dc_mutex);
for (i = 0; i < SMBD_DC_MONITOR_ATTEMPTS; ++i) {
if (dssetup_check_service() == 0) {
break;
}
(void) sleep(SMBD_DC_MONITOR_RETRY_INTERVAL);
}
if (ds_not_responding)
"smbd_dc_monitor: domain service not responding");
if (ds_not_responding || ds_cfg_changed) {
}
}
smbd.s_dc_monitor_tid = 0;
return (NULL);
}
/*
* Locate a domain controller in the current resource domain and Update
* the Netlogon credential chain.
*
* The domain configuration will be updated upon successful DC discovery.
*/
static void
smbd_dc_update(void)
{
char domain[MAXHOSTNAMELEN];
(void) smb_strupr(domain);
}
"smbd_dc_update: %s: locate failed", domain);
return;
}
if (status != NT_STATUS_SUCCESS) {
"failed to establish NETLOGON credential chain");
/*
* Restart required because the domain changed
* or the credential chain setup failed.
*/
if (smb_smf_restart_service() != 0)
" for more information");
}
}
/*
* smbd_join
*
*
* If the security mode or domain name is being changed,
* the caller must restart the service.
*/
{
else
return (status);
}
static uint32_t
{
char nb_domain[SMB_PI_MAX_DOMAIN];
sizeof (nb_domain));
return (NT_STATUS_SUCCESS);
}
static uint32_t
{
static unsigned char zero_hash[SMBAUTH_HASH_SZ];
/*
* Ensure that any previous membership of this domain has
* been cleared from the environment before we start. This
* will ensure that we don't attempt a NETLOGON_SAMLOGON
* when attempting to find the PDC.
*/
/* Clear DNS local (ADS) lookup cache too. */
/*
* Use a NULL session while searching for a DC, and
* while getting information about the domain.
*/
"domain controller for %s",
info->domain_name);
goto errout;
}
/* info->domain_name could either be NetBIOS domain name or FQDN */
if (status != NT_STATUS_SUCCESS) {
goto errout;
}
/*
* Success!
*
* Strange, mlsvc_join does some of the work to
* save the config, then the rest happens here.
* Todo: Do the config update all in one place.
*/
return (status);
return (status);
}