smb_native.c revision b819cea2f73f98c5662230cc9affc8cc84f77fcf
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington/*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * CDDL HEADER START
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * The contents of this file are subject to the terms of the
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Common Development and Distribution License (the "License").
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * You may not use this file except in compliance with the License.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * or http://www.opensolaris.org/os/licensing.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * See the License for the specific language governing permissions
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * and limitations under the License.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * When distributing Covered Code, include this CDDL HEADER in each
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * If applicable, add the following below this CDDL HEADER, with the
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * fields enclosed by brackets "[]" replaced with your own identifying
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * information: Portions Copyright [yyyy] [name of copyright owner]
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * CDDL HEADER END
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington */
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden/*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Use is subject to license terms.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington */
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden/*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * This module defines generic functions to map Native OS and Native
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * LanMan names to values.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington */
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#if defined(_KERNEL) || defined(_FAKE_KERNEL)
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#include <sys/types.h>
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden#include <sys/sunddi.h>
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#else
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#include <string.h>
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#endif
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#include <smbsrv/string.h>
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington#include <smbsrv/smbinfo.h>
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunningtontypedef struct smb_native {
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington int sn_value;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington const char *sn_name;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington} smb_native_t;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington/*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * smbnative_os_value
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Return the appropriate native OS value for the specified native OS name.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Example OS values used by Windows:
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 4.0, Windows NT, Windows NT 4.0
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 5.0, Windows 5.1
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2000, Windows 2000 5.0, Windows 2000 5.1
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2002
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows .NET
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows Server 2003
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows XP
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2000 server: "Windows 2000 2195"
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows XP Professional client: "Windows 2002 2543"
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden * Windows XP PDC server: "Windows 5.1"
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden * Windows .Net: "Windows .NET 3621"
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden * Windows .Net: "Windows .NET 3718"
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden *
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden * DAVE (Thursby Software: CIFS for MacOS) uses "MacOS", sometimes with a
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden * version number appended, i.e. "MacOS 8.5.1". We treat DAVE like NT 4.0
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * except for the cases that DAVE clients set 'watch tree' flag in notify
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * change requests.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Samba reports UNIX as its Native OS, which we can map to NT 4.0.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington */
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunningtonint
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunningtonsmbnative_os_value(const char *native_os)
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington{
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington static smb_native_t os_table[] = {
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WINNT, "Windows NT 4.0" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WINNT, "Windows NT" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN95, "Windows 4.0" },
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden { NATIVE_OS_WIN2000, "Windows 5.0" },
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden { NATIVE_OS_WIN2000, "Windows 5.1" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN2000, "Windows 2000" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN2000, "Windows 2002" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN2000, "Windows .NET" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN2000, "Windows Server" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WIN2000, "Windows XP" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_WINNT, "UNIX" },
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington { NATIVE_OS_MACOS, "MacOS" }
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington };
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden int i;
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden int len;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington const char *name;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington if (native_os == NULL)
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington return (NATIVE_OS_UNKNOWN);
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington /*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows Vista sends an empty native OS string.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington */
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington if (*native_os == '\0')
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden return (NATIVE_OS_WIN2000);
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington for (i = 0; i < sizeof (os_table)/sizeof (os_table[0]); ++i) {
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington name = os_table[i].sn_name;
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington len = strlen(name);
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington if (smb_strcasecmp(name, native_os, len) == 0)
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington return (os_table[i].sn_value);
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington }
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington return (NATIVE_OS_UNKNOWN);
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden}
d19efe4dce3fa8d1e3ef1a40238380d37664316bNeil Madden
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington/*
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * smbnative_lm_value
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Return the appropriate native LanMan value for the specified native
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * LanMan name. There's an alignment problem in some packets from some
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * clients that means we can miss the first character, so we do an
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * additional check starting from the second character.
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Example LanMan values:
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington *
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * NT LAN Manager 4.0
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 4.0
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows NT, Windows NT 4.0
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2000 LAN Manager
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2000, Windows 2000 5.0, Windows 2000 5.1
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows 2002, Windows 2002 5.1
cded99f20058449fd5f9dea3a4934f536343a1f6Phill Cunnington * Windows .NET, Windows .NET 5.2
* Windows Server 2003
* Windows XP
* NETSMB (Solaris CIFS client)
* DAVE (Thursby Software: CIFS for MacOS)
* Samba
*/
int
smbnative_lm_value(const char *native_lm)
{
static smb_native_t lm_table[] = {
{ NATIVE_LM_NT, "NT LAN Manager 4.0" },
{ NATIVE_LM_NT, "Windows NT" },
{ NATIVE_LM_NT, "Windows 4.0" },
{ NATIVE_LM_NT, "DAVE" }
};
int i;
int len;
const char *name;
/*
* Windows Vista sends an empty native LM string.
*/
if (native_lm == NULL || *native_lm == '\0')
return (NATIVE_LM_WIN2000);
for (i = 0; i < sizeof (lm_table)/sizeof (lm_table[0]); ++i) {
name = lm_table[i].sn_name;
len = strlen(name);
if ((smb_strcasecmp(name, native_lm, len) == 0) ||
(smb_strcasecmp(&name[1], native_lm, len - 1) == 0)) {
return (lm_table[i].sn_value);
}
}
return (NATIVE_LM_WIN2000);
}
/*
* smbnative_pdc_value
*
* This function is called when libsmbrdr connects to a PDC.
* The PDC type is derived from the Native LanMan string.
* The PDC value will default to PDC_WIN2000.
*
* Example strings:
*
* NT LAN Manager 4.0
* Windows 4.0, Windows NT, Windows NT 4.0
* Windows 2000 LAN Manager
* Windows 2000, Windows 2000 5.0, Windows 2000 5.1
* Windows 2002, Windows 2002 5.1
* Windows .NET, Windows .NET 5.2
* Samba
* DAVE
*/
int
smbnative_pdc_value(const char *native_lm)
{
static smb_native_t pdc_table[] = {
{ PDC_WINNT, "NT LAN Manager 4.0" },
{ PDC_WINNT, "Windows NT 4.0" },
{ PDC_WINNT, "Windows NT" },
{ PDC_WINNT, "Windows 4.0" },
{ PDC_WINNT, "DAVE" },
{ PDC_SAMBA, "Samba" }
};
int i;
int len;
const char *name;
if (native_lm == NULL || *native_lm == '\0')
return (PDC_WIN2000);
for (i = 0; i < sizeof (pdc_table)/sizeof (pdc_table[0]); ++i) {
name = pdc_table[i].sn_name;
len = strlen(name);
if ((smb_strcasecmp(name, native_lm, len) == 0) ||
(smb_strcasecmp(&name[1], native_lm, len - 1) == 0)) {
return (pdc_table[i].sn_value);
}
}
return (PDC_WIN2000);
}
/*
* Returns the native OS string for the given OS version.
* If no match is found the string for Windows 2000 is returned.
*/
const char *
smbnative_os_str(smb_version_t *version)
{
int i;
static smb_native_t osstr_table[] = {
{ SMB_MAJOR_NT, "Windows NT" },
{ SMB_MAJOR_2000, "Windows 2000" },
{ SMB_MAJOR_XP, "Windows XP" },
{ SMB_MAJOR_2003, "Windows Server 2003" },
{ SMB_MAJOR_VISTA, "" },
{ SMB_MAJOR_2008, "" },
{ SMB_MAJOR_2008R2, "" }
};
for (i = 0; i < sizeof (osstr_table)/sizeof (osstr_table[0]); ++i) {
if (version->sv_major == osstr_table[i].sn_value)
return (osstr_table[i].sn_name);
}
return (osstr_table[1].sn_name);
}
/*
* Returns the native Lanman string for the given OS version.
* If no match is found the string for Windows 2000 is returned.
*/
const char *
smbnative_lm_str(smb_version_t *version)
{
int i;
static smb_native_t lmstr_table[] = {
{ SMB_MAJOR_NT, "NT LAN Manager 4.0" },
{ SMB_MAJOR_2000, "Windows 2000 LAN Manager" },
{ SMB_MAJOR_XP, "Windows 2002 5.1" },
{ SMB_MAJOR_2003, "Windows Server 2003 5.2" },
{ SMB_MAJOR_VISTA, "" },
{ SMB_MAJOR_2008, "" },
{ SMB_MAJOR_2008R2, "" }
};
for (i = 0; i < sizeof (lmstr_table)/sizeof (lmstr_table[0]); ++i) {
if (version->sv_major == lmstr_table[i].sn_value)
return (lmstr_table[i].sn_name);
}
return (lmstr_table[1].sn_name);
}