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