Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/smb2inode.c |
| 3 | * |
| 4 | * Copyright (C) International Business Machines Corp., 2002, 2011 |
| 5 | * Etersoft, 2012 |
| 6 | * Author(s): Pavel Shilovsky (pshilovsky@samba.org), |
| 7 | * Steve French (sfrench@us.ibm.com) |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/stat.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/pagemap.h> |
| 27 | #include <asm/div64.h> |
| 28 | #include "cifsfs.h" |
| 29 | #include "cifspdu.h" |
| 30 | #include "cifsglob.h" |
| 31 | #include "cifsproto.h" |
| 32 | #include "cifs_debug.h" |
| 33 | #include "cifs_fs_sb.h" |
| 34 | #include "cifs_unicode.h" |
| 35 | #include "fscache.h" |
| 36 | #include "smb2glob.h" |
| 37 | #include "smb2pdu.h" |
| 38 | #include "smb2proto.h" |
| 39 | |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 40 | static void |
| 41 | free_set_inf_compound(struct smb_rqst *rqst) |
| 42 | { |
| 43 | if (rqst[1].rq_iov) |
| 44 | SMB2_set_info_free(&rqst[1]); |
| 45 | if (rqst[2].rq_iov) |
| 46 | SMB2_close_free(&rqst[2]); |
| 47 | } |
| 48 | |
| 49 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 50 | struct cop_vars { |
| 51 | struct cifs_open_parms oparms; |
| 52 | struct kvec rsp_iov[3]; |
| 53 | struct smb_rqst rqst[3]; |
| 54 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 55 | struct kvec qi_iov[1]; |
| 56 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
| 57 | struct kvec close_iov[1]; |
| 58 | struct smb2_file_rename_info rename_info; |
| 59 | struct smb2_file_link_info link_info; |
| 60 | }; |
| 61 | |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 62 | static int |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 63 | smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, |
| 64 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 65 | __u32 desired_access, __u32 create_disposition, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 66 | __u32 create_options, umode_t mode, void *ptr, int command, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 67 | struct cifsFileInfo *cfile) |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 68 | { |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 69 | struct cop_vars *vars = NULL; |
| 70 | struct kvec *rsp_iov; |
| 71 | struct smb_rqst *rqst; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 72 | int rc; |
| 73 | __le16 *utf16_path = NULL; |
| 74 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 75 | struct cifs_fid fid; |
| 76 | struct cifs_ses *ses = tcon->ses; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 77 | struct TCP_Server_Info *server; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 78 | int num_rqst = 0; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 79 | int resp_buftype[3]; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 80 | struct smb2_query_info_rsp *qi_rsp = NULL; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 81 | int flags = 0; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 82 | __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0}; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 83 | unsigned int size[2]; |
| 84 | void *data[2]; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 85 | int len; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 86 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 87 | vars = kzalloc(sizeof(*vars), GFP_ATOMIC); |
| 88 | if (vars == NULL) |
| 89 | return -ENOMEM; |
| 90 | rqst = &vars->rqst[0]; |
| 91 | rsp_iov = &vars->rsp_iov[0]; |
| 92 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 93 | server = cifs_pick_channel(ses); |
| 94 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 95 | if (smb3_encryption_required(tcon)) |
| 96 | flags |= CIFS_TRANSFORM_REQ; |
| 97 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 98 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 99 | |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 100 | /* We already have a handle so we can skip the open */ |
| 101 | if (cfile) |
| 102 | goto after_open; |
| 103 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 104 | /* Open */ |
| 105 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 106 | if (!utf16_path) { |
| 107 | rc = -ENOMEM; |
| 108 | goto finished; |
| 109 | } |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 110 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 111 | vars->oparms.tcon = tcon; |
| 112 | vars->oparms.desired_access = desired_access; |
| 113 | vars->oparms.disposition = create_disposition; |
| 114 | vars->oparms.create_options = cifs_create_options(cifs_sb, create_options); |
| 115 | vars->oparms.fid = &fid; |
| 116 | vars->oparms.reconnect = false; |
| 117 | vars->oparms.mode = mode; |
Steve French | c8c412f | 2020-08-13 12:38:08 -0500 | [diff] [blame] | 118 | vars->oparms.cifs_sb = cifs_sb; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 119 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 120 | rqst[num_rqst].rq_iov = &vars->open_iov[0]; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 121 | rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 122 | rc = SMB2_open_init(tcon, server, |
| 123 | &rqst[num_rqst], &oplock, &vars->oparms, |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 124 | utf16_path); |
| 125 | kfree(utf16_path); |
| 126 | if (rc) |
| 127 | goto finished; |
| 128 | |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 129 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
| 130 | after_open: |
| 131 | num_rqst++; |
| 132 | rc = 0; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 133 | |
| 134 | /* Operation */ |
| 135 | switch (command) { |
| 136 | case SMB2_OP_QUERY_INFO: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 137 | rqst[num_rqst].rq_iov = &vars->qi_iov[0]; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 138 | rqst[num_rqst].rq_nvec = 1; |
| 139 | |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 140 | if (cfile) |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 141 | rc = SMB2_query_info_init(tcon, server, |
| 142 | &rqst[num_rqst], |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 143 | cfile->fid.persistent_fid, |
| 144 | cfile->fid.volatile_fid, |
| 145 | FILE_ALL_INFORMATION, |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 146 | SMB2_O_INFO_FILE, 0, |
| 147 | sizeof(struct smb2_file_all_info) + |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 148 | PATH_MAX * 2, 0, NULL); |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 149 | else { |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 150 | rc = SMB2_query_info_init(tcon, server, |
| 151 | &rqst[num_rqst], |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 152 | COMPOUND_FID, |
| 153 | COMPOUND_FID, |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 154 | FILE_ALL_INFORMATION, |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 155 | SMB2_O_INFO_FILE, 0, |
| 156 | sizeof(struct smb2_file_all_info) + |
| 157 | PATH_MAX * 2, 0, NULL); |
| 158 | if (!rc) { |
| 159 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
| 160 | smb2_set_related(&rqst[num_rqst]); |
| 161 | } |
| 162 | } |
| 163 | |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 164 | if (rc) |
| 165 | goto finished; |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 166 | num_rqst++; |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 167 | trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid, |
| 168 | full_path); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 169 | break; |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 170 | case SMB2_OP_POSIX_QUERY_INFO: |
| 171 | rqst[num_rqst].rq_iov = &vars->qi_iov[0]; |
| 172 | rqst[num_rqst].rq_nvec = 1; |
| 173 | |
| 174 | if (cfile) |
| 175 | rc = SMB2_query_info_init(tcon, server, |
| 176 | &rqst[num_rqst], |
| 177 | cfile->fid.persistent_fid, |
| 178 | cfile->fid.volatile_fid, |
| 179 | SMB_FIND_FILE_POSIX_INFO, |
| 180 | SMB2_O_INFO_FILE, 0, |
| 181 | /* TBD: fix following to allow for longer SIDs */ |
| 182 | sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) + |
| 183 | (sizeof(struct cifs_sid) * 2), 0, NULL); |
| 184 | else { |
| 185 | rc = SMB2_query_info_init(tcon, server, |
| 186 | &rqst[num_rqst], |
| 187 | COMPOUND_FID, |
| 188 | COMPOUND_FID, |
| 189 | SMB_FIND_FILE_POSIX_INFO, |
| 190 | SMB2_O_INFO_FILE, 0, |
| 191 | sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) + |
| 192 | (sizeof(struct cifs_sid) * 2), 0, NULL); |
| 193 | if (!rc) { |
| 194 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
| 195 | smb2_set_related(&rqst[num_rqst]); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (rc) |
| 200 | goto finished; |
| 201 | num_rqst++; |
Steve French | e4bd7c4 | 2020-06-11 23:02:33 -0500 | [diff] [blame] | 202 | trace_smb3_posix_query_info_compound_enter(xid, ses->Suid, tcon->tid, full_path); |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 203 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 204 | case SMB2_OP_DELETE: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 205 | trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 206 | break; |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 207 | case SMB2_OP_MKDIR: |
| 208 | /* |
| 209 | * Directories are created through parameters in the |
| 210 | * SMB2_open() call. |
| 211 | */ |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 212 | trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 213 | break; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 214 | case SMB2_OP_RMDIR: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 215 | rqst[num_rqst].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 216 | rqst[num_rqst].rq_nvec = 1; |
| 217 | |
Ronnie Sahlberg | 271b9c0 | 2018-12-18 17:49:05 -0600 | [diff] [blame] | 218 | size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */ |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 219 | data[0] = &delete_pending[0]; |
| 220 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 221 | rc = SMB2_set_info_init(tcon, server, |
| 222 | &rqst[num_rqst], COMPOUND_FID, |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 223 | COMPOUND_FID, current->tgid, |
| 224 | FILE_DISPOSITION_INFORMATION, |
| 225 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 226 | if (rc) |
| 227 | goto finished; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 228 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 229 | smb2_set_related(&rqst[num_rqst++]); |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 230 | trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 231 | break; |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 232 | case SMB2_OP_SET_EOF: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 233 | rqst[num_rqst].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 234 | rqst[num_rqst].rq_nvec = 1; |
| 235 | |
| 236 | size[0] = 8; /* sizeof __le64 */ |
| 237 | data[0] = ptr; |
| 238 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 239 | rc = SMB2_set_info_init(tcon, server, |
| 240 | &rqst[num_rqst], COMPOUND_FID, |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 241 | COMPOUND_FID, current->tgid, |
| 242 | FILE_END_OF_FILE_INFORMATION, |
| 243 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 244 | if (rc) |
| 245 | goto finished; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 246 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 247 | smb2_set_related(&rqst[num_rqst++]); |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 248 | trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 249 | break; |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 250 | case SMB2_OP_SET_INFO: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 251 | rqst[num_rqst].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 252 | rqst[num_rqst].rq_nvec = 1; |
| 253 | |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 254 | |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 255 | size[0] = sizeof(FILE_BASIC_INFO); |
| 256 | data[0] = ptr; |
| 257 | |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 258 | if (cfile) |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 259 | rc = SMB2_set_info_init(tcon, server, |
| 260 | &rqst[num_rqst], |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 261 | cfile->fid.persistent_fid, |
| 262 | cfile->fid.volatile_fid, current->tgid, |
| 263 | FILE_BASIC_INFORMATION, |
| 264 | SMB2_O_INFO_FILE, 0, data, size); |
| 265 | else { |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 266 | rc = SMB2_set_info_init(tcon, server, |
| 267 | &rqst[num_rqst], |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 268 | COMPOUND_FID, |
| 269 | COMPOUND_FID, current->tgid, |
| 270 | FILE_BASIC_INFORMATION, |
| 271 | SMB2_O_INFO_FILE, 0, data, size); |
| 272 | if (!rc) { |
| 273 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
| 274 | smb2_set_related(&rqst[num_rqst]); |
| 275 | } |
| 276 | } |
| 277 | |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 278 | if (rc) |
| 279 | goto finished; |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 280 | num_rqst++; |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 281 | trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid, |
| 282 | full_path); |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 283 | break; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 284 | case SMB2_OP_RENAME: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 285 | rqst[num_rqst].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 286 | rqst[num_rqst].rq_nvec = 2; |
| 287 | |
| 288 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); |
| 289 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 290 | vars->rename_info.ReplaceIfExists = 1; |
| 291 | vars->rename_info.RootDirectory = 0; |
| 292 | vars->rename_info.FileNameLength = cpu_to_le32(len); |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 293 | |
| 294 | size[0] = sizeof(struct smb2_file_rename_info); |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 295 | data[0] = &vars->rename_info; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 296 | |
| 297 | size[1] = len + 2 /* null */; |
| 298 | data[1] = (__le16 *)ptr; |
| 299 | |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 300 | if (cfile) |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 301 | rc = SMB2_set_info_init(tcon, server, |
| 302 | &rqst[num_rqst], |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 303 | cfile->fid.persistent_fid, |
| 304 | cfile->fid.volatile_fid, |
| 305 | current->tgid, FILE_RENAME_INFORMATION, |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 306 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 307 | else { |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 308 | rc = SMB2_set_info_init(tcon, server, |
| 309 | &rqst[num_rqst], |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 310 | COMPOUND_FID, COMPOUND_FID, |
| 311 | current->tgid, FILE_RENAME_INFORMATION, |
| 312 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 313 | if (!rc) { |
| 314 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
| 315 | smb2_set_related(&rqst[num_rqst]); |
| 316 | } |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 317 | } |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 318 | if (rc) |
| 319 | goto finished; |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 320 | num_rqst++; |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 321 | trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 322 | break; |
| 323 | case SMB2_OP_HARDLINK: |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 324 | rqst[num_rqst].rq_iov = &vars->si_iov[0]; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 325 | rqst[num_rqst].rq_nvec = 2; |
| 326 | |
| 327 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); |
| 328 | |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 329 | vars->link_info.ReplaceIfExists = 0; |
| 330 | vars->link_info.RootDirectory = 0; |
| 331 | vars->link_info.FileNameLength = cpu_to_le32(len); |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 332 | |
| 333 | size[0] = sizeof(struct smb2_file_link_info); |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 334 | data[0] = &vars->link_info; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 335 | |
| 336 | size[1] = len + 2 /* null */; |
| 337 | data[1] = (__le16 *)ptr; |
| 338 | |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 339 | rc = SMB2_set_info_init(tcon, server, |
| 340 | &rqst[num_rqst], COMPOUND_FID, |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 341 | COMPOUND_FID, current->tgid, |
| 342 | FILE_LINK_INFORMATION, |
| 343 | SMB2_O_INFO_FILE, 0, data, size); |
Ronnie Sahlberg | 88a92c9 | 2019-07-16 10:41:46 +1000 | [diff] [blame] | 344 | if (rc) |
| 345 | goto finished; |
Ronnie Sahlberg | e77fe73 | 2018-12-31 13:43:40 +1000 | [diff] [blame] | 346 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 347 | smb2_set_related(&rqst[num_rqst++]); |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 348 | trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path); |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 349 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 350 | default: |
| 351 | cifs_dbg(VFS, "Invalid command\n"); |
| 352 | rc = -EINVAL; |
| 353 | } |
| 354 | if (rc) |
| 355 | goto finished; |
| 356 | |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 357 | /* We already have a handle so we can skip the close */ |
| 358 | if (cfile) |
| 359 | goto after_close; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 360 | /* Close */ |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 361 | rqst[num_rqst].rq_iov = &vars->close_iov[0]; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 362 | rqst[num_rqst].rq_nvec = 1; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 363 | rc = SMB2_close_init(tcon, server, |
| 364 | &rqst[num_rqst], COMPOUND_FID, |
Steve French | 43f8a6a | 2019-12-02 21:46:54 -0600 | [diff] [blame] | 365 | COMPOUND_FID, false); |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 366 | smb2_set_related(&rqst[num_rqst]); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 367 | if (rc) |
| 368 | goto finished; |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 369 | after_close: |
| 370 | num_rqst++; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 371 | |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 372 | if (cfile) { |
| 373 | cifsFileInfo_put(cfile); |
| 374 | cfile = NULL; |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 375 | rc = compound_send_recv(xid, ses, server, |
| 376 | flags, num_rqst - 2, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 377 | &rqst[1], &resp_buftype[1], |
| 378 | &rsp_iov[1]); |
| 379 | } else |
Aurelien Aptel | 352d96f | 2020-05-31 12:38:22 -0500 | [diff] [blame] | 380 | rc = compound_send_recv(xid, ses, server, |
| 381 | flags, num_rqst, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 382 | rqst, resp_buftype, |
| 383 | rsp_iov); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 384 | |
| 385 | finished: |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 386 | if (cfile) |
| 387 | cifsFileInfo_put(cfile); |
| 388 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 389 | SMB2_open_free(&rqst[0]); |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 390 | if (rc == -EREMCHG) { |
Joe Perches | a0a3036 | 2020-04-14 22:42:53 -0700 | [diff] [blame] | 391 | pr_warn_once("server share %s deleted\n", tcon->treeName); |
Steve French | 7dcc82c | 2019-09-11 00:07:36 -0500 | [diff] [blame] | 392 | tcon->need_reconnect = true; |
| 393 | } |
| 394 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 395 | switch (command) { |
| 396 | case SMB2_OP_QUERY_INFO: |
| 397 | if (rc == 0) { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 398 | qi_rsp = (struct smb2_query_info_rsp *) |
| 399 | rsp_iov[1].iov_base; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 400 | rc = smb2_validate_and_copy_iov( |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 401 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 402 | le32_to_cpu(qi_rsp->OutputBufferLength), |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 403 | &rsp_iov[1], sizeof(struct smb2_file_all_info), |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 404 | ptr); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 405 | } |
| 406 | if (rqst[1].rq_iov) |
| 407 | SMB2_query_info_free(&rqst[1]); |
| 408 | if (rqst[2].rq_iov) |
| 409 | SMB2_close_free(&rqst[2]); |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 410 | if (rc) |
| 411 | trace_smb3_query_info_compound_err(xid, ses->Suid, |
| 412 | tcon->tid, rc); |
| 413 | else |
| 414 | trace_smb3_query_info_compound_done(xid, ses->Suid, |
| 415 | tcon->tid); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 416 | break; |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 417 | case SMB2_OP_POSIX_QUERY_INFO: |
| 418 | if (rc == 0) { |
| 419 | qi_rsp = (struct smb2_query_info_rsp *) |
| 420 | rsp_iov[1].iov_base; |
| 421 | rc = smb2_validate_and_copy_iov( |
| 422 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 423 | le32_to_cpu(qi_rsp->OutputBufferLength), |
| 424 | &rsp_iov[1], sizeof(struct smb311_posix_qinfo) /* add SIDs */, ptr); |
| 425 | } |
| 426 | if (rqst[1].rq_iov) |
| 427 | SMB2_query_info_free(&rqst[1]); |
| 428 | if (rqst[2].rq_iov) |
| 429 | SMB2_close_free(&rqst[2]); |
| 430 | if (rc) |
Steve French | e4bd7c4 | 2020-06-11 23:02:33 -0500 | [diff] [blame] | 431 | trace_smb3_posix_query_info_compound_err(xid, ses->Suid, tcon->tid, rc); |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 432 | else |
Steve French | e4bd7c4 | 2020-06-11 23:02:33 -0500 | [diff] [blame] | 433 | trace_smb3_posix_query_info_compound_done(xid, ses->Suid, tcon->tid); |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 434 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 435 | case SMB2_OP_DELETE: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 436 | if (rc) |
| 437 | trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc); |
| 438 | else |
| 439 | trace_smb3_delete_done(xid, ses->Suid, tcon->tid); |
| 440 | if (rqst[1].rq_iov) |
| 441 | SMB2_close_free(&rqst[1]); |
| 442 | break; |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 443 | case SMB2_OP_MKDIR: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 444 | if (rc) |
| 445 | trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc); |
| 446 | else |
| 447 | trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid); |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 448 | if (rqst[1].rq_iov) |
| 449 | SMB2_close_free(&rqst[1]); |
| 450 | break; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 451 | case SMB2_OP_HARDLINK: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 452 | if (rc) |
| 453 | trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc); |
| 454 | else |
| 455 | trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid); |
| 456 | free_set_inf_compound(rqst); |
| 457 | break; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 458 | case SMB2_OP_RENAME: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 459 | if (rc) |
| 460 | trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc); |
| 461 | else |
| 462 | trace_smb3_rename_done(xid, ses->Suid, tcon->tid); |
| 463 | free_set_inf_compound(rqst); |
| 464 | break; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 465 | case SMB2_OP_RMDIR: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 466 | if (rc) |
| 467 | trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc); |
| 468 | else |
| 469 | trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid); |
| 470 | free_set_inf_compound(rqst); |
| 471 | break; |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 472 | case SMB2_OP_SET_EOF: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 473 | if (rc) |
| 474 | trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc); |
| 475 | else |
| 476 | trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid); |
| 477 | free_set_inf_compound(rqst); |
| 478 | break; |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 479 | case SMB2_OP_SET_INFO: |
Steve French | 8191576 | 2019-03-13 00:02:47 -0500 | [diff] [blame] | 480 | if (rc) |
| 481 | trace_smb3_set_info_compound_err(xid, ses->Suid, |
| 482 | tcon->tid, rc); |
| 483 | else |
| 484 | trace_smb3_set_info_compound_done(xid, ses->Suid, |
| 485 | tcon->tid); |
| 486 | free_set_inf_compound(rqst); |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 487 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 488 | } |
| 489 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 490 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 491 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
Ronnie Sahlberg | a7d5c29 | 2020-05-20 12:19:59 +1000 | [diff] [blame] | 492 | kfree(vars); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 493 | return rc; |
| 494 | } |
| 495 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 496 | void |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 497 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
| 498 | { |
| 499 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); |
| 500 | dst->CurrentByteOffset = src->CurrentByteOffset; |
| 501 | dst->Mode = src->Mode; |
| 502 | dst->AlignmentRequirement = src->AlignmentRequirement; |
| 503 | dst->IndexNumber1 = 0; /* we don't use it */ |
| 504 | } |
| 505 | |
| 506 | int |
| 507 | smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 508 | struct cifs_sb_info *cifs_sb, const char *full_path, |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 509 | FILE_ALL_INFO *data, bool *adjust_tz, bool *reparse) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 510 | { |
| 511 | int rc; |
| 512 | struct smb2_file_all_info *smb2_data; |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 513 | __u32 create_options = 0; |
Pavel Shilovsky | 6a9cbdd | 2019-01-16 11:48:42 -0800 | [diff] [blame] | 514 | bool no_cached_open = tcon->nohandlecache; |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 515 | struct cifsFileInfo *cfile; |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 516 | struct cached_fid *cfid = NULL; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 517 | |
| 518 | *adjust_tz = false; |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 519 | *reparse = false; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 520 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 521 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 522 | GFP_KERNEL); |
| 523 | if (smb2_data == NULL) |
| 524 | return -ENOMEM; |
Pavel Shilovsky | 6a9cbdd | 2019-01-16 11:48:42 -0800 | [diff] [blame] | 525 | |
| 526 | /* If it is a root and its handle is cached then use it */ |
| 527 | if (!strlen(full_path) && !no_cached_open) { |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 528 | rc = open_shroot(xid, tcon, cifs_sb, &cfid); |
Pavel Shilovsky | 6a9cbdd | 2019-01-16 11:48:42 -0800 | [diff] [blame] | 529 | if (rc) |
| 530 | goto out; |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 531 | |
| 532 | if (tcon->crfid.file_all_info_is_valid) { |
| 533 | move_smb2_info_to_cifs(data, |
| 534 | &tcon->crfid.file_all_info); |
| 535 | } else { |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 536 | rc = SMB2_query_info(xid, tcon, |
| 537 | cfid->fid->persistent_fid, |
| 538 | cfid->fid->volatile_fid, smb2_data); |
Ronnie Sahlberg | b0f6df7 | 2019-03-12 13:58:31 +1000 | [diff] [blame] | 539 | if (!rc) |
| 540 | move_smb2_info_to_cifs(data, smb2_data); |
| 541 | } |
Ronnie Sahlberg | 9e81e8f | 2020-10-05 12:37:52 +1000 | [diff] [blame] | 542 | close_shroot(cfid); |
Pavel Shilovsky | 6a9cbdd | 2019-01-16 11:48:42 -0800 | [diff] [blame] | 543 | goto out; |
| 544 | } |
| 545 | |
Ronnie Sahlberg | 496902d | 2019-09-09 15:30:00 +1000 | [diff] [blame] | 546 | cifs_get_readable_path(tcon, full_path, &cfile); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 547 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 548 | FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 549 | ACL_NO_MODE, smb2_data, SMB2_OP_QUERY_INFO, cfile); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 550 | if (rc == -EOPNOTSUPP) { |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 551 | *reparse = true; |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 552 | create_options |= OPEN_REPARSE_POINT; |
| 553 | |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 554 | /* Failed on a symbolic link - query a reparse point info */ |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 555 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 556 | FILE_READ_ATTRIBUTES, FILE_OPEN, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 557 | create_options, ACL_NO_MODE, |
| 558 | smb2_data, SMB2_OP_QUERY_INFO, NULL); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 559 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 560 | if (rc) |
| 561 | goto out; |
| 562 | |
| 563 | move_smb2_info_to_cifs(data, smb2_data); |
| 564 | out: |
| 565 | kfree(smb2_data); |
| 566 | return rc; |
| 567 | } |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 568 | |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 569 | |
| 570 | int |
| 571 | smb311_posix_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 572 | struct cifs_sb_info *cifs_sb, const char *full_path, |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 573 | struct smb311_posix_qinfo *data, bool *adjust_tz, bool *reparse) |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 574 | { |
| 575 | int rc; |
| 576 | __u32 create_options = 0; |
| 577 | struct cifsFileInfo *cfile; |
| 578 | struct smb311_posix_qinfo *smb2_data; |
| 579 | |
| 580 | *adjust_tz = false; |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 581 | *reparse = false; |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 582 | |
| 583 | /* BB TODO: Make struct larger when add support for parsing owner SIDs */ |
| 584 | smb2_data = kzalloc(sizeof(struct smb311_posix_qinfo), |
| 585 | GFP_KERNEL); |
| 586 | if (smb2_data == NULL) |
| 587 | return -ENOMEM; |
| 588 | |
| 589 | /* |
| 590 | * BB TODO: Add support for using the cached root handle. |
| 591 | * Create SMB2_query_posix_info worker function to do non-compounded query |
| 592 | * when we already have an open file handle for this. For now this is fast enough |
| 593 | * (always using the compounded version). |
| 594 | */ |
| 595 | |
| 596 | cifs_get_readable_path(tcon, full_path, &cfile); |
| 597 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 598 | FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, |
| 599 | ACL_NO_MODE, smb2_data, SMB2_OP_POSIX_QUERY_INFO, cfile); |
| 600 | if (rc == -EOPNOTSUPP) { |
| 601 | /* BB TODO: When support for special files added to Samba re-verify this path */ |
Steve French | 2e4564b | 2020-10-22 22:03:14 -0500 | [diff] [blame] | 602 | *reparse = true; |
Steve French | 6a5f659 | 2020-06-11 19:25:47 -0500 | [diff] [blame] | 603 | create_options |= OPEN_REPARSE_POINT; |
| 604 | |
| 605 | /* Failed on a symbolic link - query a reparse point info */ |
| 606 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 607 | FILE_READ_ATTRIBUTES, FILE_OPEN, |
| 608 | create_options, ACL_NO_MODE, |
| 609 | smb2_data, SMB2_OP_POSIX_QUERY_INFO, NULL); |
| 610 | } |
| 611 | if (rc) |
| 612 | goto out; |
| 613 | |
| 614 | /* TODO: will need to allow for the 2 SIDs when add support for getting owner UID/GID */ |
| 615 | memcpy(data, smb2_data, sizeof(struct smb311_posix_qinfo)); |
| 616 | |
| 617 | out: |
| 618 | kfree(smb2_data); |
| 619 | return rc; |
| 620 | } |
| 621 | |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 622 | int |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 623 | smb2_mkdir(const unsigned int xid, struct inode *parent_inode, umode_t mode, |
| 624 | struct cifs_tcon *tcon, const char *name, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 625 | struct cifs_sb_info *cifs_sb) |
| 626 | { |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 627 | return smb2_compound_op(xid, tcon, cifs_sb, name, |
| 628 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 629 | CREATE_NOT_FILE, mode, NULL, SMB2_OP_MKDIR, |
| 630 | NULL); |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | void |
| 634 | smb2_mkdir_setinfo(struct inode *inode, const char *name, |
| 635 | struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, |
| 636 | const unsigned int xid) |
| 637 | { |
| 638 | FILE_BASIC_INFO data; |
| 639 | struct cifsInodeInfo *cifs_i; |
Ronnie Sahlberg | dc9300a | 2019-08-30 09:53:56 +1000 | [diff] [blame] | 640 | struct cifsFileInfo *cfile; |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 641 | u32 dosattrs; |
| 642 | int tmprc; |
| 643 | |
| 644 | memset(&data, 0, sizeof(data)); |
| 645 | cifs_i = CIFS_I(inode); |
| 646 | dosattrs = cifs_i->cifsAttrs | ATTR_READONLY; |
| 647 | data.Attributes = cpu_to_le32(dosattrs); |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 648 | cifs_get_writable_path(tcon, name, FIND_WR_ANY, &cfile); |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 649 | tmprc = smb2_compound_op(xid, tcon, cifs_sb, name, |
| 650 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 651 | CREATE_NOT_FILE, ACL_NO_MODE, |
| 652 | &data, SMB2_OP_SET_INFO, cfile); |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 653 | if (tmprc == 0) |
| 654 | cifs_i->cifsAttrs = dosattrs; |
| 655 | } |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 656 | |
| 657 | int |
| 658 | smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 659 | struct cifs_sb_info *cifs_sb) |
| 660 | { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 661 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 662 | CREATE_NOT_FILE, ACL_NO_MODE, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 663 | NULL, SMB2_OP_RMDIR, NULL); |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 664 | } |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 665 | |
| 666 | int |
| 667 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 668 | struct cifs_sb_info *cifs_sb) |
| 669 | { |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 670 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
| 671 | CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 672 | ACL_NO_MODE, NULL, SMB2_OP_DELETE, NULL); |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 673 | } |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 674 | |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 675 | static int |
| 676 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, |
| 677 | const char *from_name, const char *to_name, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 678 | struct cifs_sb_info *cifs_sb, __u32 access, int command, |
| 679 | struct cifsFileInfo *cfile) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 680 | { |
| 681 | __le16 *smb2_to_name = NULL; |
| 682 | int rc; |
| 683 | |
| 684 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); |
| 685 | if (smb2_to_name == NULL) { |
| 686 | rc = -ENOMEM; |
| 687 | goto smb2_rename_path; |
| 688 | } |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 689 | rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 690 | FILE_OPEN, 0, ACL_NO_MODE, smb2_to_name, |
| 691 | command, cfile); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 692 | smb2_rename_path: |
| 693 | kfree(smb2_to_name); |
| 694 | return rc; |
| 695 | } |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 696 | |
| 697 | int |
| 698 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, |
| 699 | const char *from_name, const char *to_name, |
| 700 | struct cifs_sb_info *cifs_sb) |
| 701 | { |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 702 | struct cifsFileInfo *cfile; |
| 703 | |
Aurelien Aptel | 86f740f | 2020-02-21 11:19:06 +0100 | [diff] [blame] | 704 | cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile); |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 705 | |
| 706 | return smb2_set_path_attr(xid, tcon, from_name, to_name, |
| 707 | cifs_sb, DELETE, SMB2_OP_RENAME, cfile); |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | int |
| 711 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 712 | const char *from_name, const char *to_name, |
| 713 | struct cifs_sb_info *cifs_sb) |
| 714 | { |
| 715 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, |
Ronnie Sahlberg | 8de9e86 | 2019-08-30 08:25:46 +1000 | [diff] [blame] | 716 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK, |
| 717 | NULL); |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 718 | } |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 719 | |
| 720 | int |
| 721 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 722 | const char *full_path, __u64 size, |
| 723 | struct cifs_sb_info *cifs_sb, bool set_alloc) |
| 724 | { |
| 725 | __le64 eof = cpu_to_le64(size); |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 726 | |
| 727 | return smb2_compound_op(xid, tcon, cifs_sb, full_path, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 728 | FILE_WRITE_DATA, FILE_OPEN, 0, ACL_NO_MODE, |
| 729 | &eof, SMB2_OP_SET_EOF, NULL); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 730 | } |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 731 | |
| 732 | int |
| 733 | smb2_set_file_info(struct inode *inode, const char *full_path, |
| 734 | FILE_BASIC_INFO *buf, const unsigned int xid) |
| 735 | { |
| 736 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 737 | struct tcon_link *tlink; |
| 738 | int rc; |
| 739 | |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 740 | if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) && |
Steve French | fd09b7d | 2018-08-02 20:28:18 -0500 | [diff] [blame] | 741 | (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) && |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 742 | (buf->Attributes == 0)) |
| 743 | return 0; /* would be a no op, no sense sending this */ |
| 744 | |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 745 | tlink = cifs_sb_tlink(cifs_sb); |
| 746 | if (IS_ERR(tlink)) |
| 747 | return PTR_ERR(tlink); |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 748 | |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 749 | rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path, |
Steve French | c3ca78e | 2019-09-25 00:32:13 -0500 | [diff] [blame] | 750 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, |
| 751 | 0, ACL_NO_MODE, buf, SMB2_OP_SET_INFO, NULL); |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 752 | cifs_put_tlink(tlink); |
| 753 | return rc; |
| 754 | } |