4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
29 * This module defines generic functions to map Native OS and Native
30 * LanMan names to values.
34 #include <sys/types.h>
35 #include <sys/sunddi.h>
39 #include <smbsrv/string.h>
40 #include <smbsrv/smbinfo.h>
42 typedef struct smb_native
{
50 * Return the appropriate native OS value for the specified native OS name.
52 * Example OS values used by Windows:
54 * Windows 4.0, Windows NT, Windows NT 4.0
55 * Windows 5.0, Windows 5.1
56 * Windows 2000, Windows 2000 5.0, Windows 2000 5.1
62 * Windows 2000 server: "Windows 2000 2195"
63 * Windows XP Professional client: "Windows 2002 2543"
64 * Windows XP PDC server: "Windows 5.1"
65 * Windows .Net: "Windows .NET 3621"
66 * Windows .Net: "Windows .NET 3718"
68 * DAVE (Thursby Software: CIFS for MacOS) uses "MacOS", sometimes with a
69 * version number appended, i.e. "MacOS 8.5.1". We treat DAVE like NT 4.0
70 * except for the cases that DAVE clients set 'watch tree' flag in notify
73 * Samba reports UNIX as its Native OS, which we can map to NT 4.0.
76 smbnative_os_value(const char *native_os
)
78 static smb_native_t os_table
[] = {
79 { NATIVE_OS_WINNT
, "Windows NT 4.0" },
80 { NATIVE_OS_WINNT
, "Windows NT" },
81 { NATIVE_OS_WIN95
, "Windows 4.0" },
82 { NATIVE_OS_WIN2000
, "Windows 5.0" },
83 { NATIVE_OS_WIN2000
, "Windows 5.1" },
84 { NATIVE_OS_WIN2000
, "Windows 2000" },
85 { NATIVE_OS_WIN2000
, "Windows 2002" },
86 { NATIVE_OS_WIN2000
, "Windows .NET" },
87 { NATIVE_OS_WIN2000
, "Windows Server" },
88 { NATIVE_OS_WIN2000
, "Windows XP" },
89 { NATIVE_OS_WINNT
, "UNIX" },
90 { NATIVE_OS_MACOS
, "MacOS" }
97 if (native_os
== NULL
)
98 return (NATIVE_OS_UNKNOWN
);
101 * Windows Vista sends an empty native OS string.
103 if (*native_os
== '\0')
104 return (NATIVE_OS_WIN2000
);
106 for (i
= 0; i
< sizeof (os_table
)/sizeof (os_table
[0]); ++i
) {
107 name
= os_table
[i
].sn_name
;
110 if (smb_strcasecmp(name
, native_os
, len
) == 0)
111 return (os_table
[i
].sn_value
);
114 return (NATIVE_OS_UNKNOWN
);
120 * Return the appropriate native LanMan value for the specified native
121 * LanMan name. There's an alignment problem in some packets from some
122 * clients that means we can miss the first character, so we do an
123 * additional check starting from the second character.
125 * Example LanMan values:
129 * Windows NT, Windows NT 4.0
130 * Windows 2000 LAN Manager
131 * Windows 2000, Windows 2000 5.0, Windows 2000 5.1
132 * Windows 2002, Windows 2002 5.1
133 * Windows .NET, Windows .NET 5.2
134 * Windows Server 2003
136 * NETSMB (Solaris CIFS client)
137 * DAVE (Thursby Software: CIFS for MacOS)
141 smbnative_lm_value(const char *native_lm
)
143 static smb_native_t lm_table
[] = {
144 { NATIVE_LM_NT
, "NT LAN Manager 4.0" },
145 { NATIVE_LM_NT
, "Windows NT" },
146 { NATIVE_LM_NT
, "Windows 4.0" },
147 { NATIVE_LM_NT
, "DAVE" }
155 * Windows Vista sends an empty native LM string.
157 if (native_lm
== NULL
|| *native_lm
== '\0')
158 return (NATIVE_LM_WIN2000
);
160 for (i
= 0; i
< sizeof (lm_table
)/sizeof (lm_table
[0]); ++i
) {
161 name
= lm_table
[i
].sn_name
;
164 if ((smb_strcasecmp(name
, native_lm
, len
) == 0) ||
165 (smb_strcasecmp(&name
[1], native_lm
, len
- 1) == 0)) {
166 return (lm_table
[i
].sn_value
);
170 return (NATIVE_LM_WIN2000
);
174 * smbnative_pdc_value
176 * This function is called when libsmbrdr connects to a PDC.
177 * The PDC type is derived from the Native LanMan string.
178 * The PDC value will default to PDC_WIN2000.
183 * Windows 4.0, Windows NT, Windows NT 4.0
184 * Windows 2000 LAN Manager
185 * Windows 2000, Windows 2000 5.0, Windows 2000 5.1
186 * Windows 2002, Windows 2002 5.1
187 * Windows .NET, Windows .NET 5.2
192 smbnative_pdc_value(const char *native_lm
)
194 static smb_native_t pdc_table
[] = {
195 { PDC_WINNT
, "NT LAN Manager 4.0" },
196 { PDC_WINNT
, "Windows NT 4.0" },
197 { PDC_WINNT
, "Windows NT" },
198 { PDC_WINNT
, "Windows 4.0" },
199 { PDC_WINNT
, "DAVE" },
200 { PDC_SAMBA
, "Samba" }
207 if (native_lm
== NULL
|| *native_lm
== '\0')
208 return (PDC_WIN2000
);
210 for (i
= 0; i
< sizeof (pdc_table
)/sizeof (pdc_table
[0]); ++i
) {
211 name
= pdc_table
[i
].sn_name
;
214 if ((smb_strcasecmp(name
, native_lm
, len
) == 0) ||
215 (smb_strcasecmp(&name
[1], native_lm
, len
- 1) == 0)) {
216 return (pdc_table
[i
].sn_value
);
220 return (PDC_WIN2000
);
224 * Returns the native OS string for the given OS version.
225 * If no match is found the string for Windows 2000 is returned.
228 smbnative_os_str(smb_version_t
*version
)
232 static smb_native_t osstr_table
[] = {
233 { SMB_MAJOR_NT
, "Windows NT" },
234 { SMB_MAJOR_2000
, "Windows 2000" },
235 { SMB_MAJOR_XP
, "Windows XP" },
236 { SMB_MAJOR_2003
, "Windows Server 2003" },
237 { SMB_MAJOR_VISTA
, "" },
238 { SMB_MAJOR_2008
, "" },
239 { SMB_MAJOR_2008R2
, "" }
242 for (i
= 0; i
< sizeof (osstr_table
)/sizeof (osstr_table
[0]); ++i
) {
243 if (version
->sv_major
== osstr_table
[i
].sn_value
)
244 return (osstr_table
[i
].sn_name
);
247 return (osstr_table
[1].sn_name
);
251 * Returns the native Lanman string for the given OS version.
252 * If no match is found the string for Windows 2000 is returned.
255 smbnative_lm_str(smb_version_t
*version
)
259 static smb_native_t lmstr_table
[] = {
260 { SMB_MAJOR_NT
, "NT LAN Manager 4.0" },
261 { SMB_MAJOR_2000
, "Windows 2000 LAN Manager" },
262 { SMB_MAJOR_XP
, "Windows 2002 5.1" },
263 { SMB_MAJOR_2003
, "Windows Server 2003 5.2" },
264 { SMB_MAJOR_VISTA
, "" },
265 { SMB_MAJOR_2008
, "" },
266 { SMB_MAJOR_2008R2
, "" }
269 for (i
= 0; i
< sizeof (lmstr_table
)/sizeof (lmstr_table
[0]); ++i
) {
270 if (version
->sv_major
== lmstr_table
[i
].sn_value
)
271 return (lmstr_table
[i
].sn_name
);
274 return (lmstr_table
[1].sn_name
);