xref: /linux/fs/smb/client/cifsproto.h (revision b909d77359b82821e1c6b6a3a8a51b355b06fdb5)
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  *
4  *   Copyright (c) International Business Machines  Corp., 2002,2008
5  *   Author(s): Steve French (sfrench@us.ibm.com)
6  *
7  */
8 #ifndef _CIFSPROTO_H
9 #define _CIFSPROTO_H
10 #include <linux/nls.h>
11 #include <linux/ctype.h>
12 #include "cifsglob.h"
13 #include "trace.h"
14 #ifdef CONFIG_CIFS_DFS_UPCALL
15 #include "dfs_cache.h"
16 #endif
17 
18 struct statfs;
19 struct smb_rqst;
20 struct smb3_fs_context;
21 
22 /*
23  *****************************************************************
24  * All Prototypes
25  *****************************************************************
26  */
27 
28 extern struct smb_hdr *cifs_buf_get(void);
29 extern void cifs_buf_release(void *);
30 extern struct smb_hdr *cifs_small_buf_get(void);
31 extern void cifs_small_buf_release(void *);
32 extern void free_rsp_buf(int, void *);
33 extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *,
34 			unsigned int /* length */);
35 extern int smb_send_kvec(struct TCP_Server_Info *server,
36 			 struct msghdr *msg,
37 			 size_t *sent);
38 extern unsigned int _get_xid(void);
39 extern void _free_xid(unsigned int);
40 #define get_xid()							\
41 ({									\
42 	unsigned int __xid = _get_xid();				\
43 	cifs_dbg(FYI, "VFS: in %s as Xid: %u with uid: %d\n",		\
44 		 __func__, __xid,					\
45 		 from_kuid(&init_user_ns, current_fsuid()));		\
46 	trace_smb3_enter(__xid, __func__);				\
47 	__xid;								\
48 })
49 
50 #define free_xid(curr_xid)						\
51 do {									\
52 	_free_xid(curr_xid);						\
53 	cifs_dbg(FYI, "VFS: leaving %s (xid = %u) rc = %d\n",		\
54 		 __func__, curr_xid, (int)rc);				\
55 	if (rc)								\
56 		trace_smb3_exit_err(curr_xid, __func__, (int)rc);	\
57 	else								\
58 		trace_smb3_exit_done(curr_xid, __func__);		\
59 } while (0)
60 extern int init_cifs_idmap(void);
61 extern void exit_cifs_idmap(void);
62 extern int init_cifs_spnego(void);
63 extern void exit_cifs_spnego(void);
64 extern const char *build_path_from_dentry(struct dentry *, void *);
65 char *__build_path_from_dentry_optional_prefix(struct dentry *direntry, void *page,
66 					       const char *tree, int tree_len,
67 					       bool prefix);
68 extern char *build_path_from_dentry_optional_prefix(struct dentry *direntry,
69 						    void *page, bool prefix);
alloc_dentry_path(void)70 static inline void *alloc_dentry_path(void)
71 {
72 	return __getname();
73 }
74 
free_dentry_path(void * page)75 static inline void free_dentry_path(void *page)
76 {
77 	if (page)
78 		__putname(page);
79 }
80 
81 extern char *cifs_build_path_to_root(struct smb3_fs_context *ctx,
82 				     struct cifs_sb_info *cifs_sb,
83 				     struct cifs_tcon *tcon,
84 				     int add_treename);
85 extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
86 char *cifs_build_devname(char *nodename, const char *prepath);
87 extern void delete_mid(struct mid_q_entry *mid);
88 void __release_mid(struct kref *refcount);
89 extern void cifs_wake_up_task(struct mid_q_entry *mid);
90 extern int cifs_handle_standard(struct TCP_Server_Info *server,
91 				struct mid_q_entry *mid);
92 extern char *smb3_fs_context_fullpath(const struct smb3_fs_context *ctx,
93 				      char dirsep);
94 extern int smb3_parse_devname(const char *devname, struct smb3_fs_context *ctx);
95 extern int smb3_parse_opt(const char *options, const char *key, char **val);
96 extern int cifs_ipaddr_cmp(struct sockaddr *srcaddr, struct sockaddr *rhs);
97 extern bool cifs_match_ipaddr(struct sockaddr *srcaddr, struct sockaddr *rhs);
98 extern int cifs_discard_remaining_data(struct TCP_Server_Info *server);
99 extern int cifs_call_async(struct TCP_Server_Info *server,
100 			struct smb_rqst *rqst,
101 			mid_receive_t *receive, mid_callback_t *callback,
102 			mid_handle_t *handle, void *cbdata, const int flags,
103 			const struct cifs_credits *exist_credits);
104 extern struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses);
105 extern int cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
106 			  struct TCP_Server_Info *server,
107 			  struct smb_rqst *rqst, int *resp_buf_type,
108 			  const int flags, struct kvec *resp_iov);
109 extern int compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
110 			      struct TCP_Server_Info *server,
111 			      const int flags, const int num_rqst,
112 			      struct smb_rqst *rqst, int *resp_buf_type,
113 			      struct kvec *resp_iov);
114 extern int SendReceive(const unsigned int /* xid */ , struct cifs_ses *,
115 			struct smb_hdr * /* input */ ,
116 			struct smb_hdr * /* out */ ,
117 			int * /* bytes returned */ , const int);
118 extern int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
119 			    char *in_buf, int flags);
120 int cifs_sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server);
121 extern struct mid_q_entry *cifs_setup_request(struct cifs_ses *,
122 				struct TCP_Server_Info *,
123 				struct smb_rqst *);
124 extern struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *,
125 						struct smb_rqst *);
126 int __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
127 		    struct smb_rqst *rqst);
128 extern int cifs_check_receive(struct mid_q_entry *mid,
129 			struct TCP_Server_Info *server, bool log_error);
130 int wait_for_free_request(struct TCP_Server_Info *server, const int flags,
131 			  unsigned int *instance);
132 extern int cifs_wait_mtu_credits(struct TCP_Server_Info *server,
133 				 size_t size, size_t *num,
134 				 struct cifs_credits *credits);
135 
136 static inline int
send_cancel(struct TCP_Server_Info * server,struct smb_rqst * rqst,struct mid_q_entry * mid)137 send_cancel(struct TCP_Server_Info *server, struct smb_rqst *rqst,
138 	    struct mid_q_entry *mid)
139 {
140 	return server->ops->send_cancel ?
141 				server->ops->send_cancel(server, rqst, mid) : 0;
142 }
143 
144 int wait_for_response(struct TCP_Server_Info *server, struct mid_q_entry *midQ);
145 extern int SendReceive2(const unsigned int /* xid */ , struct cifs_ses *,
146 			struct kvec *, int /* nvec to send */,
147 			int * /* type of buf returned */, const int flags,
148 			struct kvec * /* resp vec */);
149 extern int SendReceiveBlockingLock(const unsigned int xid,
150 			struct cifs_tcon *ptcon,
151 			struct smb_hdr *in_buf,
152 			struct smb_hdr *out_buf,
153 			int *bytes_returned);
154 
155 void smb2_query_server_interfaces(struct work_struct *work);
156 void
157 cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server,
158 				      bool all_channels);
159 void
160 cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
161 				      bool mark_smb_session);
162 extern int cifs_reconnect(struct TCP_Server_Info *server,
163 			  bool mark_smb_session);
164 extern int checkSMB(char *buf, unsigned int len, struct TCP_Server_Info *srvr);
165 extern bool is_valid_oplock_break(char *, struct TCP_Server_Info *);
166 extern bool backup_cred(struct cifs_sb_info *);
167 extern bool is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 eof,
168 				   bool from_readdir);
169 extern void cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
170 			    unsigned int bytes_written);
171 void cifs_write_subrequest_terminated(struct cifs_io_subrequest *wdata, ssize_t result);
172 extern struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *, int);
173 extern int cifs_get_writable_file(struct cifsInodeInfo *cifs_inode,
174 				  int flags,
175 				  struct cifsFileInfo **ret_file);
176 extern int cifs_get_writable_path(struct cifs_tcon *tcon, const char *name,
177 				  int flags,
178 				  struct cifsFileInfo **ret_file);
179 extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *, bool);
180 extern int cifs_get_readable_path(struct cifs_tcon *tcon, const char *name,
181 				  struct cifsFileInfo **ret_file);
182 extern int cifs_get_hardlink_path(struct cifs_tcon *tcon, struct inode *inode,
183 				  struct file *file);
184 extern unsigned int smbCalcSize(void *buf);
185 extern int decode_negTokenInit(unsigned char *security_blob, int length,
186 			struct TCP_Server_Info *server);
187 extern int cifs_convert_address(struct sockaddr *dst, const char *src, int len);
188 extern void cifs_set_port(struct sockaddr *addr, const unsigned short int port);
189 extern int map_smb_to_linux_error(char *buf, bool logErr);
190 extern int map_and_check_smb_error(struct mid_q_entry *mid, bool logErr);
191 extern void header_assemble(struct smb_hdr *, char /* command */ ,
192 			    const struct cifs_tcon *, int /* length of
193 			    fixed section (word count) in two byte units */);
194 extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
195 				struct cifs_ses *ses,
196 				void **request_buf);
197 extern enum securityEnum select_sectype(struct TCP_Server_Info *server,
198 				enum securityEnum requested);
199 extern int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
200 			  struct TCP_Server_Info *server,
201 			  const struct nls_table *nls_cp);
202 extern struct timespec64 cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
203 extern u64 cifs_UnixTimeToNT(struct timespec64);
204 extern struct timespec64 cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
205 				      int offset);
206 extern void cifs_set_oplock_level(struct cifsInodeInfo *cinode, __u32 oplock);
207 extern int cifs_get_writer(struct cifsInodeInfo *cinode);
208 extern void cifs_put_writer(struct cifsInodeInfo *cinode);
209 extern void cifs_done_oplock_break(struct cifsInodeInfo *cinode);
210 extern int cifs_unlock_range(struct cifsFileInfo *cfile,
211 			     struct file_lock *flock, const unsigned int xid);
212 extern int cifs_push_mandatory_locks(struct cifsFileInfo *cfile);
213 
214 extern void cifs_down_write(struct rw_semaphore *sem);
215 struct cifsFileInfo *cifs_new_fileinfo(struct cifs_fid *fid, struct file *file,
216 				       struct tcon_link *tlink, __u32 oplock,
217 				       const char *symlink_target);
218 extern int cifs_posix_open(const char *full_path, struct inode **inode,
219 			   struct super_block *sb, int mode,
220 			   unsigned int f_flags, __u32 *oplock, __u16 *netfid,
221 			   unsigned int xid);
222 void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr);
223 extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr,
224 				     FILE_UNIX_BASIC_INFO *info,
225 				     struct cifs_sb_info *cifs_sb);
226 extern void cifs_dir_info_to_fattr(struct cifs_fattr *, FILE_DIRECTORY_INFO *,
227 					struct cifs_sb_info *);
228 extern int cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
229 			       bool from_readdir);
230 extern struct inode *cifs_iget(struct super_block *sb,
231 			       struct cifs_fattr *fattr);
232 
233 int cifs_get_inode_info(struct inode **inode, const char *full_path,
234 			struct cifs_open_info_data *data, struct super_block *sb, int xid,
235 			const struct cifs_fid *fid);
236 extern int smb311_posix_get_inode_info(struct inode **inode,
237 				       const char *full_path,
238 				       struct cifs_open_info_data *data,
239 				       struct super_block *sb,
240 				       const unsigned int xid);
241 extern int cifs_get_inode_info_unix(struct inode **pinode,
242 			const unsigned char *search_path,
243 			struct super_block *sb, unsigned int xid);
244 extern int cifs_set_file_info(struct inode *inode, struct iattr *attrs,
245 			      unsigned int xid, const char *full_path, __u32 dosattr);
246 extern int cifs_rename_pending_delete(const char *full_path,
247 				      struct dentry *dentry,
248 				      const unsigned int xid);
249 extern int sid_to_id(struct cifs_sb_info *cifs_sb, struct smb_sid *psid,
250 				struct cifs_fattr *fattr, uint sidtype);
251 extern int cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb,
252 			      struct cifs_fattr *fattr, struct inode *inode,
253 			      bool get_mode_from_special_sid,
254 			      const char *path, const struct cifs_fid *pfid);
255 extern int id_mode_to_cifs_acl(struct inode *inode, const char *path, __u64 *pnmode,
256 					kuid_t uid, kgid_t gid);
257 extern struct smb_ntsd *get_cifs_acl(struct cifs_sb_info *cifssmb, struct inode *ino,
258 				      const char *path, u32 *plen, u32 info);
259 extern struct smb_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifssb,
260 				const struct cifs_fid *pfid, u32 *plen, u32 info);
261 extern struct posix_acl *cifs_get_acl(struct mnt_idmap *idmap,
262 				      struct dentry *dentry, int type);
263 extern int cifs_set_acl(struct mnt_idmap *idmap,
264 			struct dentry *dentry, struct posix_acl *acl, int type);
265 extern int set_cifs_acl(struct smb_ntsd *pntsd, __u32 len, struct inode *ino,
266 				const char *path, int flag);
267 extern unsigned int setup_authusers_ACE(struct smb_ace *pace);
268 extern unsigned int setup_special_mode_ACE(struct smb_ace *pace,
269 					   bool posix,
270 					   __u64 nmode);
271 extern unsigned int setup_special_user_owner_ACE(struct smb_ace *pace);
272 
273 extern void dequeue_mid(struct mid_q_entry *mid, bool malformed);
274 extern int cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
275 			         unsigned int to_read);
276 extern ssize_t cifs_discard_from_socket(struct TCP_Server_Info *server,
277 					size_t to_read);
278 int cifs_read_iter_from_socket(struct TCP_Server_Info *server,
279 			       struct iov_iter *iter,
280 			       unsigned int to_read);
281 extern int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb);
282 void cifs_mount_put_conns(struct cifs_mount_ctx *mnt_ctx);
283 int cifs_mount_get_session(struct cifs_mount_ctx *mnt_ctx);
284 int cifs_is_path_remote(struct cifs_mount_ctx *mnt_ctx);
285 int cifs_mount_get_tcon(struct cifs_mount_ctx *mnt_ctx);
286 extern int cifs_match_super(struct super_block *, void *);
287 extern int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb3_fs_context *ctx);
288 extern void cifs_umount(struct cifs_sb_info *);
289 extern void cifs_mark_open_files_invalid(struct cifs_tcon *tcon);
290 extern void cifs_reopen_persistent_handles(struct cifs_tcon *tcon);
291 
292 extern bool cifs_find_lock_conflict(struct cifsFileInfo *cfile, __u64 offset,
293 				    __u64 length, __u8 type, __u16 flags,
294 				    struct cifsLockInfo **conf_lock,
295 				    int rw_check);
296 extern void cifs_add_pending_open(struct cifs_fid *fid,
297 				  struct tcon_link *tlink,
298 				  struct cifs_pending_open *open);
299 extern void cifs_add_pending_open_locked(struct cifs_fid *fid,
300 					 struct tcon_link *tlink,
301 					 struct cifs_pending_open *open);
302 extern void cifs_del_pending_open(struct cifs_pending_open *open);
303 
304 extern bool cifs_is_deferred_close(struct cifsFileInfo *cfile,
305 				struct cifs_deferred_close **dclose);
306 
307 extern void cifs_add_deferred_close(struct cifsFileInfo *cfile,
308 				struct cifs_deferred_close *dclose);
309 
310 extern void cifs_del_deferred_close(struct cifsFileInfo *cfile);
311 
312 extern void cifs_close_deferred_file(struct cifsInodeInfo *cifs_inode);
313 
314 extern void cifs_close_all_deferred_files(struct cifs_tcon *cifs_tcon);
315 
316 void cifs_close_deferred_file_under_dentry(struct cifs_tcon *cifs_tcon,
317 					   struct dentry *dentry);
318 
319 extern void cifs_mark_open_handles_for_deleted_file(struct inode *inode,
320 				const char *path);
321 
322 extern struct TCP_Server_Info *
323 cifs_get_tcp_session(struct smb3_fs_context *ctx,
324 		     struct TCP_Server_Info *primary_server);
325 extern void cifs_put_tcp_session(struct TCP_Server_Info *server,
326 				 int from_reconnect);
327 extern void cifs_put_tcon(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace);
328 
329 extern void cifs_release_automount_timer(void);
330 
331 void cifs_proc_init(void);
332 void cifs_proc_clean(void);
333 
334 extern void cifs_move_llist(struct list_head *source, struct list_head *dest);
335 extern void cifs_free_llist(struct list_head *llist);
336 extern void cifs_del_lock_waiters(struct cifsLockInfo *lock);
337 
338 int cifs_tree_connect(const unsigned int xid, struct cifs_tcon *tcon);
339 
340 extern int cifs_negotiate_protocol(const unsigned int xid,
341 				   struct cifs_ses *ses,
342 				   struct TCP_Server_Info *server);
343 extern int cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
344 			      struct TCP_Server_Info *server,
345 			      struct nls_table *nls_info);
346 extern int cifs_enable_signing(struct TCP_Server_Info *server, bool mnt_sign_required);
347 extern int CIFSSMBNegotiate(const unsigned int xid,
348 			    struct cifs_ses *ses,
349 			    struct TCP_Server_Info *server);
350 
351 extern int CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
352 		    const char *tree, struct cifs_tcon *tcon,
353 		    const struct nls_table *);
354 
355 extern int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon,
356 		const char *searchName, struct cifs_sb_info *cifs_sb,
357 		__u16 *searchHandle, __u16 search_flags,
358 		struct cifs_search_info *psrch_inf,
359 		bool msearch);
360 
361 extern int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
362 		__u16 searchHandle, __u16 search_flags,
363 		struct cifs_search_info *psrch_inf);
364 
365 extern int CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon,
366 			const __u16 search_handle);
367 
368 extern int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
369 			u16 netfid, FILE_ALL_INFO *pFindData);
370 extern int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
371 			    const char *search_Name, FILE_ALL_INFO *data,
372 			    int legacy /* whether to use old info level */,
373 			    const struct nls_table *nls_codepage, int remap);
374 extern int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon,
375 			       const char *search_name, FILE_ALL_INFO *data,
376 			       const struct nls_table *nls_codepage, int remap);
377 
378 extern int CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
379 			u16 netfid, FILE_UNIX_BASIC_INFO *pFindData);
380 extern int CIFSSMBUnixQPathInfo(const unsigned int xid,
381 			struct cifs_tcon *tcon,
382 			const unsigned char *searchName,
383 			FILE_UNIX_BASIC_INFO *pFindData,
384 			const struct nls_table *nls_codepage, int remap);
385 
386 extern int CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
387 			   const char *search_name,
388 			   struct dfs_info3_param **target_nodes,
389 			   unsigned int *num_of_nodes,
390 			   const struct nls_table *nls_codepage, int remap);
391 
392 extern int parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size,
393 			       unsigned int *num_of_nodes,
394 			       struct dfs_info3_param **target_nodes,
395 			       const struct nls_table *nls_codepage, int remap,
396 			       const char *searchName, bool is_unicode);
397 extern void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
398 				 struct cifs_sb_info *cifs_sb,
399 				 struct smb3_fs_context *ctx);
400 extern int CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon,
401 			struct kstatfs *FSData);
402 extern int SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon,
403 			struct kstatfs *FSData);
404 extern int CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon,
405 			__u64 cap);
406 
407 extern int CIFSSMBQFSAttributeInfo(const unsigned int xid,
408 			struct cifs_tcon *tcon);
409 extern int CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon);
410 extern int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon);
411 extern int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon,
412 			struct kstatfs *FSData);
413 
414 extern int SMBSetInformation(const unsigned int xid, struct cifs_tcon *tcon,
415 			     const char *fileName, __le32 attributes, __le64 write_time,
416 			     const struct nls_table *nls_codepage,
417 			     struct cifs_sb_info *cifs_sb);
418 extern int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
419 			const char *fileName, const FILE_BASIC_INFO *data,
420 			const struct nls_table *nls_codepage,
421 			struct cifs_sb_info *cifs_sb);
422 extern int CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
423 			const FILE_BASIC_INFO *data, __u16 fid,
424 			__u32 pid_of_opener);
425 extern int CIFSSMBSetFileDisposition(const unsigned int xid,
426 				     struct cifs_tcon *tcon,
427 				     bool delete_file, __u16 fid,
428 				     __u32 pid_of_opener);
429 extern int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon,
430 			 const char *file_name, __u64 size,
431 			 struct cifs_sb_info *cifs_sb, bool set_allocation,
432 			 struct dentry *dentry);
433 extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
434 			      struct cifsFileInfo *cfile, __u64 size,
435 			      bool set_allocation);
436 
437 struct cifs_unix_set_info_args {
438 	__u64	ctime;
439 	__u64	atime;
440 	__u64	mtime;
441 	__u64	mode;
442 	kuid_t	uid;
443 	kgid_t	gid;
444 	dev_t	device;
445 };
446 
447 extern int CIFSSMBUnixSetFileInfo(const unsigned int xid,
448 				  struct cifs_tcon *tcon,
449 				  const struct cifs_unix_set_info_args *args,
450 				  u16 fid, u32 pid_of_opener);
451 
452 extern int CIFSSMBUnixSetPathInfo(const unsigned int xid,
453 				  struct cifs_tcon *tcon, const char *file_name,
454 				  const struct cifs_unix_set_info_args *args,
455 				  const struct nls_table *nls_codepage,
456 				  int remap);
457 
458 extern int CIFSSMBMkDir(const unsigned int xid, struct inode *inode,
459 			umode_t mode, struct cifs_tcon *tcon,
460 			const char *name, struct cifs_sb_info *cifs_sb);
461 extern int CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon,
462 			const char *name, struct cifs_sb_info *cifs_sb);
463 extern int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon,
464 			const char *name, __u16 type,
465 			const struct nls_table *nls_codepage,
466 			int remap_special_chars);
467 extern int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
468 			  const char *name, struct cifs_sb_info *cifs_sb,
469 			  struct dentry *dentry);
470 int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon,
471 		  struct dentry *source_dentry,
472 		  const char *from_name, const char *to_name,
473 		  struct cifs_sb_info *cifs_sb);
474 extern int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *tcon,
475 				 int netfid, const char *target_name,
476 				 const struct nls_table *nls_codepage,
477 				 int remap_special_chars);
478 int CIFSCreateHardLink(const unsigned int xid,
479 		       struct cifs_tcon *tcon,
480 		       struct dentry *source_dentry,
481 		       const char *from_name, const char *to_name,
482 		       struct cifs_sb_info *cifs_sb);
483 extern int CIFSUnixCreateHardLink(const unsigned int xid,
484 			struct cifs_tcon *tcon,
485 			const char *fromName, const char *toName,
486 			const struct nls_table *nls_codepage,
487 			int remap_special_chars);
488 extern int CIFSUnixCreateSymLink(const unsigned int xid,
489 			struct cifs_tcon *tcon,
490 			const char *fromName, const char *toName,
491 			const struct nls_table *nls_codepage, int remap);
492 extern int CIFSSMBUnixQuerySymLink(const unsigned int xid,
493 			struct cifs_tcon *tcon,
494 			const unsigned char *searchName, char **syminfo,
495 			const struct nls_table *nls_codepage, int remap);
496 extern int cifs_query_reparse_point(const unsigned int xid,
497 				    struct cifs_tcon *tcon,
498 				    struct cifs_sb_info *cifs_sb,
499 				    const char *full_path,
500 				    u32 *tag, struct kvec *rsp,
501 				    int *rsp_buftype);
502 extern struct inode *cifs_create_reparse_inode(struct cifs_open_info_data *data,
503 					       struct super_block *sb,
504 					       const unsigned int xid,
505 					       struct cifs_tcon *tcon,
506 					       const char *full_path,
507 					       bool directory,
508 					       struct kvec *reparse_iov,
509 					       struct kvec *xattr_iov);
510 extern int CIFSSMB_set_compression(const unsigned int xid,
511 				   struct cifs_tcon *tcon, __u16 fid);
512 extern int CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms,
513 		     int *oplock, FILE_ALL_INFO *buf);
514 extern int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
515 			const char *fileName, const int disposition,
516 			const int access_flags, const int omode,
517 			__u16 *netfid, int *pOplock, FILE_ALL_INFO *,
518 			const struct nls_table *nls_codepage, int remap);
519 extern int CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon,
520 			u32 posix_flags, __u64 mode, __u16 *netfid,
521 			FILE_UNIX_BASIC_INFO *pRetData,
522 			__u32 *pOplock, const char *name,
523 			const struct nls_table *nls_codepage, int remap);
524 extern int CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon,
525 			const int smb_file_id);
526 
527 extern int CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon,
528 			const int smb_file_id);
529 
530 extern int CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
531 			unsigned int *nbytes, char **buf,
532 			int *return_buf_type);
533 extern int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
534 			unsigned int *nbytes, const char *buf);
535 extern int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms,
536 			unsigned int *nbytes, struct kvec *iov, const int nvec);
537 extern int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon,
538 				 const char *search_name, __u64 *inode_number,
539 				 const struct nls_table *nls_codepage,
540 				 int remap);
541 
542 extern int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon,
543 		      const __u16 netfid, const __u8 lock_type,
544 		      const __u32 num_unlock, const __u32 num_lock,
545 		      LOCKING_ANDX_RANGE *buf);
546 extern int CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
547 			const __u16 netfid, const __u32 netpid, const __u64 len,
548 			const __u64 offset, const __u32 numUnlock,
549 			const __u32 numLock, const __u8 lockType,
550 			const bool waitFlag, const __u8 oplock_level);
551 extern int CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
552 			const __u16 smb_file_id, const __u32 netpid,
553 			const loff_t start_offset, const __u64 len,
554 			struct file_lock *, const __u16 lock_type,
555 			const bool waitFlag);
556 extern int CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon);
557 extern int CIFSSMBEcho(struct TCP_Server_Info *server);
558 extern int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses);
559 
560 extern struct cifs_ses *sesInfoAlloc(void);
561 extern void sesInfoFree(struct cifs_ses *);
562 extern struct cifs_tcon *tcon_info_alloc(bool dir_leases_enabled,
563 					 enum smb3_tcon_ref_trace trace);
564 extern void tconInfoFree(struct cifs_tcon *tcon, enum smb3_tcon_ref_trace trace);
565 
566 extern int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
567 		   __u32 *pexpected_response_sequence_number);
568 extern int cifs_sign_smbv(struct kvec *iov, int n_vec, struct TCP_Server_Info *,
569 			  __u32 *);
570 extern int cifs_sign_smb(struct smb_hdr *, struct TCP_Server_Info *, __u32 *);
571 extern int cifs_verify_signature(struct smb_rqst *rqst,
572 				 struct TCP_Server_Info *server,
573 				__u32 expected_sequence_number);
574 extern int setup_ntlmv2_rsp(struct cifs_ses *, const struct nls_table *);
575 extern void cifs_crypto_secmech_release(struct TCP_Server_Info *server);
576 extern int calc_seckey(struct cifs_ses *);
577 extern int generate_smb30signingkey(struct cifs_ses *ses,
578 				    struct TCP_Server_Info *server);
579 extern int generate_smb311signingkey(struct cifs_ses *ses,
580 				     struct TCP_Server_Info *server);
581 
582 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
583 extern ssize_t CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon,
584 			const unsigned char *searchName,
585 			const unsigned char *ea_name, char *EAData,
586 			size_t bufsize, struct cifs_sb_info *cifs_sb);
587 extern int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,
588 		const char *fileName, const char *ea_name,
589 		const void *ea_value, const __u16 ea_value_len,
590 		const struct nls_table *nls_codepage,
591 		struct cifs_sb_info *cifs_sb);
592 extern int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon,
593 			__u16 fid, struct smb_ntsd **acl_inf, __u32 *buflen, __u32 info);
594 extern int CIFSSMBSetCIFSACL(const unsigned int, struct cifs_tcon *, __u16,
595 			struct smb_ntsd *pntsd, __u32 len, int aclflag);
596 extern int cifs_do_get_acl(const unsigned int xid, struct cifs_tcon *tcon,
597 			   const unsigned char *searchName,
598 			   struct posix_acl **acl, const int acl_type,
599 			   const struct nls_table *nls_codepage, int remap);
600 extern int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
601 			   const unsigned char *fileName,
602 			   const struct posix_acl *acl, const int acl_type,
603 			   const struct nls_table *nls_codepage, int remap);
604 extern int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
605 			const int netfid, __u64 *pExtAttrBits, __u64 *pMask);
606 #endif /* CIFS_ALLOW_INSECURE_LEGACY */
607 extern void cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb);
608 extern bool couldbe_mf_symlink(const struct cifs_fattr *fattr);
609 extern int check_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
610 			      struct cifs_sb_info *cifs_sb,
611 			      struct cifs_fattr *fattr,
612 			      const unsigned char *path);
613 extern int E_md4hash(const unsigned char *passwd, unsigned char *p16,
614 			const struct nls_table *codepage);
615 
616 extern struct TCP_Server_Info *
617 cifs_find_tcp_session(struct smb3_fs_context *ctx);
618 
619 struct cifs_tcon *cifs_setup_ipc(struct cifs_ses *ses, bool seal);
620 
621 void __cifs_put_smb_ses(struct cifs_ses *ses);
622 
623 extern struct cifs_ses *
624 cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx);
625 
626 int cifs_async_readv(struct cifs_io_subrequest *rdata);
627 int cifs_readv_receive(struct TCP_Server_Info *server, struct mid_q_entry *mid);
628 
629 void cifs_async_writev(struct cifs_io_subrequest *wdata);
630 int cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
631 			  struct cifs_sb_info *cifs_sb,
632 			  const unsigned char *path, char *pbuf,
633 			  unsigned int *pbytes_read);
634 int cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
635 			   struct cifs_sb_info *cifs_sb,
636 			   const unsigned char *path, char *pbuf,
637 			   unsigned int *pbytes_written);
638 struct cifs_calc_sig_ctx {
639 	struct md5_ctx *md5;
640 	struct hmac_sha256_ctx *hmac;
641 	struct shash_desc *shash;
642 };
643 int __cifs_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server,
644 			  char *signature, struct cifs_calc_sig_ctx *ctx);
645 enum securityEnum cifs_select_sectype(struct TCP_Server_Info *,
646 					enum securityEnum);
647 
648 int cifs_alloc_hash(const char *name, struct shash_desc **sdesc);
649 void cifs_free_hash(struct shash_desc **sdesc);
650 
651 int cifs_try_adding_channels(struct cifs_ses *ses);
652 bool is_ses_using_iface(struct cifs_ses *ses, struct cifs_server_iface *iface);
653 void cifs_ses_mark_for_reconnect(struct cifs_ses *ses);
654 
655 int
656 cifs_ses_get_chan_index(struct cifs_ses *ses,
657 			struct TCP_Server_Info *server);
658 void
659 cifs_chan_set_in_reconnect(struct cifs_ses *ses,
660 			     struct TCP_Server_Info *server);
661 void
662 cifs_chan_clear_in_reconnect(struct cifs_ses *ses,
663 			       struct TCP_Server_Info *server);
664 void
665 cifs_chan_set_need_reconnect(struct cifs_ses *ses,
666 			     struct TCP_Server_Info *server);
667 void
668 cifs_chan_clear_need_reconnect(struct cifs_ses *ses,
669 			       struct TCP_Server_Info *server);
670 bool
671 cifs_chan_needs_reconnect(struct cifs_ses *ses,
672 			  struct TCP_Server_Info *server);
673 bool
674 cifs_chan_is_iface_active(struct cifs_ses *ses,
675 			  struct TCP_Server_Info *server);
676 void
677 cifs_disable_secondary_channels(struct cifs_ses *ses);
678 void
679 cifs_chan_update_iface(struct cifs_ses *ses, struct TCP_Server_Info *server);
680 int
681 SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon, bool in_mount);
682 
683 void extract_unc_hostname(const char *unc, const char **h, size_t *len);
684 int copy_path_name(char *dst, const char *src);
685 int smb2_parse_query_directory(struct cifs_tcon *tcon, struct kvec *rsp_iov,
686 			       int resp_buftype,
687 			       struct cifs_search_info *srch_inf);
688 
689 struct super_block *cifs_get_dfs_tcon_super(struct cifs_tcon *tcon);
690 void cifs_put_tcp_super(struct super_block *sb);
691 int cifs_update_super_prepath(struct cifs_sb_info *cifs_sb, char *prefix);
692 char *extract_hostname(const char *unc);
693 char *extract_sharename(const char *unc);
694 int parse_reparse_point(struct reparse_data_buffer *buf,
695 			u32 plen, struct cifs_sb_info *cifs_sb,
696 			const char *full_path,
697 			struct cifs_open_info_data *data);
698 int __cifs_sfu_make_node(unsigned int xid, struct inode *inode,
699 			 struct dentry *dentry, struct cifs_tcon *tcon,
700 			 const char *full_path, umode_t mode, dev_t dev,
701 			 const char *symname);
702 int cifs_sfu_make_node(unsigned int xid, struct inode *inode,
703 		       struct dentry *dentry, struct cifs_tcon *tcon,
704 		       const char *full_path, umode_t mode, dev_t dev);
705 umode_t wire_mode_to_posix(u32 wire, bool is_dir);
706 
707 #ifdef CONFIG_CIFS_DFS_UPCALL
get_dfs_path(const unsigned int xid,struct cifs_ses * ses,const char * old_path,const struct nls_table * nls_codepage,struct dfs_info3_param * referral,int remap)708 static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
709 			       const char *old_path,
710 			       const struct nls_table *nls_codepage,
711 			       struct dfs_info3_param *referral, int remap)
712 {
713 	return dfs_cache_find(xid, ses, nls_codepage, remap, old_path,
714 			      referral, NULL);
715 }
716 
717 int match_target_ip(struct TCP_Server_Info *server,
718 		    const char *host, size_t hostlen,
719 		    bool *result);
720 int cifs_inval_name_dfs_link_error(const unsigned int xid,
721 				   struct cifs_tcon *tcon,
722 				   struct cifs_sb_info *cifs_sb,
723 				   const char *full_path,
724 				   bool *islink);
725 #else
cifs_inval_name_dfs_link_error(const unsigned int xid,struct cifs_tcon * tcon,struct cifs_sb_info * cifs_sb,const char * full_path,bool * islink)726 static inline int cifs_inval_name_dfs_link_error(const unsigned int xid,
727 				   struct cifs_tcon *tcon,
728 				   struct cifs_sb_info *cifs_sb,
729 				   const char *full_path,
730 				   bool *islink)
731 {
732 	*islink = false;
733 	return 0;
734 }
735 #endif
736 
cifs_create_options(struct cifs_sb_info * cifs_sb,int options)737 static inline int cifs_create_options(struct cifs_sb_info *cifs_sb, int options)
738 {
739 	if (cifs_sb && (backup_cred(cifs_sb)))
740 		return options | CREATE_OPEN_BACKUP_INTENT;
741 	else
742 		return options;
743 }
744 
745 int cifs_wait_for_server_reconnect(struct TCP_Server_Info *server, bool retry);
746 
cifs_put_smb_ses(struct cifs_ses * ses)747 static inline void cifs_put_smb_ses(struct cifs_ses *ses)
748 {
749 	__cifs_put_smb_ses(ses);
750 }
751 
752 /* Get an active reference of @ses and its children.
753  *
754  * NOTE: make sure to call this function when incrementing reference count of
755  * @ses to ensure that any DFS root session attached to it (@ses->dfs_root_ses)
756  * will also get its reference count incremented.
757  *
758  * cifs_put_smb_ses() will put all references, so call it when you're done.
759  */
cifs_smb_ses_inc_refcount(struct cifs_ses * ses)760 static inline void cifs_smb_ses_inc_refcount(struct cifs_ses *ses)
761 {
762 	lockdep_assert_held(&cifs_tcp_ses_lock);
763 	ses->ses_count++;
764 }
765 
dfs_src_pathname_equal(const char * s1,const char * s2)766 static inline bool dfs_src_pathname_equal(const char *s1, const char *s2)
767 {
768 	if (strlen(s1) != strlen(s2))
769 		return false;
770 	for (; *s1; s1++, s2++) {
771 		if (*s1 == '/' || *s1 == '\\') {
772 			if (*s2 != '/' && *s2 != '\\')
773 				return false;
774 		} else if (tolower(*s1) != tolower(*s2))
775 			return false;
776 	}
777 	return true;
778 }
779 
release_mid(struct mid_q_entry * mid)780 static inline void release_mid(struct mid_q_entry *mid)
781 {
782 	kref_put(&mid->refcount, __release_mid);
783 }
784 
cifs_free_open_info(struct cifs_open_info_data * data)785 static inline void cifs_free_open_info(struct cifs_open_info_data *data)
786 {
787 	kfree(data->symlink_target);
788 	free_rsp_buf(data->reparse.io.buftype, data->reparse.io.iov.iov_base);
789 	memset(data, 0, sizeof(*data));
790 }
791 
792 #endif			/* _CIFSPROTO_H */
793