/*
* 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 <stdarg.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <synch.h>
#include <syslog.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <netdb.h>
#include <resolv.h>
#include <assert.h>
/*
* IPC connection information that may be passed to the SMB Redirector.
*/
typedef struct {
} smb_ipc_t;
/*
* These three parameters are all related:
* skc_initial_credits
* skc_maximum_credits
* skc_maxworkers (max worker threads)
* They must be in non-decreasing order. Get the values in order:
* maxworkers, maximum_credits, initial_credits
* enforcing maximum values and relations as we go. Then in the
* opposite order check minimum values and relations.
*
* smb_config_getnum puts a zero in the &citem if it fails getting
* the parameter value. When fetch parameters for which zero is OK,
* the return code is intentionally ignored.
*/
void
{
int rc;
/*
* skc_maxworkers (max. no. of taskq worker threads)
*/
if (rc != SMBD_SMF_OK)
if (citem > SMB_PI_MAX_WORKERS_MAX)
/*
* The largest number of credits we let a single client have.
* It never makes sense for this to be > max_workers
*/
if (rc != SMBD_SMF_OK)
if (citem > SMB_PI_MAXIMUM_CREDITS_MAX)
/*
* The number of credits we give a client initially.
* Should be enough for a "light" workload, as the
* client will request additional credits when the
* workload increases. Must be <= maximum_credits.
*/
if (rc != SMBD_SMF_OK)
if (citem > SMB_PI_INITIAL_CREDITS_MAX)
/*
* Now enforce minimums, smaller to larger.
*/
if ((kcfg->skc_keepalive != 0) &&
sizeof (kcfg->skc_nbdomain));
sizeof (kcfg->skc_hostname));
sizeof (kcfg->skc_system_comment));
}
/* skc_negtok, skc_negtok_len: see smbd_authsvc.c */
sizeof (kcfg->skc_native_lm));
}
/*
* Get the current system NetBIOS name. The hostname is truncated at
* the first `.` or 15 bytes, whichever occurs first, and converted
* to uppercase (by smb_gethostname). Text that appears after the
* first '.' is considered to be part of the NetBIOS scope.
*
* Returns 0 on success, otherwise -1 to indicate an error.
*/
int
{
return (-1);
if (buflen >= NETBIOS_NAME_SZ)
return (0);
}
/*
* Get the SAM account of the current system.
* Returns 0 on success, otherwise, -1 to indicate an error.
*/
int
{
return (-1);
return (0);
}
/*
* Get the current system node name. The returned name is guaranteed
* to be null-terminated (gethostname may not null terminate the name).
* If the hostname has been fully-qualified for some reason, the domain
* part will be removed. The returned hostname is converted to the
* specified case (lower, upper, or preserved).
*
* If gethostname fails, the returned buffer will contain an empty
* string.
*/
int
{
char *p;
return (-1);
*buf = '\0';
return (-1);
}
*p = '\0';
switch (which) {
case SMB_CASE_LOWER:
(void) smb_strlwr(buf);
break;
case SMB_CASE_UPPER:
(void) smb_strupr(buf);
break;
case SMB_CASE_PRESERVE:
default:
break;
}
return (0);
}
/*
* Obtain the fully-qualified name for this machine in lower case. If
* the hostname is fully-qualified, accept it. Otherwise, try to find an
* appropriate domain name to append to the hostname.
*/
int
{
hostname[0] = '\0';
domain[0] = '\0';
SMB_CASE_LOWER) != 0)
return (-1);
return (-1);
if (hostname[0] == '\0')
return (-1);
if (domain[0] == '\0') {
return (0);
}
return (0);
}
/*
* smb_getdomainname
*
* Returns NETBIOS name of the domain if the system is in domain
* mode. Or returns workgroup name if the system is in workgroup
* mode.
*/
int
{
int rc;
return (-1);
*buf = '\0';
return (-1);
return (0);
}
/*
* smb_getfqdomainname
*
* In the system is in domain mode, the dns_domain property value
* is returned. Otherwise, it returns the local domain obtained via
* resolver.
*
* Returns 0 upon success. Otherwise, returns -1.
*/
int
{
int rc;
return (-1);
*buf = '\0';
if (smb_config_get_secmode() == SMB_SECMODE_DOMAIN) {
return (-1);
} else {
return (-1);
return (-1);
}
rc = 0;
}
return (rc);
}
/*
* smb_set_machine_passwd
*
* This function should be used when setting the machine password property.
* The associated sequence number is incremented.
*/
static int
{
return (-1);
(void) mutex_lock(&seqnum_mtx);
== SMBD_SMF_OK)
rc = 0;
(void) mutex_unlock(&seqnum_mtx);
return (rc);
}
static int
{
int rc;
if (buflen < SMBAUTH_HASH_SZ)
return (-1);
return (-1);
return (-1);
return (rc);
}
/*
* Set up IPC connection credentials.
*/
void
smb_ipc_init(void)
{
int rc;
(void) rw_wrlock(&smb_ipc_lock);
if (rc != 0)
(void) rw_unlock(&smb_ipc_lock);
}
/*
* Set the IPC username and password hash in memory. If the domain
* join succeeds, the credentials will be committed for use with
* authenticated IPC. Otherwise, they should be rolled back.
*/
void
{
(void) rw_wrlock(&smb_ipc_lock);
(void) rw_unlock(&smb_ipc_lock);
}
/*
* Save the host credentials to be used for authenticated IPC.
* The credentials are also saved to the original IPC info as
* rollback data in case the join domain process fails later.
*/
void
smb_ipc_commit(void)
{
(void) rw_wrlock(&smb_ipc_lock);
(void) rw_unlock(&smb_ipc_lock);
}
/*
* Restore the original credentials
*/
void
smb_ipc_rollback(void)
{
(void) rw_wrlock(&smb_ipc_lock);
(void) rw_unlock(&smb_ipc_lock);
}
void
{
(void) rw_rdlock(&smb_ipc_lock);
(void) rw_unlock(&smb_ipc_lock);
}
void
{
if (buflen < SMBAUTH_HASH_SZ)
return;
(void) rw_rdlock(&smb_ipc_lock);
(void) rw_unlock(&smb_ipc_lock);
}
/*
* smb_match_netlogon_seqnum
*
* A sequence number is associated with each machine password property
* update and the netlogon credential chain setup. If the
* sequence numbers don't match, a NETLOGON credential chain
* establishment is required.
*
* Returns 0 if kpasswd_seqnum equals to netlogon_seqnum. Otherwise,
* returns -1.
*/
{
(void) mutex_lock(&seqnum_mtx);
(void) mutex_unlock(&seqnum_mtx);
return (setpasswd_seqnum == netlogon_seqnum);
}
/*
* smb_setdomainprops
*
* This function should be called after joining an AD to
* set all the domain related SMF properties.
*
* The kpasswd_domain property is the AD domain to which the system
* is joined via kclient. If this function is invoked by the SMB
* daemon, fqdn should be set to NULL.
*/
int
{
return (-1);
return (-1);
return (-1);
return (-1);
if (smb_set_machine_passwd(passwd) != 0) {
" machine account password");
return (-1);
}
/*
* If we successfully create a trust account, we mark
* ourselves as a domain member in the environment so
* that we use the SAMLOGON version of the NETLOGON
* PDC location protocol.
*/
return (0);
}
/*
* smb_update_netlogon_seqnum
*
* This function should only be called upon a successful netlogon
* credential chain establishment to set the sequence number of the
* netlogon to match with that of the kpasswd.
*/
void
{
(void) mutex_lock(&seqnum_mtx);
(void) mutex_unlock(&seqnum_mtx);
}
/*
* Temporary fbt for dtrace until user space sdt enabled.
*/
void
{
}
/*
* Temporary fbt for dtrace until user space sdt enabled.
*
* This function is designed to be used with dtrace, i.e. see:
*
* Outside of dtrace, the messages passed to this function usually
* lack sufficient context to be useful, so we don't log them.
*/
/* ARGSUSED */
void
smb_trace(const char *s)
{
}
/*
* smb_tonetbiosname
*
* Creates a NetBIOS name based on the given name and suffix.
* NetBIOS name is 15 capital characters, padded with space if needed
* and the 16th byte is the suffix.
*/
void
{
int len;
len = 0;
if (rc > 0)
}
if (len) {
(void) smb_strupr(tmp_name);
}
}
int
{
int i, cnt;
return (0);
return (0);
for (i = 0; i < cnt; i++) {
if (i >= sz)
break;
INET_ADDRSTRLEN)) {
continue;
}
INET6_ADDRSTRLEN)) {
}
}
return (i);
}
/*
* smb_gethostbyname
*
* Looks up a host by the given name. The host entry can come
* from any of the sources for hosts specified in the
* /etc/nsswitch.conf and the NetBIOS cache.
*
* XXX Invokes nbt_name_resolve API once the NBTD is integrated
* to look in the NetBIOS cache if getipnodebyname fails.
*
* Caller should invoke freehostent to free the returned hostent.
*/
struct hostent *
{
struct hostent *h;
return (h);
}
/*
* smb_gethostbyaddr
*
* Looks up a host by the given IP address. The host entry can come
* from any of the sources for hosts specified in the
* /etc/nsswitch.conf and the NetBIOS cache.
*
* XXX Invokes nbt API to resolve name by IP once the NBTD is integrated
* to look in the NetBIOS cache if getipnodebyaddr fails.
*
* Caller should invoke freehostent to free the returned hostent.
*/
struct hostent *
{
struct hostent *h;
return (h);
}