Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/connect.c |
| 3 | * |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2007 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Lesser General Public License as published |
| 9 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 15 | * the GNU Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public License |
| 18 | * along with this library; if not, write to the Free Software |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | #include <linux/fs.h> |
| 22 | #include <linux/net.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/wait.h> |
| 26 | #include <linux/ipv6.h> |
| 27 | #include <linux/pagemap.h> |
| 28 | #include <linux/ctype.h> |
| 29 | #include <linux/utsname.h> |
| 30 | #include <linux/mempool.h> |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 32 | #include <linux/completion.h> |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 33 | #include <linux/kthread.h> |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 34 | #include <linux/pagevec.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 35 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/uaccess.h> |
| 37 | #include <asm/processor.h> |
| 38 | #include "cifspdu.h" |
| 39 | #include "cifsglob.h" |
| 40 | #include "cifsproto.h" |
| 41 | #include "cifs_unicode.h" |
| 42 | #include "cifs_debug.h" |
| 43 | #include "cifs_fs_sb.h" |
| 44 | #include "ntlmssp.h" |
| 45 | #include "nterr.h" |
| 46 | #include "rfc1002pdu.h" |
Steve French | a2653eb | 2005-11-10 15:33:38 -0800 | [diff] [blame] | 47 | #include "cn_cifs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #define CIFS_PORT 445 |
| 50 | #define RFC1001_PORT 139 |
| 51 | |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 52 | static DECLARE_COMPLETION(cifsd_complete); |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8, |
| 55 | unsigned char *p24); |
| 56 | |
| 57 | extern mempool_t *cifs_req_poolp; |
| 58 | |
| 59 | struct smb_vol { |
| 60 | char *username; |
| 61 | char *password; |
| 62 | char *domainname; |
| 63 | char *UNC; |
| 64 | char *UNCip; |
| 65 | char *in6_addr; /* ipv6 address as human readable form of in6_addr */ |
| 66 | char *iocharset; /* local code page for mapping to and from Unicode */ |
| 67 | char source_rfc1001_name[16]; /* netbios name of client */ |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 68 | char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | uid_t linux_uid; |
| 70 | gid_t linux_gid; |
| 71 | mode_t file_mode; |
| 72 | mode_t dir_mode; |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 73 | unsigned secFlg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | unsigned rw:1; |
| 75 | unsigned retry:1; |
| 76 | unsigned intr:1; |
| 77 | unsigned setuids:1; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 78 | unsigned override_uid:1; |
| 79 | unsigned override_gid:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | unsigned noperm:1; |
| 81 | unsigned no_psx_acl:1; /* set if posix acl support should be disabled */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 82 | unsigned cifs_acl:1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | unsigned no_xattr:1; /* set if xattr (EA) support should be disabled*/ |
| 84 | unsigned server_ino:1; /* use inode numbers from server ie UniqueId */ |
| 85 | unsigned direct_io:1; |
Steve French | 6a0b482 | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 86 | unsigned remap:1; /* set to remap seven reserved chars in filenames */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 87 | unsigned posix_paths:1; /* unset to not ask for posix pathnames. */ |
Steve French | d7245c2 | 2005-07-14 18:25:12 -0500 | [diff] [blame] | 88 | unsigned sfu_emul:1; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 89 | unsigned nullauth:1; /* attempt to authenticate with null user */ |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 90 | unsigned nocase; /* request case insensitive filenames */ |
| 91 | unsigned nobrl; /* disable sending byte range locks to srv */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | unsigned int rsize; |
| 93 | unsigned int wsize; |
| 94 | unsigned int sockopt; |
| 95 | unsigned short int port; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 96 | char *prepath; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | }; |
| 98 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 99 | static int ipv4_connect(struct sockaddr_in *psin_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | struct socket **csocket, |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 101 | char *netb_name, |
| 102 | char *server_netb_name); |
| 103 | static int ipv6_connect(struct sockaddr_in6 *psin_server, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | struct socket **csocket); |
| 105 | |
| 106 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 107 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * cifs tcp session reconnection |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 109 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | * mark tcp session as reconnecting so temporarily locked |
| 111 | * mark all smb sessions as reconnecting for tcp session |
| 112 | * reconnect tcp session |
| 113 | * wake up waiters on reconnection? - (not needed currently) |
| 114 | */ |
| 115 | |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 116 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | cifs_reconnect(struct TCP_Server_Info *server) |
| 118 | { |
| 119 | int rc = 0; |
| 120 | struct list_head *tmp; |
| 121 | struct cifsSesInfo *ses; |
| 122 | struct cifsTconInfo *tcon; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 123 | struct mid_q_entry *mid_entry; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | spin_lock(&GlobalMid_Lock); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 126 | if ( kthread_should_stop() ) { |
| 127 | /* the demux thread will exit normally |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | next time through the loop */ |
| 129 | spin_unlock(&GlobalMid_Lock); |
| 130 | return rc; |
| 131 | } else |
| 132 | server->tcpStatus = CifsNeedReconnect; |
| 133 | spin_unlock(&GlobalMid_Lock); |
| 134 | server->maxBuf = 0; |
| 135 | |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 136 | cFYI(1, ("Reconnecting tcp session")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* before reconnecting the tcp session, mark the smb session (uid) |
| 139 | and the tid bad so they are not used until reconnected */ |
| 140 | read_lock(&GlobalSMBSeslock); |
| 141 | list_for_each(tmp, &GlobalSMBSessionList) { |
| 142 | ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList); |
| 143 | if (ses->server) { |
| 144 | if (ses->server == server) { |
| 145 | ses->status = CifsNeedReconnect; |
| 146 | ses->ipc_tid = 0; |
| 147 | } |
| 148 | } |
| 149 | /* else tcp and smb sessions need reconnection */ |
| 150 | } |
| 151 | list_for_each(tmp, &GlobalTreeConnectionList) { |
| 152 | tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 153 | if ((tcon) && (tcon->ses) && (tcon->ses->server == server)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | tcon->tidStatus = CifsNeedReconnect; |
| 155 | } |
| 156 | } |
| 157 | read_unlock(&GlobalSMBSeslock); |
| 158 | /* do not want to be sending data on a socket we are freeing */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 159 | down(&server->tcpSem); |
| 160 | if (server->ssocket) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 161 | cFYI(1, ("State: 0x%x Flags: 0x%lx", server->ssocket->state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | server->ssocket->flags)); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 163 | server->ssocket->ops->shutdown(server->ssocket, SEND_SHUTDOWN); |
| 164 | cFYI(1, ("Post shutdown state: 0x%x Flags: 0x%lx", |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 165 | server->ssocket->state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | server->ssocket->flags)); |
| 167 | sock_release(server->ssocket); |
| 168 | server->ssocket = NULL; |
| 169 | } |
| 170 | |
| 171 | spin_lock(&GlobalMid_Lock); |
| 172 | list_for_each(tmp, &server->pending_mid_q) { |
| 173 | mid_entry = list_entry(tmp, struct |
| 174 | mid_q_entry, |
| 175 | qhead); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 176 | if (mid_entry) { |
| 177 | if (mid_entry->midState == MID_REQUEST_SUBMITTED) { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 178 | /* Mark other intransit requests as needing |
| 179 | retry so we do not immediately mark the |
| 180 | session bad again (ie after we reconnect |
| 181 | below) as they timeout too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | mid_entry->midState = MID_RETRY_NEEDED; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | spin_unlock(&GlobalMid_Lock); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 187 | up(&server->tcpSem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 189 | while ( (!kthread_should_stop()) && (server->tcpStatus != CifsGood)) { |
Steve French | 6c3d890 | 2006-07-31 22:46:20 +0000 | [diff] [blame] | 190 | try_to_freeze(); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 191 | if (server->protocolType == IPV6) { |
| 192 | rc = ipv6_connect(&server->addr.sockAddr6, |
| 193 | &server->ssocket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | } else { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 195 | rc = ipv4_connect(&server->addr.sockAddr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | &server->ssocket, |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 197 | server->workstation_RFC1001_name, |
| 198 | server->server_RFC1001_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 200 | if (rc) { |
| 201 | cFYI(1, ("reconnect error %d", rc)); |
Steve French | 0cb766a | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 202 | msleep(3000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } else { |
| 204 | atomic_inc(&tcpSesReconnectCount); |
| 205 | spin_lock(&GlobalMid_Lock); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 206 | if ( !kthread_should_stop() ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | server->tcpStatus = CifsGood; |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 208 | server->sequence_number = 0; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 209 | spin_unlock(&GlobalMid_Lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | /* atomic_set(&server->inFlight,0);*/ |
| 211 | wake_up(&server->response_q); |
| 212 | } |
| 213 | } |
| 214 | return rc; |
| 215 | } |
| 216 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 217 | /* |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 218 | return codes: |
| 219 | 0 not a transact2, or all data present |
| 220 | >0 transact2 with that much data missing |
| 221 | -EINVAL = invalid transact2 |
| 222 | |
| 223 | */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 224 | static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 225 | { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 226 | struct smb_t2_rsp *pSMBt; |
| 227 | int total_data_size; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 228 | int data_in_this_rsp; |
| 229 | int remaining; |
| 230 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 231 | if (pSMB->Command != SMB_COM_TRANSACTION2) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 232 | return 0; |
| 233 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 234 | /* check for plausible wct, bcc and t2 data and parm sizes */ |
| 235 | /* check for parm and data offset going beyond end of smb */ |
| 236 | if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */ |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 237 | cFYI(1, ("invalid transact2 word count")); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 238 | return -EINVAL; |
| 239 | } |
| 240 | |
| 241 | pSMBt = (struct smb_t2_rsp *)pSMB; |
| 242 | |
| 243 | total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); |
| 244 | data_in_this_rsp = le16_to_cpu(pSMBt->t2_rsp.DataCount); |
| 245 | |
| 246 | remaining = total_data_size - data_in_this_rsp; |
| 247 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 248 | if (remaining == 0) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 249 | return 0; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 250 | else if (remaining < 0) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 251 | cFYI(1, ("total data %d smaller than data in frame %d", |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 252 | total_data_size, data_in_this_rsp)); |
| 253 | return -EINVAL; |
| 254 | } else { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 255 | cFYI(1, ("missing %d bytes from transact2, check next response", |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 256 | remaining)); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 257 | if (total_data_size > maxBufSize) { |
| 258 | cERROR(1, ("TotalDataSize %d is over maximum buffer %d", |
| 259 | total_data_size, maxBufSize)); |
| 260 | return -EINVAL; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 261 | } |
| 262 | return remaining; |
| 263 | } |
| 264 | } |
| 265 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 266 | static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 267 | { |
| 268 | struct smb_t2_rsp *pSMB2 = (struct smb_t2_rsp *)psecond; |
| 269 | struct smb_t2_rsp *pSMBt = (struct smb_t2_rsp *)pTargetSMB; |
| 270 | int total_data_size; |
| 271 | int total_in_buf; |
| 272 | int remaining; |
| 273 | int total_in_buf2; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 274 | char *data_area_of_target; |
| 275 | char *data_area_of_buf2; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 276 | __u16 byte_count; |
| 277 | |
| 278 | total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount); |
| 279 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 280 | if (total_data_size != le16_to_cpu(pSMB2->t2_rsp.TotalDataCount)) { |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 281 | cFYI(1, ("total data size of primary and secondary t2 differ")); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount); |
| 285 | |
| 286 | remaining = total_data_size - total_in_buf; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 287 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 288 | if (remaining < 0) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 289 | return -EINVAL; |
| 290 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 291 | if (remaining == 0) /* nothing to do, ignore */ |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 292 | return 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 293 | |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 294 | total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 295 | if (remaining < total_in_buf2) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 296 | cFYI(1, ("transact2 2nd response contains too much data")); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | /* find end of first SMB data area */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 300 | data_area_of_target = (char *)&pSMBt->hdr.Protocol + |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 301 | le16_to_cpu(pSMBt->t2_rsp.DataOffset); |
| 302 | /* validate target area */ |
| 303 | |
| 304 | data_area_of_buf2 = (char *) &pSMB2->hdr.Protocol + |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 305 | le16_to_cpu(pSMB2->t2_rsp.DataOffset); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 306 | |
| 307 | data_area_of_target += total_in_buf; |
| 308 | |
| 309 | /* copy second buffer into end of first buffer */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 310 | memcpy(data_area_of_target, data_area_of_buf2, total_in_buf2); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 311 | total_in_buf += total_in_buf2; |
| 312 | pSMBt->t2_rsp.DataCount = cpu_to_le16(total_in_buf); |
| 313 | byte_count = le16_to_cpu(BCC_LE(pTargetSMB)); |
| 314 | byte_count += total_in_buf2; |
| 315 | BCC_LE(pTargetSMB) = cpu_to_le16(byte_count); |
| 316 | |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 317 | byte_count = pTargetSMB->smb_buf_length; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 318 | byte_count += total_in_buf2; |
| 319 | |
| 320 | /* BB also add check that we are not beyond maximum buffer size */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 321 | |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 322 | pTargetSMB->smb_buf_length = byte_count; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 323 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 324 | if (remaining == total_in_buf2) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 325 | cFYI(1, ("found the last secondary response")); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 326 | return 0; /* we are done */ |
| 327 | } else /* more responses to go */ |
| 328 | return 1; |
| 329 | |
| 330 | } |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | static int |
| 333 | cifs_demultiplex_thread(struct TCP_Server_Info *server) |
| 334 | { |
| 335 | int length; |
| 336 | unsigned int pdu_length, total_read; |
| 337 | struct smb_hdr *smb_buffer = NULL; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 338 | struct smb_hdr *bigbuf = NULL; |
| 339 | struct smb_hdr *smallbuf = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | struct msghdr smb_msg; |
| 341 | struct kvec iov; |
| 342 | struct socket *csocket = server->ssocket; |
| 343 | struct list_head *tmp; |
| 344 | struct cifsSesInfo *ses; |
| 345 | struct task_struct *task_to_wake = NULL; |
| 346 | struct mid_q_entry *mid_entry; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 347 | char temp; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 348 | int isLargeBuf = FALSE; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 349 | int isMultiRsp; |
| 350 | int reconnect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | current->flags |= PF_MEMALLOC; |
| 353 | server->tsk = current; /* save process info to wake at shutdown */ |
| 354 | cFYI(1, ("Demultiplex PID: %d", current->pid)); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 355 | write_lock(&GlobalSMBSeslock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | atomic_inc(&tcpSesAllocCount); |
| 357 | length = tcpSesAllocCount.counter; |
| 358 | write_unlock(&GlobalSMBSeslock); |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 359 | complete(&cifsd_complete); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 360 | if (length > 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | mempool_resize(cifs_req_poolp, |
| 362 | length + cifs_min_rcv, |
| 363 | GFP_KERNEL); |
| 364 | } |
| 365 | |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 366 | while (!kthread_should_stop()) { |
Steve French | ede1327 | 2005-08-30 20:10:14 -0700 | [diff] [blame] | 367 | if (try_to_freeze()) |
| 368 | continue; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 369 | if (bigbuf == NULL) { |
| 370 | bigbuf = cifs_buf_get(); |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 371 | if (!bigbuf) { |
| 372 | cERROR(1, ("No memory for large SMB response")); |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 373 | msleep(3000); |
| 374 | /* retry will check if exiting */ |
| 375 | continue; |
| 376 | } |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 377 | } else if (isLargeBuf) { |
| 378 | /* we are reusing a dirty large buf, clear its start */ |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 379 | memset(bigbuf, 0, sizeof (struct smb_hdr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | } |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 381 | |
| 382 | if (smallbuf == NULL) { |
| 383 | smallbuf = cifs_small_buf_get(); |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 384 | if (!smallbuf) { |
| 385 | cERROR(1, ("No memory for SMB response")); |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 386 | msleep(1000); |
| 387 | /* retry will check if exiting */ |
| 388 | continue; |
| 389 | } |
| 390 | /* beginning of smb buffer is cleared in our buf_get */ |
| 391 | } else /* if existing small buf clear beginning */ |
| 392 | memset(smallbuf, 0, sizeof (struct smb_hdr)); |
| 393 | |
| 394 | isLargeBuf = FALSE; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 395 | isMultiRsp = FALSE; |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 396 | smb_buffer = smallbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | iov.iov_base = smb_buffer; |
| 398 | iov.iov_len = 4; |
| 399 | smb_msg.msg_control = NULL; |
| 400 | smb_msg.msg_controllen = 0; |
| 401 | length = |
| 402 | kernel_recvmsg(csocket, &smb_msg, |
| 403 | &iov, 1, 4, 0 /* BB see socket.h flags */); |
| 404 | |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 405 | if ( kthread_should_stop() ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | break; |
| 407 | } else if (server->tcpStatus == CifsNeedReconnect) { |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 408 | cFYI(1, ("Reconnect after server stopped responding")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | cifs_reconnect(server); |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 410 | cFYI(1, ("call to reconnect done")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | csocket = server->ssocket; |
| 412 | continue; |
| 413 | } else if ((length == -ERESTARTSYS) || (length == -EAGAIN)) { |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 414 | msleep(1); /* minimum sleep to prevent looping |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | allowing socket to clear and app threads to set |
| 416 | tcpStatus CifsNeedReconnect if server hung */ |
| 417 | continue; |
| 418 | } else if (length <= 0) { |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 419 | if (server->tcpStatus == CifsNew) { |
| 420 | cFYI(1, ("tcp session abend after SMBnegprot")); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 421 | /* some servers kill the TCP session rather than |
| 422 | returning an SMB negprot error, in which |
| 423 | case reconnecting here is not going to help, |
| 424 | and so simply return error to mount */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | break; |
| 426 | } |
Pavel Machek | 0fd1ffe | 2006-06-13 21:31:39 +0000 | [diff] [blame] | 427 | if (!try_to_freeze() && (length == -EINTR)) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 428 | cFYI(1, ("cifsd thread killed")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | break; |
| 430 | } |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 431 | cFYI(1, ("Reconnect after unexpected peek error %d", |
Steve French | 57337e4 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 432 | length)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | cifs_reconnect(server); |
| 434 | csocket = server->ssocket; |
| 435 | wake_up(&server->response_q); |
| 436 | continue; |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 437 | } else if (length < 4) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | cFYI(1, |
Steve French | 57337e4 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 439 | ("Frame under four bytes received (%d bytes long)", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | length)); |
| 441 | cifs_reconnect(server); |
| 442 | csocket = server->ssocket; |
| 443 | wake_up(&server->response_q); |
| 444 | continue; |
| 445 | } |
Steve French | 67010fb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 446 | |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 447 | /* The right amount was read from socket - 4 bytes */ |
| 448 | /* so we can now interpret the length field */ |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 449 | |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 450 | /* the first byte big endian of the length field, |
| 451 | is actually not part of the length but the type |
| 452 | with the most common, zero, as regular data */ |
| 453 | temp = *((char *) smb_buffer); |
| 454 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 455 | /* Note that FC 1001 length is big endian on the wire, |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 456 | but we convert it here so it is always manipulated |
| 457 | as host byte order */ |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 458 | pdu_length = ntohl(smb_buffer->smb_buf_length); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 459 | smb_buffer->smb_buf_length = pdu_length; |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 460 | |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 461 | cFYI(1, ("rfc1002 length 0x%x", pdu_length+4)); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 462 | |
| 463 | if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 464 | continue; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 465 | } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 466 | cFYI(1, ("Good RFC 1002 session rsp")); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 467 | continue; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 468 | } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 469 | /* we get this from Windows 98 instead of |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 470 | an error on SMB negprot response */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 471 | cFYI(1, ("Negative RFC1002 Session Response Error 0x%x)", |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 472 | pdu_length)); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 473 | if (server->tcpStatus == CifsNew) { |
| 474 | /* if nack on negprot (rather than |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 475 | ret of smb negprot error) reconnecting |
| 476 | not going to help, ret error to mount */ |
| 477 | break; |
| 478 | } else { |
| 479 | /* give server a second to |
| 480 | clean up before reconnect attempt */ |
| 481 | msleep(1000); |
| 482 | /* always try 445 first on reconnect |
| 483 | since we get NACK on some if we ever |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 484 | connected to port 139 (the NACK is |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 485 | since we do not begin with RFC1001 |
| 486 | session initialize frame) */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 487 | server->addr.sockAddr.sin_port = |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 488 | htons(CIFS_PORT); |
| 489 | cifs_reconnect(server); |
| 490 | csocket = server->ssocket; |
| 491 | wake_up(&server->response_q); |
| 492 | continue; |
| 493 | } |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 494 | } else if (temp != (char) 0) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 495 | cERROR(1, ("Unknown RFC 1002 frame")); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 496 | cifs_dump_mem(" Received Data: ", (char *)smb_buffer, |
| 497 | length); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 498 | cifs_reconnect(server); |
| 499 | csocket = server->ssocket; |
| 500 | continue; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* else we have an SMB response */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 504 | if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) || |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 505 | (pdu_length < sizeof (struct smb_hdr) - 1 - 4)) { |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 506 | cERROR(1, ("Invalid size SMB length %d pdu_length %d", |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 507 | length, pdu_length+4)); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 508 | cifs_reconnect(server); |
| 509 | csocket = server->ssocket; |
| 510 | wake_up(&server->response_q); |
| 511 | continue; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 512 | } |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 513 | |
| 514 | /* else length ok */ |
| 515 | reconnect = 0; |
| 516 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 517 | if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 518 | isLargeBuf = TRUE; |
| 519 | memcpy(bigbuf, smallbuf, 4); |
| 520 | smb_buffer = bigbuf; |
| 521 | } |
| 522 | length = 0; |
| 523 | iov.iov_base = 4 + (char *)smb_buffer; |
| 524 | iov.iov_len = pdu_length; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 525 | for (total_read = 0; total_read < pdu_length; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 526 | total_read += length) { |
| 527 | length = kernel_recvmsg(csocket, &smb_msg, &iov, 1, |
| 528 | pdu_length - total_read, 0); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 529 | if ( kthread_should_stop() || |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 530 | (length == -EINTR)) { |
| 531 | /* then will exit */ |
| 532 | reconnect = 2; |
| 533 | break; |
| 534 | } else if (server->tcpStatus == CifsNeedReconnect) { |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 535 | cifs_reconnect(server); |
| 536 | csocket = server->ssocket; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 537 | /* Reconnect wakes up rspns q */ |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 538 | /* Now we will reread sock */ |
| 539 | reconnect = 1; |
| 540 | break; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 541 | } else if ((length == -ERESTARTSYS) || |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 542 | (length == -EAGAIN)) { |
| 543 | msleep(1); /* minimum sleep to prevent looping, |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 544 | allowing socket to clear and app |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 545 | threads to set tcpStatus |
| 546 | CifsNeedReconnect if server hung*/ |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 547 | continue; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 548 | } else if (length <= 0) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 549 | cERROR(1, ("Received no data, expecting %d", |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 550 | pdu_length - total_read)); |
| 551 | cifs_reconnect(server); |
| 552 | csocket = server->ssocket; |
| 553 | reconnect = 1; |
| 554 | break; |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 557 | if (reconnect == 2) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 558 | break; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 559 | else if (reconnect == 1) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 560 | continue; |
| 561 | |
| 562 | length += 4; /* account for rfc1002 hdr */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 563 | |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 564 | |
| 565 | dump_smb(smb_buffer, length); |
Steve French | 184ed21 | 2006-02-24 06:15:11 +0000 | [diff] [blame] | 566 | if (checkSMB(smb_buffer, smb_buffer->Mid, total_read+4)) { |
Steve French | b387eae | 2005-10-10 14:21:15 -0700 | [diff] [blame] | 567 | cifs_dump_mem("Bad SMB: ", smb_buffer, 48); |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 568 | continue; |
| 569 | } |
| 570 | |
| 571 | |
| 572 | task_to_wake = NULL; |
| 573 | spin_lock(&GlobalMid_Lock); |
| 574 | list_for_each(tmp, &server->pending_mid_q) { |
| 575 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
| 576 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 577 | if ((mid_entry->mid == smb_buffer->Mid) && |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 578 | (mid_entry->midState == MID_REQUEST_SUBMITTED) && |
| 579 | (mid_entry->command == smb_buffer->Command)) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 580 | if (check2ndT2(smb_buffer,server->maxBuf) > 0) { |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 581 | /* We have a multipart transact2 resp */ |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 582 | isMultiRsp = TRUE; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 583 | if (mid_entry->resp_buf) { |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 584 | /* merge response - fix up 1st*/ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 585 | if (coalesce_t2(smb_buffer, |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 586 | mid_entry->resp_buf)) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 587 | mid_entry->multiRsp = 1; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 588 | break; |
| 589 | } else { |
| 590 | /* all parts received */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 591 | mid_entry->multiEnd = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 592 | goto multi_t2_fnd; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 593 | } |
| 594 | } else { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 595 | if (!isLargeBuf) { |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 596 | cERROR(1,("1st trans2 resp needs bigbuf")); |
| 597 | /* BB maybe we can fix this up, switch |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 598 | to already allocated large buffer? */ |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 599 | } else { |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 600 | /* Have first buffer */ |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 601 | mid_entry->resp_buf = |
| 602 | smb_buffer; |
| 603 | mid_entry->largeBuf = 1; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 604 | bigbuf = NULL; |
| 605 | } |
| 606 | } |
| 607 | break; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 608 | } |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 609 | mid_entry->resp_buf = smb_buffer; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 610 | if (isLargeBuf) |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 611 | mid_entry->largeBuf = 1; |
| 612 | else |
| 613 | mid_entry->largeBuf = 0; |
| 614 | multi_t2_fnd: |
| 615 | task_to_wake = mid_entry->tsk; |
| 616 | mid_entry->midState = MID_RESPONSE_RECEIVED; |
Steve French | 1047abc | 2005-10-11 19:58:06 -0700 | [diff] [blame] | 617 | #ifdef CONFIG_CIFS_STATS2 |
| 618 | mid_entry->when_received = jiffies; |
| 619 | #endif |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 620 | /* so we do not time out requests to server |
| 621 | which is still responding (since server could |
| 622 | be busy but not dead) */ |
| 623 | server->lstrp = jiffies; |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 624 | break; |
| 625 | } |
| 626 | } |
| 627 | spin_unlock(&GlobalMid_Lock); |
| 628 | if (task_to_wake) { |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 629 | /* Was previous buf put in mpx struct for multi-rsp? */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 630 | if (!isMultiRsp) { |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 631 | /* smb buffer will be freed by user thread */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 632 | if (isLargeBuf) { |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 633 | bigbuf = NULL; |
| 634 | } else |
| 635 | smallbuf = NULL; |
| 636 | } |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 637 | wake_up_process(task_to_wake); |
Steve French | d7c8c94 | 2006-03-03 10:43:49 +0000 | [diff] [blame] | 638 | } else if ((is_valid_oplock_break(smb_buffer, server) == FALSE) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 639 | && (isMultiRsp == FALSE)) { |
| 640 | cERROR(1, ("No task to wake, unknown frame received! " |
| 641 | "NumMids %d", midCount.counter)); |
| 642 | cifs_dump_mem("Received Data is: ", (char *)smb_buffer, |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 643 | sizeof(struct smb_hdr)); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 644 | #ifdef CONFIG_CIFS_DEBUG2 |
| 645 | cifs_dump_detail(smb_buffer); |
| 646 | cifs_dump_mids(server); |
| 647 | #endif /* CIFS_DEBUG2 */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 648 | |
Steve French | e4eb295 | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 649 | } |
| 650 | } /* end while !EXITING */ |
| 651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | spin_lock(&GlobalMid_Lock); |
| 653 | server->tcpStatus = CifsExiting; |
| 654 | server->tsk = NULL; |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 655 | /* check if we have blocked requests that need to free */ |
| 656 | /* Note that cifs_max_pending is normally 50, but |
| 657 | can be set at module install time to as little as two */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 658 | if (atomic_read(&server->inFlight) >= cifs_max_pending) |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 659 | atomic_set(&server->inFlight, cifs_max_pending - 1); |
| 660 | /* We do not want to set the max_pending too low or we |
| 661 | could end up with the counter going negative */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | spin_unlock(&GlobalMid_Lock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 663 | /* Although there should not be any requests blocked on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | this queue it can not hurt to be paranoid and try to wake up requests |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 665 | that may haven been blocked when more than 50 at time were on the wire |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | to the same server - they now will see the session is in exit state |
| 667 | and get out of SendReceive. */ |
| 668 | wake_up_all(&server->request_q); |
| 669 | /* give those requests time to exit */ |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 670 | msleep(125); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 671 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 672 | if (server->ssocket) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | sock_release(csocket); |
| 674 | server->ssocket = NULL; |
| 675 | } |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 676 | /* buffer usuallly freed in free_mid - need to free it here on exit */ |
| 677 | if (bigbuf != NULL) |
| 678 | cifs_buf_release(bigbuf); |
| 679 | if (smallbuf != NULL) |
| 680 | cifs_small_buf_release(smallbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
| 682 | read_lock(&GlobalSMBSeslock); |
| 683 | if (list_empty(&server->pending_mid_q)) { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 684 | /* loop through server session structures attached to this and |
| 685 | mark them dead */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | list_for_each(tmp, &GlobalSMBSessionList) { |
| 687 | ses = |
| 688 | list_entry(tmp, struct cifsSesInfo, |
| 689 | cifsSessionList); |
| 690 | if (ses->server == server) { |
| 691 | ses->status = CifsExiting; |
| 692 | ses->server = NULL; |
| 693 | } |
| 694 | } |
| 695 | read_unlock(&GlobalSMBSeslock); |
| 696 | } else { |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 697 | /* although we can not zero the server struct pointer yet, |
| 698 | since there are active requests which may depnd on them, |
| 699 | mark the corresponding SMB sessions as exiting too */ |
| 700 | list_for_each(tmp, &GlobalSMBSessionList) { |
| 701 | ses = list_entry(tmp, struct cifsSesInfo, |
| 702 | cifsSessionList); |
| 703 | if (ses->server == server) { |
| 704 | ses->status = CifsExiting; |
| 705 | } |
| 706 | } |
| 707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | spin_lock(&GlobalMid_Lock); |
| 709 | list_for_each(tmp, &server->pending_mid_q) { |
| 710 | mid_entry = list_entry(tmp, struct mid_q_entry, qhead); |
| 711 | if (mid_entry->midState == MID_REQUEST_SUBMITTED) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 712 | cFYI(1, ("Clearing Mid 0x%x - waking up ", |
| 713 | mid_entry->mid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | task_to_wake = mid_entry->tsk; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 715 | if (task_to_wake) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | wake_up_process(task_to_wake); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | spin_unlock(&GlobalMid_Lock); |
| 721 | read_unlock(&GlobalSMBSeslock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | /* 1/8th of sec is more than enough time for them to exit */ |
Steve French | b8643e1 | 2005-04-28 22:41:07 -0700 | [diff] [blame] | 723 | msleep(125); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | } |
| 725 | |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 726 | if (!list_empty(&server->pending_mid_q)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 727 | /* mpx threads have not exited yet give them |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | at least the smb send timeout time for long ops */ |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 729 | /* due to delays on oplock break requests, we need |
| 730 | to wait at least 45 seconds before giving up |
| 731 | on a request getting a response and going ahead |
| 732 | and killing cifsd */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | cFYI(1, ("Wait for exit from demultiplex thread")); |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 734 | msleep(46000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | /* if threads still have not exited they are probably never |
| 736 | coming home not much else we can do but free the memory */ |
| 737 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | write_lock(&GlobalSMBSeslock); |
| 740 | atomic_dec(&tcpSesAllocCount); |
| 741 | length = tcpSesAllocCount.counter; |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 742 | |
| 743 | /* last chance to mark ses pointers invalid |
| 744 | if there are any pointing to this (e.g |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 745 | if a crazy root user tried to kill cifsd |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 746 | kernel thread explicitly this might happen) */ |
| 747 | list_for_each(tmp, &GlobalSMBSessionList) { |
| 748 | ses = list_entry(tmp, struct cifsSesInfo, |
| 749 | cifsSessionList); |
| 750 | if (ses->server == server) { |
| 751 | ses->server = NULL; |
| 752 | } |
| 753 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | write_unlock(&GlobalSMBSeslock); |
Steve French | 31ca3bc | 2005-04-28 22:41:11 -0700 | [diff] [blame] | 755 | |
| 756 | kfree(server); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 757 | if (length > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | mempool_resize(cifs_req_poolp, |
| 759 | length + cifs_min_rcv, |
| 760 | GFP_KERNEL); |
| 761 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | static int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 767 | cifs_parse_mount_options(char *options, const char *devname, |
| 768 | struct smb_vol *vol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | { |
| 770 | char *value; |
| 771 | char *data; |
| 772 | unsigned int temp_len, i, j; |
| 773 | char separator[2]; |
| 774 | |
| 775 | separator[0] = ','; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 776 | separator[1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Linus Torvalds | 12e36b2 | 2006-10-13 08:09:29 -0700 | [diff] [blame] | 778 | if (Local_System_Name[0] != 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 779 | memcpy(vol->source_rfc1001_name, Local_System_Name, 15); |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 780 | else { |
Linus Torvalds | 12e36b2 | 2006-10-13 08:09:29 -0700 | [diff] [blame] | 781 | char *nodename = utsname()->nodename; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 782 | int n = strnlen(nodename, 15); |
| 783 | memset(vol->source_rfc1001_name, 0x20, 15); |
| 784 | for (i = 0; i < n; i++) { |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 785 | /* does not have to be perfect mapping since field is |
| 786 | informational, only used for servers that do not support |
| 787 | port 445 and it can be overridden at mount time */ |
Linus Torvalds | 12e36b2 | 2006-10-13 08:09:29 -0700 | [diff] [blame] | 788 | vol->source_rfc1001_name[i] = toupper(nodename[i]); |
Steve French | 2cd646a | 2006-09-28 19:43:08 +0000 | [diff] [blame] | 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | vol->source_rfc1001_name[15] = 0; |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 792 | /* null target name indicates to use *SMBSERVR default called name |
| 793 | if we end up sending RFC1001 session initialize */ |
| 794 | vol->target_rfc1001_name[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | vol->linux_uid = current->uid; /* current->euid instead? */ |
| 796 | vol->linux_gid = current->gid; |
| 797 | vol->dir_mode = S_IRWXUGO; |
| 798 | /* 2767 perms indicate mandatory locking support */ |
| 799 | vol->file_mode = S_IALLUGO & ~(S_ISUID | S_IXGRP); |
| 800 | |
| 801 | /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */ |
| 802 | vol->rw = TRUE; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 803 | /* default is always to request posix paths. */ |
| 804 | vol->posix_paths = 1; |
| 805 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | if (!options) |
| 807 | return 1; |
| 808 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 809 | if (strncmp(options, "sep=", 4) == 0) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 810 | if (options[4] != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | separator[0] = options[4]; |
| 812 | options += 5; |
| 813 | } else { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 814 | cFYI(1, ("Null separator not allowed")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | while ((data = strsep(&options, separator)) != NULL) { |
| 819 | if (!*data) |
| 820 | continue; |
| 821 | if ((value = strchr(data, '=')) != NULL) |
| 822 | *value++ = '\0'; |
| 823 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 824 | /* Have to parse this before we parse for "user" */ |
| 825 | if (strnicmp(data, "user_xattr", 10) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | vol->no_xattr = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 827 | } else if (strnicmp(data, "nouser_xattr", 12) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | vol->no_xattr = 1; |
| 829 | } else if (strnicmp(data, "user", 4) == 0) { |
Steve French | 4b952a9 | 2006-10-30 21:46:13 +0000 | [diff] [blame] | 830 | if (!value) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | printk(KERN_WARNING |
| 832 | "CIFS: invalid or missing username\n"); |
| 833 | return 1; /* needs_arg; */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 834 | } else if (!*value) { |
Steve French | 4b952a9 | 2006-10-30 21:46:13 +0000 | [diff] [blame] | 835 | /* null user, ie anonymous, authentication */ |
| 836 | vol->nullauth = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } |
| 838 | if (strnlen(value, 200) < 200) { |
| 839 | vol->username = value; |
| 840 | } else { |
| 841 | printk(KERN_WARNING "CIFS: username too long\n"); |
| 842 | return 1; |
| 843 | } |
| 844 | } else if (strnicmp(data, "pass", 4) == 0) { |
| 845 | if (!value) { |
| 846 | vol->password = NULL; |
| 847 | continue; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 848 | } else if (value[0] == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | /* check if string begins with double comma |
| 850 | since that would mean the password really |
| 851 | does start with a comma, and would not |
| 852 | indicate an empty string */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 853 | if (value[1] != separator[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | vol->password = NULL; |
| 855 | continue; |
| 856 | } |
| 857 | } |
| 858 | temp_len = strlen(value); |
| 859 | /* removed password length check, NTLM passwords |
| 860 | can be arbitrarily long */ |
| 861 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 862 | /* if comma in password, the string will be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | prematurely null terminated. Commas in password are |
| 864 | specified across the cifs mount interface by a double |
| 865 | comma ie ,, and a comma used as in other cases ie ',' |
| 866 | as a parameter delimiter/separator is single and due |
| 867 | to the strsep above is temporarily zeroed. */ |
| 868 | |
| 869 | /* NB: password legally can have multiple commas and |
| 870 | the only illegal character in a password is null */ |
| 871 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 872 | if ((value[temp_len] == 0) && |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 873 | (value[temp_len+1] == separator[0])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | /* reinsert comma */ |
| 875 | value[temp_len] = separator[0]; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 876 | temp_len += 2; /* move after second comma */ |
| 877 | while (value[temp_len] != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | if (value[temp_len] == separator[0]) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 879 | if (value[temp_len+1] == |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 880 | separator[0]) { |
| 881 | /* skip second comma */ |
| 882 | temp_len++; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 883 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | /* single comma indicating start |
| 885 | of next parm */ |
| 886 | break; |
| 887 | } |
| 888 | } |
| 889 | temp_len++; |
| 890 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 891 | if (value[temp_len] == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | options = NULL; |
| 893 | } else { |
| 894 | value[temp_len] = 0; |
| 895 | /* point option to start of next parm */ |
| 896 | options = value + temp_len + 1; |
| 897 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 898 | /* go from value to value + temp_len condensing |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | double commas to singles. Note that this ends up |
| 900 | allocating a few bytes too many, which is ok */ |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 901 | vol->password = kzalloc(temp_len, GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 902 | if (vol->password == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 903 | printk(KERN_WARNING "CIFS: no memory " |
| 904 | "for password\n"); |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 905 | return 1; |
| 906 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 907 | for (i = 0, j = 0; i < temp_len; i++, j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | vol->password[j] = value[i]; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 909 | if (value[i] == separator[0] |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 910 | && value[i+1] == separator[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /* skip second comma */ |
| 912 | i++; |
| 913 | } |
| 914 | } |
| 915 | vol->password[j] = 0; |
| 916 | } else { |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 917 | vol->password = kzalloc(temp_len+1, GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 918 | if (vol->password == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 919 | printk(KERN_WARNING "CIFS: no memory " |
| 920 | "for password\n"); |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 921 | return 1; |
| 922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | strcpy(vol->password, value); |
| 924 | } |
| 925 | } else if (strnicmp(data, "ip", 2) == 0) { |
| 926 | if (!value || !*value) { |
| 927 | vol->UNCip = NULL; |
| 928 | } else if (strnlen(value, 35) < 35) { |
| 929 | vol->UNCip = value; |
| 930 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 931 | printk(KERN_WARNING "CIFS: ip address " |
| 932 | "too long\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | return 1; |
| 934 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 935 | } else if (strnicmp(data, "sec", 3) == 0) { |
| 936 | if (!value || !*value) { |
| 937 | cERROR(1, ("no security value specified")); |
| 938 | continue; |
| 939 | } else if (strnicmp(value, "krb5i", 5) == 0) { |
| 940 | vol->secFlg |= CIFSSEC_MAY_KRB5 | |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 941 | CIFSSEC_MUST_SIGN; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 942 | } else if (strnicmp(value, "krb5p", 5) == 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 943 | /* vol->secFlg |= CIFSSEC_MUST_SEAL | |
| 944 | CIFSSEC_MAY_KRB5; */ |
| 945 | cERROR(1, ("Krb5 cifs privacy not supported")); |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 946 | return 1; |
| 947 | } else if (strnicmp(value, "krb5", 4) == 0) { |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 948 | vol->secFlg |= CIFSSEC_MAY_KRB5; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 949 | } else if (strnicmp(value, "ntlmv2i", 7) == 0) { |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 950 | vol->secFlg |= CIFSSEC_MAY_NTLMV2 | |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 951 | CIFSSEC_MUST_SIGN; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 952 | } else if (strnicmp(value, "ntlmv2", 6) == 0) { |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 953 | vol->secFlg |= CIFSSEC_MAY_NTLMV2; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 954 | } else if (strnicmp(value, "ntlmi", 5) == 0) { |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 955 | vol->secFlg |= CIFSSEC_MAY_NTLM | |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 956 | CIFSSEC_MUST_SIGN; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 957 | } else if (strnicmp(value, "ntlm", 4) == 0) { |
| 958 | /* ntlm is default so can be turned off too */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 959 | vol->secFlg |= CIFSSEC_MAY_NTLM; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 960 | } else if (strnicmp(value, "nontlm", 6) == 0) { |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 961 | /* BB is there a better way to do this? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 962 | vol->secFlg |= CIFSSEC_MAY_NTLMV2; |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 963 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 964 | } else if (strnicmp(value, "lanman", 6) == 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 965 | vol->secFlg |= CIFSSEC_MAY_LANMAN; |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 966 | #endif |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 967 | } else if (strnicmp(value, "none", 4) == 0) { |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 968 | vol->nullauth = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 969 | } else { |
| 970 | cERROR(1, ("bad security option: %s", value)); |
| 971 | return 1; |
| 972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } else if ((strnicmp(data, "unc", 3) == 0) |
| 974 | || (strnicmp(data, "target", 6) == 0) |
| 975 | || (strnicmp(data, "path", 4) == 0)) { |
| 976 | if (!value || !*value) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 977 | printk(KERN_WARNING "CIFS: invalid path to " |
| 978 | "network resource\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return 1; /* needs_arg; */ |
| 980 | } |
| 981 | if ((temp_len = strnlen(value, 300)) < 300) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 982 | vol->UNC = kmalloc(temp_len+1, GFP_KERNEL); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 983 | if (vol->UNC == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | return 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 985 | strcpy(vol->UNC, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | if (strncmp(vol->UNC, "//", 2) == 0) { |
| 987 | vol->UNC[0] = '\\'; |
| 988 | vol->UNC[1] = '\\'; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 989 | } else if (strncmp(vol->UNC, "\\\\", 2) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | printk(KERN_WARNING |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 991 | "CIFS: UNC Path does not begin " |
| 992 | "with // or \\\\ \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | return 1; |
| 994 | } |
| 995 | } else { |
| 996 | printk(KERN_WARNING "CIFS: UNC name too long\n"); |
| 997 | return 1; |
| 998 | } |
| 999 | } else if ((strnicmp(data, "domain", 3) == 0) |
| 1000 | || (strnicmp(data, "workgroup", 5) == 0)) { |
| 1001 | if (!value || !*value) { |
| 1002 | printk(KERN_WARNING "CIFS: invalid domain name\n"); |
| 1003 | return 1; /* needs_arg; */ |
| 1004 | } |
| 1005 | /* BB are there cases in which a comma can be valid in |
| 1006 | a domain name and need special handling? */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1007 | if (strnlen(value, 256) < 256) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | vol->domainname = value; |
| 1009 | cFYI(1, ("Domain name set")); |
| 1010 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1011 | printk(KERN_WARNING "CIFS: domain name too " |
| 1012 | "long\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | return 1; |
| 1014 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1015 | } else if (strnicmp(data, "prefixpath", 10) == 0) { |
| 1016 | if (!value || !*value) { |
| 1017 | printk(KERN_WARNING |
| 1018 | "CIFS: invalid path prefix\n"); |
| 1019 | return 1; /* needs_argument */ |
| 1020 | } |
| 1021 | if ((temp_len = strnlen(value, 1024)) < 1024) { |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1022 | if (value[0] != '/') |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1023 | temp_len++; /* missing leading slash */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1024 | vol->prepath = kmalloc(temp_len+1, GFP_KERNEL); |
| 1025 | if (vol->prepath == NULL) |
| 1026 | return 1; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1027 | if (value[0] != '/') { |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1028 | vol->prepath[0] = '/'; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1029 | strcpy(vol->prepath+1, value); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1030 | } else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1031 | strcpy(vol->prepath, value); |
| 1032 | cFYI(1, ("prefix path %s", vol->prepath)); |
| 1033 | } else { |
| 1034 | printk(KERN_WARNING "CIFS: prefix too long\n"); |
| 1035 | return 1; |
| 1036 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | } else if (strnicmp(data, "iocharset", 9) == 0) { |
| 1038 | if (!value || !*value) { |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 1039 | printk(KERN_WARNING "CIFS: invalid iocharset " |
| 1040 | "specified\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | return 1; /* needs_arg; */ |
| 1042 | } |
| 1043 | if (strnlen(value, 65) < 65) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1044 | if (strnicmp(value, "default", 7)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | vol->iocharset = value; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1046 | /* if iocharset not set then load_nls_default |
| 1047 | is used by caller */ |
| 1048 | cFYI(1, ("iocharset set to %s", value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } else { |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 1050 | printk(KERN_WARNING "CIFS: iocharset name " |
| 1051 | "too long.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | return 1; |
| 1053 | } |
| 1054 | } else if (strnicmp(data, "uid", 3) == 0) { |
| 1055 | if (value && *value) { |
| 1056 | vol->linux_uid = |
| 1057 | simple_strtoul(value, &value, 0); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1058 | vol->override_uid = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | } else if (strnicmp(data, "gid", 3) == 0) { |
| 1061 | if (value && *value) { |
| 1062 | vol->linux_gid = |
| 1063 | simple_strtoul(value, &value, 0); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1064 | vol->override_gid = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | } |
| 1066 | } else if (strnicmp(data, "file_mode", 4) == 0) { |
| 1067 | if (value && *value) { |
| 1068 | vol->file_mode = |
| 1069 | simple_strtoul(value, &value, 0); |
| 1070 | } |
| 1071 | } else if (strnicmp(data, "dir_mode", 4) == 0) { |
| 1072 | if (value && *value) { |
| 1073 | vol->dir_mode = |
| 1074 | simple_strtoul(value, &value, 0); |
| 1075 | } |
| 1076 | } else if (strnicmp(data, "dirmode", 4) == 0) { |
| 1077 | if (value && *value) { |
| 1078 | vol->dir_mode = |
| 1079 | simple_strtoul(value, &value, 0); |
| 1080 | } |
| 1081 | } else if (strnicmp(data, "port", 4) == 0) { |
| 1082 | if (value && *value) { |
| 1083 | vol->port = |
| 1084 | simple_strtoul(value, &value, 0); |
| 1085 | } |
| 1086 | } else if (strnicmp(data, "rsize", 5) == 0) { |
| 1087 | if (value && *value) { |
| 1088 | vol->rsize = |
| 1089 | simple_strtoul(value, &value, 0); |
| 1090 | } |
| 1091 | } else if (strnicmp(data, "wsize", 5) == 0) { |
| 1092 | if (value && *value) { |
| 1093 | vol->wsize = |
| 1094 | simple_strtoul(value, &value, 0); |
| 1095 | } |
| 1096 | } else if (strnicmp(data, "sockopt", 5) == 0) { |
| 1097 | if (value && *value) { |
| 1098 | vol->sockopt = |
| 1099 | simple_strtoul(value, &value, 0); |
| 1100 | } |
| 1101 | } else if (strnicmp(data, "netbiosname", 4) == 0) { |
| 1102 | if (!value || !*value || (*value == ' ')) { |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 1103 | cFYI(1, ("invalid (empty) netbiosname")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1105 | memset(vol->source_rfc1001_name, 0x20, 15); |
| 1106 | for (i = 0; i < 15; i++) { |
| 1107 | /* BB are there cases in which a comma can be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | valid in this workstation netbios name (and need |
| 1109 | special handling)? */ |
| 1110 | |
| 1111 | /* We do not uppercase netbiosname for user */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1112 | if (value[i] == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | break; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1114 | else |
| 1115 | vol->source_rfc1001_name[i] = |
| 1116 | value[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | } |
| 1118 | /* The string has 16th byte zero still from |
| 1119 | set at top of the function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1120 | if ((i == 15) && (value[i] != 0)) |
| 1121 | printk(KERN_WARNING "CIFS: netbiosname" |
| 1122 | " longer than 15 truncated.\n"); |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1123 | } |
| 1124 | } else if (strnicmp(data, "servern", 7) == 0) { |
| 1125 | /* servernetbiosname specified override *SMBSERVER */ |
| 1126 | if (!value || !*value || (*value == ' ')) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 1127 | cFYI(1, ("empty server netbiosname specified")); |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1128 | } else { |
| 1129 | /* last byte, type, is 0x20 for servr type */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1130 | memset(vol->target_rfc1001_name, 0x20, 16); |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1131 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1132 | for (i = 0; i < 15; i++) { |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1133 | /* BB are there cases in which a comma can be |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1134 | valid in this workstation netbios name |
| 1135 | (and need special handling)? */ |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1136 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1137 | /* user or mount helper must uppercase |
| 1138 | the netbiosname */ |
| 1139 | if (value[i] == 0) |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1140 | break; |
| 1141 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1142 | vol->target_rfc1001_name[i] = |
| 1143 | value[i]; |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1144 | } |
| 1145 | /* The string has 16th byte zero still from |
| 1146 | set at top of the function */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1147 | if ((i == 15) && (value[i] != 0)) |
| 1148 | printk(KERN_WARNING "CIFS: server net" |
| 1149 | "biosname longer than 15 truncated.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | } else if (strnicmp(data, "credentials", 4) == 0) { |
| 1152 | /* ignore */ |
| 1153 | } else if (strnicmp(data, "version", 3) == 0) { |
| 1154 | /* ignore */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1155 | } else if (strnicmp(data, "guest", 5) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | /* ignore */ |
| 1157 | } else if (strnicmp(data, "rw", 2) == 0) { |
| 1158 | vol->rw = TRUE; |
| 1159 | } else if ((strnicmp(data, "suid", 4) == 0) || |
| 1160 | (strnicmp(data, "nosuid", 6) == 0) || |
| 1161 | (strnicmp(data, "exec", 4) == 0) || |
| 1162 | (strnicmp(data, "noexec", 6) == 0) || |
| 1163 | (strnicmp(data, "nodev", 5) == 0) || |
| 1164 | (strnicmp(data, "noauto", 6) == 0) || |
| 1165 | (strnicmp(data, "dev", 3) == 0)) { |
| 1166 | /* The mount tool or mount.cifs helper (if present) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1167 | uses these opts to set flags, and the flags are read |
| 1168 | by the kernel vfs layer before we get here (ie |
| 1169 | before read super) so there is no point trying to |
| 1170 | parse these options again and set anything and it |
| 1171 | is ok to just ignore them */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | continue; |
| 1173 | } else if (strnicmp(data, "ro", 2) == 0) { |
| 1174 | vol->rw = FALSE; |
| 1175 | } else if (strnicmp(data, "hard", 4) == 0) { |
| 1176 | vol->retry = 1; |
| 1177 | } else if (strnicmp(data, "soft", 4) == 0) { |
| 1178 | vol->retry = 0; |
| 1179 | } else if (strnicmp(data, "perm", 4) == 0) { |
| 1180 | vol->noperm = 0; |
| 1181 | } else if (strnicmp(data, "noperm", 6) == 0) { |
| 1182 | vol->noperm = 1; |
Steve French | 6a0b482 | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 1183 | } else if (strnicmp(data, "mapchars", 8) == 0) { |
| 1184 | vol->remap = 1; |
| 1185 | } else if (strnicmp(data, "nomapchars", 10) == 0) { |
| 1186 | vol->remap = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1187 | } else if (strnicmp(data, "sfu", 3) == 0) { |
| 1188 | vol->sfu_emul = 1; |
| 1189 | } else if (strnicmp(data, "nosfu", 5) == 0) { |
| 1190 | vol->sfu_emul = 0; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 1191 | } else if (strnicmp(data, "posixpaths", 10) == 0) { |
| 1192 | vol->posix_paths = 1; |
| 1193 | } else if (strnicmp(data, "noposixpaths", 12) == 0) { |
| 1194 | vol->posix_paths = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1195 | } else if ((strnicmp(data, "nocase", 6) == 0) || |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1196 | (strnicmp(data, "ignorecase", 10) == 0)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1197 | vol->nocase = 1; |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 1198 | } else if (strnicmp(data, "brl", 3) == 0) { |
| 1199 | vol->nobrl = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1200 | } else if ((strnicmp(data, "nobrl", 5) == 0) || |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1201 | (strnicmp(data, "nolock", 6) == 0)) { |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 1202 | vol->nobrl = 1; |
Steve French | d3485d3 | 2005-08-19 11:04:29 -0700 | [diff] [blame] | 1203 | /* turn off mandatory locking in mode |
| 1204 | if remote locking is turned off since the |
| 1205 | local vfs will do advisory */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1206 | if (vol->file_mode == |
| 1207 | (S_IALLUGO & ~(S_ISUID | S_IXGRP))) |
Steve French | d3485d3 | 2005-08-19 11:04:29 -0700 | [diff] [blame] | 1208 | vol->file_mode = S_IALLUGO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } else if (strnicmp(data, "setuids", 7) == 0) { |
| 1210 | vol->setuids = 1; |
| 1211 | } else if (strnicmp(data, "nosetuids", 9) == 0) { |
| 1212 | vol->setuids = 0; |
| 1213 | } else if (strnicmp(data, "nohard", 6) == 0) { |
| 1214 | vol->retry = 0; |
| 1215 | } else if (strnicmp(data, "nosoft", 6) == 0) { |
| 1216 | vol->retry = 1; |
| 1217 | } else if (strnicmp(data, "nointr", 6) == 0) { |
| 1218 | vol->intr = 0; |
| 1219 | } else if (strnicmp(data, "intr", 4) == 0) { |
| 1220 | vol->intr = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1221 | } else if (strnicmp(data, "serverino", 7) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | vol->server_ino = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1223 | } else if (strnicmp(data, "noserverino", 9) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | vol->server_ino = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1225 | } else if (strnicmp(data, "cifsacl", 7) == 0) { |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 1226 | vol->cifs_acl = 1; |
| 1227 | } else if (strnicmp(data, "nocifsacl", 9) == 0) { |
| 1228 | vol->cifs_acl = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1229 | } else if (strnicmp(data, "acl", 3) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | vol->no_psx_acl = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1231 | } else if (strnicmp(data, "noacl", 5) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | vol->no_psx_acl = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1233 | } else if (strnicmp(data, "sign", 4) == 0) { |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 1234 | vol->secFlg |= CIFSSEC_MUST_SIGN; |
| 1235 | /* } else if (strnicmp(data, "seal",4) == 0) { |
| 1236 | vol->secFlg |= CIFSSEC_MUST_SEAL; */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1237 | } else if (strnicmp(data, "direct", 6) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | vol->direct_io = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1239 | } else if (strnicmp(data, "forcedirectio", 13) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | vol->direct_io = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1241 | } else if (strnicmp(data, "in6_addr", 8) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | if (!value || !*value) { |
| 1243 | vol->in6_addr = NULL; |
| 1244 | } else if (strnlen(value, 49) == 48) { |
| 1245 | vol->in6_addr = value; |
| 1246 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1247 | printk(KERN_WARNING "CIFS: ip v6 address not " |
| 1248 | "48 characters long\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | return 1; |
| 1250 | } |
| 1251 | } else if (strnicmp(data, "noac", 4) == 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1252 | printk(KERN_WARNING "CIFS: Mount option noac not " |
| 1253 | "supported. Instead set " |
| 1254 | "/proc/fs/cifs/LookupCacheEnabled to 0\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | } else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1256 | printk(KERN_WARNING "CIFS: Unknown mount option %s\n", |
| 1257 | data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | } |
| 1259 | if (vol->UNC == NULL) { |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1260 | if (devname == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1261 | printk(KERN_WARNING "CIFS: Missing UNC name for mount " |
| 1262 | "target\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | return 1; |
| 1264 | } |
| 1265 | if ((temp_len = strnlen(devname, 300)) < 300) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1266 | vol->UNC = kmalloc(temp_len+1, GFP_KERNEL); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1267 | if (vol->UNC == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | return 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1269 | strcpy(vol->UNC, devname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | if (strncmp(vol->UNC, "//", 2) == 0) { |
| 1271 | vol->UNC[0] = '\\'; |
| 1272 | vol->UNC[1] = '\\'; |
| 1273 | } else if (strncmp(vol->UNC, "\\\\", 2) != 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1274 | printk(KERN_WARNING "CIFS: UNC Path does not " |
| 1275 | "begin with // or \\\\ \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | return 1; |
| 1277 | } |
| 1278 | } else { |
| 1279 | printk(KERN_WARNING "CIFS: UNC name too long\n"); |
| 1280 | return 1; |
| 1281 | } |
| 1282 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1283 | if (vol->UNCip == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | vol->UNCip = &vol->UNC[2]; |
| 1285 | |
| 1286 | return 0; |
| 1287 | } |
| 1288 | |
| 1289 | static struct cifsSesInfo * |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1290 | cifs_find_tcp_session(struct in_addr *target_ip_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | struct in6_addr *target_ip6_addr, |
| 1292 | char *userName, struct TCP_Server_Info **psrvTcp) |
| 1293 | { |
| 1294 | struct list_head *tmp; |
| 1295 | struct cifsSesInfo *ses; |
| 1296 | *psrvTcp = NULL; |
| 1297 | read_lock(&GlobalSMBSeslock); |
| 1298 | |
| 1299 | list_for_each(tmp, &GlobalSMBSessionList) { |
| 1300 | ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList); |
| 1301 | if (ses->server) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1302 | if ((target_ip_addr && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | (ses->server->addr.sockAddr.sin_addr.s_addr |
| 1304 | == target_ip_addr->s_addr)) || (target_ip6_addr |
| 1305 | && memcmp(&ses->server->addr.sockAddr6.sin6_addr, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1306 | target_ip6_addr, sizeof(*target_ip6_addr)))) { |
| 1307 | /* BB lock server and tcp session and increment |
| 1308 | use count here?? */ |
| 1309 | |
| 1310 | /* found a match on the TCP session */ |
| 1311 | *psrvTcp = ses->server; |
| 1312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | /* BB check if reconnection needed */ |
| 1314 | if (strncmp |
| 1315 | (ses->userName, userName, |
| 1316 | MAX_USERNAME_SIZE) == 0){ |
| 1317 | read_unlock(&GlobalSMBSeslock); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1318 | /* Found exact match on both TCP and |
| 1319 | SMB sessions */ |
| 1320 | return ses; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | /* else tcp and smb sessions need reconnection */ |
| 1325 | } |
| 1326 | read_unlock(&GlobalSMBSeslock); |
| 1327 | return NULL; |
| 1328 | } |
| 1329 | |
| 1330 | static struct cifsTconInfo * |
| 1331 | find_unc(__be32 new_target_ip_addr, char *uncName, char *userName) |
| 1332 | { |
| 1333 | struct list_head *tmp; |
| 1334 | struct cifsTconInfo *tcon; |
| 1335 | |
| 1336 | read_lock(&GlobalSMBSeslock); |
| 1337 | list_for_each(tmp, &GlobalTreeConnectionList) { |
Steve French | e466e48 | 2006-08-15 13:07:18 +0000 | [diff] [blame] | 1338 | cFYI(1, ("Next tcon")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList); |
| 1340 | if (tcon->ses) { |
| 1341 | if (tcon->ses->server) { |
| 1342 | cFYI(1, |
Steve French | e466e48 | 2006-08-15 13:07:18 +0000 | [diff] [blame] | 1343 | ("old ip addr: %x == new ip %x ?", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | tcon->ses->server->addr.sockAddr.sin_addr. |
| 1345 | s_addr, new_target_ip_addr)); |
| 1346 | if (tcon->ses->server->addr.sockAddr.sin_addr. |
| 1347 | s_addr == new_target_ip_addr) { |
Steve French | e466e48 | 2006-08-15 13:07:18 +0000 | [diff] [blame] | 1348 | /* BB lock tcon, server and tcp session and increment use count here? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | /* found a match on the TCP session */ |
| 1350 | /* BB check if reconnection needed */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1351 | cFYI(1, |
| 1352 | ("IP match, old UNC: %s new: %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | tcon->treeName, uncName)); |
| 1354 | if (strncmp |
| 1355 | (tcon->treeName, uncName, |
| 1356 | MAX_TREE_SIZE) == 0) { |
| 1357 | cFYI(1, |
Steve French | e466e48 | 2006-08-15 13:07:18 +0000 | [diff] [blame] | 1358 | ("and old usr: %s new: %s", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | tcon->treeName, uncName)); |
| 1360 | if (strncmp |
| 1361 | (tcon->ses->userName, |
| 1362 | userName, |
| 1363 | MAX_USERNAME_SIZE) == 0) { |
| 1364 | read_unlock(&GlobalSMBSeslock); |
Steve French | e466e48 | 2006-08-15 13:07:18 +0000 | [diff] [blame] | 1365 | /* matched smb session |
| 1366 | (user name */ |
| 1367 | return tcon; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | read_unlock(&GlobalSMBSeslock); |
| 1375 | return NULL; |
| 1376 | } |
| 1377 | |
| 1378 | int |
| 1379 | connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1380 | const char *old_path, const struct nls_table *nls_codepage, |
| 1381 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | { |
| 1383 | unsigned char *referrals = NULL; |
| 1384 | unsigned int num_referrals; |
| 1385 | int rc = 0; |
| 1386 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1387 | rc = get_dfs_path(xid, pSesInfo, old_path, nls_codepage, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1388 | &num_referrals, &referrals, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
| 1390 | /* BB Add in code to: if valid refrl, if not ip address contact |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1391 | the helper that resolves tcp names, mount to it, try to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | tcon to it unmount it if fail */ |
| 1393 | |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1394 | kfree(referrals); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
| 1396 | return rc; |
| 1397 | } |
| 1398 | |
| 1399 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1400 | get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path, |
| 1401 | const struct nls_table *nls_codepage, unsigned int *pnum_referrals, |
| 1402 | unsigned char **preferrals, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
| 1404 | char *temp_unc; |
| 1405 | int rc = 0; |
| 1406 | |
| 1407 | *pnum_referrals = 0; |
| 1408 | |
| 1409 | if (pSesInfo->ipc_tid == 0) { |
| 1410 | temp_unc = kmalloc(2 /* for slashes */ + |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1411 | strnlen(pSesInfo->serverName, |
| 1412 | SERVER_NAME_LEN_WITH_NULL * 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | + 1 + 4 /* slash IPC$ */ + 2, |
| 1414 | GFP_KERNEL); |
| 1415 | if (temp_unc == NULL) |
| 1416 | return -ENOMEM; |
| 1417 | temp_unc[0] = '\\'; |
| 1418 | temp_unc[1] = '\\'; |
| 1419 | strcpy(temp_unc + 2, pSesInfo->serverName); |
| 1420 | strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$"); |
| 1421 | rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage); |
| 1422 | cFYI(1, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1423 | ("CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | kfree(temp_unc); |
| 1425 | } |
| 1426 | if (rc == 0) |
| 1427 | rc = CIFSGetDFSRefer(xid, pSesInfo, old_path, preferrals, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1428 | pnum_referrals, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | return rc; |
| 1431 | } |
| 1432 | |
| 1433 | /* See RFC1001 section 14 on representation of Netbios names */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1434 | static void rfc1002mangle(char *target, char *source, unsigned int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1436 | unsigned int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1438 | for (i = 0, j = 0; i < (length); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | /* mask a nibble at a time and encode */ |
| 1440 | target[j] = 'A' + (0x0F & (source[i] >> 4)); |
| 1441 | target[j+1] = 'A' + (0x0F & source[i]); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1442 | j += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | } |
| 1446 | |
| 1447 | |
| 1448 | static int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1449 | ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket, |
| 1450 | char *netbios_name, char *target_name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
| 1452 | int rc = 0; |
| 1453 | int connected = 0; |
| 1454 | __be16 orig_port = 0; |
| 1455 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1456 | if (*csocket == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1457 | rc = sock_create_kern(PF_INET, SOCK_STREAM, |
| 1458 | IPPROTO_TCP, csocket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | if (rc < 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1460 | cERROR(1, ("Error %d creating socket", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | *csocket = NULL; |
| 1462 | return rc; |
| 1463 | } else { |
| 1464 | /* BB other socket options to set KEEPALIVE, NODELAY? */ |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 1465 | cFYI(1, ("Socket created")); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1466 | (*csocket)->sk->sk_allocation = GFP_NOFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | psin_server->sin_family = AF_INET; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1471 | if (psin_server->sin_port) { /* user overrode default port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | rc = (*csocket)->ops->connect(*csocket, |
| 1473 | (struct sockaddr *) psin_server, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1474 | sizeof (struct sockaddr_in), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | if (rc >= 0) |
| 1476 | connected = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1479 | if (!connected) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1480 | /* save original port so we can retry user specified port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | later if fall back ports fail this time */ |
| 1482 | orig_port = psin_server->sin_port; |
| 1483 | |
| 1484 | /* do not retry on the same port we just failed on */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1485 | if (psin_server->sin_port != htons(CIFS_PORT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | psin_server->sin_port = htons(CIFS_PORT); |
| 1487 | |
| 1488 | rc = (*csocket)->ops->connect(*csocket, |
| 1489 | (struct sockaddr *) psin_server, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1490 | sizeof (struct sockaddr_in), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | if (rc >= 0) |
| 1492 | connected = 1; |
| 1493 | } |
| 1494 | } |
| 1495 | if (!connected) { |
| 1496 | psin_server->sin_port = htons(RFC1001_PORT); |
| 1497 | rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1498 | psin_server, |
| 1499 | sizeof (struct sockaddr_in), 0); |
| 1500 | if (rc >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | connected = 1; |
| 1502 | } |
| 1503 | |
| 1504 | /* give up here - unless we want to retry on different |
| 1505 | protocol families some day */ |
| 1506 | if (!connected) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1507 | if (orig_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | psin_server->sin_port = orig_port; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1509 | cFYI(1, ("Error %d connecting to server via ipv4", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | sock_release(*csocket); |
| 1511 | *csocket = NULL; |
| 1512 | return rc; |
| 1513 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1514 | /* Eventually check for other socket options to change from |
| 1515 | the default. sock_setsockopt not used because it expects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | user space buffer */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1517 | cFYI(1, ("sndbuf %d rcvbuf %d rcvtimeo 0x%lx", |
| 1518 | (*csocket)->sk->sk_sndbuf, |
Steve French | b387eae | 2005-10-10 14:21:15 -0700 | [diff] [blame] | 1519 | (*csocket)->sk->sk_rcvbuf, (*csocket)->sk->sk_rcvtimeo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | (*csocket)->sk->sk_rcvtimeo = 7 * HZ; |
Steve French | b387eae | 2005-10-10 14:21:15 -0700 | [diff] [blame] | 1521 | /* make the bufsizes depend on wsize/rsize and max requests */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1522 | if ((*csocket)->sk->sk_sndbuf < (200 * 1024)) |
Steve French | b387eae | 2005-10-10 14:21:15 -0700 | [diff] [blame] | 1523 | (*csocket)->sk->sk_sndbuf = 200 * 1024; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1524 | if ((*csocket)->sk->sk_rcvbuf < (140 * 1024)) |
Steve French | b387eae | 2005-10-10 14:21:15 -0700 | [diff] [blame] | 1525 | (*csocket)->sk->sk_rcvbuf = 140 * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
| 1527 | /* send RFC1001 sessinit */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1528 | if (psin_server->sin_port == htons(RFC1001_PORT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | /* some servers require RFC1001 sessinit before sending |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1530 | negprot - BB check reconnection in case where second |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | sessinit is sent but no second negprot */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1532 | struct rfc1002_session_packet *ses_init_buf; |
| 1533 | struct smb_hdr *smb_buf; |
| 1534 | ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet), |
| 1535 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1536 | if (ses_init_buf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | ses_init_buf->trailer.session_req.called_len = 32; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1538 | if (target_name && (target_name[0] != 0)) { |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1539 | rfc1002mangle(ses_init_buf->trailer.session_req.called_name, |
| 1540 | target_name, 16); |
| 1541 | } else { |
| 1542 | rfc1002mangle(ses_init_buf->trailer.session_req.called_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1543 | DEFAULT_CIFS_CALLED_NAME, 16); |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1544 | } |
| 1545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | ses_init_buf->trailer.session_req.calling_len = 32; |
| 1547 | /* calling name ends in null (byte 16) from old smb |
| 1548 | convention. */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1549 | if (netbios_name && (netbios_name[0] != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | rfc1002mangle(ses_init_buf->trailer.session_req.calling_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1551 | netbios_name, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | } else { |
| 1553 | rfc1002mangle(ses_init_buf->trailer.session_req.calling_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1554 | "LINUX_CIFS_CLNT", 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | } |
| 1556 | ses_init_buf->trailer.session_req.scope1 = 0; |
| 1557 | ses_init_buf->trailer.session_req.scope2 = 0; |
| 1558 | smb_buf = (struct smb_hdr *)ses_init_buf; |
| 1559 | /* sizeof RFC1002_SESSION_REQUEST with no scope */ |
| 1560 | smb_buf->smb_buf_length = 0x81000044; |
| 1561 | rc = smb_send(*csocket, smb_buf, 0x44, |
| 1562 | (struct sockaddr *)psin_server); |
| 1563 | kfree(ses_init_buf); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1564 | msleep(1); /* RFC1001 layer in at least one server |
Steve French | 083d3a2 | 2006-03-03 09:53:36 +0000 | [diff] [blame] | 1565 | requires very short break before negprot |
| 1566 | presumably because not expecting negprot |
| 1567 | to follow so fast. This is a simple |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1568 | solution that works without |
Steve French | 083d3a2 | 2006-03-03 09:53:36 +0000 | [diff] [blame] | 1569 | complicating the code and causes no |
| 1570 | significant slowing down on mount |
| 1571 | for everyone else */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1573 | /* else the negprot may still work without this |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | even though malloc failed */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return rc; |
| 1579 | } |
| 1580 | |
| 1581 | static int |
| 1582 | ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket) |
| 1583 | { |
| 1584 | int rc = 0; |
| 1585 | int connected = 0; |
| 1586 | __be16 orig_port = 0; |
| 1587 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1588 | if (*csocket == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1589 | rc = sock_create_kern(PF_INET6, SOCK_STREAM, |
| 1590 | IPPROTO_TCP, csocket); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | if (rc < 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1592 | cERROR(1, ("Error %d creating ipv6 socket", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | *csocket = NULL; |
| 1594 | return rc; |
| 1595 | } else { |
| 1596 | /* BB other socket options to set KEEPALIVE, NODELAY? */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1597 | cFYI(1, ("ipv6 Socket created")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | (*csocket)->sk->sk_allocation = GFP_NOFS; |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | psin_server->sin6_family = AF_INET6; |
| 1603 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1604 | if (psin_server->sin6_port) { /* user overrode default port */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | rc = (*csocket)->ops->connect(*csocket, |
| 1606 | (struct sockaddr *) psin_server, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1607 | sizeof (struct sockaddr_in6), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | if (rc >= 0) |
| 1609 | connected = 1; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1612 | if (!connected) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1613 | /* save original port so we can retry user specified port |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | later if fall back ports fail this time */ |
| 1615 | |
| 1616 | orig_port = psin_server->sin6_port; |
| 1617 | /* do not retry on the same port we just failed on */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1618 | if (psin_server->sin6_port != htons(CIFS_PORT)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | psin_server->sin6_port = htons(CIFS_PORT); |
| 1620 | |
| 1621 | rc = (*csocket)->ops->connect(*csocket, |
| 1622 | (struct sockaddr *) psin_server, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1623 | sizeof (struct sockaddr_in6), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | if (rc >= 0) |
| 1625 | connected = 1; |
| 1626 | } |
| 1627 | } |
| 1628 | if (!connected) { |
| 1629 | psin_server->sin6_port = htons(RFC1001_PORT); |
| 1630 | rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1631 | psin_server, sizeof (struct sockaddr_in6), 0); |
| 1632 | if (rc >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | connected = 1; |
| 1634 | } |
| 1635 | |
| 1636 | /* give up here - unless we want to retry on different |
| 1637 | protocol families some day */ |
| 1638 | if (!connected) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1639 | if (orig_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | psin_server->sin6_port = orig_port; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1641 | cFYI(1, ("Error %d connecting to server via ipv6", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | sock_release(*csocket); |
| 1643 | *csocket = NULL; |
| 1644 | return rc; |
| 1645 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1646 | /* Eventually check for other socket options to change from |
| 1647 | the default. sock_setsockopt not used because it expects |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | user space buffer */ |
| 1649 | (*csocket)->sk->sk_rcvtimeo = 7 * HZ; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | return rc; |
| 1652 | } |
| 1653 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1654 | void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, |
| 1655 | struct super_block *sb, struct smb_vol *vol_info) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1656 | { |
| 1657 | /* if we are reconnecting then should we check to see if |
| 1658 | * any requested capabilities changed locally e.g. via |
| 1659 | * remount but we can not do much about it here |
| 1660 | * if they have (even if we could detect it by the following) |
| 1661 | * Perhaps we could add a backpointer to array of sb from tcon |
| 1662 | * or if we change to make all sb to same share the same |
| 1663 | * sb as NFS - then we only have one backpointer to sb. |
| 1664 | * What if we wanted to mount the server share twice once with |
| 1665 | * and once without posixacls or posix paths? */ |
| 1666 | __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1667 | |
| 1668 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1669 | if (!CIFSSMBQFSUnixInfo(xid, tcon)) { |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1670 | __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1671 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1672 | /* check for reconnect case in which we do not |
| 1673 | want to change the mount behavior if we can avoid it */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1674 | if (vol_info == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1675 | /* turn off POSIX ACL and PATHNAMES if not set |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1676 | originally at mount time */ |
| 1677 | if ((saved_cap & CIFS_UNIX_POSIX_ACL_CAP) == 0) |
| 1678 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
| 1679 | if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) |
| 1680 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1681 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1682 | |
| 1683 | |
| 1684 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1685 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1686 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1687 | cap &= CIFS_UNIX_CAP_MASK; |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1688 | if (vol_info && vol_info->no_psx_acl) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1689 | cap &= ~CIFS_UNIX_POSIX_ACL_CAP; |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1690 | else if (CIFS_UNIX_POSIX_ACL_CAP & cap) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1691 | cFYI(1, ("negotiated posix acl support")); |
| 1692 | if (sb) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1693 | sb->s_flags |= MS_POSIXACL; |
| 1694 | } |
| 1695 | |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1696 | if (vol_info && vol_info->posix_paths == 0) |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1697 | cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1698 | else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1699 | cFYI(1, ("negotiate posix pathnames")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1700 | if (sb) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1701 | CIFS_SB(sb)->mnt_cifs_flags |= |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1702 | CIFS_MOUNT_POSIX_PATHS; |
| 1703 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1704 | |
Steve French | 984acfe | 2007-04-26 16:42:50 +0000 | [diff] [blame] | 1705 | /* We might be setting the path sep back to a different |
| 1706 | form if we are reconnecting and the server switched its |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1707 | posix path capability for this share */ |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1708 | if (sb && (CIFS_SB(sb)->prepathlen > 0)) |
Steve French | 984acfe | 2007-04-26 16:42:50 +0000 | [diff] [blame] | 1709 | CIFS_SB(sb)->prepath[0] = CIFS_DIR_SEP(CIFS_SB(sb)); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1710 | |
| 1711 | if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) { |
| 1712 | if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) { |
| 1713 | CIFS_SB(sb)->rsize = 127 * 1024; |
| 1714 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1715 | cFYI(1, ("larger reads not supported by srv")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1716 | #endif |
| 1717 | } |
| 1718 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1719 | |
| 1720 | |
| 1721 | cFYI(1, ("Negotiate caps 0x%x", (int)cap)); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1722 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1723 | if (cap & CIFS_UNIX_FCNTL_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1724 | cFYI(1, ("FCNTL cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1725 | if (cap & CIFS_UNIX_EXTATTR_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1726 | cFYI(1, ("EXTATTR cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1727 | if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1728 | cFYI(1, ("POSIX path cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1729 | if (cap & CIFS_UNIX_XATTR_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1730 | cFYI(1, ("XATTR cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1731 | if (cap & CIFS_UNIX_POSIX_ACL_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1732 | cFYI(1, ("POSIX ACL cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1733 | if (cap & CIFS_UNIX_LARGE_READ_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1734 | cFYI(1, ("very large read cap")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1735 | if (cap & CIFS_UNIX_LARGE_WRITE_CAP) |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1736 | cFYI(1, ("very large write cap")); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1737 | #endif /* CIFS_DEBUG2 */ |
| 1738 | if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1739 | cFYI(1, ("setting capabilities failed")); |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 1740 | } |
| 1741 | } |
| 1742 | } |
| 1743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | int |
| 1745 | cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, |
| 1746 | char *mount_data, const char *devname) |
| 1747 | { |
| 1748 | int rc = 0; |
| 1749 | int xid; |
| 1750 | int address_type = AF_INET; |
| 1751 | struct socket *csocket = NULL; |
| 1752 | struct sockaddr_in sin_server; |
| 1753 | struct sockaddr_in6 sin_server6; |
| 1754 | struct smb_vol volume_info; |
| 1755 | struct cifsSesInfo *pSesInfo = NULL; |
| 1756 | struct cifsSesInfo *existingCifsSes = NULL; |
| 1757 | struct cifsTconInfo *tcon = NULL; |
| 1758 | struct TCP_Server_Info *srvTcp = NULL; |
| 1759 | |
| 1760 | xid = GetXid(); |
| 1761 | |
| 1762 | /* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1763 | |
| 1764 | memset(&volume_info, 0, sizeof(struct smb_vol)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | if (cifs_parse_mount_options(mount_data, devname, &volume_info)) { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1766 | kfree(volume_info.UNC); |
| 1767 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1768 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | FreeXid(xid); |
| 1770 | return -EINVAL; |
| 1771 | } |
| 1772 | |
Jeff Layton | 8426c39 | 2007-05-05 03:27:49 +0000 | [diff] [blame] | 1773 | if (volume_info.nullauth) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1774 | cFYI(1, ("null user")); |
Jeff Layton | 8426c39 | 2007-05-05 03:27:49 +0000 | [diff] [blame] | 1775 | volume_info.username = NULL; |
| 1776 | } else if (volume_info.username) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | /* BB fixme parse for domain name here */ |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 1778 | cFYI(1, ("Username: %s", volume_info.username)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } else { |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 1780 | cifserror("No username specified"); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1781 | /* In userspace mount helper we can get user name from alternate |
| 1782 | locations such as env variables and files on disk */ |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1783 | kfree(volume_info.UNC); |
| 1784 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1785 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | FreeXid(xid); |
| 1787 | return -EINVAL; |
| 1788 | } |
| 1789 | |
| 1790 | if (volume_info.UNCip && volume_info.UNC) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1791 | rc = cifs_inet_pton(AF_INET, volume_info.UNCip, |
| 1792 | &sin_server.sin_addr.s_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1794 | if (rc <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | /* not ipv4 address, try ipv6 */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1796 | rc = cifs_inet_pton(AF_INET6, volume_info.UNCip, |
| 1797 | &sin_server6.sin6_addr.in6_u); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1798 | if (rc > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | address_type = AF_INET6; |
| 1800 | } else { |
| 1801 | address_type = AF_INET; |
| 1802 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1803 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1804 | if (rc <= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | /* we failed translating address */ |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1806 | kfree(volume_info.UNC); |
| 1807 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1808 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | FreeXid(xid); |
| 1810 | return -EINVAL; |
| 1811 | } |
| 1812 | |
| 1813 | cFYI(1, ("UNC: %s ip: %s", volume_info.UNC, volume_info.UNCip)); |
| 1814 | /* success */ |
| 1815 | rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1816 | } else if (volume_info.UNCip) { |
| 1817 | /* BB using ip addr as server name to connect to the |
| 1818 | DFS root below */ |
| 1819 | cERROR(1, ("Connecting to DFS root not implemented yet")); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1820 | kfree(volume_info.UNC); |
| 1821 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1822 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | FreeXid(xid); |
| 1824 | return -EINVAL; |
| 1825 | } else /* which servers DFS root would we conect to */ { |
| 1826 | cERROR(1, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1827 | ("CIFS mount error: No UNC path (e.g. -o " |
| 1828 | "unc=//192.168.1.100/public) specified")); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1829 | kfree(volume_info.UNC); |
| 1830 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1831 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | FreeXid(xid); |
| 1833 | return -EINVAL; |
| 1834 | } |
| 1835 | |
| 1836 | /* this is needed for ASCII cp to Unicode converts */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1837 | if (volume_info.iocharset == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | cifs_sb->local_nls = load_nls_default(); |
| 1839 | /* load_nls_default can not return null */ |
| 1840 | } else { |
| 1841 | cifs_sb->local_nls = load_nls(volume_info.iocharset); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1842 | if (cifs_sb->local_nls == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1843 | cERROR(1, ("CIFS mount error: iocharset %s not found", |
| 1844 | volume_info.iocharset)); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1845 | kfree(volume_info.UNC); |
| 1846 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1847 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | FreeXid(xid); |
| 1849 | return -ELIBACC; |
| 1850 | } |
| 1851 | } |
| 1852 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1853 | if (address_type == AF_INET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | existingCifsSes = cifs_find_tcp_session(&sin_server.sin_addr, |
| 1855 | NULL /* no ipv6 addr */, |
| 1856 | volume_info.username, &srvTcp); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1857 | else if (address_type == AF_INET6) { |
| 1858 | cFYI(1, ("looking for ipv6 address")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | existingCifsSes = cifs_find_tcp_session(NULL /* no ipv4 addr */, |
| 1860 | &sin_server6.sin6_addr, |
| 1861 | volume_info.username, &srvTcp); |
Steve French | 5858ae4 | 2007-04-25 11:59:10 +0000 | [diff] [blame] | 1862 | } else { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1863 | kfree(volume_info.UNC); |
| 1864 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1865 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | FreeXid(xid); |
| 1867 | return -EINVAL; |
| 1868 | } |
| 1869 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | if (srvTcp) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1871 | cFYI(1, ("Existing tcp session with server found")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | } else { /* create socket */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1873 | if (volume_info.port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | sin_server.sin_port = htons(volume_info.port); |
| 1875 | else |
| 1876 | sin_server.sin_port = 0; |
Steve French | 5858ae4 | 2007-04-25 11:59:10 +0000 | [diff] [blame] | 1877 | if (address_type == AF_INET6) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 1878 | cFYI(1, ("attempting ipv6 connect")); |
Steve French | 5858ae4 | 2007-04-25 11:59:10 +0000 | [diff] [blame] | 1879 | /* BB should we allow ipv6 on port 139? */ |
| 1880 | /* other OS never observed in Wild doing 139 with v6 */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1881 | rc = ipv6_connect(&sin_server6, &csocket); |
| 1882 | } else |
| 1883 | rc = ipv4_connect(&sin_server, &csocket, |
Steve French | a10faeb2 | 2005-08-22 21:38:31 -0700 | [diff] [blame] | 1884 | volume_info.source_rfc1001_name, |
| 1885 | volume_info.target_rfc1001_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | if (rc < 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1887 | cERROR(1, ("Error connecting to IPv4 socket. " |
| 1888 | "Aborting operation")); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1889 | if (csocket != NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | sock_release(csocket); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1891 | kfree(volume_info.UNC); |
| 1892 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1893 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | FreeXid(xid); |
| 1895 | return rc; |
| 1896 | } |
| 1897 | |
| 1898 | srvTcp = kmalloc(sizeof (struct TCP_Server_Info), GFP_KERNEL); |
| 1899 | if (srvTcp == NULL) { |
| 1900 | rc = -ENOMEM; |
| 1901 | sock_release(csocket); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1902 | kfree(volume_info.UNC); |
| 1903 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1904 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | FreeXid(xid); |
| 1906 | return rc; |
| 1907 | } else { |
| 1908 | memset(srvTcp, 0, sizeof (struct TCP_Server_Info)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1909 | memcpy(&srvTcp->addr.sockAddr, &sin_server, |
| 1910 | sizeof (struct sockaddr_in)); |
| 1911 | atomic_set(&srvTcp->inFlight, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | /* BB Add code for ipv6 case too */ |
| 1913 | srvTcp->ssocket = csocket; |
| 1914 | srvTcp->protocolType = IPV4; |
| 1915 | init_waitqueue_head(&srvTcp->response_q); |
| 1916 | init_waitqueue_head(&srvTcp->request_q); |
| 1917 | INIT_LIST_HEAD(&srvTcp->pending_mid_q); |
| 1918 | /* at this point we are the only ones with the pointer |
| 1919 | to the struct since the kernel thread not created yet |
| 1920 | so no need to spinlock this init of tcpStatus */ |
| 1921 | srvTcp->tcpStatus = CifsNew; |
| 1922 | init_MUTEX(&srvTcp->tcpSem); |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 1923 | srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd"); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1924 | if ( IS_ERR(srvTcp->tsk) ) { |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 1925 | rc = PTR_ERR(srvTcp->tsk); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1926 | cERROR(1, ("error %d create cifsd thread", rc)); |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 1927 | srvTcp->tsk = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | sock_release(csocket); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1929 | kfree(volume_info.UNC); |
| 1930 | kfree(volume_info.password); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 1931 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | FreeXid(xid); |
| 1933 | return rc; |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 1934 | } |
| 1935 | wait_for_completion(&cifsd_complete); |
| 1936 | rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1937 | memcpy(srvTcp->workstation_RFC1001_name, |
| 1938 | volume_info.source_rfc1001_name, 16); |
| 1939 | memcpy(srvTcp->server_RFC1001_name, |
| 1940 | volume_info.target_rfc1001_name, 16); |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 1941 | srvTcp->sequence_number = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | if (existingCifsSes) { |
| 1946 | pSesInfo = existingCifsSes; |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 1947 | cFYI(1, ("Existing smb sess found")); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1948 | kfree(volume_info.password); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | /* volume_info.UNC freed at end of function */ |
| 1950 | } else if (!rc) { |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 1951 | cFYI(1, ("Existing smb sess not found")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | pSesInfo = sesInfoAlloc(); |
| 1953 | if (pSesInfo == NULL) |
| 1954 | rc = -ENOMEM; |
| 1955 | else { |
| 1956 | pSesInfo->server = srvTcp; |
| 1957 | sprintf(pSesInfo->serverName, "%u.%u.%u.%u", |
| 1958 | NIPQUAD(sin_server.sin_addr.s_addr)); |
| 1959 | } |
| 1960 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1961 | if (!rc) { |
| 1962 | /* volume_info.password freed at unmount */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | if (volume_info.password) |
| 1964 | pSesInfo->password = volume_info.password; |
| 1965 | if (volume_info.username) |
| 1966 | strncpy(pSesInfo->userName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1967 | volume_info.username, |
| 1968 | MAX_USERNAME_SIZE); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1969 | if (volume_info.domainname) { |
| 1970 | int len = strlen(volume_info.domainname); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1971 | pSesInfo->domainName = |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1972 | kmalloc(len + 1, GFP_KERNEL); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1973 | if (pSesInfo->domainName) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 1974 | strcpy(pSesInfo->domainName, |
| 1975 | volume_info.domainname); |
| 1976 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | pSesInfo->linux_uid = volume_info.linux_uid; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 1978 | pSesInfo->overrideSecFlg = volume_info.secFlg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | down(&pSesInfo->sesSem); |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 1980 | /* BB FIXME need to pass vol->secFlgs BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1981 | rc = cifs_setup_session(xid, pSesInfo, |
| 1982 | cifs_sb->local_nls); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | up(&pSesInfo->sesSem); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1984 | if (!rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | atomic_inc(&srvTcp->socketUseCount); |
| 1986 | } else |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 1987 | kfree(volume_info.password); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | /* search for existing tcon to this server share */ |
| 1991 | if (!rc) { |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 1992 | if (volume_info.rsize > CIFSMaxBufSize) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1993 | cERROR(1, ("rsize %d too large, using MaxBufSize", |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 1994 | volume_info.rsize)); |
| 1995 | cifs_sb->rsize = CIFSMaxBufSize; |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 1996 | } else if ((volume_info.rsize) && |
| 1997 | (volume_info.rsize <= CIFSMaxBufSize)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | cifs_sb->rsize = volume_info.rsize; |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 1999 | else /* default */ |
| 2000 | cifs_sb->rsize = CIFSMaxBufSize; |
| 2001 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2002 | if (volume_info.wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2003 | cERROR(1, ("wsize %d too large, using 4096 instead", |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 2004 | volume_info.wsize)); |
| 2005 | cifs_sb->wsize = 4096; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2006 | } else if (volume_info.wsize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | cifs_sb->wsize = volume_info.wsize; |
| 2008 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2009 | cifs_sb->wsize = |
Steve French | 1877c9e | 2006-01-27 18:36:11 -0800 | [diff] [blame] | 2010 | min_t(const int, PAGEVEC_SIZE * PAGE_CACHE_SIZE, |
| 2011 | 127*1024); |
Steve French | 17cbbaf | 2006-01-24 20:26:48 -0800 | [diff] [blame] | 2012 | /* old default of CIFSMaxBufSize was too small now |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2013 | that SMB Write2 can send multiple pages in kvec. |
Steve French | 17cbbaf | 2006-01-24 20:26:48 -0800 | [diff] [blame] | 2014 | RFC1001 does not describe what happens when frame |
| 2015 | bigger than 128K is sent so use that as max in |
| 2016 | conjunction with 52K kvec constraint on arch with 4K |
| 2017 | page size */ |
| 2018 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2019 | if (cifs_sb->rsize < 2048) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2020 | cifs_sb->rsize = 2048; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 2021 | /* Windows ME may prefer this */ |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 2022 | cFYI(1, ("readsize set to minimum: 2048")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | } |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 2024 | /* calculate prepath */ |
| 2025 | cifs_sb->prepath = volume_info.prepath; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2026 | if (cifs_sb->prepath) { |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 2027 | cifs_sb->prepathlen = strlen(cifs_sb->prepath); |
| 2028 | cifs_sb->prepath[0] = CIFS_DIR_SEP(cifs_sb); |
| 2029 | volume_info.prepath = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2030 | } else |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 2031 | cifs_sb->prepathlen = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | cifs_sb->mnt_uid = volume_info.linux_uid; |
| 2033 | cifs_sb->mnt_gid = volume_info.linux_gid; |
| 2034 | cifs_sb->mnt_file_mode = volume_info.file_mode; |
| 2035 | cifs_sb->mnt_dir_mode = volume_info.dir_mode; |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 2036 | cFYI(1, ("file mode: 0x%x dir mode: 0x%x", |
| 2037 | cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2039 | if (volume_info.noperm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2041 | if (volume_info.setuids) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2043 | if (volume_info.server_ino) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SERVER_INUM; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2045 | if (volume_info.remap) |
Steve French | 6a0b482 | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 2046 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_MAP_SPECIAL_CHR; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2047 | if (volume_info.no_xattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_XATTR; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2049 | if (volume_info.sfu_emul) |
Steve French | d7245c2 | 2005-07-14 18:25:12 -0500 | [diff] [blame] | 2050 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2051 | if (volume_info.nobrl) |
Steve French | c46fa8a | 2005-08-18 20:49:57 -0700 | [diff] [blame] | 2052 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2053 | if (volume_info.cifs_acl) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2054 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_CIFS_ACL; |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2055 | if (volume_info.override_uid) |
| 2056 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_UID; |
| 2057 | if (volume_info.override_gid) |
| 2058 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID; |
| 2059 | if (volume_info.direct_io) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 2060 | cFYI(1, ("mounting share using direct i/o")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO; |
| 2062 | } |
| 2063 | |
| 2064 | tcon = |
| 2065 | find_unc(sin_server.sin_addr.s_addr, volume_info.UNC, |
| 2066 | volume_info.username); |
| 2067 | if (tcon) { |
Steve French | bf82067 | 2005-12-01 22:32:42 -0800 | [diff] [blame] | 2068 | cFYI(1, ("Found match on UNC path")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | /* we can have only one retry value for a connection |
| 2070 | to a share so for resources mounted more than once |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2071 | to the same server share the last value passed in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | for the retry flag is used */ |
| 2073 | tcon->retry = volume_info.retry; |
Steve French | d3485d3 | 2005-08-19 11:04:29 -0700 | [diff] [blame] | 2074 | tcon->nocase = volume_info.nocase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | } else { |
| 2076 | tcon = tconInfoAlloc(); |
| 2077 | if (tcon == NULL) |
| 2078 | rc = -ENOMEM; |
| 2079 | else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2080 | /* check for null share name ie connecting to |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2081 | * dfs root */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2083 | /* BB check if this works for exactly length |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2084 | * three strings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | if ((strchr(volume_info.UNC + 3, '\\') == NULL) |
| 2086 | && (strchr(volume_info.UNC + 3, '/') == |
| 2087 | NULL)) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2088 | rc = connect_to_dfs_path(xid, pSesInfo, |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2089 | "", cifs_sb->local_nls, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2090 | cifs_sb->mnt_cifs_flags & |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2091 | CIFS_MOUNT_MAP_SPECIAL_CHR); |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 2092 | kfree(volume_info.UNC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | FreeXid(xid); |
| 2094 | return -ENODEV; |
| 2095 | } else { |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2096 | /* BB Do we need to wrap sesSem around |
| 2097 | * this TCon call and Unix SetFS as |
| 2098 | * we do on SessSetup and reconnect? */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2099 | rc = CIFSTCon(xid, pSesInfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | volume_info.UNC, |
| 2101 | tcon, cifs_sb->local_nls); |
| 2102 | cFYI(1, ("CIFS Tcon rc = %d", rc)); |
| 2103 | } |
| 2104 | if (!rc) { |
| 2105 | atomic_inc(&pSesInfo->inUse); |
| 2106 | tcon->retry = volume_info.retry; |
Steve French | d3485d3 | 2005-08-19 11:04:29 -0700 | [diff] [blame] | 2107 | tcon->nocase = volume_info.nocase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | } |
| 2111 | } |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2112 | if (pSesInfo) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2113 | if (pSesInfo->capabilities & CAP_LARGE_FILES) { |
| 2114 | sb->s_maxbytes = (u64) 1 << 63; |
| 2115 | } else |
| 2116 | sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */ |
| 2117 | } |
| 2118 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2119 | /* BB FIXME fix time_gran to be larger for LANMAN sessions */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | sb->s_time_gran = 100; |
| 2121 | |
| 2122 | /* on error free sesinfo and tcon struct if needed */ |
| 2123 | if (rc) { |
| 2124 | /* if session setup failed, use count is zero but |
| 2125 | we still need to free cifsd thread */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2126 | if (atomic_read(&srvTcp->socketUseCount) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | spin_lock(&GlobalMid_Lock); |
| 2128 | srvTcp->tcpStatus = CifsExiting; |
| 2129 | spin_unlock(&GlobalMid_Lock); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2130 | if (srvTcp->tsk) { |
Steve French | 28356a1 | 2007-05-23 14:45:36 +0000 | [diff] [blame] | 2131 | struct task_struct *tsk; |
| 2132 | /* If we could verify that kthread_stop would |
| 2133 | always wake up processes blocked in |
| 2134 | tcp in recv_mesg then we could remove the |
| 2135 | send_sig call */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2136 | force_sig(SIGKILL, srvTcp->tsk); |
Steve French | 28356a1 | 2007-05-23 14:45:36 +0000 | [diff] [blame] | 2137 | tsk = srvTcp->tsk; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2138 | if (tsk) |
Steve French | f7f7c31 | 2007-05-24 02:29:51 +0000 | [diff] [blame] | 2139 | kthread_stop(tsk); |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 2140 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | } |
| 2142 | /* If find_unc succeeded then rc == 0 so we can not end */ |
| 2143 | if (tcon) /* up accidently freeing someone elses tcon struct */ |
| 2144 | tconInfoFree(tcon); |
| 2145 | if (existingCifsSes == NULL) { |
| 2146 | if (pSesInfo) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2147 | if ((pSesInfo->server) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | (pSesInfo->status == CifsGood)) { |
| 2149 | int temp_rc; |
| 2150 | temp_rc = CIFSSMBLogoff(xid, pSesInfo); |
| 2151 | /* if the socketUseCount is now zero */ |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2152 | if ((temp_rc == -ESHUTDOWN) && |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2153 | (pSesInfo->server) && |
Jeff | 5d9c720 | 2007-06-25 22:16:35 +0000 | [diff] [blame] | 2154 | (pSesInfo->server->tsk)) { |
Steve French | 28356a1 | 2007-05-23 14:45:36 +0000 | [diff] [blame] | 2155 | struct task_struct *tsk; |
Jeff | 5d9c720 | 2007-06-25 22:16:35 +0000 | [diff] [blame] | 2156 | force_sig(SIGKILL, |
| 2157 | pSesInfo->server->tsk); |
Steve French | 28356a1 | 2007-05-23 14:45:36 +0000 | [diff] [blame] | 2158 | tsk = pSesInfo->server->tsk; |
Steve French | f7f7c31 | 2007-05-24 02:29:51 +0000 | [diff] [blame] | 2159 | if (tsk) |
Steve French | 28356a1 | 2007-05-23 14:45:36 +0000 | [diff] [blame] | 2160 | kthread_stop(tsk); |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 2161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | } else |
| 2163 | cFYI(1, ("No session or bad tcon")); |
| 2164 | sesInfoFree(pSesInfo); |
| 2165 | /* pSesInfo = NULL; */ |
| 2166 | } |
| 2167 | } |
| 2168 | } else { |
| 2169 | atomic_inc(&tcon->useCount); |
| 2170 | cifs_sb->tcon = tcon; |
| 2171 | tcon->ses = pSesInfo; |
| 2172 | |
Steve French | 82940a4 | 2006-03-02 03:24:57 +0000 | [diff] [blame] | 2173 | /* do not care if following two calls succeed - informational */ |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2174 | CIFSSMBQFSDeviceInfo(xid, tcon); |
| 2175 | CIFSSMBQFSAttributeInfo(xid, tcon); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2176 | |
Steve French | 8af1897 | 2007-02-14 04:42:51 +0000 | [diff] [blame] | 2177 | /* tell server which Unix caps we support */ |
| 2178 | if (tcon->ses->capabilities & CAP_UNIX) |
| 2179 | reset_cifs_unix_caps(xid, tcon, sb, &volume_info); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2180 | else if (cifs_sb->rsize > (1024 * 127)) { |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 2181 | cifs_sb->rsize = 1024 * 127; |
| 2182 | #ifdef CONFIG_CIFS_DEBUG2 |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 2183 | cFYI(1, ("no very large read support, rsize 127K")); |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 2184 | #endif |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2185 | |
Steve French | 75865f8 | 2007-06-24 18:30:48 +0000 | [diff] [blame] | 2186 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 2187 | if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X)) |
| 2188 | cifs_sb->wsize = min(cifs_sb->wsize, |
| 2189 | (tcon->ses->server->maxBuf - |
| 2190 | MAX_CIFS_HDR_SIZE)); |
Steve French | 0ae0efa | 2005-10-10 10:57:19 -0700 | [diff] [blame] | 2191 | if (!(tcon->ses->capabilities & CAP_LARGE_READ_X)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2192 | cifs_sb->rsize = min(cifs_sb->rsize, |
| 2193 | (tcon->ses->server->maxBuf - |
| 2194 | MAX_CIFS_HDR_SIZE)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | } |
| 2196 | |
| 2197 | /* volume_info.password is freed above when existing session found |
| 2198 | (in which case it is not needed anymore) but when new sesion is created |
| 2199 | the password ptr is put in the new session structure (in which case the |
| 2200 | password will be freed at unmount time) */ |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 2201 | kfree(volume_info.UNC); |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 2202 | kfree(volume_info.prepath); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | FreeXid(xid); |
| 2204 | return rc; |
| 2205 | } |
| 2206 | |
| 2207 | static int |
| 2208 | CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses, |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2209 | char session_key[CIFS_SESS_KEY_SIZE], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | const struct nls_table *nls_codepage) |
| 2211 | { |
| 2212 | struct smb_hdr *smb_buffer; |
| 2213 | struct smb_hdr *smb_buffer_response; |
| 2214 | SESSION_SETUP_ANDX *pSMB; |
| 2215 | SESSION_SETUP_ANDX *pSMBr; |
| 2216 | char *bcc_ptr; |
| 2217 | char *user; |
| 2218 | char *domain; |
| 2219 | int rc = 0; |
| 2220 | int remaining_words = 0; |
| 2221 | int bytes_returned = 0; |
| 2222 | int len; |
| 2223 | __u32 capabilities; |
| 2224 | __u16 count; |
| 2225 | |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 2226 | cFYI(1, ("In sesssetup")); |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2227 | if (ses == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | return -EINVAL; |
| 2229 | user = ses->userName; |
| 2230 | domain = ses->domainName; |
| 2231 | smb_buffer = cifs_buf_get(); |
| 2232 | if (smb_buffer == NULL) { |
| 2233 | return -ENOMEM; |
| 2234 | } |
| 2235 | smb_buffer_response = smb_buffer; |
| 2236 | pSMBr = pSMB = (SESSION_SETUP_ANDX *) smb_buffer; |
| 2237 | |
| 2238 | /* send SMBsessionSetup here */ |
| 2239 | header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX, |
| 2240 | NULL /* no tCon exists yet */ , 13 /* wct */ ); |
| 2241 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 2242 | smb_buffer->Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | pSMB->req_no_secext.AndXCommand = 0xFF; |
| 2244 | pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); |
| 2245 | pSMB->req_no_secext.MaxMpxCount = cpu_to_le16(ses->server->maxReq); |
| 2246 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2247 | if (ses->server->secMode & |
| 2248 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 2250 | |
| 2251 | capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | |
| 2252 | CAP_LARGE_WRITE_X | CAP_LARGE_READ_X; |
| 2253 | if (ses->capabilities & CAP_UNICODE) { |
| 2254 | smb_buffer->Flags2 |= SMBFLG2_UNICODE; |
| 2255 | capabilities |= CAP_UNICODE; |
| 2256 | } |
| 2257 | if (ses->capabilities & CAP_STATUS32) { |
| 2258 | smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 2259 | capabilities |= CAP_STATUS32; |
| 2260 | } |
| 2261 | if (ses->capabilities & CAP_DFS) { |
| 2262 | smb_buffer->Flags2 |= SMBFLG2_DFS; |
| 2263 | capabilities |= CAP_DFS; |
| 2264 | } |
| 2265 | pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities); |
| 2266 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2267 | pSMB->req_no_secext.CaseInsensitivePasswordLength = |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2268 | cpu_to_le16(CIFS_SESS_KEY_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2269 | |
| 2270 | pSMB->req_no_secext.CaseSensitivePasswordLength = |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2271 | cpu_to_le16(CIFS_SESS_KEY_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | bcc_ptr = pByteArea(smb_buffer); |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2273 | memcpy(bcc_ptr, (char *) session_key, CIFS_SESS_KEY_SIZE); |
| 2274 | bcc_ptr += CIFS_SESS_KEY_SIZE; |
| 2275 | memcpy(bcc_ptr, (char *) session_key, CIFS_SESS_KEY_SIZE); |
| 2276 | bcc_ptr += CIFS_SESS_KEY_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | |
| 2278 | if (ses->capabilities & CAP_UNICODE) { |
| 2279 | if ((long) bcc_ptr % 2) { /* must be word aligned for Unicode */ |
| 2280 | *bcc_ptr = 0; |
| 2281 | bcc_ptr++; |
| 2282 | } |
Steve French | 4523cc3 | 2007-04-30 20:13:06 +0000 | [diff] [blame] | 2283 | if (user == NULL) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 2284 | bytes_returned = 0; /* skip null user */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2285 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | bytes_returned = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2287 | cifs_strtoUCS((__le16 *) bcc_ptr, user, 100, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2288 | nls_codepage); |
| 2289 | /* convert number of 16 bit words to bytes */ |
| 2290 | bcc_ptr += 2 * bytes_returned; |
| 2291 | bcc_ptr += 2; /* trailing null */ |
| 2292 | if (domain == NULL) |
| 2293 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2294 | cifs_strtoUCS((__le16 *) bcc_ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | "CIFS_LINUX_DOM", 32, nls_codepage); |
| 2296 | else |
| 2297 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2298 | cifs_strtoUCS((__le16 *) bcc_ptr, domain, 64, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | nls_codepage); |
| 2300 | bcc_ptr += 2 * bytes_returned; |
| 2301 | bcc_ptr += 2; |
| 2302 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2303 | cifs_strtoUCS((__le16 *) bcc_ptr, "Linux version ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | 32, nls_codepage); |
| 2305 | bcc_ptr += 2 * bytes_returned; |
| 2306 | bytes_returned = |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 2307 | cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | 32, nls_codepage); |
| 2309 | bcc_ptr += 2 * bytes_returned; |
| 2310 | bcc_ptr += 2; |
| 2311 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2312 | cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | 64, nls_codepage); |
| 2314 | bcc_ptr += 2 * bytes_returned; |
| 2315 | bcc_ptr += 2; |
| 2316 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2317 | if (user != NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | strncpy(bcc_ptr, user, 200); |
| 2319 | bcc_ptr += strnlen(user, 200); |
| 2320 | } |
| 2321 | *bcc_ptr = 0; |
| 2322 | bcc_ptr++; |
| 2323 | if (domain == NULL) { |
| 2324 | strcpy(bcc_ptr, "CIFS_LINUX_DOM"); |
| 2325 | bcc_ptr += strlen("CIFS_LINUX_DOM") + 1; |
| 2326 | } else { |
| 2327 | strncpy(bcc_ptr, domain, 64); |
| 2328 | bcc_ptr += strnlen(domain, 64); |
| 2329 | *bcc_ptr = 0; |
| 2330 | bcc_ptr++; |
| 2331 | } |
| 2332 | strcpy(bcc_ptr, "Linux version "); |
| 2333 | bcc_ptr += strlen("Linux version "); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 2334 | strcpy(bcc_ptr, utsname()->release); |
| 2335 | bcc_ptr += strlen(utsname()->release) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | strcpy(bcc_ptr, CIFS_NETWORK_OPSYS); |
| 2337 | bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1; |
| 2338 | } |
| 2339 | count = (long) bcc_ptr - (long) pByteArea(smb_buffer); |
| 2340 | smb_buffer->smb_buf_length += count; |
| 2341 | pSMB->req_no_secext.ByteCount = cpu_to_le16(count); |
| 2342 | |
| 2343 | rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, |
| 2344 | &bytes_returned, 1); |
| 2345 | if (rc) { |
| 2346 | /* rc = map_smb_to_linux_error(smb_buffer_response); now done in SendReceive */ |
| 2347 | } else if ((smb_buffer_response->WordCount == 3) |
| 2348 | || (smb_buffer_response->WordCount == 4)) { |
| 2349 | __u16 action = le16_to_cpu(pSMBr->resp.Action); |
| 2350 | __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength); |
| 2351 | if (action & GUEST_LOGIN) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2352 | cFYI(1, (" Guest login")); /* BB mark SesInfo struct? */ |
| 2353 | ses->Suid = smb_buffer_response->Uid; /* UID left in wire format |
| 2354 | (little endian) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | cFYI(1, ("UID = %d ", ses->Suid)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2356 | /* response can have either 3 or 4 word count - Samba sends 3 */ |
| 2357 | bcc_ptr = pByteArea(smb_buffer_response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | if ((pSMBr->resp.hdr.WordCount == 3) |
| 2359 | || ((pSMBr->resp.hdr.WordCount == 4) |
| 2360 | && (blob_len < pSMBr->resp.ByteCount))) { |
| 2361 | if (pSMBr->resp.hdr.WordCount == 4) |
| 2362 | bcc_ptr += blob_len; |
| 2363 | |
| 2364 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { |
| 2365 | if ((long) (bcc_ptr) % 2) { |
| 2366 | remaining_words = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2367 | (BCC(smb_buffer_response) - 1) / 2; |
| 2368 | /* Unicode strings must be word |
| 2369 | aligned */ |
| 2370 | bcc_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | } else { |
| 2372 | remaining_words = |
| 2373 | BCC(smb_buffer_response) / 2; |
| 2374 | } |
| 2375 | len = |
| 2376 | UniStrnlen((wchar_t *) bcc_ptr, |
| 2377 | remaining_words - 1); |
| 2378 | /* We look for obvious messed up bcc or strings in response so we do not go off |
| 2379 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
| 2380 | terminating last Unicode string in response */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2381 | if (ses->serverOS) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2382 | kfree(ses->serverOS); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2383 | ses->serverOS = kzalloc(2 * (len + 1), |
| 2384 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2385 | if (ses->serverOS == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2386 | goto sesssetup_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | cifs_strfromUCS_le(ses->serverOS, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2388 | (__le16 *)bcc_ptr, |
| 2389 | len, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | bcc_ptr += 2 * (len + 1); |
| 2391 | remaining_words -= len + 1; |
| 2392 | ses->serverOS[2 * len] = 0; |
| 2393 | ses->serverOS[1 + (2 * len)] = 0; |
| 2394 | if (remaining_words > 0) { |
| 2395 | len = UniStrnlen((wchar_t *)bcc_ptr, |
| 2396 | remaining_words-1); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2397 | kfree(ses->serverNOS); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2398 | ses->serverNOS = kzalloc(2 * (len + 1), |
| 2399 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2400 | if (ses->serverNOS == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2401 | goto sesssetup_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | cifs_strfromUCS_le(ses->serverNOS, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2403 | (__le16 *)bcc_ptr, |
| 2404 | len, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2405 | bcc_ptr += 2 * (len + 1); |
| 2406 | ses->serverNOS[2 * len] = 0; |
| 2407 | ses->serverNOS[1 + (2 * len)] = 0; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2408 | if (strncmp(ses->serverNOS, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2409 | "NT LAN Manager 4", 16) == 0) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 2410 | cFYI(1, ("NT4 server")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | ses->flags |= CIFS_SES_NT4; |
| 2412 | } |
| 2413 | remaining_words -= len + 1; |
| 2414 | if (remaining_words > 0) { |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2415 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2416 | /* last string is not always null terminated |
| 2417 | (for e.g. for Windows XP & 2000) */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2418 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2419 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | ses->serverDomain = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2421 | kzalloc(2*(len+1), |
| 2422 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2423 | if (ses->serverDomain == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2424 | goto sesssetup_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | cifs_strfromUCS_le(ses->serverDomain, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2426 | (__le16 *)bcc_ptr, |
| 2427 | len, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | bcc_ptr += 2 * (len + 1); |
| 2429 | ses->serverDomain[2*len] = 0; |
| 2430 | ses->serverDomain[1+(2*len)] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2431 | } else { /* else no more room so create |
| 2432 | dummy domain string */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2433 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2434 | kfree(ses->serverDomain); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2435 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2436 | kzalloc(2, GFP_KERNEL); |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2437 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2438 | } else { /* no room so create dummy domain |
| 2439 | and NOS string */ |
| 2440 | |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2441 | /* if these kcallocs fail not much we |
| 2442 | can do, but better to not fail the |
| 2443 | sesssetup itself */ |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2444 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2446 | kzalloc(2, GFP_KERNEL); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2447 | kfree(ses->serverNOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | ses->serverNOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2449 | kzalloc(2, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2450 | } |
| 2451 | } else { /* ASCII */ |
| 2452 | len = strnlen(bcc_ptr, 1024); |
| 2453 | if (((long) bcc_ptr + len) - (long) |
| 2454 | pByteArea(smb_buffer_response) |
| 2455 | <= BCC(smb_buffer_response)) { |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2456 | kfree(ses->serverOS); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2457 | ses->serverOS = kzalloc(len + 1, |
| 2458 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2459 | if (ses->serverOS == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2460 | goto sesssetup_nomem; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2461 | strncpy(ses->serverOS, bcc_ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
| 2463 | bcc_ptr += len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2464 | /* null terminate the string */ |
| 2465 | bcc_ptr[0] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | bcc_ptr++; |
| 2467 | |
| 2468 | len = strnlen(bcc_ptr, 1024); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2469 | kfree(ses->serverNOS); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2470 | ses->serverNOS = kzalloc(len + 1, |
| 2471 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2472 | if (ses->serverNOS == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2473 | goto sesssetup_nomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | strncpy(ses->serverNOS, bcc_ptr, len); |
| 2475 | bcc_ptr += len; |
| 2476 | bcc_ptr[0] = 0; |
| 2477 | bcc_ptr++; |
| 2478 | |
| 2479 | len = strnlen(bcc_ptr, 1024); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2480 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2481 | kfree(ses->serverDomain); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2482 | ses->serverDomain = kzalloc(len + 1, |
| 2483 | GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2484 | if (ses->serverDomain == NULL) |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2485 | goto sesssetup_nomem; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2486 | strncpy(ses->serverDomain, bcc_ptr, |
| 2487 | len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | bcc_ptr += len; |
| 2489 | bcc_ptr[0] = 0; |
| 2490 | bcc_ptr++; |
| 2491 | } else |
| 2492 | cFYI(1, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2493 | ("Variable field of length %d " |
| 2494 | "extends beyond end of smb ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | len)); |
| 2496 | } |
| 2497 | } else { |
| 2498 | cERROR(1, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2499 | (" Security Blob Length extends beyond " |
| 2500 | "end of SMB")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | } else { |
| 2503 | cERROR(1, |
| 2504 | (" Invalid Word count %d: ", |
| 2505 | smb_buffer_response->WordCount)); |
| 2506 | rc = -EIO; |
| 2507 | } |
Steve French | 433dc24 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 2508 | sesssetup_nomem: /* do not return an error on nomem for the info strings, |
| 2509 | since that could make reconnection harder, and |
| 2510 | reconnection might be needed to free memory */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | if (smb_buffer) |
| 2512 | cifs_buf_release(smb_buffer); |
| 2513 | |
| 2514 | return rc; |
| 2515 | } |
| 2516 | |
| 2517 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | CIFSNTLMSSPNegotiateSessSetup(unsigned int xid, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2519 | struct cifsSesInfo *ses, int *pNTLMv2_flag, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | const struct nls_table *nls_codepage) |
| 2521 | { |
| 2522 | struct smb_hdr *smb_buffer; |
| 2523 | struct smb_hdr *smb_buffer_response; |
| 2524 | SESSION_SETUP_ANDX *pSMB; |
| 2525 | SESSION_SETUP_ANDX *pSMBr; |
| 2526 | char *bcc_ptr; |
| 2527 | char *domain; |
| 2528 | int rc = 0; |
| 2529 | int remaining_words = 0; |
| 2530 | int bytes_returned = 0; |
| 2531 | int len; |
| 2532 | int SecurityBlobLength = sizeof (NEGOTIATE_MESSAGE); |
| 2533 | PNEGOTIATE_MESSAGE SecurityBlob; |
| 2534 | PCHALLENGE_MESSAGE SecurityBlob2; |
| 2535 | __u32 negotiate_flags, capabilities; |
| 2536 | __u16 count; |
| 2537 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2538 | cFYI(1, ("In NTLMSSP sesssetup (negotiate)")); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2539 | if (ses == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | return -EINVAL; |
| 2541 | domain = ses->domainName; |
| 2542 | *pNTLMv2_flag = FALSE; |
| 2543 | smb_buffer = cifs_buf_get(); |
| 2544 | if (smb_buffer == NULL) { |
| 2545 | return -ENOMEM; |
| 2546 | } |
| 2547 | smb_buffer_response = smb_buffer; |
| 2548 | pSMB = (SESSION_SETUP_ANDX *) smb_buffer; |
| 2549 | pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response; |
| 2550 | |
| 2551 | /* send SMBsessionSetup here */ |
| 2552 | header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX, |
| 2553 | NULL /* no tCon exists yet */ , 12 /* wct */ ); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 2554 | |
| 2555 | smb_buffer->Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 2557 | pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT); |
| 2558 | |
| 2559 | pSMB->req.AndXCommand = 0xFF; |
| 2560 | pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); |
| 2561 | pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); |
| 2562 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2563 | if (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2564 | smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 2565 | |
| 2566 | capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | |
| 2567 | CAP_EXTENDED_SECURITY; |
| 2568 | if (ses->capabilities & CAP_UNICODE) { |
| 2569 | smb_buffer->Flags2 |= SMBFLG2_UNICODE; |
| 2570 | capabilities |= CAP_UNICODE; |
| 2571 | } |
| 2572 | if (ses->capabilities & CAP_STATUS32) { |
| 2573 | smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 2574 | capabilities |= CAP_STATUS32; |
| 2575 | } |
| 2576 | if (ses->capabilities & CAP_DFS) { |
| 2577 | smb_buffer->Flags2 |= SMBFLG2_DFS; |
| 2578 | capabilities |= CAP_DFS; |
| 2579 | } |
| 2580 | pSMB->req.Capabilities = cpu_to_le32(capabilities); |
| 2581 | |
| 2582 | bcc_ptr = (char *) &pSMB->req.SecurityBlob; |
| 2583 | SecurityBlob = (PNEGOTIATE_MESSAGE) bcc_ptr; |
| 2584 | strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8); |
| 2585 | SecurityBlob->MessageType = NtLmNegotiate; |
| 2586 | negotiate_flags = |
| 2587 | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_NEGOTIATE_OEM | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2588 | NTLMSSP_REQUEST_TARGET | NTLMSSP_NEGOTIATE_NTLM | |
| 2589 | NTLMSSP_NEGOTIATE_56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN | */ NTLMSSP_NEGOTIATE_128; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2591 | if (sign_CIFS_PDUs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | negotiate_flags |= NTLMSSP_NEGOTIATE_SIGN; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2593 | /* if (ntlmv2_support) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 2594 | negotiate_flags |= NTLMSSP_NEGOTIATE_NTLMV2;*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | /* setup pointers to domain name and workstation name */ |
| 2596 | bcc_ptr += SecurityBlobLength; |
| 2597 | |
| 2598 | SecurityBlob->WorkstationName.Buffer = 0; |
| 2599 | SecurityBlob->WorkstationName.Length = 0; |
| 2600 | SecurityBlob->WorkstationName.MaximumLength = 0; |
| 2601 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2602 | /* Domain not sent on first Sesssetup in NTLMSSP, instead it is sent |
| 2603 | along with username on auth request (ie the response to challenge) */ |
| 2604 | SecurityBlob->DomainName.Buffer = 0; |
| 2605 | SecurityBlob->DomainName.Length = 0; |
| 2606 | SecurityBlob->DomainName.MaximumLength = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | if (ses->capabilities & CAP_UNICODE) { |
| 2608 | if ((long) bcc_ptr % 2) { |
| 2609 | *bcc_ptr = 0; |
| 2610 | bcc_ptr++; |
| 2611 | } |
| 2612 | |
| 2613 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2614 | cifs_strtoUCS((__le16 *) bcc_ptr, "Linux version ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | 32, nls_codepage); |
| 2616 | bcc_ptr += 2 * bytes_returned; |
| 2617 | bytes_returned = |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 2618 | cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, 32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | nls_codepage); |
| 2620 | bcc_ptr += 2 * bytes_returned; |
| 2621 | bcc_ptr += 2; /* null terminate Linux version */ |
| 2622 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2623 | cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | 64, nls_codepage); |
| 2625 | bcc_ptr += 2 * bytes_returned; |
| 2626 | *(bcc_ptr + 1) = 0; |
| 2627 | *(bcc_ptr + 2) = 0; |
| 2628 | bcc_ptr += 2; /* null terminate network opsys string */ |
| 2629 | *(bcc_ptr + 1) = 0; |
| 2630 | *(bcc_ptr + 2) = 0; |
| 2631 | bcc_ptr += 2; /* null domain */ |
| 2632 | } else { /* ASCII */ |
| 2633 | strcpy(bcc_ptr, "Linux version "); |
| 2634 | bcc_ptr += strlen("Linux version "); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 2635 | strcpy(bcc_ptr, utsname()->release); |
| 2636 | bcc_ptr += strlen(utsname()->release) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | strcpy(bcc_ptr, CIFS_NETWORK_OPSYS); |
| 2638 | bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1; |
| 2639 | bcc_ptr++; /* empty domain field */ |
| 2640 | *bcc_ptr = 0; |
| 2641 | } |
| 2642 | SecurityBlob->NegotiateFlags = cpu_to_le32(negotiate_flags); |
| 2643 | pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength); |
| 2644 | count = (long) bcc_ptr - (long) pByteArea(smb_buffer); |
| 2645 | smb_buffer->smb_buf_length += count; |
| 2646 | pSMB->req.ByteCount = cpu_to_le16(count); |
| 2647 | |
| 2648 | rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, |
| 2649 | &bytes_returned, 1); |
| 2650 | |
| 2651 | if (smb_buffer_response->Status.CifsError == |
| 2652 | cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED)) |
| 2653 | rc = 0; |
| 2654 | |
| 2655 | if (rc) { |
| 2656 | /* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */ |
| 2657 | } else if ((smb_buffer_response->WordCount == 3) |
| 2658 | || (smb_buffer_response->WordCount == 4)) { |
| 2659 | __u16 action = le16_to_cpu(pSMBr->resp.Action); |
| 2660 | __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength); |
| 2661 | |
| 2662 | if (action & GUEST_LOGIN) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2663 | cFYI(1, (" Guest login")); |
| 2664 | /* Do we want to set anything in SesInfo struct when guest login? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2666 | bcc_ptr = pByteArea(smb_buffer_response); |
| 2667 | /* response can have either 3 or 4 word count - Samba sends 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | |
| 2669 | SecurityBlob2 = (PCHALLENGE_MESSAGE) bcc_ptr; |
| 2670 | if (SecurityBlob2->MessageType != NtLmChallenge) { |
| 2671 | cFYI(1, |
| 2672 | ("Unexpected NTLMSSP message type received %d", |
| 2673 | SecurityBlob2->MessageType)); |
| 2674 | } else if (ses) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2675 | ses->Suid = smb_buffer_response->Uid; /* UID left in le format */ |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2676 | cFYI(1, ("UID = %d", ses->Suid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | if ((pSMBr->resp.hdr.WordCount == 3) |
| 2678 | || ((pSMBr->resp.hdr.WordCount == 4) |
| 2679 | && (blob_len < |
| 2680 | pSMBr->resp.ByteCount))) { |
| 2681 | |
| 2682 | if (pSMBr->resp.hdr.WordCount == 4) { |
| 2683 | bcc_ptr += blob_len; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2684 | cFYI(1, ("Security Blob Length %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | blob_len)); |
| 2686 | } |
| 2687 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2688 | cFYI(1, ("NTLMSSP Challenge rcvd")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | |
| 2690 | memcpy(ses->server->cryptKey, |
| 2691 | SecurityBlob2->Challenge, |
| 2692 | CIFS_CRYPTO_KEY_SIZE); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2693 | if (SecurityBlob2->NegotiateFlags & |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 2694 | cpu_to_le32(NTLMSSP_NEGOTIATE_NTLMV2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | *pNTLMv2_flag = TRUE; |
| 2696 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2697 | if ((SecurityBlob2->NegotiateFlags & |
| 2698 | cpu_to_le32(NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | || (sign_CIFS_PDUs > 1)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2700 | ses->server->secMode |= |
| 2701 | SECMODE_SIGN_REQUIRED; |
| 2702 | if ((SecurityBlob2->NegotiateFlags & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | cpu_to_le32(NTLMSSP_NEGOTIATE_SIGN)) && (sign_CIFS_PDUs)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2704 | ses->server->secMode |= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2705 | SECMODE_SIGN_ENABLED; |
| 2706 | |
| 2707 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { |
| 2708 | if ((long) (bcc_ptr) % 2) { |
| 2709 | remaining_words = |
| 2710 | (BCC(smb_buffer_response) |
| 2711 | - 1) / 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2712 | /* Must word align unicode strings */ |
| 2713 | bcc_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } else { |
| 2715 | remaining_words = |
| 2716 | BCC |
| 2717 | (smb_buffer_response) / 2; |
| 2718 | } |
| 2719 | len = |
| 2720 | UniStrnlen((wchar_t *) bcc_ptr, |
| 2721 | remaining_words - 1); |
| 2722 | /* We look for obvious messed up bcc or strings in response so we do not go off |
| 2723 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
| 2724 | terminating last Unicode string in response */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2725 | if (ses->serverOS) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2726 | kfree(ses->serverOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | ses->serverOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2728 | kzalloc(2 * (len + 1), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2729 | cifs_strfromUCS_le(ses->serverOS, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2730 | (__le16 *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | bcc_ptr, len, |
| 2732 | nls_codepage); |
| 2733 | bcc_ptr += 2 * (len + 1); |
| 2734 | remaining_words -= len + 1; |
| 2735 | ses->serverOS[2 * len] = 0; |
| 2736 | ses->serverOS[1 + (2 * len)] = 0; |
| 2737 | if (remaining_words > 0) { |
| 2738 | len = UniStrnlen((wchar_t *) |
| 2739 | bcc_ptr, |
| 2740 | remaining_words |
| 2741 | - 1); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2742 | kfree(ses->serverNOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | ses->serverNOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2744 | kzalloc(2 * (len + 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | GFP_KERNEL); |
| 2746 | cifs_strfromUCS_le(ses-> |
| 2747 | serverNOS, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2748 | (__le16 *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | bcc_ptr, |
| 2750 | len, |
| 2751 | nls_codepage); |
| 2752 | bcc_ptr += 2 * (len + 1); |
| 2753 | ses->serverNOS[2 * len] = 0; |
| 2754 | ses->serverNOS[1 + |
| 2755 | (2 * len)] = 0; |
| 2756 | remaining_words -= len + 1; |
| 2757 | if (remaining_words > 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2758 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); |
| 2759 | /* last string not always null terminated |
| 2760 | (for e.g. for Windows XP & 2000) */ |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2761 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2763 | kzalloc(2 * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | (len + |
| 2765 | 1), |
| 2766 | GFP_KERNEL); |
| 2767 | cifs_strfromUCS_le |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2768 | (ses->serverDomain, |
| 2769 | (__le16 *)bcc_ptr, |
| 2770 | len, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | bcc_ptr += |
| 2772 | 2 * (len + 1); |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2773 | ses->serverDomain[2*len] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | = 0; |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2775 | ses->serverDomain |
| 2776 | [1 + (2 * len)] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | = 0; |
| 2778 | } /* else no more room so create dummy domain string */ |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2779 | else { |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2780 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2782 | kzalloc(2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | GFP_KERNEL); |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2785 | } else { /* no room so create dummy domain and NOS string */ |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2786 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2788 | kzalloc(2, GFP_KERNEL); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2789 | kfree(ses->serverNOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | ses->serverNOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2791 | kzalloc(2, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
| 2793 | } else { /* ASCII */ |
| 2794 | len = strnlen(bcc_ptr, 1024); |
| 2795 | if (((long) bcc_ptr + len) - (long) |
| 2796 | pByteArea(smb_buffer_response) |
| 2797 | <= BCC(smb_buffer_response)) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2798 | if (ses->serverOS) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 2799 | kfree(ses->serverOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | ses->serverOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2801 | kzalloc(len + 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | GFP_KERNEL); |
| 2803 | strncpy(ses->serverOS, |
| 2804 | bcc_ptr, len); |
| 2805 | |
| 2806 | bcc_ptr += len; |
| 2807 | bcc_ptr[0] = 0; /* null terminate string */ |
| 2808 | bcc_ptr++; |
| 2809 | |
| 2810 | len = strnlen(bcc_ptr, 1024); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2811 | kfree(ses->serverNOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | ses->serverNOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2813 | kzalloc(len + 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | GFP_KERNEL); |
| 2815 | strncpy(ses->serverNOS, bcc_ptr, len); |
| 2816 | bcc_ptr += len; |
| 2817 | bcc_ptr[0] = 0; |
| 2818 | bcc_ptr++; |
| 2819 | |
| 2820 | len = strnlen(bcc_ptr, 1024); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 2821 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 2823 | kzalloc(len + 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | GFP_KERNEL); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2825 | strncpy(ses->serverDomain, |
| 2826 | bcc_ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | bcc_ptr += len; |
| 2828 | bcc_ptr[0] = 0; |
| 2829 | bcc_ptr++; |
| 2830 | } else |
| 2831 | cFYI(1, |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 2832 | ("field of length %d " |
| 2833 | "extends beyond end of smb", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | len)); |
| 2835 | } |
| 2836 | } else { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2837 | cERROR(1, ("Security Blob Length extends beyond" |
| 2838 | " end of SMB")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2839 | } |
| 2840 | } else { |
| 2841 | cERROR(1, ("No session structure passed in.")); |
| 2842 | } |
| 2843 | } else { |
| 2844 | cERROR(1, |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 2845 | (" Invalid Word count %d:", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | smb_buffer_response->WordCount)); |
| 2847 | rc = -EIO; |
| 2848 | } |
| 2849 | |
| 2850 | if (smb_buffer) |
| 2851 | cifs_buf_release(smb_buffer); |
| 2852 | |
| 2853 | return rc; |
| 2854 | } |
| 2855 | static int |
| 2856 | CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses, |
| 2857 | char *ntlm_session_key, int ntlmv2_flag, |
| 2858 | const struct nls_table *nls_codepage) |
| 2859 | { |
| 2860 | struct smb_hdr *smb_buffer; |
| 2861 | struct smb_hdr *smb_buffer_response; |
| 2862 | SESSION_SETUP_ANDX *pSMB; |
| 2863 | SESSION_SETUP_ANDX *pSMBr; |
| 2864 | char *bcc_ptr; |
| 2865 | char *user; |
| 2866 | char *domain; |
| 2867 | int rc = 0; |
| 2868 | int remaining_words = 0; |
| 2869 | int bytes_returned = 0; |
| 2870 | int len; |
| 2871 | int SecurityBlobLength = sizeof (AUTHENTICATE_MESSAGE); |
| 2872 | PAUTHENTICATE_MESSAGE SecurityBlob; |
| 2873 | __u32 negotiate_flags, capabilities; |
| 2874 | __u16 count; |
| 2875 | |
| 2876 | cFYI(1, ("In NTLMSSPSessSetup (Authenticate)")); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2877 | if (ses == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2878 | return -EINVAL; |
| 2879 | user = ses->userName; |
| 2880 | domain = ses->domainName; |
| 2881 | smb_buffer = cifs_buf_get(); |
| 2882 | if (smb_buffer == NULL) { |
| 2883 | return -ENOMEM; |
| 2884 | } |
| 2885 | smb_buffer_response = smb_buffer; |
| 2886 | pSMB = (SESSION_SETUP_ANDX *) smb_buffer; |
| 2887 | pSMBr = (SESSION_SETUP_ANDX *) smb_buffer_response; |
| 2888 | |
| 2889 | /* send SMBsessionSetup here */ |
| 2890 | header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX, |
| 2891 | NULL /* no tCon exists yet */ , 12 /* wct */ ); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 2892 | |
| 2893 | smb_buffer->Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT); |
| 2895 | pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 2896 | pSMB->req.AndXCommand = 0xFF; |
| 2897 | pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); |
| 2898 | pSMB->req.MaxMpxCount = cpu_to_le16(ses->server->maxReq); |
| 2899 | |
| 2900 | pSMB->req.hdr.Uid = ses->Suid; |
| 2901 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2902 | if (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2903 | smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 2904 | |
| 2905 | capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | |
| 2906 | CAP_EXTENDED_SECURITY; |
| 2907 | if (ses->capabilities & CAP_UNICODE) { |
| 2908 | smb_buffer->Flags2 |= SMBFLG2_UNICODE; |
| 2909 | capabilities |= CAP_UNICODE; |
| 2910 | } |
| 2911 | if (ses->capabilities & CAP_STATUS32) { |
| 2912 | smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 2913 | capabilities |= CAP_STATUS32; |
| 2914 | } |
| 2915 | if (ses->capabilities & CAP_DFS) { |
| 2916 | smb_buffer->Flags2 |= SMBFLG2_DFS; |
| 2917 | capabilities |= CAP_DFS; |
| 2918 | } |
| 2919 | pSMB->req.Capabilities = cpu_to_le32(capabilities); |
| 2920 | |
| 2921 | bcc_ptr = (char *) &pSMB->req.SecurityBlob; |
| 2922 | SecurityBlob = (PAUTHENTICATE_MESSAGE) bcc_ptr; |
| 2923 | strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8); |
| 2924 | SecurityBlob->MessageType = NtLmAuthenticate; |
| 2925 | bcc_ptr += SecurityBlobLength; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2926 | negotiate_flags = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2927 | NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET | |
| 2928 | NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO | |
| 2929 | 0x80000000 | NTLMSSP_NEGOTIATE_128; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2930 | if (sign_CIFS_PDUs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | negotiate_flags |= /* NTLMSSP_NEGOTIATE_ALWAYS_SIGN |*/ NTLMSSP_NEGOTIATE_SIGN; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 2932 | if (ntlmv2_flag) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | negotiate_flags |= NTLMSSP_NEGOTIATE_NTLMV2; |
| 2934 | |
| 2935 | /* setup pointers to domain name and workstation name */ |
| 2936 | |
| 2937 | SecurityBlob->WorkstationName.Buffer = 0; |
| 2938 | SecurityBlob->WorkstationName.Length = 0; |
| 2939 | SecurityBlob->WorkstationName.MaximumLength = 0; |
| 2940 | SecurityBlob->SessionKey.Length = 0; |
| 2941 | SecurityBlob->SessionKey.MaximumLength = 0; |
| 2942 | SecurityBlob->SessionKey.Buffer = 0; |
| 2943 | |
| 2944 | SecurityBlob->LmChallengeResponse.Length = 0; |
| 2945 | SecurityBlob->LmChallengeResponse.MaximumLength = 0; |
| 2946 | SecurityBlob->LmChallengeResponse.Buffer = 0; |
| 2947 | |
| 2948 | SecurityBlob->NtChallengeResponse.Length = |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2949 | cpu_to_le16(CIFS_SESS_KEY_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | SecurityBlob->NtChallengeResponse.MaximumLength = |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2951 | cpu_to_le16(CIFS_SESS_KEY_SIZE); |
| 2952 | memcpy(bcc_ptr, ntlm_session_key, CIFS_SESS_KEY_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2953 | SecurityBlob->NtChallengeResponse.Buffer = |
| 2954 | cpu_to_le32(SecurityBlobLength); |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 2955 | SecurityBlobLength += CIFS_SESS_KEY_SIZE; |
| 2956 | bcc_ptr += CIFS_SESS_KEY_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
| 2958 | if (ses->capabilities & CAP_UNICODE) { |
| 2959 | if (domain == NULL) { |
| 2960 | SecurityBlob->DomainName.Buffer = 0; |
| 2961 | SecurityBlob->DomainName.Length = 0; |
| 2962 | SecurityBlob->DomainName.MaximumLength = 0; |
| 2963 | } else { |
| 2964 | __u16 len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2965 | cifs_strtoUCS((__le16 *) bcc_ptr, domain, 64, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2966 | nls_codepage); |
| 2967 | len *= 2; |
| 2968 | SecurityBlob->DomainName.MaximumLength = |
| 2969 | cpu_to_le16(len); |
| 2970 | SecurityBlob->DomainName.Buffer = |
| 2971 | cpu_to_le32(SecurityBlobLength); |
| 2972 | bcc_ptr += len; |
| 2973 | SecurityBlobLength += len; |
| 2974 | SecurityBlob->DomainName.Length = |
| 2975 | cpu_to_le16(len); |
| 2976 | } |
| 2977 | if (user == NULL) { |
| 2978 | SecurityBlob->UserName.Buffer = 0; |
| 2979 | SecurityBlob->UserName.Length = 0; |
| 2980 | SecurityBlob->UserName.MaximumLength = 0; |
| 2981 | } else { |
| 2982 | __u16 len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2983 | cifs_strtoUCS((__le16 *) bcc_ptr, user, 64, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | nls_codepage); |
| 2985 | len *= 2; |
| 2986 | SecurityBlob->UserName.MaximumLength = |
| 2987 | cpu_to_le16(len); |
| 2988 | SecurityBlob->UserName.Buffer = |
| 2989 | cpu_to_le32(SecurityBlobLength); |
| 2990 | bcc_ptr += len; |
| 2991 | SecurityBlobLength += len; |
| 2992 | SecurityBlob->UserName.Length = |
| 2993 | cpu_to_le16(len); |
| 2994 | } |
| 2995 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 2996 | /* SecurityBlob->WorkstationName.Length = |
| 2997 | cifs_strtoUCS((__le16 *) bcc_ptr, "AMACHINE",64, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | SecurityBlob->WorkstationName.Length *= 2; |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 2999 | SecurityBlob->WorkstationName.MaximumLength = |
| 3000 | cpu_to_le16(SecurityBlob->WorkstationName.Length); |
| 3001 | SecurityBlob->WorkstationName.Buffer = |
| 3002 | cpu_to_le32(SecurityBlobLength); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | bcc_ptr += SecurityBlob->WorkstationName.Length; |
| 3004 | SecurityBlobLength += SecurityBlob->WorkstationName.Length; |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3005 | SecurityBlob->WorkstationName.Length = |
| 3006 | cpu_to_le16(SecurityBlob->WorkstationName.Length); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3007 | |
| 3008 | if ((long) bcc_ptr % 2) { |
| 3009 | *bcc_ptr = 0; |
| 3010 | bcc_ptr++; |
| 3011 | } |
| 3012 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3013 | cifs_strtoUCS((__le16 *) bcc_ptr, "Linux version ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3014 | 32, nls_codepage); |
| 3015 | bcc_ptr += 2 * bytes_returned; |
| 3016 | bytes_returned = |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 3017 | cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, 32, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | nls_codepage); |
| 3019 | bcc_ptr += 2 * bytes_returned; |
| 3020 | bcc_ptr += 2; /* null term version string */ |
| 3021 | bytes_returned = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3022 | cifs_strtoUCS((__le16 *) bcc_ptr, CIFS_NETWORK_OPSYS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | 64, nls_codepage); |
| 3024 | bcc_ptr += 2 * bytes_returned; |
| 3025 | *(bcc_ptr + 1) = 0; |
| 3026 | *(bcc_ptr + 2) = 0; |
| 3027 | bcc_ptr += 2; /* null terminate network opsys string */ |
| 3028 | *(bcc_ptr + 1) = 0; |
| 3029 | *(bcc_ptr + 2) = 0; |
| 3030 | bcc_ptr += 2; /* null domain */ |
| 3031 | } else { /* ASCII */ |
| 3032 | if (domain == NULL) { |
| 3033 | SecurityBlob->DomainName.Buffer = 0; |
| 3034 | SecurityBlob->DomainName.Length = 0; |
| 3035 | SecurityBlob->DomainName.MaximumLength = 0; |
| 3036 | } else { |
| 3037 | __u16 len; |
| 3038 | negotiate_flags |= NTLMSSP_NEGOTIATE_DOMAIN_SUPPLIED; |
| 3039 | strncpy(bcc_ptr, domain, 63); |
| 3040 | len = strnlen(domain, 64); |
| 3041 | SecurityBlob->DomainName.MaximumLength = |
| 3042 | cpu_to_le16(len); |
| 3043 | SecurityBlob->DomainName.Buffer = |
| 3044 | cpu_to_le32(SecurityBlobLength); |
| 3045 | bcc_ptr += len; |
| 3046 | SecurityBlobLength += len; |
| 3047 | SecurityBlob->DomainName.Length = cpu_to_le16(len); |
| 3048 | } |
| 3049 | if (user == NULL) { |
| 3050 | SecurityBlob->UserName.Buffer = 0; |
| 3051 | SecurityBlob->UserName.Length = 0; |
| 3052 | SecurityBlob->UserName.MaximumLength = 0; |
| 3053 | } else { |
| 3054 | __u16 len; |
| 3055 | strncpy(bcc_ptr, user, 63); |
| 3056 | len = strnlen(user, 64); |
| 3057 | SecurityBlob->UserName.MaximumLength = |
| 3058 | cpu_to_le16(len); |
| 3059 | SecurityBlob->UserName.Buffer = |
| 3060 | cpu_to_le32(SecurityBlobLength); |
| 3061 | bcc_ptr += len; |
| 3062 | SecurityBlobLength += len; |
| 3063 | SecurityBlob->UserName.Length = cpu_to_le16(len); |
| 3064 | } |
| 3065 | /* BB fill in our workstation name if known BB */ |
| 3066 | |
| 3067 | strcpy(bcc_ptr, "Linux version "); |
| 3068 | bcc_ptr += strlen("Linux version "); |
Serge E. Hallyn | e9ff399 | 2006-10-02 02:18:11 -0700 | [diff] [blame] | 3069 | strcpy(bcc_ptr, utsname()->release); |
| 3070 | bcc_ptr += strlen(utsname()->release) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3071 | strcpy(bcc_ptr, CIFS_NETWORK_OPSYS); |
| 3072 | bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1; |
| 3073 | bcc_ptr++; /* null domain */ |
| 3074 | *bcc_ptr = 0; |
| 3075 | } |
| 3076 | SecurityBlob->NegotiateFlags = cpu_to_le32(negotiate_flags); |
| 3077 | pSMB->req.SecurityBlobLength = cpu_to_le16(SecurityBlobLength); |
| 3078 | count = (long) bcc_ptr - (long) pByteArea(smb_buffer); |
| 3079 | smb_buffer->smb_buf_length += count; |
| 3080 | pSMB->req.ByteCount = cpu_to_le16(count); |
| 3081 | |
| 3082 | rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, |
| 3083 | &bytes_returned, 1); |
| 3084 | if (rc) { |
| 3085 | /* rc = map_smb_to_linux_error(smb_buffer_response); *//* done in SendReceive now */ |
| 3086 | } else if ((smb_buffer_response->WordCount == 3) |
| 3087 | || (smb_buffer_response->WordCount == 4)) { |
| 3088 | __u16 action = le16_to_cpu(pSMBr->resp.Action); |
| 3089 | __u16 blob_len = |
| 3090 | le16_to_cpu(pSMBr->resp.SecurityBlobLength); |
| 3091 | if (action & GUEST_LOGIN) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3092 | cFYI(1, (" Guest login")); /* BB Should we set anything |
| 3093 | in SesInfo struct ? */ |
| 3094 | /* if (SecurityBlob2->MessageType != NtLm??) { |
| 3095 | cFYI("Unexpected message type on auth response is %d")); |
| 3096 | } */ |
| 3097 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3098 | if (ses) { |
| 3099 | cFYI(1, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3100 | ("Check challenge UID %d vs auth response UID %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | ses->Suid, smb_buffer_response->Uid)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3102 | /* UID left in wire format */ |
| 3103 | ses->Suid = smb_buffer_response->Uid; |
| 3104 | bcc_ptr = pByteArea(smb_buffer_response); |
| 3105 | /* response can have either 3 or 4 word count - Samba sends 3 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | if ((pSMBr->resp.hdr.WordCount == 3) |
| 3107 | || ((pSMBr->resp.hdr.WordCount == 4) |
| 3108 | && (blob_len < |
| 3109 | pSMBr->resp.ByteCount))) { |
| 3110 | if (pSMBr->resp.hdr.WordCount == 4) { |
| 3111 | bcc_ptr += |
| 3112 | blob_len; |
| 3113 | cFYI(1, |
| 3114 | ("Security Blob Length %d ", |
| 3115 | blob_len)); |
| 3116 | } |
| 3117 | |
| 3118 | cFYI(1, |
| 3119 | ("NTLMSSP response to Authenticate ")); |
| 3120 | |
| 3121 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { |
| 3122 | if ((long) (bcc_ptr) % 2) { |
| 3123 | remaining_words = |
| 3124 | (BCC(smb_buffer_response) |
| 3125 | - 1) / 2; |
| 3126 | bcc_ptr++; /* Unicode strings must be word aligned */ |
| 3127 | } else { |
| 3128 | remaining_words = BCC(smb_buffer_response) / 2; |
| 3129 | } |
| 3130 | len = |
| 3131 | UniStrnlen((wchar_t *) bcc_ptr,remaining_words - 1); |
| 3132 | /* We look for obvious messed up bcc or strings in response so we do not go off |
| 3133 | the end since (at least) WIN2K and Windows XP have a major bug in not null |
| 3134 | terminating last Unicode string in response */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3135 | if (ses->serverOS) |
Steve French | 0877583 | 2006-05-30 18:08:26 +0000 | [diff] [blame] | 3136 | kfree(ses->serverOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | ses->serverOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3138 | kzalloc(2 * (len + 1), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | cifs_strfromUCS_le(ses->serverOS, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3140 | (__le16 *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3141 | bcc_ptr, len, |
| 3142 | nls_codepage); |
| 3143 | bcc_ptr += 2 * (len + 1); |
| 3144 | remaining_words -= len + 1; |
| 3145 | ses->serverOS[2 * len] = 0; |
| 3146 | ses->serverOS[1 + (2 * len)] = 0; |
| 3147 | if (remaining_words > 0) { |
| 3148 | len = UniStrnlen((wchar_t *) |
| 3149 | bcc_ptr, |
| 3150 | remaining_words |
| 3151 | - 1); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 3152 | kfree(ses->serverNOS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3153 | ses->serverNOS = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3154 | kzalloc(2 * (len + 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | GFP_KERNEL); |
| 3156 | cifs_strfromUCS_le(ses-> |
| 3157 | serverNOS, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3158 | (__le16 *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | bcc_ptr, |
| 3160 | len, |
| 3161 | nls_codepage); |
| 3162 | bcc_ptr += 2 * (len + 1); |
| 3163 | ses->serverNOS[2 * len] = 0; |
| 3164 | ses->serverNOS[1+(2*len)] = 0; |
| 3165 | remaining_words -= len + 1; |
| 3166 | if (remaining_words > 0) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3167 | len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | /* last string not always null terminated (e.g. for Windows XP & 2000) */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3169 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3170 | kfree(ses->serverDomain); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | ses->serverDomain = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3172 | kzalloc(2 * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | (len + |
| 3174 | 1), |
| 3175 | GFP_KERNEL); |
| 3176 | cifs_strfromUCS_le |
| 3177 | (ses-> |
| 3178 | serverDomain, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3179 | (__le16 *) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | bcc_ptr, len, |
| 3181 | nls_codepage); |
| 3182 | bcc_ptr += |
| 3183 | 2 * (len + 1); |
| 3184 | ses-> |
| 3185 | serverDomain[2 |
| 3186 | * len] |
| 3187 | = 0; |
| 3188 | ses-> |
| 3189 | serverDomain[1 |
| 3190 | + |
| 3191 | (2 |
| 3192 | * |
| 3193 | len)] |
| 3194 | = 0; |
| 3195 | } /* else no more room so create dummy domain string */ |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3196 | else { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3197 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3198 | kfree(ses->serverDomain); |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3199 | ses->serverDomain = kzalloc(2,GFP_KERNEL); |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3200 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | } else { /* no room so create dummy domain and NOS string */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3202 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3203 | kfree(ses->serverDomain); |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3204 | ses->serverDomain = kzalloc(2, GFP_KERNEL); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 3205 | kfree(ses->serverNOS); |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3206 | ses->serverNOS = kzalloc(2, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | } |
| 3208 | } else { /* ASCII */ |
| 3209 | len = strnlen(bcc_ptr, 1024); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3210 | if (((long) bcc_ptr + len) - |
| 3211 | (long) pByteArea(smb_buffer_response) |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3212 | <= BCC(smb_buffer_response)) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3213 | if (ses->serverOS) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3214 | kfree(ses->serverOS); |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3215 | ses->serverOS = kzalloc(len + 1,GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | strncpy(ses->serverOS,bcc_ptr, len); |
| 3217 | |
| 3218 | bcc_ptr += len; |
| 3219 | bcc_ptr[0] = 0; /* null terminate the string */ |
| 3220 | bcc_ptr++; |
| 3221 | |
| 3222 | len = strnlen(bcc_ptr, 1024); |
Steve French | cd49b49 | 2006-06-26 04:22:36 +0000 | [diff] [blame] | 3223 | kfree(ses->serverNOS); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3224 | ses->serverNOS = kzalloc(len+1, |
| 3225 | GFP_KERNEL); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3226 | strncpy(ses->serverNOS, |
| 3227 | bcc_ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | bcc_ptr += len; |
| 3229 | bcc_ptr[0] = 0; |
| 3230 | bcc_ptr++; |
| 3231 | |
| 3232 | len = strnlen(bcc_ptr, 1024); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3233 | if (ses->serverDomain) |
Steve French | a424f8b | 2006-05-30 18:06:04 +0000 | [diff] [blame] | 3234 | kfree(ses->serverDomain); |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3235 | ses->serverDomain = |
| 3236 | kzalloc(len+1, |
| 3237 | GFP_KERNEL); |
| 3238 | strncpy(ses->serverDomain, |
| 3239 | bcc_ptr, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | bcc_ptr += len; |
| 3241 | bcc_ptr[0] = 0; |
| 3242 | bcc_ptr++; |
| 3243 | } else |
| 3244 | cFYI(1, |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3245 | ("field of length %d " |
| 3246 | "extends beyond end of smb ", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | len)); |
| 3248 | } |
| 3249 | } else { |
| 3250 | cERROR(1, |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame^] | 3251 | (" Security Blob extends beyond end " |
| 3252 | "of SMB")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | } else { |
| 3255 | cERROR(1, ("No session structure passed in.")); |
| 3256 | } |
| 3257 | } else { |
| 3258 | cERROR(1, |
| 3259 | (" Invalid Word count %d: ", |
| 3260 | smb_buffer_response->WordCount)); |
| 3261 | rc = -EIO; |
| 3262 | } |
| 3263 | |
| 3264 | if (smb_buffer) |
| 3265 | cifs_buf_release(smb_buffer); |
| 3266 | |
| 3267 | return rc; |
| 3268 | } |
| 3269 | |
| 3270 | int |
| 3271 | CIFSTCon(unsigned int xid, struct cifsSesInfo *ses, |
| 3272 | const char *tree, struct cifsTconInfo *tcon, |
| 3273 | const struct nls_table *nls_codepage) |
| 3274 | { |
| 3275 | struct smb_hdr *smb_buffer; |
| 3276 | struct smb_hdr *smb_buffer_response; |
| 3277 | TCONX_REQ *pSMB; |
| 3278 | TCONX_RSP *pSMBr; |
| 3279 | unsigned char *bcc_ptr; |
| 3280 | int rc = 0; |
| 3281 | int length; |
| 3282 | __u16 count; |
| 3283 | |
| 3284 | if (ses == NULL) |
| 3285 | return -EIO; |
| 3286 | |
| 3287 | smb_buffer = cifs_buf_get(); |
| 3288 | if (smb_buffer == NULL) { |
| 3289 | return -ENOMEM; |
| 3290 | } |
| 3291 | smb_buffer_response = smb_buffer; |
| 3292 | |
| 3293 | header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX, |
| 3294 | NULL /*no tid */ , 4 /*wct */ ); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 3295 | |
| 3296 | smb_buffer->Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3297 | smb_buffer->Uid = ses->Suid; |
| 3298 | pSMB = (TCONX_REQ *) smb_buffer; |
| 3299 | pSMBr = (TCONX_RSP *) smb_buffer_response; |
| 3300 | |
| 3301 | pSMB->AndXCommand = 0xFF; |
| 3302 | pSMB->Flags = cpu_to_le16(TCON_EXTENDED_SECINFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | bcc_ptr = &pSMB->Password[0]; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3304 | if ((ses->server->secMode) & SECMODE_USER) { |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3305 | pSMB->PasswordLength = cpu_to_le16(1); /* minimum */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3306 | *bcc_ptr = 0; /* password is null byte */ |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3307 | bcc_ptr++; /* skip password */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3308 | /* already aligned so no need to do it below */ |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3309 | } else { |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3310 | pSMB->PasswordLength = cpu_to_le16(CIFS_SESS_KEY_SIZE); |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3311 | /* BB FIXME add code to fail this if NTLMv2 or Kerberos |
| 3312 | specified as required (when that support is added to |
| 3313 | the vfs in the future) as only NTLM or the much |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3314 | weaker LANMAN (which we do not send by default) is accepted |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3315 | by Samba (not sure whether other servers allow |
| 3316 | NTLMv2 password here) */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3317 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3318 | if ((extended_security & CIFSSEC_MAY_LANMAN) && |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3319 | (ses->server->secType == LANMAN)) |
| 3320 | calc_lanman_hash(ses, bcc_ptr); |
| 3321 | else |
| 3322 | #endif /* CIFS_WEAK_PW_HASH */ |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3323 | SMBNTencrypt(ses->password, |
| 3324 | ses->server->cryptKey, |
| 3325 | bcc_ptr); |
| 3326 | |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3327 | bcc_ptr += CIFS_SESS_KEY_SIZE; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3328 | if (ses->capabilities & CAP_UNICODE) { |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3329 | /* must align unicode strings */ |
| 3330 | *bcc_ptr = 0; /* null byte password */ |
| 3331 | bcc_ptr++; |
| 3332 | } |
Steve French | eeac804 | 2006-01-13 21:34:58 -0800 | [diff] [blame] | 3333 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3335 | if (ses->server->secMode & |
Steve French | a878fb2 | 2006-05-30 18:04:19 +0000 | [diff] [blame] | 3336 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 3338 | |
| 3339 | if (ses->capabilities & CAP_STATUS32) { |
| 3340 | smb_buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 3341 | } |
| 3342 | if (ses->capabilities & CAP_DFS) { |
| 3343 | smb_buffer->Flags2 |= SMBFLG2_DFS; |
| 3344 | } |
| 3345 | if (ses->capabilities & CAP_UNICODE) { |
| 3346 | smb_buffer->Flags2 |= SMBFLG2_UNICODE; |
| 3347 | length = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3348 | cifs_strtoUCS((__le16 *) bcc_ptr, tree, |
| 3349 | 6 /* max utf8 char length in bytes */ * |
Steve French | a878fb2 | 2006-05-30 18:04:19 +0000 | [diff] [blame] | 3350 | (/* server len*/ + 256 /* share len */), nls_codepage); |
| 3351 | bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | bcc_ptr += 2; /* skip trailing null */ |
| 3353 | } else { /* ASCII */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3354 | strcpy(bcc_ptr, tree); |
| 3355 | bcc_ptr += strlen(tree) + 1; |
| 3356 | } |
| 3357 | strcpy(bcc_ptr, "?????"); |
| 3358 | bcc_ptr += strlen("?????"); |
| 3359 | bcc_ptr += 1; |
| 3360 | count = bcc_ptr - &pSMB->Password[0]; |
| 3361 | pSMB->hdr.smb_buf_length += count; |
| 3362 | pSMB->ByteCount = cpu_to_le16(count); |
| 3363 | |
| 3364 | rc = SendReceive(xid, ses, smb_buffer, smb_buffer_response, &length, 0); |
| 3365 | |
| 3366 | /* if (rc) rc = map_smb_to_linux_error(smb_buffer_response); */ |
| 3367 | /* above now done in SendReceive */ |
| 3368 | if ((rc == 0) && (tcon != NULL)) { |
| 3369 | tcon->tidStatus = CifsGood; |
| 3370 | tcon->tid = smb_buffer_response->Tid; |
| 3371 | bcc_ptr = pByteArea(smb_buffer_response); |
| 3372 | length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3373 | /* skip service field (NB: this field is always ASCII) */ |
| 3374 | bcc_ptr += length + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | strncpy(tcon->treeName, tree, MAX_TREE_SIZE); |
| 3376 | if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { |
| 3377 | length = UniStrnlen((wchar_t *) bcc_ptr, 512); |
| 3378 | if ((bcc_ptr + (2 * length)) - |
| 3379 | pByteArea(smb_buffer_response) <= |
| 3380 | BCC(smb_buffer_response)) { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 3381 | kfree(tcon->nativeFileSystem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | tcon->nativeFileSystem = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3383 | kzalloc(length + 2, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | cifs_strfromUCS_le(tcon->nativeFileSystem, |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 3385 | (__le16 *) bcc_ptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3386 | length, nls_codepage); |
| 3387 | bcc_ptr += 2 * length; |
| 3388 | bcc_ptr[0] = 0; /* null terminate the string */ |
| 3389 | bcc_ptr[1] = 0; |
| 3390 | bcc_ptr += 2; |
| 3391 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3392 | /* else do not bother copying these information fields*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | } else { |
| 3394 | length = strnlen(bcc_ptr, 1024); |
| 3395 | if ((bcc_ptr + length) - |
| 3396 | pByteArea(smb_buffer_response) <= |
| 3397 | BCC(smb_buffer_response)) { |
Jesper Juhl | f99d49a | 2005-11-07 01:01:34 -0800 | [diff] [blame] | 3398 | kfree(tcon->nativeFileSystem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | tcon->nativeFileSystem = |
Pekka Enberg | e915fc4 | 2005-09-06 15:18:35 -0700 | [diff] [blame] | 3400 | kzalloc(length + 1, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | strncpy(tcon->nativeFileSystem, bcc_ptr, |
| 3402 | length); |
| 3403 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3404 | /* else do not bother copying these information fields*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3406 | if ((smb_buffer_response->WordCount == 3) || |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 3407 | (smb_buffer_response->WordCount == 7)) |
| 3408 | /* field is in same location */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 3409 | tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport); |
| 3410 | else |
| 3411 | tcon->Flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags)); |
| 3413 | } else if ((rc == 0) && tcon == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3414 | /* all we need to save for IPC$ connection */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | ses->ipc_tid = smb_buffer_response->Tid; |
| 3416 | } |
| 3417 | |
| 3418 | if (smb_buffer) |
| 3419 | cifs_buf_release(smb_buffer); |
| 3420 | return rc; |
| 3421 | } |
| 3422 | |
| 3423 | int |
| 3424 | cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb) |
| 3425 | { |
| 3426 | int rc = 0; |
| 3427 | int xid; |
| 3428 | struct cifsSesInfo *ses = NULL; |
| 3429 | struct task_struct *cifsd_task; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3430 | char *tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3431 | |
| 3432 | xid = GetXid(); |
| 3433 | |
| 3434 | if (cifs_sb->tcon) { |
| 3435 | ses = cifs_sb->tcon->ses; /* save ptr to ses before delete tcon!*/ |
| 3436 | rc = CIFSSMBTDis(xid, cifs_sb->tcon); |
| 3437 | if (rc == -EBUSY) { |
| 3438 | FreeXid(xid); |
| 3439 | return 0; |
| 3440 | } |
| 3441 | tconInfoFree(cifs_sb->tcon); |
| 3442 | if ((ses) && (ses->server)) { |
| 3443 | /* save off task so we do not refer to ses later */ |
| 3444 | cifsd_task = ses->server->tsk; |
| 3445 | cFYI(1, ("About to do SMBLogoff ")); |
| 3446 | rc = CIFSSMBLogoff(xid, ses); |
| 3447 | if (rc == -EBUSY) { |
| 3448 | FreeXid(xid); |
| 3449 | return 0; |
| 3450 | } else if (rc == -ESHUTDOWN) { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 3451 | cFYI(1, ("Waking up socket by sending signal")); |
Steve French | f7f7c31 | 2007-05-24 02:29:51 +0000 | [diff] [blame] | 3452 | if (cifsd_task) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3453 | force_sig(SIGKILL, cifsd_task); |
Igor Mammedov | aaf737a | 2007-04-03 19:16:43 +0000 | [diff] [blame] | 3454 | kthread_stop(cifsd_task); |
Steve French | f191401 | 2005-08-18 09:37:34 -0700 | [diff] [blame] | 3455 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3456 | rc = 0; |
| 3457 | } /* else - we have an smb session |
| 3458 | left on this socket do not kill cifsd */ |
| 3459 | } else |
| 3460 | cFYI(1, ("No session or bad tcon")); |
| 3461 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3463 | cifs_sb->tcon = NULL; |
Steve French | 2fe87f0 | 2006-09-21 07:02:52 +0000 | [diff] [blame] | 3464 | tmp = cifs_sb->prepath; |
| 3465 | cifs_sb->prepathlen = 0; |
| 3466 | cifs_sb->prepath = NULL; |
| 3467 | kfree(tmp); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 3468 | if (ses) |
| 3469 | schedule_timeout_interruptible(msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | if (ses) |
| 3471 | sesInfoFree(ses); |
| 3472 | |
| 3473 | FreeXid(xid); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3474 | return rc; /* BB check if we should always return zero here */ |
| 3475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | |
| 3477 | int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3478 | struct nls_table *nls_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | { |
| 3480 | int rc = 0; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 3481 | char ntlm_session_key[CIFS_SESS_KEY_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | int ntlmv2_flag = FALSE; |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3483 | int first_time = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | |
| 3485 | /* what if server changes its buffer size after dropping the session? */ |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3486 | if (pSesInfo->server->maxBuf == 0) /* no need to send on reconnect */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | rc = CIFSSMBNegotiate(xid, pSesInfo); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3488 | if (rc == -EAGAIN) /* retry only once on 1st time connection */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | rc = CIFSSMBNegotiate(xid, pSesInfo); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3490 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3491 | rc = -EHOSTDOWN; |
| 3492 | } |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3493 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3494 | spin_lock(&GlobalMid_Lock); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3495 | if (pSesInfo->server->tcpStatus != CifsExiting) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | pSesInfo->server->tcpStatus = CifsGood; |
| 3497 | else |
| 3498 | rc = -EHOSTDOWN; |
| 3499 | spin_unlock(&GlobalMid_Lock); |
| 3500 | |
| 3501 | } |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3502 | first_time = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | } |
| 3504 | if (!rc) { |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 3505 | pSesInfo->flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3506 | pSesInfo->capabilities = pSesInfo->server->capabilities; |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3507 | if (linuxExtEnabled == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3508 | pSesInfo->capabilities &= (~CAP_UNIX); |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3509 | /* pSesInfo->sequence_number = 0;*/ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3510 | cFYI(1, |
| 3511 | ("Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | pSesInfo->server->secMode, |
| 3513 | pSesInfo->server->capabilities, |
Steve French | 175ec9e | 2006-09-30 01:07:38 +0000 | [diff] [blame] | 3514 | pSesInfo->server->timeAdj)); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3515 | if (experimEnabled < 2) |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 3516 | rc = CIFS_SessSetup(xid, pSesInfo, |
| 3517 | first_time, nls_info); |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 3518 | else if (extended_security |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3519 | && (pSesInfo->capabilities |
Steve French | 175ec9e | 2006-09-30 01:07:38 +0000 | [diff] [blame] | 3520 | & CAP_EXTENDED_SECURITY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | && (pSesInfo->server->secType == NTLMSSP)) { |
Steve French | 189acaa | 2006-06-23 02:33:48 +0000 | [diff] [blame] | 3522 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3523 | } else if (extended_security |
| 3524 | && (pSesInfo->capabilities & CAP_EXTENDED_SECURITY) |
| 3525 | && (pSesInfo->server->secType == RawNTLMSSP)) { |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 3526 | cFYI(1, ("NTLMSSP sesssetup")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | rc = CIFSNTLMSSPNegotiateSessSetup(xid, |
| 3528 | pSesInfo, |
| 3529 | &ntlmv2_flag, |
| 3530 | nls_info); |
| 3531 | if (!rc) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3532 | if (ntlmv2_flag) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3533 | char *v2_response; |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 3534 | cFYI(1, ("more secure NTLM ver2 hash")); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3535 | if (CalcNTLMv2_partial_mac_key(pSesInfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3536 | nls_info)) { |
| 3537 | rc = -ENOMEM; |
| 3538 | goto ss_err_exit; |
| 3539 | } else |
| 3540 | v2_response = kmalloc(16 + 64 /* blob */, GFP_KERNEL); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3541 | if (v2_response) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3542 | CalcNTLMv2_response(pSesInfo, |
| 3543 | v2_response); |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3544 | /* if (first_time) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3545 | cifs_calculate_ntlmv2_mac_key( |
| 3546 | pSesInfo->server->mac_signing_key, |
| 3547 | response, ntlm_session_key,*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | kfree(v2_response); |
| 3549 | /* BB Put dummy sig in SessSetup PDU? */ |
| 3550 | } else { |
| 3551 | rc = -ENOMEM; |
| 3552 | goto ss_err_exit; |
| 3553 | } |
| 3554 | |
| 3555 | } else { |
| 3556 | SMBNTencrypt(pSesInfo->password, |
| 3557 | pSesInfo->server->cryptKey, |
| 3558 | ntlm_session_key); |
| 3559 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3560 | if (first_time) |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3561 | cifs_calculate_mac_key( |
Steve French | b609f06 | 2007-07-09 07:55:14 +0000 | [diff] [blame] | 3562 | &pSesInfo->server->mac_signing_key, |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3563 | ntlm_session_key, |
| 3564 | pSesInfo->password); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | } |
| 3566 | /* for better security the weaker lanman hash not sent |
| 3567 | in AuthSessSetup so we no longer calculate it */ |
| 3568 | |
| 3569 | rc = CIFSNTLMSSPAuthSessSetup(xid, |
| 3570 | pSesInfo, |
| 3571 | ntlm_session_key, |
| 3572 | ntlmv2_flag, |
| 3573 | nls_info); |
| 3574 | } |
| 3575 | } else { /* old style NTLM 0.12 session setup */ |
| 3576 | SMBNTencrypt(pSesInfo->password, |
| 3577 | pSesInfo->server->cryptKey, |
| 3578 | ntlm_session_key); |
| 3579 | |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3580 | if (first_time) |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3581 | cifs_calculate_mac_key( |
Steve French | b609f06 | 2007-07-09 07:55:14 +0000 | [diff] [blame] | 3582 | &pSesInfo->server->mac_signing_key, |
Steve French | ad009ac | 2005-04-28 22:41:05 -0700 | [diff] [blame] | 3583 | ntlm_session_key, pSesInfo->password); |
| 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | rc = CIFSSessSetup(xid, pSesInfo, |
| 3586 | ntlm_session_key, nls_info); |
| 3587 | } |
| 3588 | if (rc) { |
Steve French | fb8c4b1 | 2007-07-10 01:16:18 +0000 | [diff] [blame] | 3589 | cERROR(1, ("Send error in SessSetup = %d", rc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | } else { |
Steve French | 467a8f8 | 2007-06-27 22:41:32 +0000 | [diff] [blame] | 3591 | cFYI(1, ("CIFS Session Established successfully")); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | pSesInfo->status = CifsGood; |
| 3593 | } |
| 3594 | } |
| 3595 | ss_err_exit: |
| 3596 | return rc; |
| 3597 | } |
| 3598 | |