1/* SPDX-License-Identifier: LGPL-2.1 */
2/*
3 *
4 * Copyright (c) International Business Machines Corp., 2002, 2011
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
8 *
9 */
10#ifndef _SMB2PROTO_H
11#define _SMB2PROTO_H
12
13#include <linux/nls.h>
14#include <linux/key-type.h>
15#include "cached_dir.h"
16
17struct statfs;
18struct smb_rqst;
19
20/*
21 *****************************************************************
22 * All Prototypes
23 *****************************************************************
24 */
25extern int map_smb2_to_linux_error(char *buf, bool log_err);
26extern int smb2_check_message(char *buf, unsigned int pdu_len, unsigned int length,
27 struct TCP_Server_Info *server);
28extern unsigned int smb2_calc_size(void *buf);
29extern char *smb2_get_data_area_len(int *off, int *len,
30 struct smb2_hdr *shdr);
31extern __le16 *cifs_convert_path_to_utf16(const char *from,
32 struct cifs_sb_info *cifs_sb);
33
34extern int smb2_verify_signature(struct smb_rqst *, struct TCP_Server_Info *);
35extern int smb2_check_receive(struct mid_q_entry *mid,
36 struct TCP_Server_Info *server, bool log_error);
37extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses,
38 struct TCP_Server_Info *,
39 struct smb_rqst *rqst);
40extern struct mid_q_entry *smb2_setup_async_request(
41 struct TCP_Server_Info *server, struct smb_rqst *rqst);
42extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
43 __u64 ses_id, __u32 tid);
44extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
45extern bool smb2_is_valid_oplock_break(char *buffer,
46 struct TCP_Server_Info *srv);
47extern int smb3_handle_read_data(struct TCP_Server_Info *server,
48 struct mid_q_entry *mid);
49struct inode *smb2_create_reparse_inode(struct cifs_open_info_data *data,
50 struct super_block *sb,
51 const unsigned int xid,
52 struct cifs_tcon *tcon,
53 const char *full_path,
54 bool directory,
55 struct kvec *reparse_iov,
56 struct kvec *xattr_iov);
57int smb2_query_reparse_point(const unsigned int xid,
58 struct cifs_tcon *tcon,
59 struct cifs_sb_info *cifs_sb,
60 const char *full_path,
61 u32 *tag, struct kvec *rsp,
62 int *rsp_buftype);
63int smb2_query_path_info(const unsigned int xid,
64 struct cifs_tcon *tcon,
65 struct cifs_sb_info *cifs_sb,
66 const char *full_path,
67 struct cifs_open_info_data *data);
68extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
69 const char *full_path, __u64 size,
70 struct cifs_sb_info *cifs_sb, bool set_alloc,
71 struct dentry *dentry);
72extern int smb2_set_file_info(struct inode *inode, const char *full_path,
73 FILE_BASIC_INFO *buf, const unsigned int xid);
74extern int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
75 umode_t mode, struct cifs_tcon *tcon,
76 const char *full_path,
77 struct cifs_sb_info *cifs_sb);
78extern int smb2_mkdir(const unsigned int xid, struct inode *inode,
79 umode_t mode, struct cifs_tcon *tcon,
80 const char *name, struct cifs_sb_info *cifs_sb);
81extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path,
82 struct cifs_sb_info *cifs_sb,
83 struct cifs_tcon *tcon, const unsigned int xid);
84extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon,
85 const char *name, struct cifs_sb_info *cifs_sb);
86extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon,
87 const char *name, struct cifs_sb_info *cifs_sb,
88 struct dentry *dentry);
89int smb2_rename_path(const unsigned int xid,
90 struct cifs_tcon *tcon,
91 struct dentry *source_dentry,
92 const char *from_name, const char *to_name,
93 struct cifs_sb_info *cifs_sb);
94int smb2_create_hardlink(const unsigned int xid,
95 struct cifs_tcon *tcon,
96 struct dentry *source_dentry,
97 const char *from_name, const char *to_name,
98 struct cifs_sb_info *cifs_sb);
99extern int smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
100 struct cifs_sb_info *cifs_sb, const unsigned char *path,
101 char *pbuf, unsigned int *pbytes_written);
102extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
103 struct cifs_sb_info *cifs_sb,
104 const unsigned char *path, char *pbuf,
105 unsigned int *pbytes_read);
106int smb2_fix_symlink_target_type(char **target, bool directory, struct cifs_sb_info *cifs_sb);
107int smb2_parse_native_symlink(char **target, const char *buf, unsigned int len,
108 bool relative,
109 const char *full_path,
110 struct cifs_sb_info *cifs_sb);
111int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb,
112 const struct kvec *iov,
113 const char *full_path,
114 char **path);
115int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
116 void *buf);
117extern int smb2_unlock_range(struct cifsFileInfo *cfile,
118 struct file_lock *flock, const unsigned int xid);
119extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile);
120extern void smb2_reconnect_server(struct work_struct *work);
121extern int smb3_crypto_aead_allocate(struct TCP_Server_Info *server);
122extern unsigned long smb_rqst_len(struct TCP_Server_Info *server,
123 struct smb_rqst *rqst);
124extern void smb2_set_next_command(struct cifs_tcon *tcon,
125 struct smb_rqst *rqst);
126extern void smb2_set_related(struct smb_rqst *rqst);
127extern void smb2_set_replay(struct TCP_Server_Info *server,
128 struct smb_rqst *rqst);
129extern bool smb2_should_replay(struct cifs_tcon *tcon,
130 int *pretries,
131 int *pcur_sleep);
132
133/*
134 * SMB2 Worker functions - most of protocol specific implementation details
135 * are contained within these calls.
136 */
137extern int SMB2_negotiate(const unsigned int xid,
138 struct cifs_ses *ses,
139 struct TCP_Server_Info *server);
140extern int SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
141 struct TCP_Server_Info *server,
142 const struct nls_table *nls_cp);
143extern int SMB2_logoff(const unsigned int xid, struct cifs_ses *ses);
144extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,
145 const char *tree, struct cifs_tcon *tcon,
146 const struct nls_table *);
147extern int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon);
148extern int SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms,
149 __le16 *path, __u8 *oplock,
150 struct smb2_file_all_info *buf,
151 struct create_posix_rsp *posix,
152 struct kvec *err_iov, int *resp_buftype);
153extern int SMB2_open_init(struct cifs_tcon *tcon,
154 struct TCP_Server_Info *server,
155 struct smb_rqst *rqst,
156 __u8 *oplock, struct cifs_open_parms *oparms,
157 __le16 *path);
158extern void SMB2_open_free(struct smb_rqst *rqst);
159extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon,
160 u64 persistent_fid, u64 volatile_fid, u32 opcode,
161 char *in_data, u32 indatalen, u32 maxoutlen,
162 char **out_data, u32 *plen /* returned data len */);
163extern int SMB2_ioctl_init(struct cifs_tcon *tcon,
164 struct TCP_Server_Info *server,
165 struct smb_rqst *rqst,
166 u64 persistent_fid, u64 volatile_fid, u32 opcode,
167 char *in_data, u32 indatalen,
168 __u32 max_response_size);
169extern void SMB2_ioctl_free(struct smb_rqst *rqst);
170extern int SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,
171 u64 persistent_fid, u64 volatile_fid, bool watch_tree,
172 u32 completion_filter, u32 max_out_data_len,
173 char **out_data, u32 *plen /* returned data len */);
174
175extern int __SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
176 u64 persistent_fid, u64 volatile_fid,
177 struct smb2_file_network_open_info *pbuf);
178extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
179 u64 persistent_file_id, u64 volatile_file_id);
180extern int SMB2_close_init(struct cifs_tcon *tcon,
181 struct TCP_Server_Info *server,
182 struct smb_rqst *rqst,
183 u64 persistent_fid, u64 volatile_fid,
184 bool query_attrs);
185extern void SMB2_close_free(struct smb_rqst *rqst);
186extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon,
187 u64 persistent_file_id, u64 volatile_file_id);
188extern int SMB2_flush_init(const unsigned int xid, struct smb_rqst *rqst,
189 struct cifs_tcon *tcon,
190 struct TCP_Server_Info *server,
191 u64 persistent_file_id, u64 volatile_file_id);
192extern void SMB2_flush_free(struct smb_rqst *rqst);
193extern int SMB311_posix_query_info(const unsigned int xid, struct cifs_tcon *tcon,
194 u64 persistent_fid, u64 volatile_fid, struct smb311_posix_qinfo *data, u32 *plen);
195extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
196 u64 persistent_file_id, u64 volatile_file_id,
197 struct smb2_file_all_info *data);
198extern int SMB2_query_info_init(struct cifs_tcon *tcon,
199 struct TCP_Server_Info *server,
200 struct smb_rqst *rqst,
201 u64 persistent_fid, u64 volatile_fid,
202 u8 info_class, u8 info_type,
203 u32 additional_info, size_t output_len,
204 size_t input_len, void *input);
205extern void SMB2_query_info_free(struct smb_rqst *rqst);
206extern int SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon,
207 u64 persistent_file_id, u64 volatile_file_id,
208 void **data, unsigned int *plen, u32 info);
209extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
210 u64 persistent_fid, u64 volatile_fid,
211 __le64 *uniqueid);
212extern int smb2_async_readv(struct cifs_io_subrequest *rdata);
213extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
214 unsigned int *nbytes, char **buf, int *buf_type);
215extern void smb2_async_writev(struct cifs_io_subrequest *wdata);
216extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
217 unsigned int *nbytes, struct kvec *iov, int n_vec);
218extern int SMB2_echo(struct TCP_Server_Info *server);
219extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
220 u64 persistent_fid, u64 volatile_fid, int index,
221 struct cifs_search_info *srch_inf);
222extern int SMB2_query_directory_init(unsigned int xid, struct cifs_tcon *tcon,
223 struct TCP_Server_Info *server,
224 struct smb_rqst *rqst,
225 u64 persistent_fid, u64 volatile_fid,
226 int index, int info_level);
227extern void SMB2_query_directory_free(struct smb_rqst *rqst);
228extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon,
229 u64 persistent_fid, u64 volatile_fid, u32 pid,
230 loff_t new_eof);
231extern int SMB2_set_info_init(struct cifs_tcon *tcon,
232 struct TCP_Server_Info *server,
233 struct smb_rqst *rqst,
234 u64 persistent_fid, u64 volatile_fid, u32 pid,
235 u8 info_class, u8 info_type, u32 additional_info,
236 void **data, unsigned int *size);
237extern void SMB2_set_info_free(struct smb_rqst *rqst);
238extern int SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
239 u64 persistent_fid, u64 volatile_fid,
240 struct smb_ntsd *pnntsd, int pacllen, int aclflag);
241extern int SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
242 u64 persistent_fid, u64 volatile_fid,
243 struct smb2_file_full_ea_info *buf, int len);
244extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
245 u64 persistent_fid, u64 volatile_fid);
246extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
247 const u64 persistent_fid, const u64 volatile_fid,
248 const __u8 oplock_level);
249extern int smb2_handle_cancelled_close(struct cifs_tcon *tcon,
250 __u64 persistent_fid,
251 __u64 volatile_fid);
252extern int smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server);
253void smb2_cancelled_close_fid(struct work_struct *work);
254extern int SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon,
255 u64 persistent_file_id, u64 volatile_file_id,
256 struct kstatfs *FSData);
257extern int SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
258 u64 persistent_file_id, u64 volatile_file_id, int lvl);
259extern int SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
260 const __u64 persist_fid, const __u64 volatile_fid,
261 const __u32 pid, const __u64 length, const __u64 offset,
262 const __u32 lockFlags, const bool wait);
263extern int smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
264 const __u64 persist_fid, const __u64 volatile_fid,
265 const __u32 pid, const __u32 num_lock,
266 struct smb2_lock_element *buf);
267extern int SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
268 __u8 *lease_key, const __le32 lease_state);
269extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
270
271extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
272 enum securityEnum);
273int smb2_parse_contexts(struct TCP_Server_Info *server,
274 struct kvec *rsp_iov,
275 __u16 *epoch,
276 char *lease_key, __u8 *oplock,
277 struct smb2_file_all_info *buf,
278 struct create_posix_rsp *posix);
279
280extern int smb3_encryption_required(const struct cifs_tcon *tcon);
281extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length,
282 struct kvec *iov, unsigned int min_buf_size);
283extern int smb2_validate_and_copy_iov(unsigned int offset,
284 unsigned int buffer_length,
285 struct kvec *iov,
286 unsigned int minbufsize, char *data);
287extern void smb2_copy_fs_info_to_kstatfs(
288 struct smb2_fs_full_size_info *pfs_inf,
289 struct kstatfs *kst);
290extern int smb3_crypto_shash_allocate(struct TCP_Server_Info *server);
291extern void smb311_update_preauth_hash(struct cifs_ses *ses,
292 struct TCP_Server_Info *server,
293 struct kvec *iov, int nvec);
294extern int smb2_query_info_compound(const unsigned int xid,
295 struct cifs_tcon *tcon,
296 const char *path, u32 desired_access,
297 u32 class, u32 type, u32 output_len,
298 struct kvec *rsp, int *buftype,
299 struct cifs_sb_info *cifs_sb);
300/* query path info from the server using SMB311 POSIX extensions*/
301int posix_info_parse(const void *beg, const void *end,
302 struct smb2_posix_info_parsed *out);
303int posix_info_sid_size(const void *beg, const void *end);
304int smb2_rename_pending_delete(const char *full_path,
305 struct dentry *dentry,
306 const unsigned int xid);
307
308#endif /* _SMB2PROTO_H */
309

source code of linux/fs/smb/client/smb2proto.h