/*
* 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 2015 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 <errno.h>
#include <smbsrv/libsmbns.h>
#include <smbsrv/libmlsvc.h>
#include "smbd.h"
static void *smbd_dc_monitor(void *);
static void smbd_dc_update(void);
static int smbd_dc_check(smb_domainex_t *);
/* 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);
}
/*
* Refresh the DC monitor. Called from SMF refresh and when idmap
* finds a different DC from what we were using previously.
* Update our domain (and current DC) information.
*/
void
smbd_dc_monitor_refresh(void)
{
(void) mutex_lock(&smbd_dc_mutex);
(void) cond_signal(&smbd_dc_cv);
(void) mutex_unlock(&smbd_dc_mutex);
}
/*ARGSUSED*/
static void *
{
int i;
/* Wait for smb_dclocator_init() to complete. */
smbd_online_wait("smbd_dc_monitor");
while (smbd_online()) {
(void) mutex_lock(&smbd_dc_mutex);
if (smbd.s_pdc_changed) {
/* NB: smb_ddiscover_refresh was called. */
}
(void) mutex_unlock(&smbd_dc_mutex);
if (ds_cfg_changed) {
goto rediscover;
}
if (!smb_domain_getinfo(&di)) {
goto rediscover;
}
goto rediscover;
}
for (i = 0; i < SMBD_DC_MONITOR_ATTEMPTS; ++i) {
if (smbd_dc_check(&di) == 0) {
break;
}
(void) sleep(SMBD_DC_MONITOR_RETRY_INTERVAL);
}
if (ds_not_responding) {
"smbd_dc_monitor: DC not responding: %s",
}
if (ds_not_responding || ds_cfg_changed) {
/*
* An smb_ads_refresh will be done by the
* smb_ddiscover_service when necessary.
* Note: smbd_dc_monitor_refresh was already
* called if appropriate.
*/
}
}
smbd.s_dc_monitor_tid = 0;
return (NULL);
}
/*
* Simply attempt a connection to the DC.
*/
static int
{
int salen = 0;
int rc;
case AF_INET: {
break;
}
case AF_INET6: {
sizeof (in6_addr_t));
break;
}
default:
return (-1);
}
if (sock < 0)
return (errno);
if (rc < 0)
return (rc);
}
/*
* 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)
{
/*
* Don't want this active until we're a domain member.
*/
if (smb_config_get_secmode() != SMB_SECMODE_DOMAIN)
return;
return;
if (domain[0] == '\0') {
"smbd_dc_update: no domain name set");
return;
}
"smbd_dc_update: %s: locate failed", domain);
return;
}
if (status != NT_STATUS_SUCCESS) {
"failed to establish NETLOGON credential chain");
}
}
/*
* smbd_join
*
*
* If the security mode or domain name is being changed,
* the caller must restart the service.
*/
void
{
else
}
static void
{
sizeof (nb_domain));
(void) smb_config_set_idmap_domain("");
(void) smb_config_refresh_idmap();
}
static void
{
/* info->domain_name could either be NetBIOS domain name or FQDN */
} else {
}
}