xref: /linux/fs/smb/client/fs_context.h (revision ba6ec09911b805778a2fed6d626bfe77b011a717)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2020, Microsoft Corporation.
4  *
5  *   Author(s): Steve French <stfrench@microsoft.com>
6  *              David Howells <dhowells@redhat.com>
7  */
8 
9 #ifndef _FS_CONTEXT_H
10 #define _FS_CONTEXT_H
11 
12 #include "cifsglob.h"
13 #include <linux/parser.h>
14 #include <linux/fs_parser.h>
15 
16 /* Log errors in fs_context (new mount api) but also in dmesg (old style) */
17 #define cifs_errorf(fc, fmt, ...)			\
18 	do {						\
19 		errorf(fc, fmt, ## __VA_ARGS__);	\
20 		cifs_dbg(VFS, fmt, ## __VA_ARGS__);	\
21 	} while (0)
22 
23 enum smb_version {
24 	Smb_1 = 1,
25 	Smb_20,
26 	Smb_21,
27 	Smb_30,
28 	Smb_302,
29 	Smb_311,
30 	Smb_3any,
31 	Smb_default,
32 	Smb_version_err
33 };
34 
35 enum {
36 	Opt_cache_loose,
37 	Opt_cache_strict,
38 	Opt_cache_none,
39 	Opt_cache_ro,
40 	Opt_cache_rw,
41 	Opt_cache_err
42 };
43 
44 enum cifs_reparse_parm {
45 	Opt_reparse_default,
46 	Opt_reparse_none,
47 	Opt_reparse_nfs,
48 	Opt_reparse_wsl,
49 	Opt_reparse_err
50 };
51 
52 enum cifs_symlink_parm {
53 	Opt_symlink_default,
54 	Opt_symlink_none,
55 	Opt_symlink_native,
56 	Opt_symlink_unix,
57 	Opt_symlink_mfsymlinks,
58 	Opt_symlink_sfu,
59 	Opt_symlink_nfs,
60 	Opt_symlink_wsl,
61 	Opt_symlink_err
62 };
63 
64 enum cifs_sec_param {
65 	Opt_sec_krb5,
66 	Opt_sec_krb5i,
67 	Opt_sec_krb5p,
68 	Opt_sec_ntlmsspi,
69 	Opt_sec_ntlmssp,
70 	Opt_sec_ntlmv2,
71 	Opt_sec_ntlmv2i,
72 	Opt_sec_none,
73 
74 	Opt_sec_err
75 };
76 
77 enum cifs_upcall_target_param {
78 	Opt_upcall_target_mount,
79 	Opt_upcall_target_application,
80 	Opt_upcall_target_err
81 };
82 
83 enum cifs_param {
84 	/* Mount options that take no arguments */
85 	Opt_user_xattr,
86 	Opt_forceuid,
87 	Opt_forcegid,
88 	Opt_noblocksend,
89 	Opt_noautotune,
90 	Opt_nolease,
91 	Opt_nosparse,
92 	Opt_hard,
93 	Opt_soft,
94 	Opt_perm,
95 	Opt_nodelete,
96 	Opt_mapposix,
97 	Opt_mapchars,
98 	Opt_nomapchars,
99 	Opt_sfu,
100 	Opt_nodfs,
101 	Opt_posixpaths,
102 	Opt_unix,
103 	Opt_nocase,
104 	Opt_brl,
105 	Opt_handlecache,
106 	Opt_forcemandatorylock,
107 	Opt_setuidfromacl,
108 	Opt_setuids,
109 	Opt_dynperm,
110 	Opt_intr,
111 	Opt_strictsync,
112 	Opt_serverino,
113 	Opt_rwpidforward,
114 	Opt_cifsacl,
115 	Opt_acl,
116 	Opt_locallease,
117 	Opt_sign,
118 	Opt_ignore_signature,
119 	Opt_seal,
120 	Opt_noac,
121 	Opt_fsc,
122 	Opt_mfsymlinks,
123 	Opt_multiuser,
124 	Opt_sloppy,
125 	Opt_nosharesock,
126 	Opt_persistent,
127 	Opt_resilient,
128 	Opt_tcp_nodelay,
129 	Opt_domainauto,
130 	Opt_rdma,
131 	Opt_modesid,
132 	Opt_rootfs,
133 	Opt_multichannel,
134 	Opt_compress,
135 	Opt_witness,
136 	Opt_is_upcall_target_mount,
137 	Opt_is_upcall_target_application,
138 
139 	/* Mount options which take numeric value */
140 	Opt_backupuid,
141 	Opt_backupgid,
142 	Opt_uid,
143 	Opt_cruid,
144 	Opt_gid,
145 	Opt_port,
146 	Opt_file_mode,
147 	Opt_dirmode,
148 	Opt_min_enc_offload,
149 	Opt_retrans,
150 	Opt_blocksize,
151 	Opt_rasize,
152 	Opt_rsize,
153 	Opt_wsize,
154 	Opt_actimeo,
155 	Opt_acdirmax,
156 	Opt_acregmax,
157 	Opt_closetimeo,
158 	Opt_echo_interval,
159 	Opt_max_credits,
160 	Opt_max_cached_dirs,
161 	Opt_snapshot,
162 	Opt_max_channels,
163 	Opt_handletimeout,
164 
165 	/* Mount options which take string value */
166 	Opt_source,
167 	Opt_user,
168 	Opt_pass,
169 	Opt_pass2,
170 	Opt_ip,
171 	Opt_domain,
172 	Opt_srcaddr,
173 	Opt_iocharset,
174 	Opt_netbiosname,
175 	Opt_servern,
176 	Opt_ver,
177 	Opt_vers,
178 	Opt_sec,
179 	Opt_cache,
180 	Opt_reparse,
181 	Opt_upcalltarget,
182 	Opt_nativesocket,
183 	Opt_symlink,
184 	Opt_symlinkroot,
185 
186 	/* Mount options to be ignored */
187 	Opt_ignore,
188 
189 	Opt_err
190 };
191 
192 struct smb3_fs_context {
193 	bool forceuid_specified;
194 	bool forcegid_specified;
195 	bool uid_specified;
196 	bool cruid_specified;
197 	bool gid_specified;
198 	bool sloppy;
199 	bool got_ip;
200 	bool got_version;
201 	bool got_rsize;
202 	bool got_wsize;
203 	bool got_bsize;
204 	unsigned short port;
205 
206 	char *username;
207 	char *password;
208 	char *password2;
209 	char *domainname;
210 	char *source;
211 	char *server_hostname;
212 	char *UNC;
213 	char *nodename;
214 	char workstation_name[CIFS_MAX_WORKSTATION_LEN];
215 	char *iocharset;  /* local code page for mapping to and from Unicode */
216 	char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
217 	char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
218 	kuid_t cred_uid;
219 	kuid_t linux_uid;
220 	kgid_t linux_gid;
221 	kuid_t backupuid;
222 	kgid_t backupgid;
223 	umode_t file_mode;
224 	umode_t dir_mode;
225 	enum securityEnum sectype; /* sectype requested via mnt opts */
226 	enum upcall_target_enum upcall_target; /* where to upcall for mount */
227 	bool sign; /* was signing requested via mnt opts? */
228 	bool ignore_signature:1;
229 	bool retry:1;
230 	bool intr:1;
231 	bool setuids:1;
232 	bool setuidfromacl:1;
233 	bool override_uid:1;
234 	bool override_gid:1;
235 	bool dynperm:1;
236 	bool noperm:1;
237 	bool nodelete:1;
238 	bool mode_ace:1;
239 	bool no_psx_acl:1; /* set if posix acl support should be disabled */
240 	bool cifs_acl:1;
241 	bool backupuid_specified; /* mount option  backupuid  is specified */
242 	bool backupgid_specified; /* mount option  backupgid  is specified */
243 	bool no_xattr:1;   /* set if xattr (EA) support should be disabled*/
244 	bool server_ino:1; /* use inode numbers from server ie UniqueId */
245 	bool direct_io:1;
246 	bool strict_io:1; /* strict cache behavior */
247 	bool cache_ro:1;
248 	bool cache_rw:1;
249 	bool remap:1;      /* set to remap seven reserved chars in filenames */
250 	bool sfu_remap:1;  /* remap seven reserved chars ala SFU */
251 	bool posix_paths:1; /* unset to not ask for posix pathnames. */
252 	bool no_linux_ext:1;
253 	bool linux_ext:1;
254 	bool sfu_emul:1;
255 	bool nullauth:1;   /* attempt to authenticate with null user */
256 	bool nocase:1;     /* request case insensitive filenames */
257 	bool nobrl:1;      /* disable sending byte range locks to srv */
258 	bool nohandlecache:1; /* disable caching dir handles if srvr probs */
259 	bool mand_lock:1;  /* send mandatory not posix byte range lock reqs */
260 	bool seal:1;       /* request transport encryption on share */
261 	bool nodfs:1;      /* Do not request DFS, even if available */
262 	bool local_lease:1; /* check leases only on local system, not remote */
263 	bool noblocksnd:1;
264 	bool noautotune:1;
265 	bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
266 	bool no_lease:1;     /* disable requesting leases */
267 	bool no_sparse:1;    /* do not attempt to set files sparse */
268 	bool fsc:1;	/* enable fscache */
269 	bool mfsymlinks:1; /* use Minshall+French Symlinks */
270 	bool multiuser:1;
271 	bool rwpidforward:1; /* pid forward for read/write operations */
272 	bool nosharesock:1;
273 	bool persistent:1;
274 	bool nopersistent:1;
275 	bool resilient:1; /* noresilient not required since not fored for CA */
276 	bool domainauto:1;
277 	bool rdma:1;
278 	bool multichannel:1;
279 	bool use_client_guid:1;
280 	/* reuse existing guid for multichannel */
281 	u8 client_guid[SMB2_CLIENT_GUID_SIZE];
282 	unsigned int bsize;
283 	unsigned int rasize;
284 	unsigned int rsize;
285 	unsigned int wsize;
286 	unsigned int min_offload;
287 	unsigned int retrans;
288 	bool sockopt_tcp_nodelay:1;
289 	/* attribute cache timeout for files and directories in jiffies */
290 	unsigned long acregmax;
291 	unsigned long acdirmax;
292 	/* timeout for deferred close of files in jiffies */
293 	unsigned long closetimeo;
294 	struct smb_version_operations *ops;
295 	struct smb_version_values *vals;
296 	char *prepath;
297 	struct sockaddr_storage dstaddr; /* destination address */
298 	struct sockaddr_storage srcaddr; /* allow binding to a local IP */
299 	struct nls_table *local_nls; /* This is a copy of the pointer in cifs_sb */
300 	unsigned int echo_interval; /* echo interval in secs */
301 	__u64 snapshot_time; /* needed for timewarp tokens */
302 	__u32 handle_timeout; /* persistent and durable handle timeout in ms */
303 	unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
304 	unsigned int max_channels;
305 	unsigned int max_cached_dirs;
306 	bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */
307 	bool rootfs:1; /* if it's a SMB root file system */
308 	bool witness:1; /* use witness protocol */
309 	char *leaf_fullpath;
310 	struct cifs_ses *dfs_root_ses;
311 	bool dfs_automount:1; /* set for dfs automount only */
312 	enum cifs_reparse_type reparse_type;
313 	enum cifs_symlink_type symlink_type;
314 	bool nonativesocket:1;
315 	bool dfs_conn:1; /* set for dfs mounts */
316 	char *dns_dom;
317 	char *symlinkroot; /* top level directory for native SMB symlinks in absolute format */
318 };
319 
320 extern const struct fs_parameter_spec smb3_fs_parameters[];
321 
322 extern enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb);
323 
324 extern int smb3_init_fs_context(struct fs_context *fc);
325 extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx);
326 extern void smb3_cleanup_fs_context(struct smb3_fs_context *ctx);
327 
smb3_fc2context(const struct fs_context * fc)328 static inline struct smb3_fs_context *smb3_fc2context(const struct fs_context *fc)
329 {
330 	return fc->fs_private;
331 }
332 
333 extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx);
334 extern int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses);
335 extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
336 
337 /*
338  * max deferred close timeout (jiffies) - 2^30
339  */
340 #define SMB3_MAX_DCLOSETIMEO (1 << 30)
341 #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */
342 #define MAX_CACHED_FIDS 16
343 extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
344 
345 extern struct mutex cifs_mount_mutex;
346 
cifs_mount_lock(void)347 static inline void cifs_mount_lock(void)
348 {
349 	mutex_lock(&cifs_mount_mutex);
350 }
351 
cifs_mount_unlock(void)352 static inline void cifs_mount_unlock(void)
353 {
354 	mutex_unlock(&cifs_mount_mutex);
355 }
356 
357 #endif
358