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