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