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