Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/cifssmb.c |
| 3 | * |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4 | * Copyright (C) International Business Machines Corp., 2002,2010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Author(s): Steve French (sfrench@us.ibm.com) |
| 6 | * |
| 7 | * Contains the routines for constructing the SMB PDUs themselves |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* SMB/CIFS PDU handling routines here - except for leftovers in connect.c */ |
| 25 | /* These are mostly routines that operate on a pathname, or on a tree id */ |
| 26 | /* (mounted volume), but there are eight handle based routines which must be */ |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 27 | /* treated slightly differently for reconnection purposes since we never */ |
| 28 | /* want to reuse a stale file handle and only the caller knows the file info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/kernel.h> |
| 32 | #include <linux/vfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/posix_acl_xattr.h> |
| 35 | #include <asm/uaccess.h> |
| 36 | #include "cifspdu.h" |
| 37 | #include "cifsglob.h" |
Shirish Pargaonkar | d0d66c4 | 2007-10-03 18:22:19 +0000 | [diff] [blame] | 38 | #include "cifsacl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "cifsproto.h" |
| 40 | #include "cifs_unicode.h" |
| 41 | #include "cifs_debug.h" |
| 42 | |
| 43 | #ifdef CONFIG_CIFS_POSIX |
| 44 | static struct { |
| 45 | int index; |
| 46 | char *name; |
| 47 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 49 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 50 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 51 | #endif /* weak password hashing for legacy clients */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 52 | {CIFS_PROT, "\2NT LM 0.12"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 53 | {POSIX_PROT, "\2POSIX 2"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | {BAD_PROT, "\2"} |
| 55 | }; |
| 56 | #else |
| 57 | static struct { |
| 58 | int index; |
| 59 | char *name; |
| 60 | } protocols[] = { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 61 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
| 62 | {LANMAN_PROT, "\2LM1.2X002"}, |
Steve French | 18f75ca | 2006-10-01 03:13:01 +0000 | [diff] [blame] | 63 | {LANMAN2_PROT, "\2LANMAN2.1"}, |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 64 | #endif /* weak password hashing for legacy clients */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 65 | {CIFS_PROT, "\2NT LM 0.12"}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | {BAD_PROT, "\2"} |
| 67 | }; |
| 68 | #endif |
| 69 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 70 | /* define the number of elements in the cifs dialect array */ |
| 71 | #ifdef CONFIG_CIFS_POSIX |
| 72 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 73 | #define CIFS_NUM_PROT 4 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 74 | #else |
| 75 | #define CIFS_NUM_PROT 2 |
| 76 | #endif /* CIFS_WEAK_PW_HASH */ |
| 77 | #else /* not posix */ |
| 78 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 9ac00b7 | 2006-09-30 04:13:17 +0000 | [diff] [blame] | 79 | #define CIFS_NUM_PROT 3 |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 80 | #else |
| 81 | #define CIFS_NUM_PROT 1 |
| 82 | #endif /* CONFIG_CIFS_WEAK_PW_HASH */ |
| 83 | #endif /* CIFS_POSIX */ |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* Mark as invalid, all open files on tree connections since they |
| 86 | were closed when session to server was lost */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 87 | static void mark_open_files_invalid(struct cifsTconInfo *pTcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
| 89 | struct cifsFileInfo *open_file = NULL; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 90 | struct list_head *tmp; |
| 91 | struct list_head *tmp1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | /* list all files open on tree connection and mark them invalid */ |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 94 | spin_lock(&cifs_file_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | list_for_each_safe(tmp, tmp1, &pTcon->openFileList) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 96 | open_file = list_entry(tmp, struct cifsFileInfo, tlist); |
Steve French | ad8b15f | 2008-08-08 21:10:16 +0000 | [diff] [blame] | 97 | open_file->invalidHandle = true; |
Jeff Layton | 3bc303c | 2009-09-21 06:47:50 -0400 | [diff] [blame] | 98 | open_file->oplock_break_cancelled = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
Jeff Layton | 4477288 | 2010-10-15 15:34:03 -0400 | [diff] [blame] | 100 | spin_unlock(&cifs_file_list_lock); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 101 | /* BB Add call to invalidate_inodes(sb) for all superblocks mounted |
| 102 | to this tcon */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 105 | /* reconnect the socket, tcon, and smb session if needed */ |
| 106 | static int |
| 107 | cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) |
| 108 | { |
| 109 | int rc = 0; |
| 110 | struct cifsSesInfo *ses; |
| 111 | struct TCP_Server_Info *server; |
| 112 | struct nls_table *nls_codepage; |
| 113 | |
| 114 | /* |
| 115 | * SMBs NegProt, SessSetup, uLogoff do not have tcon yet so check for |
| 116 | * tcp and smb session status done differently for those three - in the |
| 117 | * calling routine |
| 118 | */ |
| 119 | if (!tcon) |
| 120 | return 0; |
| 121 | |
| 122 | ses = tcon->ses; |
| 123 | server = ses->server; |
| 124 | |
| 125 | /* |
| 126 | * only tree disconnect, open, and write, (and ulogoff which does not |
| 127 | * have tcon) are allowed as we start force umount |
| 128 | */ |
| 129 | if (tcon->tidStatus == CifsExiting) { |
| 130 | if (smb_command != SMB_COM_WRITE_ANDX && |
| 131 | smb_command != SMB_COM_OPEN_ANDX && |
| 132 | smb_command != SMB_COM_TREE_DISCONNECT) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 133 | cFYI(1, "can not send cmd %d while umounting", |
| 134 | smb_command); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 135 | return -ENODEV; |
| 136 | } |
| 137 | } |
| 138 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 139 | /* |
| 140 | * Give demultiplex thread up to 10 seconds to reconnect, should be |
| 141 | * greater than cifs socket timeout which is 7 seconds |
| 142 | */ |
| 143 | while (server->tcpStatus == CifsNeedReconnect) { |
| 144 | wait_event_interruptible_timeout(server->response_q, |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 145 | (server->tcpStatus != CifsNeedReconnect), 10 * HZ); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 146 | |
Steve French | fd88ce9 | 2011-04-12 01:01:14 +0000 | [diff] [blame] | 147 | /* are we still trying to reconnect? */ |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 148 | if (server->tcpStatus != CifsNeedReconnect) |
| 149 | break; |
| 150 | |
| 151 | /* |
| 152 | * on "soft" mounts we wait once. Hard mounts keep |
| 153 | * retrying until process is killed or server comes |
| 154 | * back on-line |
| 155 | */ |
Jeff Layton | d402539 | 2011-02-07 08:54:35 -0500 | [diff] [blame] | 156 | if (!tcon->retry) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 157 | cFYI(1, "gave up waiting on reconnect in smb_init"); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 158 | return -EHOSTDOWN; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if (!ses->need_reconnect && !tcon->need_reconnect) |
| 163 | return 0; |
| 164 | |
| 165 | nls_codepage = load_nls_default(); |
| 166 | |
| 167 | /* |
| 168 | * need to prevent multiple threads trying to simultaneously |
| 169 | * reconnect the same SMB session |
| 170 | */ |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 171 | mutex_lock(&ses->session_mutex); |
Jeff Layton | 198b568 | 2010-04-24 07:57:48 -0400 | [diff] [blame] | 172 | rc = cifs_negotiate_protocol(0, ses); |
| 173 | if (rc == 0 && ses->need_reconnect) |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 174 | rc = cifs_setup_session(0, ses, nls_codepage); |
| 175 | |
| 176 | /* do we need to reconnect tcon? */ |
| 177 | if (rc || !tcon->need_reconnect) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 178 | mutex_unlock(&ses->session_mutex); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 179 | goto out; |
| 180 | } |
| 181 | |
| 182 | mark_open_files_invalid(tcon); |
| 183 | rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage); |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 184 | mutex_unlock(&ses->session_mutex); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 185 | cFYI(1, "reconnect tcon rc = %d", rc); |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 186 | |
| 187 | if (rc) |
| 188 | goto out; |
| 189 | |
| 190 | /* |
| 191 | * FIXME: check if wsize needs updated due to negotiated smb buffer |
| 192 | * size shrinking |
| 193 | */ |
| 194 | atomic_inc(&tconInfoReconnectCount); |
| 195 | |
| 196 | /* tell server Unix caps we support */ |
| 197 | if (ses->capabilities & CAP_UNIX) |
| 198 | reset_cifs_unix_caps(0, tcon, NULL, NULL); |
| 199 | |
| 200 | /* |
| 201 | * Removed call to reopen open files here. It is safer (and faster) to |
| 202 | * reopen files one at a time as needed in read and write. |
| 203 | * |
| 204 | * FIXME: what about file locks? don't we need to reclaim them ASAP? |
| 205 | */ |
| 206 | |
| 207 | out: |
| 208 | /* |
| 209 | * Check if handle based operation so we know whether we can continue |
| 210 | * or not without returning to caller to reset file handle |
| 211 | */ |
| 212 | switch (smb_command) { |
| 213 | case SMB_COM_READ_ANDX: |
| 214 | case SMB_COM_WRITE_ANDX: |
| 215 | case SMB_COM_CLOSE: |
| 216 | case SMB_COM_FIND_CLOSE2: |
| 217 | case SMB_COM_LOCKING_ANDX: |
| 218 | rc = -EAGAIN; |
| 219 | } |
| 220 | |
| 221 | unload_nls(nls_codepage); |
| 222 | return rc; |
| 223 | } |
| 224 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 225 | /* Allocate and return pointer to an SMB request buffer, and set basic |
| 226 | SMB information in the SMB header. If the return code is zero, this |
| 227 | function must have filled in request_buf pointer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | static int |
| 229 | small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 230 | void **request_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | { |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 232 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Jeff Layton | 9162ab2 | 2009-09-03 12:07:17 -0400 | [diff] [blame] | 234 | rc = cifs_reconnect_tcon(tcon, smb_command); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 235 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | return rc; |
| 237 | |
| 238 | *request_buf = cifs_small_buf_get(); |
| 239 | if (*request_buf == NULL) { |
| 240 | /* BB should we add a retry in here if not a writepage? */ |
| 241 | return -ENOMEM; |
| 242 | } |
| 243 | |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 244 | header_assemble((struct smb_hdr *) *request_buf, smb_command, |
Steve French | c18c842 | 2007-07-18 23:21:09 +0000 | [diff] [blame] | 245 | tcon, wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 247 | if (tcon != NULL) |
| 248 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 249 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 250 | return 0; |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 253 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 254 | small_smb_init_no_tc(const int smb_command, const int wct, |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 255 | struct cifsSesInfo *ses, void **request_buf) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 256 | { |
| 257 | int rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 258 | struct smb_hdr *buffer; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 259 | |
Steve French | 5815449d | 2006-02-14 01:36:20 +0000 | [diff] [blame] | 260 | rc = small_smb_init(smb_command, wct, NULL, request_buf); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 261 | if (rc) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 262 | return rc; |
| 263 | |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 264 | buffer = (struct smb_hdr *)*request_buf; |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 265 | buffer->Mid = GetNextMid(ses->server); |
| 266 | if (ses->capabilities & CAP_UNICODE) |
| 267 | buffer->Flags2 |= SMBFLG2_UNICODE; |
Steve French | 04fdabe | 2006-02-10 05:52:50 +0000 | [diff] [blame] | 268 | if (ses->capabilities & CAP_STATUS32) |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 269 | buffer->Flags2 |= SMBFLG2_ERR_STATUS; |
| 270 | |
| 271 | /* uid, tid can stay at zero as set in header assemble */ |
| 272 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 273 | /* BB add support for turning on the signing when |
Steve French | 12b3b8f | 2006-02-09 21:12:47 +0000 | [diff] [blame] | 274 | this function is used after 1st of session setup requests */ |
| 275 | |
| 276 | return rc; |
| 277 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 280 | static int |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 281 | __smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 282 | void **request_buf, void **response_buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | *request_buf = cifs_buf_get(); |
| 285 | if (*request_buf == NULL) { |
| 286 | /* BB should we add a retry in here if not a writepage? */ |
| 287 | return -ENOMEM; |
| 288 | } |
| 289 | /* Although the original thought was we needed the response buf for */ |
| 290 | /* potential retries of smb operations it turns out we can determine */ |
| 291 | /* from the mid flags when the request buffer can be resent without */ |
| 292 | /* having to use a second distinct buffer for the response */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 293 | if (response_buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 294 | *response_buf = *request_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 297 | wct); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 299 | if (tcon != NULL) |
| 300 | cifs_stats_inc(&tcon->num_smbs_sent); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 301 | |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | /* If the return code is zero, this function must fill in request_buf pointer */ |
| 306 | static int |
| 307 | smb_init(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 308 | void **request_buf, void **response_buf) |
| 309 | { |
| 310 | int rc; |
| 311 | |
| 312 | rc = cifs_reconnect_tcon(tcon, smb_command); |
| 313 | if (rc) |
| 314 | return rc; |
| 315 | |
| 316 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
| 317 | } |
| 318 | |
| 319 | static int |
| 320 | smb_init_no_reconnect(int smb_command, int wct, struct cifsTconInfo *tcon, |
| 321 | void **request_buf, void **response_buf) |
| 322 | { |
| 323 | if (tcon->ses->need_reconnect || tcon->need_reconnect) |
| 324 | return -EHOSTDOWN; |
| 325 | |
| 326 | return __smb_init(smb_command, wct, tcon, request_buf, response_buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 329 | static int validate_t2(struct smb_t2_rsp *pSMB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 331 | unsigned int total_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 333 | /* check for plausible wct */ |
| 334 | if (pSMB->hdr.WordCount < 10) |
| 335 | goto vt2_err; |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* check for parm and data offset going beyond end of smb */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 338 | if (get_unaligned_le16(&pSMB->t2_rsp.ParameterOffset) > 1024 || |
| 339 | get_unaligned_le16(&pSMB->t2_rsp.DataOffset) > 1024) |
| 340 | goto vt2_err; |
| 341 | |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 342 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 343 | if (total_size >= 512) |
| 344 | goto vt2_err; |
| 345 | |
Jeff Layton | fd5707e | 2011-03-31 17:22:07 -0400 | [diff] [blame] | 346 | /* check that bcc is at least as big as parms + data, and that it is |
| 347 | * less than negotiated smb buffer |
| 348 | */ |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 349 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 350 | if (total_size > get_bcc(&pSMB->hdr) || |
| 351 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 352 | goto vt2_err; |
| 353 | |
| 354 | return 0; |
| 355 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 356 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 358 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 360 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 361 | static inline void inc_rfc1001_len(void *pSMB, int count) |
| 362 | { |
| 363 | struct smb_hdr *hdr = (struct smb_hdr *)pSMB; |
| 364 | |
| 365 | be32_add_cpu(&hdr->smb_buf_length, count); |
| 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | int |
| 369 | CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) |
| 370 | { |
| 371 | NEGOTIATE_REQ *pSMB; |
| 372 | NEGOTIATE_RSP *pSMBr; |
| 373 | int rc = 0; |
| 374 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 375 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 376 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 378 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 380 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | server = ses->server; |
| 382 | else { |
| 383 | rc = -EIO; |
| 384 | return rc; |
| 385 | } |
| 386 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 387 | (void **) &pSMB, (void **) &pSMBr); |
| 388 | if (rc) |
| 389 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 390 | |
| 391 | /* if any of auth flags (ie not sign or seal) are overriden use them */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 392 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 393 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 394 | else /* if override flags set only sign/seal OR them with global auth */ |
Jeff Layton | 04912d6 | 2010-04-24 07:57:45 -0400 | [diff] [blame] | 395 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 396 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 397 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 398 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 399 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 400 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 401 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 402 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 403 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 404 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 405 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 406 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 407 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 408 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 409 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 410 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 411 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 412 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 413 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 414 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 415 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 416 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 417 | count += strlen(protocols[i].name) + 1; |
| 418 | /* null at end of source and target buffers anyway */ |
| 419 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 420 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | pSMB->ByteCount = cpu_to_le16(count); |
| 422 | |
| 423 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 424 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 425 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 426 | goto neg_err_exit; |
| 427 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 428 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 429 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 430 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 431 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 432 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 433 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 434 | could not negotiate a common dialect */ |
| 435 | rc = -EOPNOTSUPP; |
| 436 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 437 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 438 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 439 | && ((server->dialect == LANMAN_PROT) |
| 440 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 441 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 442 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 443 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 444 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 445 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 446 | server->secType = LANMAN; |
| 447 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 448 | cERROR(1, "mount failed weak security disabled" |
| 449 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 450 | rc = -EOPNOTSUPP; |
| 451 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 452 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 453 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); |
| 454 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); |
| 455 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 456 | (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 457 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 458 | /* even though we do not use raw we might as well set this |
| 459 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 460 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 461 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 462 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 463 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 464 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 465 | server->capabilities = CAP_MPX_MODE; |
| 466 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 467 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 468 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 469 | /* OS/2 often does not set timezone therefore |
| 470 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 471 | * Could deviate slightly from the right zone. |
| 472 | * Smallest defined timezone difference is 15 minutes |
| 473 | * (i.e. Nepal). Rounding up/down is done to match |
| 474 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 475 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 476 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 477 | struct timespec ts, utc; |
| 478 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 479 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 480 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 481 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 482 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 483 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 484 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 485 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 486 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 487 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 488 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 489 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 490 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 491 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 492 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 493 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 494 | server->timeAdj = (int)tmp; |
| 495 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 496 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 497 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 498 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 499 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 500 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 501 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 502 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 503 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 504 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 505 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 506 | CIFS_CRYPTO_KEY_SIZE); |
| 507 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 508 | rc = -EIO; /* need cryptkey unless plain text */ |
| 509 | goto neg_err_exit; |
| 510 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 511 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 512 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 513 | /* we will not end up setting signing flags - as no signing |
| 514 | was in LANMAN and server did not return the flags on */ |
| 515 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 516 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 517 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 518 | cERROR(1, "mount failed, cifs module not built " |
| 519 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 520 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 521 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 522 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 523 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 524 | /* unknown wct */ |
| 525 | rc = -EOPNOTSUPP; |
| 526 | goto neg_err_exit; |
| 527 | } |
| 528 | /* else wct == 17 NTLM */ |
| 529 | server->secMode = pSMBr->SecurityMode; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 530 | if ((server->secMode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 531 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 532 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 533 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 534 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 535 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 536 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 537 | cERROR(1, "Server requests plain text password" |
| 538 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 539 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 540 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 541 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 542 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 543 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 544 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 545 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 546 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 547 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 548 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 549 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 550 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 551 | server->secType = LANMAN; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 552 | else { |
| 553 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 554 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 555 | goto neg_err_exit; |
| 556 | } |
| 557 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 558 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 559 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 560 | little endian */ |
| 561 | server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount); |
| 562 | /* probably no need to store and check maxvcs */ |
| 563 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 565 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 566 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 567 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 568 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 569 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 570 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 571 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 572 | CIFS_CRYPTO_KEY_SIZE); |
| 573 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) |
| 574 | && (pSMBr->EncryptionKeyLength == 0)) { |
| 575 | /* decode security blob */ |
| 576 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 577 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 578 | goto neg_err_exit; |
| 579 | } |
| 580 | |
| 581 | /* BB might be helpful to save off the domain of server here */ |
| 582 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 583 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 584 | (server->capabilities & CAP_EXTENDED_SECURITY)) { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 585 | count = get_bcc(&pSMBr->hdr); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 586 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 588 | goto neg_err_exit; |
| 589 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 590 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 591 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 592 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 593 | if (memcmp(server->server_GUID, |
| 594 | pSMBr->u.extended_response. |
| 595 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 596 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 597 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 598 | pSMBr->u.extended_response.GUID, |
| 599 | 16); |
| 600 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 601 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 602 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 603 | memcpy(server->server_GUID, |
| 604 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 605 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 606 | |
| 607 | if (count == 16) { |
| 608 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 609 | } else { |
| 610 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 611 | SecurityBlob, count - 16, |
| 612 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 613 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 614 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 615 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 616 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 617 | if (server->secType == Kerberos) { |
| 618 | if (!server->sec_kerberos && |
| 619 | !server->sec_mskerberos) |
| 620 | rc = -EOPNOTSUPP; |
| 621 | } else if (server->secType == RawNTLMSSP) { |
| 622 | if (!server->sec_ntlmssp) |
| 623 | rc = -EOPNOTSUPP; |
| 624 | } else |
| 625 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 627 | } else |
| 628 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 629 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 630 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 631 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 632 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 633 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 634 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 635 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 636 | cFYI(1, "Signing disabled"); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 637 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 638 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 639 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 640 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 641 | rc = -EOPNOTSUPP; |
| 642 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 643 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 644 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 645 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 646 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 647 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 648 | if ((server->secMode & |
| 649 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 650 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 651 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 652 | } else |
| 653 | server->secMode |= SECMODE_SIGN_REQUIRED; |
| 654 | } else { |
| 655 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 656 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 657 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 658 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 660 | |
| 661 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 662 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 663 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 664 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | return rc; |
| 666 | } |
| 667 | |
| 668 | int |
| 669 | CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) |
| 670 | { |
| 671 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 674 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 675 | |
| 676 | /* BB: do we need to check this? These should never be NULL. */ |
| 677 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 678 | return -EIO; |
| 679 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 681 | * No need to return error on this operation if tid invalidated and |
| 682 | * closed on server already e.g. due to tcp session crashing. Also, |
| 683 | * the tcon is no longer on the list, so no need to take lock before |
| 684 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 686 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 687 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 689 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 690 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 691 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 693 | |
| 694 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 696 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 698 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 699 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (rc == -EAGAIN) |
| 701 | rc = 0; |
| 702 | |
| 703 | return rc; |
| 704 | } |
| 705 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 706 | /* |
| 707 | * This is a no-op for now. We're not really interested in the reply, but |
| 708 | * rather in the fact that the server sent one and that server->lstrp |
| 709 | * gets updated. |
| 710 | * |
| 711 | * FIXME: maybe we should consider checking that the reply matches request? |
| 712 | */ |
| 713 | static void |
| 714 | cifs_echo_callback(struct mid_q_entry *mid) |
| 715 | { |
| 716 | struct TCP_Server_Info *server = mid->callback_data; |
| 717 | |
| 718 | DeleteMidQEntry(mid); |
| 719 | atomic_dec(&server->inFlight); |
| 720 | wake_up(&server->request_q); |
| 721 | } |
| 722 | |
| 723 | int |
| 724 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 725 | { |
| 726 | ECHO_REQ *smb; |
| 727 | int rc = 0; |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 728 | struct kvec iov; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 729 | |
| 730 | cFYI(1, "In echo request"); |
| 731 | |
| 732 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 733 | if (rc) |
| 734 | return rc; |
| 735 | |
| 736 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 737 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8f | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 738 | smb->hdr.WordCount = 1; |
| 739 | put_unaligned_le16(1, &smb->EchoCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 740 | put_bcc(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 741 | smb->Data[0] = 'a'; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 742 | inc_rfc1001_len(smb, 3); |
Jeff Layton | fcc31cb | 2011-05-19 16:22:53 -0400 | [diff] [blame] | 743 | iov.iov_base = smb; |
| 744 | iov.iov_len = be32_to_cpu(smb->hdr.smb_buf_length) + 4; |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 745 | |
Jeff Layton | 59ffd84 | 2011-05-19 16:22:55 -0400 | [diff] [blame^] | 746 | rc = cifs_call_async(server, &iov, 1, cifs_echo_callback, server, true); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 747 | if (rc) |
| 748 | cFYI(1, "Echo request failed: %d", rc); |
| 749 | |
| 750 | cifs_small_buf_release(smb); |
| 751 | |
| 752 | return rc; |
| 753 | } |
| 754 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | int |
| 756 | CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) |
| 757 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | LOGOFF_ANDX_REQ *pSMB; |
| 759 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 761 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 762 | |
| 763 | /* |
| 764 | * BB: do we need to check validity of ses and server? They should |
| 765 | * always be valid since we have an active reference. If not, that |
| 766 | * should probably be a BUG() |
| 767 | */ |
| 768 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | return -EIO; |
| 770 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 771 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 772 | if (ses->need_reconnect) |
| 773 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 774 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 776 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 777 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | return rc; |
| 779 | } |
| 780 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 781 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 782 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 783 | if (ses->server->secMode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 785 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | pSMB->hdr.Uid = ses->Suid; |
| 788 | |
| 789 | pSMB->AndXCommand = 0xFF; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 790 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 791 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 792 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | |
| 794 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 795 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | error */ |
| 797 | if (rc == -EAGAIN) |
| 798 | rc = 0; |
| 799 | return rc; |
| 800 | } |
| 801 | |
| 802 | int |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 803 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 804 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 805 | { |
| 806 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 807 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 808 | struct unlink_psx_rq *pRqD; |
| 809 | int name_len; |
| 810 | int rc = 0; |
| 811 | int bytes_returned = 0; |
| 812 | __u16 params, param_offset, offset, byte_count; |
| 813 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 814 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 815 | PsxDelete: |
| 816 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 817 | (void **) &pSMBr); |
| 818 | if (rc) |
| 819 | return rc; |
| 820 | |
| 821 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 822 | name_len = |
| 823 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
| 824 | PATH_MAX, nls_codepage, remap); |
| 825 | name_len++; /* trailing null */ |
| 826 | name_len *= 2; |
| 827 | } else { /* BB add path length overrun check */ |
| 828 | name_len = strnlen(fileName, PATH_MAX); |
| 829 | name_len++; /* trailing null */ |
| 830 | strncpy(pSMB->FileName, fileName, name_len); |
| 831 | } |
| 832 | |
| 833 | params = 6 + name_len; |
| 834 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 835 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 836 | pSMB->MaxSetupCount = 0; |
| 837 | pSMB->Reserved = 0; |
| 838 | pSMB->Flags = 0; |
| 839 | pSMB->Timeout = 0; |
| 840 | pSMB->Reserved2 = 0; |
| 841 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 842 | InformationLevel) - 4; |
| 843 | offset = param_offset + params; |
| 844 | |
| 845 | /* Setup pointer to Request Data (inode type) */ |
| 846 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 847 | pRqD->type = cpu_to_le16(type); |
| 848 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 849 | pSMB->DataOffset = cpu_to_le16(offset); |
| 850 | pSMB->SetupCount = 1; |
| 851 | pSMB->Reserved3 = 0; |
| 852 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 853 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 854 | |
| 855 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 856 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 857 | pSMB->ParameterCount = cpu_to_le16(params); |
| 858 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 859 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 860 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 861 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 862 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 863 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 864 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 865 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 866 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 867 | cifs_buf_release(pSMB); |
| 868 | |
| 869 | cifs_stats_inc(&tcon->num_deletes); |
| 870 | |
| 871 | if (rc == -EAGAIN) |
| 872 | goto PsxDelete; |
| 873 | |
| 874 | return rc; |
| 875 | } |
| 876 | |
| 877 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 878 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 879 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | { |
| 881 | DELETE_FILE_REQ *pSMB = NULL; |
| 882 | DELETE_FILE_RSP *pSMBr = NULL; |
| 883 | int rc = 0; |
| 884 | int bytes_returned; |
| 885 | int name_len; |
| 886 | |
| 887 | DelFileRetry: |
| 888 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 889 | (void **) &pSMBr); |
| 890 | if (rc) |
| 891 | return rc; |
| 892 | |
| 893 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 894 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 895 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 896 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | name_len++; /* trailing null */ |
| 898 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 899 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | name_len = strnlen(fileName, PATH_MAX); |
| 901 | name_len++; /* trailing null */ |
| 902 | strncpy(pSMB->fileName, fileName, name_len); |
| 903 | } |
| 904 | pSMB->SearchAttributes = |
| 905 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 906 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 907 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 909 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 910 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 911 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 912 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 913 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | |
| 915 | cifs_buf_release(pSMB); |
| 916 | if (rc == -EAGAIN) |
| 917 | goto DelFileRetry; |
| 918 | |
| 919 | return rc; |
| 920 | } |
| 921 | |
| 922 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 923 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 924 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | { |
| 926 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 927 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 928 | int rc = 0; |
| 929 | int bytes_returned; |
| 930 | int name_len; |
| 931 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 932 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | RmDirRetry: |
| 934 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 935 | (void **) &pSMBr); |
| 936 | if (rc) |
| 937 | return rc; |
| 938 | |
| 939 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 940 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, |
| 941 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | name_len++; /* trailing null */ |
| 943 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 944 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | name_len = strnlen(dirName, PATH_MAX); |
| 946 | name_len++; /* trailing null */ |
| 947 | strncpy(pSMB->DirName, dirName, name_len); |
| 948 | } |
| 949 | |
| 950 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 951 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 953 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 954 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 955 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 956 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 957 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
| 959 | cifs_buf_release(pSMB); |
| 960 | if (rc == -EAGAIN) |
| 961 | goto RmDirRetry; |
| 962 | return rc; |
| 963 | } |
| 964 | |
| 965 | int |
| 966 | CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 967 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
| 969 | int rc = 0; |
| 970 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 971 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 972 | int bytes_returned; |
| 973 | int name_len; |
| 974 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 975 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | MkDirRetry: |
| 977 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 978 | (void **) &pSMBr); |
| 979 | if (rc) |
| 980 | return rc; |
| 981 | |
| 982 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 983 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 984 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | name_len++; /* trailing null */ |
| 986 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 987 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | name_len = strnlen(name, PATH_MAX); |
| 989 | name_len++; /* trailing null */ |
| 990 | strncpy(pSMB->DirName, name, name_len); |
| 991 | } |
| 992 | |
| 993 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 994 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 996 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 997 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 998 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 999 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1000 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1001 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | cifs_buf_release(pSMB); |
| 1003 | if (rc == -EAGAIN) |
| 1004 | goto MkDirRetry; |
| 1005 | return rc; |
| 1006 | } |
| 1007 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1008 | int |
| 1009 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1010 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1011 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1012 | const struct nls_table *nls_codepage, int remap) |
| 1013 | { |
| 1014 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1015 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1016 | int name_len; |
| 1017 | int rc = 0; |
| 1018 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1019 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1020 | OPEN_PSX_REQ *pdata; |
| 1021 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1022 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1023 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1024 | PsxCreat: |
| 1025 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1026 | (void **) &pSMBr); |
| 1027 | if (rc) |
| 1028 | return rc; |
| 1029 | |
| 1030 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1031 | name_len = |
| 1032 | cifsConvertToUCS((__le16 *) pSMB->FileName, name, |
| 1033 | PATH_MAX, nls_codepage, remap); |
| 1034 | name_len++; /* trailing null */ |
| 1035 | name_len *= 2; |
| 1036 | } else { /* BB improve the check for buffer overruns BB */ |
| 1037 | name_len = strnlen(name, PATH_MAX); |
| 1038 | name_len++; /* trailing null */ |
| 1039 | strncpy(pSMB->FileName, name, name_len); |
| 1040 | } |
| 1041 | |
| 1042 | params = 6 + name_len; |
| 1043 | count = sizeof(OPEN_PSX_REQ); |
| 1044 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1045 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1046 | pSMB->MaxSetupCount = 0; |
| 1047 | pSMB->Reserved = 0; |
| 1048 | pSMB->Flags = 0; |
| 1049 | pSMB->Timeout = 0; |
| 1050 | pSMB->Reserved2 = 0; |
| 1051 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1052 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1053 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1054 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1055 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1056 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1057 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1058 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1059 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1060 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1061 | pSMB->SetupCount = 1; |
| 1062 | pSMB->Reserved3 = 0; |
| 1063 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1064 | byte_count = 3 /* pad */ + params + count; |
| 1065 | |
| 1066 | pSMB->DataCount = cpu_to_le16(count); |
| 1067 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1068 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1069 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1070 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1071 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1072 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1073 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1074 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1075 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1076 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1077 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1078 | goto psx_create_err; |
| 1079 | } |
| 1080 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1081 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1082 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1083 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1084 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP)) { |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1085 | rc = -EIO; /* bad smb */ |
| 1086 | goto psx_create_err; |
| 1087 | } |
| 1088 | |
| 1089 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1090 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1091 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1092 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1093 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1094 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1095 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1096 | /* Let caller know file was created so we can set the mode. */ |
| 1097 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1098 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1099 | *pOplock |= CIFS_CREATE_ACTION; |
| 1100 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1101 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1102 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1103 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1104 | } else { |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1105 | if (get_bcc(&pSMBr->hdr) < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1106 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1107 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1108 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1109 | goto psx_create_err; |
| 1110 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1111 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1112 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1113 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1114 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1115 | |
| 1116 | psx_create_err: |
| 1117 | cifs_buf_release(pSMB); |
| 1118 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1119 | if (posix_flags & SMB_O_DIRECTORY) |
| 1120 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1121 | else |
| 1122 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1123 | |
| 1124 | if (rc == -EAGAIN) |
| 1125 | goto PsxCreat; |
| 1126 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1127 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1130 | static __u16 convert_disposition(int disposition) |
| 1131 | { |
| 1132 | __u16 ofun = 0; |
| 1133 | |
| 1134 | switch (disposition) { |
| 1135 | case FILE_SUPERSEDE: |
| 1136 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1137 | break; |
| 1138 | case FILE_OPEN: |
| 1139 | ofun = SMBOPEN_OAPPEND; |
| 1140 | break; |
| 1141 | case FILE_CREATE: |
| 1142 | ofun = SMBOPEN_OCREATE; |
| 1143 | break; |
| 1144 | case FILE_OPEN_IF: |
| 1145 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1146 | break; |
| 1147 | case FILE_OVERWRITE: |
| 1148 | ofun = SMBOPEN_OTRUNC; |
| 1149 | break; |
| 1150 | case FILE_OVERWRITE_IF: |
| 1151 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1152 | break; |
| 1153 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1154 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1155 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1156 | } |
| 1157 | return ofun; |
| 1158 | } |
| 1159 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1160 | static int |
| 1161 | access_flags_to_smbopen_mode(const int access_flags) |
| 1162 | { |
| 1163 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1164 | |
| 1165 | if (masked_flags == GENERIC_READ) |
| 1166 | return SMBOPEN_READ; |
| 1167 | else if (masked_flags == GENERIC_WRITE) |
| 1168 | return SMBOPEN_WRITE; |
| 1169 | |
| 1170 | /* just go for read/write */ |
| 1171 | return SMBOPEN_READWRITE; |
| 1172 | } |
| 1173 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1174 | int |
| 1175 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
| 1176 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1177 | const int access_flags, const int create_options, __u16 *netfid, |
| 1178 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1179 | const struct nls_table *nls_codepage, int remap) |
| 1180 | { |
| 1181 | int rc = -EACCES; |
| 1182 | OPENX_REQ *pSMB = NULL; |
| 1183 | OPENX_RSP *pSMBr = NULL; |
| 1184 | int bytes_returned; |
| 1185 | int name_len; |
| 1186 | __u16 count; |
| 1187 | |
| 1188 | OldOpenRetry: |
| 1189 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1190 | (void **) &pSMBr); |
| 1191 | if (rc) |
| 1192 | return rc; |
| 1193 | |
| 1194 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1195 | |
| 1196 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1197 | count = 1; /* account for one byte pad to word boundary */ |
| 1198 | name_len = |
| 1199 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
| 1200 | fileName, PATH_MAX, nls_codepage, remap); |
| 1201 | name_len++; /* trailing null */ |
| 1202 | name_len *= 2; |
| 1203 | } else { /* BB improve check for buffer overruns BB */ |
| 1204 | count = 0; /* no pad */ |
| 1205 | name_len = strnlen(fileName, PATH_MAX); |
| 1206 | name_len++; /* trailing null */ |
| 1207 | strncpy(pSMB->fileName, fileName, name_len); |
| 1208 | } |
| 1209 | if (*pOplock & REQ_OPLOCK) |
| 1210 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1211 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1212 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1213 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1214 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1215 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1216 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1217 | /* set file as system file if special file such |
| 1218 | as fifo and server expecting SFU style and |
| 1219 | no Unix extensions */ |
| 1220 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1221 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1222 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1223 | else /* BB FIXME BB */ |
| 1224 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1225 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1226 | if (create_options & CREATE_OPTION_READONLY) |
| 1227 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1228 | |
| 1229 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1230 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1231 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1232 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1233 | |
| 1234 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1235 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1236 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1237 | inc_rfc1001_len(pSMB, count); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1238 | |
| 1239 | pSMB->ByteCount = cpu_to_le16(count); |
| 1240 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1241 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1242 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1243 | cifs_stats_inc(&tcon->num_opens); |
| 1244 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1245 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1246 | } else { |
| 1247 | /* BB verify if wct == 15 */ |
| 1248 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1249 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1250 | |
| 1251 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1252 | /* Let caller know file was created so we can set the mode. */ |
| 1253 | /* Do we care about the CreateAction in any other cases? */ |
| 1254 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1255 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1256 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1257 | /* BB FIXME END */ |
| 1258 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1259 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1260 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1261 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1262 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1263 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1264 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1265 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1266 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1267 | pfile_info->AllocationSize = |
| 1268 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1269 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1270 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1271 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | cifs_buf_release(pSMB); |
| 1276 | if (rc == -EAGAIN) |
| 1277 | goto OldOpenRetry; |
| 1278 | return rc; |
| 1279 | } |
| 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | int |
| 1282 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
| 1283 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1284 | const int access_flags, const int create_options, __u16 *netfid, |
| 1285 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1286 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | { |
| 1288 | int rc = -EACCES; |
| 1289 | OPEN_REQ *pSMB = NULL; |
| 1290 | OPEN_RSP *pSMBr = NULL; |
| 1291 | int bytes_returned; |
| 1292 | int name_len; |
| 1293 | __u16 count; |
| 1294 | |
| 1295 | openRetry: |
| 1296 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1297 | (void **) &pSMBr); |
| 1298 | if (rc) |
| 1299 | return rc; |
| 1300 | |
| 1301 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1302 | |
| 1303 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1304 | count = 1; /* account for one byte pad to word boundary */ |
| 1305 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 1306 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1307 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | name_len++; /* trailing null */ |
| 1309 | name_len *= 2; |
| 1310 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1311 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | count = 0; /* no pad */ |
| 1313 | name_len = strnlen(fileName, PATH_MAX); |
| 1314 | name_len++; /* trailing null */ |
| 1315 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1316 | strncpy(pSMB->fileName, fileName, name_len); |
| 1317 | } |
| 1318 | if (*pOplock & REQ_OPLOCK) |
| 1319 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1320 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1323 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1324 | /* set file as system file if special file such |
| 1325 | as fifo and server expecting SFU style and |
| 1326 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1327 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1328 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1329 | else |
| 1330 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1333 | /* but it helps speed up case sensitive checks for other |
| 1334 | servers such as Samba */ |
| 1335 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1336 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1337 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1338 | if (create_options & CREATE_OPTION_READONLY) |
| 1339 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1342 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1343 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1344 | /* BB Expirement with various impersonation levels and verify */ |
| 1345 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | pSMB->SecurityFlags = |
| 1347 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1348 | |
| 1349 | count += name_len; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1350 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
| 1352 | pSMB->ByteCount = cpu_to_le16(count); |
| 1353 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1354 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1355 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1356 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1358 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1360 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1362 | /* Let caller know file was created so we can set the mode. */ |
| 1363 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1364 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1365 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1366 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1367 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1368 | 36 /* CreationTime to Attributes */); |
| 1369 | /* the file_info buf is endian converted by caller */ |
| 1370 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1371 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1372 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1373 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | cifs_buf_release(pSMB); |
| 1378 | if (rc == -EAGAIN) |
| 1379 | goto openRetry; |
| 1380 | return rc; |
| 1381 | } |
| 1382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1384 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
| 1385 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
| 1386 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | { |
| 1388 | int rc = -EACCES; |
| 1389 | READ_REQ *pSMB = NULL; |
| 1390 | READ_RSP *pSMBr = NULL; |
| 1391 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1392 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1393 | int resp_buf_type = 0; |
| 1394 | struct kvec iov[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1396 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1397 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1398 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1399 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1400 | wct = 10; /* old style read */ |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1401 | if ((lseek >> 32) > 0) { |
| 1402 | /* can not handle this big offset for old */ |
| 1403 | return -EIO; |
| 1404 | } |
| 1405 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
| 1407 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1408 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | if (rc) |
| 1410 | return rc; |
| 1411 | |
| 1412 | /* tcon and ses pointer are checked in smb_init */ |
| 1413 | if (tcon->ses->server == NULL) |
| 1414 | return -ECONNABORTED; |
| 1415 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1416 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | pSMB->Fid = netfid; |
| 1418 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1419 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1420 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | pSMB->Remaining = 0; |
| 1423 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1424 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1425 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1426 | pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1427 | else { |
| 1428 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1429 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1430 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1431 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1432 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1433 | |
| 1434 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1435 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1436 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1437 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1438 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1439 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1441 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | } else { |
| 1443 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1444 | data_length = data_length << 16; |
| 1445 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1446 | *nbytes = data_length; |
| 1447 | |
| 1448 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1449 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1451 | cFYI(1, "bad length %d for count %d", |
| 1452 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | rc = -EIO; |
| 1454 | *nbytes = 0; |
| 1455 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1456 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1457 | le16_to_cpu(pSMBr->DataOffset); |
| 1458 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1459 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1460 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1461 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1462 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1463 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | } |
| 1465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1467 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1468 | if (*buf) { |
| 1469 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1470 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1471 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1472 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1473 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1474 | /* return buffer to caller to free */ |
| 1475 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1476 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1477 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1478 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1479 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1480 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1481 | |
| 1482 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | since file handle passed in no longer valid */ |
| 1484 | return rc; |
| 1485 | } |
| 1486 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | int |
| 1489 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, |
| 1490 | const int netfid, const unsigned int count, |
| 1491 | const __u64 offset, unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1492 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | { |
| 1494 | int rc = -EACCES; |
| 1495 | WRITE_REQ *pSMB = NULL; |
| 1496 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1497 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | __u32 bytes_sent; |
| 1499 | __u16 byte_count; |
| 1500 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1501 | *nbytes = 0; |
| 1502 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1503 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1504 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1505 | return -ECONNABORTED; |
| 1506 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1507 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1508 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1509 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1510 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1511 | if ((offset >> 32) > 0) { |
| 1512 | /* can not handle big offset for old srv */ |
| 1513 | return -EIO; |
| 1514 | } |
| 1515 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1516 | |
| 1517 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | (void **) &pSMBr); |
| 1519 | if (rc) |
| 1520 | return rc; |
| 1521 | /* tcon and ses pointer are checked in smb_init */ |
| 1522 | if (tcon->ses->server == NULL) |
| 1523 | return -ECONNABORTED; |
| 1524 | |
| 1525 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1526 | pSMB->Fid = netfid; |
| 1527 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1528 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1529 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | pSMB->Reserved = 0xFFFFFFFF; |
| 1532 | pSMB->WriteMode = 0; |
| 1533 | pSMB->Remaining = 0; |
| 1534 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1535 | /* Can increase buffer size if buffer is big enough in some cases ie we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1537 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1538 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1539 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1541 | } else { |
| 1542 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1543 | & ~0xFF; |
| 1544 | } |
| 1545 | |
| 1546 | if (bytes_sent > count) |
| 1547 | bytes_sent = count; |
| 1548 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1549 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1550 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1551 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1552 | else if (ubuf) { |
| 1553 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | cifs_buf_release(pSMB); |
| 1555 | return -EFAULT; |
| 1556 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1557 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | /* No buffer */ |
| 1559 | cifs_buf_release(pSMB); |
| 1560 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1561 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1562 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1563 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1564 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1565 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1568 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1569 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1570 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1571 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1572 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1573 | else { /* old style write has byte count 4 bytes earlier |
| 1574 | so 4 bytes pad */ |
| 1575 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1576 | (struct smb_com_writex_req *)pSMB; |
| 1577 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1578 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1581 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1582 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1584 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } else { |
| 1586 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1587 | *nbytes = (*nbytes) << 16; |
| 1588 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1589 | |
| 1590 | /* |
| 1591 | * Mask off high 16 bits when bytes written as returned by the |
| 1592 | * server is greater than bytes requested by the client. Some |
| 1593 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1594 | */ |
| 1595 | if (*nbytes > count) |
| 1596 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | cifs_buf_release(pSMB); |
| 1600 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1601 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | since file handle passed in no longer valid */ |
| 1603 | |
| 1604 | return rc; |
| 1605 | } |
| 1606 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1607 | int |
| 1608 | CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | const int netfid, const unsigned int count, |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1610 | const __u64 offset, unsigned int *nbytes, struct kvec *iov, |
| 1611 | int n_vec, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
| 1613 | int rc = -EACCES; |
| 1614 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1615 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1616 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1617 | int resp_buf_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 1619 | *nbytes = 0; |
| 1620 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1621 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 1622 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1623 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1624 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1625 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1626 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1627 | if ((offset >> 32) > 0) { |
| 1628 | /* can not handle big offset for old srv */ |
| 1629 | return -EIO; |
| 1630 | } |
| 1631 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1632 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | if (rc) |
| 1634 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | /* tcon and ses pointer are checked in smb_init */ |
| 1636 | if (tcon->ses->server == NULL) |
| 1637 | return -ECONNABORTED; |
| 1638 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1639 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | pSMB->Fid = netfid; |
| 1641 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1642 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1643 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | pSMB->Reserved = 0xFFFFFFFF; |
| 1645 | pSMB->WriteMode = 0; |
| 1646 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1649 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1651 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 1652 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1653 | /* header + 1 byte pad */ |
| 1654 | smb_hdr_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 1; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1655 | if (wct == 14) |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1656 | inc_rfc1001_len(pSMB, count + 1); |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1657 | else /* wct == 12 */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1658 | inc_rfc1001_len(pSMB, count + 5); /* smb data starts later */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1659 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1660 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 1661 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1662 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1663 | (struct smb_com_writex_req *)pSMB; |
| 1664 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 1665 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1666 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1667 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1668 | iov[0].iov_len = smb_hdr_len + 4; |
| 1669 | else /* wct == 12 pad bigger by four bytes */ |
| 1670 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1671 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1672 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1673 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1674 | long_op); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1675 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1677 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1678 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1679 | /* presumably this can not happen, but best to be safe */ |
| 1680 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1681 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1682 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1683 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1684 | *nbytes = (*nbytes) << 16; |
| 1685 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1686 | |
| 1687 | /* |
| 1688 | * Mask off high 16 bits when bytes written as returned by the |
| 1689 | * server is greater than bytes requested by the client. OS/2 |
| 1690 | * servers are known to set incorrect CountHigh values. |
| 1691 | */ |
| 1692 | if (*nbytes > count) |
| 1693 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1696 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1697 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1698 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1699 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1700 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1702 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | since file handle passed in no longer valid */ |
| 1704 | |
| 1705 | return rc; |
| 1706 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1707 | |
| 1708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | int |
| 1710 | CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, |
| 1711 | const __u16 smb_file_id, const __u64 len, |
| 1712 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1713 | const __u32 numLock, const __u8 lockType, |
| 1714 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | { |
| 1716 | int rc = 0; |
| 1717 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1718 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | int bytes_returned; |
| 1720 | int timeout = 0; |
| 1721 | __u16 count; |
| 1722 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1723 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1724 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 1725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | if (rc) |
| 1727 | return rc; |
| 1728 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1729 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1730 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1732 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1733 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 1735 | } else { |
| 1736 | pSMB->Timeout = 0; |
| 1737 | } |
| 1738 | |
| 1739 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 1740 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 1741 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1742 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1744 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 1745 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1746 | if ((numLock != 0) || (numUnlock != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
| 1748 | /* BB where to store pid high? */ |
| 1749 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 1750 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 1751 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 1752 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 1753 | count = sizeof(LOCKING_ANDX_RANGE); |
| 1754 | } else { |
| 1755 | /* oplock break */ |
| 1756 | count = 0; |
| 1757 | } |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1758 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | pSMB->ByteCount = cpu_to_le16(count); |
| 1760 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1761 | if (waitFlag) { |
| 1762 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1763 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1764 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1765 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1766 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, |
| 1767 | timeout); |
| 1768 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1769 | } |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1770 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1771 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1772 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1774 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1775 | since file handle passed in no longer valid */ |
| 1776 | return rc; |
| 1777 | } |
| 1778 | |
| 1779 | int |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1780 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
| 1781 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1782 | struct file_lock *pLockData, const __u16 lock_type, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1783 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1784 | { |
| 1785 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 1786 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1787 | struct cifs_posix_lock *parm_data; |
| 1788 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1789 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1790 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1791 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1792 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1793 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1794 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1795 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1796 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1797 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 1798 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1799 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1800 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 1801 | |
| 1802 | if (rc) |
| 1803 | return rc; |
| 1804 | |
| 1805 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 1806 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1807 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1808 | pSMB->MaxSetupCount = 0; |
| 1809 | pSMB->Reserved = 0; |
| 1810 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1811 | pSMB->Reserved2 = 0; |
| 1812 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 1813 | offset = param_offset + params; |
| 1814 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1815 | count = sizeof(struct cifs_posix_lock); |
| 1816 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1817 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1818 | pSMB->SetupCount = 1; |
| 1819 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1820 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1821 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 1822 | else |
| 1823 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 1824 | byte_count = 3 /* pad */ + params + count; |
| 1825 | pSMB->DataCount = cpu_to_le16(count); |
| 1826 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1827 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1828 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1829 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1830 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1831 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 1832 | |
| 1833 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1834 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1835 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1836 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1837 | pSMB->Timeout = cpu_to_le32(-1); |
| 1838 | } else |
| 1839 | pSMB->Timeout = 0; |
| 1840 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1841 | parm_data->pid = cpu_to_le32(current->tgid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1842 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1843 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1844 | |
| 1845 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 1846 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1847 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 1848 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1849 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1850 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1851 | if (waitFlag) { |
| 1852 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 1853 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 1854 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1855 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 1856 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1857 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 1858 | &resp_buf_type, timeout); |
| 1859 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 1860 | not try to free it twice below on exit */ |
| 1861 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1864 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1865 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1866 | } else if (get_flag) { |
| 1867 | /* lock structure can be returned on get */ |
| 1868 | __u16 data_offset; |
| 1869 | __u16 data_count; |
| 1870 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1871 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 1872 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(*parm_data)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1873 | rc = -EIO; /* bad smb */ |
| 1874 | goto plk_err_exit; |
| 1875 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1876 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 1877 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1878 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1879 | rc = -EIO; |
| 1880 | goto plk_err_exit; |
| 1881 | } |
| 1882 | parm_data = (struct cifs_posix_lock *) |
| 1883 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1884 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1885 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1886 | else { |
| 1887 | if (parm_data->lock_type == |
| 1888 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 1889 | pLockData->fl_type = F_RDLCK; |
| 1890 | else if (parm_data->lock_type == |
| 1891 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 1892 | pLockData->fl_type = F_WRLCK; |
| 1893 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 1894 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 1895 | pLockData->fl_end = pLockData->fl_start + |
| 1896 | le64_to_cpu(parm_data->length) - 1; |
| 1897 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1898 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1899 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1900 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1901 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1902 | if (pSMB) |
| 1903 | cifs_small_buf_release(pSMB); |
| 1904 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1905 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 1906 | cifs_small_buf_release(iov[0].iov_base); |
| 1907 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 1908 | cifs_buf_release(iov[0].iov_base); |
| 1909 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1910 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 1911 | since file handle passed in no longer valid */ |
| 1912 | |
| 1913 | return rc; |
| 1914 | } |
| 1915 | |
| 1916 | |
| 1917 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1919 | { |
| 1920 | int rc = 0; |
| 1921 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1922 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
| 1924 | /* do not retry on dead session on close */ |
| 1925 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1926 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | return 0; |
| 1928 | if (rc) |
| 1929 | return rc; |
| 1930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 1932 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1934 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1935 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1937 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1939 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | } |
| 1941 | } |
| 1942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1944 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | rc = 0; |
| 1946 | |
| 1947 | return rc; |
| 1948 | } |
| 1949 | |
| 1950 | int |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1951 | CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1952 | { |
| 1953 | int rc = 0; |
| 1954 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1955 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1956 | |
| 1957 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 1958 | if (rc) |
| 1959 | return rc; |
| 1960 | |
| 1961 | pSMB->FileID = (__u16) smb_file_id; |
| 1962 | pSMB->ByteCount = 0; |
| 1963 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 1964 | cifs_stats_inc(&tcon->num_flushes); |
| 1965 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1966 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1967 | |
| 1968 | return rc; |
| 1969 | } |
| 1970 | |
| 1971 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, |
| 1973 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1974 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | { |
| 1976 | int rc = 0; |
| 1977 | RENAME_REQ *pSMB = NULL; |
| 1978 | RENAME_RSP *pSMBr = NULL; |
| 1979 | int bytes_returned; |
| 1980 | int name_len, name_len2; |
| 1981 | __u16 count; |
| 1982 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1983 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | renameRetry: |
| 1985 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 1986 | (void **) &pSMBr); |
| 1987 | if (rc) |
| 1988 | return rc; |
| 1989 | |
| 1990 | pSMB->BufferFormat = 0x04; |
| 1991 | pSMB->SearchAttributes = |
| 1992 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 1993 | ATTR_DIRECTORY); |
| 1994 | |
| 1995 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1996 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1997 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1998 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | name_len++; /* trailing null */ |
| 2000 | name_len *= 2; |
| 2001 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2002 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2003 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 2004 | name_len2 = |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2005 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2006 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2008 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2009 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | name_len = strnlen(fromName, PATH_MAX); |
| 2011 | name_len++; /* trailing null */ |
| 2012 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2013 | name_len2 = strnlen(toName, PATH_MAX); |
| 2014 | name_len2++; /* trailing null */ |
| 2015 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2016 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2017 | name_len2++; /* trailing null */ |
| 2018 | name_len2++; /* signature byte */ |
| 2019 | } |
| 2020 | |
| 2021 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2022 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | pSMB->ByteCount = cpu_to_le16(count); |
| 2024 | |
| 2025 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2026 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2027 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2028 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2029 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | cifs_buf_release(pSMB); |
| 2032 | |
| 2033 | if (rc == -EAGAIN) |
| 2034 | goto renameRetry; |
| 2035 | |
| 2036 | return rc; |
| 2037 | } |
| 2038 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2039 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2040 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2041 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | { |
| 2043 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2044 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2045 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | char *data_offset; |
| 2047 | char dummy_string[30]; |
| 2048 | int rc = 0; |
| 2049 | int bytes_returned = 0; |
| 2050 | int len_of_str; |
| 2051 | __u16 params, param_offset, offset, count, byte_count; |
| 2052 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2053 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2055 | (void **) &pSMBr); |
| 2056 | if (rc) |
| 2057 | return rc; |
| 2058 | |
| 2059 | params = 6; |
| 2060 | pSMB->MaxSetupCount = 0; |
| 2061 | pSMB->Reserved = 0; |
| 2062 | pSMB->Flags = 0; |
| 2063 | pSMB->Timeout = 0; |
| 2064 | pSMB->Reserved2 = 0; |
| 2065 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2066 | offset = param_offset + params; |
| 2067 | |
| 2068 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2069 | rename_info = (struct set_file_rename *) data_offset; |
| 2070 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2071 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | pSMB->SetupCount = 1; |
| 2073 | pSMB->Reserved3 = 0; |
| 2074 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2075 | byte_count = 3 /* pad */ + params; |
| 2076 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2077 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2078 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2079 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2080 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2081 | rename_info->overwrite = cpu_to_le32(1); |
| 2082 | rename_info->root_fid = 0; |
| 2083 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2084 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2085 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
| 2086 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2087 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | } else { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2089 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2090 | target_name, PATH_MAX, nls_codepage, |
| 2091 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | } |
| 2093 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2094 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | byte_count += count; |
| 2096 | pSMB->DataCount = cpu_to_le16(count); |
| 2097 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2098 | pSMB->Fid = netfid; |
| 2099 | pSMB->InformationLevel = |
| 2100 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2101 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2102 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2104 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2105 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2106 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2107 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2108 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | cifs_buf_release(pSMB); |
| 2111 | |
| 2112 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2113 | since file handle passed in no longer valid */ |
| 2114 | |
| 2115 | return rc; |
| 2116 | } |
| 2117 | |
| 2118 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2119 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
| 2120 | const __u16 target_tid, const char *toName, const int flags, |
| 2121 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | { |
| 2123 | int rc = 0; |
| 2124 | COPY_REQ *pSMB = NULL; |
| 2125 | COPY_RSP *pSMBr = NULL; |
| 2126 | int bytes_returned; |
| 2127 | int name_len, name_len2; |
| 2128 | __u16 count; |
| 2129 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2130 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | copyRetry: |
| 2132 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2133 | (void **) &pSMBr); |
| 2134 | if (rc) |
| 2135 | return rc; |
| 2136 | |
| 2137 | pSMB->BufferFormat = 0x04; |
| 2138 | pSMB->Tid2 = target_tid; |
| 2139 | |
| 2140 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2141 | |
| 2142 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2143 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2144 | fromName, PATH_MAX, nls_codepage, |
| 2145 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | name_len++; /* trailing null */ |
| 2147 | name_len *= 2; |
| 2148 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2149 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2150 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2151 | name_len2 = |
| 2152 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2153 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2155 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2156 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | name_len = strnlen(fromName, PATH_MAX); |
| 2158 | name_len++; /* trailing null */ |
| 2159 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2160 | name_len2 = strnlen(toName, PATH_MAX); |
| 2161 | name_len2++; /* trailing null */ |
| 2162 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2163 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2164 | name_len2++; /* trailing null */ |
| 2165 | name_len2++; /* signature byte */ |
| 2166 | } |
| 2167 | |
| 2168 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2169 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | pSMB->ByteCount = cpu_to_le16(count); |
| 2171 | |
| 2172 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2173 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2174 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2175 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2176 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2178 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | |
| 2180 | if (rc == -EAGAIN) |
| 2181 | goto copyRetry; |
| 2182 | |
| 2183 | return rc; |
| 2184 | } |
| 2185 | |
| 2186 | int |
| 2187 | CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, |
| 2188 | const char *fromName, const char *toName, |
| 2189 | const struct nls_table *nls_codepage) |
| 2190 | { |
| 2191 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2192 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2193 | char *data_offset; |
| 2194 | int name_len; |
| 2195 | int name_len_target; |
| 2196 | int rc = 0; |
| 2197 | int bytes_returned = 0; |
| 2198 | __u16 params, param_offset, offset, byte_count; |
| 2199 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2200 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | createSymLinkRetry: |
| 2202 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2203 | (void **) &pSMBr); |
| 2204 | if (rc) |
| 2205 | return rc; |
| 2206 | |
| 2207 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2208 | name_len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2209 | cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | /* find define for this maxpathcomponent */ |
| 2211 | , nls_codepage); |
| 2212 | name_len++; /* trailing null */ |
| 2213 | name_len *= 2; |
| 2214 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2215 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | name_len = strnlen(fromName, PATH_MAX); |
| 2217 | name_len++; /* trailing null */ |
| 2218 | strncpy(pSMB->FileName, fromName, name_len); |
| 2219 | } |
| 2220 | params = 6 + name_len; |
| 2221 | pSMB->MaxSetupCount = 0; |
| 2222 | pSMB->Reserved = 0; |
| 2223 | pSMB->Flags = 0; |
| 2224 | pSMB->Timeout = 0; |
| 2225 | pSMB->Reserved2 = 0; |
| 2226 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2227 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | offset = param_offset + params; |
| 2229 | |
| 2230 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2231 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2232 | name_len_target = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2233 | cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | /* find define for this maxpathcomponent */ |
| 2235 | , nls_codepage); |
| 2236 | name_len_target++; /* trailing null */ |
| 2237 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2238 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2239 | name_len_target = strnlen(toName, PATH_MAX); |
| 2240 | name_len_target++; /* trailing null */ |
| 2241 | strncpy(data_offset, toName, name_len_target); |
| 2242 | } |
| 2243 | |
| 2244 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2245 | /* BB find exact max on data count below from sess */ |
| 2246 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2247 | pSMB->SetupCount = 1; |
| 2248 | pSMB->Reserved3 = 0; |
| 2249 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2250 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2251 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2252 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2253 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2254 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2255 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2256 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2257 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2258 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2259 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2261 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2262 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2263 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2264 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2265 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2267 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
| 2269 | if (rc == -EAGAIN) |
| 2270 | goto createSymLinkRetry; |
| 2271 | |
| 2272 | return rc; |
| 2273 | } |
| 2274 | |
| 2275 | int |
| 2276 | CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2277 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2278 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2279 | { |
| 2280 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2281 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2282 | char *data_offset; |
| 2283 | int name_len; |
| 2284 | int name_len_target; |
| 2285 | int rc = 0; |
| 2286 | int bytes_returned = 0; |
| 2287 | __u16 params, param_offset, offset, byte_count; |
| 2288 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2289 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | createHardLinkRetry: |
| 2291 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2292 | (void **) &pSMBr); |
| 2293 | if (rc) |
| 2294 | return rc; |
| 2295 | |
| 2296 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2297 | name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2298 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | name_len++; /* trailing null */ |
| 2300 | name_len *= 2; |
| 2301 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2302 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | name_len = strnlen(toName, PATH_MAX); |
| 2304 | name_len++; /* trailing null */ |
| 2305 | strncpy(pSMB->FileName, toName, name_len); |
| 2306 | } |
| 2307 | params = 6 + name_len; |
| 2308 | pSMB->MaxSetupCount = 0; |
| 2309 | pSMB->Reserved = 0; |
| 2310 | pSMB->Flags = 0; |
| 2311 | pSMB->Timeout = 0; |
| 2312 | pSMB->Reserved2 = 0; |
| 2313 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2314 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | offset = param_offset + params; |
| 2316 | |
| 2317 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2318 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2319 | name_len_target = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2320 | cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2321 | nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | name_len_target++; /* trailing null */ |
| 2323 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2324 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2326 | name_len_target++; /* trailing null */ |
| 2327 | strncpy(data_offset, fromName, name_len_target); |
| 2328 | } |
| 2329 | |
| 2330 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2331 | /* BB find exact max on data count below from sess*/ |
| 2332 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2333 | pSMB->SetupCount = 1; |
| 2334 | pSMB->Reserved3 = 0; |
| 2335 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2336 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2337 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2338 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2339 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2340 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2341 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2342 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2343 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2344 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2345 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2347 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2348 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2349 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2350 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2351 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | |
| 2353 | cifs_buf_release(pSMB); |
| 2354 | if (rc == -EAGAIN) |
| 2355 | goto createHardLinkRetry; |
| 2356 | |
| 2357 | return rc; |
| 2358 | } |
| 2359 | |
| 2360 | int |
| 2361 | CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2362 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2363 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | { |
| 2365 | int rc = 0; |
| 2366 | NT_RENAME_REQ *pSMB = NULL; |
| 2367 | RENAME_RSP *pSMBr = NULL; |
| 2368 | int bytes_returned; |
| 2369 | int name_len, name_len2; |
| 2370 | __u16 count; |
| 2371 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2372 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | winCreateHardLinkRetry: |
| 2374 | |
| 2375 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2376 | (void **) &pSMBr); |
| 2377 | if (rc) |
| 2378 | return rc; |
| 2379 | |
| 2380 | pSMB->SearchAttributes = |
| 2381 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2382 | ATTR_DIRECTORY); |
| 2383 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2384 | pSMB->ClusterCount = 0; |
| 2385 | |
| 2386 | pSMB->BufferFormat = 0x04; |
| 2387 | |
| 2388 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2389 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2390 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2391 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | name_len++; /* trailing null */ |
| 2393 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2394 | |
| 2395 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2396 | pSMB->OldFileName[name_len] = 0x04; |
| 2397 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | name_len2 = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2399 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2400 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2402 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2403 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | name_len = strnlen(fromName, PATH_MAX); |
| 2405 | name_len++; /* trailing null */ |
| 2406 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2407 | name_len2 = strnlen(toName, PATH_MAX); |
| 2408 | name_len2++; /* trailing null */ |
| 2409 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2410 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2411 | name_len2++; /* trailing null */ |
| 2412 | name_len2++; /* signature byte */ |
| 2413 | } |
| 2414 | |
| 2415 | count = 1 /* string type byte */ + name_len + name_len2; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2416 | inc_rfc1001_len(pSMB, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | pSMB->ByteCount = cpu_to_le16(count); |
| 2418 | |
| 2419 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2420 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2421 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2422 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2423 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | cifs_buf_release(pSMB); |
| 2426 | if (rc == -EAGAIN) |
| 2427 | goto winCreateHardLinkRetry; |
| 2428 | |
| 2429 | return rc; |
| 2430 | } |
| 2431 | |
| 2432 | int |
| 2433 | CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2434 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | const struct nls_table *nls_codepage) |
| 2436 | { |
| 2437 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2438 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2439 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2440 | int rc = 0; |
| 2441 | int bytes_returned; |
| 2442 | int name_len; |
| 2443 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2444 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2446 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | |
| 2448 | querySymLinkRetry: |
| 2449 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2450 | (void **) &pSMBr); |
| 2451 | if (rc) |
| 2452 | return rc; |
| 2453 | |
| 2454 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2455 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2456 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
| 2457 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | name_len++; /* trailing null */ |
| 2459 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2460 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | name_len = strnlen(searchName, PATH_MAX); |
| 2462 | name_len++; /* trailing null */ |
| 2463 | strncpy(pSMB->FileName, searchName, name_len); |
| 2464 | } |
| 2465 | |
| 2466 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2467 | pSMB->TotalDataCount = 0; |
| 2468 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 2469 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | pSMB->MaxSetupCount = 0; |
| 2471 | pSMB->Reserved = 0; |
| 2472 | pSMB->Flags = 0; |
| 2473 | pSMB->Timeout = 0; |
| 2474 | pSMB->Reserved2 = 0; |
| 2475 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2476 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | pSMB->DataCount = 0; |
| 2478 | pSMB->DataOffset = 0; |
| 2479 | pSMB->SetupCount = 1; |
| 2480 | pSMB->Reserved3 = 0; |
| 2481 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2482 | byte_count = params + 1 /* pad */ ; |
| 2483 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2484 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2485 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 2486 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2487 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2489 | |
| 2490 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2491 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2492 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2493 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } else { |
| 2495 | /* decode response */ |
| 2496 | |
| 2497 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2498 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2499 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2500 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2502 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2503 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2505 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 2506 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 2507 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2508 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 2509 | is_unicode = true; |
| 2510 | else |
| 2511 | is_unicode = false; |
| 2512 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2513 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 2514 | *symlinkinfo = cifs_strndup_from_ucs(data_start, count, |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2515 | is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 2516 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2517 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | } |
| 2519 | } |
| 2520 | cifs_buf_release(pSMB); |
| 2521 | if (rc == -EAGAIN) |
| 2522 | goto querySymLinkRetry; |
| 2523 | return rc; |
| 2524 | } |
| 2525 | |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 2526 | #ifdef CONFIG_CIFS_SYMLINK_EXPERIMENTAL |
| 2527 | /* |
| 2528 | * Recent Windows versions now create symlinks more frequently |
| 2529 | * and they use the "reparse point" mechanism below. We can of course |
| 2530 | * do symlinks nicely to Samba and other servers which support the |
| 2531 | * CIFS Unix Extensions and we can also do SFU symlinks and "client only" |
| 2532 | * "MF" symlinks optionally, but for recent Windows we really need to |
| 2533 | * reenable the code below and fix the cifs_symlink callers to handle this. |
| 2534 | * In the interim this code has been moved to its own config option so |
| 2535 | * it is not compiled in by default until callers fixed up and more tested. |
| 2536 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | int |
| 2538 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
| 2539 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2540 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | const struct nls_table *nls_codepage) |
| 2542 | { |
| 2543 | int rc = 0; |
| 2544 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2545 | struct smb_com_transaction_ioctl_req *pSMB; |
| 2546 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2548 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 2550 | (void **) &pSMBr); |
| 2551 | if (rc) |
| 2552 | return rc; |
| 2553 | |
| 2554 | pSMB->TotalParameterCount = 0 ; |
| 2555 | pSMB->TotalDataCount = 0; |
| 2556 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 2557 | /* BB find exact data count max from sess structure BB */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2558 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2559 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2560 | pSMB->MaxSetupCount = 4; |
| 2561 | pSMB->Reserved = 0; |
| 2562 | pSMB->ParameterOffset = 0; |
| 2563 | pSMB->DataCount = 0; |
| 2564 | pSMB->DataOffset = 0; |
| 2565 | pSMB->SetupCount = 4; |
| 2566 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 2567 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2568 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 2569 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 2570 | pSMB->IsRootFlag = 0; |
| 2571 | pSMB->Fid = fid; /* file handle always le */ |
| 2572 | pSMB->ByteCount = 0; |
| 2573 | |
| 2574 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2575 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2576 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2577 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | } else { /* decode response */ |
| 2579 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2580 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2581 | if (get_bcc(&pSMBr->hdr) < 2 || data_offset > 512) { |
| 2582 | /* BB also check enough total bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2584 | goto qreparse_out; |
| 2585 | } |
| 2586 | if (data_count && (data_count < 2048)) { |
| 2587 | char *end_of_smb = 2 /* sizeof byte count */ + |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2588 | get_bcc(&pSMBr->hdr) + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2590 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2591 | (struct reparse_data *) |
| 2592 | ((char *)&pSMBr->hdr.Protocol |
| 2593 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2594 | if ((char *)reparse_buf >= end_of_smb) { |
| 2595 | rc = -EIO; |
| 2596 | goto qreparse_out; |
| 2597 | } |
| 2598 | if ((reparse_buf->LinkNamesBuf + |
| 2599 | reparse_buf->TargetNameOffset + |
| 2600 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2601 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2602 | rc = -EIO; |
| 2603 | goto qreparse_out; |
| 2604 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2605 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2606 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2607 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2608 | (reparse_buf->LinkNamesBuf + |
| 2609 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2610 | buflen, |
| 2611 | reparse_buf->TargetNameLen, |
| 2612 | nls_codepage, 0); |
| 2613 | } else { /* ASCII names */ |
| 2614 | strncpy(symlinkinfo, |
| 2615 | reparse_buf->LinkNamesBuf + |
| 2616 | reparse_buf->TargetNameOffset, |
| 2617 | min_t(const int, buflen, |
| 2618 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2620 | } else { |
| 2621 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2622 | cFYI(1, "Invalid return data count on " |
| 2623 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2625 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 2626 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2627 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 2629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 2631 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | |
| 2633 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2634 | since file handle passed in no longer valid */ |
| 2635 | |
| 2636 | return rc; |
| 2637 | } |
Steve French | c52a9554 | 2011-02-24 06:16:22 +0000 | [diff] [blame] | 2638 | #endif /* CIFS_SYMLINK_EXPERIMENTAL */ /* BB temporarily unused */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | |
| 2640 | #ifdef CONFIG_CIFS_POSIX |
| 2641 | |
| 2642 | /*Convert an Access Control Entry from wire format to local POSIX xattr format*/ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2643 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 2644 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | { |
| 2646 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2647 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 2648 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 2649 | ace->e_id = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2650 | /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | |
| 2652 | return; |
| 2653 | } |
| 2654 | |
| 2655 | /* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2656 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 2657 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | { |
| 2659 | int size = 0; |
| 2660 | int i; |
| 2661 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2662 | struct cifs_posix_ace *pACE; |
| 2663 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 2664 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
| 2666 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 2667 | return -EOPNOTSUPP; |
| 2668 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2669 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2671 | pACE = &cifs_acl->ace_array[0]; |
| 2672 | size = sizeof(struct cifs_posix_acl); |
| 2673 | size += sizeof(struct cifs_posix_ace) * count; |
| 2674 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2675 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2676 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 2677 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | return -EINVAL; |
| 2679 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2680 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2682 | size = sizeof(struct cifs_posix_acl); |
| 2683 | size += sizeof(struct cifs_posix_ace) * count; |
| 2684 | /* skip past access ACEs to get to default ACEs */ |
| 2685 | pACE = &cifs_acl->ace_array[count]; |
| 2686 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 2687 | size += sizeof(struct cifs_posix_ace) * count; |
| 2688 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2689 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | return -EINVAL; |
| 2691 | } else { |
| 2692 | /* illegal type */ |
| 2693 | return -EINVAL; |
| 2694 | } |
| 2695 | |
| 2696 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2697 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2698 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2699 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | return -ERANGE; |
| 2701 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2702 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2703 | for (i = 0; i < count ; i++) { |
| 2704 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 2705 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | return size; |
| 2709 | } |
| 2710 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2711 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 2712 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | { |
| 2714 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 2715 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2716 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 2717 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2719 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 2721 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2722 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2723 | cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2724 | /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | return rc; |
| 2726 | } |
| 2727 | |
| 2728 | /* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2729 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 2730 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | { |
| 2732 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2733 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 2734 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | int count; |
| 2736 | int i; |
| 2737 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2738 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | return 0; |
| 2740 | |
| 2741 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2742 | cFYI(1, "setting acl with %d entries from buf of length %d and " |
Steve French | 63135e0 | 2007-07-17 17:34:02 +0000 | [diff] [blame] | 2743 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2744 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2745 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2746 | cFYI(1, "unknown POSIX ACL version %d", |
| 2747 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | return 0; |
| 2749 | } |
| 2750 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2751 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2752 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2753 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2754 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2756 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | return 0; |
| 2758 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2759 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 2761 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2762 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | /* ACE not converted */ |
| 2764 | break; |
| 2765 | } |
| 2766 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2767 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2768 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 2769 | rc += sizeof(struct cifs_posix_acl); |
| 2770 | /* BB add check to make sure ACL does not overflow SMB */ |
| 2771 | } |
| 2772 | return rc; |
| 2773 | } |
| 2774 | |
| 2775 | int |
| 2776 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2777 | const unsigned char *searchName, |
| 2778 | char *acl_inf, const int buflen, const int acl_type, |
| 2779 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | { |
| 2781 | /* SMB_QUERY_POSIX_ACL */ |
| 2782 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2783 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2784 | int rc = 0; |
| 2785 | int bytes_returned; |
| 2786 | int name_len; |
| 2787 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2788 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2789 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | |
| 2791 | queryAclRetry: |
| 2792 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2793 | (void **) &pSMBr); |
| 2794 | if (rc) |
| 2795 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2796 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2798 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2799 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2800 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | name_len++; /* trailing null */ |
| 2802 | name_len *= 2; |
| 2803 | pSMB->FileName[name_len] = 0; |
| 2804 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2805 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | name_len = strnlen(searchName, PATH_MAX); |
| 2807 | name_len++; /* trailing null */ |
| 2808 | strncpy(pSMB->FileName, searchName, name_len); |
| 2809 | } |
| 2810 | |
| 2811 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2812 | pSMB->TotalDataCount = 0; |
| 2813 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2814 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2816 | pSMB->MaxSetupCount = 0; |
| 2817 | pSMB->Reserved = 0; |
| 2818 | pSMB->Flags = 0; |
| 2819 | pSMB->Timeout = 0; |
| 2820 | pSMB->Reserved2 = 0; |
| 2821 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2822 | offsetof(struct smb_com_transaction2_qpi_req, |
| 2823 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | pSMB->DataCount = 0; |
| 2825 | pSMB->DataOffset = 0; |
| 2826 | pSMB->SetupCount = 1; |
| 2827 | pSMB->Reserved3 = 0; |
| 2828 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2829 | byte_count = params + 1 /* pad */ ; |
| 2830 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2831 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2832 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 2833 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2834 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2836 | |
| 2837 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2838 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2839 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2841 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2842 | } else { |
| 2843 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2845 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2847 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | rc = -EIO; /* bad smb */ |
| 2849 | else { |
| 2850 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2851 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2852 | rc = cifs_copy_posix_acl(acl_inf, |
| 2853 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2854 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2855 | } |
| 2856 | } |
| 2857 | cifs_buf_release(pSMB); |
| 2858 | if (rc == -EAGAIN) |
| 2859 | goto queryAclRetry; |
| 2860 | return rc; |
| 2861 | } |
| 2862 | |
| 2863 | int |
| 2864 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2865 | const unsigned char *fileName, |
| 2866 | const char *local_acl, const int buflen, |
| 2867 | const int acl_type, |
| 2868 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | { |
| 2870 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 2871 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 2872 | char *parm_data; |
| 2873 | int name_len; |
| 2874 | int rc = 0; |
| 2875 | int bytes_returned = 0; |
| 2876 | __u16 params, byte_count, data_count, param_offset, offset; |
| 2877 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2878 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2879 | setAclRetry: |
| 2880 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2881 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | if (rc) |
| 2883 | return rc; |
| 2884 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2885 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2886 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2887 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | name_len++; /* trailing null */ |
| 2889 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2890 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | name_len = strnlen(fileName, PATH_MAX); |
| 2892 | name_len++; /* trailing null */ |
| 2893 | strncpy(pSMB->FileName, fileName, name_len); |
| 2894 | } |
| 2895 | params = 6 + name_len; |
| 2896 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2897 | /* BB find max SMB size from sess */ |
| 2898 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | pSMB->MaxSetupCount = 0; |
| 2900 | pSMB->Reserved = 0; |
| 2901 | pSMB->Flags = 0; |
| 2902 | pSMB->Timeout = 0; |
| 2903 | pSMB->Reserved2 = 0; |
| 2904 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2905 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | offset = param_offset + params; |
| 2907 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 2908 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2909 | |
| 2910 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2911 | data_count = ACL_to_cifs_posix(parm_data, local_acl, buflen, acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2913 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | rc = -EOPNOTSUPP; |
| 2915 | goto setACLerrorExit; |
| 2916 | } |
| 2917 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2918 | pSMB->SetupCount = 1; |
| 2919 | pSMB->Reserved3 = 0; |
| 2920 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2921 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 2922 | byte_count = 3 /* pad */ + params + data_count; |
| 2923 | pSMB->DataCount = cpu_to_le16(data_count); |
| 2924 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2925 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2926 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2927 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2928 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2930 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2931 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2932 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2933 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | |
| 2935 | setACLerrorExit: |
| 2936 | cifs_buf_release(pSMB); |
| 2937 | if (rc == -EAGAIN) |
| 2938 | goto setAclRetry; |
| 2939 | return rc; |
| 2940 | } |
| 2941 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2942 | /* BB fix tabs in this function FIXME BB */ |
| 2943 | int |
| 2944 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2945 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2946 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2947 | int rc = 0; |
| 2948 | struct smb_t2_qfi_req *pSMB = NULL; |
| 2949 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 2950 | int bytes_returned; |
| 2951 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2952 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2953 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2954 | if (tcon == NULL) |
| 2955 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2956 | |
| 2957 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2958 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2959 | (void **) &pSMBr); |
| 2960 | if (rc) |
| 2961 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2962 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2963 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2964 | pSMB->t2.TotalDataCount = 0; |
| 2965 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 2966 | /* BB find exact max data count below from sess structure BB */ |
| 2967 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 2968 | pSMB->t2.MaxSetupCount = 0; |
| 2969 | pSMB->t2.Reserved = 0; |
| 2970 | pSMB->t2.Flags = 0; |
| 2971 | pSMB->t2.Timeout = 0; |
| 2972 | pSMB->t2.Reserved2 = 0; |
| 2973 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 2974 | Fid) - 4); |
| 2975 | pSMB->t2.DataCount = 0; |
| 2976 | pSMB->t2.DataOffset = 0; |
| 2977 | pSMB->t2.SetupCount = 1; |
| 2978 | pSMB->t2.Reserved3 = 0; |
| 2979 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2980 | byte_count = params + 1 /* pad */ ; |
| 2981 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 2982 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 2983 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 2984 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2985 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 2986 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2987 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2988 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2989 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2990 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2991 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2992 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2993 | } else { |
| 2994 | /* decode response */ |
| 2995 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2996 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 2997 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2998 | /* If rc should we check for EOPNOSUPP and |
| 2999 | disable the srvino flag? or in caller? */ |
| 3000 | rc = -EIO; /* bad smb */ |
| 3001 | else { |
| 3002 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3003 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 3004 | struct file_chattr_info *pfinfo; |
| 3005 | /* BB Do we need a cast or hash here ? */ |
| 3006 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3007 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3008 | rc = -EIO; |
| 3009 | goto GetExtAttrOut; |
| 3010 | } |
| 3011 | pfinfo = (struct file_chattr_info *) |
| 3012 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 3013 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3014 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3015 | } |
| 3016 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3017 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3018 | cifs_buf_release(pSMB); |
| 3019 | if (rc == -EAGAIN) |
| 3020 | goto GetExtAttrRetry; |
| 3021 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3024 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3026 | #ifdef CONFIG_CIFS_ACL |
| 3027 | /* |
| 3028 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3029 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3030 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3031 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3032 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3033 | * by caller |
| 3034 | */ |
| 3035 | static int |
| 3036 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
| 3037 | const int parm_len, struct cifsTconInfo *tcon, |
| 3038 | void **ret_buf) |
| 3039 | { |
| 3040 | int rc; |
| 3041 | __u32 temp_offset; |
| 3042 | struct smb_com_ntransact_req *pSMB; |
| 3043 | |
| 3044 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3045 | (void **)&pSMB); |
| 3046 | if (rc) |
| 3047 | return rc; |
| 3048 | *ret_buf = (void *)pSMB; |
| 3049 | pSMB->Reserved = 0; |
| 3050 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3051 | pSMB->TotalDataCount = 0; |
| 3052 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 3053 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3054 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3055 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3056 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3057 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3058 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3059 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3060 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3061 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3062 | return 0; |
| 3063 | } |
| 3064 | |
| 3065 | static int |
| 3066 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3067 | __u32 *pparmlen, __u32 *pdatalen) |
| 3068 | { |
| 3069 | char *end_of_smb; |
| 3070 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3071 | struct smb_com_ntransact_rsp *pSMBr; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3072 | u16 bcc; |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3073 | |
| 3074 | *pdatalen = 0; |
| 3075 | *pparmlen = 0; |
| 3076 | |
| 3077 | if (buf == NULL) |
| 3078 | return -EINVAL; |
| 3079 | |
| 3080 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3081 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3082 | bcc = get_bcc(&pSMBr->hdr); |
| 3083 | end_of_smb = 2 /* sizeof byte count */ + bcc + |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3084 | (char *)&pSMBr->ByteCount; |
| 3085 | |
| 3086 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3087 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3088 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3089 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3090 | |
| 3091 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3092 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3093 | |
| 3094 | /* should we also check that parm and data areas do not overlap? */ |
| 3095 | if (*ppparm > end_of_smb) { |
| 3096 | cFYI(1, "parms start after end of smb"); |
| 3097 | return -EINVAL; |
| 3098 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3099 | cFYI(1, "parm end after end of smb"); |
| 3100 | return -EINVAL; |
| 3101 | } else if (*ppdata > end_of_smb) { |
| 3102 | cFYI(1, "data starts after end of smb"); |
| 3103 | return -EINVAL; |
| 3104 | } else if (data_count + *ppdata > end_of_smb) { |
| 3105 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3106 | *ppdata, data_count, (data_count + *ppdata), |
| 3107 | end_of_smb, pSMBr); |
| 3108 | return -EINVAL; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3109 | } else if (parm_count + data_count > bcc) { |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3110 | cFYI(1, "parm count and data count larger than SMB"); |
| 3111 | return -EINVAL; |
| 3112 | } |
| 3113 | *pdatalen = data_count; |
| 3114 | *pparmlen = parm_count; |
| 3115 | return 0; |
| 3116 | } |
| 3117 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3118 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3119 | int |
| 3120 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3121 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3122 | { |
| 3123 | int rc = 0; |
| 3124 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3125 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3126 | struct kvec iov[1]; |
| 3127 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3128 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3129 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3130 | *pbuflen = 0; |
| 3131 | *acl_inf = NULL; |
| 3132 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3133 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3134 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3135 | if (rc) |
| 3136 | return rc; |
| 3137 | |
| 3138 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3139 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3140 | pSMB->MaxSetupCount = 0; |
| 3141 | pSMB->Fid = fid; /* file handle always le */ |
| 3142 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3143 | CIFS_ACL_DACL); |
| 3144 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3145 | inc_rfc1001_len(pSMB, 11); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3146 | iov[0].iov_base = (char *)pSMB; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3147 | iov[0].iov_len = be32_to_cpu(pSMB->hdr.smb_buf_length) + 4; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3148 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3149 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3150 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3151 | cifs_stats_inc(&tcon->num_acl_get); |
| 3152 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3153 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3154 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3155 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3156 | __u32 parm_len; |
| 3157 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3158 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3159 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3160 | |
| 3161 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3162 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3163 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3164 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3165 | goto qsec_out; |
| 3166 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3167 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3168 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3169 | |
| 3170 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3171 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3172 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3173 | goto qsec_out; |
| 3174 | } |
| 3175 | |
| 3176 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3177 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3178 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3179 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3180 | cERROR(1, "acl length %d does not match %d", |
| 3181 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3182 | if (*pbuflen > acl_len) |
| 3183 | *pbuflen = acl_len; |
| 3184 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3185 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3186 | /* check if buffer is big enough for the acl |
| 3187 | header followed by the smallest SID */ |
| 3188 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3189 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3190 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3191 | rc = -EINVAL; |
| 3192 | *pbuflen = 0; |
| 3193 | } else { |
| 3194 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3195 | if (*acl_inf == NULL) { |
| 3196 | *pbuflen = 0; |
| 3197 | rc = -ENOMEM; |
| 3198 | } |
| 3199 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3200 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3201 | } |
| 3202 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3203 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3204 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3205 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3206 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3207 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3208 | return rc; |
| 3209 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3210 | |
| 3211 | int |
| 3212 | CIFSSMBSetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
| 3213 | struct cifs_ntsd *pntsd, __u32 acllen) |
| 3214 | { |
| 3215 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3216 | int rc = 0; |
| 3217 | int bytes_returned = 0; |
| 3218 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3219 | NTRANSACT_RSP *pSMBr = NULL; |
| 3220 | |
| 3221 | setCifsAclRetry: |
| 3222 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3223 | (void **) &pSMBr); |
| 3224 | if (rc) |
| 3225 | return (rc); |
| 3226 | |
| 3227 | pSMB->MaxSetupCount = 0; |
| 3228 | pSMB->Reserved = 0; |
| 3229 | |
| 3230 | param_count = 8; |
| 3231 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3232 | data_count = acllen; |
| 3233 | data_offset = param_offset + param_count; |
| 3234 | byte_count = 3 /* pad */ + param_count; |
| 3235 | |
| 3236 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3237 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3238 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3239 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3240 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3241 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3242 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3243 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3244 | pSMB->SetupCount = 0; |
| 3245 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3246 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3247 | |
| 3248 | pSMB->Fid = fid; /* file handle always le */ |
| 3249 | pSMB->Reserved2 = 0; |
| 3250 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL); |
| 3251 | |
| 3252 | if (pntsd && acllen) { |
| 3253 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3254 | (char *) pntsd, |
| 3255 | acllen); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3256 | inc_rfc1001_len(pSMB, byte_count + data_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3257 | } else |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3258 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3259 | |
| 3260 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3261 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3262 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3263 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3264 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3265 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3266 | cifs_buf_release(pSMB); |
| 3267 | |
| 3268 | if (rc == -EAGAIN) |
| 3269 | goto setCifsAclRetry; |
| 3270 | |
| 3271 | return (rc); |
| 3272 | } |
| 3273 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3274 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3275 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3276 | /* Legacy Query Path Information call for lookup to old servers such |
| 3277 | as Win9x/WinME */ |
| 3278 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3279 | const unsigned char *searchName, |
| 3280 | FILE_ALL_INFO *pFinfo, |
| 3281 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3282 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3283 | QUERY_INFORMATION_REQ *pSMB; |
| 3284 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3285 | int rc = 0; |
| 3286 | int bytes_returned; |
| 3287 | int name_len; |
| 3288 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3289 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3290 | QInfRetry: |
| 3291 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3292 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3293 | if (rc) |
| 3294 | return rc; |
| 3295 | |
| 3296 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3297 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3298 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
| 3299 | PATH_MAX, nls_codepage, remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3300 | name_len++; /* trailing null */ |
| 3301 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3302 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3303 | name_len = strnlen(searchName, PATH_MAX); |
| 3304 | name_len++; /* trailing null */ |
| 3305 | strncpy(pSMB->FileName, searchName, name_len); |
| 3306 | } |
| 3307 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3308 | name_len++; /* account for buffer type byte */ |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3309 | inc_rfc1001_len(pSMB, (__u16)name_len); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3310 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3311 | |
| 3312 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3313 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3314 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3315 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3316 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3317 | struct timespec ts; |
| 3318 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3319 | |
| 3320 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3321 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3322 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3323 | ts.tv_nsec = 0; |
| 3324 | ts.tv_sec = time; |
| 3325 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3326 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3327 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3328 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3329 | pFinfo->AllocationSize = |
| 3330 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3331 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3332 | pFinfo->Attributes = |
| 3333 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3334 | } else |
| 3335 | rc = -EIO; /* bad buffer passed in */ |
| 3336 | |
| 3337 | cifs_buf_release(pSMB); |
| 3338 | |
| 3339 | if (rc == -EAGAIN) |
| 3340 | goto QInfRetry; |
| 3341 | |
| 3342 | return rc; |
| 3343 | } |
| 3344 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3345 | int |
| 3346 | CIFSSMBQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3347 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3348 | { |
| 3349 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3350 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3351 | int rc = 0; |
| 3352 | int bytes_returned; |
| 3353 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3354 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3355 | QFileInfoRetry: |
| 3356 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3357 | (void **) &pSMBr); |
| 3358 | if (rc) |
| 3359 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3360 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3361 | params = 2 /* level */ + 2 /* fid */; |
| 3362 | pSMB->t2.TotalDataCount = 0; |
| 3363 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3364 | /* BB find exact max data count below from sess structure BB */ |
| 3365 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3366 | pSMB->t2.MaxSetupCount = 0; |
| 3367 | pSMB->t2.Reserved = 0; |
| 3368 | pSMB->t2.Flags = 0; |
| 3369 | pSMB->t2.Timeout = 0; |
| 3370 | pSMB->t2.Reserved2 = 0; |
| 3371 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3372 | Fid) - 4); |
| 3373 | pSMB->t2.DataCount = 0; |
| 3374 | pSMB->t2.DataOffset = 0; |
| 3375 | pSMB->t2.SetupCount = 1; |
| 3376 | pSMB->t2.Reserved3 = 0; |
| 3377 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3378 | byte_count = params + 1 /* pad */ ; |
| 3379 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3380 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3381 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3382 | pSMB->Pad = 0; |
| 3383 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3384 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3385 | |
| 3386 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3387 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3388 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3389 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3390 | } else { /* decode response */ |
| 3391 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3392 | |
| 3393 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3394 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3395 | else if (get_bcc(&pSMBr->hdr) < 40) |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3396 | rc = -EIO; /* bad smb */ |
| 3397 | else if (pFindData) { |
| 3398 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3399 | memcpy((char *) pFindData, |
| 3400 | (char *) &pSMBr->hdr.Protocol + |
| 3401 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3402 | } else |
| 3403 | rc = -ENOMEM; |
| 3404 | } |
| 3405 | cifs_buf_release(pSMB); |
| 3406 | if (rc == -EAGAIN) |
| 3407 | goto QFileInfoRetry; |
| 3408 | |
| 3409 | return rc; |
| 3410 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3411 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | int |
| 3413 | CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3414 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3415 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3416 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3417 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | { |
| 3419 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3420 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3421 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3422 | int rc = 0; |
| 3423 | int bytes_returned; |
| 3424 | int name_len; |
| 3425 | __u16 params, byte_count; |
| 3426 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3427 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | QPathInfoRetry: |
| 3429 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3430 | (void **) &pSMBr); |
| 3431 | if (rc) |
| 3432 | return rc; |
| 3433 | |
| 3434 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3435 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3436 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3437 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3438 | name_len++; /* trailing null */ |
| 3439 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3440 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | name_len = strnlen(searchName, PATH_MAX); |
| 3442 | name_len++; /* trailing null */ |
| 3443 | strncpy(pSMB->FileName, searchName, name_len); |
| 3444 | } |
| 3445 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3446 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | pSMB->TotalDataCount = 0; |
| 3448 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3449 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3450 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3451 | pSMB->MaxSetupCount = 0; |
| 3452 | pSMB->Reserved = 0; |
| 3453 | pSMB->Flags = 0; |
| 3454 | pSMB->Timeout = 0; |
| 3455 | pSMB->Reserved2 = 0; |
| 3456 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3457 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | pSMB->DataCount = 0; |
| 3459 | pSMB->DataOffset = 0; |
| 3460 | pSMB->SetupCount = 1; |
| 3461 | pSMB->Reserved3 = 0; |
| 3462 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3463 | byte_count = params + 1 /* pad */ ; |
| 3464 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3465 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3466 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3467 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 3468 | else |
| 3469 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3470 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3471 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3473 | |
| 3474 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3475 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3476 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3477 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | } else { /* decode response */ |
| 3479 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3480 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3481 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3482 | rc = -EIO; |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3483 | else if (!legacy && get_bcc(&pSMBr->hdr) < 40) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | rc = -EIO; /* bad smb */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3485 | else if (legacy && get_bcc(&pSMBr->hdr) < 24) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3486 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 3487 | last field */ |
| 3488 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3489 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3491 | |
| 3492 | /* On legacy responses we do not read the last field, |
| 3493 | EAsize, fortunately since it varies by subdialect and |
| 3494 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 3495 | bytes depending but we don't care here */ |
| 3496 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3497 | size = sizeof(FILE_INFO_STANDARD); |
| 3498 | else |
| 3499 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | memcpy((char *) pFindData, |
| 3501 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3502 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | } else |
| 3504 | rc = -ENOMEM; |
| 3505 | } |
| 3506 | cifs_buf_release(pSMB); |
| 3507 | if (rc == -EAGAIN) |
| 3508 | goto QPathInfoRetry; |
| 3509 | |
| 3510 | return rc; |
| 3511 | } |
| 3512 | |
| 3513 | int |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3514 | CIFSSMBUnixQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3515 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 3516 | { |
| 3517 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3518 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3519 | int rc = 0; |
| 3520 | int bytes_returned; |
| 3521 | __u16 params, byte_count; |
| 3522 | |
| 3523 | UnixQFileInfoRetry: |
| 3524 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3525 | (void **) &pSMBr); |
| 3526 | if (rc) |
| 3527 | return rc; |
| 3528 | |
| 3529 | params = 2 /* level */ + 2 /* fid */; |
| 3530 | pSMB->t2.TotalDataCount = 0; |
| 3531 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3532 | /* BB find exact max data count below from sess structure BB */ |
| 3533 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3534 | pSMB->t2.MaxSetupCount = 0; |
| 3535 | pSMB->t2.Reserved = 0; |
| 3536 | pSMB->t2.Flags = 0; |
| 3537 | pSMB->t2.Timeout = 0; |
| 3538 | pSMB->t2.Reserved2 = 0; |
| 3539 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3540 | Fid) - 4); |
| 3541 | pSMB->t2.DataCount = 0; |
| 3542 | pSMB->t2.DataOffset = 0; |
| 3543 | pSMB->t2.SetupCount = 1; |
| 3544 | pSMB->t2.Reserved3 = 0; |
| 3545 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3546 | byte_count = params + 1 /* pad */ ; |
| 3547 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3548 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3549 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3550 | pSMB->Pad = 0; |
| 3551 | pSMB->Fid = netfid; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3552 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3553 | |
| 3554 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3555 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3556 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3557 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3558 | } else { /* decode response */ |
| 3559 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3560 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3561 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3562 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3563 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3564 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3565 | rc = -EIO; /* bad smb */ |
| 3566 | } else { |
| 3567 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3568 | memcpy((char *) pFindData, |
| 3569 | (char *) &pSMBr->hdr.Protocol + |
| 3570 | data_offset, |
| 3571 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | cifs_buf_release(pSMB); |
| 3576 | if (rc == -EAGAIN) |
| 3577 | goto UnixQFileInfoRetry; |
| 3578 | |
| 3579 | return rc; |
| 3580 | } |
| 3581 | |
| 3582 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3583 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3584 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3585 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3586 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3587 | { |
| 3588 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 3589 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3590 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3591 | int rc = 0; |
| 3592 | int bytes_returned = 0; |
| 3593 | int name_len; |
| 3594 | __u16 params, byte_count; |
| 3595 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3596 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | UnixQPathInfoRetry: |
| 3598 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3599 | (void **) &pSMBr); |
| 3600 | if (rc) |
| 3601 | return rc; |
| 3602 | |
| 3603 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3604 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3605 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3606 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3607 | name_len++; /* trailing null */ |
| 3608 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3609 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | name_len = strnlen(searchName, PATH_MAX); |
| 3611 | name_len++; /* trailing null */ |
| 3612 | strncpy(pSMB->FileName, searchName, name_len); |
| 3613 | } |
| 3614 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3615 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | pSMB->TotalDataCount = 0; |
| 3617 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3618 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3619 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | pSMB->MaxSetupCount = 0; |
| 3621 | pSMB->Reserved = 0; |
| 3622 | pSMB->Flags = 0; |
| 3623 | pSMB->Timeout = 0; |
| 3624 | pSMB->Reserved2 = 0; |
| 3625 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3626 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | pSMB->DataCount = 0; |
| 3628 | pSMB->DataOffset = 0; |
| 3629 | pSMB->SetupCount = 1; |
| 3630 | pSMB->Reserved3 = 0; |
| 3631 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3632 | byte_count = params + 1 /* pad */ ; |
| 3633 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3634 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3635 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3636 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3637 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3639 | |
| 3640 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3641 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3642 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3643 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3644 | } else { /* decode response */ |
| 3645 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3646 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 3647 | if (rc || get_bcc(&pSMBr->hdr) < sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3648 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 3649 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3650 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | rc = -EIO; /* bad smb */ |
| 3652 | } else { |
| 3653 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3654 | memcpy((char *) pFindData, |
| 3655 | (char *) &pSMBr->hdr.Protocol + |
| 3656 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3657 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | cifs_buf_release(pSMB); |
| 3661 | if (rc == -EAGAIN) |
| 3662 | goto UnixQPathInfoRetry; |
| 3663 | |
| 3664 | return rc; |
| 3665 | } |
| 3666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 3668 | int |
| 3669 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3670 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3672 | __u16 *pnetfid, |
| 3673 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | { |
| 3675 | /* level 257 SMB_ */ |
| 3676 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 3677 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3678 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3679 | int rc = 0; |
| 3680 | int bytes_returned = 0; |
| 3681 | int name_len; |
| 3682 | __u16 params, byte_count; |
| 3683 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3684 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3685 | |
| 3686 | findFirstRetry: |
| 3687 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3688 | (void **) &pSMBr); |
| 3689 | if (rc) |
| 3690 | return rc; |
| 3691 | |
| 3692 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3693 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3694 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3695 | PATH_MAX, nls_codepage, remap); |
| 3696 | /* We can not add the asterik earlier in case |
| 3697 | it got remapped to 0xF03A as if it were part of the |
| 3698 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3700 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3701 | pSMB->FileName[name_len+1] = 0; |
| 3702 | pSMB->FileName[name_len+2] = '*'; |
| 3703 | pSMB->FileName[name_len+3] = 0; |
| 3704 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 3706 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3707 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } else { /* BB add check for overrun of SMB buf BB */ |
| 3709 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3711 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3712 | free buffer exit; BB */ |
| 3713 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3714 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 3715 | pSMB->FileName[name_len+1] = '*'; |
| 3716 | pSMB->FileName[name_len+2] = 0; |
| 3717 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3718 | } |
| 3719 | |
| 3720 | params = 12 + name_len /* includes null */ ; |
| 3721 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3722 | pSMB->MaxParameterCount = cpu_to_le16(10); |
| 3723 | pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - |
| 3724 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3725 | pSMB->MaxSetupCount = 0; |
| 3726 | pSMB->Reserved = 0; |
| 3727 | pSMB->Flags = 0; |
| 3728 | pSMB->Timeout = 0; |
| 3729 | pSMB->Reserved2 = 0; |
| 3730 | byte_count = params + 1 /* pad */ ; |
| 3731 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3732 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3733 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3734 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 3735 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | pSMB->DataCount = 0; |
| 3737 | pSMB->DataOffset = 0; |
| 3738 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 3739 | pSMB->Reserved3 = 0; |
| 3740 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 3741 | pSMB->SearchAttributes = |
| 3742 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3743 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3744 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 3745 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | CIFS_SEARCH_RETURN_RESUME); |
| 3747 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3748 | |
| 3749 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 3750 | pSMB->SearchStorageType = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3751 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3752 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3753 | |
| 3754 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3755 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3756 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3758 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 3759 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3761 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 3762 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3763 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | |
| 3765 | /* BB eventually could optimize out free and realloc of buf */ |
| 3766 | /* for this case */ |
| 3767 | if (rc == -EAGAIN) |
| 3768 | goto findFirstRetry; |
| 3769 | } else { /* decode response */ |
| 3770 | /* BB remember to free buffer if error BB */ |
| 3771 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3772 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3773 | unsigned int lnoff; |
| 3774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3776 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3778 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | |
| 3780 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3781 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3782 | psrch_inf->srch_entries_start = |
| 3783 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 3786 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 3787 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3788 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3789 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3790 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3791 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3793 | psrch_inf->entries_in_buffer = |
| 3794 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 3795 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3796 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3797 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3798 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3799 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3800 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3801 | psrch_inf->last_entry = NULL; |
| 3802 | return rc; |
| 3803 | } |
| 3804 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 3805 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3806 | lnoff; |
| 3807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | *pnetfid = parms->SearchHandle; |
| 3809 | } else { |
| 3810 | cifs_buf_release(pSMB); |
| 3811 | } |
| 3812 | } |
| 3813 | |
| 3814 | return rc; |
| 3815 | } |
| 3816 | |
| 3817 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3818 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | { |
| 3820 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 3821 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3822 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | char *response_data; |
| 3824 | int rc = 0; |
| 3825 | int bytes_returned, name_len; |
| 3826 | __u16 params, byte_count; |
| 3827 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3828 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3830 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | return -ENOENT; |
| 3832 | |
| 3833 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3834 | (void **) &pSMBr); |
| 3835 | if (rc) |
| 3836 | return rc; |
| 3837 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3838 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | byte_count = 0; |
| 3840 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3841 | pSMB->MaxParameterCount = cpu_to_le16(8); |
| 3842 | pSMB->MaxDataCount = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3843 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
| 3844 | 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | pSMB->MaxSetupCount = 0; |
| 3846 | pSMB->Reserved = 0; |
| 3847 | pSMB->Flags = 0; |
| 3848 | pSMB->Timeout = 0; |
| 3849 | pSMB->Reserved2 = 0; |
| 3850 | pSMB->ParameterOffset = cpu_to_le16( |
| 3851 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 3852 | pSMB->DataCount = 0; |
| 3853 | pSMB->DataOffset = 0; |
| 3854 | pSMB->SetupCount = 1; |
| 3855 | pSMB->Reserved3 = 0; |
| 3856 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 3857 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 3858 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3859 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3860 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3861 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 3862 | pSMB->SearchFlags = |
| 3863 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 3864 | |
| 3865 | name_len = psrch_inf->resume_name_len; |
| 3866 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3867 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3868 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 3869 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 3870 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 3871 | pSMB->ResumeFileName[name_len] = 0; |
| 3872 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3873 | } else { |
| 3874 | rc = -EINVAL; |
| 3875 | goto FNext2_err_exit; |
| 3876 | } |
| 3877 | byte_count = params + 1 /* pad */ ; |
| 3878 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3879 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 3880 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3882 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3883 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3884 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3885 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | if (rc) { |
| 3887 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3888 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 3889 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3890 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3892 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | } else { /* decode response */ |
| 3894 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3895 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3896 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3897 | unsigned int lnoff; |
| 3898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3899 | /* BB fixme add lock for file (srch_info) struct here */ |
| 3900 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3901 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3903 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3904 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 3905 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 3906 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 3907 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 3908 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3909 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3910 | cifs_small_buf_release( |
| 3911 | psrch_inf->ntwrk_buf_start); |
| 3912 | else |
| 3913 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3914 | psrch_inf->srch_entries_start = response_data; |
| 3915 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3916 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3917 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3918 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3919 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3920 | psrch_inf->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3921 | psrch_inf->entries_in_buffer = |
| 3922 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3923 | psrch_inf->index_of_last_entry += |
| 3924 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3925 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3926 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3927 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3928 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3929 | psrch_inf->last_entry = NULL; |
| 3930 | return rc; |
| 3931 | } else |
| 3932 | psrch_inf->last_entry = |
| 3933 | psrch_inf->srch_entries_start + lnoff; |
| 3934 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3935 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 3936 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | |
| 3938 | /* BB fixme add unlock here */ |
| 3939 | } |
| 3940 | |
| 3941 | } |
| 3942 | |
| 3943 | /* BB On error, should we leave previous search buf (and count and |
| 3944 | last entry fields) intact or free the previous one? */ |
| 3945 | |
| 3946 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3947 | since file handle passed in no longer valid */ |
| 3948 | FNext2_err_exit: |
| 3949 | if (rc != 0) |
| 3950 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3951 | return rc; |
| 3952 | } |
| 3953 | |
| 3954 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3955 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
| 3956 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | { |
| 3958 | int rc = 0; |
| 3959 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3961 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 3963 | |
| 3964 | /* no sense returning error if session restarted |
| 3965 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3966 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3967 | return 0; |
| 3968 | if (rc) |
| 3969 | return rc; |
| 3970 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | pSMB->FileID = searchHandle; |
| 3972 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3973 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3974 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3975 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3976 | |
Steve French | a454434 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3977 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3978 | |
| 3979 | /* Since session is dead, search handle closed on server already */ |
| 3980 | if (rc == -EAGAIN) |
| 3981 | rc = 0; |
| 3982 | |
| 3983 | return rc; |
| 3984 | } |
| 3985 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3986 | int |
| 3987 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3988 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3989 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3990 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | { |
| 3992 | int rc = 0; |
| 3993 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3994 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3995 | int name_len, bytes_returned; |
| 3996 | __u16 params, byte_count; |
| 3997 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3998 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3999 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4000 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | |
| 4002 | GetInodeNumberRetry: |
| 4003 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4004 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | if (rc) |
| 4006 | return rc; |
| 4007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4009 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4010 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4011 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | name_len++; /* trailing null */ |
| 4013 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4014 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | name_len = strnlen(searchName, PATH_MAX); |
| 4016 | name_len++; /* trailing null */ |
| 4017 | strncpy(pSMB->FileName, searchName, name_len); |
| 4018 | } |
| 4019 | |
| 4020 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4021 | pSMB->TotalDataCount = 0; |
| 4022 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4023 | /* BB find exact max data count below from sess structure BB */ |
| 4024 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4025 | pSMB->MaxSetupCount = 0; |
| 4026 | pSMB->Reserved = 0; |
| 4027 | pSMB->Flags = 0; |
| 4028 | pSMB->Timeout = 0; |
| 4029 | pSMB->Reserved2 = 0; |
| 4030 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4031 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | pSMB->DataCount = 0; |
| 4033 | pSMB->DataOffset = 0; |
| 4034 | pSMB->SetupCount = 1; |
| 4035 | pSMB->Reserved3 = 0; |
| 4036 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4037 | byte_count = params + 1 /* pad */ ; |
| 4038 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4039 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4040 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4041 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4042 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4044 | |
| 4045 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4046 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4047 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4048 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | } else { |
| 4050 | /* decode response */ |
| 4051 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | /* BB also check enough total bytes returned */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4053 | if (rc || get_bcc(&pSMBr->hdr) < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | /* If rc should we check for EOPNOSUPP and |
| 4055 | disable the srvino flag? or in caller? */ |
| 4056 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4057 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4058 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4059 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4060 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4062 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4063 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | rc = -EIO; |
| 4065 | goto GetInodeNumOut; |
| 4066 | } |
| 4067 | pfinfo = (struct file_internal_info *) |
| 4068 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4069 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4070 | } |
| 4071 | } |
| 4072 | GetInodeNumOut: |
| 4073 | cifs_buf_release(pSMB); |
| 4074 | if (rc == -EAGAIN) |
| 4075 | goto GetInodeNumberRetry; |
| 4076 | return rc; |
| 4077 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4079 | /* parses DFS refferal V3 structure |
| 4080 | * caller is responsible for freeing target_nodes |
| 4081 | * returns: |
| 4082 | * on success - 0 |
| 4083 | * on failure - errno |
| 4084 | */ |
| 4085 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4086 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4087 | unsigned int *num_of_nodes, |
| 4088 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4089 | const struct nls_table *nls_codepage, int remap, |
| 4090 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4091 | { |
| 4092 | int i, rc = 0; |
| 4093 | char *data_end; |
| 4094 | bool is_unicode; |
| 4095 | struct dfs_referral_level_3 *ref; |
| 4096 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4097 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4098 | is_unicode = true; |
| 4099 | else |
| 4100 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4101 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4102 | |
| 4103 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4104 | cERROR(1, "num_referrals: must be at least > 0," |
| 4105 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4106 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4107 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4111 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4112 | cERROR(1, "Referrals of V%d version are not supported," |
| 4113 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4114 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4115 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | /* get the upper boundary of the resp buffer */ |
| 4119 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4120 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4121 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4122 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4123 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4124 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4125 | |
| 4126 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4127 | *num_of_nodes, GFP_KERNEL); |
| 4128 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4129 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4130 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4131 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4132 | } |
| 4133 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4134 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4135 | for (i = 0; i < *num_of_nodes; i++) { |
| 4136 | char *temp; |
| 4137 | int max_len; |
| 4138 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4139 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4140 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4141 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4142 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4143 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4144 | if (tmp == NULL) { |
| 4145 | rc = -ENOMEM; |
| 4146 | goto parse_DFS_referrals_exit; |
| 4147 | } |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4148 | cifsConvertToUCS((__le16 *) tmp, searchName, |
| 4149 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4150 | node->path_consumed = cifs_ucs2_bytes(tmp, |
| 4151 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4152 | nls_codepage); |
| 4153 | kfree(tmp); |
| 4154 | } else |
| 4155 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4156 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4157 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4158 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4159 | |
| 4160 | /* copy DfsPath */ |
| 4161 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4162 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4163 | node->path_name = cifs_strndup_from_ucs(temp, max_len, |
| 4164 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4165 | if (!node->path_name) { |
| 4166 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4167 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4168 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4169 | |
| 4170 | /* copy link target UNC */ |
| 4171 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4172 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4173 | node->node_name = cifs_strndup_from_ucs(temp, max_len, |
| 4174 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4175 | if (!node->node_name) |
| 4176 | rc = -ENOMEM; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4177 | } |
| 4178 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4179 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4180 | if (rc) { |
| 4181 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4182 | *target_nodes = NULL; |
| 4183 | *num_of_nodes = 0; |
| 4184 | } |
| 4185 | return rc; |
| 4186 | } |
| 4187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | int |
| 4189 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
| 4190 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4191 | struct dfs_info3_param **target_nodes, |
| 4192 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4193 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | { |
| 4195 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4196 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4197 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | int rc = 0; |
| 4199 | int bytes_returned; |
| 4200 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4202 | *num_of_nodes = 0; |
| 4203 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4205 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | if (ses == NULL) |
| 4207 | return -ENODEV; |
| 4208 | getDFSRetry: |
| 4209 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4210 | (void **) &pSMBr); |
| 4211 | if (rc) |
| 4212 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4213 | |
| 4214 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4215 | but should never be null here anyway */ |
| 4216 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4218 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4219 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4220 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4221 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | |
| 4224 | if (ses->capabilities & CAP_UNICODE) { |
| 4225 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4226 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4227 | cifsConvertToUCS((__le16 *) pSMB->RequestFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4228 | searchName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | name_len++; /* trailing null */ |
| 4230 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4231 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4232 | name_len = strnlen(searchName, PATH_MAX); |
| 4233 | name_len++; /* trailing null */ |
| 4234 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4235 | } |
| 4236 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4237 | if (ses->server) { |
| 4238 | if (ses->server->secMode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4239 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4240 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4241 | } |
| 4242 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4243 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4246 | pSMB->TotalDataCount = 0; |
| 4247 | pSMB->DataCount = 0; |
| 4248 | pSMB->DataOffset = 0; |
| 4249 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4250 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4251 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4252 | pSMB->MaxSetupCount = 0; |
| 4253 | pSMB->Reserved = 0; |
| 4254 | pSMB->Flags = 0; |
| 4255 | pSMB->Timeout = 0; |
| 4256 | pSMB->Reserved2 = 0; |
| 4257 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4258 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | pSMB->SetupCount = 1; |
| 4260 | pSMB->Reserved3 = 0; |
| 4261 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4262 | byte_count = params + 3 /* pad */ ; |
| 4263 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4264 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4265 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4266 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4268 | |
| 4269 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4270 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4271 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4272 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4273 | goto GetDFSRefExit; |
| 4274 | } |
| 4275 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4277 | /* BB Also check if enough total bytes returned? */ |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4278 | if (rc || get_bcc(&pSMBr->hdr) < 17) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4279 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4280 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4281 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4282 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4283 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4284 | get_bcc(&pSMBr->hdr), |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4285 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4286 | |
| 4287 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4288 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4289 | target_nodes, nls_codepage, remap, |
| 4290 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4292 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4293 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | |
| 4295 | if (rc == -EAGAIN) |
| 4296 | goto getDFSRetry; |
| 4297 | |
| 4298 | return rc; |
| 4299 | } |
| 4300 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4301 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4302 | int |
| 4303 | SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
| 4304 | { |
| 4305 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4306 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4307 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4308 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4309 | int rc = 0; |
| 4310 | int bytes_returned = 0; |
| 4311 | __u16 params, byte_count; |
| 4312 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4313 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4314 | oldQFSInfoRetry: |
| 4315 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4316 | (void **) &pSMBr); |
| 4317 | if (rc) |
| 4318 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4319 | |
| 4320 | params = 2; /* level */ |
| 4321 | pSMB->TotalDataCount = 0; |
| 4322 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4323 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4324 | pSMB->MaxSetupCount = 0; |
| 4325 | pSMB->Reserved = 0; |
| 4326 | pSMB->Flags = 0; |
| 4327 | pSMB->Timeout = 0; |
| 4328 | pSMB->Reserved2 = 0; |
| 4329 | byte_count = params + 1 /* pad */ ; |
| 4330 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4331 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4332 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4333 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4334 | pSMB->DataCount = 0; |
| 4335 | pSMB->DataOffset = 0; |
| 4336 | pSMB->SetupCount = 1; |
| 4337 | pSMB->Reserved3 = 0; |
| 4338 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4339 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4340 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4341 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4342 | |
| 4343 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4344 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4345 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4346 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4347 | } else { /* decode response */ |
| 4348 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4349 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4350 | if (rc || get_bcc(&pSMBr->hdr) < 18) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4351 | rc = -EIO; /* bad smb */ |
| 4352 | else { |
| 4353 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4354 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4355 | get_bcc(&pSMBr->hdr), data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4356 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4357 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4358 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4359 | FSData->f_bsize = |
| 4360 | le16_to_cpu(response_data->BytesPerSector) * |
| 4361 | le32_to_cpu(response_data-> |
| 4362 | SectorsPerAllocationUnit); |
| 4363 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4364 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4365 | FSData->f_bfree = FSData->f_bavail = |
| 4366 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4367 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4368 | (unsigned long long)FSData->f_blocks, |
| 4369 | (unsigned long long)FSData->f_bfree, |
| 4370 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | cifs_buf_release(pSMB); |
| 4374 | |
| 4375 | if (rc == -EAGAIN) |
| 4376 | goto oldQFSInfoRetry; |
| 4377 | |
| 4378 | return rc; |
| 4379 | } |
| 4380 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4382 | CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4383 | { |
| 4384 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4385 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4386 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4387 | FILE_SYSTEM_INFO *response_data; |
| 4388 | int rc = 0; |
| 4389 | int bytes_returned = 0; |
| 4390 | __u16 params, byte_count; |
| 4391 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4392 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4393 | QFSInfoRetry: |
| 4394 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4395 | (void **) &pSMBr); |
| 4396 | if (rc) |
| 4397 | return rc; |
| 4398 | |
| 4399 | params = 2; /* level */ |
| 4400 | pSMB->TotalDataCount = 0; |
| 4401 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4402 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | pSMB->MaxSetupCount = 0; |
| 4404 | pSMB->Reserved = 0; |
| 4405 | pSMB->Flags = 0; |
| 4406 | pSMB->Timeout = 0; |
| 4407 | pSMB->Reserved2 = 0; |
| 4408 | byte_count = params + 1 /* pad */ ; |
| 4409 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4410 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4411 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4412 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | pSMB->DataCount = 0; |
| 4414 | pSMB->DataOffset = 0; |
| 4415 | pSMB->SetupCount = 1; |
| 4416 | pSMB->Reserved3 = 0; |
| 4417 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4418 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4419 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4420 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4421 | |
| 4422 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4423 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4424 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4425 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4426 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4427 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4428 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4429 | if (rc || get_bcc(&pSMBr->hdr) < 24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | rc = -EIO; /* bad smb */ |
| 4431 | else { |
| 4432 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | |
| 4434 | response_data = |
| 4435 | (FILE_SYSTEM_INFO |
| 4436 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4437 | data_offset); |
| 4438 | FSData->f_bsize = |
| 4439 | le32_to_cpu(response_data->BytesPerSector) * |
| 4440 | le32_to_cpu(response_data-> |
| 4441 | SectorsPerAllocationUnit); |
| 4442 | FSData->f_blocks = |
| 4443 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4444 | FSData->f_bfree = FSData->f_bavail = |
| 4445 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4446 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4447 | (unsigned long long)FSData->f_blocks, |
| 4448 | (unsigned long long)FSData->f_bfree, |
| 4449 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | cifs_buf_release(pSMB); |
| 4453 | |
| 4454 | if (rc == -EAGAIN) |
| 4455 | goto QFSInfoRetry; |
| 4456 | |
| 4457 | return rc; |
| 4458 | } |
| 4459 | |
| 4460 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4461 | CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | { |
| 4463 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4464 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4465 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4466 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 4467 | int rc = 0; |
| 4468 | int bytes_returned = 0; |
| 4469 | __u16 params, byte_count; |
| 4470 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4471 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4472 | QFSAttributeRetry: |
| 4473 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4474 | (void **) &pSMBr); |
| 4475 | if (rc) |
| 4476 | return rc; |
| 4477 | |
| 4478 | params = 2; /* level */ |
| 4479 | pSMB->TotalDataCount = 0; |
| 4480 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4481 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4482 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4483 | pSMB->MaxSetupCount = 0; |
| 4484 | pSMB->Reserved = 0; |
| 4485 | pSMB->Flags = 0; |
| 4486 | pSMB->Timeout = 0; |
| 4487 | pSMB->Reserved2 = 0; |
| 4488 | byte_count = params + 1 /* pad */ ; |
| 4489 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4490 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4491 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4492 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4493 | pSMB->DataCount = 0; |
| 4494 | pSMB->DataOffset = 0; |
| 4495 | pSMB->SetupCount = 1; |
| 4496 | pSMB->Reserved3 = 0; |
| 4497 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4498 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4499 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4500 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4501 | |
| 4502 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4503 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4504 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4505 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | } else { /* decode response */ |
| 4507 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4508 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4509 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4510 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4511 | rc = -EIO; /* bad smb */ |
| 4512 | } else { |
| 4513 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4514 | response_data = |
| 4515 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 4516 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4517 | data_offset); |
| 4518 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4519 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4520 | } |
| 4521 | } |
| 4522 | cifs_buf_release(pSMB); |
| 4523 | |
| 4524 | if (rc == -EAGAIN) |
| 4525 | goto QFSAttributeRetry; |
| 4526 | |
| 4527 | return rc; |
| 4528 | } |
| 4529 | |
| 4530 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4531 | CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | { |
| 4533 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4534 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4535 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4536 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 4537 | int rc = 0; |
| 4538 | int bytes_returned = 0; |
| 4539 | __u16 params, byte_count; |
| 4540 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4541 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | QFSDeviceRetry: |
| 4543 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4544 | (void **) &pSMBr); |
| 4545 | if (rc) |
| 4546 | return rc; |
| 4547 | |
| 4548 | params = 2; /* level */ |
| 4549 | pSMB->TotalDataCount = 0; |
| 4550 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4551 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4552 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4553 | pSMB->MaxSetupCount = 0; |
| 4554 | pSMB->Reserved = 0; |
| 4555 | pSMB->Flags = 0; |
| 4556 | pSMB->Timeout = 0; |
| 4557 | pSMB->Reserved2 = 0; |
| 4558 | byte_count = params + 1 /* pad */ ; |
| 4559 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4560 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4561 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4562 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4563 | |
| 4564 | pSMB->DataCount = 0; |
| 4565 | pSMB->DataOffset = 0; |
| 4566 | pSMB->SetupCount = 1; |
| 4567 | pSMB->Reserved3 = 0; |
| 4568 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4569 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4570 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4572 | |
| 4573 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4574 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4575 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4576 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4577 | } else { /* decode response */ |
| 4578 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4579 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4580 | if (rc || get_bcc(&pSMBr->hdr) < |
| 4581 | sizeof(FILE_SYSTEM_DEVICE_INFO)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4582 | rc = -EIO; /* bad smb */ |
| 4583 | else { |
| 4584 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4585 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4586 | (FILE_SYSTEM_DEVICE_INFO *) |
| 4587 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4588 | data_offset); |
| 4589 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4590 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | } |
| 4592 | } |
| 4593 | cifs_buf_release(pSMB); |
| 4594 | |
| 4595 | if (rc == -EAGAIN) |
| 4596 | goto QFSDeviceRetry; |
| 4597 | |
| 4598 | return rc; |
| 4599 | } |
| 4600 | |
| 4601 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4602 | CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | { |
| 4604 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 4605 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4606 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4607 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 4608 | int rc = 0; |
| 4609 | int bytes_returned = 0; |
| 4610 | __u16 params, byte_count; |
| 4611 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4612 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4613 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4614 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4615 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4616 | if (rc) |
| 4617 | return rc; |
| 4618 | |
| 4619 | params = 2; /* level */ |
| 4620 | pSMB->TotalDataCount = 0; |
| 4621 | pSMB->DataCount = 0; |
| 4622 | pSMB->DataOffset = 0; |
| 4623 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4624 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4625 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4626 | pSMB->MaxSetupCount = 0; |
| 4627 | pSMB->Reserved = 0; |
| 4628 | pSMB->Flags = 0; |
| 4629 | pSMB->Timeout = 0; |
| 4630 | pSMB->Reserved2 = 0; |
| 4631 | byte_count = params + 1 /* pad */ ; |
| 4632 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4633 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4634 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4635 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | pSMB->SetupCount = 1; |
| 4637 | pSMB->Reserved3 = 0; |
| 4638 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4639 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4640 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4642 | |
| 4643 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4644 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4645 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4646 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | } else { /* decode response */ |
| 4648 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4649 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4650 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4651 | rc = -EIO; /* bad smb */ |
| 4652 | } else { |
| 4653 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4654 | response_data = |
| 4655 | (FILE_SYSTEM_UNIX_INFO |
| 4656 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4657 | data_offset); |
| 4658 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4659 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | } |
| 4661 | } |
| 4662 | cifs_buf_release(pSMB); |
| 4663 | |
| 4664 | if (rc == -EAGAIN) |
| 4665 | goto QFSUnixRetry; |
| 4666 | |
| 4667 | |
| 4668 | return rc; |
| 4669 | } |
| 4670 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4671 | int |
Steve French | 45abc6e | 2005-06-23 13:42:03 -0500 | [diff] [blame] | 4672 | CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4673 | { |
| 4674 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 4675 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 4676 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 4677 | int rc = 0; |
| 4678 | int bytes_returned = 0; |
| 4679 | __u16 params, param_offset, offset, byte_count; |
| 4680 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4681 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4682 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 4683 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4684 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4685 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4686 | if (rc) |
| 4687 | return rc; |
| 4688 | |
| 4689 | params = 4; /* 2 bytes zero followed by info level. */ |
| 4690 | pSMB->MaxSetupCount = 0; |
| 4691 | pSMB->Reserved = 0; |
| 4692 | pSMB->Flags = 0; |
| 4693 | pSMB->Timeout = 0; |
| 4694 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4695 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 4696 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4697 | offset = param_offset + params; |
| 4698 | |
| 4699 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4700 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4701 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4702 | pSMB->SetupCount = 1; |
| 4703 | pSMB->Reserved3 = 0; |
| 4704 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 4705 | byte_count = 1 /* pad */ + params + 12; |
| 4706 | |
| 4707 | pSMB->DataCount = cpu_to_le16(12); |
| 4708 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4709 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4710 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4711 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4712 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4713 | |
| 4714 | /* Params. */ |
| 4715 | pSMB->FileNum = 0; |
| 4716 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 4717 | |
| 4718 | /* Data. */ |
| 4719 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 4720 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 4721 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 4722 | |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4723 | inc_rfc1001_len(pSMB, byte_count); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4724 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4725 | |
| 4726 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4727 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4728 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4729 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4730 | } else { /* decode response */ |
| 4731 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4732 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4733 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4734 | } |
| 4735 | cifs_buf_release(pSMB); |
| 4736 | |
| 4737 | if (rc == -EAGAIN) |
| 4738 | goto SETFSUnixRetry; |
| 4739 | |
| 4740 | return rc; |
| 4741 | } |
| 4742 | |
| 4743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4744 | |
| 4745 | int |
| 4746 | CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4747 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4748 | { |
| 4749 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 4750 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4751 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4752 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 4753 | int rc = 0; |
| 4754 | int bytes_returned = 0; |
| 4755 | __u16 params, byte_count; |
| 4756 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4757 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | QFSPosixRetry: |
| 4759 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4760 | (void **) &pSMBr); |
| 4761 | if (rc) |
| 4762 | return rc; |
| 4763 | |
| 4764 | params = 2; /* level */ |
| 4765 | pSMB->TotalDataCount = 0; |
| 4766 | pSMB->DataCount = 0; |
| 4767 | pSMB->DataOffset = 0; |
| 4768 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4769 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4770 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | pSMB->MaxSetupCount = 0; |
| 4772 | pSMB->Reserved = 0; |
| 4773 | pSMB->Flags = 0; |
| 4774 | pSMB->Timeout = 0; |
| 4775 | pSMB->Reserved2 = 0; |
| 4776 | byte_count = params + 1 /* pad */ ; |
| 4777 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4778 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4779 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4780 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4781 | pSMB->SetupCount = 1; |
| 4782 | pSMB->Reserved3 = 0; |
| 4783 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4784 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4785 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4787 | |
| 4788 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4789 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4790 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4791 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | } else { /* decode response */ |
| 4793 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4794 | |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 4795 | if (rc || get_bcc(&pSMBr->hdr) < 13) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | rc = -EIO; /* bad smb */ |
| 4797 | } else { |
| 4798 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4799 | response_data = |
| 4800 | (FILE_SYSTEM_POSIX_INFO |
| 4801 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4802 | data_offset); |
| 4803 | FSData->f_bsize = |
| 4804 | le32_to_cpu(response_data->BlockSize); |
| 4805 | FSData->f_blocks = |
| 4806 | le64_to_cpu(response_data->TotalBlocks); |
| 4807 | FSData->f_bfree = |
| 4808 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4809 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | FSData->f_bavail = FSData->f_bfree; |
| 4811 | } else { |
| 4812 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4813 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4815 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4817 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4818 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4819 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4820 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4821 | } |
| 4822 | } |
| 4823 | cifs_buf_release(pSMB); |
| 4824 | |
| 4825 | if (rc == -EAGAIN) |
| 4826 | goto QFSPosixRetry; |
| 4827 | |
| 4828 | return rc; |
| 4829 | } |
| 4830 | |
| 4831 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4832 | /* We can not use write of zero bytes trick to |
| 4833 | set file size due to need for large file support. Also note that |
| 4834 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | routine which is only needed to work around a sharing violation bug |
| 4836 | in Samba which this routine can run into */ |
| 4837 | |
| 4838 | int |
| 4839 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4840 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4841 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | { |
| 4843 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 4844 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 4845 | struct file_end_of_file_info *parm_data; |
| 4846 | int name_len; |
| 4847 | int rc = 0; |
| 4848 | int bytes_returned = 0; |
| 4849 | __u16 params, byte_count, data_count, param_offset, offset; |
| 4850 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4851 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4852 | SetEOFRetry: |
| 4853 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4854 | (void **) &pSMBr); |
| 4855 | if (rc) |
| 4856 | return rc; |
| 4857 | |
| 4858 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4859 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4860 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4861 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | name_len++; /* trailing null */ |
| 4863 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4864 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4865 | name_len = strnlen(fileName, PATH_MAX); |
| 4866 | name_len++; /* trailing null */ |
| 4867 | strncpy(pSMB->FileName, fileName, name_len); |
| 4868 | } |
| 4869 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4870 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4872 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4873 | pSMB->MaxSetupCount = 0; |
| 4874 | pSMB->Reserved = 0; |
| 4875 | pSMB->Flags = 0; |
| 4876 | pSMB->Timeout = 0; |
| 4877 | pSMB->Reserved2 = 0; |
| 4878 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4879 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4881 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4882 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4883 | pSMB->InformationLevel = |
| 4884 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4885 | else |
| 4886 | pSMB->InformationLevel = |
| 4887 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 4888 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4890 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4891 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4892 | else |
| 4893 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4894 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | parm_data = |
| 4898 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 4899 | offset); |
| 4900 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4901 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4902 | pSMB->SetupCount = 1; |
| 4903 | pSMB->Reserved3 = 0; |
| 4904 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 4905 | byte_count = 3 /* pad */ + params + data_count; |
| 4906 | pSMB->DataCount = cpu_to_le16(data_count); |
| 4907 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4908 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4909 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4910 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4911 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | parm_data->FileSize = cpu_to_le64(size); |
| 4913 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4914 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4915 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4916 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4917 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4918 | |
| 4919 | cifs_buf_release(pSMB); |
| 4920 | |
| 4921 | if (rc == -EAGAIN) |
| 4922 | goto SetEOFRetry; |
| 4923 | |
| 4924 | return rc; |
| 4925 | } |
| 4926 | |
| 4927 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4928 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4929 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4930 | { |
| 4931 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | struct file_end_of_file_info *parm_data; |
| 4933 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4934 | __u16 params, param_offset, offset, byte_count, count; |
| 4935 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4936 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 4937 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4938 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4939 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | if (rc) |
| 4941 | return rc; |
| 4942 | |
| 4943 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4944 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4946 | params = 6; |
| 4947 | pSMB->MaxSetupCount = 0; |
| 4948 | pSMB->Reserved = 0; |
| 4949 | pSMB->Flags = 0; |
| 4950 | pSMB->Timeout = 0; |
| 4951 | pSMB->Reserved2 = 0; |
| 4952 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4953 | offset = param_offset + params; |
| 4954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4955 | count = sizeof(struct file_end_of_file_info); |
| 4956 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4957 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4958 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | pSMB->SetupCount = 1; |
| 4960 | pSMB->Reserved3 = 0; |
| 4961 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4962 | byte_count = 3 /* pad */ + params + count; |
| 4963 | pSMB->DataCount = cpu_to_le16(count); |
| 4964 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4965 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4966 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4967 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4968 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4969 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 4970 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4971 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4972 | parm_data->FileSize = cpu_to_le64(size); |
| 4973 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4974 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4976 | pSMB->InformationLevel = |
| 4977 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4978 | else |
| 4979 | pSMB->InformationLevel = |
| 4980 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4981 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4982 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4983 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4984 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4985 | else |
| 4986 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4987 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | } |
| 4989 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 4990 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4991 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4992 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4994 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | } |
| 4996 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4997 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | since file handle passed in no longer valid */ |
| 4999 | |
| 5000 | return rc; |
| 5001 | } |
| 5002 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5003 | /* Some legacy servers such as NT4 require that the file times be set on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | an open handle, rather than by pathname - this is awkward due to |
| 5005 | potential access conflicts on the open, but it is unavoidable for these |
| 5006 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 5007 | time and resort to the original setpathinfo level which takes the ancient |
| 5008 | DOS time format with 2 second granularity */ |
| 5009 | int |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5010 | CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 5011 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | { |
| 5013 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5014 | char *data_offset; |
| 5015 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5016 | __u16 params, param_offset, offset, byte_count, count; |
| 5017 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5018 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5019 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | if (rc) |
| 5022 | return rc; |
| 5023 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5024 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5025 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5027 | params = 6; |
| 5028 | pSMB->MaxSetupCount = 0; |
| 5029 | pSMB->Reserved = 0; |
| 5030 | pSMB->Flags = 0; |
| 5031 | pSMB->Timeout = 0; |
| 5032 | pSMB->Reserved2 = 0; |
| 5033 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5034 | offset = param_offset + params; |
| 5035 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5036 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5038 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5040 | /* BB find max SMB PDU from sess */ |
| 5041 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5042 | pSMB->SetupCount = 1; |
| 5043 | pSMB->Reserved3 = 0; |
| 5044 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5045 | byte_count = 3 /* pad */ + params + count; |
| 5046 | pSMB->DataCount = cpu_to_le16(count); |
| 5047 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5048 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5049 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5050 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5051 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5052 | pSMB->Fid = fid; |
| 5053 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5054 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5055 | else |
| 5056 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5057 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5058 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5059 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5060 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5061 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5062 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5063 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5065 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5066 | since file handle passed in no longer valid */ |
| 5067 | |
| 5068 | return rc; |
| 5069 | } |
| 5070 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5071 | int |
| 5072 | CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, |
| 5073 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5074 | { |
| 5075 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5076 | char *data_offset; |
| 5077 | int rc = 0; |
| 5078 | __u16 params, param_offset, offset, byte_count, count; |
| 5079 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5080 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5081 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5082 | |
| 5083 | if (rc) |
| 5084 | return rc; |
| 5085 | |
| 5086 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5087 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5088 | |
| 5089 | params = 6; |
| 5090 | pSMB->MaxSetupCount = 0; |
| 5091 | pSMB->Reserved = 0; |
| 5092 | pSMB->Flags = 0; |
| 5093 | pSMB->Timeout = 0; |
| 5094 | pSMB->Reserved2 = 0; |
| 5095 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5096 | offset = param_offset + params; |
| 5097 | |
| 5098 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5099 | |
| 5100 | count = 1; |
| 5101 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5102 | /* BB find max SMB PDU from sess */ |
| 5103 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5104 | pSMB->SetupCount = 1; |
| 5105 | pSMB->Reserved3 = 0; |
| 5106 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5107 | byte_count = 3 /* pad */ + params + count; |
| 5108 | pSMB->DataCount = cpu_to_le16(count); |
| 5109 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5110 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5111 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5112 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5113 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5114 | pSMB->Fid = fid; |
| 5115 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5116 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5117 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5118 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5119 | *data_offset = delete_file ? 1 : 0; |
| 5120 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5121 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5122 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5123 | |
| 5124 | return rc; |
| 5125 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | |
| 5127 | int |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5128 | CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 5129 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5130 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5131 | { |
| 5132 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5133 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5134 | int name_len; |
| 5135 | int rc = 0; |
| 5136 | int bytes_returned = 0; |
| 5137 | char *data_offset; |
| 5138 | __u16 params, param_offset, offset, byte_count, count; |
| 5139 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5140 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5141 | |
| 5142 | SetTimesRetry: |
| 5143 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5144 | (void **) &pSMBr); |
| 5145 | if (rc) |
| 5146 | return rc; |
| 5147 | |
| 5148 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5149 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 5150 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5151 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5152 | name_len++; /* trailing null */ |
| 5153 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5154 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | name_len = strnlen(fileName, PATH_MAX); |
| 5156 | name_len++; /* trailing null */ |
| 5157 | strncpy(pSMB->FileName, fileName, name_len); |
| 5158 | } |
| 5159 | |
| 5160 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5161 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5162 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5163 | /* BB find max SMB PDU from sess structure BB */ |
| 5164 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | pSMB->MaxSetupCount = 0; |
| 5166 | pSMB->Reserved = 0; |
| 5167 | pSMB->Flags = 0; |
| 5168 | pSMB->Timeout = 0; |
| 5169 | pSMB->Reserved2 = 0; |
| 5170 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5171 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | offset = param_offset + params; |
| 5173 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5174 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5175 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5176 | pSMB->SetupCount = 1; |
| 5177 | pSMB->Reserved3 = 0; |
| 5178 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5179 | byte_count = 3 /* pad */ + params + count; |
| 5180 | |
| 5181 | pSMB->DataCount = cpu_to_le16(count); |
| 5182 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5183 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5184 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5185 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5186 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5187 | else |
| 5188 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5189 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5190 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5191 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5192 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5193 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5194 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5195 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5196 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5197 | |
| 5198 | cifs_buf_release(pSMB); |
| 5199 | |
| 5200 | if (rc == -EAGAIN) |
| 5201 | goto SetTimesRetry; |
| 5202 | |
| 5203 | return rc; |
| 5204 | } |
| 5205 | |
| 5206 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5207 | /* Can be used to set attributes */ |
| 5208 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5209 | handling it anyway and NT4 was what we thought it would be needed for |
| 5210 | Do not delete it until we prove whether needed for Win9x though */ |
| 5211 | int |
| 5212 | CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5213 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5214 | { |
| 5215 | SETATTR_REQ *pSMB = NULL; |
| 5216 | SETATTR_RSP *pSMBr = NULL; |
| 5217 | int rc = 0; |
| 5218 | int bytes_returned; |
| 5219 | int name_len; |
| 5220 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5221 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5222 | |
| 5223 | SetAttrLgcyRetry: |
| 5224 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5225 | (void **) &pSMBr); |
| 5226 | if (rc) |
| 5227 | return rc; |
| 5228 | |
| 5229 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5230 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5231 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5232 | PATH_MAX, nls_codepage); |
| 5233 | name_len++; /* trailing null */ |
| 5234 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5235 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5236 | name_len = strnlen(fileName, PATH_MAX); |
| 5237 | name_len++; /* trailing null */ |
| 5238 | strncpy(pSMB->fileName, fileName, name_len); |
| 5239 | } |
| 5240 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5241 | pSMB->BufferFormat = 0x04; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5242 | inc_rfc1001_len(pSMB, name_len + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5244 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5245 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5246 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5247 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | |
| 5249 | cifs_buf_release(pSMB); |
| 5250 | |
| 5251 | if (rc == -EAGAIN) |
| 5252 | goto SetAttrLgcyRetry; |
| 5253 | |
| 5254 | return rc; |
| 5255 | } |
| 5256 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5257 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5258 | static void |
| 5259 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5260 | const struct cifs_unix_set_info_args *args) |
| 5261 | { |
| 5262 | u64 mode = args->mode; |
| 5263 | |
| 5264 | /* |
| 5265 | * Samba server ignores set of file size to zero due to bugs in some |
| 5266 | * older clients, but we should be precise - we use SetFileSize to |
| 5267 | * set file size and do not want to truncate file size to zero |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 5268 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5269 | * zero instead of -1 here |
| 5270 | */ |
| 5271 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5272 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5273 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5274 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5275 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5276 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5277 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5278 | /* better to leave device as zero when it is */ |
| 5279 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5280 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5281 | data_offset->Permissions = cpu_to_le64(mode); |
| 5282 | |
| 5283 | if (S_ISREG(mode)) |
| 5284 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5285 | else if (S_ISDIR(mode)) |
| 5286 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5287 | else if (S_ISLNK(mode)) |
| 5288 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5289 | else if (S_ISCHR(mode)) |
| 5290 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5291 | else if (S_ISBLK(mode)) |
| 5292 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5293 | else if (S_ISFIFO(mode)) |
| 5294 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5295 | else if (S_ISSOCK(mode)) |
| 5296 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5297 | } |
| 5298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | int |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5300 | CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 5301 | const struct cifs_unix_set_info_args *args, |
| 5302 | u16 fid, u32 pid_of_opener) |
| 5303 | { |
| 5304 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5305 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5306 | int rc = 0; |
| 5307 | u16 params, param_offset, offset, byte_count, count; |
| 5308 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5309 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5310 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5311 | |
| 5312 | if (rc) |
| 5313 | return rc; |
| 5314 | |
| 5315 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5316 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5317 | |
| 5318 | params = 6; |
| 5319 | pSMB->MaxSetupCount = 0; |
| 5320 | pSMB->Reserved = 0; |
| 5321 | pSMB->Flags = 0; |
| 5322 | pSMB->Timeout = 0; |
| 5323 | pSMB->Reserved2 = 0; |
| 5324 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5325 | offset = param_offset + params; |
| 5326 | |
| 5327 | data_offset = (FILE_UNIX_BASIC_INFO *) |
| 5328 | ((char *)(&pSMB->hdr.Protocol) + offset); |
| 5329 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5330 | |
| 5331 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5332 | /* BB find max SMB PDU from sess */ |
| 5333 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5334 | pSMB->SetupCount = 1; |
| 5335 | pSMB->Reserved3 = 0; |
| 5336 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5337 | byte_count = 3 /* pad */ + params + count; |
| 5338 | pSMB->DataCount = cpu_to_le16(count); |
| 5339 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5340 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5341 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5342 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5343 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5344 | pSMB->Fid = fid; |
| 5345 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5346 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5347 | inc_rfc1001_len(pSMB, byte_count); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5348 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5349 | |
| 5350 | cifs_fill_unix_set_info(data_offset, args); |
| 5351 | |
| 5352 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5353 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5354 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5355 | |
| 5356 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5357 | since file handle passed in no longer valid */ |
| 5358 | |
| 5359 | return rc; |
| 5360 | } |
| 5361 | |
| 5362 | int |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5363 | CIFSSMBUnixSetPathInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5364 | const struct cifs_unix_set_info_args *args, |
| 5365 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | { |
| 5367 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5368 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5369 | int name_len; |
| 5370 | int rc = 0; |
| 5371 | int bytes_returned = 0; |
| 5372 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5373 | __u16 params, param_offset, offset, count, byte_count; |
| 5374 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5375 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | setPermsRetry: |
| 5377 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5378 | (void **) &pSMBr); |
| 5379 | if (rc) |
| 5380 | return rc; |
| 5381 | |
| 5382 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5383 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5384 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5385 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | name_len++; /* trailing null */ |
| 5387 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5388 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | name_len = strnlen(fileName, PATH_MAX); |
| 5390 | name_len++; /* trailing null */ |
| 5391 | strncpy(pSMB->FileName, fileName, name_len); |
| 5392 | } |
| 5393 | |
| 5394 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5395 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5397 | /* BB find max SMB PDU from sess structure BB */ |
| 5398 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | pSMB->MaxSetupCount = 0; |
| 5400 | pSMB->Reserved = 0; |
| 5401 | pSMB->Flags = 0; |
| 5402 | pSMB->Timeout = 0; |
| 5403 | pSMB->Reserved2 = 0; |
| 5404 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5405 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5406 | offset = param_offset + params; |
| 5407 | data_offset = |
| 5408 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5409 | offset); |
| 5410 | memset(data_offset, 0, count); |
| 5411 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5412 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5413 | pSMB->SetupCount = 1; |
| 5414 | pSMB->Reserved3 = 0; |
| 5415 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5416 | byte_count = 3 /* pad */ + params + count; |
| 5417 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5418 | pSMB->DataCount = cpu_to_le16(count); |
| 5419 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5420 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5421 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5422 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5423 | inc_rfc1001_len(pSMB, byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5424 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5425 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5426 | |
| 5427 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5428 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5429 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5430 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5431 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5432 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5433 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | if (rc == -EAGAIN) |
| 5435 | goto setPermsRetry; |
| 5436 | return rc; |
| 5437 | } |
| 5438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5439 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5440 | /* |
| 5441 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 5442 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 5443 | * it looks for that attribute name and stuffs that value into the EAData |
| 5444 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 5445 | * buffer. In both cases, the return value is either the length of the |
| 5446 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 5447 | * the data isn't copied to it, but the length is returned. |
| 5448 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5449 | ssize_t |
| 5450 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5451 | const unsigned char *searchName, const unsigned char *ea_name, |
| 5452 | char *EAData, size_t buf_size, |
| 5453 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5454 | { |
| 5455 | /* BB assumes one setup word */ |
| 5456 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5457 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5458 | int rc = 0; |
| 5459 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5460 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5461 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5462 | struct fea *temp_fea; |
| 5463 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5464 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5465 | __u16 params, byte_count, data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5467 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5468 | QAllEAsRetry: |
| 5469 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5470 | (void **) &pSMBr); |
| 5471 | if (rc) |
| 5472 | return rc; |
| 5473 | |
| 5474 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5475 | list_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5476 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5477 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5478 | list_len++; /* trailing null */ |
| 5479 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5481 | list_len = strnlen(searchName, PATH_MAX); |
| 5482 | list_len++; /* trailing null */ |
| 5483 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | } |
| 5485 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5486 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | pSMB->TotalDataCount = 0; |
| 5488 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5489 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5490 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | pSMB->MaxSetupCount = 0; |
| 5492 | pSMB->Reserved = 0; |
| 5493 | pSMB->Flags = 0; |
| 5494 | pSMB->Timeout = 0; |
| 5495 | pSMB->Reserved2 = 0; |
| 5496 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5497 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | pSMB->DataCount = 0; |
| 5499 | pSMB->DataOffset = 0; |
| 5500 | pSMB->SetupCount = 1; |
| 5501 | pSMB->Reserved3 = 0; |
| 5502 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5503 | byte_count = params + 1 /* pad */ ; |
| 5504 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5505 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5506 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5507 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5508 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5510 | |
| 5511 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5512 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5513 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5514 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5515 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5516 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5517 | |
| 5518 | |
| 5519 | /* BB also check enough total bytes returned */ |
| 5520 | /* BB we need to improve the validity checking |
| 5521 | of these trans2 responses */ |
| 5522 | |
| 5523 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Jeff Layton | 820a803 | 2011-05-04 08:05:26 -0400 | [diff] [blame] | 5524 | if (rc || get_bcc(&pSMBr->hdr) < 4) { |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5525 | rc = -EIO; /* bad smb */ |
| 5526 | goto QAllEAsOut; |
| 5527 | } |
| 5528 | |
| 5529 | /* check that length of list is not more than bcc */ |
| 5530 | /* check that each entry does not go beyond length |
| 5531 | of list */ |
| 5532 | /* check that each element of each entry does not |
| 5533 | go beyond end of list */ |
| 5534 | /* validate_trans2_offsets() */ |
| 5535 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 5536 | |
| 5537 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5538 | ea_response_data = (struct fealist *) |
| 5539 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5540 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5541 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5542 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5543 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5544 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5545 | goto QAllEAsOut; |
| 5546 | } |
| 5547 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5548 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 5549 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5550 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5551 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5552 | rc = -EIO; |
| 5553 | goto QAllEAsOut; |
| 5554 | } |
| 5555 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5556 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5557 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5558 | temp_fea = ea_response_data->list; |
| 5559 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5560 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 5561 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5562 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5563 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5564 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5565 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5566 | /* make sure we can read name_len and value_len */ |
| 5567 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5568 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5569 | rc = -EIO; |
| 5570 | goto QAllEAsOut; |
| 5571 | } |
| 5572 | |
| 5573 | name_len = temp_fea->name_len; |
| 5574 | value_len = le16_to_cpu(temp_fea->value_len); |
| 5575 | list_len -= name_len + 1 + value_len; |
| 5576 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5577 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5578 | rc = -EIO; |
| 5579 | goto QAllEAsOut; |
| 5580 | } |
| 5581 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5582 | if (ea_name) { |
| 5583 | if (strncmp(ea_name, temp_ptr, name_len) == 0) { |
| 5584 | temp_ptr += name_len + 1; |
| 5585 | rc = value_len; |
| 5586 | if (buf_size == 0) |
| 5587 | goto QAllEAsOut; |
| 5588 | if ((size_t)value_len > buf_size) { |
| 5589 | rc = -ERANGE; |
| 5590 | goto QAllEAsOut; |
| 5591 | } |
| 5592 | memcpy(EAData, temp_ptr, value_len); |
| 5593 | goto QAllEAsOut; |
| 5594 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5595 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5596 | /* account for prefix user. and trailing null */ |
| 5597 | rc += (5 + 1 + name_len); |
| 5598 | if (rc < (int) buf_size) { |
| 5599 | memcpy(EAData, "user.", 5); |
| 5600 | EAData += 5; |
| 5601 | memcpy(EAData, temp_ptr, name_len); |
| 5602 | EAData += name_len; |
| 5603 | /* null terminate name */ |
| 5604 | *EAData = 0; |
| 5605 | ++EAData; |
| 5606 | } else if (buf_size == 0) { |
| 5607 | /* skip copy - calc size only */ |
| 5608 | } else { |
| 5609 | /* stop before overrun buffer */ |
| 5610 | rc = -ERANGE; |
| 5611 | break; |
| 5612 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5613 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5614 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5615 | temp_fea = (struct fea *)temp_ptr; |
| 5616 | } |
| 5617 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5618 | /* didn't find the named attribute */ |
| 5619 | if (ea_name) |
| 5620 | rc = -ENODATA; |
| 5621 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5622 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5623 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5624 | if (rc == -EAGAIN) |
| 5625 | goto QAllEAsRetry; |
| 5626 | |
| 5627 | return (ssize_t)rc; |
| 5628 | } |
| 5629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | int |
| 5631 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5632 | const char *ea_name, const void *ea_value, |
| 5633 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 5634 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | { |
| 5636 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5637 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5638 | struct fealist *parm_data; |
| 5639 | int name_len; |
| 5640 | int rc = 0; |
| 5641 | int bytes_returned = 0; |
| 5642 | __u16 params, param_offset, byte_count, offset, count; |
| 5643 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5644 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | SetEARetry: |
| 5646 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5647 | (void **) &pSMBr); |
| 5648 | if (rc) |
| 5649 | return rc; |
| 5650 | |
| 5651 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5652 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5653 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5654 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | name_len++; /* trailing null */ |
| 5656 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5657 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5658 | name_len = strnlen(fileName, PATH_MAX); |
| 5659 | name_len++; /* trailing null */ |
| 5660 | strncpy(pSMB->FileName, fileName, name_len); |
| 5661 | } |
| 5662 | |
| 5663 | params = 6 + name_len; |
| 5664 | |
| 5665 | /* done calculating parms using name_len of file name, |
| 5666 | now use name_len to calculate length of ea name |
| 5667 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5668 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5669 | name_len = 0; |
| 5670 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5671 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 5673 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5674 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5675 | /* BB find max SMB PDU from sess */ |
| 5676 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | pSMB->MaxSetupCount = 0; |
| 5678 | pSMB->Reserved = 0; |
| 5679 | pSMB->Flags = 0; |
| 5680 | pSMB->Timeout = 0; |
| 5681 | pSMB->Reserved2 = 0; |
| 5682 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5683 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | offset = param_offset + params; |
| 5685 | pSMB->InformationLevel = |
| 5686 | cpu_to_le16(SMB_SET_FILE_EA); |
| 5687 | |
| 5688 | parm_data = |
| 5689 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 5690 | offset); |
| 5691 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5692 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5693 | pSMB->SetupCount = 1; |
| 5694 | pSMB->Reserved3 = 0; |
| 5695 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5696 | byte_count = 3 /* pad */ + params + count; |
| 5697 | pSMB->DataCount = cpu_to_le16(count); |
| 5698 | parm_data->list_len = cpu_to_le32(count); |
| 5699 | parm_data->list[0].EA_flags = 0; |
| 5700 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 5701 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5702 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5703 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5704 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5705 | parm_data->list[0].name[name_len] = 0; |
| 5706 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 5707 | /* caller ensures that ea_value_len is less than 64K but |
| 5708 | we need to ensure that it fits within the smb */ |
| 5709 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5710 | /*BB add length check to see if it would fit in |
| 5711 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5712 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 5713 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5714 | memcpy(parm_data->list[0].name+name_len+1, |
| 5715 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5716 | |
| 5717 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5718 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5719 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5720 | pSMB->Reserved4 = 0; |
Steve French | be8e3b0 | 2011-04-29 05:40:20 +0000 | [diff] [blame] | 5721 | inc_rfc1001_len(pSMB, byte_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5722 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5723 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5724 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5725 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5726 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | |
| 5728 | cifs_buf_release(pSMB); |
| 5729 | |
| 5730 | if (rc == -EAGAIN) |
| 5731 | goto SetEARetry; |
| 5732 | |
| 5733 | return rc; |
| 5734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame] | 5736 | |
| 5737 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 5738 | /* |
| 5739 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 5740 | * to allow network clients (such as Windows) to display updated |
| 5741 | * lists of files in directory listings automatically when |
| 5742 | * files are added by one user when another user has the |
| 5743 | * same directory open on their desktop. The Linux cifs kernel |
| 5744 | * client hooked into the kernel side of this interface for |
| 5745 | * the same reason, but ironically when the VFS moved from |
| 5746 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 5747 | * network file system clients (the most obvious use case |
| 5748 | * for notify interfaces is when multiple users can update |
| 5749 | * the contents of the same directory - exactly what network |
| 5750 | * file systems can do) although the server (Samba) could |
| 5751 | * still use it. For the short term we leave the worker |
| 5752 | * function ifdeffed out (below) until inotify is fixed |
| 5753 | * in the VFS to make it easier to plug in network file |
| 5754 | * system clients. If inotify turns out to be permanently |
| 5755 | * incompatible for network fs clients, we could instead simply |
| 5756 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 5757 | */ |
| 5758 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
| 5759 | const int notify_subdirs, const __u16 netfid, |
| 5760 | __u32 filter, struct file *pfile, int multishot, |
| 5761 | const struct nls_table *nls_codepage) |
| 5762 | { |
| 5763 | int rc = 0; |
| 5764 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 5765 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 5766 | struct dir_notify_req *dnotify_req; |
| 5767 | int bytes_returned; |
| 5768 | |
| 5769 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 5770 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 5771 | (void **) &pSMBr); |
| 5772 | if (rc) |
| 5773 | return rc; |
| 5774 | |
| 5775 | pSMB->TotalParameterCount = 0 ; |
| 5776 | pSMB->TotalDataCount = 0; |
| 5777 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 5778 | /* BB find exact data count max from sess structure BB */ |
| 5779 | pSMB->MaxDataCount = 0; /* same in little endian or be */ |
| 5780 | /* BB VERIFY verify which is correct for above BB */ |
| 5781 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 5782 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 5783 | |
| 5784 | pSMB->MaxSetupCount = 4; |
| 5785 | pSMB->Reserved = 0; |
| 5786 | pSMB->ParameterOffset = 0; |
| 5787 | pSMB->DataCount = 0; |
| 5788 | pSMB->DataOffset = 0; |
| 5789 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 5790 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 5791 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5792 | if (notify_subdirs) |
| 5793 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 5794 | pSMB->Reserved2 = 0; |
| 5795 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 5796 | pSMB->Fid = netfid; /* file handle always le */ |
| 5797 | pSMB->ByteCount = 0; |
| 5798 | |
| 5799 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5800 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 5801 | CIFS_ASYNC_OP); |
| 5802 | if (rc) { |
| 5803 | cFYI(1, "Error in Notify = %d", rc); |
| 5804 | } else { |
| 5805 | /* Add file to outstanding requests */ |
| 5806 | /* BB change to kmem cache alloc */ |
| 5807 | dnotify_req = kmalloc( |
| 5808 | sizeof(struct dir_notify_req), |
| 5809 | GFP_KERNEL); |
| 5810 | if (dnotify_req) { |
| 5811 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 5812 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 5813 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 5814 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 5815 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 5816 | dnotify_req->netfid = netfid; |
| 5817 | dnotify_req->pfile = pfile; |
| 5818 | dnotify_req->filter = filter; |
| 5819 | dnotify_req->multishot = multishot; |
| 5820 | spin_lock(&GlobalMid_Lock); |
| 5821 | list_add_tail(&dnotify_req->lhead, |
| 5822 | &GlobalDnotifyReqList); |
| 5823 | spin_unlock(&GlobalMid_Lock); |
| 5824 | } else |
| 5825 | rc = -ENOMEM; |
| 5826 | } |
| 5827 | cifs_buf_release(pSMB); |
| 5828 | return rc; |
| 5829 | } |
| 5830 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |