| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1 | /* | 
|  | 2 | *   fs/cifs/sess.c | 
|  | 3 | * | 
|  | 4 | *   SMB/CIFS session setup handling routines | 
|  | 5 | * | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 6 | *   Copyright (c) International Business Machines  Corp., 2006, 2007 | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 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 French | 9c53588 | 2006-06-01 05:09:10 +0000 | [diff] [blame] | 31 | #include <linux/utsname.h> | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 32 | #include "cifs_spnego.h" | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 33 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 34 | extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 35 | unsigned char *p24); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 36 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 37 | static __u32 cifs_ssetup_hdr(struct cifsSesInfo *ses, SESSION_SETUP_ANDX *pSMB) | 
|  | 38 | { | 
|  | 39 | __u32 capabilities = 0; | 
|  | 40 |  | 
|  | 41 | /* init fields common to all four types of SessSetup */ | 
|  | 42 | /* note that header is initialized to zero in header_assemble */ | 
|  | 43 | pSMB->req.AndXCommand = 0xFF; | 
|  | 44 | pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); | 
|  | 45 | pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); | 
|  | 46 |  | 
|  | 47 | /* Now no need to set SMBFLG_CASELESS or obsolete CANONICAL PATH */ | 
|  | 48 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 49 | /* BB verify whether signing required on neg or just on auth frame | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 50 | (and NTLM case) */ | 
|  | 51 |  | 
|  | 52 | capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | | 
|  | 53 | CAP_LARGE_WRITE_X | CAP_LARGE_READ_X; | 
|  | 54 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 55 | if (ses->server->secMode & | 
|  | 56 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 57 | pSMB->req.hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; | 
|  | 58 |  | 
|  | 59 | if (ses->capabilities & CAP_UNICODE) { | 
|  | 60 | pSMB->req.hdr.Flags2 |= SMBFLG2_UNICODE; | 
|  | 61 | capabilities |= CAP_UNICODE; | 
|  | 62 | } | 
|  | 63 | if (ses->capabilities & CAP_STATUS32) { | 
|  | 64 | pSMB->req.hdr.Flags2 |= SMBFLG2_ERR_STATUS; | 
|  | 65 | capabilities |= CAP_STATUS32; | 
|  | 66 | } | 
|  | 67 | if (ses->capabilities & CAP_DFS) { | 
|  | 68 | pSMB->req.hdr.Flags2 |= SMBFLG2_DFS; | 
|  | 69 | capabilities |= CAP_DFS; | 
|  | 70 | } | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 71 | if (ses->capabilities & CAP_UNIX) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 72 | capabilities |= CAP_UNIX; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 73 |  | 
|  | 74 | /* BB check whether to init vcnum BB */ | 
|  | 75 | return capabilities; | 
|  | 76 | } | 
|  | 77 |  | 
| Jeff Layton | 0d3a01f | 2007-10-16 17:32:19 +0000 | [diff] [blame] | 78 | static void | 
|  | 79 | unicode_oslm_strings(char **pbcc_area, const struct nls_table *nls_cp) | 
|  | 80 | { | 
|  | 81 | char *bcc_ptr = *pbcc_area; | 
|  | 82 | int bytes_ret = 0; | 
|  | 83 |  | 
|  | 84 | /* Copy OS version */ | 
|  | 85 | bytes_ret = cifs_strtoUCS((__le16 *)bcc_ptr, "Linux version ", 32, | 
|  | 86 | nls_cp); | 
|  | 87 | bcc_ptr += 2 * bytes_ret; | 
|  | 88 | bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, init_utsname()->release, | 
|  | 89 | 32, nls_cp); | 
|  | 90 | bcc_ptr += 2 * bytes_ret; | 
|  | 91 | bcc_ptr += 2; /* trailing null */ | 
|  | 92 |  | 
|  | 93 | bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS, | 
|  | 94 | 32, nls_cp); | 
|  | 95 | bcc_ptr += 2 * bytes_ret; | 
|  | 96 | bcc_ptr += 2; /* trailing null */ | 
|  | 97 |  | 
|  | 98 | *pbcc_area = bcc_ptr; | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | static void unicode_domain_string(char **pbcc_area, struct cifsSesInfo *ses, | 
|  | 102 | const struct nls_table *nls_cp) | 
|  | 103 | { | 
|  | 104 | char *bcc_ptr = *pbcc_area; | 
|  | 105 | int bytes_ret = 0; | 
|  | 106 |  | 
|  | 107 | /* copy domain */ | 
|  | 108 | if (ses->domainName == NULL) { | 
|  | 109 | /* Sending null domain better than using a bogus domain name (as | 
|  | 110 | we did briefly in 2.6.18) since server will use its default */ | 
|  | 111 | *bcc_ptr = 0; | 
|  | 112 | *(bcc_ptr+1) = 0; | 
|  | 113 | bytes_ret = 0; | 
|  | 114 | } else | 
|  | 115 | bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->domainName, | 
|  | 116 | 256, nls_cp); | 
|  | 117 | bcc_ptr += 2 * bytes_ret; | 
|  | 118 | bcc_ptr += 2;  /* account for null terminator */ | 
|  | 119 |  | 
|  | 120 | *pbcc_area = bcc_ptr; | 
|  | 121 | } | 
|  | 122 |  | 
|  | 123 |  | 
| Steve French | 3870253 | 2007-07-08 15:40:40 +0000 | [diff] [blame] | 124 | static void unicode_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses, | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 125 | const struct nls_table *nls_cp) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 126 | { | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 127 | char *bcc_ptr = *pbcc_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 128 | int bytes_ret = 0; | 
|  | 129 |  | 
|  | 130 | /* BB FIXME add check that strings total less | 
|  | 131 | than 335 or will need to send them as arrays */ | 
|  | 132 |  | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 133 | /* unicode strings, must be word aligned before the call */ | 
|  | 134 | /*	if ((long) bcc_ptr % 2)	{ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 135 | *bcc_ptr = 0; | 
|  | 136 | bcc_ptr++; | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 137 | } */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 138 | /* copy user */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 139 | if (ses->userName == NULL) { | 
| Steve French | 6e659c6 | 2006-11-08 23:10:46 +0000 | [diff] [blame] | 140 | /* null user mount */ | 
|  | 141 | *bcc_ptr = 0; | 
|  | 142 | *(bcc_ptr+1) = 0; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 143 | } else { /* 300 should be long enough for any conceivable user name */ | 
|  | 144 | bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->userName, | 
|  | 145 | 300, nls_cp); | 
|  | 146 | } | 
|  | 147 | bcc_ptr += 2 * bytes_ret; | 
|  | 148 | bcc_ptr += 2; /* account for null termination */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 149 |  | 
| Jeff Layton | 0d3a01f | 2007-10-16 17:32:19 +0000 | [diff] [blame] | 150 | unicode_domain_string(&bcc_ptr, ses, nls_cp); | 
|  | 151 | unicode_oslm_strings(&bcc_ptr, nls_cp); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 152 |  | 
|  | 153 | *pbcc_area = bcc_ptr; | 
|  | 154 | } | 
|  | 155 |  | 
| Steve French | 3870253 | 2007-07-08 15:40:40 +0000 | [diff] [blame] | 156 | static void ascii_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses, | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 157 | const struct nls_table *nls_cp) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 158 | { | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 159 | char *bcc_ptr = *pbcc_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 160 |  | 
|  | 161 | /* copy user */ | 
|  | 162 | /* BB what about null user mounts - check that we do this BB */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 163 | /* copy user */ | 
|  | 164 | if (ses->userName == NULL) { | 
|  | 165 | /* BB what about null user mounts - check that we do this BB */ | 
|  | 166 | } else { /* 300 should be long enough for any conceivable user name */ | 
|  | 167 | strncpy(bcc_ptr, ses->userName, 300); | 
|  | 168 | } | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 169 | /* BB improve check for overflow */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 170 | bcc_ptr += strnlen(ses->userName, 300); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 171 | *bcc_ptr = 0; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 172 | bcc_ptr++; /* account for null termination */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 173 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 174 | /* copy domain */ | 
|  | 175 |  | 
|  | 176 | if (ses->domainName != NULL) { | 
|  | 177 | strncpy(bcc_ptr, ses->domainName, 256); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 178 | bcc_ptr += strnlen(ses->domainName, 256); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 179 | } /* else we will send a null domain name | 
| Steve French | 6e659c6 | 2006-11-08 23:10:46 +0000 | [diff] [blame] | 180 | so the server will default to its own domain */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 181 | *bcc_ptr = 0; | 
|  | 182 | bcc_ptr++; | 
|  | 183 |  | 
|  | 184 | /* BB check for overflow here */ | 
|  | 185 |  | 
|  | 186 | strcpy(bcc_ptr, "Linux version "); | 
|  | 187 | bcc_ptr += strlen("Linux version "); | 
| Serge E. Hallyn | 96b644b | 2006-10-02 02:18:13 -0700 | [diff] [blame] | 188 | strcpy(bcc_ptr, init_utsname()->release); | 
|  | 189 | bcc_ptr += strlen(init_utsname()->release) + 1; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 190 |  | 
|  | 191 | strcpy(bcc_ptr, CIFS_NETWORK_OPSYS); | 
|  | 192 | bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1; | 
|  | 193 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 194 | *pbcc_area = bcc_ptr; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 197 | static int decode_unicode_ssetup(char **pbcc_area, int bleft, | 
|  | 198 | struct cifsSesInfo *ses, | 
|  | 199 | const struct nls_table *nls_cp) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 200 | { | 
|  | 201 | int rc = 0; | 
|  | 202 | int words_left, len; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 203 | char *data = *pbcc_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 204 |  | 
|  | 205 |  | 
|  | 206 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 207 | cFYI(1, ("bleft %d", bleft)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 208 |  | 
|  | 209 |  | 
| Steve French | 8e6f195 | 2007-01-22 01:19:30 +0000 | [diff] [blame] | 210 | /* SMB header is unaligned, so cifs servers word align start of | 
|  | 211 | Unicode strings */ | 
|  | 212 | data++; | 
|  | 213 | bleft--; /* Windows servers do not always double null terminate | 
|  | 214 | their final Unicode string - in which case we | 
|  | 215 | now will not attempt to decode the byte of junk | 
|  | 216 | which follows it */ | 
| Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 217 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 218 | words_left = bleft / 2; | 
|  | 219 |  | 
|  | 220 | /* save off server operating system */ | 
|  | 221 | len = UniStrnlen((wchar_t *) data, words_left); | 
|  | 222 |  | 
|  | 223 | /* We look for obvious messed up bcc or strings in response so we do not go off | 
|  | 224 | the end since (at least) WIN2K and Windows XP have a major bug in not null | 
|  | 225 | terminating last Unicode string in response  */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 226 | if (len >= words_left) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 227 | return rc; | 
|  | 228 |  | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 229 | kfree(ses->serverOS); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 230 | /* UTF-8 string will not grow more than four times as big as UCS-16 */ | 
|  | 231 | ses->serverOS = kzalloc(4 * len, GFP_KERNEL); | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 232 | if (ses->serverOS != NULL) | 
|  | 233 | cifs_strfromUCS_le(ses->serverOS, (__le16 *)data, len, nls_cp); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 234 | data += 2 * (len + 1); | 
|  | 235 | words_left -= len + 1; | 
|  | 236 |  | 
|  | 237 | /* save off server network operating system */ | 
|  | 238 | len = UniStrnlen((wchar_t *) data, words_left); | 
|  | 239 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 240 | if (len >= words_left) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 241 | return rc; | 
|  | 242 |  | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 243 | kfree(ses->serverNOS); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 244 | ses->serverNOS = kzalloc(4 * len, GFP_KERNEL); /* BB this is wrong length FIXME BB */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 245 | if (ses->serverNOS != NULL) { | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 246 | cifs_strfromUCS_le(ses->serverNOS, (__le16 *)data, len, | 
|  | 247 | nls_cp); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 248 | if (strncmp(ses->serverNOS, "NT LAN Manager 4", 16) == 0) { | 
|  | 249 | cFYI(1, ("NT4 server")); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 250 | ses->flags |= CIFS_SES_NT4; | 
|  | 251 | } | 
|  | 252 | } | 
|  | 253 | data += 2 * (len + 1); | 
|  | 254 | words_left -= len + 1; | 
|  | 255 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 256 | /* save off server domain */ | 
|  | 257 | len = UniStrnlen((wchar_t *) data, words_left); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 258 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 259 | if (len > words_left) | 
|  | 260 | return rc; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 261 |  | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 262 | kfree(ses->serverDomain); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 263 | ses->serverDomain = kzalloc(2 * (len + 1), GFP_KERNEL); /* BB FIXME wrong length */ | 
|  | 264 | if (ses->serverDomain != NULL) { | 
|  | 265 | cifs_strfromUCS_le(ses->serverDomain, (__le16 *)data, len, | 
|  | 266 | nls_cp); | 
|  | 267 | ses->serverDomain[2*len] = 0; | 
|  | 268 | ses->serverDomain[(2*len) + 1] = 0; | 
|  | 269 | } | 
|  | 270 | data += 2 * (len + 1); | 
|  | 271 | words_left -= len + 1; | 
|  | 272 |  | 
|  | 273 | cFYI(1, ("words left: %d", words_left)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 274 |  | 
|  | 275 | return rc; | 
|  | 276 | } | 
|  | 277 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 278 | static int decode_ascii_ssetup(char **pbcc_area, int bleft, | 
|  | 279 | struct cifsSesInfo *ses, | 
|  | 280 | const struct nls_table *nls_cp) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 281 | { | 
|  | 282 | int rc = 0; | 
|  | 283 | int len; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 284 | char *bcc_ptr = *pbcc_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 285 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 286 | cFYI(1, ("decode sessetup ascii. bleft %d", bleft)); | 
| Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 287 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 288 | len = strnlen(bcc_ptr, bleft); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 289 | if (len >= bleft) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 290 | return rc; | 
| Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 291 |  | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 292 | kfree(ses->serverOS); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 293 |  | 
|  | 294 | ses->serverOS = kzalloc(len + 1, GFP_KERNEL); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 295 | if (ses->serverOS) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 296 | strncpy(ses->serverOS, bcc_ptr, len); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 297 | if (strncmp(ses->serverOS, "OS/2", 4) == 0) { | 
|  | 298 | cFYI(1, ("OS/2 server")); | 
| Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 299 | ses->flags |= CIFS_SES_OS2; | 
|  | 300 | } | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 301 |  | 
|  | 302 | bcc_ptr += len + 1; | 
|  | 303 | bleft -= len + 1; | 
|  | 304 |  | 
|  | 305 | len = strnlen(bcc_ptr, bleft); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 306 | if (len >= bleft) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 307 | return rc; | 
|  | 308 |  | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 309 | kfree(ses->serverNOS); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 310 |  | 
|  | 311 | ses->serverNOS = kzalloc(len + 1, GFP_KERNEL); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 312 | if (ses->serverNOS) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 313 | strncpy(ses->serverNOS, bcc_ptr, len); | 
|  | 314 |  | 
|  | 315 | bcc_ptr += len + 1; | 
|  | 316 | bleft -= len + 1; | 
|  | 317 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 318 | len = strnlen(bcc_ptr, bleft); | 
|  | 319 | if (len > bleft) | 
|  | 320 | return rc; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 321 |  | 
| Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 322 | /* No domain field in LANMAN case. Domain is | 
|  | 323 | returned by old servers in the SMB negprot response */ | 
|  | 324 | /* BB For newer servers which do not support Unicode, | 
|  | 325 | but thus do return domain here we could add parsing | 
|  | 326 | for it later, but it is not very important */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 327 | cFYI(1, ("ascii: bytes left %d", bleft)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 328 |  | 
|  | 329 | return rc; | 
|  | 330 | } | 
|  | 331 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 332 | int | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 333 | CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time, | 
|  | 334 | const struct nls_table *nls_cp) | 
|  | 335 | { | 
|  | 336 | int rc = 0; | 
|  | 337 | int wct; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 338 | struct smb_hdr *smb_buf; | 
|  | 339 | char *bcc_ptr; | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 340 | char *str_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 341 | SESSION_SETUP_ANDX *pSMB; | 
|  | 342 | __u32 capabilities; | 
|  | 343 | int count; | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 344 | int resp_buf_type; | 
|  | 345 | struct kvec iov[3]; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 346 | enum securityEnum type; | 
|  | 347 | __u16 action; | 
|  | 348 | int bytes_remaining; | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 349 | struct key *spnego_key = NULL; | 
| Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 350 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 351 | if (ses == NULL) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 352 | return -EINVAL; | 
|  | 353 |  | 
|  | 354 | type = ses->server->secType; | 
| Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 355 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 356 | cFYI(1, ("sess setup type %d", type)); | 
|  | 357 | if (type == LANMAN) { | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 358 | #ifndef CONFIG_CIFS_WEAK_PW_HASH | 
|  | 359 | /* LANMAN and plaintext are less secure and off by default. | 
|  | 360 | So we make this explicitly be turned on in kconfig (in the | 
|  | 361 | build) and turned on at runtime (changed from the default) | 
|  | 362 | in proc/fs/cifs or via mount parm.  Unfortunately this is | 
|  | 363 | needed for old Win (e.g. Win95), some obscure NAS and OS/2 */ | 
|  | 364 | return -EOPNOTSUPP; | 
|  | 365 | #endif | 
|  | 366 | wct = 10; /* lanman 2 style sessionsetup */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 367 | } else if ((type == NTLM) || (type == NTLMv2)) { | 
| Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 368 | /* For NTLMv2 failures eventually may need to retry NTLM */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 369 | wct = 13; /* old style NTLM sessionsetup */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 370 | } else /* same size: negotiate or auth, NTLMSSP or extended security */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 371 | wct = 12; | 
|  | 372 |  | 
|  | 373 | rc = small_smb_init_no_tc(SMB_COM_SESSION_SETUP_ANDX, wct, ses, | 
|  | 374 | (void **)&smb_buf); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 375 | if (rc) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 376 | return rc; | 
|  | 377 |  | 
|  | 378 | pSMB = (SESSION_SETUP_ANDX *)smb_buf; | 
|  | 379 |  | 
|  | 380 | capabilities = cifs_ssetup_hdr(ses, pSMB); | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 381 |  | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 382 | /* we will send the SMB in three pieces: | 
|  | 383 | a fixed length beginning part, an optional | 
|  | 384 | SPNEGO blob (which can be zero length), and a | 
|  | 385 | last part which will include the strings | 
|  | 386 | and rest of bcc area. This allows us to avoid | 
|  | 387 | a large buffer 17K allocation */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 388 | iov[0].iov_base = (char *)pSMB; | 
|  | 389 | iov[0].iov_len = smb_buf->smb_buf_length + 4; | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 390 |  | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 391 | /* setting this here allows the code at the end of the function | 
|  | 392 | to free the request buffer if there's an error */ | 
|  | 393 | resp_buf_type = CIFS_SMALL_BUFFER; | 
|  | 394 |  | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 395 | /* 2000 big enough to fit max user, domain, NOS name etc. */ | 
|  | 396 | str_area = kmalloc(2000, GFP_KERNEL); | 
| Cyrill Gorcunov | 5e6e623 | 2007-08-18 00:15:20 +0000 | [diff] [blame] | 397 | if (str_area == NULL) { | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 398 | rc = -ENOMEM; | 
|  | 399 | goto ssetup_exit; | 
| Cyrill Gorcunov | 5e6e623 | 2007-08-18 00:15:20 +0000 | [diff] [blame] | 400 | } | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 401 | bcc_ptr = str_area; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 402 |  | 
| Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 403 | ses->flags &= ~CIFS_SES_LANMAN; | 
|  | 404 |  | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 405 | iov[1].iov_base = NULL; | 
|  | 406 | iov[1].iov_len = 0; | 
|  | 407 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 408 | if (type == LANMAN) { | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 409 | #ifdef CONFIG_CIFS_WEAK_PW_HASH | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 410 | char lnm_session_key[CIFS_SESS_KEY_SIZE]; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 411 |  | 
|  | 412 | /* no capabilities flags in old lanman negotiation */ | 
|  | 413 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 414 | pSMB->old_req.PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 415 | /* BB calculate hash with password */ | 
|  | 416 | /* and copy into bcc */ | 
|  | 417 |  | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 418 | calc_lanman_hash(ses, lnm_session_key); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 419 | ses->flags |= CIFS_SES_LANMAN; | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 420 | /* #ifdef CONFIG_CIFS_DEBUG2 | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 421 | cifs_dump_mem("cryptkey: ",ses->server->cryptKey, | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 422 | CIFS_SESS_KEY_SIZE); | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 423 | #endif */ | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 424 | memcpy(bcc_ptr, (char *)lnm_session_key, CIFS_SESS_KEY_SIZE); | 
|  | 425 | bcc_ptr += CIFS_SESS_KEY_SIZE; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 426 |  | 
|  | 427 | /* can not sign if LANMAN negotiated so no need | 
|  | 428 | to calculate signing key? but what if server | 
|  | 429 | changed to do higher than lanman dialect and | 
|  | 430 | we reconnected would we ever calc signing_key? */ | 
|  | 431 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 432 | cFYI(1, ("Negotiating LANMAN setting up strings")); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 433 | /* Unicode not allowed for LANMAN dialects */ | 
|  | 434 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 435 | #endif | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 436 | } else if (type == NTLM) { | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 437 | char ntlm_session_key[CIFS_SESS_KEY_SIZE]; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 438 |  | 
|  | 439 | pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities); | 
|  | 440 | pSMB->req_no_secext.CaseInsensitivePasswordLength = | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 441 | cpu_to_le16(CIFS_SESS_KEY_SIZE); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 442 | pSMB->req_no_secext.CaseSensitivePasswordLength = | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 443 | cpu_to_le16(CIFS_SESS_KEY_SIZE); | 
| Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 444 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 445 | /* calculate session key */ | 
|  | 446 | SMBNTencrypt(ses->password, ses->server->cryptKey, | 
|  | 447 | ntlm_session_key); | 
|  | 448 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 449 | if (first_time) /* should this be moved into common code | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 450 | with similar ntlmv2 path? */ | 
| Steve French | b609f06 | 2007-07-09 07:55:14 +0000 | [diff] [blame] | 451 | cifs_calculate_mac_key(&ses->server->mac_signing_key, | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 452 | ntlm_session_key, ses->password); | 
|  | 453 | /* copy session key */ | 
|  | 454 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 455 | memcpy(bcc_ptr, (char *)ntlm_session_key, CIFS_SESS_KEY_SIZE); | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 456 | bcc_ptr += CIFS_SESS_KEY_SIZE; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 457 | memcpy(bcc_ptr, (char *)ntlm_session_key, CIFS_SESS_KEY_SIZE); | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 458 | bcc_ptr += CIFS_SESS_KEY_SIZE; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 459 | if (ses->capabilities & CAP_UNICODE) { | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 460 | /* unicode strings must be word aligned */ | 
|  | 461 | if (iov[0].iov_len % 2) { | 
|  | 462 | *bcc_ptr = 0; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 463 | bcc_ptr++; | 
|  | 464 | } | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 465 | unicode_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 466 | } else | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 467 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
|  | 468 | } else if (type == NTLMv2) { | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 469 | char *v2_sess_key = | 
| Steve French | 6d027cf | 2006-06-05 16:26:05 +0000 | [diff] [blame] | 470 | kmalloc(sizeof(struct ntlmv2_resp), GFP_KERNEL); | 
| Steve French | f64b23a | 2006-06-05 05:27:37 +0000 | [diff] [blame] | 471 |  | 
|  | 472 | /* BB FIXME change all users of v2_sess_key to | 
|  | 473 | struct ntlmv2_resp */ | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 474 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 475 | if (v2_sess_key == NULL) { | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 476 | rc = -ENOMEM; | 
|  | 477 | goto ssetup_exit; | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 478 | } | 
|  | 479 |  | 
|  | 480 | pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities); | 
|  | 481 |  | 
|  | 482 | /* LM2 password would be here if we supported it */ | 
|  | 483 | pSMB->req_no_secext.CaseInsensitivePasswordLength = 0; | 
|  | 484 | /*	cpu_to_le16(LM2_SESS_KEY_SIZE); */ | 
|  | 485 |  | 
|  | 486 | pSMB->req_no_secext.CaseSensitivePasswordLength = | 
| Steve French | f64b23a | 2006-06-05 05:27:37 +0000 | [diff] [blame] | 487 | cpu_to_le16(sizeof(struct ntlmv2_resp)); | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 488 |  | 
|  | 489 | /* calculate session key */ | 
| Steve French | 1717ffc | 2006-06-08 05:41:32 +0000 | [diff] [blame] | 490 | setup_ntlmv2_rsp(ses, v2_sess_key, nls_cp); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 491 | if (first_time) /* should this be moved into common code | 
|  | 492 | with similar ntlmv2 path? */ | 
| Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 493 | /*   cifs_calculate_ntlmv2_mac_key(ses->server->mac_signing_key, | 
|  | 494 | response BB FIXME, v2_sess_key); */ | 
|  | 495 |  | 
|  | 496 | /* copy session key */ | 
|  | 497 |  | 
|  | 498 | /*	memcpy(bcc_ptr, (char *)ntlm_session_key,LM2_SESS_KEY_SIZE); | 
|  | 499 | bcc_ptr += LM2_SESS_KEY_SIZE; */ | 
| Steve French | 3870253 | 2007-07-08 15:40:40 +0000 | [diff] [blame] | 500 | memcpy(bcc_ptr, (char *)v2_sess_key, | 
|  | 501 | sizeof(struct ntlmv2_resp)); | 
| Steve French | f64b23a | 2006-06-05 05:27:37 +0000 | [diff] [blame] | 502 | bcc_ptr += sizeof(struct ntlmv2_resp); | 
|  | 503 | kfree(v2_sess_key); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 504 | if (ses->capabilities & CAP_UNICODE) { | 
|  | 505 | if (iov[0].iov_len % 2) { | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 506 | *bcc_ptr = 0; | 
| Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 507 | bcc_ptr++; | 
|  | 508 | } | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 509 | unicode_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
| Steve French | 0223cf0 | 2006-06-27 19:50:57 +0000 | [diff] [blame] | 510 | } else | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 511 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 512 | } else if (type == Kerberos) { | 
|  | 513 | #ifdef CONFIG_CIFS_UPCALL | 
|  | 514 | struct cifs_spnego_msg *msg; | 
|  | 515 | spnego_key = cifs_get_spnego_key(ses); | 
|  | 516 | if (IS_ERR(spnego_key)) { | 
|  | 517 | rc = PTR_ERR(spnego_key); | 
|  | 518 | spnego_key = NULL; | 
|  | 519 | goto ssetup_exit; | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 | msg = spnego_key->payload.data; | 
|  | 523 | /* bail out if key is too long */ | 
|  | 524 | if (msg->sesskey_len > | 
|  | 525 | sizeof(ses->server->mac_signing_key.data.krb5)) { | 
|  | 526 | cERROR(1, ("Kerberos signing key too long (%u bytes)", | 
|  | 527 | msg->sesskey_len)); | 
|  | 528 | rc = -EOVERFLOW; | 
|  | 529 | goto ssetup_exit; | 
|  | 530 | } | 
|  | 531 | ses->server->mac_signing_key.len = msg->sesskey_len; | 
|  | 532 | memcpy(ses->server->mac_signing_key.data.krb5, msg->data, | 
|  | 533 | msg->sesskey_len); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 534 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; | 
|  | 535 | capabilities |= CAP_EXTENDED_SECURITY; | 
|  | 536 | pSMB->req.Capabilities = cpu_to_le32(capabilities); | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 537 | iov[1].iov_base = msg->data + msg->sesskey_len; | 
|  | 538 | iov[1].iov_len = msg->secblob_len; | 
|  | 539 | pSMB->req.SecurityBlobLength = cpu_to_le16(iov[1].iov_len); | 
|  | 540 |  | 
|  | 541 | if (ses->capabilities & CAP_UNICODE) { | 
|  | 542 | /* unicode strings must be word aligned */ | 
|  | 543 | if (iov[0].iov_len % 2) { | 
|  | 544 | *bcc_ptr = 0; | 
|  | 545 | bcc_ptr++; | 
|  | 546 | } | 
|  | 547 | unicode_oslm_strings(&bcc_ptr, nls_cp); | 
|  | 548 | unicode_domain_string(&bcc_ptr, ses, nls_cp); | 
|  | 549 | } else | 
|  | 550 | /* BB: is this right? */ | 
|  | 551 | ascii_ssetup_strings(&bcc_ptr, ses, nls_cp); | 
|  | 552 | #else /* ! CONFIG_CIFS_UPCALL */ | 
|  | 553 | cERROR(1, ("Kerberos negotiated but upcall support disabled!")); | 
|  | 554 | rc = -ENOSYS; | 
|  | 555 | goto ssetup_exit; | 
|  | 556 | #endif /* CONFIG_CIFS_UPCALL */ | 
|  | 557 | } else { | 
|  | 558 | cERROR(1, ("secType %d not supported!", type)); | 
|  | 559 | rc = -ENOSYS; | 
|  | 560 | goto ssetup_exit; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 561 | } | 
|  | 562 |  | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 563 | iov[2].iov_base = str_area; | 
|  | 564 | iov[2].iov_len = (long) bcc_ptr - (long) str_area; | 
|  | 565 |  | 
|  | 566 | count = iov[1].iov_len + iov[2].iov_len; | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 567 | smb_buf->smb_buf_length += count; | 
|  | 568 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 569 | BCC_LE(smb_buf) = cpu_to_le16(count); | 
|  | 570 |  | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 571 | rc = SendReceive2(xid, ses, iov, 3 /* num_iovecs */, &resp_buf_type, | 
| Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 572 | CIFS_STD_OP /* not long */ | CIFS_LOG_ERROR); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 573 | /* SMB request buf freed in SendReceive2 */ | 
|  | 574 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 575 | cFYI(1, ("ssetup rc from sendrecv2 is %d", rc)); | 
|  | 576 | if (rc) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 577 | goto ssetup_exit; | 
|  | 578 |  | 
|  | 579 | pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base; | 
|  | 580 | smb_buf = (struct smb_hdr *)iov[0].iov_base; | 
|  | 581 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 582 | if ((smb_buf->WordCount != 3) && (smb_buf->WordCount != 4)) { | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 583 | rc = -EIO; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 584 | cERROR(1, ("bad word count %d", smb_buf->WordCount)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 585 | goto ssetup_exit; | 
|  | 586 | } | 
|  | 587 | action = le16_to_cpu(pSMB->resp.Action); | 
|  | 588 | if (action & GUEST_LOGIN) | 
| Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 589 | cFYI(1, ("Guest login")); /* BB mark SesInfo struct? */ | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 590 | ses->Suid = smb_buf->Uid;   /* UID left in wire format (le) */ | 
|  | 591 | cFYI(1, ("UID = %d ", ses->Suid)); | 
|  | 592 | /* response can have either 3 or 4 word count - Samba sends 3 */ | 
|  | 593 | /* and lanman response is 3 */ | 
|  | 594 | bytes_remaining = BCC(smb_buf); | 
|  | 595 | bcc_ptr = pByteArea(smb_buf); | 
|  | 596 |  | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 597 | if (smb_buf->WordCount == 4) { | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 598 | __u16 blob_len; | 
|  | 599 | blob_len = le16_to_cpu(pSMB->resp.SecurityBlobLength); | 
|  | 600 | bcc_ptr += blob_len; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 601 | if (blob_len > bytes_remaining) { | 
|  | 602 | cERROR(1, ("bad security blob length %d", blob_len)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 603 | rc = -EINVAL; | 
|  | 604 | goto ssetup_exit; | 
|  | 605 | } | 
|  | 606 | bytes_remaining -= blob_len; | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 607 | } | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 608 |  | 
|  | 609 | /* BB check if Unicode and decode strings */ | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 610 | if (smb_buf->Flags2 & SMBFLG2_UNICODE) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 611 | rc = decode_unicode_ssetup(&bcc_ptr, bytes_remaining, | 
|  | 612 | ses, nls_cp); | 
|  | 613 | else | 
| Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 614 | rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, | 
|  | 615 | ses, nls_cp); | 
| Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 616 |  | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 617 | ssetup_exit: | 
| Steve French | 2442421 | 2007-11-16 23:37:35 +0000 | [diff] [blame] | 618 | if (spnego_key) | 
|  | 619 | key_put(spnego_key); | 
| Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 620 | kfree(str_area); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 621 | if (resp_buf_type == CIFS_SMALL_BUFFER) { | 
|  | 622 | cFYI(1, ("ssetup freeing small buf %p", iov[0].iov_base)); | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 623 | cifs_small_buf_release(iov[0].iov_base); | 
| Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 624 | } else if (resp_buf_type == CIFS_LARGE_BUFFER) | 
| Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 625 | cifs_buf_release(iov[0].iov_base); | 
|  | 626 |  | 
|  | 627 | return rc; | 
|  | 628 | } |