blob: a8a083543ba050fa65cceee9a302c9b733f68311 [file] [log] [blame]
Steve French39798772006-05-31 22:40:51 +00001/*
2 * fs/cifs/sess.c
3 *
4 * SMB/CIFS session setup handling routines
5 *
6 * Copyright (c) International Business Machines Corp., 2006
7 * Author(s): Steve French (sfrench@us.ibm.com)
8 *
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "cifspdu.h"
25#include "cifsglob.h"
26#include "cifsproto.h"
27#include "cifs_unicode.h"
28#include "cifs_debug.h"
29#include "ntlmssp.h"
30#include "nterr.h"
Steve French9c535882006-06-01 05:09:10 +000031#include <linux/utsname.h>
Steve French39798772006-05-31 22:40:51 +000032
Steve French39798772006-05-31 22:40:51 +000033extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
34 unsigned char *p24);
35
Steve French39798772006-05-31 22:40:51 +000036static __u32 cifs_ssetup_hdr(struct cifsSesInfo *ses, SESSION_SETUP_ANDX *pSMB)
37{
38 __u32 capabilities = 0;
39
40 /* init fields common to all four types of SessSetup */
41 /* note that header is initialized to zero in header_assemble */
42 pSMB->req.AndXCommand = 0xFF;
43 pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
44 pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
45
46 /* Now no need to set SMBFLG_CASELESS or obsolete CANONICAL PATH */
47
48 /* BB verify whether signing required on neg or just on auth frame
49 (and NTLM case) */
50
51 capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
52 CAP_LARGE_WRITE_X | CAP_LARGE_READ_X;
53
54 if(ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
55 pSMB->req.hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
56
57 if (ses->capabilities & CAP_UNICODE) {
58 pSMB->req.hdr.Flags2 |= SMBFLG2_UNICODE;
59 capabilities |= CAP_UNICODE;
60 }
61 if (ses->capabilities & CAP_STATUS32) {
62 pSMB->req.hdr.Flags2 |= SMBFLG2_ERR_STATUS;
63 capabilities |= CAP_STATUS32;
64 }
65 if (ses->capabilities & CAP_DFS) {
66 pSMB->req.hdr.Flags2 |= SMBFLG2_DFS;
67 capabilities |= CAP_DFS;
68 }
69 if (ses->capabilities & CAP_UNIX) {
70 capabilities |= CAP_UNIX;
71 }
72
73 /* BB check whether to init vcnum BB */
74 return capabilities;
75}
76
Steve French7c7b25b2006-06-01 19:20:10 +000077static void unicode_ssetup_strings(char ** pbcc_area, struct cifsSesInfo *ses,
Steve French39798772006-05-31 22:40:51 +000078 const struct nls_table * nls_cp)
79{
80 char * bcc_ptr = *pbcc_area;
81 int bytes_ret = 0;
82
83 /* BB FIXME add check that strings total less
84 than 335 or will need to send them as arrays */
85
Steve French0223cf02006-06-27 19:50:57 +000086 /* unicode strings, must be word aligned before the call */
87/* if ((long) bcc_ptr % 2) {
Steve French39798772006-05-31 22:40:51 +000088 *bcc_ptr = 0;
89 bcc_ptr++;
Steve French0223cf02006-06-27 19:50:57 +000090 } */
Steve French39798772006-05-31 22:40:51 +000091 /* copy user */
92 if(ses->userName == NULL) {
93 /* BB what about null user mounts - check that we do this BB */
94 } else { /* 300 should be long enough for any conceivable user name */
95 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->userName,
96 300, nls_cp);
97 }
98 bcc_ptr += 2 * bytes_ret;
99 bcc_ptr += 2; /* account for null termination */
100 /* copy domain */
101 if(ses->domainName == NULL)
102 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr,
103 "CIFS_LINUX_DOM", 32, nls_cp);
104 else
105 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->domainName,
106 256, nls_cp);
107 bcc_ptr += 2 * bytes_ret;
108 bcc_ptr += 2; /* account for null terminator */
109
110 /* Copy OS version */
111 bytes_ret = cifs_strtoUCS((__le16 *)bcc_ptr, "Linux version ", 32,
112 nls_cp);
113 bcc_ptr += 2 * bytes_ret;
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700114 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, init_utsname()->release,
Steve French39798772006-05-31 22:40:51 +0000115 32, nls_cp);
116 bcc_ptr += 2 * bytes_ret;
117 bcc_ptr += 2; /* trailing null */
118
119 bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS,
120 32, nls_cp);
121 bcc_ptr += 2 * bytes_ret;
122 bcc_ptr += 2; /* trailing null */
123
124 *pbcc_area = bcc_ptr;
125}
126
Steve French7c7b25b2006-06-01 19:20:10 +0000127static void ascii_ssetup_strings(char ** pbcc_area, struct cifsSesInfo *ses,
Steve French39798772006-05-31 22:40:51 +0000128 const struct nls_table * nls_cp)
129{
130 char * bcc_ptr = *pbcc_area;
131
132 /* copy user */
133 /* BB what about null user mounts - check that we do this BB */
134 /* copy user */
135 if(ses->userName == NULL) {
136 /* BB what about null user mounts - check that we do this BB */
137 } else { /* 300 should be long enough for any conceivable user name */
138 strncpy(bcc_ptr, ses->userName, 300);
139 }
140 /* BB improve check for overflow */
Steve French750d1152006-06-27 06:28:30 +0000141 bcc_ptr += strnlen(ses->userName, 300);
Steve French39798772006-05-31 22:40:51 +0000142 *bcc_ptr = 0;
143 bcc_ptr++; /* account for null termination */
144
145 /* copy domain */
146
147 if(ses->domainName == NULL) {
148 strcpy(bcc_ptr, "CIFS_LINUX_DOM");
149 bcc_ptr += 14; /* strlen(CIFS_LINUX_DOM) */
150 } else {
151 strncpy(bcc_ptr, ses->domainName, 256);
152 bcc_ptr += strnlen(ses->domainName, 256);
153 }
154 *bcc_ptr = 0;
155 bcc_ptr++;
156
157 /* BB check for overflow here */
158
159 strcpy(bcc_ptr, "Linux version ");
160 bcc_ptr += strlen("Linux version ");
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700161 strcpy(bcc_ptr, init_utsname()->release);
162 bcc_ptr += strlen(init_utsname()->release) + 1;
Steve French39798772006-05-31 22:40:51 +0000163
164 strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
165 bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
166
167 *pbcc_area = bcc_ptr;
168}
169
Steve French7c7b25b2006-06-01 19:20:10 +0000170static int decode_unicode_ssetup(char ** pbcc_area, int bleft, struct cifsSesInfo *ses,
Steve French39798772006-05-31 22:40:51 +0000171 const struct nls_table * nls_cp)
172{
173 int rc = 0;
174 int words_left, len;
175 char * data = *pbcc_area;
176
177
178
179 cFYI(1,("bleft %d",bleft));
180
181
182 /* word align, if bytes remaining is not even */
183 if(bleft % 2) {
184 bleft--;
185 data++;
186 }
187 words_left = bleft / 2;
188
189 /* save off server operating system */
190 len = UniStrnlen((wchar_t *) data, words_left);
191
192/* We look for obvious messed up bcc or strings in response so we do not go off
193 the end since (at least) WIN2K and Windows XP have a major bug in not null
194 terminating last Unicode string in response */
195 if(len >= words_left)
196 return rc;
197
198 if(ses->serverOS)
199 kfree(ses->serverOS);
200 /* UTF-8 string will not grow more than four times as big as UCS-16 */
201 ses->serverOS = kzalloc(4 * len, GFP_KERNEL);
202 if(ses->serverOS != NULL) {
203 cifs_strfromUCS_le(ses->serverOS, (__le16 *)data, len,
204 nls_cp);
205 }
206 data += 2 * (len + 1);
207 words_left -= len + 1;
208
209 /* save off server network operating system */
210 len = UniStrnlen((wchar_t *) data, words_left);
211
212 if(len >= words_left)
213 return rc;
214
215 if(ses->serverNOS)
216 kfree(ses->serverNOS);
217 ses->serverNOS = kzalloc(4 * len, GFP_KERNEL); /* BB this is wrong length FIXME BB */
218 if(ses->serverNOS != NULL) {
219 cifs_strfromUCS_le(ses->serverNOS, (__le16 *)data, len,
220 nls_cp);
221 if(strncmp(ses->serverNOS, "NT LAN Manager 4",16) == 0) {
222 cFYI(1,("NT4 server"));
223 ses->flags |= CIFS_SES_NT4;
224 }
225 }
226 data += 2 * (len + 1);
227 words_left -= len + 1;
228
229 /* save off server domain */
230 len = UniStrnlen((wchar_t *) data, words_left);
231
232 if(len > words_left)
233 return rc;
234
235 if(ses->serverDomain)
236 kfree(ses->serverDomain);
237 ses->serverDomain = kzalloc(2 * (len + 1), GFP_KERNEL); /* BB FIXME wrong length */
238 if(ses->serverDomain != NULL) {
239 cifs_strfromUCS_le(ses->serverDomain, (__le16 *)data, len,
240 nls_cp);
241 ses->serverDomain[2*len] = 0;
242 ses->serverDomain[(2*len) + 1] = 0;
243 }
244 data += 2 * (len + 1);
245 words_left -= len + 1;
246
247 cFYI(1,("words left: %d",words_left));
248
249 return rc;
250}
251
Steve French7c7b25b2006-06-01 19:20:10 +0000252static int decode_ascii_ssetup(char ** pbcc_area, int bleft, struct cifsSesInfo *ses,
Steve French39798772006-05-31 22:40:51 +0000253 const struct nls_table * nls_cp)
254{
255 int rc = 0;
256 int len;
257 char * bcc_ptr = *pbcc_area;
258
259 cFYI(1,("decode sessetup ascii. bleft %d", bleft));
260
261 len = strnlen(bcc_ptr, bleft);
262 if(len >= bleft)
263 return rc;
264
265 if(ses->serverOS)
266 kfree(ses->serverOS);
267
268 ses->serverOS = kzalloc(len + 1, GFP_KERNEL);
269 if(ses->serverOS)
270 strncpy(ses->serverOS, bcc_ptr, len);
Steve French9ac00b72006-09-30 04:13:17 +0000271 if(strncmp(ses->serverOS, "OS/2",4) == 0) {
272 cFYI(1,("OS/2 server"));
273 ses->flags |= CIFS_SES_OS2;
274 }
Steve French39798772006-05-31 22:40:51 +0000275
276 bcc_ptr += len + 1;
277 bleft -= len + 1;
278
279 len = strnlen(bcc_ptr, bleft);
280 if(len >= bleft)
281 return rc;
282
283 if(ses->serverNOS)
284 kfree(ses->serverNOS);
285
286 ses->serverNOS = kzalloc(len + 1, GFP_KERNEL);
287 if(ses->serverNOS)
288 strncpy(ses->serverNOS, bcc_ptr, len);
289
290 bcc_ptr += len + 1;
291 bleft -= len + 1;
292
293 len = strnlen(bcc_ptr, bleft);
294 if(len > bleft)
295 return rc;
296
Steve French9ac00b72006-09-30 04:13:17 +0000297 /* No domain field in LANMAN case. Domain is
298 returned by old servers in the SMB negprot response */
299 /* BB For newer servers which do not support Unicode,
300 but thus do return domain here we could add parsing
301 for it later, but it is not very important */
Steve French39798772006-05-31 22:40:51 +0000302 cFYI(1,("ascii: bytes left %d",bleft));
303
304 return rc;
305}
306
307int
308CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
309 const struct nls_table *nls_cp)
310{
311 int rc = 0;
312 int wct;
Steve French39798772006-05-31 22:40:51 +0000313 struct smb_hdr *smb_buf;
314 char *bcc_ptr;
Steve French750d1152006-06-27 06:28:30 +0000315 char *str_area;
Steve French39798772006-05-31 22:40:51 +0000316 SESSION_SETUP_ANDX *pSMB;
317 __u32 capabilities;
318 int count;
319 int resp_buf_type = 0;
Steve French750d1152006-06-27 06:28:30 +0000320 struct kvec iov[2];
Steve French39798772006-05-31 22:40:51 +0000321 enum securityEnum type;
322 __u16 action;
323 int bytes_remaining;
Steve French254e55e2006-06-04 05:53:15 +0000324
Steve French39798772006-05-31 22:40:51 +0000325 if(ses == NULL)
326 return -EINVAL;
327
328 type = ses->server->secType;
Steve Frenchf40c5622006-06-28 00:13:38 +0000329
330 cFYI(1,("sess setup type %d",type));
Steve French39798772006-05-31 22:40:51 +0000331 if(type == LANMAN) {
332#ifndef CONFIG_CIFS_WEAK_PW_HASH
333 /* LANMAN and plaintext are less secure and off by default.
334 So we make this explicitly be turned on in kconfig (in the
335 build) and turned on at runtime (changed from the default)
336 in proc/fs/cifs or via mount parm. Unfortunately this is
337 needed for old Win (e.g. Win95), some obscure NAS and OS/2 */
338 return -EOPNOTSUPP;
339#endif
340 wct = 10; /* lanman 2 style sessionsetup */
Steve French9312f672006-06-04 22:21:07 +0000341 } else if((type == NTLM) || (type == NTLMv2)) {
342 /* For NTLMv2 failures eventually may need to retry NTLM */
Steve French39798772006-05-31 22:40:51 +0000343 wct = 13; /* old style NTLM sessionsetup */
Steve French9312f672006-06-04 22:21:07 +0000344 } else /* same size for negotiate or auth, NTLMSSP or extended security */
Steve French39798772006-05-31 22:40:51 +0000345 wct = 12;
346
347 rc = small_smb_init_no_tc(SMB_COM_SESSION_SETUP_ANDX, wct, ses,
348 (void **)&smb_buf);
349 if(rc)
350 return rc;
351
352 pSMB = (SESSION_SETUP_ANDX *)smb_buf;
353
354 capabilities = cifs_ssetup_hdr(ses, pSMB);
Steve French750d1152006-06-27 06:28:30 +0000355
356 /* we will send the SMB in two pieces,
357 a fixed length beginning part, and a
358 second part which will include the strings
359 and rest of bcc area, in order to avoid having
360 to do a large buffer 17K allocation */
361 iov[0].iov_base = (char *)pSMB;
362 iov[0].iov_len = smb_buf->smb_buf_length + 4;
363
364 /* 2000 big enough to fit max user, domain, NOS name etc. */
365 str_area = kmalloc(2000, GFP_KERNEL);
366 bcc_ptr = str_area;
Steve French39798772006-05-31 22:40:51 +0000367
Steve French9ac00b72006-09-30 04:13:17 +0000368 ses->flags &= ~CIFS_SES_LANMAN;
369
Steve French39798772006-05-31 22:40:51 +0000370 if(type == LANMAN) {
371#ifdef CONFIG_CIFS_WEAK_PW_HASH
Steve French7c7b25b2006-06-01 19:20:10 +0000372 char lnm_session_key[CIFS_SESS_KEY_SIZE];
Steve French39798772006-05-31 22:40:51 +0000373
374 /* no capabilities flags in old lanman negotiation */
375
Steve French5ddaa682006-08-15 13:35:48 +0000376 pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE);
Steve French39798772006-05-31 22:40:51 +0000377 /* BB calculate hash with password */
378 /* and copy into bcc */
379
Steve French7c7b25b2006-06-01 19:20:10 +0000380 calc_lanman_hash(ses, lnm_session_key);
Steve French9ac00b72006-09-30 04:13:17 +0000381 ses->flags |= CIFS_SES_LANMAN;
Steve French750d1152006-06-27 06:28:30 +0000382/* #ifdef CONFIG_CIFS_DEBUG2
Steve French39798772006-05-31 22:40:51 +0000383 cifs_dump_mem("cryptkey: ",ses->server->cryptKey,
Steve French7c7b25b2006-06-01 19:20:10 +0000384 CIFS_SESS_KEY_SIZE);
Steve French750d1152006-06-27 06:28:30 +0000385#endif */
Steve French7c7b25b2006-06-01 19:20:10 +0000386 memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_SESS_KEY_SIZE);
387 bcc_ptr += CIFS_SESS_KEY_SIZE;
Steve French39798772006-05-31 22:40:51 +0000388
389 /* can not sign if LANMAN negotiated so no need
390 to calculate signing key? but what if server
391 changed to do higher than lanman dialect and
392 we reconnected would we ever calc signing_key? */
393
Steve French750d1152006-06-27 06:28:30 +0000394 cFYI(1,("Negotiating LANMAN setting up strings"));
Steve French39798772006-05-31 22:40:51 +0000395 /* Unicode not allowed for LANMAN dialects */
396 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
397#endif
398 } else if (type == NTLM) {
Steve French7c7b25b2006-06-01 19:20:10 +0000399 char ntlm_session_key[CIFS_SESS_KEY_SIZE];
Steve French39798772006-05-31 22:40:51 +0000400
401 pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities);
402 pSMB->req_no_secext.CaseInsensitivePasswordLength =
Steve French7c7b25b2006-06-01 19:20:10 +0000403 cpu_to_le16(CIFS_SESS_KEY_SIZE);
Steve French39798772006-05-31 22:40:51 +0000404 pSMB->req_no_secext.CaseSensitivePasswordLength =
Steve French7c7b25b2006-06-01 19:20:10 +0000405 cpu_to_le16(CIFS_SESS_KEY_SIZE);
Steve French39798772006-05-31 22:40:51 +0000406
407 /* calculate session key */
408 SMBNTencrypt(ses->password, ses->server->cryptKey,
409 ntlm_session_key);
410
411 if(first_time) /* should this be moved into common code
412 with similar ntlmv2 path? */
Steve French750d1152006-06-27 06:28:30 +0000413 cifs_calculate_mac_key(ses->server->mac_signing_key,
Steve French39798772006-05-31 22:40:51 +0000414 ntlm_session_key, ses->password);
415 /* copy session key */
416
Steve French7c7b25b2006-06-01 19:20:10 +0000417 memcpy(bcc_ptr, (char *)ntlm_session_key,CIFS_SESS_KEY_SIZE);
418 bcc_ptr += CIFS_SESS_KEY_SIZE;
419 memcpy(bcc_ptr, (char *)ntlm_session_key,CIFS_SESS_KEY_SIZE);
420 bcc_ptr += CIFS_SESS_KEY_SIZE;
Steve French0223cf02006-06-27 19:50:57 +0000421 if(ses->capabilities & CAP_UNICODE) {
422 /* unicode strings must be word aligned */
423 if (iov[0].iov_len % 2) {
424 *bcc_ptr = 0;
425 bcc_ptr++;
426 }
Steve French7c7b25b2006-06-01 19:20:10 +0000427 unicode_ssetup_strings(&bcc_ptr, ses, nls_cp);
Steve French0223cf02006-06-27 19:50:57 +0000428 } else
Steve French7c7b25b2006-06-01 19:20:10 +0000429 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
430 } else if (type == NTLMv2) {
Steve French6d027cf2006-06-05 16:26:05 +0000431 char * v2_sess_key =
432 kmalloc(sizeof(struct ntlmv2_resp), GFP_KERNEL);
Steve Frenchf64b23a2006-06-05 05:27:37 +0000433
434 /* BB FIXME change all users of v2_sess_key to
435 struct ntlmv2_resp */
Steve French7c7b25b2006-06-01 19:20:10 +0000436
437 if(v2_sess_key == NULL) {
438 cifs_small_buf_release(smb_buf);
439 return -ENOMEM;
440 }
441
442 pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities);
443
444 /* LM2 password would be here if we supported it */
445 pSMB->req_no_secext.CaseInsensitivePasswordLength = 0;
446 /* cpu_to_le16(LM2_SESS_KEY_SIZE); */
447
448 pSMB->req_no_secext.CaseSensitivePasswordLength =
Steve Frenchf64b23a2006-06-05 05:27:37 +0000449 cpu_to_le16(sizeof(struct ntlmv2_resp));
Steve French7c7b25b2006-06-01 19:20:10 +0000450
451 /* calculate session key */
Steve French1717ffc2006-06-08 05:41:32 +0000452 setup_ntlmv2_rsp(ses, v2_sess_key, nls_cp);
Steve French7c7b25b2006-06-01 19:20:10 +0000453 if(first_time) /* should this be moved into common code
454 with similar ntlmv2 path? */
455 /* cifs_calculate_ntlmv2_mac_key(ses->server->mac_signing_key,
456 response BB FIXME, v2_sess_key); */
457
458 /* copy session key */
459
460 /* memcpy(bcc_ptr, (char *)ntlm_session_key,LM2_SESS_KEY_SIZE);
461 bcc_ptr += LM2_SESS_KEY_SIZE; */
Steve Frenchf64b23a2006-06-05 05:27:37 +0000462 memcpy(bcc_ptr, (char *)v2_sess_key, sizeof(struct ntlmv2_resp));
463 bcc_ptr += sizeof(struct ntlmv2_resp);
464 kfree(v2_sess_key);
Steve French0223cf02006-06-27 19:50:57 +0000465 if(ses->capabilities & CAP_UNICODE) {
466 if(iov[0].iov_len % 2) {
467 *bcc_ptr = 0;
468 } bcc_ptr++;
Steve French39798772006-05-31 22:40:51 +0000469 unicode_ssetup_strings(&bcc_ptr, ses, nls_cp);
Steve French0223cf02006-06-27 19:50:57 +0000470 } else
Steve French39798772006-05-31 22:40:51 +0000471 ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
472 } else /* NTLMSSP or SPNEGO */ {
473 pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
474 capabilities |= CAP_EXTENDED_SECURITY;
475 pSMB->req.Capabilities = cpu_to_le32(capabilities);
476 /* BB set password lengths */
477 }
478
Steve French750d1152006-06-27 06:28:30 +0000479 count = (long) bcc_ptr - (long) str_area;
Steve French39798772006-05-31 22:40:51 +0000480 smb_buf->smb_buf_length += count;
481
Steve French39798772006-05-31 22:40:51 +0000482 BCC_LE(smb_buf) = cpu_to_le16(count);
483
Steve French750d1152006-06-27 06:28:30 +0000484 iov[1].iov_base = str_area;
485 iov[1].iov_len = count;
486 rc = SendReceive2(xid, ses, iov, 2 /* num_iovecs */, &resp_buf_type, 0);
Steve French39798772006-05-31 22:40:51 +0000487 /* SMB request buf freed in SendReceive2 */
488
489 cFYI(1,("ssetup rc from sendrecv2 is %d",rc));
490 if(rc)
491 goto ssetup_exit;
492
493 pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base;
494 smb_buf = (struct smb_hdr *)iov[0].iov_base;
495
496 if((smb_buf->WordCount != 3) && (smb_buf->WordCount != 4)) {
497 rc = -EIO;
498 cERROR(1,("bad word count %d", smb_buf->WordCount));
499 goto ssetup_exit;
500 }
501 action = le16_to_cpu(pSMB->resp.Action);
502 if (action & GUEST_LOGIN)
Steve French189acaa2006-06-23 02:33:48 +0000503 cFYI(1, ("Guest login")); /* BB mark SesInfo struct? */
Steve French39798772006-05-31 22:40:51 +0000504 ses->Suid = smb_buf->Uid; /* UID left in wire format (le) */
505 cFYI(1, ("UID = %d ", ses->Suid));
506 /* response can have either 3 or 4 word count - Samba sends 3 */
507 /* and lanman response is 3 */
508 bytes_remaining = BCC(smb_buf);
509 bcc_ptr = pByteArea(smb_buf);
510
511 if(smb_buf->WordCount == 4) {
512 __u16 blob_len;
513 blob_len = le16_to_cpu(pSMB->resp.SecurityBlobLength);
514 bcc_ptr += blob_len;
515 if(blob_len > bytes_remaining) {
516 cERROR(1,("bad security blob length %d", blob_len));
517 rc = -EINVAL;
518 goto ssetup_exit;
519 }
520 bytes_remaining -= blob_len;
521 }
522
523 /* BB check if Unicode and decode strings */
524 if(smb_buf->Flags2 & SMBFLG2_UNICODE)
525 rc = decode_unicode_ssetup(&bcc_ptr, bytes_remaining,
526 ses, nls_cp);
527 else
528 rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,nls_cp);
529
530ssetup_exit:
Steve French750d1152006-06-27 06:28:30 +0000531 kfree(str_area);
Steve French39798772006-05-31 22:40:51 +0000532 if(resp_buf_type == CIFS_SMALL_BUFFER) {
533 cFYI(1,("ssetup freeing small buf %p", iov[0].iov_base));
534 cifs_small_buf_release(iov[0].iov_base);
535 } else if(resp_buf_type == CIFS_LARGE_BUFFER)
536 cifs_buf_release(iov[0].iov_base);
537
538 return rc;
539}