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 | a4544347 | 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 | a4544347 | 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 | |
| 342 | /* check that bcc is at least as big as parms + data */ |
| 343 | /* check that bcc is less than negotiated smb buffer */ |
| 344 | total_size = get_unaligned_le16(&pSMB->t2_rsp.ParameterCount); |
| 345 | if (total_size >= 512) |
| 346 | goto vt2_err; |
| 347 | |
| 348 | total_size += get_unaligned_le16(&pSMB->t2_rsp.DataCount); |
| 349 | if (total_size > get_bcc(&pSMB->hdr) || |
| 350 | total_size >= CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) |
| 351 | goto vt2_err; |
| 352 | |
| 353 | return 0; |
| 354 | vt2_err: |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 355 | cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | sizeof(struct smb_t2_rsp) + 16); |
Jeff Layton | 12df83c | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 357 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | int |
| 361 | CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses) |
| 362 | { |
| 363 | NEGOTIATE_REQ *pSMB; |
| 364 | NEGOTIATE_RSP *pSMBr; |
| 365 | int rc = 0; |
| 366 | int bytes_returned; |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 367 | int i; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 368 | struct TCP_Server_Info *server; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | u16 count; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 370 | unsigned int secFlags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 372 | if (ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | server = ses->server; |
| 374 | else { |
| 375 | rc = -EIO; |
| 376 | return rc; |
| 377 | } |
| 378 | rc = smb_init(SMB_COM_NEGOTIATE, 0, NULL /* no tcon yet */ , |
| 379 | (void **) &pSMB, (void **) &pSMBr); |
| 380 | if (rc) |
| 381 | return rc; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 382 | |
| 383 | /* 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] | 384 | if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL))) |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 385 | secFlags = ses->overrideSecFlg; /* BB FIXME fix sign flags? */ |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 386 | 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] | 387 | secFlags = global_secflags | ses->overrideSecFlg; |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 388 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 389 | cFYI(1, "secFlags 0x%x", secFlags); |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 390 | |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 391 | pSMB->hdr.Mid = GetNextMid(server); |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 392 | pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 393 | |
Yehuda Sadeh Weinraub | 100c1dd | 2007-06-05 21:31:16 +0000 | [diff] [blame] | 394 | if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 395 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 396 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 397 | cFYI(1, "Kerberos only mechanism, enable extended security"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 398 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
Jeff Layton | b4d6fcf | 2011-01-07 11:30:28 -0500 | [diff] [blame] | 399 | } else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP) |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 400 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 401 | else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 402 | cFYI(1, "NTLMSSP only mechanism, enable extended security"); |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 403 | pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; |
| 404 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 405 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 406 | count = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 407 | for (i = 0; i < CIFS_NUM_PROT; i++) { |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 408 | strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); |
| 409 | count += strlen(protocols[i].name) + 1; |
| 410 | /* null at end of source and target buffers anyway */ |
| 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | pSMB->hdr.smb_buf_length += count; |
| 413 | pSMB->ByteCount = cpu_to_le16(count); |
| 414 | |
| 415 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 416 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 417 | if (rc != 0) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 418 | goto neg_err_exit; |
| 419 | |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 420 | server->dialect = le16_to_cpu(pSMBr->DialectIndex); |
| 421 | cFYI(1, "Dialect: %d", server->dialect); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 422 | /* Check wct = 1 error case */ |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 423 | if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 424 | /* core returns wct = 1, but we do not ask for core - otherwise |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 425 | small wct just comes when dialect index is -1 indicating we |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 426 | could not negotiate a common dialect */ |
| 427 | rc = -EOPNOTSUPP; |
| 428 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 429 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 430 | } else if ((pSMBr->hdr.WordCount == 13) |
Jeff Layton | 9bf67e5 | 2010-04-24 07:57:46 -0400 | [diff] [blame] | 431 | && ((server->dialect == LANMAN_PROT) |
| 432 | || (server->dialect == LANMAN2_PROT))) { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 433 | __s16 tmp; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 434 | struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 435 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 436 | if ((secFlags & CIFSSEC_MAY_LANMAN) || |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 437 | (secFlags & CIFSSEC_MAY_PLNTXT)) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 438 | server->secType = LANMAN; |
| 439 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 440 | cERROR(1, "mount failed weak security disabled" |
| 441 | " in /proc/fs/cifs/SecurityFlags"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 442 | rc = -EOPNOTSUPP; |
| 443 | goto neg_err_exit; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 444 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 445 | server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); |
| 446 | server->maxReq = le16_to_cpu(rsp->MaxMpxCount); |
| 447 | server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 448 | (__u32)CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 449 | server->max_vcs = le16_to_cpu(rsp->MaxNumberVcs); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 450 | /* even though we do not use raw we might as well set this |
| 451 | accurately, in case we ever find a need for it */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 452 | if ((le16_to_cpu(rsp->RawMode) & RAW_ENABLE) == RAW_ENABLE) { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 453 | server->max_rw = 0xFF00; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 454 | server->capabilities = CAP_MPX_MODE | CAP_RAW_MODE; |
| 455 | } else { |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 456 | server->max_rw = 0;/* do not need to use raw anyway */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 457 | server->capabilities = CAP_MPX_MODE; |
| 458 | } |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 459 | tmp = (__s16)le16_to_cpu(rsp->ServerTimeZone); |
Steve French | 1a70d65 | 2006-10-02 05:59:18 +0000 | [diff] [blame] | 460 | if (tmp == -1) { |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 461 | /* OS/2 often does not set timezone therefore |
| 462 | * we must use server time to calc time zone. |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 463 | * Could deviate slightly from the right zone. |
| 464 | * Smallest defined timezone difference is 15 minutes |
| 465 | * (i.e. Nepal). Rounding up/down is done to match |
| 466 | * this requirement. |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 467 | */ |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 468 | int val, seconds, remain, result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 469 | struct timespec ts, utc; |
| 470 | utc = CURRENT_TIME; |
Jeff Layton | c4a2c08 | 2009-05-27 09:37:33 -0400 | [diff] [blame] | 471 | ts = cnvrtDosUnixTm(rsp->SrvTime.Date, |
| 472 | rsp->SrvTime.Time, 0); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 473 | cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d", |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 474 | (int)ts.tv_sec, (int)utc.tv_sec, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 475 | (int)(utc.tv_sec - ts.tv_sec)); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 476 | val = (int)(utc.tv_sec - ts.tv_sec); |
Andre Haupt | 8594c15 | 2007-08-30 20:18:41 +0000 | [diff] [blame] | 477 | seconds = abs(val); |
Steve French | 947a506 | 2006-10-02 05:55:25 +0000 | [diff] [blame] | 478 | result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 479 | remain = seconds % MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 480 | if (remain >= (MIN_TZ_ADJ / 2)) |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 481 | result += MIN_TZ_ADJ; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 482 | if (val < 0) |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 483 | result = -result; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 484 | server->timeAdj = result; |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 485 | } else { |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 486 | server->timeAdj = (int)tmp; |
| 487 | server->timeAdj *= 60; /* also in seconds */ |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 488 | } |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 489 | cFYI(1, "server->timeAdj: %d seconds", server->timeAdj); |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 490 | |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 491 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 492 | /* BB get server time for time conversions and add |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 493 | code to use it and timezone since this is not UTC */ |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 494 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 495 | if (rsp->EncryptionKeyLength == |
Steve French | 25ee4a9 | 2006-09-30 00:54:23 +0000 | [diff] [blame] | 496 | cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 497 | memcpy(ses->server->cryptkey, rsp->EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 498 | CIFS_CRYPTO_KEY_SIZE); |
| 499 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 500 | rc = -EIO; /* need cryptkey unless plain text */ |
| 501 | goto neg_err_exit; |
| 502 | } |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 503 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 504 | cFYI(1, "LANMAN negotiated"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 505 | /* we will not end up setting signing flags - as no signing |
| 506 | was in LANMAN and server did not return the flags on */ |
| 507 | goto signing_check; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 508 | #else /* weak security disabled */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 509 | } else if (pSMBr->hdr.WordCount == 13) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 510 | cERROR(1, "mount failed, cifs module not built " |
| 511 | "with CIFS_WEAK_PW_HASH support"); |
Dan Carpenter | 8212cf7 | 2010-03-15 11:22:26 +0300 | [diff] [blame] | 512 | rc = -EOPNOTSUPP; |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 513 | #endif /* WEAK_PW_HASH */ |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 514 | goto neg_err_exit; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 515 | } else if (pSMBr->hdr.WordCount != 17) { |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 516 | /* unknown wct */ |
| 517 | rc = -EOPNOTSUPP; |
| 518 | goto neg_err_exit; |
| 519 | } |
| 520 | /* else wct == 17 NTLM */ |
| 521 | server->secMode = pSMBr->SecurityMode; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 522 | if ((server->secMode & SECMODE_USER) == 0) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 523 | cFYI(1, "share mode security"); |
Steve French | 3979877 | 2006-05-31 22:40:51 +0000 | [diff] [blame] | 524 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 525 | if ((server->secMode & SECMODE_PW_ENCRYPT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 526 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 750d115 | 2006-06-27 06:28:30 +0000 | [diff] [blame] | 527 | if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) |
Steve French | bdc4bf6e | 2006-06-02 22:57:13 +0000 | [diff] [blame] | 528 | #endif /* CIFS_WEAK_PW_HASH */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 529 | cERROR(1, "Server requests plain text password" |
| 530 | " but client support disabled"); |
Steve French | 9312f67 | 2006-06-04 22:21:07 +0000 | [diff] [blame] | 531 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 532 | if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 533 | server->secType = NTLMv2; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 534 | else if (secFlags & CIFSSEC_MAY_NTLM) |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 535 | server->secType = NTLM; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 536 | else if (secFlags & CIFSSEC_MAY_NTLMV2) |
Steve French | f40c562 | 2006-06-28 00:13:38 +0000 | [diff] [blame] | 537 | server->secType = NTLMv2; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 538 | else if (secFlags & CIFSSEC_MAY_KRB5) |
| 539 | server->secType = Kerberos; |
Steve French | ac68392 | 2009-05-06 04:16:04 +0000 | [diff] [blame] | 540 | else if (secFlags & CIFSSEC_MAY_NTLMSSP) |
Steve French | f46c723 | 2009-06-25 03:04:20 +0000 | [diff] [blame] | 541 | server->secType = RawNTLMSSP; |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 542 | else if (secFlags & CIFSSEC_MAY_LANMAN) |
| 543 | server->secType = LANMAN; |
| 544 | /* #ifdef CONFIG_CIFS_EXPERIMENTAL |
| 545 | else if (secFlags & CIFSSEC_MAY_PLNTXT) |
| 546 | server->secType = ?? |
| 547 | #endif */ |
| 548 | else { |
| 549 | rc = -EOPNOTSUPP; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 550 | cERROR(1, "Invalid security type"); |
Steve French | a013689 | 2007-10-04 20:05:09 +0000 | [diff] [blame] | 551 | goto neg_err_exit; |
| 552 | } |
| 553 | /* else ... any others ...? */ |
Steve French | 7c7b25b | 2006-06-01 19:20:10 +0000 | [diff] [blame] | 554 | |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 555 | /* one byte, so no need to convert this or EncryptionKeyLen from |
| 556 | little endian */ |
| 557 | server->maxReq = le16_to_cpu(pSMBr->MaxMpxCount); |
| 558 | /* probably no need to store and check maxvcs */ |
| 559 | server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE); |
Steve French | eca6acf | 2009-02-20 05:43:09 +0000 | [diff] [blame] | 561 | server->max_rw = le32_to_cpu(pSMBr->MaxRawSize); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 562 | cFYI(DBG2, "Max buf = %d", ses->server->maxBuf); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 563 | server->capabilities = le32_to_cpu(pSMBr->Capabilities); |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 564 | server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone); |
| 565 | server->timeAdj *= 60; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 566 | if (pSMBr->EncryptionKeyLength == CIFS_CRYPTO_KEY_SIZE) { |
Shirish Pargaonkar | d3ba50b | 2010-10-27 15:20:36 -0500 | [diff] [blame] | 567 | memcpy(ses->server->cryptkey, pSMBr->u.EncryptionKey, |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 568 | CIFS_CRYPTO_KEY_SIZE); |
| 569 | } else if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) |
| 570 | && (pSMBr->EncryptionKeyLength == 0)) { |
| 571 | /* decode security blob */ |
| 572 | } else if (server->secMode & SECMODE_PW_ENCRYPT) { |
| 573 | rc = -EIO; /* no crypt key only if plain text pwd */ |
| 574 | goto neg_err_exit; |
| 575 | } |
| 576 | |
| 577 | /* BB might be helpful to save off the domain of server here */ |
| 578 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 579 | if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 580 | (server->capabilities & CAP_EXTENDED_SECURITY)) { |
| 581 | count = pSMBr->ByteCount; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 582 | if (count < 16) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | rc = -EIO; |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 584 | goto neg_err_exit; |
| 585 | } |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 586 | spin_lock(&cifs_tcp_ses_lock); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 587 | if (server->srv_count > 1) { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 588 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 589 | if (memcmp(server->server_GUID, |
| 590 | pSMBr->u.extended_response. |
| 591 | GUID, 16) != 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 592 | cFYI(1, "server UID changed"); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 593 | memcpy(server->server_GUID, |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 594 | pSMBr->u.extended_response.GUID, |
| 595 | 16); |
| 596 | } |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 597 | } else { |
Suresh Jayaraman | 3f9bcca | 2010-10-18 23:29:37 +0530 | [diff] [blame] | 598 | spin_unlock(&cifs_tcp_ses_lock); |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 599 | memcpy(server->server_GUID, |
| 600 | pSMBr->u.extended_response.GUID, 16); |
Jeff Layton | e7ddee9 | 2008-11-14 13:44:38 -0500 | [diff] [blame] | 601 | } |
Jeff Layton | e187e44 | 2007-10-16 17:10:44 +0000 | [diff] [blame] | 602 | |
| 603 | if (count == 16) { |
| 604 | server->secType = RawNTLMSSP; |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 605 | } else { |
| 606 | rc = decode_negTokenInit(pSMBr->u.extended_response. |
Jeff Layton | 26efa0b | 2010-04-24 07:57:49 -0400 | [diff] [blame] | 607 | SecurityBlob, count - 16, |
| 608 | server); |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 609 | if (rc == 1) |
Jeff Layton | e545937 | 2007-11-03 05:11:06 +0000 | [diff] [blame] | 610 | rc = 0; |
Shirish Pargaonkar | ef571ca | 2008-07-24 15:56:05 +0000 | [diff] [blame] | 611 | else |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 612 | rc = -EINVAL; |
Shirish Pargaonkar | 2b149f1 | 2010-09-18 22:02:18 -0500 | [diff] [blame] | 613 | if (server->secType == Kerberos) { |
| 614 | if (!server->sec_kerberos && |
| 615 | !server->sec_mskerberos) |
| 616 | rc = -EOPNOTSUPP; |
| 617 | } else if (server->secType == RawNTLMSSP) { |
| 618 | if (!server->sec_ntlmssp) |
| 619 | rc = -EOPNOTSUPP; |
| 620 | } else |
| 621 | rc = -EOPNOTSUPP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 623 | } else |
| 624 | server->capabilities &= ~CAP_EXTENDED_SECURITY; |
| 625 | |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 626 | #ifdef CONFIG_CIFS_WEAK_PW_HASH |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 627 | signing_check: |
Steve French | 6344a42 | 2006-06-12 04:18:35 +0000 | [diff] [blame] | 628 | #endif |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 629 | if ((secFlags & CIFSSEC_MAY_SIGN) == 0) { |
| 630 | /* MUST_SIGN already includes the MAY_SIGN FLAG |
| 631 | so if this is zero it means that signing is disabled */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 632 | cFYI(1, "Signing disabled"); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 633 | if (server->secMode & SECMODE_SIGN_REQUIRED) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 634 | cERROR(1, "Server requires " |
Jeff Layton | 7111d21 | 2007-10-16 16:50:25 +0000 | [diff] [blame] | 635 | "packet signing to be enabled in " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 636 | "/proc/fs/cifs/SecurityFlags."); |
Steve French | abb63d6 | 2007-10-18 02:58:40 +0000 | [diff] [blame] | 637 | rc = -EOPNOTSUPP; |
| 638 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 639 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 640 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 641 | } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { |
| 642 | /* signing required */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 643 | cFYI(1, "Must sign - secFlags 0x%x", secFlags); |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 644 | if ((server->secMode & |
| 645 | (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 646 | cERROR(1, "signing required but server lacks support"); |
Jeff | 38c10a1 | 2007-07-06 21:10:07 +0000 | [diff] [blame] | 647 | rc = -EOPNOTSUPP; |
Steve French | 762e5ab | 2007-06-28 18:41:42 +0000 | [diff] [blame] | 648 | } else |
| 649 | server->secMode |= SECMODE_SIGN_REQUIRED; |
| 650 | } else { |
| 651 | /* signing optional ie CIFSSEC_MAY_SIGN */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 652 | if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 653 | server->secMode &= |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 654 | ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 656 | |
| 657 | neg_err_exit: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 658 | cifs_buf_release(pSMB); |
Steve French | 254e55e | 2006-06-04 05:53:15 +0000 | [diff] [blame] | 659 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 660 | cFYI(1, "negprot rc %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return rc; |
| 662 | } |
| 663 | |
| 664 | int |
| 665 | CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon) |
| 666 | { |
| 667 | struct smb_hdr *smb_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 670 | cFYI(1, "In tree disconnect"); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 671 | |
| 672 | /* BB: do we need to check this? These should never be NULL. */ |
| 673 | if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) |
| 674 | return -EIO; |
| 675 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | /* |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 677 | * No need to return error on this operation if tid invalidated and |
| 678 | * closed on server already e.g. due to tcp session crashing. Also, |
| 679 | * the tcon is no longer on the list, so no need to take lock before |
| 680 | * checking this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | */ |
Steve French | 268875b | 2009-06-25 00:29:21 +0000 | [diff] [blame] | 682 | if ((tcon->need_reconnect) || (tcon->ses->need_reconnect)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 683 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 685 | rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 686 | (void **)&smb_buffer); |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 687 | if (rc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return rc; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 689 | |
| 690 | rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 692 | cFYI(1, "Tree disconnect failed %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 694 | /* No need to return error on this operation if tid invalidated and |
Jeff Layton | f1987b4 | 2008-11-15 11:12:47 -0500 | [diff] [blame] | 695 | closed on server already e.g. due to tcp session crashing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | if (rc == -EAGAIN) |
| 697 | rc = 0; |
| 698 | |
| 699 | return rc; |
| 700 | } |
| 701 | |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 702 | /* |
| 703 | * This is a no-op for now. We're not really interested in the reply, but |
| 704 | * rather in the fact that the server sent one and that server->lstrp |
| 705 | * gets updated. |
| 706 | * |
| 707 | * FIXME: maybe we should consider checking that the reply matches request? |
| 708 | */ |
| 709 | static void |
| 710 | cifs_echo_callback(struct mid_q_entry *mid) |
| 711 | { |
| 712 | struct TCP_Server_Info *server = mid->callback_data; |
| 713 | |
| 714 | DeleteMidQEntry(mid); |
| 715 | atomic_dec(&server->inFlight); |
| 716 | wake_up(&server->request_q); |
| 717 | } |
| 718 | |
| 719 | int |
| 720 | CIFSSMBEcho(struct TCP_Server_Info *server) |
| 721 | { |
| 722 | ECHO_REQ *smb; |
| 723 | int rc = 0; |
| 724 | |
| 725 | cFYI(1, "In echo request"); |
| 726 | |
| 727 | rc = small_smb_init(SMB_COM_ECHO, 0, NULL, (void **)&smb); |
| 728 | if (rc) |
| 729 | return rc; |
| 730 | |
| 731 | /* set up echo request */ |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 732 | smb->hdr.Tid = 0xffff; |
Jeff Layton | 99d86c8 | 2011-01-20 21:19:25 -0500 | [diff] [blame] | 733 | smb->hdr.WordCount = 1; |
| 734 | put_unaligned_le16(1, &smb->EchoCount); |
| 735 | put_bcc_le(1, &smb->hdr); |
Jeff Layton | 766fdbb | 2011-01-11 07:24:21 -0500 | [diff] [blame] | 736 | smb->Data[0] = 'a'; |
| 737 | smb->hdr.smb_buf_length += 3; |
| 738 | |
| 739 | rc = cifs_call_async(server, (struct smb_hdr *)smb, |
| 740 | cifs_echo_callback, server); |
| 741 | if (rc) |
| 742 | cFYI(1, "Echo request failed: %d", rc); |
| 743 | |
| 744 | cifs_small_buf_release(smb); |
| 745 | |
| 746 | return rc; |
| 747 | } |
| 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | int |
| 750 | CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses) |
| 751 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | LOGOFF_ANDX_REQ *pSMB; |
| 753 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 755 | cFYI(1, "In SMBLogoff for session disconnect"); |
Jeff Layton | 14fbf50 | 2008-11-14 13:53:46 -0500 | [diff] [blame] | 756 | |
| 757 | /* |
| 758 | * BB: do we need to check validity of ses and server? They should |
| 759 | * always be valid since we have an active reference. If not, that |
| 760 | * should probably be a BUG() |
| 761 | */ |
| 762 | if (!ses || !ses->server) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | return -EIO; |
| 764 | |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 765 | mutex_lock(&ses->session_mutex); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 766 | if (ses->need_reconnect) |
| 767 | goto session_already_dead; /* no need to send SMBlogoff if uid |
| 768 | already closed due to reconnect */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | rc = small_smb_init(SMB_COM_LOGOFF_ANDX, 2, NULL, (void **)&pSMB); |
| 770 | if (rc) { |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 771 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | return rc; |
| 773 | } |
| 774 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 775 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 776 | |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 777 | if (ses->server->secMode & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 779 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
| 781 | pSMB->hdr.Uid = ses->Suid; |
| 782 | |
| 783 | pSMB->AndXCommand = 0xFF; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 784 | rc = SendReceiveNoRsp(xid, ses, (struct smb_hdr *) pSMB, 0); |
Steve French | 3b79521 | 2008-11-13 19:45:32 +0000 | [diff] [blame] | 785 | session_already_dead: |
Steve French | d7b619c | 2010-02-25 05:36:46 +0000 | [diff] [blame] | 786 | mutex_unlock(&ses->session_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | /* if session dead then we do not need to do ulogoff, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 789 | since server closed smb session, no sense reporting |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | error */ |
| 791 | if (rc == -EAGAIN) |
| 792 | rc = 0; |
| 793 | return rc; |
| 794 | } |
| 795 | |
| 796 | int |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 797 | CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 798 | __u16 type, const struct nls_table *nls_codepage, int remap) |
| 799 | { |
| 800 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 801 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 802 | struct unlink_psx_rq *pRqD; |
| 803 | int name_len; |
| 804 | int rc = 0; |
| 805 | int bytes_returned = 0; |
| 806 | __u16 params, param_offset, offset, byte_count; |
| 807 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 808 | cFYI(1, "In POSIX delete"); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 809 | PsxDelete: |
| 810 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 811 | (void **) &pSMBr); |
| 812 | if (rc) |
| 813 | return rc; |
| 814 | |
| 815 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 816 | name_len = |
| 817 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
| 818 | PATH_MAX, nls_codepage, remap); |
| 819 | name_len++; /* trailing null */ |
| 820 | name_len *= 2; |
| 821 | } else { /* BB add path length overrun check */ |
| 822 | name_len = strnlen(fileName, PATH_MAX); |
| 823 | name_len++; /* trailing null */ |
| 824 | strncpy(pSMB->FileName, fileName, name_len); |
| 825 | } |
| 826 | |
| 827 | params = 6 + name_len; |
| 828 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 829 | pSMB->MaxDataCount = 0; /* BB double check this with jra */ |
| 830 | pSMB->MaxSetupCount = 0; |
| 831 | pSMB->Reserved = 0; |
| 832 | pSMB->Flags = 0; |
| 833 | pSMB->Timeout = 0; |
| 834 | pSMB->Reserved2 = 0; |
| 835 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
| 836 | InformationLevel) - 4; |
| 837 | offset = param_offset + params; |
| 838 | |
| 839 | /* Setup pointer to Request Data (inode type) */ |
| 840 | pRqD = (struct unlink_psx_rq *)(((char *)&pSMB->hdr.Protocol) + offset); |
| 841 | pRqD->type = cpu_to_le16(type); |
| 842 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 843 | pSMB->DataOffset = cpu_to_le16(offset); |
| 844 | pSMB->SetupCount = 1; |
| 845 | pSMB->Reserved3 = 0; |
| 846 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 847 | byte_count = 3 /* pad */ + params + sizeof(struct unlink_psx_rq); |
| 848 | |
| 849 | pSMB->DataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 850 | pSMB->TotalDataCount = cpu_to_le16(sizeof(struct unlink_psx_rq)); |
| 851 | pSMB->ParameterCount = cpu_to_le16(params); |
| 852 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 853 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_UNLINK); |
| 854 | pSMB->Reserved4 = 0; |
| 855 | pSMB->hdr.smb_buf_length += byte_count; |
| 856 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 857 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 858 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 859 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 860 | cFYI(1, "Posix delete returned %d", rc); |
Steve French | 2d785a5 | 2007-07-15 01:48:57 +0000 | [diff] [blame] | 861 | cifs_buf_release(pSMB); |
| 862 | |
| 863 | cifs_stats_inc(&tcon->num_deletes); |
| 864 | |
| 865 | if (rc == -EAGAIN) |
| 866 | goto PsxDelete; |
| 867 | |
| 868 | return rc; |
| 869 | } |
| 870 | |
| 871 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 872 | CIFSSMBDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
| 873 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
| 875 | DELETE_FILE_REQ *pSMB = NULL; |
| 876 | DELETE_FILE_RSP *pSMBr = NULL; |
| 877 | int rc = 0; |
| 878 | int bytes_returned; |
| 879 | int name_len; |
| 880 | |
| 881 | DelFileRetry: |
| 882 | rc = smb_init(SMB_COM_DELETE, 1, tcon, (void **) &pSMB, |
| 883 | (void **) &pSMBr); |
| 884 | if (rc) |
| 885 | return rc; |
| 886 | |
| 887 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 888 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 889 | cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 890 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | name_len++; /* trailing null */ |
| 892 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 893 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | name_len = strnlen(fileName, PATH_MAX); |
| 895 | name_len++; /* trailing null */ |
| 896 | strncpy(pSMB->fileName, fileName, name_len); |
| 897 | } |
| 898 | pSMB->SearchAttributes = |
| 899 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM); |
| 900 | pSMB->BufferFormat = 0x04; |
| 901 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 902 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 903 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 904 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 905 | cifs_stats_inc(&tcon->num_deletes); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 906 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 907 | cFYI(1, "Error in RMFile = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
| 909 | cifs_buf_release(pSMB); |
| 910 | if (rc == -EAGAIN) |
| 911 | goto DelFileRetry; |
| 912 | |
| 913 | return rc; |
| 914 | } |
| 915 | |
| 916 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 917 | CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 918 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | { |
| 920 | DELETE_DIRECTORY_REQ *pSMB = NULL; |
| 921 | DELETE_DIRECTORY_RSP *pSMBr = NULL; |
| 922 | int rc = 0; |
| 923 | int bytes_returned; |
| 924 | int name_len; |
| 925 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 926 | cFYI(1, "In CIFSSMBRmDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | RmDirRetry: |
| 928 | rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 929 | (void **) &pSMBr); |
| 930 | if (rc) |
| 931 | return rc; |
| 932 | |
| 933 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 934 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, dirName, |
| 935 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | name_len++; /* trailing null */ |
| 937 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 938 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | name_len = strnlen(dirName, PATH_MAX); |
| 940 | name_len++; /* trailing null */ |
| 941 | strncpy(pSMB->DirName, dirName, name_len); |
| 942 | } |
| 943 | |
| 944 | pSMB->BufferFormat = 0x04; |
| 945 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 946 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 947 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 948 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 949 | cifs_stats_inc(&tcon->num_rmdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 950 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 951 | cFYI(1, "Error in RMDir = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
| 953 | cifs_buf_release(pSMB); |
| 954 | if (rc == -EAGAIN) |
| 955 | goto RmDirRetry; |
| 956 | return rc; |
| 957 | } |
| 958 | |
| 959 | int |
| 960 | CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 961 | const char *name, const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | { |
| 963 | int rc = 0; |
| 964 | CREATE_DIRECTORY_REQ *pSMB = NULL; |
| 965 | CREATE_DIRECTORY_RSP *pSMBr = NULL; |
| 966 | int bytes_returned; |
| 967 | int name_len; |
| 968 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 969 | cFYI(1, "In CIFSSMBMkDir"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | MkDirRetry: |
| 971 | rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB, |
| 972 | (void **) &pSMBr); |
| 973 | if (rc) |
| 974 | return rc; |
| 975 | |
| 976 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 977 | name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 978 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | name_len++; /* trailing null */ |
| 980 | name_len *= 2; |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 981 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | name_len = strnlen(name, PATH_MAX); |
| 983 | name_len++; /* trailing null */ |
| 984 | strncpy(pSMB->DirName, name, name_len); |
| 985 | } |
| 986 | |
| 987 | pSMB->BufferFormat = 0x04; |
| 988 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 989 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 990 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 991 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 992 | cifs_stats_inc(&tcon->num_mkdirs); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 993 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 994 | cFYI(1, "Error in Mkdir = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | cifs_buf_release(pSMB); |
| 997 | if (rc == -EAGAIN) |
| 998 | goto MkDirRetry; |
| 999 | return rc; |
| 1000 | } |
| 1001 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1002 | int |
| 1003 | CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1004 | __u64 mode, __u16 *netfid, FILE_UNIX_BASIC_INFO *pRetData, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1005 | __u32 *pOplock, const char *name, |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1006 | const struct nls_table *nls_codepage, int remap) |
| 1007 | { |
| 1008 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 1009 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 1010 | int name_len; |
| 1011 | int rc = 0; |
| 1012 | int bytes_returned = 0; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1013 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1014 | OPEN_PSX_REQ *pdata; |
| 1015 | OPEN_PSX_RSP *psx_rsp; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1016 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1017 | cFYI(1, "In POSIX Create"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1018 | PsxCreat: |
| 1019 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 1020 | (void **) &pSMBr); |
| 1021 | if (rc) |
| 1022 | return rc; |
| 1023 | |
| 1024 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1025 | name_len = |
| 1026 | cifsConvertToUCS((__le16 *) pSMB->FileName, name, |
| 1027 | PATH_MAX, nls_codepage, remap); |
| 1028 | name_len++; /* trailing null */ |
| 1029 | name_len *= 2; |
| 1030 | } else { /* BB improve the check for buffer overruns BB */ |
| 1031 | name_len = strnlen(name, PATH_MAX); |
| 1032 | name_len++; /* trailing null */ |
| 1033 | strncpy(pSMB->FileName, name, name_len); |
| 1034 | } |
| 1035 | |
| 1036 | params = 6 + name_len; |
| 1037 | count = sizeof(OPEN_PSX_REQ); |
| 1038 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 1039 | pSMB->MaxDataCount = cpu_to_le16(1000); /* large enough */ |
| 1040 | pSMB->MaxSetupCount = 0; |
| 1041 | pSMB->Reserved = 0; |
| 1042 | pSMB->Flags = 0; |
| 1043 | pSMB->Timeout = 0; |
| 1044 | pSMB->Reserved2 = 0; |
| 1045 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1046 | InformationLevel) - 4; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1047 | offset = param_offset + params; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1048 | pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1049 | pdata->Level = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1050 | pdata->Permissions = cpu_to_le64(mode); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1051 | pdata->PosixOpenFlags = cpu_to_le32(posix_flags); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1052 | pdata->OpenFlags = cpu_to_le32(*pOplock); |
| 1053 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 1054 | pSMB->DataOffset = cpu_to_le16(offset); |
| 1055 | pSMB->SetupCount = 1; |
| 1056 | pSMB->Reserved3 = 0; |
| 1057 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 1058 | byte_count = 3 /* pad */ + params + count; |
| 1059 | |
| 1060 | pSMB->DataCount = cpu_to_le16(count); |
| 1061 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1062 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1063 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1064 | pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); |
| 1065 | pSMB->Reserved4 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1066 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1067 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 1068 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1069 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 1070 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1071 | cFYI(1, "Posix create returned %d", rc); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1072 | goto psx_create_err; |
| 1073 | } |
| 1074 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1075 | cFYI(1, "copying inode info"); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1076 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 1077 | |
| 1078 | if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) { |
| 1079 | rc = -EIO; /* bad smb */ |
| 1080 | goto psx_create_err; |
| 1081 | } |
| 1082 | |
| 1083 | /* copy return information to pRetData */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1084 | psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1085 | + le16_to_cpu(pSMBr->t2.DataOffset)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1086 | |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1087 | *pOplock = le16_to_cpu(psx_rsp->OplockFlags); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1088 | if (netfid) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1089 | *netfid = psx_rsp->Fid; /* cifs fid stays in le */ |
| 1090 | /* Let caller know file was created so we can set the mode. */ |
| 1091 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1092 | if (cpu_to_le32(FILE_CREATE) == psx_rsp->CreateAction) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1093 | *pOplock |= CIFS_CREATE_ACTION; |
| 1094 | /* check to make sure response data is there */ |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1095 | if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) { |
| 1096 | pRetData->Type = cpu_to_le32(-1); /* unknown */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1097 | cFYI(DBG2, "unknown type"); |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1098 | } else { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1099 | if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1100 | + sizeof(FILE_UNIX_BASIC_INFO)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1101 | cERROR(1, "Open response data too small"); |
Cyril Gorcunov | 8f2376a | 2007-10-14 17:58:43 +0000 | [diff] [blame] | 1102 | pRetData->Type = cpu_to_le32(-1); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1103 | goto psx_create_err; |
| 1104 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1105 | memcpy((char *) pRetData, |
Steve French | cbac3cb | 2007-04-25 11:46:06 +0000 | [diff] [blame] | 1106 | (char *)psx_rsp + sizeof(OPEN_PSX_RSP), |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1107 | sizeof(FILE_UNIX_BASIC_INFO)); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1108 | } |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1109 | |
| 1110 | psx_create_err: |
| 1111 | cifs_buf_release(pSMB); |
| 1112 | |
Steve French | 65bc98b | 2009-07-10 15:27:25 +0000 | [diff] [blame] | 1113 | if (posix_flags & SMB_O_DIRECTORY) |
| 1114 | cifs_stats_inc(&tcon->num_posixmkdirs); |
| 1115 | else |
| 1116 | cifs_stats_inc(&tcon->num_posixopens); |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1117 | |
| 1118 | if (rc == -EAGAIN) |
| 1119 | goto PsxCreat; |
| 1120 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1121 | return rc; |
Steve French | 2dd29d3 | 2007-04-23 22:07:35 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1124 | static __u16 convert_disposition(int disposition) |
| 1125 | { |
| 1126 | __u16 ofun = 0; |
| 1127 | |
| 1128 | switch (disposition) { |
| 1129 | case FILE_SUPERSEDE: |
| 1130 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1131 | break; |
| 1132 | case FILE_OPEN: |
| 1133 | ofun = SMBOPEN_OAPPEND; |
| 1134 | break; |
| 1135 | case FILE_CREATE: |
| 1136 | ofun = SMBOPEN_OCREATE; |
| 1137 | break; |
| 1138 | case FILE_OPEN_IF: |
| 1139 | ofun = SMBOPEN_OCREATE | SMBOPEN_OAPPEND; |
| 1140 | break; |
| 1141 | case FILE_OVERWRITE: |
| 1142 | ofun = SMBOPEN_OTRUNC; |
| 1143 | break; |
| 1144 | case FILE_OVERWRITE_IF: |
| 1145 | ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC; |
| 1146 | break; |
| 1147 | default: |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1148 | cFYI(1, "unknown disposition %d", disposition); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1149 | ofun = SMBOPEN_OAPPEND; /* regular open */ |
| 1150 | } |
| 1151 | return ofun; |
| 1152 | } |
| 1153 | |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1154 | static int |
| 1155 | access_flags_to_smbopen_mode(const int access_flags) |
| 1156 | { |
| 1157 | int masked_flags = access_flags & (GENERIC_READ | GENERIC_WRITE); |
| 1158 | |
| 1159 | if (masked_flags == GENERIC_READ) |
| 1160 | return SMBOPEN_READ; |
| 1161 | else if (masked_flags == GENERIC_WRITE) |
| 1162 | return SMBOPEN_WRITE; |
| 1163 | |
| 1164 | /* just go for read/write */ |
| 1165 | return SMBOPEN_READWRITE; |
| 1166 | } |
| 1167 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1168 | int |
| 1169 | SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, |
| 1170 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1171 | const int access_flags, const int create_options, __u16 *netfid, |
| 1172 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1173 | const struct nls_table *nls_codepage, int remap) |
| 1174 | { |
| 1175 | int rc = -EACCES; |
| 1176 | OPENX_REQ *pSMB = NULL; |
| 1177 | OPENX_RSP *pSMBr = NULL; |
| 1178 | int bytes_returned; |
| 1179 | int name_len; |
| 1180 | __u16 count; |
| 1181 | |
| 1182 | OldOpenRetry: |
| 1183 | rc = smb_init(SMB_COM_OPEN_ANDX, 15, tcon, (void **) &pSMB, |
| 1184 | (void **) &pSMBr); |
| 1185 | if (rc) |
| 1186 | return rc; |
| 1187 | |
| 1188 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1189 | |
| 1190 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1191 | count = 1; /* account for one byte pad to word boundary */ |
| 1192 | name_len = |
| 1193 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
| 1194 | fileName, PATH_MAX, nls_codepage, remap); |
| 1195 | name_len++; /* trailing null */ |
| 1196 | name_len *= 2; |
| 1197 | } else { /* BB improve check for buffer overruns BB */ |
| 1198 | count = 0; /* no pad */ |
| 1199 | name_len = strnlen(fileName, PATH_MAX); |
| 1200 | name_len++; /* trailing null */ |
| 1201 | strncpy(pSMB->fileName, fileName, name_len); |
| 1202 | } |
| 1203 | if (*pOplock & REQ_OPLOCK) |
| 1204 | pSMB->OpenFlags = cpu_to_le16(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1205 | else if (*pOplock & REQ_BATCHOPLOCK) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1206 | pSMB->OpenFlags = cpu_to_le16(REQ_BATCHOPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1207 | |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1208 | pSMB->OpenFlags |= cpu_to_le16(REQ_MORE_INFO); |
Jeff Layton | 35fc37d | 2008-05-14 10:22:03 -0700 | [diff] [blame] | 1209 | pSMB->Mode = cpu_to_le16(access_flags_to_smbopen_mode(access_flags)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1210 | pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ |
| 1211 | /* set file as system file if special file such |
| 1212 | as fifo and server expecting SFU style and |
| 1213 | no Unix extensions */ |
| 1214 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1215 | if (create_options & CREATE_OPTION_SPECIAL) |
| 1216 | pSMB->FileAttributes = cpu_to_le16(ATTR_SYSTEM); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1217 | else /* BB FIXME BB */ |
| 1218 | pSMB->FileAttributes = cpu_to_le16(0/*ATTR_NORMAL*/); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1219 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1220 | if (create_options & CREATE_OPTION_READONLY) |
| 1221 | pSMB->FileAttributes |= cpu_to_le16(ATTR_READONLY); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1222 | |
| 1223 | /* BB FIXME BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1224 | /* pSMB->CreateOptions = cpu_to_le32(create_options & |
| 1225 | CREATE_OPTIONS_MASK); */ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1226 | /* BB FIXME END BB */ |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 1227 | |
| 1228 | pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1229 | pSMB->OpenFunction = cpu_to_le16(convert_disposition(openDisposition)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1230 | count += name_len; |
| 1231 | pSMB->hdr.smb_buf_length += count; |
| 1232 | |
| 1233 | pSMB->ByteCount = cpu_to_le16(count); |
| 1234 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1235 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1236 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1237 | cifs_stats_inc(&tcon->num_opens); |
| 1238 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1239 | cFYI(1, "Error in Open = %d", rc); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1240 | } else { |
| 1241 | /* BB verify if wct == 15 */ |
| 1242 | |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1243 | /* *pOplock = pSMBr->OplockLevel; */ /* BB take from action field*/ |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1244 | |
| 1245 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1246 | /* Let caller know file was created so we can set the mode. */ |
| 1247 | /* Do we care about the CreateAction in any other cases? */ |
| 1248 | /* BB FIXME BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1249 | /* if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1250 | *pOplock |= CIFS_CREATE_ACTION; */ |
| 1251 | /* BB FIXME END */ |
| 1252 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1253 | if (pfile_info) { |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1254 | pfile_info->CreationTime = 0; /* BB convert CreateTime*/ |
| 1255 | pfile_info->LastAccessTime = 0; /* BB fixme */ |
| 1256 | pfile_info->LastWriteTime = 0; /* BB fixme */ |
| 1257 | pfile_info->ChangeTime = 0; /* BB fixme */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1258 | pfile_info->Attributes = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1259 | cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1260 | /* the file_info buf is endian converted by caller */ |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 1261 | pfile_info->AllocationSize = |
| 1262 | cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); |
| 1263 | pfile_info->EndOfFile = pfile_info->AllocationSize; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1264 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
Jeff Layton | 9a8165f | 2008-10-17 21:03:20 -0400 | [diff] [blame] | 1265 | pfile_info->DeletePending = 0; |
Steve French | a9d02ad | 2005-08-24 23:06:05 -0700 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | |
| 1269 | cifs_buf_release(pSMB); |
| 1270 | if (rc == -EAGAIN) |
| 1271 | goto OldOpenRetry; |
| 1272 | return rc; |
| 1273 | } |
| 1274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | int |
| 1276 | CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, |
| 1277 | const char *fileName, const int openDisposition, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1278 | const int access_flags, const int create_options, __u16 *netfid, |
| 1279 | int *pOplock, FILE_ALL_INFO *pfile_info, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1280 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | { |
| 1282 | int rc = -EACCES; |
| 1283 | OPEN_REQ *pSMB = NULL; |
| 1284 | OPEN_RSP *pSMBr = NULL; |
| 1285 | int bytes_returned; |
| 1286 | int name_len; |
| 1287 | __u16 count; |
| 1288 | |
| 1289 | openRetry: |
| 1290 | rc = smb_init(SMB_COM_NT_CREATE_ANDX, 24, tcon, (void **) &pSMB, |
| 1291 | (void **) &pSMBr); |
| 1292 | if (rc) |
| 1293 | return rc; |
| 1294 | |
| 1295 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1296 | |
| 1297 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1298 | count = 1; /* account for one byte pad to word boundary */ |
| 1299 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 1300 | cifsConvertToUCS((__le16 *) (pSMB->fileName + 1), |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1301 | fileName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | name_len++; /* trailing null */ |
| 1303 | name_len *= 2; |
| 1304 | pSMB->NameLength = cpu_to_le16(name_len); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1305 | } else { /* BB improve check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | count = 0; /* no pad */ |
| 1307 | name_len = strnlen(fileName, PATH_MAX); |
| 1308 | name_len++; /* trailing null */ |
| 1309 | pSMB->NameLength = cpu_to_le16(name_len); |
| 1310 | strncpy(pSMB->fileName, fileName, name_len); |
| 1311 | } |
| 1312 | if (*pOplock & REQ_OPLOCK) |
| 1313 | pSMB->OpenFlags = cpu_to_le32(REQ_OPLOCK); |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1314 | else if (*pOplock & REQ_BATCHOPLOCK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | pSMB->OpenFlags = cpu_to_le32(REQ_BATCHOPLOCK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | pSMB->DesiredAccess = cpu_to_le32(access_flags); |
| 1317 | pSMB->AllocationSize = 0; |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1318 | /* set file as system file if special file such |
| 1319 | as fifo and server expecting SFU style and |
| 1320 | no Unix extensions */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1321 | if (create_options & CREATE_OPTION_SPECIAL) |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1322 | pSMB->FileAttributes = cpu_to_le32(ATTR_SYSTEM); |
| 1323 | else |
| 1324 | pSMB->FileAttributes = cpu_to_le32(ATTR_NORMAL); |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | /* XP does not handle ATTR_POSIX_SEMANTICS */ |
| 1327 | /* but it helps speed up case sensitive checks for other |
| 1328 | servers such as Samba */ |
| 1329 | if (tcon->ses->capabilities & CAP_UNIX) |
| 1330 | pSMB->FileAttributes |= cpu_to_le32(ATTR_POSIX_SEMANTICS); |
| 1331 | |
Jeff Layton | 67750fb | 2008-05-09 22:28:02 +0000 | [diff] [blame] | 1332 | if (create_options & CREATE_OPTION_READONLY) |
| 1333 | pSMB->FileAttributes |= cpu_to_le32(ATTR_READONLY); |
| 1334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | pSMB->ShareAccess = cpu_to_le32(FILE_SHARE_ALL); |
| 1336 | pSMB->CreateDisposition = cpu_to_le32(openDisposition); |
Steve French | eda3c029 | 2005-07-21 15:20:28 -0700 | [diff] [blame] | 1337 | pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1338 | /* BB Expirement with various impersonation levels and verify */ |
| 1339 | pSMB->ImpersonationLevel = cpu_to_le32(SECURITY_IMPERSONATION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | pSMB->SecurityFlags = |
| 1341 | SECURITY_CONTEXT_TRACKING | SECURITY_EFFECTIVE_ONLY; |
| 1342 | |
| 1343 | count += name_len; |
| 1344 | pSMB->hdr.smb_buf_length += count; |
| 1345 | |
| 1346 | pSMB->ByteCount = cpu_to_le16(count); |
| 1347 | /* long_op set to 1 to allow for oplock break timeouts */ |
| 1348 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1349 | (struct smb_hdr *)pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1350 | cifs_stats_inc(&tcon->num_opens); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1352 | cFYI(1, "Error in Open = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | } else { |
Steve French | 09d1db5 | 2005-04-28 22:41:08 -0700 | [diff] [blame] | 1354 | *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | *netfid = pSMBr->Fid; /* cifs fid stays in le */ |
| 1356 | /* Let caller know file was created so we can set the mode. */ |
| 1357 | /* Do we care about the CreateAction in any other cases? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1358 | if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1359 | *pOplock |= CIFS_CREATE_ACTION; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1360 | if (pfile_info) { |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1361 | memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime, |
| 1362 | 36 /* CreationTime to Attributes */); |
| 1363 | /* the file_info buf is endian converted by caller */ |
| 1364 | pfile_info->AllocationSize = pSMBr->AllocationSize; |
| 1365 | pfile_info->EndOfFile = pSMBr->EndOfFile; |
| 1366 | pfile_info->NumberOfLinks = cpu_to_le32(1); |
| 1367 | pfile_info->DeletePending = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | } |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 1370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | cifs_buf_release(pSMB); |
| 1372 | if (rc == -EAGAIN) |
| 1373 | goto openRetry; |
| 1374 | return rc; |
| 1375 | } |
| 1376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1378 | CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid, |
| 1379 | const unsigned int count, const __u64 lseek, unsigned int *nbytes, |
| 1380 | char **buf, int *pbuf_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | { |
| 1382 | int rc = -EACCES; |
| 1383 | READ_REQ *pSMB = NULL; |
| 1384 | READ_RSP *pSMBr = NULL; |
| 1385 | char *pReadData = NULL; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1386 | int wct; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1387 | int resp_buf_type = 0; |
| 1388 | struct kvec iov[1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1390 | cFYI(1, "Reading %d bytes on fid %d", count, netfid); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1391 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1392 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1393 | else { |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1394 | wct = 10; /* old style read */ |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1395 | if ((lseek >> 32) > 0) { |
| 1396 | /* can not handle this big offset for old */ |
| 1397 | return -EIO; |
| 1398 | } |
| 1399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
| 1401 | *nbytes = 0; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1402 | rc = small_smb_init(SMB_COM_READ_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | if (rc) |
| 1404 | return rc; |
| 1405 | |
| 1406 | /* tcon and ses pointer are checked in smb_init */ |
| 1407 | if (tcon->ses->server == NULL) |
| 1408 | return -ECONNABORTED; |
| 1409 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1410 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | pSMB->Fid = netfid; |
| 1412 | pSMB->OffsetLow = cpu_to_le32(lseek & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1413 | if (wct == 12) |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1414 | pSMB->OffsetHigh = cpu_to_le32(lseek >> 32); |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | pSMB->Remaining = 0; |
| 1417 | pSMB->MaxCount = cpu_to_le16(count & 0xFFFF); |
| 1418 | pSMB->MaxCountHigh = cpu_to_le32(count >> 16); |
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->ByteCount = 0; /* no need to do le conversion since 0 */ |
| 1421 | else { |
| 1422 | /* old style read */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1423 | struct smb_com_readx_req *pSMBW = |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1424 | (struct smb_com_readx_req *)pSMB; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1425 | pSMBW->ByteCount = 0; |
Steve French | bfa0d75 | 2005-08-31 21:50:37 -0700 | [diff] [blame] | 1426 | } |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1427 | |
| 1428 | iov[0].iov_base = (char *)pSMB; |
| 1429 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 1430 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 1431 | &resp_buf_type, CIFS_LOG_ERROR); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1432 | cifs_stats_inc(&tcon->num_reads); |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1433 | pSMBr = (READ_RSP *)iov[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1435 | cERROR(1, "Send error in read = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } else { |
| 1437 | int data_length = le16_to_cpu(pSMBr->DataLengthHigh); |
| 1438 | data_length = data_length << 16; |
| 1439 | data_length += le16_to_cpu(pSMBr->DataLength); |
| 1440 | *nbytes = data_length; |
| 1441 | |
| 1442 | /*check that DataLength would not go beyond end of SMB */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1443 | if ((data_length > CIFSMaxBufSize) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | || (data_length > count)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1445 | cFYI(1, "bad length %d for count %d", |
| 1446 | data_length, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | rc = -EIO; |
| 1448 | *nbytes = 0; |
| 1449 | } else { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1450 | pReadData = (char *) (&pSMBr->hdr.Protocol) + |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1451 | le16_to_cpu(pSMBr->DataOffset); |
| 1452 | /* if (rc = copy_to_user(buf, pReadData, data_length)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1453 | cERROR(1, "Faulting on read rc = %d",rc); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1454 | rc = -EFAULT; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 1455 | }*/ /* can not use copy_to_user when using page cache*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1456 | if (*buf) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1457 | memcpy(*buf, pReadData, data_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | } |
| 1459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1461 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1462 | if (*buf) { |
| 1463 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1464 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1465 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1466 | cifs_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1467 | } else if (resp_buf_type != CIFS_NO_BUFFER) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1468 | /* return buffer to caller to free */ |
| 1469 | *buf = iov[0].iov_base; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1470 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1471 | *pbuf_type = CIFS_SMALL_BUFFER; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1472 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1473 | *pbuf_type = CIFS_LARGE_BUFFER; |
Steve French | 6cec2ae | 2006-02-22 17:31:52 -0600 | [diff] [blame] | 1474 | } /* else no valid buffer on return - leave as null */ |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1475 | |
| 1476 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | since file handle passed in no longer valid */ |
| 1478 | return rc; |
| 1479 | } |
| 1480 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | int |
| 1483 | CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, |
| 1484 | const int netfid, const unsigned int count, |
| 1485 | const __u64 offset, unsigned int *nbytes, const char *buf, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1486 | const char __user *ubuf, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | { |
| 1488 | int rc = -EACCES; |
| 1489 | WRITE_REQ *pSMB = NULL; |
| 1490 | WRITE_RSP *pSMBr = NULL; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1491 | int bytes_returned, wct; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | __u32 bytes_sent; |
| 1493 | __u16 byte_count; |
| 1494 | |
Steve French | a24e2d7 | 2010-04-03 17:20:21 +0000 | [diff] [blame] | 1495 | *nbytes = 0; |
| 1496 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1497 | /* cFYI(1, "write at %lld %d bytes", offset, count);*/ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1498 | if (tcon->ses == NULL) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1499 | return -ECONNABORTED; |
| 1500 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1501 | if (tcon->ses->capabilities & CAP_LARGE_FILES) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1502 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1503 | else { |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1504 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1505 | if ((offset >> 32) > 0) { |
| 1506 | /* can not handle big offset for old srv */ |
| 1507 | return -EIO; |
| 1508 | } |
| 1509 | } |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1510 | |
| 1511 | rc = smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | (void **) &pSMBr); |
| 1513 | if (rc) |
| 1514 | return rc; |
| 1515 | /* tcon and ses pointer are checked in smb_init */ |
| 1516 | if (tcon->ses->server == NULL) |
| 1517 | return -ECONNABORTED; |
| 1518 | |
| 1519 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1520 | pSMB->Fid = netfid; |
| 1521 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1522 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1523 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | pSMB->Reserved = 0xFFFFFFFF; |
| 1526 | pSMB->WriteMode = 0; |
| 1527 | pSMB->Remaining = 0; |
| 1528 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1529 | /* 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] | 1530 | can send more if LARGE_WRITE_X capability returned by the server and if |
| 1531 | our buffer is big enough or if we convert to iovecs on socket writes |
| 1532 | and eliminate the copy to the CIFS buffer */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1533 | if (tcon->ses->capabilities & CAP_LARGE_WRITE_X) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | bytes_sent = min_t(const unsigned int, CIFSMaxBufSize, count); |
| 1535 | } else { |
| 1536 | bytes_sent = (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) |
| 1537 | & ~0xFF; |
| 1538 | } |
| 1539 | |
| 1540 | if (bytes_sent > count) |
| 1541 | bytes_sent = count; |
| 1542 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1543 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1544 | if (buf) |
Steve French | 61e7480 | 2008-12-03 00:57:54 +0000 | [diff] [blame] | 1545 | memcpy(pSMB->Data, buf, bytes_sent); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1546 | else if (ubuf) { |
| 1547 | if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | cifs_buf_release(pSMB); |
| 1549 | return -EFAULT; |
| 1550 | } |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1551 | } else if (count != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | /* No buffer */ |
| 1553 | cifs_buf_release(pSMB); |
| 1554 | return -EINVAL; |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1555 | } /* else setting file size with write of zero bytes */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1556 | if (wct == 14) |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1557 | byte_count = bytes_sent + 1; /* pad */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1558 | else /* wct == 12 */ |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1559 | byte_count = bytes_sent + 5; /* bigger pad, smaller smb hdr */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | pSMB->DataLengthLow = cpu_to_le16(bytes_sent & 0xFFFF); |
| 1562 | pSMB->DataLengthHigh = cpu_to_le16(bytes_sent >> 16); |
Steve French | e30dcf3 | 2005-09-20 20:49:16 -0700 | [diff] [blame] | 1563 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1564 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1565 | if (wct == 14) |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1566 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1567 | else { /* old style write has byte count 4 bytes earlier |
| 1568 | so 4 bytes pad */ |
| 1569 | struct smb_com_writex_req *pSMBW = |
Steve French | 1c95518 | 2005-08-30 20:58:07 -0700 | [diff] [blame] | 1570 | (struct smb_com_writex_req *)pSMB; |
| 1571 | pSMBW->ByteCount = cpu_to_le16(byte_count); |
| 1572 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
| 1574 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 1575 | (struct smb_hdr *) pSMBr, &bytes_returned, long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1576 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 1578 | cFYI(1, "Send error in write = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | } else { |
| 1580 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1581 | *nbytes = (*nbytes) << 16; |
| 1582 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1583 | |
| 1584 | /* |
| 1585 | * Mask off high 16 bits when bytes written as returned by the |
| 1586 | * server is greater than bytes requested by the client. Some |
| 1587 | * OS/2 servers are known to set incorrect CountHigh values. |
| 1588 | */ |
| 1589 | if (*nbytes > count) |
| 1590 | *nbytes &= 0xFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | cifs_buf_release(pSMB); |
| 1594 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1595 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | since file handle passed in no longer valid */ |
| 1597 | |
| 1598 | return rc; |
| 1599 | } |
| 1600 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1601 | int |
| 1602 | CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | const int netfid, const unsigned int count, |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1604 | const __u64 offset, unsigned int *nbytes, struct kvec *iov, |
| 1605 | int n_vec, const int long_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
| 1607 | int rc = -EACCES; |
| 1608 | WRITE_REQ *pSMB = NULL; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1609 | int wct; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1610 | int smb_hdr_len; |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1611 | int resp_buf_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | |
Jeff Layton | fbec9ab | 2009-04-03 13:44:00 -0400 | [diff] [blame] | 1613 | *nbytes = 0; |
| 1614 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1615 | cFYI(1, "write2 at %lld %d bytes", (long long)offset, count); |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 1616 | |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1617 | if (tcon->ses->capabilities & CAP_LARGE_FILES) { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1618 | wct = 14; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1619 | } else { |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1620 | wct = 12; |
Steve French | 4c3130e | 2008-12-09 00:28:16 +0000 | [diff] [blame] | 1621 | if ((offset >> 32) > 0) { |
| 1622 | /* can not handle big offset for old srv */ |
| 1623 | return -EIO; |
| 1624 | } |
| 1625 | } |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1626 | rc = small_smb_init(SMB_COM_WRITE_ANDX, wct, tcon, (void **) &pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | if (rc) |
| 1628 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | /* tcon and ses pointer are checked in smb_init */ |
| 1630 | if (tcon->ses->server == NULL) |
| 1631 | return -ECONNABORTED; |
| 1632 | |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1633 | pSMB->AndXCommand = 0xFF; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | pSMB->Fid = netfid; |
| 1635 | pSMB->OffsetLow = cpu_to_le32(offset & 0xFFFFFFFF); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1636 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1637 | pSMB->OffsetHigh = cpu_to_le32(offset >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | pSMB->Reserved = 0xFFFFFFFF; |
| 1639 | pSMB->WriteMode = 0; |
| 1640 | pSMB->Remaining = 0; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | pSMB->DataOffset = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1643 | cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1645 | pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); |
| 1646 | pSMB->DataLengthHigh = cpu_to_le16(count >> 16); |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1647 | smb_hdr_len = pSMB->hdr.smb_buf_length + 1; /* hdr + 1 byte pad */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1648 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1649 | pSMB->hdr.smb_buf_length += count+1; |
| 1650 | else /* wct == 12 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1651 | pSMB->hdr.smb_buf_length += count+5; /* smb data starts later */ |
| 1652 | if (wct == 14) |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1653 | pSMB->ByteCount = cpu_to_le16(count + 1); |
| 1654 | else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1655 | struct smb_com_writex_req *pSMBW = |
Steve French | 8cc64c6 | 2005-10-03 13:49:43 -0700 | [diff] [blame] | 1656 | (struct smb_com_writex_req *)pSMB; |
| 1657 | pSMBW->ByteCount = cpu_to_le16(count + 5); |
| 1658 | } |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1659 | iov[0].iov_base = pSMB; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1660 | if (wct == 14) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1661 | iov[0].iov_len = smb_hdr_len + 4; |
| 1662 | else /* wct == 12 pad bigger by four bytes */ |
| 1663 | iov[0].iov_len = smb_hdr_len + 8; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1664 | |
Steve French | 3e84469 | 2005-10-03 13:37:24 -0700 | [diff] [blame] | 1665 | |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1666 | rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1667 | long_op); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1668 | cifs_stats_inc(&tcon->num_writes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1670 | cFYI(1, "Send error Write2 = %d", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1671 | } else if (resp_buf_type == 0) { |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1672 | /* presumably this can not happen, but best to be safe */ |
| 1673 | rc = -EIO; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1674 | } else { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1675 | WRITE_RSP *pSMBr = (WRITE_RSP *)iov[0].iov_base; |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1676 | *nbytes = le16_to_cpu(pSMBr->CountHigh); |
| 1677 | *nbytes = (*nbytes) << 16; |
| 1678 | *nbytes += le16_to_cpu(pSMBr->Count); |
Suresh Jayaraman | 6513a81 | 2010-03-31 12:00:03 +0530 | [diff] [blame] | 1679 | |
| 1680 | /* |
| 1681 | * Mask off high 16 bits when bytes written as returned by the |
| 1682 | * server is greater than bytes requested by the client. OS/2 |
| 1683 | * servers are known to set incorrect CountHigh values. |
| 1684 | */ |
| 1685 | if (*nbytes > count) |
| 1686 | *nbytes &= 0xFFFF; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 1689 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1690 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1691 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1692 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
Steve French | ec637e3 | 2005-12-12 20:53:18 -0800 | [diff] [blame] | 1693 | cifs_buf_release(iov[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1695 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | since file handle passed in no longer valid */ |
| 1697 | |
| 1698 | return rc; |
| 1699 | } |
Steve French | d6e04ae | 2005-06-13 13:24:43 -0500 | [diff] [blame] | 1700 | |
| 1701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | int |
| 1703 | CIFSSMBLock(const int xid, struct cifsTconInfo *tcon, |
| 1704 | const __u16 smb_file_id, const __u64 len, |
| 1705 | const __u64 offset, const __u32 numUnlock, |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1706 | const __u32 numLock, const __u8 lockType, |
| 1707 | const bool waitFlag, const __u8 oplock_level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | { |
| 1709 | int rc = 0; |
| 1710 | LOCK_REQ *pSMB = NULL; |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1711 | /* LOCK_RSP *pSMBr = NULL; */ /* No response data other than rc to parse */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | int bytes_returned; |
| 1713 | int timeout = 0; |
| 1714 | __u16 count; |
| 1715 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1716 | cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock); |
Steve French | 46810cb | 2005-04-28 22:41:09 -0700 | [diff] [blame] | 1717 | rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); |
| 1718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | if (rc) |
| 1720 | return rc; |
| 1721 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1722 | if (lockType == LOCKING_ANDX_OPLOCK_RELEASE) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1723 | timeout = CIFS_ASYNC_OP; /* no response expected */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | pSMB->Timeout = 0; |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1725 | } else if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1726 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | pSMB->Timeout = cpu_to_le32(-1);/* blocking - do not time out */ |
| 1728 | } else { |
| 1729 | pSMB->Timeout = 0; |
| 1730 | } |
| 1731 | |
| 1732 | pSMB->NumberOfLocks = cpu_to_le16(numLock); |
| 1733 | pSMB->NumberOfUnlocks = cpu_to_le16(numUnlock); |
| 1734 | pSMB->LockType = lockType; |
Pavel Shilovsky | 12fed00 | 2011-01-17 20:15:44 +0300 | [diff] [blame] | 1735 | pSMB->OplockLevel = oplock_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | pSMB->AndXCommand = 0xFF; /* none */ |
| 1737 | pSMB->Fid = smb_file_id; /* netfid stays le */ |
| 1738 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1739 | if ((numLock != 0) || (numUnlock != 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | pSMB->Locks[0].Pid = cpu_to_le16(current->tgid); |
| 1741 | /* BB where to store pid high? */ |
| 1742 | pSMB->Locks[0].LengthLow = cpu_to_le32((u32)len); |
| 1743 | pSMB->Locks[0].LengthHigh = cpu_to_le32((u32)(len>>32)); |
| 1744 | pSMB->Locks[0].OffsetLow = cpu_to_le32((u32)offset); |
| 1745 | pSMB->Locks[0].OffsetHigh = cpu_to_le32((u32)(offset>>32)); |
| 1746 | count = sizeof(LOCKING_ANDX_RANGE); |
| 1747 | } else { |
| 1748 | /* oplock break */ |
| 1749 | count = 0; |
| 1750 | } |
| 1751 | pSMB->hdr.smb_buf_length += count; |
| 1752 | pSMB->ByteCount = cpu_to_le16(count); |
| 1753 | |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1754 | if (waitFlag) { |
| 1755 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
Steve French | aaa9bbe | 2008-05-23 17:38:32 +0000 | [diff] [blame] | 1756 | (struct smb_hdr *) pSMB, &bytes_returned); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1757 | cifs_small_buf_release(pSMB); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1758 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1759 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *)pSMB, |
| 1760 | timeout); |
| 1761 | /* SMB buffer freed by function above */ |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1762 | } |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1763 | cifs_stats_inc(&tcon->num_locks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1764 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1765 | cFYI(1, "Send error in Lock = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1767 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | since file handle passed in no longer valid */ |
| 1769 | return rc; |
| 1770 | } |
| 1771 | |
| 1772 | int |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1773 | CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, |
| 1774 | const __u16 smb_file_id, const int get_flag, const __u64 len, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1775 | struct file_lock *pLockData, const __u16 lock_type, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 1776 | const bool waitFlag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1777 | { |
| 1778 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 1779 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1780 | struct cifs_posix_lock *parm_data; |
| 1781 | int rc = 0; |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1782 | int timeout = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1783 | int bytes_returned = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1784 | int resp_buf_type = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1785 | __u16 params, param_offset, offset, byte_count, count; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1786 | struct kvec iov[1]; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1787 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1788 | cFYI(1, "Posix Lock"); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1789 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1790 | if (pLockData == NULL) |
Marcin Slusarz | ed5f037 | 2008-05-13 04:01:01 +0000 | [diff] [blame] | 1791 | return -EINVAL; |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1792 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1793 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 1794 | |
| 1795 | if (rc) |
| 1796 | return rc; |
| 1797 | |
| 1798 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; |
| 1799 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1800 | params = 6; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1801 | pSMB->MaxSetupCount = 0; |
| 1802 | pSMB->Reserved = 0; |
| 1803 | pSMB->Flags = 0; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1804 | pSMB->Reserved2 = 0; |
| 1805 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 1806 | offset = param_offset + params; |
| 1807 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1808 | count = sizeof(struct cifs_posix_lock); |
| 1809 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 1810 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1811 | pSMB->SetupCount = 1; |
| 1812 | pSMB->Reserved3 = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1813 | if (get_flag) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1814 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 1815 | else |
| 1816 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 1817 | byte_count = 3 /* pad */ + params + count; |
| 1818 | pSMB->DataCount = cpu_to_le16(count); |
| 1819 | pSMB->ParameterCount = cpu_to_le16(params); |
| 1820 | pSMB->TotalDataCount = pSMB->DataCount; |
| 1821 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 1822 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1823 | parm_data = (struct cifs_posix_lock *) |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1824 | (((char *) &pSMB->hdr.Protocol) + offset); |
| 1825 | |
| 1826 | parm_data->lock_type = cpu_to_le16(lock_type); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1827 | if (waitFlag) { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1828 | timeout = CIFS_BLOCKING_OP; /* blocking operation, no timeout */ |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1829 | parm_data->lock_flags = cpu_to_le16(1); |
Steve French | 3a5ff61 | 2006-07-14 22:37:11 +0000 | [diff] [blame] | 1830 | pSMB->Timeout = cpu_to_le32(-1); |
| 1831 | } else |
| 1832 | pSMB->Timeout = 0; |
| 1833 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1834 | parm_data->pid = cpu_to_le32(current->tgid); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1835 | parm_data->start = cpu_to_le64(pLockData->fl_start); |
Steve French | cec6815a | 2006-05-30 18:07:17 +0000 | [diff] [blame] | 1836 | parm_data->length = cpu_to_le64(len); /* normalize negative numbers */ |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1837 | |
| 1838 | pSMB->DataOffset = cpu_to_le16(offset); |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 1839 | pSMB->Fid = smb_file_id; |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1840 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_LOCK); |
| 1841 | pSMB->Reserved4 = 0; |
| 1842 | pSMB->hdr.smb_buf_length += byte_count; |
| 1843 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1844 | if (waitFlag) { |
| 1845 | rc = SendReceiveBlockingLock(xid, tcon, (struct smb_hdr *) pSMB, |
| 1846 | (struct smb_hdr *) pSMBr, &bytes_returned); |
| 1847 | } else { |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1848 | iov[0].iov_base = (char *)pSMB; |
| 1849 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 1850 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovecs */, |
| 1851 | &resp_buf_type, timeout); |
| 1852 | pSMB = NULL; /* request buf already freed by SendReceive2. Do |
| 1853 | not try to free it twice below on exit */ |
| 1854 | pSMBr = (struct smb_com_transaction2_sfi_rsp *)iov[0].iov_base; |
Jeremy Allison | 7ee1af7 | 2006-08-02 21:56:33 +0000 | [diff] [blame] | 1855 | } |
| 1856 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1857 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1858 | cFYI(1, "Send error in Posix Lock = %d", rc); |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1859 | } else if (get_flag) { |
| 1860 | /* lock structure can be returned on get */ |
| 1861 | __u16 data_offset; |
| 1862 | __u16 data_count; |
| 1863 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1864 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1865 | if (rc || (pSMBr->ByteCount < sizeof(struct cifs_posix_lock))) { |
| 1866 | rc = -EIO; /* bad smb */ |
| 1867 | goto plk_err_exit; |
| 1868 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1869 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 1870 | data_count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1871 | if (data_count < sizeof(struct cifs_posix_lock)) { |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1872 | rc = -EIO; |
| 1873 | goto plk_err_exit; |
| 1874 | } |
| 1875 | parm_data = (struct cifs_posix_lock *) |
| 1876 | ((char *)&pSMBr->hdr.Protocol + data_offset); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1877 | if (parm_data->lock_type == __constant_cpu_to_le16(CIFS_UNLCK)) |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1878 | pLockData->fl_type = F_UNLCK; |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1879 | else { |
| 1880 | if (parm_data->lock_type == |
| 1881 | __constant_cpu_to_le16(CIFS_RDLCK)) |
| 1882 | pLockData->fl_type = F_RDLCK; |
| 1883 | else if (parm_data->lock_type == |
| 1884 | __constant_cpu_to_le16(CIFS_WRLCK)) |
| 1885 | pLockData->fl_type = F_WRLCK; |
| 1886 | |
Steve French | 5443d13 | 2011-03-13 05:08:25 +0000 | [diff] [blame] | 1887 | pLockData->fl_start = le64_to_cpu(parm_data->start); |
| 1888 | pLockData->fl_end = pLockData->fl_start + |
| 1889 | le64_to_cpu(parm_data->length) - 1; |
| 1890 | pLockData->fl_pid = le32_to_cpu(parm_data->pid); |
Pavel Shilovsky | f05337c | 2010-04-05 09:59:14 +0400 | [diff] [blame] | 1891 | } |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1892 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1893 | |
Steve French | fc94cdb | 2006-05-30 18:03:32 +0000 | [diff] [blame] | 1894 | plk_err_exit: |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1895 | if (pSMB) |
| 1896 | cifs_small_buf_release(pSMB); |
| 1897 | |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1898 | if (resp_buf_type == CIFS_SMALL_BUFFER) |
| 1899 | cifs_small_buf_release(iov[0].iov_base); |
| 1900 | else if (resp_buf_type == CIFS_LARGE_BUFFER) |
| 1901 | cifs_buf_release(iov[0].iov_base); |
| 1902 | |
Steve French | 08547b0 | 2006-02-28 22:39:25 +0000 | [diff] [blame] | 1903 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 1904 | since file handle passed in no longer valid */ |
| 1905 | |
| 1906 | return rc; |
| 1907 | } |
| 1908 | |
| 1909 | |
| 1910 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1912 | { |
| 1913 | int rc = 0; |
| 1914 | CLOSE_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1915 | cFYI(1, "In CIFSSMBClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | |
| 1917 | /* do not retry on dead session on close */ |
| 1918 | rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1919 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | return 0; |
| 1921 | if (rc) |
| 1922 | return rc; |
| 1923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | pSMB->FileID = (__u16) smb_file_id; |
Steve French | b815f1e5 | 2006-10-02 05:53:29 +0000 | [diff] [blame] | 1925 | pSMB->LastWriteTime = 0xFFFFFFFF; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 1927 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 1928 | cifs_stats_inc(&tcon->num_closes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (rc) { |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1930 | if (rc != -EINTR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | /* EINTR is expected when user ctl-c to kill app */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1932 | cERROR(1, "Send error in Close = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | /* Since session is dead, file will be closed on server already */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 1937 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | rc = 0; |
| 1939 | |
| 1940 | return rc; |
| 1941 | } |
| 1942 | |
| 1943 | int |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1944 | CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id) |
| 1945 | { |
| 1946 | int rc = 0; |
| 1947 | FLUSH_REQ *pSMB = NULL; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1948 | cFYI(1, "In CIFSSMBFlush"); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1949 | |
| 1950 | rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB); |
| 1951 | if (rc) |
| 1952 | return rc; |
| 1953 | |
| 1954 | pSMB->FileID = (__u16) smb_file_id; |
| 1955 | pSMB->ByteCount = 0; |
| 1956 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 1957 | cifs_stats_inc(&tcon->num_flushes); |
| 1958 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1959 | cERROR(1, "Send error in Flush = %d", rc); |
Steve French | b298f22 | 2009-02-21 21:17:43 +0000 | [diff] [blame] | 1960 | |
| 1961 | return rc; |
| 1962 | } |
| 1963 | |
| 1964 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, |
| 1966 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1967 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
| 1969 | int rc = 0; |
| 1970 | RENAME_REQ *pSMB = NULL; |
| 1971 | RENAME_RSP *pSMBr = NULL; |
| 1972 | int bytes_returned; |
| 1973 | int name_len, name_len2; |
| 1974 | __u16 count; |
| 1975 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 1976 | cFYI(1, "In CIFSSMBRename"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | renameRetry: |
| 1978 | rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB, |
| 1979 | (void **) &pSMBr); |
| 1980 | if (rc) |
| 1981 | return rc; |
| 1982 | |
| 1983 | pSMB->BufferFormat = 0x04; |
| 1984 | pSMB->SearchAttributes = |
| 1985 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 1986 | ATTR_DIRECTORY); |
| 1987 | |
| 1988 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 1989 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 1990 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1991 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | name_len++; /* trailing null */ |
| 1993 | name_len *= 2; |
| 1994 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 1995 | /* protocol requires ASCII signature byte on Unicode string */ |
| 1996 | pSMB->OldFileName[name_len + 1] = 0x00; |
| 1997 | name_len2 = |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 1998 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 1999 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2001 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2002 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | name_len = strnlen(fromName, PATH_MAX); |
| 2004 | name_len++; /* trailing null */ |
| 2005 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2006 | name_len2 = strnlen(toName, PATH_MAX); |
| 2007 | name_len2++; /* trailing null */ |
| 2008 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2009 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2010 | name_len2++; /* trailing null */ |
| 2011 | name_len2++; /* signature byte */ |
| 2012 | } |
| 2013 | |
| 2014 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 2015 | pSMB->hdr.smb_buf_length += count; |
| 2016 | pSMB->ByteCount = cpu_to_le16(count); |
| 2017 | |
| 2018 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2019 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2020 | cifs_stats_inc(&tcon->num_renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2021 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2022 | cFYI(1, "Send error in rename = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | cifs_buf_release(pSMB); |
| 2025 | |
| 2026 | if (rc == -EAGAIN) |
| 2027 | goto renameRetry; |
| 2028 | |
| 2029 | return rc; |
| 2030 | } |
| 2031 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2032 | int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon, |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2033 | int netfid, const char *target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2034 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
| 2036 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 2037 | struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2038 | struct set_file_rename *rename_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | char *data_offset; |
| 2040 | char dummy_string[30]; |
| 2041 | int rc = 0; |
| 2042 | int bytes_returned = 0; |
| 2043 | int len_of_str; |
| 2044 | __u16 params, param_offset, offset, count, byte_count; |
| 2045 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2046 | cFYI(1, "Rename to File by handle"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2047 | rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB, |
| 2048 | (void **) &pSMBr); |
| 2049 | if (rc) |
| 2050 | return rc; |
| 2051 | |
| 2052 | params = 6; |
| 2053 | pSMB->MaxSetupCount = 0; |
| 2054 | pSMB->Reserved = 0; |
| 2055 | pSMB->Flags = 0; |
| 2056 | pSMB->Timeout = 0; |
| 2057 | pSMB->Reserved2 = 0; |
| 2058 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 2059 | offset = param_offset + params; |
| 2060 | |
| 2061 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2062 | rename_info = (struct set_file_rename *) data_offset; |
| 2063 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2064 | pSMB->MaxDataCount = cpu_to_le16(1000); /* BB find max SMB from sess */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | pSMB->SetupCount = 1; |
| 2066 | pSMB->Reserved3 = 0; |
| 2067 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 2068 | byte_count = 3 /* pad */ + params; |
| 2069 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2070 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2071 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2072 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2073 | /* construct random name ".cifs_tmp<inodenum><mid>" */ |
| 2074 | rename_info->overwrite = cpu_to_le32(1); |
| 2075 | rename_info->root_fid = 0; |
| 2076 | /* unicode only call */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2077 | if (target_name == NULL) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2078 | sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid); |
| 2079 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2080 | dummy_string, 24, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | } else { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2082 | len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2083 | target_name, PATH_MAX, nls_codepage, |
| 2084 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | rename_info->target_name_len = cpu_to_le32(2 * len_of_str); |
Jeff Layton | 391e575 | 2008-09-24 11:32:59 -0400 | [diff] [blame] | 2087 | count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | byte_count += count; |
| 2089 | pSMB->DataCount = cpu_to_le16(count); |
| 2090 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2091 | pSMB->Fid = netfid; |
| 2092 | pSMB->InformationLevel = |
| 2093 | cpu_to_le16(SMB_SET_FILE_RENAME_INFORMATION); |
| 2094 | pSMB->Reserved4 = 0; |
| 2095 | pSMB->hdr.smb_buf_length += byte_count; |
| 2096 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2097 | rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2098 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2099 | cifs_stats_inc(&pTcon->num_t2renames); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2100 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2101 | cFYI(1, "Send error in Rename (by file handle) = %d", rc); |
Steve French | a5a2b48 | 2005-08-20 21:42:53 -0700 | [diff] [blame] | 2102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | cifs_buf_release(pSMB); |
| 2104 | |
| 2105 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2106 | since file handle passed in no longer valid */ |
| 2107 | |
| 2108 | return rc; |
| 2109 | } |
| 2110 | |
| 2111 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2112 | CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName, |
| 2113 | const __u16 target_tid, const char *toName, const int flags, |
| 2114 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | { |
| 2116 | int rc = 0; |
| 2117 | COPY_REQ *pSMB = NULL; |
| 2118 | COPY_RSP *pSMBr = NULL; |
| 2119 | int bytes_returned; |
| 2120 | int name_len, name_len2; |
| 2121 | __u16 count; |
| 2122 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2123 | cFYI(1, "In CIFSSMBCopy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | copyRetry: |
| 2125 | rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB, |
| 2126 | (void **) &pSMBr); |
| 2127 | if (rc) |
| 2128 | return rc; |
| 2129 | |
| 2130 | pSMB->BufferFormat = 0x04; |
| 2131 | pSMB->Tid2 = target_tid; |
| 2132 | |
| 2133 | pSMB->Flags = cpu_to_le16(flags & COPY_TREE); |
| 2134 | |
| 2135 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2136 | name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2137 | fromName, PATH_MAX, nls_codepage, |
| 2138 | remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | name_len++; /* trailing null */ |
| 2140 | name_len *= 2; |
| 2141 | pSMB->OldFileName[name_len] = 0x04; /* pad */ |
| 2142 | /* protocol requires ASCII signature byte on Unicode string */ |
| 2143 | pSMB->OldFileName[name_len + 1] = 0x00; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2144 | name_len2 = |
| 2145 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2146 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2148 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2149 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | name_len = strnlen(fromName, PATH_MAX); |
| 2151 | name_len++; /* trailing null */ |
| 2152 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2153 | name_len2 = strnlen(toName, PATH_MAX); |
| 2154 | name_len2++; /* trailing null */ |
| 2155 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2156 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2157 | name_len2++; /* trailing null */ |
| 2158 | name_len2++; /* signature byte */ |
| 2159 | } |
| 2160 | |
| 2161 | count = 1 /* 1st signature byte */ + name_len + name_len2; |
| 2162 | pSMB->hdr.smb_buf_length += count; |
| 2163 | pSMB->ByteCount = cpu_to_le16(count); |
| 2164 | |
| 2165 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2166 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2167 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2168 | cFYI(1, "Send error in copy = %d with %d files copied", |
| 2169 | rc, le16_to_cpu(pSMBr->CopyCount)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | } |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2171 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | |
| 2173 | if (rc == -EAGAIN) |
| 2174 | goto copyRetry; |
| 2175 | |
| 2176 | return rc; |
| 2177 | } |
| 2178 | |
| 2179 | int |
| 2180 | CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon, |
| 2181 | const char *fromName, const char *toName, |
| 2182 | const struct nls_table *nls_codepage) |
| 2183 | { |
| 2184 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2185 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2186 | char *data_offset; |
| 2187 | int name_len; |
| 2188 | int name_len_target; |
| 2189 | int rc = 0; |
| 2190 | int bytes_returned = 0; |
| 2191 | __u16 params, param_offset, offset, byte_count; |
| 2192 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2193 | cFYI(1, "In Symlink Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2194 | createSymLinkRetry: |
| 2195 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2196 | (void **) &pSMBr); |
| 2197 | if (rc) |
| 2198 | return rc; |
| 2199 | |
| 2200 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2201 | name_len = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2202 | cifs_strtoUCS((__le16 *) pSMB->FileName, fromName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | /* find define for this maxpathcomponent */ |
| 2204 | , nls_codepage); |
| 2205 | name_len++; /* trailing null */ |
| 2206 | name_len *= 2; |
| 2207 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2208 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | name_len = strnlen(fromName, PATH_MAX); |
| 2210 | name_len++; /* trailing null */ |
| 2211 | strncpy(pSMB->FileName, fromName, name_len); |
| 2212 | } |
| 2213 | params = 6 + name_len; |
| 2214 | pSMB->MaxSetupCount = 0; |
| 2215 | pSMB->Reserved = 0; |
| 2216 | pSMB->Flags = 0; |
| 2217 | pSMB->Timeout = 0; |
| 2218 | pSMB->Reserved2 = 0; |
| 2219 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2220 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | offset = param_offset + params; |
| 2222 | |
| 2223 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2224 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2225 | name_len_target = |
Steve French | e89dc92 | 2005-11-11 15:18:19 -0800 | [diff] [blame] | 2226 | cifs_strtoUCS((__le16 *) data_offset, toName, PATH_MAX |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | /* find define for this maxpathcomponent */ |
| 2228 | , nls_codepage); |
| 2229 | name_len_target++; /* trailing null */ |
| 2230 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2231 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | name_len_target = strnlen(toName, PATH_MAX); |
| 2233 | name_len_target++; /* trailing null */ |
| 2234 | strncpy(data_offset, toName, name_len_target); |
| 2235 | } |
| 2236 | |
| 2237 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2238 | /* BB find exact max on data count below from sess */ |
| 2239 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2240 | pSMB->SetupCount = 1; |
| 2241 | pSMB->Reserved3 = 0; |
| 2242 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2243 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2244 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2245 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2246 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2247 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2248 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2249 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2250 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_LINK); |
| 2251 | pSMB->Reserved4 = 0; |
| 2252 | pSMB->hdr.smb_buf_length += byte_count; |
| 2253 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2254 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2255 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2256 | cifs_stats_inc(&tcon->num_symlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2257 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2258 | cFYI(1, "Send error in SetPathInfo create symlink = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2259 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 2260 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | |
| 2262 | if (rc == -EAGAIN) |
| 2263 | goto createSymLinkRetry; |
| 2264 | |
| 2265 | return rc; |
| 2266 | } |
| 2267 | |
| 2268 | int |
| 2269 | CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2270 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2271 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | { |
| 2273 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 2274 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 2275 | char *data_offset; |
| 2276 | int name_len; |
| 2277 | int name_len_target; |
| 2278 | int rc = 0; |
| 2279 | int bytes_returned = 0; |
| 2280 | __u16 params, param_offset, offset, byte_count; |
| 2281 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2282 | cFYI(1, "In Create Hard link Unix style"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | createHardLinkRetry: |
| 2284 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2285 | (void **) &pSMBr); |
| 2286 | if (rc) |
| 2287 | return rc; |
| 2288 | |
| 2289 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2290 | name_len = cifsConvertToUCS((__le16 *) pSMB->FileName, toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2291 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | name_len++; /* trailing null */ |
| 2293 | name_len *= 2; |
| 2294 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2295 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | name_len = strnlen(toName, PATH_MAX); |
| 2297 | name_len++; /* trailing null */ |
| 2298 | strncpy(pSMB->FileName, toName, name_len); |
| 2299 | } |
| 2300 | params = 6 + name_len; |
| 2301 | pSMB->MaxSetupCount = 0; |
| 2302 | pSMB->Reserved = 0; |
| 2303 | pSMB->Flags = 0; |
| 2304 | pSMB->Timeout = 0; |
| 2305 | pSMB->Reserved2 = 0; |
| 2306 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2307 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | offset = param_offset + params; |
| 2309 | |
| 2310 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 2311 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2312 | name_len_target = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2313 | cifsConvertToUCS((__le16 *) data_offset, fromName, PATH_MAX, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2314 | nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | name_len_target++; /* trailing null */ |
| 2316 | name_len_target *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2317 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | name_len_target = strnlen(fromName, PATH_MAX); |
| 2319 | name_len_target++; /* trailing null */ |
| 2320 | strncpy(data_offset, fromName, name_len_target); |
| 2321 | } |
| 2322 | |
| 2323 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 2324 | /* BB find exact max on data count below from sess*/ |
| 2325 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 2326 | pSMB->SetupCount = 1; |
| 2327 | pSMB->Reserved3 = 0; |
| 2328 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2329 | byte_count = 3 /* pad */ + params + name_len_target; |
| 2330 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2331 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2332 | pSMB->DataCount = cpu_to_le16(name_len_target); |
| 2333 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2334 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2335 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2336 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_HLINK); |
| 2337 | pSMB->Reserved4 = 0; |
| 2338 | pSMB->hdr.smb_buf_length += byte_count; |
| 2339 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2340 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2341 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2342 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2343 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2344 | cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | |
| 2346 | cifs_buf_release(pSMB); |
| 2347 | if (rc == -EAGAIN) |
| 2348 | goto createHardLinkRetry; |
| 2349 | |
| 2350 | return rc; |
| 2351 | } |
| 2352 | |
| 2353 | int |
| 2354 | CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon, |
| 2355 | const char *fromName, const char *toName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2356 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | { |
| 2358 | int rc = 0; |
| 2359 | NT_RENAME_REQ *pSMB = NULL; |
| 2360 | RENAME_RSP *pSMBr = NULL; |
| 2361 | int bytes_returned; |
| 2362 | int name_len, name_len2; |
| 2363 | __u16 count; |
| 2364 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2365 | cFYI(1, "In CIFSCreateHardLink"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | winCreateHardLinkRetry: |
| 2367 | |
| 2368 | rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB, |
| 2369 | (void **) &pSMBr); |
| 2370 | if (rc) |
| 2371 | return rc; |
| 2372 | |
| 2373 | pSMB->SearchAttributes = |
| 2374 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 2375 | ATTR_DIRECTORY); |
| 2376 | pSMB->Flags = cpu_to_le16(CREATE_HARD_LINK); |
| 2377 | pSMB->ClusterCount = 0; |
| 2378 | |
| 2379 | pSMB->BufferFormat = 0x04; |
| 2380 | |
| 2381 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2382 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 2383 | cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2384 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | name_len++; /* trailing null */ |
| 2386 | name_len *= 2; |
Jeff Layton | fcc7c09 | 2009-02-28 12:59:03 -0500 | [diff] [blame] | 2387 | |
| 2388 | /* protocol specifies ASCII buffer format (0x04) for unicode */ |
| 2389 | pSMB->OldFileName[name_len] = 0x04; |
| 2390 | pSMB->OldFileName[name_len + 1] = 0x00; /* pad */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | name_len2 = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2392 | cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2393 | toName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; |
| 2395 | name_len2 *= 2; /* convert to bytes */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2396 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | name_len = strnlen(fromName, PATH_MAX); |
| 2398 | name_len++; /* trailing null */ |
| 2399 | strncpy(pSMB->OldFileName, fromName, name_len); |
| 2400 | name_len2 = strnlen(toName, PATH_MAX); |
| 2401 | name_len2++; /* trailing null */ |
| 2402 | pSMB->OldFileName[name_len] = 0x04; /* 2nd buffer format */ |
| 2403 | strncpy(&pSMB->OldFileName[name_len + 1], toName, name_len2); |
| 2404 | name_len2++; /* trailing null */ |
| 2405 | name_len2++; /* signature byte */ |
| 2406 | } |
| 2407 | |
| 2408 | count = 1 /* string type byte */ + name_len + name_len2; |
| 2409 | pSMB->hdr.smb_buf_length += count; |
| 2410 | pSMB->ByteCount = cpu_to_le16(count); |
| 2411 | |
| 2412 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2413 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 2414 | cifs_stats_inc(&tcon->num_hardlinks); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2415 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2416 | cFYI(1, "Send error in hard link (NT rename) = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | cifs_buf_release(pSMB); |
| 2419 | if (rc == -EAGAIN) |
| 2420 | goto winCreateHardLinkRetry; |
| 2421 | |
| 2422 | return rc; |
| 2423 | } |
| 2424 | |
| 2425 | int |
| 2426 | CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2427 | const unsigned char *searchName, char **symlinkinfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | const struct nls_table *nls_codepage) |
| 2429 | { |
| 2430 | /* SMB_QUERY_FILE_UNIX_LINK */ |
| 2431 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2432 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2433 | int rc = 0; |
| 2434 | int bytes_returned; |
| 2435 | int name_len; |
| 2436 | __u16 params, byte_count; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2437 | char *data_start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2439 | cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | |
| 2441 | querySymLinkRetry: |
| 2442 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2443 | (void **) &pSMBr); |
| 2444 | if (rc) |
| 2445 | return rc; |
| 2446 | |
| 2447 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2448 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2449 | cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, |
| 2450 | PATH_MAX, nls_codepage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | name_len++; /* trailing null */ |
| 2452 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2453 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | name_len = strnlen(searchName, PATH_MAX); |
| 2455 | name_len++; /* trailing null */ |
| 2456 | strncpy(pSMB->FileName, searchName, name_len); |
| 2457 | } |
| 2458 | |
| 2459 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2460 | pSMB->TotalDataCount = 0; |
| 2461 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Jeff Layton | 46a7574 | 2009-05-24 18:45:17 -0400 | [diff] [blame] | 2462 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | pSMB->MaxSetupCount = 0; |
| 2464 | pSMB->Reserved = 0; |
| 2465 | pSMB->Flags = 0; |
| 2466 | pSMB->Timeout = 0; |
| 2467 | pSMB->Reserved2 = 0; |
| 2468 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2469 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | pSMB->DataCount = 0; |
| 2471 | pSMB->DataOffset = 0; |
| 2472 | pSMB->SetupCount = 1; |
| 2473 | pSMB->Reserved3 = 0; |
| 2474 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2475 | byte_count = params + 1 /* pad */ ; |
| 2476 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2477 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2478 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_LINK); |
| 2479 | pSMB->Reserved4 = 0; |
| 2480 | pSMB->hdr.smb_buf_length += byte_count; |
| 2481 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2482 | |
| 2483 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2484 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2485 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2486 | cFYI(1, "Send error in QuerySymLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | } else { |
| 2488 | /* decode response */ |
| 2489 | |
| 2490 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | /* BB also check enough total bytes returned */ |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2492 | if (rc || (pSMBr->ByteCount < 2)) |
| 2493 | rc = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | else { |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2495 | bool is_unicode; |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2496 | u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2498 | data_start = ((char *) &pSMBr->hdr.Protocol) + |
| 2499 | le16_to_cpu(pSMBr->t2.DataOffset); |
| 2500 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2501 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 2502 | is_unicode = true; |
| 2503 | else |
| 2504 | is_unicode = false; |
| 2505 | |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2506 | /* BB FIXME investigate remapping reserved chars here */ |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 2507 | *symlinkinfo = cifs_strndup_from_ucs(data_start, count, |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 2508 | is_unicode, nls_codepage); |
Jeff Layton | 8b6427a | 2009-05-19 09:57:03 -0400 | [diff] [blame] | 2509 | if (!*symlinkinfo) |
Jeff Layton | 460b969 | 2009-04-30 07:17:56 -0400 | [diff] [blame] | 2510 | rc = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | } |
| 2512 | } |
| 2513 | cifs_buf_release(pSMB); |
| 2514 | if (rc == -EAGAIN) |
| 2515 | goto querySymLinkRetry; |
| 2516 | return rc; |
| 2517 | } |
| 2518 | |
Parag Warudkar | c948977 | 2007-10-23 18:09:48 +0000 | [diff] [blame] | 2519 | #ifdef CONFIG_CIFS_EXPERIMENTAL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2520 | int |
| 2521 | CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, |
| 2522 | const unsigned char *searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2523 | char *symlinkinfo, const int buflen, __u16 fid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | const struct nls_table *nls_codepage) |
| 2525 | { |
| 2526 | int rc = 0; |
| 2527 | int bytes_returned; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2528 | struct smb_com_transaction_ioctl_req *pSMB; |
| 2529 | struct smb_com_transaction_ioctl_rsp *pSMBr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2531 | cFYI(1, "In Windows reparse style QueryLink for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 2533 | (void **) &pSMBr); |
| 2534 | if (rc) |
| 2535 | return rc; |
| 2536 | |
| 2537 | pSMB->TotalParameterCount = 0 ; |
| 2538 | pSMB->TotalDataCount = 0; |
| 2539 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 2540 | /* BB find exact data count max from sess structure BB */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2541 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 2542 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | pSMB->MaxSetupCount = 4; |
| 2544 | pSMB->Reserved = 0; |
| 2545 | pSMB->ParameterOffset = 0; |
| 2546 | pSMB->DataCount = 0; |
| 2547 | pSMB->DataOffset = 0; |
| 2548 | pSMB->SetupCount = 4; |
| 2549 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_IOCTL); |
| 2550 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2551 | pSMB->FunctionCode = cpu_to_le32(FSCTL_GET_REPARSE_POINT); |
| 2552 | pSMB->IsFsctl = 1; /* FSCTL */ |
| 2553 | pSMB->IsRootFlag = 0; |
| 2554 | pSMB->Fid = fid; /* file handle always le */ |
| 2555 | pSMB->ByteCount = 0; |
| 2556 | |
| 2557 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2558 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2559 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2560 | cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | } else { /* decode response */ |
| 2562 | __u32 data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 2563 | __u32 data_count = le32_to_cpu(pSMBr->DataCount); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2564 | if ((pSMBr->ByteCount < 2) || (data_offset > 512)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | /* BB also check enough total bytes returned */ |
| 2566 | rc = -EIO; /* bad smb */ |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2567 | goto qreparse_out; |
| 2568 | } |
| 2569 | if (data_count && (data_count < 2048)) { |
| 2570 | char *end_of_smb = 2 /* sizeof byte count */ + |
| 2571 | pSMBr->ByteCount + (char *)&pSMBr->ByteCount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2573 | struct reparse_data *reparse_buf = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2574 | (struct reparse_data *) |
| 2575 | ((char *)&pSMBr->hdr.Protocol |
| 2576 | + data_offset); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2577 | if ((char *)reparse_buf >= end_of_smb) { |
| 2578 | rc = -EIO; |
| 2579 | goto qreparse_out; |
| 2580 | } |
| 2581 | if ((reparse_buf->LinkNamesBuf + |
| 2582 | reparse_buf->TargetNameOffset + |
| 2583 | reparse_buf->TargetNameLen) > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2584 | cFYI(1, "reparse buf beyond SMB"); |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2585 | rc = -EIO; |
| 2586 | goto qreparse_out; |
| 2587 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2588 | |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2589 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2590 | cifs_from_ucs2(symlinkinfo, (__le16 *) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2591 | (reparse_buf->LinkNamesBuf + |
| 2592 | reparse_buf->TargetNameOffset), |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2593 | buflen, |
| 2594 | reparse_buf->TargetNameLen, |
| 2595 | nls_codepage, 0); |
| 2596 | } else { /* ASCII names */ |
| 2597 | strncpy(symlinkinfo, |
| 2598 | reparse_buf->LinkNamesBuf + |
| 2599 | reparse_buf->TargetNameOffset, |
| 2600 | min_t(const int, buflen, |
| 2601 | reparse_buf->TargetNameLen)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2603 | } else { |
| 2604 | rc = -EIO; |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2605 | cFYI(1, "Invalid return data count on " |
| 2606 | "get reparse info ioctl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2608 | symlinkinfo[buflen] = 0; /* just in case so the caller |
| 2609 | does not go off the end of the buffer */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2610 | cFYI(1, "readlink result - %s", symlinkinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | } |
Steve French | 989c7e5 | 2009-05-02 05:32:20 +0000 | [diff] [blame] | 2612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | qreparse_out: |
Steve French | 4a6d87f | 2005-08-13 08:15:54 -0700 | [diff] [blame] | 2614 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2615 | |
| 2616 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 2617 | since file handle passed in no longer valid */ |
| 2618 | |
| 2619 | return rc; |
| 2620 | } |
Steve French | afe48c3 | 2009-05-02 05:25:46 +0000 | [diff] [blame] | 2621 | #endif /* CIFS_EXPERIMENTAL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | |
| 2623 | #ifdef CONFIG_CIFS_POSIX |
| 2624 | |
| 2625 | /*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] | 2626 | static void cifs_convert_ace(posix_acl_xattr_entry *ace, |
| 2627 | struct cifs_posix_ace *cifs_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | { |
| 2629 | /* u8 cifs fields do not need le conversion */ |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2630 | ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); |
| 2631 | ace->e_tag = cpu_to_le16(cifs_ace->cifs_e_tag); |
| 2632 | 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] | 2633 | /* 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] | 2634 | |
| 2635 | return; |
| 2636 | } |
| 2637 | |
| 2638 | /* 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] | 2639 | static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen, |
| 2640 | const int acl_type, const int size_of_data_area) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | { |
| 2642 | int size = 0; |
| 2643 | int i; |
| 2644 | __u16 count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2645 | struct cifs_posix_ace *pACE; |
| 2646 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src; |
| 2647 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | |
| 2649 | if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) |
| 2650 | return -EOPNOTSUPP; |
| 2651 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2652 | if (acl_type & ACL_TYPE_ACCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2654 | pACE = &cifs_acl->ace_array[0]; |
| 2655 | size = sizeof(struct cifs_posix_acl); |
| 2656 | size += sizeof(struct cifs_posix_ace) * count; |
| 2657 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2658 | if (size_of_data_area < size) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2659 | cFYI(1, "bad CIFS POSIX ACL size %d vs. %d", |
| 2660 | size_of_data_area, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | return -EINVAL; |
| 2662 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2663 | } else if (acl_type & ACL_TYPE_DEFAULT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | count = le16_to_cpu(cifs_acl->access_entry_count); |
| 2665 | size = sizeof(struct cifs_posix_acl); |
| 2666 | size += sizeof(struct cifs_posix_ace) * count; |
| 2667 | /* skip past access ACEs to get to default ACEs */ |
| 2668 | pACE = &cifs_acl->ace_array[count]; |
| 2669 | count = le16_to_cpu(cifs_acl->default_entry_count); |
| 2670 | size += sizeof(struct cifs_posix_ace) * count; |
| 2671 | /* check if we would go beyond end of SMB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2672 | if (size_of_data_area < size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2673 | return -EINVAL; |
| 2674 | } else { |
| 2675 | /* illegal type */ |
| 2676 | return -EINVAL; |
| 2677 | } |
| 2678 | |
| 2679 | size = posix_acl_xattr_size(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2680 | if ((buflen == 0) || (local_acl == NULL)) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2681 | /* used to query ACL EA size */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2682 | } else if (size > buflen) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | return -ERANGE; |
| 2684 | } else /* buffer big enough */ { |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2685 | local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2686 | for (i = 0; i < count ; i++) { |
| 2687 | cifs_convert_ace(&local_acl->a_entries[i], pACE); |
| 2688 | pACE++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2689 | } |
| 2690 | } |
| 2691 | return size; |
| 2692 | } |
| 2693 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2694 | static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace, |
| 2695 | const posix_acl_xattr_entry *local_ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | { |
| 2697 | __u16 rc = 0; /* 0 = ACL converted ok */ |
| 2698 | |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2699 | cifs_ace->cifs_e_perm = le16_to_cpu(local_ace->e_perm); |
| 2700 | cifs_ace->cifs_e_tag = le16_to_cpu(local_ace->e_tag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | /* BB is there a better way to handle the large uid? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2702 | if (local_ace->e_id == cpu_to_le32(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | /* Probably no need to le convert -1 on any arch but can not hurt */ |
| 2704 | cifs_ace->cifs_uid = cpu_to_le64(-1); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2705 | } else |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2706 | 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] | 2707 | /*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] | 2708 | return rc; |
| 2709 | } |
| 2710 | |
| 2711 | /* 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] | 2712 | static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL, |
| 2713 | const int buflen, const int acl_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | { |
| 2715 | __u16 rc = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2716 | struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data; |
| 2717 | posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | int count; |
| 2719 | int i; |
| 2720 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2721 | if ((buflen == 0) || (pACL == NULL) || (cifs_acl == NULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | return 0; |
| 2723 | |
| 2724 | count = posix_acl_xattr_count((size_t)buflen); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2725 | 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] | 2726 | "version of %d", |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2727 | count, buflen, le32_to_cpu(local_acl->a_version)); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2728 | if (le32_to_cpu(local_acl->a_version) != 2) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2729 | cFYI(1, "unknown POSIX ACL version %d", |
| 2730 | le32_to_cpu(local_acl->a_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2731 | return 0; |
| 2732 | } |
| 2733 | cifs_acl->version = cpu_to_le16(1); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2734 | if (acl_type == ACL_TYPE_ACCESS) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2735 | cifs_acl->access_entry_count = cpu_to_le16(count); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2736 | else if (acl_type == ACL_TYPE_DEFAULT) |
Steve French | ff7feac | 2005-11-15 16:45:16 -0800 | [diff] [blame] | 2737 | cifs_acl->default_entry_count = cpu_to_le16(count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | else { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2739 | cFYI(1, "unknown ACL type %d", acl_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2740 | return 0; |
| 2741 | } |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2742 | for (i = 0; i < count; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], |
| 2744 | &local_acl->a_entries[i]); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2745 | if (rc != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | /* ACE not converted */ |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2750 | if (rc == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | rc = (__u16)(count * sizeof(struct cifs_posix_ace)); |
| 2752 | rc += sizeof(struct cifs_posix_acl); |
| 2753 | /* BB add check to make sure ACL does not overflow SMB */ |
| 2754 | } |
| 2755 | return rc; |
| 2756 | } |
| 2757 | |
| 2758 | int |
| 2759 | CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2760 | const unsigned char *searchName, |
| 2761 | char *acl_inf, const int buflen, const int acl_type, |
| 2762 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | { |
| 2764 | /* SMB_QUERY_POSIX_ACL */ |
| 2765 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 2766 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 2767 | int rc = 0; |
| 2768 | int bytes_returned; |
| 2769 | int name_len; |
| 2770 | __u16 params, byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2771 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2772 | cFYI(1, "In GetPosixACL (Unix) for path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | |
| 2774 | queryAclRetry: |
| 2775 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2776 | (void **) &pSMBr); |
| 2777 | if (rc) |
| 2778 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2781 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2782 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2783 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | name_len++; /* trailing null */ |
| 2785 | name_len *= 2; |
| 2786 | pSMB->FileName[name_len] = 0; |
| 2787 | pSMB->FileName[name_len+1] = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2788 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | name_len = strnlen(searchName, PATH_MAX); |
| 2790 | name_len++; /* trailing null */ |
| 2791 | strncpy(pSMB->FileName, searchName, name_len); |
| 2792 | } |
| 2793 | |
| 2794 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 2795 | pSMB->TotalDataCount = 0; |
| 2796 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2797 | /* BB find exact max data count below from sess structure BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 2799 | pSMB->MaxSetupCount = 0; |
| 2800 | pSMB->Reserved = 0; |
| 2801 | pSMB->Flags = 0; |
| 2802 | pSMB->Timeout = 0; |
| 2803 | pSMB->Reserved2 = 0; |
| 2804 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2805 | offsetof(struct smb_com_transaction2_qpi_req, |
| 2806 | InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | pSMB->DataCount = 0; |
| 2808 | pSMB->DataOffset = 0; |
| 2809 | pSMB->SetupCount = 1; |
| 2810 | pSMB->Reserved3 = 0; |
| 2811 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 2812 | byte_count = params + 1 /* pad */ ; |
| 2813 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 2814 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 2815 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_ACL); |
| 2816 | pSMB->Reserved4 = 0; |
| 2817 | pSMB->hdr.smb_buf_length += byte_count; |
| 2818 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2819 | |
| 2820 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2821 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 2822 | cifs_stats_inc(&tcon->num_acl_get); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2824 | cFYI(1, "Send error in Query POSIX ACL = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | } else { |
| 2826 | /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2827 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2829 | if (rc || (pSMBr->ByteCount < 2)) |
| 2830 | /* BB also check enough total bytes returned */ |
| 2831 | rc = -EIO; /* bad smb */ |
| 2832 | else { |
| 2833 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2834 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2835 | rc = cifs_copy_posix_acl(acl_inf, |
| 2836 | (char *)&pSMBr->hdr.Protocol+data_offset, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2837 | buflen, acl_type, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | cifs_buf_release(pSMB); |
| 2841 | if (rc == -EAGAIN) |
| 2842 | goto queryAclRetry; |
| 2843 | return rc; |
| 2844 | } |
| 2845 | |
| 2846 | int |
| 2847 | CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2848 | const unsigned char *fileName, |
| 2849 | const char *local_acl, const int buflen, |
| 2850 | const int acl_type, |
| 2851 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2852 | { |
| 2853 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 2854 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 2855 | char *parm_data; |
| 2856 | int name_len; |
| 2857 | int rc = 0; |
| 2858 | int bytes_returned = 0; |
| 2859 | __u16 params, byte_count, data_count, param_offset, offset; |
| 2860 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2861 | cFYI(1, "In SetPosixACL (Unix) for path %s", fileName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | setAclRetry: |
| 2863 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2864 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | if (rc) |
| 2866 | return rc; |
| 2867 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 2868 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2869 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 2870 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | name_len++; /* trailing null */ |
| 2872 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2873 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | name_len = strnlen(fileName, PATH_MAX); |
| 2875 | name_len++; /* trailing null */ |
| 2876 | strncpy(pSMB->FileName, fileName, name_len); |
| 2877 | } |
| 2878 | params = 6 + name_len; |
| 2879 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 2880 | /* BB find max SMB size from sess */ |
| 2881 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | pSMB->MaxSetupCount = 0; |
| 2883 | pSMB->Reserved = 0; |
| 2884 | pSMB->Flags = 0; |
| 2885 | pSMB->Timeout = 0; |
| 2886 | pSMB->Reserved2 = 0; |
| 2887 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2888 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | offset = param_offset + params; |
| 2890 | parm_data = ((char *) &pSMB->hdr.Protocol) + offset; |
| 2891 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 2892 | |
| 2893 | /* convert to on the wire format for POSIX ACL */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2894 | 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] | 2895 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2896 | if (data_count == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | rc = -EOPNOTSUPP; |
| 2898 | goto setACLerrorExit; |
| 2899 | } |
| 2900 | pSMB->DataOffset = cpu_to_le16(offset); |
| 2901 | pSMB->SetupCount = 1; |
| 2902 | pSMB->Reserved3 = 0; |
| 2903 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 2904 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_POSIX_ACL); |
| 2905 | byte_count = 3 /* pad */ + params + data_count; |
| 2906 | pSMB->DataCount = cpu_to_le16(data_count); |
| 2907 | pSMB->TotalDataCount = pSMB->DataCount; |
| 2908 | pSMB->ParameterCount = cpu_to_le16(params); |
| 2909 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 2910 | pSMB->Reserved4 = 0; |
| 2911 | pSMB->hdr.smb_buf_length += byte_count; |
| 2912 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 2913 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2914 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2915 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2916 | cFYI(1, "Set POSIX ACL returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
| 2918 | setACLerrorExit: |
| 2919 | cifs_buf_release(pSMB); |
| 2920 | if (rc == -EAGAIN) |
| 2921 | goto setAclRetry; |
| 2922 | return rc; |
| 2923 | } |
| 2924 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2925 | /* BB fix tabs in this function FIXME BB */ |
| 2926 | int |
| 2927 | CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2928 | const int netfid, __u64 *pExtAttrBits, __u64 *pMask) |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2929 | { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 2930 | int rc = 0; |
| 2931 | struct smb_t2_qfi_req *pSMB = NULL; |
| 2932 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 2933 | int bytes_returned; |
| 2934 | __u16 params, byte_count; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2935 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2936 | cFYI(1, "In GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2937 | if (tcon == NULL) |
| 2938 | return -ENODEV; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2939 | |
| 2940 | GetExtAttrRetry: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2941 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 2942 | (void **) &pSMBr); |
| 2943 | if (rc) |
| 2944 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2945 | |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 2946 | params = 2 /* level */ + 2 /* fid */; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2947 | pSMB->t2.TotalDataCount = 0; |
| 2948 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 2949 | /* BB find exact max data count below from sess structure BB */ |
| 2950 | pSMB->t2.MaxDataCount = cpu_to_le16(4000); |
| 2951 | pSMB->t2.MaxSetupCount = 0; |
| 2952 | pSMB->t2.Reserved = 0; |
| 2953 | pSMB->t2.Flags = 0; |
| 2954 | pSMB->t2.Timeout = 0; |
| 2955 | pSMB->t2.Reserved2 = 0; |
| 2956 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 2957 | Fid) - 4); |
| 2958 | pSMB->t2.DataCount = 0; |
| 2959 | pSMB->t2.DataOffset = 0; |
| 2960 | pSMB->t2.SetupCount = 1; |
| 2961 | pSMB->t2.Reserved3 = 0; |
| 2962 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 2963 | byte_count = params + 1 /* pad */ ; |
| 2964 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 2965 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 2966 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_ATTR_FLAGS); |
| 2967 | pSMB->Pad = 0; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2968 | pSMB->Fid = netfid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2969 | pSMB->hdr.smb_buf_length += byte_count; |
| 2970 | pSMB->t2.ByteCount = cpu_to_le16(byte_count); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2971 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2972 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 2973 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 2974 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2975 | cFYI(1, "error %d in GetExtAttr", rc); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2976 | } else { |
| 2977 | /* decode response */ |
| 2978 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 2979 | if (rc || (pSMBr->ByteCount < 2)) |
| 2980 | /* BB also check enough total bytes returned */ |
| 2981 | /* If rc should we check for EOPNOSUPP and |
| 2982 | disable the srvino flag? or in caller? */ |
| 2983 | rc = -EIO; /* bad smb */ |
| 2984 | else { |
| 2985 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 2986 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
| 2987 | struct file_chattr_info *pfinfo; |
| 2988 | /* BB Do we need a cast or hash here ? */ |
| 2989 | if (count != 16) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 2990 | cFYI(1, "Illegal size ret in GetExtAttr"); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2991 | rc = -EIO; |
| 2992 | goto GetExtAttrOut; |
| 2993 | } |
| 2994 | pfinfo = (struct file_chattr_info *) |
| 2995 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
| 2996 | *pExtAttrBits = le64_to_cpu(pfinfo->mode); |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 2997 | *pMask = le64_to_cpu(pfinfo->mask); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 2998 | } |
| 2999 | } |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3000 | GetExtAttrOut: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3001 | cifs_buf_release(pSMB); |
| 3002 | if (rc == -EAGAIN) |
| 3003 | goto GetExtAttrRetry; |
| 3004 | return rc; |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Steve French | f654bac | 2005-04-28 22:41:04 -0700 | [diff] [blame] | 3007 | #endif /* CONFIG_POSIX */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3009 | #ifdef CONFIG_CIFS_ACL |
| 3010 | /* |
| 3011 | * Initialize NT TRANSACT SMB into small smb request buffer. This assumes that |
| 3012 | * all NT TRANSACTS that we init here have total parm and data under about 400 |
| 3013 | * bytes (to fit in small cifs buffer size), which is the case so far, it |
| 3014 | * easily fits. NB: Setup words themselves and ByteCount MaxSetupCount (size of |
| 3015 | * returned setup area) and MaxParameterCount (returned parms size) must be set |
| 3016 | * by caller |
| 3017 | */ |
| 3018 | static int |
| 3019 | smb_init_nttransact(const __u16 sub_command, const int setup_count, |
| 3020 | const int parm_len, struct cifsTconInfo *tcon, |
| 3021 | void **ret_buf) |
| 3022 | { |
| 3023 | int rc; |
| 3024 | __u32 temp_offset; |
| 3025 | struct smb_com_ntransact_req *pSMB; |
| 3026 | |
| 3027 | rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, |
| 3028 | (void **)&pSMB); |
| 3029 | if (rc) |
| 3030 | return rc; |
| 3031 | *ret_buf = (void *)pSMB; |
| 3032 | pSMB->Reserved = 0; |
| 3033 | pSMB->TotalParameterCount = cpu_to_le32(parm_len); |
| 3034 | pSMB->TotalDataCount = 0; |
| 3035 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 3036 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3037 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3038 | pSMB->DataCount = pSMB->TotalDataCount; |
| 3039 | temp_offset = offsetof(struct smb_com_ntransact_req, Parms) + |
| 3040 | (setup_count * 2) - 4 /* for rfc1001 length itself */; |
| 3041 | pSMB->ParameterOffset = cpu_to_le32(temp_offset); |
| 3042 | pSMB->DataOffset = cpu_to_le32(temp_offset + parm_len); |
| 3043 | pSMB->SetupCount = setup_count; /* no need to le convert byte fields */ |
| 3044 | pSMB->SubCommand = cpu_to_le16(sub_command); |
| 3045 | return 0; |
| 3046 | } |
| 3047 | |
| 3048 | static int |
| 3049 | validate_ntransact(char *buf, char **ppparm, char **ppdata, |
| 3050 | __u32 *pparmlen, __u32 *pdatalen) |
| 3051 | { |
| 3052 | char *end_of_smb; |
| 3053 | __u32 data_count, data_offset, parm_count, parm_offset; |
| 3054 | struct smb_com_ntransact_rsp *pSMBr; |
| 3055 | |
| 3056 | *pdatalen = 0; |
| 3057 | *pparmlen = 0; |
| 3058 | |
| 3059 | if (buf == NULL) |
| 3060 | return -EINVAL; |
| 3061 | |
| 3062 | pSMBr = (struct smb_com_ntransact_rsp *)buf; |
| 3063 | |
| 3064 | /* ByteCount was converted from little endian in SendReceive */ |
| 3065 | end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + |
| 3066 | (char *)&pSMBr->ByteCount; |
| 3067 | |
| 3068 | data_offset = le32_to_cpu(pSMBr->DataOffset); |
| 3069 | data_count = le32_to_cpu(pSMBr->DataCount); |
| 3070 | parm_offset = le32_to_cpu(pSMBr->ParameterOffset); |
| 3071 | parm_count = le32_to_cpu(pSMBr->ParameterCount); |
| 3072 | |
| 3073 | *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; |
| 3074 | *ppdata = (char *)&pSMBr->hdr.Protocol + data_offset; |
| 3075 | |
| 3076 | /* should we also check that parm and data areas do not overlap? */ |
| 3077 | if (*ppparm > end_of_smb) { |
| 3078 | cFYI(1, "parms start after end of smb"); |
| 3079 | return -EINVAL; |
| 3080 | } else if (parm_count + *ppparm > end_of_smb) { |
| 3081 | cFYI(1, "parm end after end of smb"); |
| 3082 | return -EINVAL; |
| 3083 | } else if (*ppdata > end_of_smb) { |
| 3084 | cFYI(1, "data starts after end of smb"); |
| 3085 | return -EINVAL; |
| 3086 | } else if (data_count + *ppdata > end_of_smb) { |
| 3087 | cFYI(1, "data %p + count %d (%p) past smb end %p start %p", |
| 3088 | *ppdata, data_count, (data_count + *ppdata), |
| 3089 | end_of_smb, pSMBr); |
| 3090 | return -EINVAL; |
| 3091 | } else if (parm_count + data_count > pSMBr->ByteCount) { |
| 3092 | cFYI(1, "parm count and data count larger than SMB"); |
| 3093 | return -EINVAL; |
| 3094 | } |
| 3095 | *pdatalen = data_count; |
| 3096 | *pparmlen = parm_count; |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3100 | /* Get Security Descriptor (by handle) from remote server for a file or dir */ |
| 3101 | int |
| 3102 | CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3103 | struct cifs_ntsd **acl_inf, __u32 *pbuflen) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3104 | { |
| 3105 | int rc = 0; |
| 3106 | int buf_type = 0; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3107 | QUERY_SEC_DESC_REQ *pSMB; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3108 | struct kvec iov[1]; |
| 3109 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3110 | cFYI(1, "GetCifsACL"); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3111 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3112 | *pbuflen = 0; |
| 3113 | *acl_inf = NULL; |
| 3114 | |
Steve French | b9c7a2b | 2007-10-26 23:40:20 +0000 | [diff] [blame] | 3115 | rc = smb_init_nttransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3116 | 8 /* parm len */, tcon, (void **) &pSMB); |
| 3117 | if (rc) |
| 3118 | return rc; |
| 3119 | |
| 3120 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3121 | /* BB TEST with big acls that might need to be e.g. larger than 16K */ |
| 3122 | pSMB->MaxSetupCount = 0; |
| 3123 | pSMB->Fid = fid; /* file handle always le */ |
| 3124 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_OWNER | CIFS_ACL_GROUP | |
| 3125 | CIFS_ACL_DACL); |
| 3126 | pSMB->ByteCount = cpu_to_le16(11); /* 3 bytes pad + 8 bytes parm */ |
| 3127 | pSMB->hdr.smb_buf_length += 11; |
| 3128 | iov[0].iov_base = (char *)pSMB; |
| 3129 | iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; |
| 3130 | |
Steve French | a761ac5 | 2007-10-18 21:45:27 +0000 | [diff] [blame] | 3131 | rc = SendReceive2(xid, tcon->ses, iov, 1 /* num iovec */, &buf_type, |
Jeff Layton | 7749981 | 2011-01-11 07:24:23 -0500 | [diff] [blame] | 3132 | 0); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3133 | cifs_stats_inc(&tcon->num_acl_get); |
| 3134 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3135 | cFYI(1, "Send error in QuerySecDesc = %d", rc); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3136 | } else { /* decode response */ |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3137 | __le32 *parm; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3138 | __u32 parm_len; |
| 3139 | __u32 acl_len; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3140 | struct smb_com_ntransact_rsp *pSMBr; |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3141 | char *pdata; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3142 | |
| 3143 | /* validate_nttransact */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3144 | rc = validate_ntransact(iov[0].iov_base, (char **)&parm, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3145 | &pdata, &parm_len, pbuflen); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3146 | if (rc) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3147 | goto qsec_out; |
| 3148 | pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; |
| 3149 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3150 | cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf); |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3151 | |
| 3152 | if (le32_to_cpu(pSMBr->ParameterCount) != 4) { |
| 3153 | rc = -EIO; /* bad smb */ |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3154 | *pbuflen = 0; |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3155 | goto qsec_out; |
| 3156 | } |
| 3157 | |
| 3158 | /* BB check that data area is minimum length and as big as acl_len */ |
| 3159 | |
Steve French | af6f461 | 2007-10-16 18:40:37 +0000 | [diff] [blame] | 3160 | acl_len = le32_to_cpu(*parm); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3161 | if (acl_len != *pbuflen) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3162 | cERROR(1, "acl length %d does not match %d", |
| 3163 | acl_len, *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3164 | if (*pbuflen > acl_len) |
| 3165 | *pbuflen = acl_len; |
| 3166 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3167 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3168 | /* check if buffer is big enough for the acl |
| 3169 | header followed by the smallest SID */ |
| 3170 | if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) || |
| 3171 | (*pbuflen >= 64 * 1024)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3172 | cERROR(1, "bad acl length %d", *pbuflen); |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3173 | rc = -EINVAL; |
| 3174 | *pbuflen = 0; |
| 3175 | } else { |
| 3176 | *acl_inf = kmalloc(*pbuflen, GFP_KERNEL); |
| 3177 | if (*acl_inf == NULL) { |
| 3178 | *pbuflen = 0; |
| 3179 | rc = -ENOMEM; |
| 3180 | } |
| 3181 | memcpy(*acl_inf, pdata, *pbuflen); |
| 3182 | } |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3183 | } |
| 3184 | qsec_out: |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3185 | if (buf_type == CIFS_SMALL_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3186 | cifs_small_buf_release(iov[0].iov_base); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3187 | else if (buf_type == CIFS_LARGE_BUFFER) |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3188 | cifs_buf_release(iov[0].iov_base); |
Steve French | 4b8f930 | 2006-02-26 16:41:18 +0000 | [diff] [blame] | 3189 | /* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3190 | return rc; |
| 3191 | } |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3192 | |
| 3193 | int |
| 3194 | CIFSSMBSetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, |
| 3195 | struct cifs_ntsd *pntsd, __u32 acllen) |
| 3196 | { |
| 3197 | __u16 byte_count, param_count, data_count, param_offset, data_offset; |
| 3198 | int rc = 0; |
| 3199 | int bytes_returned = 0; |
| 3200 | SET_SEC_DESC_REQ *pSMB = NULL; |
| 3201 | NTRANSACT_RSP *pSMBr = NULL; |
| 3202 | |
| 3203 | setCifsAclRetry: |
| 3204 | rc = smb_init(SMB_COM_NT_TRANSACT, 19, tcon, (void **) &pSMB, |
| 3205 | (void **) &pSMBr); |
| 3206 | if (rc) |
| 3207 | return (rc); |
| 3208 | |
| 3209 | pSMB->MaxSetupCount = 0; |
| 3210 | pSMB->Reserved = 0; |
| 3211 | |
| 3212 | param_count = 8; |
| 3213 | param_offset = offsetof(struct smb_com_transaction_ssec_req, Fid) - 4; |
| 3214 | data_count = acllen; |
| 3215 | data_offset = param_offset + param_count; |
| 3216 | byte_count = 3 /* pad */ + param_count; |
| 3217 | |
| 3218 | pSMB->DataCount = cpu_to_le32(data_count); |
| 3219 | pSMB->TotalDataCount = pSMB->DataCount; |
| 3220 | pSMB->MaxParameterCount = cpu_to_le32(4); |
| 3221 | pSMB->MaxDataCount = cpu_to_le32(16384); |
| 3222 | pSMB->ParameterCount = cpu_to_le32(param_count); |
| 3223 | pSMB->ParameterOffset = cpu_to_le32(param_offset); |
| 3224 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 3225 | pSMB->DataOffset = cpu_to_le32(data_offset); |
| 3226 | pSMB->SetupCount = 0; |
| 3227 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_SET_SECURITY_DESC); |
| 3228 | pSMB->ByteCount = cpu_to_le16(byte_count+data_count); |
| 3229 | |
| 3230 | pSMB->Fid = fid; /* file handle always le */ |
| 3231 | pSMB->Reserved2 = 0; |
| 3232 | pSMB->AclFlags = cpu_to_le32(CIFS_ACL_DACL); |
| 3233 | |
| 3234 | if (pntsd && acllen) { |
| 3235 | memcpy((char *) &pSMBr->hdr.Protocol + data_offset, |
| 3236 | (char *) pntsd, |
| 3237 | acllen); |
| 3238 | pSMB->hdr.smb_buf_length += (byte_count + data_count); |
| 3239 | |
| 3240 | } else |
| 3241 | pSMB->hdr.smb_buf_length += byte_count; |
| 3242 | |
| 3243 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3244 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3245 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3246 | cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3247 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3248 | cFYI(1, "Set CIFS ACL returned %d", rc); |
Steve French | 9783758 | 2007-12-31 07:47:21 +0000 | [diff] [blame] | 3249 | cifs_buf_release(pSMB); |
| 3250 | |
| 3251 | if (rc == -EAGAIN) |
| 3252 | goto setCifsAclRetry; |
| 3253 | |
| 3254 | return (rc); |
| 3255 | } |
| 3256 | |
Jeff Layton | 79df1ba | 2010-12-06 12:52:08 -0500 | [diff] [blame] | 3257 | #endif /* CONFIG_CIFS_ACL */ |
Steve French | 0a4b92c | 2006-01-12 15:44:21 -0800 | [diff] [blame] | 3258 | |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3259 | /* Legacy Query Path Information call for lookup to old servers such |
| 3260 | as Win9x/WinME */ |
| 3261 | int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3262 | const unsigned char *searchName, |
| 3263 | FILE_ALL_INFO *pFinfo, |
| 3264 | const struct nls_table *nls_codepage, int remap) |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3265 | { |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3266 | QUERY_INFORMATION_REQ *pSMB; |
| 3267 | QUERY_INFORMATION_RSP *pSMBr; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3268 | int rc = 0; |
| 3269 | int bytes_returned; |
| 3270 | int name_len; |
| 3271 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3272 | cFYI(1, "In SMBQPath path %s", searchName); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3273 | QInfRetry: |
| 3274 | rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3275 | (void **) &pSMBr); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3276 | if (rc) |
| 3277 | return rc; |
| 3278 | |
| 3279 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3280 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3281 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
| 3282 | PATH_MAX, nls_codepage, remap); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3283 | name_len++; /* trailing null */ |
| 3284 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3285 | } else { |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3286 | name_len = strnlen(searchName, PATH_MAX); |
| 3287 | name_len++; /* trailing null */ |
| 3288 | strncpy(pSMB->FileName, searchName, name_len); |
| 3289 | } |
| 3290 | pSMB->BufferFormat = 0x04; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3291 | name_len++; /* account for buffer type byte */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3292 | pSMB->hdr.smb_buf_length += (__u16) name_len; |
| 3293 | pSMB->ByteCount = cpu_to_le16(name_len); |
| 3294 | |
| 3295 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3296 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3297 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3298 | cFYI(1, "Send error in QueryInfo = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3299 | } else if (pFinfo) { |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3300 | struct timespec ts; |
| 3301 | __u32 time = le32_to_cpu(pSMBr->last_write_time); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3302 | |
| 3303 | /* decode response */ |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3304 | /* BB FIXME - add time zone adjustment BB */ |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3305 | memset(pFinfo, 0, sizeof(FILE_ALL_INFO)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3306 | ts.tv_nsec = 0; |
| 3307 | ts.tv_sec = time; |
| 3308 | /* decode time fields */ |
Al Viro | 733f99a | 2006-10-14 16:48:26 +0100 | [diff] [blame] | 3309 | pFinfo->ChangeTime = cpu_to_le64(cifs_UnixTimeToNT(ts)); |
Steve French | 1bd5bbc | 2006-09-28 03:35:57 +0000 | [diff] [blame] | 3310 | pFinfo->LastWriteTime = pFinfo->ChangeTime; |
| 3311 | pFinfo->LastAccessTime = 0; |
Steve French | 70ca734 | 2005-09-22 16:32:06 -0700 | [diff] [blame] | 3312 | pFinfo->AllocationSize = |
| 3313 | cpu_to_le64(le32_to_cpu(pSMBr->size)); |
| 3314 | pFinfo->EndOfFile = pFinfo->AllocationSize; |
| 3315 | pFinfo->Attributes = |
| 3316 | cpu_to_le32(le16_to_cpu(pSMBr->attr)); |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3317 | } else |
| 3318 | rc = -EIO; /* bad buffer passed in */ |
| 3319 | |
| 3320 | cifs_buf_release(pSMB); |
| 3321 | |
| 3322 | if (rc == -EAGAIN) |
| 3323 | goto QInfRetry; |
| 3324 | |
| 3325 | return rc; |
| 3326 | } |
| 3327 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3328 | int |
| 3329 | CIFSSMBQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3330 | u16 netfid, FILE_ALL_INFO *pFindData) |
| 3331 | { |
| 3332 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3333 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3334 | int rc = 0; |
| 3335 | int bytes_returned; |
| 3336 | __u16 params, byte_count; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3337 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3338 | QFileInfoRetry: |
| 3339 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3340 | (void **) &pSMBr); |
| 3341 | if (rc) |
| 3342 | return rc; |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3343 | |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3344 | params = 2 /* level */ + 2 /* fid */; |
| 3345 | pSMB->t2.TotalDataCount = 0; |
| 3346 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3347 | /* BB find exact max data count below from sess structure BB */ |
| 3348 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3349 | pSMB->t2.MaxSetupCount = 0; |
| 3350 | pSMB->t2.Reserved = 0; |
| 3351 | pSMB->t2.Flags = 0; |
| 3352 | pSMB->t2.Timeout = 0; |
| 3353 | pSMB->t2.Reserved2 = 0; |
| 3354 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3355 | Fid) - 4); |
| 3356 | pSMB->t2.DataCount = 0; |
| 3357 | pSMB->t2.DataOffset = 0; |
| 3358 | pSMB->t2.SetupCount = 1; |
| 3359 | pSMB->t2.Reserved3 = 0; |
| 3360 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3361 | byte_count = params + 1 /* pad */ ; |
| 3362 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3363 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3364 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
| 3365 | pSMB->Pad = 0; |
| 3366 | pSMB->Fid = netfid; |
| 3367 | pSMB->hdr.smb_buf_length += byte_count; |
| 3368 | |
| 3369 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3370 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3371 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3372 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | bcd5357 | 2010-02-12 07:44:16 -0500 | [diff] [blame] | 3373 | } else { /* decode response */ |
| 3374 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3375 | |
| 3376 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3377 | rc = -EIO; |
| 3378 | else if (pSMBr->ByteCount < 40) |
| 3379 | rc = -EIO; /* bad smb */ |
| 3380 | else if (pFindData) { |
| 3381 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3382 | memcpy((char *) pFindData, |
| 3383 | (char *) &pSMBr->hdr.Protocol + |
| 3384 | data_offset, sizeof(FILE_ALL_INFO)); |
| 3385 | } else |
| 3386 | rc = -ENOMEM; |
| 3387 | } |
| 3388 | cifs_buf_release(pSMB); |
| 3389 | if (rc == -EAGAIN) |
| 3390 | goto QFileInfoRetry; |
| 3391 | |
| 3392 | return rc; |
| 3393 | } |
Steve French | 6b8edfe | 2005-08-23 20:26:03 -0700 | [diff] [blame] | 3394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | int |
| 3396 | CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3397 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3398 | FILE_ALL_INFO *pFindData, |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3399 | int legacy /* old style infolevel */, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3400 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | { |
| 3402 | /* level 263 SMB_QUERY_FILE_ALL_INFO */ |
| 3403 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3404 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3405 | int rc = 0; |
| 3406 | int bytes_returned; |
| 3407 | int name_len; |
| 3408 | __u16 params, byte_count; |
| 3409 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3410 | /* cFYI(1, "In QPathInfo path %s", searchName); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3411 | QPathInfoRetry: |
| 3412 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3413 | (void **) &pSMBr); |
| 3414 | if (rc) |
| 3415 | return rc; |
| 3416 | |
| 3417 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3418 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3419 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3420 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | name_len++; /* trailing null */ |
| 3422 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3423 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | name_len = strnlen(searchName, PATH_MAX); |
| 3425 | name_len++; /* trailing null */ |
| 3426 | strncpy(pSMB->FileName, searchName, name_len); |
| 3427 | } |
| 3428 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3429 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | pSMB->TotalDataCount = 0; |
| 3431 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3432 | /* BB find exact max SMB PDU from sess structure BB */ |
| 3433 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | pSMB->MaxSetupCount = 0; |
| 3435 | pSMB->Reserved = 0; |
| 3436 | pSMB->Flags = 0; |
| 3437 | pSMB->Timeout = 0; |
| 3438 | pSMB->Reserved2 = 0; |
| 3439 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3440 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | pSMB->DataCount = 0; |
| 3442 | pSMB->DataOffset = 0; |
| 3443 | pSMB->SetupCount = 1; |
| 3444 | pSMB->Reserved3 = 0; |
| 3445 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3446 | byte_count = params + 1 /* pad */ ; |
| 3447 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3448 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3449 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3450 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_STANDARD); |
| 3451 | else |
| 3452 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | pSMB->Reserved4 = 0; |
| 3454 | pSMB->hdr.smb_buf_length += byte_count; |
| 3455 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3456 | |
| 3457 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3458 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3459 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3460 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3461 | } else { /* decode response */ |
| 3462 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3463 | |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3464 | if (rc) /* BB add auto retry on EOPNOTSUPP? */ |
| 3465 | rc = -EIO; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3466 | else if (!legacy && (pSMBr->ByteCount < 40)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3467 | rc = -EIO; /* bad smb */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3468 | else if (legacy && (pSMBr->ByteCount < 24)) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3469 | rc = -EIO; /* 24 or 26 expected but we do not read |
| 3470 | last field */ |
| 3471 | else if (pFindData) { |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3472 | int size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3473 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3474 | |
| 3475 | /* On legacy responses we do not read the last field, |
| 3476 | EAsize, fortunately since it varies by subdialect and |
| 3477 | also note it differs on Set vs. Get, ie two bytes or 4 |
| 3478 | bytes depending but we don't care here */ |
| 3479 | if (legacy) |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3480 | size = sizeof(FILE_INFO_STANDARD); |
| 3481 | else |
| 3482 | size = sizeof(FILE_ALL_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3483 | memcpy((char *) pFindData, |
| 3484 | (char *) &pSMBr->hdr.Protocol + |
Steve French | acf1a1b | 2006-10-12 03:28:28 +0000 | [diff] [blame] | 3485 | data_offset, size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } else |
| 3487 | rc = -ENOMEM; |
| 3488 | } |
| 3489 | cifs_buf_release(pSMB); |
| 3490 | if (rc == -EAGAIN) |
| 3491 | goto QPathInfoRetry; |
| 3492 | |
| 3493 | return rc; |
| 3494 | } |
| 3495 | |
| 3496 | int |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3497 | CIFSSMBUnixQFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 3498 | u16 netfid, FILE_UNIX_BASIC_INFO *pFindData) |
| 3499 | { |
| 3500 | struct smb_t2_qfi_req *pSMB = NULL; |
| 3501 | struct smb_t2_qfi_rsp *pSMBr = NULL; |
| 3502 | int rc = 0; |
| 3503 | int bytes_returned; |
| 3504 | __u16 params, byte_count; |
| 3505 | |
| 3506 | UnixQFileInfoRetry: |
| 3507 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3508 | (void **) &pSMBr); |
| 3509 | if (rc) |
| 3510 | return rc; |
| 3511 | |
| 3512 | params = 2 /* level */ + 2 /* fid */; |
| 3513 | pSMB->t2.TotalDataCount = 0; |
| 3514 | pSMB->t2.MaxParameterCount = cpu_to_le16(4); |
| 3515 | /* BB find exact max data count below from sess structure BB */ |
| 3516 | pSMB->t2.MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
| 3517 | pSMB->t2.MaxSetupCount = 0; |
| 3518 | pSMB->t2.Reserved = 0; |
| 3519 | pSMB->t2.Flags = 0; |
| 3520 | pSMB->t2.Timeout = 0; |
| 3521 | pSMB->t2.Reserved2 = 0; |
| 3522 | pSMB->t2.ParameterOffset = cpu_to_le16(offsetof(struct smb_t2_qfi_req, |
| 3523 | Fid) - 4); |
| 3524 | pSMB->t2.DataCount = 0; |
| 3525 | pSMB->t2.DataOffset = 0; |
| 3526 | pSMB->t2.SetupCount = 1; |
| 3527 | pSMB->t2.Reserved3 = 0; |
| 3528 | pSMB->t2.SubCommand = cpu_to_le16(TRANS2_QUERY_FILE_INFORMATION); |
| 3529 | byte_count = params + 1 /* pad */ ; |
| 3530 | pSMB->t2.TotalParameterCount = cpu_to_le16(params); |
| 3531 | pSMB->t2.ParameterCount = pSMB->t2.TotalParameterCount; |
| 3532 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3533 | pSMB->Pad = 0; |
| 3534 | pSMB->Fid = netfid; |
| 3535 | pSMB->hdr.smb_buf_length += byte_count; |
| 3536 | |
| 3537 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3538 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3539 | if (rc) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3540 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3541 | } else { /* decode response */ |
| 3542 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3543 | |
| 3544 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3545 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3546 | "Unix Extensions can be disabled on mount " |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 3547 | "by specifying the nosfu mount option."); |
Jeff Layton | c8634fd | 2010-02-12 07:44:17 -0500 | [diff] [blame] | 3548 | rc = -EIO; /* bad smb */ |
| 3549 | } else { |
| 3550 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3551 | memcpy((char *) pFindData, |
| 3552 | (char *) &pSMBr->hdr.Protocol + |
| 3553 | data_offset, |
| 3554 | sizeof(FILE_UNIX_BASIC_INFO)); |
| 3555 | } |
| 3556 | } |
| 3557 | |
| 3558 | cifs_buf_release(pSMB); |
| 3559 | if (rc == -EAGAIN) |
| 3560 | goto UnixQFileInfoRetry; |
| 3561 | |
| 3562 | return rc; |
| 3563 | } |
| 3564 | |
| 3565 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3566 | CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 3567 | const unsigned char *searchName, |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 3568 | FILE_UNIX_BASIC_INFO *pFindData, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3569 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | { |
| 3571 | /* SMB_QUERY_FILE_UNIX_BASIC */ |
| 3572 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3573 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3574 | int rc = 0; |
| 3575 | int bytes_returned = 0; |
| 3576 | int name_len; |
| 3577 | __u16 params, byte_count; |
| 3578 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3579 | cFYI(1, "In QPathInfo (Unix) the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3580 | UnixQPathInfoRetry: |
| 3581 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3582 | (void **) &pSMBr); |
| 3583 | if (rc) |
| 3584 | return rc; |
| 3585 | |
| 3586 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3587 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3588 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3589 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | name_len++; /* trailing null */ |
| 3591 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3592 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | name_len = strnlen(searchName, PATH_MAX); |
| 3594 | name_len++; /* trailing null */ |
| 3595 | strncpy(pSMB->FileName, searchName, name_len); |
| 3596 | } |
| 3597 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3598 | params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | pSMB->TotalDataCount = 0; |
| 3600 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 3601 | /* BB find exact max SMB PDU from sess structure BB */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3602 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | pSMB->MaxSetupCount = 0; |
| 3604 | pSMB->Reserved = 0; |
| 3605 | pSMB->Flags = 0; |
| 3606 | pSMB->Timeout = 0; |
| 3607 | pSMB->Reserved2 = 0; |
| 3608 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3609 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | pSMB->DataCount = 0; |
| 3611 | pSMB->DataOffset = 0; |
| 3612 | pSMB->SetupCount = 1; |
| 3613 | pSMB->Reserved3 = 0; |
| 3614 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 3615 | byte_count = params + 1 /* pad */ ; |
| 3616 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3617 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3618 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC); |
| 3619 | pSMB->Reserved4 = 0; |
| 3620 | pSMB->hdr.smb_buf_length += byte_count; |
| 3621 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3622 | |
| 3623 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3624 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 3625 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3626 | cFYI(1, "Send error in QPathInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3627 | } else { /* decode response */ |
| 3628 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 3629 | |
| 3630 | if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3631 | cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n" |
Steve French | 1e71f25 | 2007-09-20 15:30:07 +0000 | [diff] [blame] | 3632 | "Unix Extensions can be disabled on mount " |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3633 | "by specifying the nosfu mount option."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | rc = -EIO; /* bad smb */ |
| 3635 | } else { |
| 3636 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 3637 | memcpy((char *) pFindData, |
| 3638 | (char *) &pSMBr->hdr.Protocol + |
| 3639 | data_offset, |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3640 | sizeof(FILE_UNIX_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3641 | } |
| 3642 | } |
| 3643 | cifs_buf_release(pSMB); |
| 3644 | if (rc == -EAGAIN) |
| 3645 | goto UnixQPathInfoRetry; |
| 3646 | |
| 3647 | return rc; |
| 3648 | } |
| 3649 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | /* xid, tcon, searchName and codepage are input parms, rest are returned */ |
| 3651 | int |
| 3652 | CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3653 | const char *searchName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | const struct nls_table *nls_codepage, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3655 | __u16 *pnetfid, |
| 3656 | struct cifs_search_info *psrch_inf, int remap, const char dirsep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | { |
| 3658 | /* level 257 SMB_ */ |
| 3659 | TRANSACTION2_FFIRST_REQ *pSMB = NULL; |
| 3660 | TRANSACTION2_FFIRST_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3661 | T2_FFIRST_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | int rc = 0; |
| 3663 | int bytes_returned = 0; |
| 3664 | int name_len; |
| 3665 | __u16 params, byte_count; |
| 3666 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3667 | cFYI(1, "In FindFirst for %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | |
| 3669 | findFirstRetry: |
| 3670 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3671 | (void **) &pSMBr); |
| 3672 | if (rc) |
| 3673 | return rc; |
| 3674 | |
| 3675 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3676 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3677 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3678 | PATH_MAX, nls_codepage, remap); |
| 3679 | /* We can not add the asterik earlier in case |
| 3680 | it got remapped to 0xF03A as if it were part of the |
| 3681 | directory name instead of a wildcard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | name_len *= 2; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3683 | pSMB->FileName[name_len] = dirsep; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3684 | pSMB->FileName[name_len+1] = 0; |
| 3685 | pSMB->FileName[name_len+2] = '*'; |
| 3686 | pSMB->FileName[name_len+3] = 0; |
| 3687 | name_len += 4; /* now the trailing null */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3688 | pSMB->FileName[name_len] = 0; /* null terminate just in case */ |
| 3689 | pSMB->FileName[name_len+1] = 0; |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 3690 | name_len += 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | } else { /* BB add check for overrun of SMB buf BB */ |
| 3692 | name_len = strnlen(searchName, PATH_MAX); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | /* BB fix here and in unicode clause above ie |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3694 | if (name_len > buffersize-header) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | free buffer exit; BB */ |
| 3696 | strncpy(pSMB->FileName, searchName, name_len); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 3697 | pSMB->FileName[name_len] = dirsep; |
Steve French | 6857547 | 2005-04-30 11:10:57 -0700 | [diff] [blame] | 3698 | pSMB->FileName[name_len+1] = '*'; |
| 3699 | pSMB->FileName[name_len+2] = 0; |
| 3700 | name_len += 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | } |
| 3702 | |
| 3703 | params = 12 + name_len /* includes null */ ; |
| 3704 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3705 | pSMB->MaxParameterCount = cpu_to_le16(10); |
| 3706 | pSMB->MaxDataCount = cpu_to_le16((tcon->ses->server->maxBuf - |
| 3707 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 3708 | pSMB->MaxSetupCount = 0; |
| 3709 | pSMB->Reserved = 0; |
| 3710 | pSMB->Flags = 0; |
| 3711 | pSMB->Timeout = 0; |
| 3712 | pSMB->Reserved2 = 0; |
| 3713 | byte_count = params + 1 /* pad */ ; |
| 3714 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3715 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3716 | pSMB->ParameterOffset = cpu_to_le16( |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3717 | offsetof(struct smb_com_transaction2_ffirst_req, SearchAttributes) |
| 3718 | - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | pSMB->DataCount = 0; |
| 3720 | pSMB->DataOffset = 0; |
| 3721 | pSMB->SetupCount = 1; /* one byte, no need to make endian neutral */ |
| 3722 | pSMB->Reserved3 = 0; |
| 3723 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_FIRST); |
| 3724 | pSMB->SearchAttributes = |
| 3725 | cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | |
| 3726 | ATTR_DIRECTORY); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3727 | pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); |
| 3728 | pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | CIFS_SEARCH_RETURN_RESUME); |
| 3730 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3731 | |
| 3732 | /* BB what should we set StorageType to? Does it matter? BB */ |
| 3733 | pSMB->SearchStorageType = 0; |
| 3734 | pSMB->hdr.smb_buf_length += byte_count; |
| 3735 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 3736 | |
| 3737 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3738 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3739 | cifs_stats_inc(&tcon->num_ffirst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3741 | if (rc) {/* BB add logic to retry regular search if Unix search |
| 3742 | rejected unexpectedly by server */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | /* BB Add code to handle unsupported level rc */ |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3744 | cFYI(1, "Error in FindFirst = %d", rc); |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 3745 | |
Steve French | 8827481 | 2006-03-09 22:21:45 +0000 | [diff] [blame] | 3746 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | |
| 3748 | /* BB eventually could optimize out free and realloc of buf */ |
| 3749 | /* for this case */ |
| 3750 | if (rc == -EAGAIN) |
| 3751 | goto findFirstRetry; |
| 3752 | } else { /* decode response */ |
| 3753 | /* BB remember to free buffer if error BB */ |
| 3754 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3755 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3756 | unsigned int lnoff; |
| 3757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3758 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3759 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3760 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3761 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | |
| 3763 | psrch_inf->ntwrk_buf_start = (char *)pSMBr; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3764 | psrch_inf->smallBuf = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3765 | psrch_inf->srch_entries_start = |
| 3766 | (char *) &pSMBr->hdr.Protocol + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + |
| 3769 | le16_to_cpu(pSMBr->t2.ParameterOffset)); |
| 3770 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3771 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3772 | psrch_inf->endOfSearch = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3774 | psrch_inf->endOfSearch = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3776 | psrch_inf->entries_in_buffer = |
| 3777 | le16_to_cpu(parms->SearchCount); |
Steve French | 6080823 | 2006-04-22 15:53:05 +0000 | [diff] [blame] | 3778 | psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3780 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3781 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3782 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3783 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3784 | psrch_inf->last_entry = NULL; |
| 3785 | return rc; |
| 3786 | } |
| 3787 | |
Steve French | 0752f15 | 2008-10-07 20:03:33 +0000 | [diff] [blame] | 3788 | psrch_inf->last_entry = psrch_inf->srch_entries_start + |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3789 | lnoff; |
| 3790 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | *pnetfid = parms->SearchHandle; |
| 3792 | } else { |
| 3793 | cifs_buf_release(pSMB); |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | return rc; |
| 3798 | } |
| 3799 | |
| 3800 | int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3801 | __u16 searchHandle, struct cifs_search_info *psrch_inf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3802 | { |
| 3803 | TRANSACTION2_FNEXT_REQ *pSMB = NULL; |
| 3804 | TRANSACTION2_FNEXT_RSP *pSMBr = NULL; |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3805 | T2_FNEXT_RSP_PARMS *parms; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | char *response_data; |
| 3807 | int rc = 0; |
| 3808 | int bytes_returned, name_len; |
| 3809 | __u16 params, byte_count; |
| 3810 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3811 | cFYI(1, "In FindNext"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3812 | |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3813 | if (psrch_inf->endOfSearch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | return -ENOENT; |
| 3815 | |
| 3816 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 3817 | (void **) &pSMBr); |
| 3818 | if (rc) |
| 3819 | return rc; |
| 3820 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3821 | params = 14; /* includes 2 bytes of null string, converted to LE below*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3822 | byte_count = 0; |
| 3823 | pSMB->TotalDataCount = 0; /* no EAs */ |
| 3824 | pSMB->MaxParameterCount = cpu_to_le16(8); |
| 3825 | pSMB->MaxDataCount = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3826 | cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & |
| 3827 | 0xFFFFFF00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | pSMB->MaxSetupCount = 0; |
| 3829 | pSMB->Reserved = 0; |
| 3830 | pSMB->Flags = 0; |
| 3831 | pSMB->Timeout = 0; |
| 3832 | pSMB->Reserved2 = 0; |
| 3833 | pSMB->ParameterOffset = cpu_to_le16( |
| 3834 | offsetof(struct smb_com_transaction2_fnext_req,SearchHandle) - 4); |
| 3835 | pSMB->DataCount = 0; |
| 3836 | pSMB->DataOffset = 0; |
| 3837 | pSMB->SetupCount = 1; |
| 3838 | pSMB->Reserved3 = 0; |
| 3839 | pSMB->SubCommand = cpu_to_le16(TRANS2_FIND_NEXT); |
| 3840 | pSMB->SearchHandle = searchHandle; /* always kept as le */ |
| 3841 | pSMB->SearchCount = |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 3842 | cpu_to_le16(CIFSMaxBufSize / sizeof(FILE_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); |
| 3844 | pSMB->ResumeKey = psrch_inf->resume_key; |
| 3845 | pSMB->SearchFlags = |
| 3846 | cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | CIFS_SEARCH_RETURN_RESUME); |
| 3847 | |
| 3848 | name_len = psrch_inf->resume_name_len; |
| 3849 | params += name_len; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3850 | if (name_len < PATH_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3851 | memcpy(pSMB->ResumeFileName, psrch_inf->presume_name, name_len); |
| 3852 | byte_count += name_len; |
Steve French | ef6724e | 2005-08-02 21:31:05 -0700 | [diff] [blame] | 3853 | /* 14 byte parm len above enough for 2 byte null terminator */ |
| 3854 | pSMB->ResumeFileName[name_len] = 0; |
| 3855 | pSMB->ResumeFileName[name_len+1] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | } else { |
| 3857 | rc = -EINVAL; |
| 3858 | goto FNext2_err_exit; |
| 3859 | } |
| 3860 | byte_count = params + 1 /* pad */ ; |
| 3861 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 3862 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 3863 | pSMB->hdr.smb_buf_length += byte_count; |
| 3864 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3865 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 3867 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3868 | cifs_stats_inc(&tcon->num_fnext); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | if (rc) { |
| 3870 | if (rc == -EBADF) { |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3871 | psrch_inf->endOfSearch = true; |
Jeff Layton | 6353450 | 2008-05-12 19:56:05 -0700 | [diff] [blame] | 3872 | cifs_buf_release(pSMB); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3873 | rc = 0; /* search probably was closed at end of search*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3874 | } else |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3875 | cFYI(1, "FindNext returned = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3876 | } else { /* decode response */ |
| 3877 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3878 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3879 | if (rc == 0) { |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3880 | unsigned int lnoff; |
| 3881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3882 | /* BB fixme add lock for file (srch_info) struct here */ |
| 3883 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3884 | psrch_inf->unicode = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3885 | else |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3886 | psrch_inf->unicode = false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3887 | response_data = (char *) &pSMBr->hdr.Protocol + |
| 3888 | le16_to_cpu(pSMBr->t2.ParameterOffset); |
| 3889 | parms = (T2_FNEXT_RSP_PARMS *)response_data; |
| 3890 | response_data = (char *)&pSMBr->hdr.Protocol + |
| 3891 | le16_to_cpu(pSMBr->t2.DataOffset); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3892 | if (psrch_inf->smallBuf) |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3893 | cifs_small_buf_release( |
| 3894 | psrch_inf->ntwrk_buf_start); |
| 3895 | else |
| 3896 | cifs_buf_release(psrch_inf->ntwrk_buf_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3897 | psrch_inf->srch_entries_start = response_data; |
| 3898 | psrch_inf->ntwrk_buf_start = (char *)pSMB; |
Steve French | d47d7c1 | 2006-02-28 03:45:48 +0000 | [diff] [blame] | 3899 | psrch_inf->smallBuf = 0; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3900 | if (parms->EndofSearch) |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 3901 | psrch_inf->endOfSearch = 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->endOfSearch = false; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3904 | psrch_inf->entries_in_buffer = |
| 3905 | le16_to_cpu(parms->SearchCount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3906 | psrch_inf->index_of_last_entry += |
| 3907 | psrch_inf->entries_in_buffer; |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3908 | lnoff = le16_to_cpu(parms->LastNameOffset); |
| 3909 | if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE < |
| 3910 | lnoff) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3911 | cERROR(1, "ignoring corrupt resume name"); |
Steve French | b77d753 | 2008-10-08 19:13:46 +0000 | [diff] [blame] | 3912 | psrch_inf->last_entry = NULL; |
| 3913 | return rc; |
| 3914 | } else |
| 3915 | psrch_inf->last_entry = |
| 3916 | psrch_inf->srch_entries_start + lnoff; |
| 3917 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3918 | /* cFYI(1, "fnxt2 entries in buf %d index_of_last %d", |
| 3919 | psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | |
| 3921 | /* BB fixme add unlock here */ |
| 3922 | } |
| 3923 | |
| 3924 | } |
| 3925 | |
| 3926 | /* BB On error, should we leave previous search buf (and count and |
| 3927 | last entry fields) intact or free the previous one? */ |
| 3928 | |
| 3929 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 3930 | since file handle passed in no longer valid */ |
| 3931 | FNext2_err_exit: |
| 3932 | if (rc != 0) |
| 3933 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | return rc; |
| 3935 | } |
| 3936 | |
| 3937 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3938 | CIFSFindClose(const int xid, struct cifsTconInfo *tcon, |
| 3939 | const __u16 searchHandle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | { |
| 3941 | int rc = 0; |
| 3942 | FINDCLOSE_REQ *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3944 | cFYI(1, "In CIFSSMBFindClose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB); |
| 3946 | |
| 3947 | /* no sense returning error if session restarted |
| 3948 | as file handle has been closed */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3949 | if (rc == -EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | return 0; |
| 3951 | if (rc) |
| 3952 | return rc; |
| 3953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | pSMB->FileID = searchHandle; |
| 3955 | pSMB->ByteCount = 0; |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 3956 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3957 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3958 | cERROR(1, "Send error in FindClose = %d", rc); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3959 | |
Steve French | a4544347 | 2005-08-24 13:59:35 -0700 | [diff] [blame] | 3960 | cifs_stats_inc(&tcon->num_fclose); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3961 | |
| 3962 | /* Since session is dead, search handle closed on server already */ |
| 3963 | if (rc == -EAGAIN) |
| 3964 | rc = 0; |
| 3965 | |
| 3966 | return rc; |
| 3967 | } |
| 3968 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3969 | int |
| 3970 | CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3971 | const unsigned char *searchName, |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 3972 | __u64 *inode_number, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3973 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3974 | { |
| 3975 | int rc = 0; |
| 3976 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 3977 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 3978 | int name_len, bytes_returned; |
| 3979 | __u16 params, byte_count; |
| 3980 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 3981 | cFYI(1, "In GetSrvInodeNum for %s", searchName); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 3982 | if (tcon == NULL) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3983 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3984 | |
| 3985 | GetInodeNumberRetry: |
| 3986 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3987 | (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3988 | if (rc) |
| 3989 | return rc; |
| 3990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3991 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 3992 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 3993 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3994 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3995 | name_len++; /* trailing null */ |
| 3996 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 3997 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | name_len = strnlen(searchName, PATH_MAX); |
| 3999 | name_len++; /* trailing null */ |
| 4000 | strncpy(pSMB->FileName, searchName, name_len); |
| 4001 | } |
| 4002 | |
| 4003 | params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; |
| 4004 | pSMB->TotalDataCount = 0; |
| 4005 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4006 | /* BB find exact max data count below from sess structure BB */ |
| 4007 | pSMB->MaxDataCount = cpu_to_le16(4000); |
| 4008 | pSMB->MaxSetupCount = 0; |
| 4009 | pSMB->Reserved = 0; |
| 4010 | pSMB->Flags = 0; |
| 4011 | pSMB->Timeout = 0; |
| 4012 | pSMB->Reserved2 = 0; |
| 4013 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4014 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4015 | pSMB->DataCount = 0; |
| 4016 | pSMB->DataOffset = 0; |
| 4017 | pSMB->SetupCount = 1; |
| 4018 | pSMB->Reserved3 = 0; |
| 4019 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 4020 | byte_count = params + 1 /* pad */ ; |
| 4021 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4022 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4023 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FILE_INTERNAL_INFO); |
| 4024 | pSMB->Reserved4 = 0; |
| 4025 | pSMB->hdr.smb_buf_length += byte_count; |
| 4026 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4027 | |
| 4028 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4029 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4030 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4031 | cFYI(1, "error %d in QueryInternalInfo", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4032 | } else { |
| 4033 | /* decode response */ |
| 4034 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4035 | if (rc || (pSMBr->ByteCount < 2)) |
| 4036 | /* BB also check enough total bytes returned */ |
| 4037 | /* If rc should we check for EOPNOSUPP and |
| 4038 | disable the srvino flag? or in caller? */ |
| 4039 | rc = -EIO; /* bad smb */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4040 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4041 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4042 | __u16 count = le16_to_cpu(pSMBr->t2.DataCount); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4043 | struct file_internal_info *pfinfo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | /* BB Do we need a cast or hash here ? */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4045 | if (count < 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4046 | cFYI(1, "Illegal size ret in QryIntrnlInf"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | rc = -EIO; |
| 4048 | goto GetInodeNumOut; |
| 4049 | } |
| 4050 | pfinfo = (struct file_internal_info *) |
| 4051 | (data_offset + (char *) &pSMBr->hdr.Protocol); |
Steve French | 85a6dac | 2009-04-01 05:22:00 +0000 | [diff] [blame] | 4052 | *inode_number = le64_to_cpu(pfinfo->UniqueId); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | } |
| 4054 | } |
| 4055 | GetInodeNumOut: |
| 4056 | cifs_buf_release(pSMB); |
| 4057 | if (rc == -EAGAIN) |
| 4058 | goto GetInodeNumberRetry; |
| 4059 | return rc; |
| 4060 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4061 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4062 | /* parses DFS refferal V3 structure |
| 4063 | * caller is responsible for freeing target_nodes |
| 4064 | * returns: |
| 4065 | * on success - 0 |
| 4066 | * on failure - errno |
| 4067 | */ |
| 4068 | static int |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4069 | parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr, |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4070 | unsigned int *num_of_nodes, |
| 4071 | struct dfs_info3_param **target_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4072 | const struct nls_table *nls_codepage, int remap, |
| 4073 | const char *searchName) |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4074 | { |
| 4075 | int i, rc = 0; |
| 4076 | char *data_end; |
| 4077 | bool is_unicode; |
| 4078 | struct dfs_referral_level_3 *ref; |
| 4079 | |
Harvey Harrison | 5ca33c6 | 2008-07-23 17:45:58 -0700 | [diff] [blame] | 4080 | if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) |
| 4081 | is_unicode = true; |
| 4082 | else |
| 4083 | is_unicode = false; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4084 | *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals); |
| 4085 | |
| 4086 | if (*num_of_nodes < 1) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4087 | cERROR(1, "num_referrals: must be at least > 0," |
| 4088 | "but we get num_referrals = %d\n", *num_of_nodes); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4089 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4090 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals); |
Al Viro | 1d92cfd | 2008-06-02 10:59:02 +0100 | [diff] [blame] | 4094 | if (ref->VersionNumber != cpu_to_le16(3)) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4095 | cERROR(1, "Referrals of V%d version are not supported," |
| 4096 | "should be V3", le16_to_cpu(ref->VersionNumber)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4097 | rc = -EINVAL; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4098 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | /* get the upper boundary of the resp buffer */ |
| 4102 | data_end = (char *)(&(pSMBr->PathConsumed)) + |
| 4103 | le16_to_cpu(pSMBr->t2.DataCount); |
| 4104 | |
Steve French | f19159d | 2010-04-21 04:12:10 +0000 | [diff] [blame] | 4105 | cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4106 | *num_of_nodes, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4107 | le32_to_cpu(pSMBr->DFSFlags)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4108 | |
| 4109 | *target_nodes = kzalloc(sizeof(struct dfs_info3_param) * |
| 4110 | *num_of_nodes, GFP_KERNEL); |
| 4111 | if (*target_nodes == NULL) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4112 | cERROR(1, "Failed to allocate buffer for target_nodes\n"); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4113 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4114 | goto parse_DFS_referrals_exit; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4115 | } |
| 4116 | |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 4117 | /* collect necessary data from referrals */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4118 | for (i = 0; i < *num_of_nodes; i++) { |
| 4119 | char *temp; |
| 4120 | int max_len; |
| 4121 | struct dfs_info3_param *node = (*target_nodes)+i; |
| 4122 | |
Steve French | 0e0d2cf | 2009-05-01 05:27:32 +0000 | [diff] [blame] | 4123 | node->flags = le32_to_cpu(pSMBr->DFSFlags); |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4124 | if (is_unicode) { |
Jeff Layton | 331c313 | 2008-12-17 06:31:53 -0500 | [diff] [blame] | 4125 | __le16 *tmp = kmalloc(strlen(searchName)*2 + 2, |
| 4126 | GFP_KERNEL); |
Steve French | 2920ee2 | 2009-08-31 15:27:26 +0000 | [diff] [blame] | 4127 | if (tmp == NULL) { |
| 4128 | rc = -ENOMEM; |
| 4129 | goto parse_DFS_referrals_exit; |
| 4130 | } |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4131 | cifsConvertToUCS((__le16 *) tmp, searchName, |
| 4132 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 69f801f | 2009-04-30 06:46:32 -0400 | [diff] [blame] | 4133 | node->path_consumed = cifs_ucs2_bytes(tmp, |
| 4134 | le16_to_cpu(pSMBr->PathConsumed), |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4135 | nls_codepage); |
| 4136 | kfree(tmp); |
| 4137 | } else |
| 4138 | node->path_consumed = le16_to_cpu(pSMBr->PathConsumed); |
| 4139 | |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4140 | node->server_type = le16_to_cpu(ref->ServerType); |
| 4141 | node->ref_flag = le16_to_cpu(ref->ReferralEntryFlags); |
| 4142 | |
| 4143 | /* copy DfsPath */ |
| 4144 | temp = (char *)ref + le16_to_cpu(ref->DfsPathOffset); |
| 4145 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4146 | node->path_name = cifs_strndup_from_ucs(temp, max_len, |
| 4147 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4148 | if (!node->path_name) { |
| 4149 | rc = -ENOMEM; |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4150 | goto parse_DFS_referrals_exit; |
Jeff Layton | 066ce68 | 2009-04-30 07:16:14 -0400 | [diff] [blame] | 4151 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4152 | |
| 4153 | /* copy link target UNC */ |
| 4154 | temp = (char *)ref + le16_to_cpu(ref->NetworkAddressOffset); |
| 4155 | max_len = data_end - temp; |
Steve French | d185cda | 2009-04-30 17:45:10 +0000 | [diff] [blame] | 4156 | node->node_name = cifs_strndup_from_ucs(temp, max_len, |
| 4157 | is_unicode, nls_codepage); |
Jeff Layton | d8e2f53 | 2009-05-14 07:46:59 -0400 | [diff] [blame] | 4158 | if (!node->node_name) |
| 4159 | rc = -ENOMEM; |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4160 | } |
| 4161 | |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4162 | parse_DFS_referrals_exit: |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4163 | if (rc) { |
| 4164 | free_dfs_info_array(*target_nodes, *num_of_nodes); |
| 4165 | *target_nodes = NULL; |
| 4166 | *num_of_nodes = 0; |
| 4167 | } |
| 4168 | return rc; |
| 4169 | } |
| 4170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | int |
| 4172 | CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses, |
| 4173 | const unsigned char *searchName, |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4174 | struct dfs_info3_param **target_nodes, |
| 4175 | unsigned int *num_of_nodes, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4176 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | { |
| 4178 | /* TRANS2_GET_DFS_REFERRAL */ |
| 4179 | TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; |
| 4180 | TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | int rc = 0; |
| 4182 | int bytes_returned; |
| 4183 | int name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4184 | __u16 params, byte_count; |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4185 | *num_of_nodes = 0; |
| 4186 | *target_nodes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4188 | cFYI(1, "In GetDFSRefer the path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4189 | if (ses == NULL) |
| 4190 | return -ENODEV; |
| 4191 | getDFSRetry: |
| 4192 | rc = smb_init(SMB_COM_TRANSACTION2, 15, NULL, (void **) &pSMB, |
| 4193 | (void **) &pSMBr); |
| 4194 | if (rc) |
| 4195 | return rc; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4196 | |
| 4197 | /* server pointer checked in called function, |
Steve French | 1982c34 | 2005-08-17 12:38:22 -0700 | [diff] [blame] | 4198 | but should never be null here anyway */ |
| 4199 | pSMB->hdr.Mid = GetNextMid(ses->server); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4200 | pSMB->hdr.Tid = ses->ipc_tid; |
| 4201 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4202 | if (ses->capabilities & CAP_STATUS32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | pSMB->hdr.Flags2 |= SMBFLG2_ERR_STATUS; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4204 | if (ses->capabilities & CAP_DFS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | pSMB->hdr.Flags2 |= SMBFLG2_DFS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4206 | |
| 4207 | if (ses->capabilities & CAP_UNICODE) { |
| 4208 | pSMB->hdr.Flags2 |= SMBFLG2_UNICODE; |
| 4209 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4210 | cifsConvertToUCS((__le16 *) pSMB->RequestFileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4211 | searchName, PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | name_len++; /* trailing null */ |
| 4213 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4214 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4215 | name_len = strnlen(searchName, PATH_MAX); |
| 4216 | name_len++; /* trailing null */ |
| 4217 | strncpy(pSMB->RequestFileName, searchName, name_len); |
| 4218 | } |
| 4219 | |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4220 | if (ses->server) { |
| 4221 | if (ses->server->secMode & |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4222 | (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) |
| 4223 | pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; |
| 4224 | } |
| 4225 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4226 | pSMB->hdr.Uid = ses->Suid; |
Steve French | 1a4e15a | 2006-10-12 21:33:51 +0000 | [diff] [blame] | 4227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4228 | params = 2 /* level */ + name_len /*includes null */ ; |
| 4229 | pSMB->TotalDataCount = 0; |
| 4230 | pSMB->DataCount = 0; |
| 4231 | pSMB->DataOffset = 0; |
| 4232 | pSMB->MaxParameterCount = 0; |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4233 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4234 | pSMB->MaxDataCount = cpu_to_le16(4000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | pSMB->MaxSetupCount = 0; |
| 4236 | pSMB->Reserved = 0; |
| 4237 | pSMB->Flags = 0; |
| 4238 | pSMB->Timeout = 0; |
| 4239 | pSMB->Reserved2 = 0; |
| 4240 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4241 | struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4242 | pSMB->SetupCount = 1; |
| 4243 | pSMB->Reserved3 = 0; |
| 4244 | pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); |
| 4245 | byte_count = params + 3 /* pad */ ; |
| 4246 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4247 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4248 | pSMB->MaxReferralLevel = cpu_to_le16(3); |
| 4249 | pSMB->hdr.smb_buf_length += byte_count; |
| 4250 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4251 | |
| 4252 | rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, |
| 4253 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4254 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4255 | cFYI(1, "Send error in GetDFSRefer = %d", rc); |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4256 | goto GetDFSRefExit; |
| 4257 | } |
| 4258 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4260 | /* BB Also check if enough total bytes returned? */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4261 | if (rc || (pSMBr->ByteCount < 17)) { |
Steve French | c2cf07d | 2008-05-15 06:20:02 +0000 | [diff] [blame] | 4262 | rc = -EIO; /* bad smb */ |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4263 | goto GetDFSRefExit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | } |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4265 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4266 | cFYI(1, "Decoding GetDFSRefer response BCC: %d Offset %d", |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4267 | pSMBr->ByteCount, |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4268 | le16_to_cpu(pSMBr->t2.DataOffset)); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4269 | |
| 4270 | /* parse returned result into more usable form */ |
Steve French | a1fe78f | 2008-05-16 18:48:38 +0000 | [diff] [blame] | 4271 | rc = parse_DFS_referrals(pSMBr, num_of_nodes, |
Igor Mammedov | 2c55608 | 2008-10-23 13:58:42 +0400 | [diff] [blame] | 4272 | target_nodes, nls_codepage, remap, |
| 4273 | searchName); |
Igor Mammedov | fec4585 | 2008-05-16 13:06:30 +0400 | [diff] [blame] | 4274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4275 | GetDFSRefExit: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 4276 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | |
| 4278 | if (rc == -EAGAIN) |
| 4279 | goto getDFSRetry; |
| 4280 | |
| 4281 | return rc; |
| 4282 | } |
| 4283 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4284 | /* Query File System Info such as free space to old servers such as Win 9x */ |
| 4285 | int |
| 4286 | SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
| 4287 | { |
| 4288 | /* level 0x01 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4289 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4290 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4291 | FILE_SYSTEM_ALLOC_INFO *response_data; |
| 4292 | int rc = 0; |
| 4293 | int bytes_returned = 0; |
| 4294 | __u16 params, byte_count; |
| 4295 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4296 | cFYI(1, "OldQFSInfo"); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4297 | oldQFSInfoRetry: |
| 4298 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4299 | (void **) &pSMBr); |
| 4300 | if (rc) |
| 4301 | return rc; |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4302 | |
| 4303 | params = 2; /* level */ |
| 4304 | pSMB->TotalDataCount = 0; |
| 4305 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 4306 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 4307 | pSMB->MaxSetupCount = 0; |
| 4308 | pSMB->Reserved = 0; |
| 4309 | pSMB->Flags = 0; |
| 4310 | pSMB->Timeout = 0; |
| 4311 | pSMB->Reserved2 = 0; |
| 4312 | byte_count = params + 1 /* pad */ ; |
| 4313 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4314 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4315 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
| 4316 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
| 4317 | pSMB->DataCount = 0; |
| 4318 | pSMB->DataOffset = 0; |
| 4319 | pSMB->SetupCount = 1; |
| 4320 | pSMB->Reserved3 = 0; |
| 4321 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4322 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_ALLOCATION); |
| 4323 | pSMB->hdr.smb_buf_length += byte_count; |
| 4324 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4325 | |
| 4326 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4327 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4328 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4329 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4330 | } else { /* decode response */ |
| 4331 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4332 | |
| 4333 | if (rc || (pSMBr->ByteCount < 18)) |
| 4334 | rc = -EIO; /* bad smb */ |
| 4335 | else { |
| 4336 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4337 | cFYI(1, "qfsinf resp BCC: %d Offset %d", |
| 4338 | pSMBr->ByteCount, data_offset); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4339 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4340 | response_data = (FILE_SYSTEM_ALLOC_INFO *) |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4341 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 4342 | FSData->f_bsize = |
| 4343 | le16_to_cpu(response_data->BytesPerSector) * |
| 4344 | le32_to_cpu(response_data-> |
| 4345 | SectorsPerAllocationUnit); |
| 4346 | FSData->f_blocks = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4347 | le32_to_cpu(response_data->TotalAllocationUnits); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4348 | FSData->f_bfree = FSData->f_bavail = |
| 4349 | le32_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4350 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4351 | (unsigned long long)FSData->f_blocks, |
| 4352 | (unsigned long long)FSData->f_bfree, |
| 4353 | FSData->f_bsize); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4354 | } |
| 4355 | } |
| 4356 | cifs_buf_release(pSMB); |
| 4357 | |
| 4358 | if (rc == -EAGAIN) |
| 4359 | goto oldQFSInfoRetry; |
| 4360 | |
| 4361 | return rc; |
| 4362 | } |
| 4363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4365 | CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | { |
| 4367 | /* level 0x103 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4368 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4369 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4370 | FILE_SYSTEM_INFO *response_data; |
| 4371 | int rc = 0; |
| 4372 | int bytes_returned = 0; |
| 4373 | __u16 params, byte_count; |
| 4374 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4375 | cFYI(1, "In QFSInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4376 | QFSInfoRetry: |
| 4377 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4378 | (void **) &pSMBr); |
| 4379 | if (rc) |
| 4380 | return rc; |
| 4381 | |
| 4382 | params = 2; /* level */ |
| 4383 | pSMB->TotalDataCount = 0; |
| 4384 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4385 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4386 | pSMB->MaxSetupCount = 0; |
| 4387 | pSMB->Reserved = 0; |
| 4388 | pSMB->Flags = 0; |
| 4389 | pSMB->Timeout = 0; |
| 4390 | pSMB->Reserved2 = 0; |
| 4391 | byte_count = params + 1 /* pad */ ; |
| 4392 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4393 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4394 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4395 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | pSMB->DataCount = 0; |
| 4397 | pSMB->DataOffset = 0; |
| 4398 | pSMB->SetupCount = 1; |
| 4399 | pSMB->Reserved3 = 0; |
| 4400 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4401 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_SIZE_INFO); |
| 4402 | pSMB->hdr.smb_buf_length += byte_count; |
| 4403 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4404 | |
| 4405 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4406 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4407 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4408 | cFYI(1, "Send error in QFSInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | } else { /* decode response */ |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4410 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | |
Steve French | 2096243 | 2005-09-21 22:05:57 -0700 | [diff] [blame] | 4412 | if (rc || (pSMBr->ByteCount < 24)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4413 | rc = -EIO; /* bad smb */ |
| 4414 | else { |
| 4415 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | |
| 4417 | response_data = |
| 4418 | (FILE_SYSTEM_INFO |
| 4419 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4420 | data_offset); |
| 4421 | FSData->f_bsize = |
| 4422 | le32_to_cpu(response_data->BytesPerSector) * |
| 4423 | le32_to_cpu(response_data-> |
| 4424 | SectorsPerAllocationUnit); |
| 4425 | FSData->f_blocks = |
| 4426 | le64_to_cpu(response_data->TotalAllocationUnits); |
| 4427 | FSData->f_bfree = FSData->f_bavail = |
| 4428 | le64_to_cpu(response_data->FreeAllocationUnits); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4429 | cFYI(1, "Blocks: %lld Free: %lld Block size %ld", |
| 4430 | (unsigned long long)FSData->f_blocks, |
| 4431 | (unsigned long long)FSData->f_bfree, |
| 4432 | FSData->f_bsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | cifs_buf_release(pSMB); |
| 4436 | |
| 4437 | if (rc == -EAGAIN) |
| 4438 | goto QFSInfoRetry; |
| 4439 | |
| 4440 | return rc; |
| 4441 | } |
| 4442 | |
| 4443 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4444 | CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | { |
| 4446 | /* level 0x105 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4447 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4448 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4449 | FILE_SYSTEM_ATTRIBUTE_INFO *response_data; |
| 4450 | int rc = 0; |
| 4451 | int bytes_returned = 0; |
| 4452 | __u16 params, byte_count; |
| 4453 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4454 | cFYI(1, "In QFSAttributeInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4455 | QFSAttributeRetry: |
| 4456 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4457 | (void **) &pSMBr); |
| 4458 | if (rc) |
| 4459 | return rc; |
| 4460 | |
| 4461 | params = 2; /* level */ |
| 4462 | pSMB->TotalDataCount = 0; |
| 4463 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4464 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4465 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | pSMB->MaxSetupCount = 0; |
| 4467 | pSMB->Reserved = 0; |
| 4468 | pSMB->Flags = 0; |
| 4469 | pSMB->Timeout = 0; |
| 4470 | pSMB->Reserved2 = 0; |
| 4471 | byte_count = params + 1 /* pad */ ; |
| 4472 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4473 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4474 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4475 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | pSMB->DataCount = 0; |
| 4477 | pSMB->DataOffset = 0; |
| 4478 | pSMB->SetupCount = 1; |
| 4479 | pSMB->Reserved3 = 0; |
| 4480 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4481 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_ATTRIBUTE_INFO); |
| 4482 | pSMB->hdr.smb_buf_length += byte_count; |
| 4483 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4484 | |
| 4485 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4486 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4487 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4488 | cERROR(1, "Send error in QFSAttributeInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4489 | } else { /* decode response */ |
| 4490 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4491 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4492 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4493 | /* BB also check if enough bytes returned */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | rc = -EIO; /* bad smb */ |
| 4495 | } else { |
| 4496 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4497 | response_data = |
| 4498 | (FILE_SYSTEM_ATTRIBUTE_INFO |
| 4499 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4500 | data_offset); |
| 4501 | memcpy(&tcon->fsAttrInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4502 | sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4503 | } |
| 4504 | } |
| 4505 | cifs_buf_release(pSMB); |
| 4506 | |
| 4507 | if (rc == -EAGAIN) |
| 4508 | goto QFSAttributeRetry; |
| 4509 | |
| 4510 | return rc; |
| 4511 | } |
| 4512 | |
| 4513 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4514 | CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4515 | { |
| 4516 | /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */ |
| 4517 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4518 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4519 | FILE_SYSTEM_DEVICE_INFO *response_data; |
| 4520 | int rc = 0; |
| 4521 | int bytes_returned = 0; |
| 4522 | __u16 params, byte_count; |
| 4523 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4524 | cFYI(1, "In QFSDeviceInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | QFSDeviceRetry: |
| 4526 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4527 | (void **) &pSMBr); |
| 4528 | if (rc) |
| 4529 | return rc; |
| 4530 | |
| 4531 | params = 2; /* level */ |
| 4532 | pSMB->TotalDataCount = 0; |
| 4533 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4534 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4535 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | pSMB->MaxSetupCount = 0; |
| 4537 | pSMB->Reserved = 0; |
| 4538 | pSMB->Flags = 0; |
| 4539 | pSMB->Timeout = 0; |
| 4540 | pSMB->Reserved2 = 0; |
| 4541 | byte_count = params + 1 /* pad */ ; |
| 4542 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 4543 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 4544 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4545 | struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | |
| 4547 | pSMB->DataCount = 0; |
| 4548 | pSMB->DataOffset = 0; |
| 4549 | pSMB->SetupCount = 1; |
| 4550 | pSMB->Reserved3 = 0; |
| 4551 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4552 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_FS_DEVICE_INFO); |
| 4553 | pSMB->hdr.smb_buf_length += byte_count; |
| 4554 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4555 | |
| 4556 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4557 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4558 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4559 | cFYI(1, "Send error in QFSDeviceInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | } else { /* decode response */ |
| 4561 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4562 | |
Steve French | 630f3f0c | 2007-10-25 21:17:17 +0000 | [diff] [blame] | 4563 | if (rc || (pSMBr->ByteCount < sizeof(FILE_SYSTEM_DEVICE_INFO))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | rc = -EIO; /* bad smb */ |
| 4565 | else { |
| 4566 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4567 | response_data = |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4568 | (FILE_SYSTEM_DEVICE_INFO *) |
| 4569 | (((char *) &pSMBr->hdr.Protocol) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | data_offset); |
| 4571 | memcpy(&tcon->fsDevInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4572 | sizeof(FILE_SYSTEM_DEVICE_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4573 | } |
| 4574 | } |
| 4575 | cifs_buf_release(pSMB); |
| 4576 | |
| 4577 | if (rc == -EAGAIN) |
| 4578 | goto QFSDeviceRetry; |
| 4579 | |
| 4580 | return rc; |
| 4581 | } |
| 4582 | |
| 4583 | int |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4584 | CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | { |
| 4586 | /* level 0x200 SMB_QUERY_CIFS_UNIX_INFO */ |
| 4587 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4588 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4589 | FILE_SYSTEM_UNIX_INFO *response_data; |
| 4590 | int rc = 0; |
| 4591 | int bytes_returned = 0; |
| 4592 | __u16 params, byte_count; |
| 4593 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4594 | cFYI(1, "In QFSUnixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4595 | QFSUnixRetry: |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4596 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4597 | (void **) &pSMB, (void **) &pSMBr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | if (rc) |
| 4599 | return rc; |
| 4600 | |
| 4601 | params = 2; /* level */ |
| 4602 | pSMB->TotalDataCount = 0; |
| 4603 | pSMB->DataCount = 0; |
| 4604 | pSMB->DataOffset = 0; |
| 4605 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4606 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4607 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4608 | pSMB->MaxSetupCount = 0; |
| 4609 | pSMB->Reserved = 0; |
| 4610 | pSMB->Flags = 0; |
| 4611 | pSMB->Timeout = 0; |
| 4612 | pSMB->Reserved2 = 0; |
| 4613 | byte_count = params + 1 /* pad */ ; |
| 4614 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4615 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4616 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4617 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4618 | pSMB->SetupCount = 1; |
| 4619 | pSMB->Reserved3 = 0; |
| 4620 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4621 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_CIFS_UNIX_INFO); |
| 4622 | pSMB->hdr.smb_buf_length += byte_count; |
| 4623 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4624 | |
| 4625 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4626 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4627 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4628 | cERROR(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4629 | } else { /* decode response */ |
| 4630 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4631 | |
| 4632 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4633 | rc = -EIO; /* bad smb */ |
| 4634 | } else { |
| 4635 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4636 | response_data = |
| 4637 | (FILE_SYSTEM_UNIX_INFO |
| 4638 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4639 | data_offset); |
| 4640 | memcpy(&tcon->fsUnixInfo, response_data, |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4641 | sizeof(FILE_SYSTEM_UNIX_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4642 | } |
| 4643 | } |
| 4644 | cifs_buf_release(pSMB); |
| 4645 | |
| 4646 | if (rc == -EAGAIN) |
| 4647 | goto QFSUnixRetry; |
| 4648 | |
| 4649 | |
| 4650 | return rc; |
| 4651 | } |
| 4652 | |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4653 | int |
Steve French | 45abc6e | 2005-06-23 13:42:03 -0500 | [diff] [blame] | 4654 | CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4655 | { |
| 4656 | /* level 0x200 SMB_SET_CIFS_UNIX_INFO */ |
| 4657 | TRANSACTION2_SETFSI_REQ *pSMB = NULL; |
| 4658 | TRANSACTION2_SETFSI_RSP *pSMBr = NULL; |
| 4659 | int rc = 0; |
| 4660 | int bytes_returned = 0; |
| 4661 | __u16 params, param_offset, offset, byte_count; |
| 4662 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4663 | cFYI(1, "In SETFSUnixInfo"); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4664 | SETFSUnixRetry: |
Steve French | f26282c | 2006-03-01 09:17:37 +0000 | [diff] [blame] | 4665 | /* BB switch to small buf init to save memory */ |
Jeff Layton | f569599 | 2010-09-29 15:27:08 -0400 | [diff] [blame] | 4666 | rc = smb_init_no_reconnect(SMB_COM_TRANSACTION2, 15, tcon, |
| 4667 | (void **) &pSMB, (void **) &pSMBr); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4668 | if (rc) |
| 4669 | return rc; |
| 4670 | |
| 4671 | params = 4; /* 2 bytes zero followed by info level. */ |
| 4672 | pSMB->MaxSetupCount = 0; |
| 4673 | pSMB->Reserved = 0; |
| 4674 | pSMB->Flags = 0; |
| 4675 | pSMB->Timeout = 0; |
| 4676 | pSMB->Reserved2 = 0; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4677 | param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) |
| 4678 | - 4; |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4679 | offset = param_offset + params; |
| 4680 | |
| 4681 | pSMB->MaxParameterCount = cpu_to_le16(4); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4682 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4683 | pSMB->MaxDataCount = cpu_to_le16(100); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4684 | pSMB->SetupCount = 1; |
| 4685 | pSMB->Reserved3 = 0; |
| 4686 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FS_INFORMATION); |
| 4687 | byte_count = 1 /* pad */ + params + 12; |
| 4688 | |
| 4689 | pSMB->DataCount = cpu_to_le16(12); |
| 4690 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4691 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4692 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4693 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4694 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4695 | |
| 4696 | /* Params. */ |
| 4697 | pSMB->FileNum = 0; |
| 4698 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_CIFS_UNIX_INFO); |
| 4699 | |
| 4700 | /* Data. */ |
| 4701 | pSMB->ClientUnixMajor = cpu_to_le16(CIFS_UNIX_MAJOR_VERSION); |
| 4702 | pSMB->ClientUnixMinor = cpu_to_le16(CIFS_UNIX_MINOR_VERSION); |
| 4703 | pSMB->ClientUnixCap = cpu_to_le64(cap); |
| 4704 | |
| 4705 | pSMB->hdr.smb_buf_length += byte_count; |
| 4706 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4707 | |
| 4708 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4709 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4710 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4711 | cERROR(1, "Send error in SETFSUnixInfo = %d", rc); |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4712 | } else { /* decode response */ |
| 4713 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4714 | if (rc) |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4715 | rc = -EIO; /* bad smb */ |
Jeremy Allison | ac67055 | 2005-06-22 17:26:35 -0700 | [diff] [blame] | 4716 | } |
| 4717 | cifs_buf_release(pSMB); |
| 4718 | |
| 4719 | if (rc == -EAGAIN) |
| 4720 | goto SETFSUnixRetry; |
| 4721 | |
| 4722 | return rc; |
| 4723 | } |
| 4724 | |
| 4725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4726 | |
| 4727 | int |
| 4728 | CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4729 | struct kstatfs *FSData) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | { |
| 4731 | /* level 0x201 SMB_QUERY_CIFS_POSIX_INFO */ |
| 4732 | TRANSACTION2_QFSI_REQ *pSMB = NULL; |
| 4733 | TRANSACTION2_QFSI_RSP *pSMBr = NULL; |
| 4734 | FILE_SYSTEM_POSIX_INFO *response_data; |
| 4735 | int rc = 0; |
| 4736 | int bytes_returned = 0; |
| 4737 | __u16 params, byte_count; |
| 4738 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4739 | cFYI(1, "In QFSPosixInfo"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | QFSPosixRetry: |
| 4741 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4742 | (void **) &pSMBr); |
| 4743 | if (rc) |
| 4744 | return rc; |
| 4745 | |
| 4746 | params = 2; /* level */ |
| 4747 | pSMB->TotalDataCount = 0; |
| 4748 | pSMB->DataCount = 0; |
| 4749 | pSMB->DataOffset = 0; |
| 4750 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4751 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4752 | pSMB->MaxDataCount = cpu_to_le16(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4753 | pSMB->MaxSetupCount = 0; |
| 4754 | pSMB->Reserved = 0; |
| 4755 | pSMB->Flags = 0; |
| 4756 | pSMB->Timeout = 0; |
| 4757 | pSMB->Reserved2 = 0; |
| 4758 | byte_count = params + 1 /* pad */ ; |
| 4759 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4760 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4761 | pSMB->ParameterOffset = cpu_to_le16(offsetof(struct |
| 4762 | smb_com_transaction2_qfsi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4763 | pSMB->SetupCount = 1; |
| 4764 | pSMB->Reserved3 = 0; |
| 4765 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); |
| 4766 | pSMB->InformationLevel = cpu_to_le16(SMB_QUERY_POSIX_FS_INFO); |
| 4767 | pSMB->hdr.smb_buf_length += byte_count; |
| 4768 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4769 | |
| 4770 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4771 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 4772 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4773 | cFYI(1, "Send error in QFSUnixInfo = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | } else { /* decode response */ |
| 4775 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 4776 | |
| 4777 | if (rc || (pSMBr->ByteCount < 13)) { |
| 4778 | rc = -EIO; /* bad smb */ |
| 4779 | } else { |
| 4780 | __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 4781 | response_data = |
| 4782 | (FILE_SYSTEM_POSIX_INFO |
| 4783 | *) (((char *) &pSMBr->hdr.Protocol) + |
| 4784 | data_offset); |
| 4785 | FSData->f_bsize = |
| 4786 | le32_to_cpu(response_data->BlockSize); |
| 4787 | FSData->f_blocks = |
| 4788 | le64_to_cpu(response_data->TotalBlocks); |
| 4789 | FSData->f_bfree = |
| 4790 | le64_to_cpu(response_data->BlocksAvail); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4791 | if (response_data->UserBlocksAvail == cpu_to_le64(-1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4792 | FSData->f_bavail = FSData->f_bfree; |
| 4793 | } else { |
| 4794 | FSData->f_bavail = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4795 | le64_to_cpu(response_data->UserBlocksAvail); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | } |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4797 | if (response_data->TotalFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4798 | FSData->f_files = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4799 | le64_to_cpu(response_data->TotalFileNodes); |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4800 | if (response_data->FreeFileNodes != cpu_to_le64(-1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4801 | FSData->f_ffree = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4802 | le64_to_cpu(response_data->FreeFileNodes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4803 | } |
| 4804 | } |
| 4805 | cifs_buf_release(pSMB); |
| 4806 | |
| 4807 | if (rc == -EAGAIN) |
| 4808 | goto QFSPosixRetry; |
| 4809 | |
| 4810 | return rc; |
| 4811 | } |
| 4812 | |
| 4813 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4814 | /* We can not use write of zero bytes trick to |
| 4815 | set file size due to need for large file support. Also note that |
| 4816 | this SetPathInfo is preferred to SetFileInfo based method in next |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4817 | routine which is only needed to work around a sharing violation bug |
| 4818 | in Samba which this routine can run into */ |
| 4819 | |
| 4820 | int |
| 4821 | CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4822 | __u64 size, bool SetAllocation, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4823 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4824 | { |
| 4825 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 4826 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 4827 | struct file_end_of_file_info *parm_data; |
| 4828 | int name_len; |
| 4829 | int rc = 0; |
| 4830 | int bytes_returned = 0; |
| 4831 | __u16 params, byte_count, data_count, param_offset, offset; |
| 4832 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4833 | cFYI(1, "In SetEOF"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4834 | SetEOFRetry: |
| 4835 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 4836 | (void **) &pSMBr); |
| 4837 | if (rc) |
| 4838 | return rc; |
| 4839 | |
| 4840 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 4841 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 4842 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 4843 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | name_len++; /* trailing null */ |
| 4845 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4846 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | name_len = strnlen(fileName, PATH_MAX); |
| 4848 | name_len++; /* trailing null */ |
| 4849 | strncpy(pSMB->FileName, fileName, name_len); |
| 4850 | } |
| 4851 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 4852 | data_count = sizeof(struct file_end_of_file_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4853 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 4854 | pSMB->MaxDataCount = cpu_to_le16(4100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4855 | pSMB->MaxSetupCount = 0; |
| 4856 | pSMB->Reserved = 0; |
| 4857 | pSMB->Flags = 0; |
| 4858 | pSMB->Timeout = 0; |
| 4859 | pSMB->Reserved2 = 0; |
| 4860 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4861 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4862 | offset = param_offset + params; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4863 | if (SetAllocation) { |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4864 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4865 | pSMB->InformationLevel = |
| 4866 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4867 | else |
| 4868 | pSMB->InformationLevel = |
| 4869 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
| 4870 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4872 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4873 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4874 | else |
| 4875 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4876 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | parm_data = |
| 4880 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + |
| 4881 | offset); |
| 4882 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4883 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4884 | pSMB->SetupCount = 1; |
| 4885 | pSMB->Reserved3 = 0; |
| 4886 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 4887 | byte_count = 3 /* pad */ + params + data_count; |
| 4888 | pSMB->DataCount = cpu_to_le16(data_count); |
| 4889 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4890 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4891 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4892 | pSMB->Reserved4 = 0; |
| 4893 | pSMB->hdr.smb_buf_length += byte_count; |
| 4894 | parm_data->FileSize = cpu_to_le64(size); |
| 4895 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 4896 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 4897 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 4898 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4899 | cFYI(1, "SetPathInfo (file size) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4900 | |
| 4901 | cifs_buf_release(pSMB); |
| 4902 | |
| 4903 | if (rc == -EAGAIN) |
| 4904 | goto SetEOFRetry; |
| 4905 | |
| 4906 | return rc; |
| 4907 | } |
| 4908 | |
| 4909 | int |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4910 | CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, |
Steve French | 4b18f2a | 2008-04-29 00:06:05 +0000 | [diff] [blame] | 4911 | __u16 fid, __u32 pid_of_opener, bool SetAllocation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4912 | { |
| 4913 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | struct file_end_of_file_info *parm_data; |
| 4915 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | __u16 params, param_offset, offset, byte_count, count; |
| 4917 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4918 | cFYI(1, "SetFileSize (via SetFileInfo) %lld", |
| 4919 | (long long)size); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 4920 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 4921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4922 | if (rc) |
| 4923 | return rc; |
| 4924 | |
| 4925 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 4926 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | params = 6; |
| 4929 | pSMB->MaxSetupCount = 0; |
| 4930 | pSMB->Reserved = 0; |
| 4931 | pSMB->Flags = 0; |
| 4932 | pSMB->Timeout = 0; |
| 4933 | pSMB->Reserved2 = 0; |
| 4934 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 4935 | offset = param_offset + params; |
| 4936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4937 | count = sizeof(struct file_end_of_file_info); |
| 4938 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 4939 | /* BB find exact max SMB PDU from sess structure BB */ |
| 4940 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4941 | pSMB->SetupCount = 1; |
| 4942 | pSMB->Reserved3 = 0; |
| 4943 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 4944 | byte_count = 3 /* pad */ + params + count; |
| 4945 | pSMB->DataCount = cpu_to_le16(count); |
| 4946 | pSMB->ParameterCount = cpu_to_le16(params); |
| 4947 | pSMB->TotalDataCount = pSMB->DataCount; |
| 4948 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 4949 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 4950 | parm_data = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4951 | (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) |
| 4952 | + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | pSMB->DataOffset = cpu_to_le16(offset); |
| 4954 | parm_data->FileSize = cpu_to_le64(size); |
| 4955 | pSMB->Fid = fid; |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 4956 | if (SetAllocation) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4957 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4958 | pSMB->InformationLevel = |
| 4959 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); |
| 4960 | else |
| 4961 | pSMB->InformationLevel = |
| 4962 | cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4963 | } else /* Set File Size */ { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 4965 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4966 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4967 | else |
| 4968 | pSMB->InformationLevel = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4969 | cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4970 | } |
| 4971 | pSMB->Reserved4 = 0; |
| 4972 | pSMB->hdr.smb_buf_length += byte_count; |
| 4973 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 4974 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4975 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 4976 | cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4977 | } |
| 4978 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4979 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4980 | since file handle passed in no longer valid */ |
| 4981 | |
| 4982 | return rc; |
| 4983 | } |
| 4984 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 4985 | /* 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] | 4986 | an open handle, rather than by pathname - this is awkward due to |
| 4987 | potential access conflicts on the open, but it is unavoidable for these |
| 4988 | old servers since the only other choice is to go from 100 nanosecond DCE |
| 4989 | time and resort to the original setpathinfo level which takes the ancient |
| 4990 | DOS time format with 2 second granularity */ |
| 4991 | int |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 4992 | CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 4993 | const FILE_BASIC_INFO *data, __u16 fid, __u32 pid_of_opener) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4994 | { |
| 4995 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | char *data_offset; |
| 4997 | int rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | __u16 params, param_offset, offset, byte_count, count; |
| 4999 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5000 | cFYI(1, "Set Times (via SetFileInfo)"); |
Steve French | cd63499 | 2005-04-28 22:41:10 -0700 | [diff] [blame] | 5001 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5003 | if (rc) |
| 5004 | return rc; |
| 5005 | |
Jeff Layton | 2dd2dfa | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5006 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5007 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5008 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | params = 6; |
| 5010 | pSMB->MaxSetupCount = 0; |
| 5011 | pSMB->Reserved = 0; |
| 5012 | pSMB->Flags = 0; |
| 5013 | pSMB->Timeout = 0; |
| 5014 | pSMB->Reserved2 = 0; |
| 5015 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5016 | offset = param_offset + params; |
| 5017 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5018 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5020 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5022 | /* BB find max SMB PDU from sess */ |
| 5023 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5024 | pSMB->SetupCount = 1; |
| 5025 | pSMB->Reserved3 = 0; |
| 5026 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5027 | byte_count = 3 /* pad */ + params + count; |
| 5028 | pSMB->DataCount = cpu_to_le16(count); |
| 5029 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5030 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5031 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5032 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5033 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5034 | pSMB->Fid = fid; |
| 5035 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5036 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5037 | else |
| 5038 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5039 | pSMB->Reserved4 = 0; |
| 5040 | pSMB->hdr.smb_buf_length += byte_count; |
| 5041 | pSMB->ByteCount = cpu_to_le16(byte_count); |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5042 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Steve French | 133672e | 2007-11-13 22:41:37 +0000 | [diff] [blame] | 5043 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5044 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5045 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5047 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | since file handle passed in no longer valid */ |
| 5049 | |
| 5050 | return rc; |
| 5051 | } |
| 5052 | |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5053 | int |
| 5054 | CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon, |
| 5055 | bool delete_file, __u16 fid, __u32 pid_of_opener) |
| 5056 | { |
| 5057 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5058 | char *data_offset; |
| 5059 | int rc = 0; |
| 5060 | __u16 params, param_offset, offset, byte_count, count; |
| 5061 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5062 | cFYI(1, "Set File Disposition (via SetFileInfo)"); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5063 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5064 | |
| 5065 | if (rc) |
| 5066 | return rc; |
| 5067 | |
| 5068 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5069 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5070 | |
| 5071 | params = 6; |
| 5072 | pSMB->MaxSetupCount = 0; |
| 5073 | pSMB->Reserved = 0; |
| 5074 | pSMB->Flags = 0; |
| 5075 | pSMB->Timeout = 0; |
| 5076 | pSMB->Reserved2 = 0; |
| 5077 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5078 | offset = param_offset + params; |
| 5079 | |
| 5080 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5081 | |
| 5082 | count = 1; |
| 5083 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5084 | /* BB find max SMB PDU from sess */ |
| 5085 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5086 | pSMB->SetupCount = 1; |
| 5087 | pSMB->Reserved3 = 0; |
| 5088 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5089 | byte_count = 3 /* pad */ + params + count; |
| 5090 | pSMB->DataCount = cpu_to_le16(count); |
| 5091 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5092 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5093 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5094 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5095 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5096 | pSMB->Fid = fid; |
| 5097 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_DISPOSITION_INFO); |
| 5098 | pSMB->Reserved4 = 0; |
| 5099 | pSMB->hdr.smb_buf_length += byte_count; |
| 5100 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5101 | *data_offset = delete_file ? 1 : 0; |
| 5102 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5103 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5104 | cFYI(1, "Send error in SetFileDisposition = %d", rc); |
Jeff Layton | 6d22f09 | 2008-09-23 11:48:35 -0400 | [diff] [blame] | 5105 | |
| 5106 | return rc; |
| 5107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | |
| 5109 | int |
Jeff Layton | 6fc000e | 2008-08-02 07:26:12 -0400 | [diff] [blame] | 5110 | CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon, |
| 5111 | const char *fileName, const FILE_BASIC_INFO *data, |
| 5112 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5113 | { |
| 5114 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5115 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5116 | int name_len; |
| 5117 | int rc = 0; |
| 5118 | int bytes_returned = 0; |
| 5119 | char *data_offset; |
| 5120 | __u16 params, param_offset, offset, byte_count, count; |
| 5121 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5122 | cFYI(1, "In SetTimes"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5123 | |
| 5124 | SetTimesRetry: |
| 5125 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5126 | (void **) &pSMBr); |
| 5127 | if (rc) |
| 5128 | return rc; |
| 5129 | |
| 5130 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5131 | name_len = |
Steve French | b1a4569 | 2005-05-17 16:07:23 -0500 | [diff] [blame] | 5132 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5133 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | name_len++; /* trailing null */ |
| 5135 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5136 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | name_len = strnlen(fileName, PATH_MAX); |
| 5138 | name_len++; /* trailing null */ |
| 5139 | strncpy(pSMB->FileName, fileName, name_len); |
| 5140 | } |
| 5141 | |
| 5142 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5143 | count = sizeof(FILE_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5144 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5145 | /* BB find max SMB PDU from sess structure BB */ |
| 5146 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | pSMB->MaxSetupCount = 0; |
| 5148 | pSMB->Reserved = 0; |
| 5149 | pSMB->Flags = 0; |
| 5150 | pSMB->Timeout = 0; |
| 5151 | pSMB->Reserved2 = 0; |
| 5152 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5153 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | offset = param_offset + params; |
| 5155 | data_offset = (char *) (&pSMB->hdr.Protocol) + offset; |
| 5156 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5157 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5158 | pSMB->SetupCount = 1; |
| 5159 | pSMB->Reserved3 = 0; |
| 5160 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5161 | byte_count = 3 /* pad */ + params + count; |
| 5162 | |
| 5163 | pSMB->DataCount = cpu_to_le16(count); |
| 5164 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5165 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5166 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5167 | if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) |
| 5168 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO2); |
| 5169 | else |
| 5170 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_BASIC_INFO); |
| 5171 | pSMB->Reserved4 = 0; |
| 5172 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5173 | memcpy(data_offset, data, sizeof(FILE_BASIC_INFO)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5174 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5175 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5176 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5177 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5178 | cFYI(1, "SetPathInfo (times) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5179 | |
| 5180 | cifs_buf_release(pSMB); |
| 5181 | |
| 5182 | if (rc == -EAGAIN) |
| 5183 | goto SetTimesRetry; |
| 5184 | |
| 5185 | return rc; |
| 5186 | } |
| 5187 | |
| 5188 | /* Can not be used to set time stamps yet (due to old DOS time format) */ |
| 5189 | /* Can be used to set attributes */ |
| 5190 | #if 0 /* Possibly not needed - since it turns out that strangely NT4 has a bug |
| 5191 | handling it anyway and NT4 was what we thought it would be needed for |
| 5192 | Do not delete it until we prove whether needed for Win9x though */ |
| 5193 | int |
| 5194 | CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5195 | __u16 dos_attrs, const struct nls_table *nls_codepage) |
| 5196 | { |
| 5197 | SETATTR_REQ *pSMB = NULL; |
| 5198 | SETATTR_RSP *pSMBr = NULL; |
| 5199 | int rc = 0; |
| 5200 | int bytes_returned; |
| 5201 | int name_len; |
| 5202 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5203 | cFYI(1, "In SetAttrLegacy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5204 | |
| 5205 | SetAttrLgcyRetry: |
| 5206 | rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB, |
| 5207 | (void **) &pSMBr); |
| 5208 | if (rc) |
| 5209 | return rc; |
| 5210 | |
| 5211 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5212 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5213 | ConvertToUCS((__le16 *) pSMB->fileName, fileName, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5214 | PATH_MAX, nls_codepage); |
| 5215 | name_len++; /* trailing null */ |
| 5216 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5217 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | name_len = strnlen(fileName, PATH_MAX); |
| 5219 | name_len++; /* trailing null */ |
| 5220 | strncpy(pSMB->fileName, fileName, name_len); |
| 5221 | } |
| 5222 | pSMB->attr = cpu_to_le16(dos_attrs); |
| 5223 | pSMB->BufferFormat = 0x04; |
| 5224 | pSMB->hdr.smb_buf_length += name_len + 1; |
| 5225 | pSMB->ByteCount = cpu_to_le16(name_len + 1); |
| 5226 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5227 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5228 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5229 | cFYI(1, "Error in LegacySetAttr = %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | |
| 5231 | cifs_buf_release(pSMB); |
| 5232 | |
| 5233 | if (rc == -EAGAIN) |
| 5234 | goto SetAttrLgcyRetry; |
| 5235 | |
| 5236 | return rc; |
| 5237 | } |
| 5238 | #endif /* temporarily unneeded SetAttr legacy function */ |
| 5239 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5240 | static void |
| 5241 | cifs_fill_unix_set_info(FILE_UNIX_BASIC_INFO *data_offset, |
| 5242 | const struct cifs_unix_set_info_args *args) |
| 5243 | { |
| 5244 | u64 mode = args->mode; |
| 5245 | |
| 5246 | /* |
| 5247 | * Samba server ignores set of file size to zero due to bugs in some |
| 5248 | * older clients, but we should be precise - we use SetFileSize to |
| 5249 | * 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] | 5250 | * accidentally as happened on one Samba server beta by putting |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5251 | * zero instead of -1 here |
| 5252 | */ |
| 5253 | data_offset->EndOfFile = cpu_to_le64(NO_CHANGE_64); |
| 5254 | data_offset->NumOfBytes = cpu_to_le64(NO_CHANGE_64); |
| 5255 | data_offset->LastStatusChange = cpu_to_le64(args->ctime); |
| 5256 | data_offset->LastAccessTime = cpu_to_le64(args->atime); |
| 5257 | data_offset->LastModificationTime = cpu_to_le64(args->mtime); |
| 5258 | data_offset->Uid = cpu_to_le64(args->uid); |
| 5259 | data_offset->Gid = cpu_to_le64(args->gid); |
| 5260 | /* better to leave device as zero when it is */ |
| 5261 | data_offset->DevMajor = cpu_to_le64(MAJOR(args->device)); |
| 5262 | data_offset->DevMinor = cpu_to_le64(MINOR(args->device)); |
| 5263 | data_offset->Permissions = cpu_to_le64(mode); |
| 5264 | |
| 5265 | if (S_ISREG(mode)) |
| 5266 | data_offset->Type = cpu_to_le32(UNIX_FILE); |
| 5267 | else if (S_ISDIR(mode)) |
| 5268 | data_offset->Type = cpu_to_le32(UNIX_DIR); |
| 5269 | else if (S_ISLNK(mode)) |
| 5270 | data_offset->Type = cpu_to_le32(UNIX_SYMLINK); |
| 5271 | else if (S_ISCHR(mode)) |
| 5272 | data_offset->Type = cpu_to_le32(UNIX_CHARDEV); |
| 5273 | else if (S_ISBLK(mode)) |
| 5274 | data_offset->Type = cpu_to_le32(UNIX_BLOCKDEV); |
| 5275 | else if (S_ISFIFO(mode)) |
| 5276 | data_offset->Type = cpu_to_le32(UNIX_FIFO); |
| 5277 | else if (S_ISSOCK(mode)) |
| 5278 | data_offset->Type = cpu_to_le32(UNIX_SOCKET); |
| 5279 | } |
| 5280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | int |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5282 | CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon, |
| 5283 | const struct cifs_unix_set_info_args *args, |
| 5284 | u16 fid, u32 pid_of_opener) |
| 5285 | { |
| 5286 | struct smb_com_transaction2_sfi_req *pSMB = NULL; |
| 5287 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5288 | int rc = 0; |
| 5289 | u16 params, param_offset, offset, byte_count, count; |
| 5290 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5291 | cFYI(1, "Set Unix Info (via SetFileInfo)"); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5292 | rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB); |
| 5293 | |
| 5294 | if (rc) |
| 5295 | return rc; |
| 5296 | |
| 5297 | pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); |
| 5298 | pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); |
| 5299 | |
| 5300 | params = 6; |
| 5301 | pSMB->MaxSetupCount = 0; |
| 5302 | pSMB->Reserved = 0; |
| 5303 | pSMB->Flags = 0; |
| 5304 | pSMB->Timeout = 0; |
| 5305 | pSMB->Reserved2 = 0; |
| 5306 | param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; |
| 5307 | offset = param_offset + params; |
| 5308 | |
| 5309 | data_offset = (FILE_UNIX_BASIC_INFO *) |
| 5310 | ((char *)(&pSMB->hdr.Protocol) + offset); |
| 5311 | count = sizeof(FILE_UNIX_BASIC_INFO); |
| 5312 | |
| 5313 | pSMB->MaxParameterCount = cpu_to_le16(2); |
| 5314 | /* BB find max SMB PDU from sess */ |
| 5315 | pSMB->MaxDataCount = cpu_to_le16(1000); |
| 5316 | pSMB->SetupCount = 1; |
| 5317 | pSMB->Reserved3 = 0; |
| 5318 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_FILE_INFORMATION); |
| 5319 | byte_count = 3 /* pad */ + params + count; |
| 5320 | pSMB->DataCount = cpu_to_le16(count); |
| 5321 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5322 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5323 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5324 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5325 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5326 | pSMB->Fid = fid; |
| 5327 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5328 | pSMB->Reserved4 = 0; |
| 5329 | pSMB->hdr.smb_buf_length += byte_count; |
| 5330 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5331 | |
| 5332 | cifs_fill_unix_set_info(data_offset, args); |
| 5333 | |
| 5334 | rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0); |
| 5335 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5336 | cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc); |
Jeff Layton | 3bbeeb3 | 2009-07-09 20:02:50 -0400 | [diff] [blame] | 5337 | |
| 5338 | /* Note: On -EAGAIN error only caller can retry on handle based calls |
| 5339 | since file handle passed in no longer valid */ |
| 5340 | |
| 5341 | return rc; |
| 5342 | } |
| 5343 | |
| 5344 | int |
Jeff Layton | 01ea95e | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5345 | CIFSSMBUnixSetPathInfo(const int xid, struct cifsTconInfo *tcon, char *fileName, |
| 5346 | const struct cifs_unix_set_info_args *args, |
| 5347 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5348 | { |
| 5349 | TRANSACTION2_SPI_REQ *pSMB = NULL; |
| 5350 | TRANSACTION2_SPI_RSP *pSMBr = NULL; |
| 5351 | int name_len; |
| 5352 | int rc = 0; |
| 5353 | int bytes_returned = 0; |
| 5354 | FILE_UNIX_BASIC_INFO *data_offset; |
| 5355 | __u16 params, param_offset, offset, count, byte_count; |
| 5356 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5357 | cFYI(1, "In SetUID/GID/Mode"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | setPermsRetry: |
| 5359 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5360 | (void **) &pSMBr); |
| 5361 | if (rc) |
| 5362 | return rc; |
| 5363 | |
| 5364 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5365 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5366 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5367 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5368 | name_len++; /* trailing null */ |
| 5369 | name_len *= 2; |
Steve French | 3e87d80 | 2005-09-18 20:49:21 -0700 | [diff] [blame] | 5370 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5371 | name_len = strnlen(fileName, PATH_MAX); |
| 5372 | name_len++; /* trailing null */ |
| 5373 | strncpy(pSMB->FileName, fileName, name_len); |
| 5374 | } |
| 5375 | |
| 5376 | params = 6 + name_len; |
Steve French | 26f5736 | 2007-08-30 22:09:15 +0000 | [diff] [blame] | 5377 | count = sizeof(FILE_UNIX_BASIC_INFO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5379 | /* BB find max SMB PDU from sess structure BB */ |
| 5380 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5381 | pSMB->MaxSetupCount = 0; |
| 5382 | pSMB->Reserved = 0; |
| 5383 | pSMB->Flags = 0; |
| 5384 | pSMB->Timeout = 0; |
| 5385 | pSMB->Reserved2 = 0; |
| 5386 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5387 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | offset = param_offset + params; |
| 5389 | data_offset = |
| 5390 | (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + |
| 5391 | offset); |
| 5392 | memset(data_offset, 0, count); |
| 5393 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5394 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5395 | pSMB->SetupCount = 1; |
| 5396 | pSMB->Reserved3 = 0; |
| 5397 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5398 | byte_count = 3 /* pad */ + params + count; |
| 5399 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5400 | pSMB->DataCount = cpu_to_le16(count); |
| 5401 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5402 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5403 | pSMB->InformationLevel = cpu_to_le16(SMB_SET_FILE_UNIX_BASIC); |
| 5404 | pSMB->Reserved4 = 0; |
| 5405 | pSMB->hdr.smb_buf_length += byte_count; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5406 | |
Jeff Layton | 654cf14 | 2009-07-09 20:02:49 -0400 | [diff] [blame] | 5407 | cifs_fill_unix_set_info(data_offset, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | |
| 5409 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5410 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5411 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5412 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5413 | cFYI(1, "SetPathInfo (perms) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5415 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | if (rc == -EAGAIN) |
| 5417 | goto setPermsRetry; |
| 5418 | return rc; |
| 5419 | } |
| 5420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5421 | #ifdef CONFIG_CIFS_XATTR |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5422 | /* |
| 5423 | * Do a path-based QUERY_ALL_EAS call and parse the result. This is a common |
| 5424 | * function used by listxattr and getxattr type calls. When ea_name is set, |
| 5425 | * it looks for that attribute name and stuffs that value into the EAData |
| 5426 | * buffer. When ea_name is NULL, it stuffs a list of attribute names into the |
| 5427 | * buffer. In both cases, the return value is either the length of the |
| 5428 | * resulting data or a negative error code. If EAData is a NULL pointer then |
| 5429 | * the data isn't copied to it, but the length is returned. |
| 5430 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5431 | ssize_t |
| 5432 | CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5433 | const unsigned char *searchName, const unsigned char *ea_name, |
| 5434 | char *EAData, size_t buf_size, |
| 5435 | const struct nls_table *nls_codepage, int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5436 | { |
| 5437 | /* BB assumes one setup word */ |
| 5438 | TRANSACTION2_QPI_REQ *pSMB = NULL; |
| 5439 | TRANSACTION2_QPI_RSP *pSMBr = NULL; |
| 5440 | int rc = 0; |
| 5441 | int bytes_returned; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5442 | int list_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5443 | struct fealist *ea_response_data; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5444 | struct fea *temp_fea; |
| 5445 | char *temp_ptr; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5446 | char *end_of_smb; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5447 | __u16 params, byte_count, data_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5449 | cFYI(1, "In Query All EAs path %s", searchName); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | QAllEAsRetry: |
| 5451 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5452 | (void **) &pSMBr); |
| 5453 | if (rc) |
| 5454 | return rc; |
| 5455 | |
| 5456 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5457 | list_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5458 | cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5459 | PATH_MAX, nls_codepage, remap); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5460 | list_len++; /* trailing null */ |
| 5461 | list_len *= 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5462 | } else { /* BB improve the check for buffer overruns BB */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5463 | list_len = strnlen(searchName, PATH_MAX); |
| 5464 | list_len++; /* trailing null */ |
| 5465 | strncpy(pSMB->FileName, searchName, list_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5466 | } |
| 5467 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5468 | params = 2 /* level */ + 4 /* reserved */ + list_len /* includes NUL */; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | pSMB->TotalDataCount = 0; |
| 5470 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5471 | /* BB find exact max SMB PDU from sess structure BB */ |
Jeff Layton | e529614 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5472 | pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | pSMB->MaxSetupCount = 0; |
| 5474 | pSMB->Reserved = 0; |
| 5475 | pSMB->Flags = 0; |
| 5476 | pSMB->Timeout = 0; |
| 5477 | pSMB->Reserved2 = 0; |
| 5478 | pSMB->ParameterOffset = cpu_to_le16(offsetof( |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5479 | struct smb_com_transaction2_qpi_req, InformationLevel) - 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | pSMB->DataCount = 0; |
| 5481 | pSMB->DataOffset = 0; |
| 5482 | pSMB->SetupCount = 1; |
| 5483 | pSMB->Reserved3 = 0; |
| 5484 | pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_PATH_INFORMATION); |
| 5485 | byte_count = params + 1 /* pad */ ; |
| 5486 | pSMB->TotalParameterCount = cpu_to_le16(params); |
| 5487 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5488 | pSMB->InformationLevel = cpu_to_le16(SMB_INFO_QUERY_ALL_EAS); |
| 5489 | pSMB->Reserved4 = 0; |
| 5490 | pSMB->hdr.smb_buf_length += byte_count; |
| 5491 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5492 | |
| 5493 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5494 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
| 5495 | if (rc) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5496 | cFYI(1, "Send error in QueryAllEAs = %d", rc); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5497 | goto QAllEAsOut; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5499 | |
| 5500 | |
| 5501 | /* BB also check enough total bytes returned */ |
| 5502 | /* BB we need to improve the validity checking |
| 5503 | of these trans2 responses */ |
| 5504 | |
| 5505 | rc = validate_t2((struct smb_t2_rsp *)pSMBr); |
| 5506 | if (rc || (pSMBr->ByteCount < 4)) { |
| 5507 | rc = -EIO; /* bad smb */ |
| 5508 | goto QAllEAsOut; |
| 5509 | } |
| 5510 | |
| 5511 | /* check that length of list is not more than bcc */ |
| 5512 | /* check that each entry does not go beyond length |
| 5513 | of list */ |
| 5514 | /* check that each element of each entry does not |
| 5515 | go beyond end of list */ |
| 5516 | /* validate_trans2_offsets() */ |
| 5517 | /* BB check if start of smb + data_offset > &bcc+ bcc */ |
| 5518 | |
| 5519 | data_offset = le16_to_cpu(pSMBr->t2.DataOffset); |
| 5520 | ea_response_data = (struct fealist *) |
| 5521 | (((char *) &pSMBr->hdr.Protocol) + data_offset); |
| 5522 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5523 | list_len = le32_to_cpu(ea_response_data->list_len); |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5524 | cFYI(1, "ea length %d", list_len); |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5525 | if (list_len <= 8) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5526 | cFYI(1, "empty EA list returned from server"); |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5527 | goto QAllEAsOut; |
| 5528 | } |
| 5529 | |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5530 | /* make sure list_len doesn't go past end of SMB */ |
Jeff Layton | 690c522 | 2011-01-20 13:36:51 -0500 | [diff] [blame] | 5531 | end_of_smb = (char *)pByteArea(&pSMBr->hdr) + get_bcc(&pSMBr->hdr); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5532 | if ((char *)ea_response_data + list_len > end_of_smb) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5533 | cFYI(1, "EA list appears to go beyond SMB"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5534 | rc = -EIO; |
| 5535 | goto QAllEAsOut; |
| 5536 | } |
| 5537 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5538 | /* account for ea list len */ |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5539 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5540 | temp_fea = ea_response_data->list; |
| 5541 | temp_ptr = (char *)temp_fea; |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5542 | while (list_len > 0) { |
Steve French | 122ca00 | 2010-02-24 21:56:48 +0000 | [diff] [blame] | 5543 | unsigned int name_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5544 | __u16 value_len; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5545 | |
Jeff Layton | 6e462b9 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5546 | list_len -= 4; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5547 | temp_ptr += 4; |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5548 | /* make sure we can read name_len and value_len */ |
| 5549 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5550 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5551 | rc = -EIO; |
| 5552 | goto QAllEAsOut; |
| 5553 | } |
| 5554 | |
| 5555 | name_len = temp_fea->name_len; |
| 5556 | value_len = le16_to_cpu(temp_fea->value_len); |
| 5557 | list_len -= name_len + 1 + value_len; |
| 5558 | if (list_len < 0) { |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5559 | cFYI(1, "EA entry goes beyond length of list"); |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5560 | rc = -EIO; |
| 5561 | goto QAllEAsOut; |
| 5562 | } |
| 5563 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5564 | if (ea_name) { |
| 5565 | if (strncmp(ea_name, temp_ptr, name_len) == 0) { |
| 5566 | temp_ptr += name_len + 1; |
| 5567 | rc = value_len; |
| 5568 | if (buf_size == 0) |
| 5569 | goto QAllEAsOut; |
| 5570 | if ((size_t)value_len > buf_size) { |
| 5571 | rc = -ERANGE; |
| 5572 | goto QAllEAsOut; |
| 5573 | } |
| 5574 | memcpy(EAData, temp_ptr, value_len); |
| 5575 | goto QAllEAsOut; |
| 5576 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5577 | } else { |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5578 | /* account for prefix user. and trailing null */ |
| 5579 | rc += (5 + 1 + name_len); |
| 5580 | if (rc < (int) buf_size) { |
| 5581 | memcpy(EAData, "user.", 5); |
| 5582 | EAData += 5; |
| 5583 | memcpy(EAData, temp_ptr, name_len); |
| 5584 | EAData += name_len; |
| 5585 | /* null terminate name */ |
| 5586 | *EAData = 0; |
| 5587 | ++EAData; |
| 5588 | } else if (buf_size == 0) { |
| 5589 | /* skip copy - calc size only */ |
| 5590 | } else { |
| 5591 | /* stop before overrun buffer */ |
| 5592 | rc = -ERANGE; |
| 5593 | break; |
| 5594 | } |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5595 | } |
Jeff Layton | 0cd126b | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5596 | temp_ptr += name_len + 1 + value_len; |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5597 | temp_fea = (struct fea *)temp_ptr; |
| 5598 | } |
| 5599 | |
Jeff Layton | 31c0519 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5600 | /* didn't find the named attribute */ |
| 5601 | if (ea_name) |
| 5602 | rc = -ENODATA; |
| 5603 | |
Jeff Layton | f0d3868 | 2010-02-10 16:18:26 -0500 | [diff] [blame] | 5604 | QAllEAsOut: |
Steve French | 0d817bc | 2008-05-22 02:02:03 +0000 | [diff] [blame] | 5605 | cifs_buf_release(pSMB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | if (rc == -EAGAIN) |
| 5607 | goto QAllEAsRetry; |
| 5608 | |
| 5609 | return (ssize_t)rc; |
| 5610 | } |
| 5611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5612 | int |
| 5613 | CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5614 | const char *ea_name, const void *ea_value, |
| 5615 | const __u16 ea_value_len, const struct nls_table *nls_codepage, |
| 5616 | int remap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | { |
| 5618 | struct smb_com_transaction2_spi_req *pSMB = NULL; |
| 5619 | struct smb_com_transaction2_spi_rsp *pSMBr = NULL; |
| 5620 | struct fealist *parm_data; |
| 5621 | int name_len; |
| 5622 | int rc = 0; |
| 5623 | int bytes_returned = 0; |
| 5624 | __u16 params, param_offset, byte_count, offset, count; |
| 5625 | |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5626 | cFYI(1, "In SetEA"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | SetEARetry: |
| 5628 | rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, |
| 5629 | (void **) &pSMBr); |
| 5630 | if (rc) |
| 5631 | return rc; |
| 5632 | |
| 5633 | if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { |
| 5634 | name_len = |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5635 | cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, |
Steve French | 737b758 | 2005-04-28 22:41:06 -0700 | [diff] [blame] | 5636 | PATH_MAX, nls_codepage, remap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | name_len++; /* trailing null */ |
| 5638 | name_len *= 2; |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5639 | } else { /* BB improve the check for buffer overruns BB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | name_len = strnlen(fileName, PATH_MAX); |
| 5641 | name_len++; /* trailing null */ |
| 5642 | strncpy(pSMB->FileName, fileName, name_len); |
| 5643 | } |
| 5644 | |
| 5645 | params = 6 + name_len; |
| 5646 | |
| 5647 | /* done calculating parms using name_len of file name, |
| 5648 | now use name_len to calculate length of ea name |
| 5649 | we are going to create in the inode xattrs */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5650 | if (ea_name == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | name_len = 0; |
| 5652 | else |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5653 | name_len = strnlen(ea_name, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | |
Steve French | dae5dbd | 2007-12-30 23:49:57 +0000 | [diff] [blame] | 5655 | count = sizeof(*parm_data) + ea_value_len + name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | pSMB->MaxParameterCount = cpu_to_le16(2); |
Steve French | 582d21e | 2008-05-13 04:54:12 +0000 | [diff] [blame] | 5657 | /* BB find max SMB PDU from sess */ |
| 5658 | pSMB->MaxDataCount = cpu_to_le16(1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5659 | pSMB->MaxSetupCount = 0; |
| 5660 | pSMB->Reserved = 0; |
| 5661 | pSMB->Flags = 0; |
| 5662 | pSMB->Timeout = 0; |
| 5663 | pSMB->Reserved2 = 0; |
| 5664 | param_offset = offsetof(struct smb_com_transaction2_spi_req, |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5665 | InformationLevel) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5666 | offset = param_offset + params; |
| 5667 | pSMB->InformationLevel = |
| 5668 | cpu_to_le16(SMB_SET_FILE_EA); |
| 5669 | |
| 5670 | parm_data = |
| 5671 | (struct fealist *) (((char *) &pSMB->hdr.Protocol) + |
| 5672 | offset); |
| 5673 | pSMB->ParameterOffset = cpu_to_le16(param_offset); |
| 5674 | pSMB->DataOffset = cpu_to_le16(offset); |
| 5675 | pSMB->SetupCount = 1; |
| 5676 | pSMB->Reserved3 = 0; |
| 5677 | pSMB->SubCommand = cpu_to_le16(TRANS2_SET_PATH_INFORMATION); |
| 5678 | byte_count = 3 /* pad */ + params + count; |
| 5679 | pSMB->DataCount = cpu_to_le16(count); |
| 5680 | parm_data->list_len = cpu_to_le32(count); |
| 5681 | parm_data->list[0].EA_flags = 0; |
| 5682 | /* we checked above that name len is less than 255 */ |
Alexey Dobriyan | 53b3531 | 2006-03-24 03:16:13 -0800 | [diff] [blame] | 5683 | parm_data->list[0].name_len = (__u8)name_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | /* EA names are always ASCII */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5685 | if (ea_name) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5686 | strncpy(parm_data->list[0].name, ea_name, name_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | parm_data->list[0].name[name_len] = 0; |
| 5688 | parm_data->list[0].value_len = cpu_to_le16(ea_value_len); |
| 5689 | /* caller ensures that ea_value_len is less than 64K but |
| 5690 | we need to ensure that it fits within the smb */ |
| 5691 | |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5692 | /*BB add length check to see if it would fit in |
| 5693 | negotiated SMB buffer size BB */ |
Steve French | 790fe57 | 2007-07-07 19:25:05 +0000 | [diff] [blame] | 5694 | /* if (ea_value_len > buffer_size - 512 (enough for header)) */ |
| 5695 | if (ea_value_len) |
Steve French | 50c2f75 | 2007-07-13 00:33:32 +0000 | [diff] [blame] | 5696 | memcpy(parm_data->list[0].name+name_len+1, |
| 5697 | ea_value, ea_value_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5698 | |
| 5699 | pSMB->TotalDataCount = pSMB->DataCount; |
| 5700 | pSMB->ParameterCount = cpu_to_le16(params); |
| 5701 | pSMB->TotalParameterCount = pSMB->ParameterCount; |
| 5702 | pSMB->Reserved4 = 0; |
| 5703 | pSMB->hdr.smb_buf_length += byte_count; |
| 5704 | pSMB->ByteCount = cpu_to_le16(byte_count); |
| 5705 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5706 | (struct smb_hdr *) pSMBr, &bytes_returned, 0); |
Steve French | ad7a292 | 2008-02-07 23:25:02 +0000 | [diff] [blame] | 5707 | if (rc) |
Joe Perches | b6b38f7 | 2010-04-21 03:50:45 +0000 | [diff] [blame] | 5708 | cFYI(1, "SetPathInfo (EA) returned %d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5709 | |
| 5710 | cifs_buf_release(pSMB); |
| 5711 | |
| 5712 | if (rc == -EAGAIN) |
| 5713 | goto SetEARetry; |
| 5714 | |
| 5715 | return rc; |
| 5716 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5717 | #endif |
Steve French | 0eff0e2 | 2011-02-24 05:39:23 +0000 | [diff] [blame^] | 5718 | |
| 5719 | #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* BB unused temporarily */ |
| 5720 | /* |
| 5721 | * Years ago the kernel added a "dnotify" function for Samba server, |
| 5722 | * to allow network clients (such as Windows) to display updated |
| 5723 | * lists of files in directory listings automatically when |
| 5724 | * files are added by one user when another user has the |
| 5725 | * same directory open on their desktop. The Linux cifs kernel |
| 5726 | * client hooked into the kernel side of this interface for |
| 5727 | * the same reason, but ironically when the VFS moved from |
| 5728 | * "dnotify" to "inotify" it became harder to plug in Linux |
| 5729 | * network file system clients (the most obvious use case |
| 5730 | * for notify interfaces is when multiple users can update |
| 5731 | * the contents of the same directory - exactly what network |
| 5732 | * file systems can do) although the server (Samba) could |
| 5733 | * still use it. For the short term we leave the worker |
| 5734 | * function ifdeffed out (below) until inotify is fixed |
| 5735 | * in the VFS to make it easier to plug in network file |
| 5736 | * system clients. If inotify turns out to be permanently |
| 5737 | * incompatible for network fs clients, we could instead simply |
| 5738 | * expose this config flag by adding a future cifs (and smb2) notify ioctl. |
| 5739 | */ |
| 5740 | int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, |
| 5741 | const int notify_subdirs, const __u16 netfid, |
| 5742 | __u32 filter, struct file *pfile, int multishot, |
| 5743 | const struct nls_table *nls_codepage) |
| 5744 | { |
| 5745 | int rc = 0; |
| 5746 | struct smb_com_transaction_change_notify_req *pSMB = NULL; |
| 5747 | struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL; |
| 5748 | struct dir_notify_req *dnotify_req; |
| 5749 | int bytes_returned; |
| 5750 | |
| 5751 | cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid); |
| 5752 | rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, |
| 5753 | (void **) &pSMBr); |
| 5754 | if (rc) |
| 5755 | return rc; |
| 5756 | |
| 5757 | pSMB->TotalParameterCount = 0 ; |
| 5758 | pSMB->TotalDataCount = 0; |
| 5759 | pSMB->MaxParameterCount = cpu_to_le32(2); |
| 5760 | /* BB find exact data count max from sess structure BB */ |
| 5761 | pSMB->MaxDataCount = 0; /* same in little endian or be */ |
| 5762 | /* BB VERIFY verify which is correct for above BB */ |
| 5763 | pSMB->MaxDataCount = cpu_to_le32((tcon->ses->server->maxBuf - |
| 5764 | MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); |
| 5765 | |
| 5766 | pSMB->MaxSetupCount = 4; |
| 5767 | pSMB->Reserved = 0; |
| 5768 | pSMB->ParameterOffset = 0; |
| 5769 | pSMB->DataCount = 0; |
| 5770 | pSMB->DataOffset = 0; |
| 5771 | pSMB->SetupCount = 4; /* single byte does not need le conversion */ |
| 5772 | pSMB->SubCommand = cpu_to_le16(NT_TRANSACT_NOTIFY_CHANGE); |
| 5773 | pSMB->ParameterCount = pSMB->TotalParameterCount; |
| 5774 | if (notify_subdirs) |
| 5775 | pSMB->WatchTree = 1; /* one byte - no le conversion needed */ |
| 5776 | pSMB->Reserved2 = 0; |
| 5777 | pSMB->CompletionFilter = cpu_to_le32(filter); |
| 5778 | pSMB->Fid = netfid; /* file handle always le */ |
| 5779 | pSMB->ByteCount = 0; |
| 5780 | |
| 5781 | rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, |
| 5782 | (struct smb_hdr *)pSMBr, &bytes_returned, |
| 5783 | CIFS_ASYNC_OP); |
| 5784 | if (rc) { |
| 5785 | cFYI(1, "Error in Notify = %d", rc); |
| 5786 | } else { |
| 5787 | /* Add file to outstanding requests */ |
| 5788 | /* BB change to kmem cache alloc */ |
| 5789 | dnotify_req = kmalloc( |
| 5790 | sizeof(struct dir_notify_req), |
| 5791 | GFP_KERNEL); |
| 5792 | if (dnotify_req) { |
| 5793 | dnotify_req->Pid = pSMB->hdr.Pid; |
| 5794 | dnotify_req->PidHigh = pSMB->hdr.PidHigh; |
| 5795 | dnotify_req->Mid = pSMB->hdr.Mid; |
| 5796 | dnotify_req->Tid = pSMB->hdr.Tid; |
| 5797 | dnotify_req->Uid = pSMB->hdr.Uid; |
| 5798 | dnotify_req->netfid = netfid; |
| 5799 | dnotify_req->pfile = pfile; |
| 5800 | dnotify_req->filter = filter; |
| 5801 | dnotify_req->multishot = multishot; |
| 5802 | spin_lock(&GlobalMid_Lock); |
| 5803 | list_add_tail(&dnotify_req->lhead, |
| 5804 | &GlobalDnotifyReqList); |
| 5805 | spin_unlock(&GlobalMid_Lock); |
| 5806 | } else |
| 5807 | rc = -ENOMEM; |
| 5808 | } |
| 5809 | cifs_buf_release(pSMB); |
| 5810 | return rc; |
| 5811 | } |
| 5812 | #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */ |