xref: /linux/fs/smb/client/smb1proto.h (revision 6f7e6393d1ce636bb7ec77a7fe7b77458fddf701)
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 _SMB1PROTO_H
9 #define _SMB1PROTO_H
10 
11 #include <linux/uidgid_types.h>
12 #include <linux/unaligned.h>
13 #include "../common/smb2pdu.h"
14 #include "cifsglob.h"
15 
16 struct cifs_unix_set_info_args {
17 	__u64	ctime;
18 	__u64	atime;
19 	__u64	mtime;
20 	__u64	mode;
21 	kuid_t	uid;
22 	kgid_t	gid;
23 	dev_t	device;
24 };
25 
26 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
27 
28 /*
29  * cifssmb.c
30  */
31 int small_smb_init_no_tc(const int smb_command, const int wct,
32 			 struct cifs_ses *ses, void **request_buf);
33 int CIFSSMBNegotiate(const unsigned int xid, struct cifs_ses *ses,
34 		     struct TCP_Server_Info *server);
35 int CIFSTCon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
36 	     struct cifs_tcon *tcon, const struct nls_table *nls_codepage);
37 int CIFSSMBTDis(const unsigned int xid, struct cifs_tcon *tcon);
38 int CIFSSMBEcho(struct TCP_Server_Info *server);
39 int CIFSSMBLogoff(const unsigned int xid, struct cifs_ses *ses);
40 int CIFSPOSIXDelFile(const unsigned int xid, struct cifs_tcon *tcon,
41 		     const char *fileName, __u16 type,
42 		     const struct nls_table *nls_codepage, int remap);
43 int CIFSSMBDelFile(const unsigned int xid, struct cifs_tcon *tcon,
44 		   const char *name, struct cifs_sb_info *cifs_sb,
45 		   struct dentry *dentry);
46 int CIFSSMBRmDir(const unsigned int xid, struct cifs_tcon *tcon,
47 		 const char *name, struct cifs_sb_info *cifs_sb);
48 int CIFSSMBMkDir(const unsigned int xid, struct inode *inode, umode_t mode,
49 		 struct cifs_tcon *tcon, const char *name,
50 		 struct cifs_sb_info *cifs_sb);
51 int CIFSPOSIXCreate(const unsigned int xid, struct cifs_tcon *tcon,
52 		    __u32 posix_flags, __u64 mode, __u16 *netfid,
53 		    FILE_UNIX_BASIC_INFO *pRetData, __u32 *pOplock,
54 		    const char *name, const struct nls_table *nls_codepage,
55 		    int remap);
56 int SMBLegacyOpen(const unsigned int xid, struct cifs_tcon *tcon,
57 		  const char *fileName, const int openDisposition,
58 		  const int access_flags, const int create_options,
59 		  __u16 *netfid, int *pOplock, FILE_ALL_INFO *pfile_info,
60 		  const struct nls_table *nls_codepage, int remap);
61 int CIFS_open(const unsigned int xid, struct cifs_open_parms *oparms,
62 	      int *oplock, FILE_ALL_INFO *buf);
63 int cifs_async_readv(struct cifs_io_subrequest *rdata);
64 int CIFSSMBRead(const unsigned int xid, struct cifs_io_parms *io_parms,
65 		unsigned int *nbytes, char **buf, int *pbuf_type);
66 int CIFSSMBWrite(const unsigned int xid, struct cifs_io_parms *io_parms,
67 		 unsigned int *nbytes, const char *buf);
68 void cifs_async_writev(struct cifs_io_subrequest *wdata);
69 int CIFSSMBWrite2(const unsigned int xid, struct cifs_io_parms *io_parms,
70 		  unsigned int *nbytes, struct kvec *iov, int n_vec);
71 int cifs_lockv(const unsigned int xid, struct cifs_tcon *tcon,
72 	       const __u16 netfid, const __u8 lock_type,
73 	       const __u32 num_unlock, const __u32 num_lock,
74 	       LOCKING_ANDX_RANGE *buf);
75 int CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,
76 		const __u16 smb_file_id, const __u32 netpid, const __u64 len,
77 		const __u64 offset, const __u32 numUnlock, const __u32 numLock,
78 		const __u8 lockType, const bool waitFlag,
79 		const __u8 oplock_level);
80 int CIFSSMBPosixLock(const unsigned int xid, struct cifs_tcon *tcon,
81 		     const __u16 smb_file_id, const __u32 netpid,
82 		     const loff_t start_offset, const __u64 len,
83 		     struct file_lock *pLockData, const __u16 lock_type,
84 		     const bool waitFlag);
85 int CIFSSMBClose(const unsigned int xid, struct cifs_tcon *tcon,
86 		 int smb_file_id);
87 int CIFSSMBFlush(const unsigned int xid, struct cifs_tcon *tcon,
88 		 int smb_file_id);
89 int CIFSSMBRename(const unsigned int xid, struct cifs_tcon *tcon,
90 		  struct dentry *source_dentry, const char *from_name,
91 		  const char *to_name, struct cifs_sb_info *cifs_sb);
92 int CIFSSMBRenameOpenFile(const unsigned int xid, struct cifs_tcon *pTcon,
93 			  int netfid, const char *target_name,
94 			  const struct nls_table *nls_codepage, int remap);
95 int CIFSUnixCreateSymLink(const unsigned int xid, struct cifs_tcon *tcon,
96 			  const char *fromName, const char *toName,
97 			  const struct nls_table *nls_codepage, int remap);
98 int CIFSUnixCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon,
99 			   const char *fromName, const char *toName,
100 			   const struct nls_table *nls_codepage, int remap);
101 int CIFSCreateHardLink(const unsigned int xid, struct cifs_tcon *tcon,
102 		       struct dentry *source_dentry, const char *from_name,
103 		       const char *to_name, struct cifs_sb_info *cifs_sb);
104 int CIFSSMBUnixQuerySymLink(const unsigned int xid, struct cifs_tcon *tcon,
105 			    const unsigned char *searchName,
106 			    char **symlinkinfo,
107 			    const struct nls_table *nls_codepage, int remap);
108 int cifs_query_reparse_point(const unsigned int xid, struct cifs_tcon *tcon,
109 			     struct cifs_sb_info *cifs_sb,
110 			     const char *full_path, u32 *tag, struct kvec *rsp,
111 			     int *rsp_buftype);
112 struct inode *cifs_create_reparse_inode(struct cifs_open_info_data *data,
113 					struct super_block *sb,
114 					const unsigned int xid,
115 					struct cifs_tcon *tcon,
116 					const char *full_path, bool directory,
117 					struct kvec *reparse_iov,
118 					struct kvec *xattr_iov);
119 int CIFSSMB_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
120 			    __u16 fid);
121 int cifs_do_get_acl(const unsigned int xid, struct cifs_tcon *tcon,
122 		    const unsigned char *searchName, struct posix_acl **acl,
123 		    const int acl_type, const struct nls_table *nls_codepage,
124 		    int remap);
125 int cifs_do_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
126 		    const unsigned char *fileName, const struct posix_acl *acl,
127 		    const int acl_type, const struct nls_table *nls_codepage,
128 		    int remap);
129 int CIFSGetExtAttr(const unsigned int xid, struct cifs_tcon *tcon,
130 		   const int netfid, __u64 *pExtAttrBits, __u64 *pMask);
131 int CIFSSMBGetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon,
132 		      __u16 fid, struct smb_ntsd **acl_inf, __u32 *pbuflen,
133 		      __u32 info);
134 int CIFSSMBSetCIFSACL(const unsigned int xid, struct cifs_tcon *tcon,
135 		      __u16 fid, struct smb_ntsd *pntsd, __u32 acllen,
136 		      int aclflag);
137 int SMBQueryInformation(const unsigned int xid, struct cifs_tcon *tcon,
138 			const char *search_name, FILE_ALL_INFO *data,
139 			const struct nls_table *nls_codepage, int remap);
140 int CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
141 		     u16 netfid, FILE_ALL_INFO *pFindData);
142 int CIFSSMBQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
143 		     const char *search_name, FILE_ALL_INFO *data,
144 		     int legacy /* old style infolevel */,
145 		     const struct nls_table *nls_codepage, int remap);
146 int CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
147 			 u16 netfid, FILE_UNIX_BASIC_INFO *pFindData);
148 int CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
149 			 const unsigned char *searchName,
150 			 FILE_UNIX_BASIC_INFO *pFindData,
151 			 const struct nls_table *nls_codepage, int remap);
152 int CIFSFindFirst(const unsigned int xid, struct cifs_tcon *tcon,
153 		  const char *searchName, struct cifs_sb_info *cifs_sb,
154 		  __u16 *pnetfid, __u16 search_flags,
155 		  struct cifs_search_info *psrch_inf, bool msearch);
156 int CIFSFindNext(const unsigned int xid, struct cifs_tcon *tcon,
157 		 __u16 searchHandle, __u16 search_flags,
158 		 struct cifs_search_info *psrch_inf);
159 int CIFSFindClose(const unsigned int xid, struct cifs_tcon *tcon,
160 		  const __u16 searchHandle);
161 int CIFSGetSrvInodeNumber(const unsigned int xid, struct cifs_tcon *tcon,
162 			  const char *search_name, __u64 *inode_number,
163 			  const struct nls_table *nls_codepage, int remap);
164 int CIFSGetDFSRefer(const unsigned int xid, struct cifs_ses *ses,
165 		    const char *search_name,
166 		    struct dfs_info3_param **target_nodes,
167 		    unsigned int *num_of_nodes,
168 		    const struct nls_table *nls_codepage, int remap);
169 int SMBOldQFSInfo(const unsigned int xid, struct cifs_tcon *tcon,
170 		  struct kstatfs *FSData);
171 int CIFSSMBQFSInfo(const unsigned int xid, struct cifs_tcon *tcon,
172 		   struct kstatfs *FSData);
173 int CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon);
174 int CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon);
175 int CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon);
176 int CIFSSMBSetFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon,
177 			 __u64 cap);
178 int CIFSSMBQFSPosixInfo(const unsigned int xid, struct cifs_tcon *tcon,
179 			struct kstatfs *FSData);
180 int CIFSSMBSetEOF(const unsigned int xid, struct cifs_tcon *tcon,
181 		  const char *file_name, __u64 size,
182 		  struct cifs_sb_info *cifs_sb, bool set_allocation,
183 		  struct dentry *dentry);
184 int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon,
185 		       struct cifsFileInfo *cfile, __u64 size,
186 		       bool set_allocation);
187 int SMBSetInformation(const unsigned int xid, struct cifs_tcon *tcon,
188 		      const char *fileName, __le32 attributes,
189 		      __le64 write_time, const struct nls_table *nls_codepage,
190 		      struct cifs_sb_info *cifs_sb);
191 int CIFSSMBSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
192 		       const FILE_BASIC_INFO *data, __u16 fid,
193 		       __u32 pid_of_opener);
194 int CIFSSMBSetFileDisposition(const unsigned int xid, struct cifs_tcon *tcon,
195 			      bool delete_file, __u16 fid,
196 			      __u32 pid_of_opener);
197 int CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
198 		       const char *fileName, const FILE_BASIC_INFO *data,
199 		       const struct nls_table *nls_codepage,
200 		       struct cifs_sb_info *cifs_sb);
201 int CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
202 			   const struct cifs_unix_set_info_args *args, u16 fid,
203 			   u32 pid_of_opener);
204 int CIFSSMBUnixSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
205 			   const char *file_name,
206 			   const struct cifs_unix_set_info_args *args,
207 			   const struct nls_table *nls_codepage, int remap);
208 ssize_t CIFSSMBQAllEAs(const unsigned int xid, struct cifs_tcon *tcon,
209 		       const unsigned char *searchName,
210 		       const unsigned char *ea_name, char *EAData,
211 		       size_t buf_size, struct cifs_sb_info *cifs_sb);
212 int CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,
213 		 const char *fileName, const char *ea_name,
214 		 const void *ea_value, const __u16 ea_value_len,
215 		 const struct nls_table *nls_codepage,
216 		 struct cifs_sb_info *cifs_sb);
217 
218 /*
219  * smb1debug.c
220  */
221 void cifs_dump_detail(void *buf, size_t buf_len,
222 		      struct TCP_Server_Info *server);
223 
224 /*
225  * smb1encrypt.c
226  */
227 int cifs_sign_rqst(struct smb_rqst *rqst, struct TCP_Server_Info *server,
228 		   __u32 *pexpected_response_sequence_number);
229 int cifs_verify_signature(struct smb_rqst *rqst,
230 			  struct TCP_Server_Info *server,
231 			  __u32 expected_sequence_number);
232 
233 /*
234  * smb1maperror.c
235  */
236 int map_smb_to_linux_error(char *buf, bool logErr);
237 int map_and_check_smb_error(struct TCP_Server_Info *server,
238 			    struct mid_q_entry *mid, bool logErr);
239 
240 /*
241  * smb1misc.c
242  */
243 unsigned int header_assemble(struct smb_hdr *buffer, char smb_command,
244 			     const struct cifs_tcon *treeCon, int word_count);
245 bool is_valid_oplock_break(char *buffer, struct TCP_Server_Info *srv);
246 unsigned int smbCalcSize(void *buf);
247 
248 /*
249  * smb1ops.c
250  */
251 extern struct smb_version_operations smb1_operations;
252 extern struct smb_version_values smb1_values;
253 
254 void reset_cifs_unix_caps(unsigned int xid, struct cifs_tcon *tcon,
255 			  struct cifs_sb_info *cifs_sb,
256 			  struct smb3_fs_context *ctx);
257 
258 /*
259  * smb1session.c
260  */
261 int CIFS_SessSetup(const unsigned int xid, struct cifs_ses *ses,
262 		   struct TCP_Server_Info *server,
263 		   const struct nls_table *nls_cp);
264 
265 /*
266  * smb1transport.c
267  */
268 struct mid_q_entry *cifs_setup_async_request(struct TCP_Server_Info *server,
269 					     struct smb_rqst *rqst);
270 int SendReceiveNoRsp(const unsigned int xid, struct cifs_ses *ses,
271 		     char *in_buf, unsigned int in_len, int flags);
272 int cifs_check_receive(struct mid_q_entry *mid, struct TCP_Server_Info *server,
273 		       bool log_error);
274 struct mid_q_entry *cifs_setup_request(struct cifs_ses *ses,
275 				       struct TCP_Server_Info *server,
276 				       struct smb_rqst *rqst);
277 int SendReceive2(const unsigned int xid, struct cifs_ses *ses,
278 		 struct kvec *iov, int n_vec, int *resp_buf_type /* ret */,
279 		 const int flags, struct kvec *resp_iov);
280 int SendReceive(const unsigned int xid, struct cifs_ses *ses,
281 		struct smb_hdr *in_buf, unsigned int in_len,
282 		struct smb_hdr *out_buf, int *pbytes_returned,
283 		const int flags);
284 bool cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server,
285 		       char *buf, int malformed);
286 int checkSMB(char *buf, unsigned int pdu_len, unsigned int total_read,
287 	     struct TCP_Server_Info *server);
288 
289 
290 static inline __u16
291 get_mid(const struct smb_hdr *smb)
292 {
293 	return le16_to_cpu(smb->Mid);
294 }
295 
296 static inline bool
297 compare_mid(__u16 mid, const struct smb_hdr *smb)
298 {
299 	return mid == le16_to_cpu(smb->Mid);
300 }
301 
302 #define GETU16(var)  (*((__u16 *)var))	/* BB check for endian issues */
303 #define GETU32(var)  (*((__u32 *)var))	/* BB check for endian issues */
304 
305 /* given a pointer to an smb_hdr, retrieve a void pointer to the ByteCount */
306 static inline void *
307 BCC(struct smb_hdr *smb)
308 {
309 	return (void *)smb + sizeof(*smb) + 2 * smb->WordCount;
310 }
311 
312 /* given a pointer to an smb_hdr retrieve the pointer to the byte area */
313 #define pByteArea(smb_var) (BCC(smb_var) + 2)
314 
315 /* get the unconverted ByteCount for a SMB packet and return it */
316 static inline __u16
317 get_bcc(struct smb_hdr *hdr)
318 {
319 	__le16 *bc_ptr = (__le16 *)BCC(hdr);
320 
321 	return get_unaligned_le16(bc_ptr);
322 }
323 
324 /* set the ByteCount for a SMB packet in little-endian */
325 static inline void
326 put_bcc(__u16 count, struct smb_hdr *hdr)
327 {
328 	__le16 *bc_ptr = (__le16 *)BCC(hdr);
329 
330 	put_unaligned_le16(count, bc_ptr);
331 }
332 
333 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */
334 
335 #endif /* _SMB1PROTO_H */
336