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