xref: /openbmc/linux/fs/smb/client/fs_context.h (revision 390c08fd3eeb3ebd0e9576de8b6eec8eae2d595d)
138c8a9a5SSteve French /* SPDX-License-Identifier: GPL-2.0-or-later */
238c8a9a5SSteve French /*
338c8a9a5SSteve French  *   Copyright (C) 2020, Microsoft Corporation.
438c8a9a5SSteve French  *
538c8a9a5SSteve French  *   Author(s): Steve French <stfrench@microsoft.com>
638c8a9a5SSteve French  *              David Howells <dhowells@redhat.com>
738c8a9a5SSteve French  */
838c8a9a5SSteve French 
938c8a9a5SSteve French #ifndef _FS_CONTEXT_H
1038c8a9a5SSteve French #define _FS_CONTEXT_H
1138c8a9a5SSteve French 
1238c8a9a5SSteve French #include "cifsglob.h"
1338c8a9a5SSteve French #include <linux/parser.h>
1438c8a9a5SSteve French #include <linux/fs_parser.h>
1538c8a9a5SSteve French 
1638c8a9a5SSteve French /* Log errors in fs_context (new mount api) but also in dmesg (old style) */
1738c8a9a5SSteve French #define cifs_errorf(fc, fmt, ...)			\
1838c8a9a5SSteve French 	do {						\
1938c8a9a5SSteve French 		errorf(fc, fmt, ## __VA_ARGS__);	\
2038c8a9a5SSteve French 		cifs_dbg(VFS, fmt, ## __VA_ARGS__);	\
2138c8a9a5SSteve French 	} while (0)
2238c8a9a5SSteve French 
2338c8a9a5SSteve French enum smb_version {
2438c8a9a5SSteve French 	Smb_1 = 1,
2538c8a9a5SSteve French 	Smb_20,
2638c8a9a5SSteve French 	Smb_21,
2738c8a9a5SSteve French 	Smb_30,
2838c8a9a5SSteve French 	Smb_302,
2938c8a9a5SSteve French 	Smb_311,
3038c8a9a5SSteve French 	Smb_3any,
3138c8a9a5SSteve French 	Smb_default,
3238c8a9a5SSteve French 	Smb_version_err
3338c8a9a5SSteve French };
3438c8a9a5SSteve French 
3538c8a9a5SSteve French enum {
3638c8a9a5SSteve French 	Opt_cache_loose,
3738c8a9a5SSteve French 	Opt_cache_strict,
3838c8a9a5SSteve French 	Opt_cache_none,
3938c8a9a5SSteve French 	Opt_cache_ro,
4038c8a9a5SSteve French 	Opt_cache_rw,
4138c8a9a5SSteve French 	Opt_cache_err
4238c8a9a5SSteve French };
4338c8a9a5SSteve French 
4438c8a9a5SSteve French enum cifs_sec_param {
4538c8a9a5SSteve French 	Opt_sec_krb5,
4638c8a9a5SSteve French 	Opt_sec_krb5i,
4738c8a9a5SSteve French 	Opt_sec_krb5p,
4838c8a9a5SSteve French 	Opt_sec_ntlmsspi,
4938c8a9a5SSteve French 	Opt_sec_ntlmssp,
5038c8a9a5SSteve French 	Opt_sec_ntlmv2,
5138c8a9a5SSteve French 	Opt_sec_ntlmv2i,
5238c8a9a5SSteve French 	Opt_sec_none,
5338c8a9a5SSteve French 
5438c8a9a5SSteve French 	Opt_sec_err
5538c8a9a5SSteve French };
5638c8a9a5SSteve French 
5738c8a9a5SSteve French enum cifs_param {
5838c8a9a5SSteve French 	/* Mount options that take no arguments */
5938c8a9a5SSteve French 	Opt_user_xattr,
6038c8a9a5SSteve French 	Opt_forceuid,
6138c8a9a5SSteve French 	Opt_forcegid,
6238c8a9a5SSteve French 	Opt_noblocksend,
6338c8a9a5SSteve French 	Opt_noautotune,
6438c8a9a5SSteve French 	Opt_nolease,
6538c8a9a5SSteve French 	Opt_nosparse,
6638c8a9a5SSteve French 	Opt_hard,
6738c8a9a5SSteve French 	Opt_soft,
6838c8a9a5SSteve French 	Opt_perm,
6938c8a9a5SSteve French 	Opt_nodelete,
7038c8a9a5SSteve French 	Opt_mapposix,
7138c8a9a5SSteve French 	Opt_mapchars,
7238c8a9a5SSteve French 	Opt_nomapchars,
7338c8a9a5SSteve French 	Opt_sfu,
7438c8a9a5SSteve French 	Opt_nodfs,
7538c8a9a5SSteve French 	Opt_posixpaths,
7638c8a9a5SSteve French 	Opt_unix,
7738c8a9a5SSteve French 	Opt_nocase,
7838c8a9a5SSteve French 	Opt_brl,
7938c8a9a5SSteve French 	Opt_handlecache,
8038c8a9a5SSteve French 	Opt_forcemandatorylock,
8138c8a9a5SSteve French 	Opt_setuidfromacl,
8238c8a9a5SSteve French 	Opt_setuids,
8338c8a9a5SSteve French 	Opt_dynperm,
8438c8a9a5SSteve French 	Opt_intr,
8538c8a9a5SSteve French 	Opt_strictsync,
8638c8a9a5SSteve French 	Opt_serverino,
8738c8a9a5SSteve French 	Opt_rwpidforward,
8838c8a9a5SSteve French 	Opt_cifsacl,
8938c8a9a5SSteve French 	Opt_acl,
9038c8a9a5SSteve French 	Opt_locallease,
9138c8a9a5SSteve French 	Opt_sign,
9238c8a9a5SSteve French 	Opt_ignore_signature,
9338c8a9a5SSteve French 	Opt_seal,
9438c8a9a5SSteve French 	Opt_noac,
9538c8a9a5SSteve French 	Opt_fsc,
9638c8a9a5SSteve French 	Opt_mfsymlinks,
9738c8a9a5SSteve French 	Opt_multiuser,
9838c8a9a5SSteve French 	Opt_sloppy,
9938c8a9a5SSteve French 	Opt_nosharesock,
10038c8a9a5SSteve French 	Opt_persistent,
10138c8a9a5SSteve French 	Opt_resilient,
10238c8a9a5SSteve French 	Opt_tcp_nodelay,
10338c8a9a5SSteve French 	Opt_domainauto,
10438c8a9a5SSteve French 	Opt_rdma,
10538c8a9a5SSteve French 	Opt_modesid,
10638c8a9a5SSteve French 	Opt_rootfs,
10738c8a9a5SSteve French 	Opt_multichannel,
10838c8a9a5SSteve French 	Opt_compress,
10938c8a9a5SSteve French 	Opt_witness,
11038c8a9a5SSteve French 
11138c8a9a5SSteve French 	/* Mount options which take numeric value */
11238c8a9a5SSteve French 	Opt_backupuid,
11338c8a9a5SSteve French 	Opt_backupgid,
11438c8a9a5SSteve French 	Opt_uid,
11538c8a9a5SSteve French 	Opt_cruid,
11638c8a9a5SSteve French 	Opt_gid,
11738c8a9a5SSteve French 	Opt_port,
11838c8a9a5SSteve French 	Opt_file_mode,
11938c8a9a5SSteve French 	Opt_dirmode,
12038c8a9a5SSteve French 	Opt_min_enc_offload,
12138c8a9a5SSteve French 	Opt_blocksize,
12238c8a9a5SSteve French 	Opt_rasize,
12338c8a9a5SSteve French 	Opt_rsize,
12438c8a9a5SSteve French 	Opt_wsize,
12538c8a9a5SSteve French 	Opt_actimeo,
12638c8a9a5SSteve French 	Opt_acdirmax,
12738c8a9a5SSteve French 	Opt_acregmax,
12838c8a9a5SSteve French 	Opt_closetimeo,
12938c8a9a5SSteve French 	Opt_echo_interval,
13038c8a9a5SSteve French 	Opt_max_credits,
1316a50d71dSSteve French 	Opt_max_cached_dirs,
13238c8a9a5SSteve French 	Opt_snapshot,
13338c8a9a5SSteve French 	Opt_max_channels,
13438c8a9a5SSteve French 	Opt_handletimeout,
13538c8a9a5SSteve French 
13638c8a9a5SSteve French 	/* Mount options which take string value */
13738c8a9a5SSteve French 	Opt_source,
13838c8a9a5SSteve French 	Opt_user,
13938c8a9a5SSteve French 	Opt_pass,
14038c8a9a5SSteve French 	Opt_ip,
14138c8a9a5SSteve French 	Opt_domain,
14238c8a9a5SSteve French 	Opt_srcaddr,
14338c8a9a5SSteve French 	Opt_iocharset,
14438c8a9a5SSteve French 	Opt_netbiosname,
14538c8a9a5SSteve French 	Opt_servern,
14638c8a9a5SSteve French 	Opt_ver,
14738c8a9a5SSteve French 	Opt_vers,
14838c8a9a5SSteve French 	Opt_sec,
14938c8a9a5SSteve French 	Opt_cache,
15038c8a9a5SSteve French 
15138c8a9a5SSteve French 	/* Mount options to be ignored */
15238c8a9a5SSteve French 	Opt_ignore,
15338c8a9a5SSteve French 
15438c8a9a5SSteve French 	Opt_err
15538c8a9a5SSteve French };
15638c8a9a5SSteve French 
15738c8a9a5SSteve French struct smb3_fs_context {
15838c8a9a5SSteve French 	bool uid_specified;
15938c8a9a5SSteve French 	bool cruid_specified;
16038c8a9a5SSteve French 	bool gid_specified;
16138c8a9a5SSteve French 	bool sloppy;
16238c8a9a5SSteve French 	bool got_ip;
16338c8a9a5SSteve French 	bool got_version;
16438c8a9a5SSteve French 	bool got_rsize;
16538c8a9a5SSteve French 	bool got_wsize;
16638c8a9a5SSteve French 	bool got_bsize;
16738c8a9a5SSteve French 	unsigned short port;
16838c8a9a5SSteve French 
16938c8a9a5SSteve French 	char *username;
17038c8a9a5SSteve French 	char *password;
17138c8a9a5SSteve French 	char *domainname;
17238c8a9a5SSteve French 	char *source;
17338c8a9a5SSteve French 	char *server_hostname;
17438c8a9a5SSteve French 	char *UNC;
17538c8a9a5SSteve French 	char *nodename;
17638c8a9a5SSteve French 	char workstation_name[CIFS_MAX_WORKSTATION_LEN];
17738c8a9a5SSteve French 	char *iocharset;  /* local code page for mapping to and from Unicode */
17838c8a9a5SSteve French 	char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
17938c8a9a5SSteve French 	char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
18038c8a9a5SSteve French 	kuid_t cred_uid;
18138c8a9a5SSteve French 	kuid_t linux_uid;
18238c8a9a5SSteve French 	kgid_t linux_gid;
18338c8a9a5SSteve French 	kuid_t backupuid;
18438c8a9a5SSteve French 	kgid_t backupgid;
18538c8a9a5SSteve French 	umode_t file_mode;
18638c8a9a5SSteve French 	umode_t dir_mode;
18738c8a9a5SSteve French 	enum securityEnum sectype; /* sectype requested via mnt opts */
18838c8a9a5SSteve French 	bool sign; /* was signing requested via mnt opts? */
18938c8a9a5SSteve French 	bool ignore_signature:1;
19038c8a9a5SSteve French 	bool retry:1;
19138c8a9a5SSteve French 	bool intr:1;
19238c8a9a5SSteve French 	bool setuids:1;
19338c8a9a5SSteve French 	bool setuidfromacl:1;
19438c8a9a5SSteve French 	bool override_uid:1;
19538c8a9a5SSteve French 	bool override_gid:1;
19638c8a9a5SSteve French 	bool dynperm:1;
19738c8a9a5SSteve French 	bool noperm:1;
19838c8a9a5SSteve French 	bool nodelete:1;
19938c8a9a5SSteve French 	bool mode_ace:1;
20038c8a9a5SSteve French 	bool no_psx_acl:1; /* set if posix acl support should be disabled */
20138c8a9a5SSteve French 	bool cifs_acl:1;
20238c8a9a5SSteve French 	bool backupuid_specified; /* mount option  backupuid  is specified */
20338c8a9a5SSteve French 	bool backupgid_specified; /* mount option  backupgid  is specified */
20438c8a9a5SSteve French 	bool no_xattr:1;   /* set if xattr (EA) support should be disabled*/
20538c8a9a5SSteve French 	bool server_ino:1; /* use inode numbers from server ie UniqueId */
20638c8a9a5SSteve French 	bool direct_io:1;
20738c8a9a5SSteve French 	bool strict_io:1; /* strict cache behavior */
20838c8a9a5SSteve French 	bool cache_ro:1;
20938c8a9a5SSteve French 	bool cache_rw:1;
21038c8a9a5SSteve French 	bool remap:1;      /* set to remap seven reserved chars in filenames */
21138c8a9a5SSteve French 	bool sfu_remap:1;  /* remap seven reserved chars ala SFU */
21238c8a9a5SSteve French 	bool posix_paths:1; /* unset to not ask for posix pathnames. */
21338c8a9a5SSteve French 	bool no_linux_ext:1;
21438c8a9a5SSteve French 	bool linux_ext:1;
21538c8a9a5SSteve French 	bool sfu_emul:1;
21638c8a9a5SSteve French 	bool nullauth:1;   /* attempt to authenticate with null user */
21738c8a9a5SSteve French 	bool nocase:1;     /* request case insensitive filenames */
21838c8a9a5SSteve French 	bool nobrl:1;      /* disable sending byte range locks to srv */
21938c8a9a5SSteve French 	bool nohandlecache:1; /* disable caching dir handles if srvr probs */
22038c8a9a5SSteve French 	bool mand_lock:1;  /* send mandatory not posix byte range lock reqs */
22138c8a9a5SSteve French 	bool seal:1;       /* request transport encryption on share */
22238c8a9a5SSteve French 	bool nodfs:1;      /* Do not request DFS, even if available */
22338c8a9a5SSteve French 	bool local_lease:1; /* check leases only on local system, not remote */
22438c8a9a5SSteve French 	bool noblocksnd:1;
22538c8a9a5SSteve French 	bool noautotune:1;
22638c8a9a5SSteve French 	bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
22738c8a9a5SSteve French 	bool no_lease:1;     /* disable requesting leases */
22838c8a9a5SSteve French 	bool no_sparse:1;    /* do not attempt to set files sparse */
22938c8a9a5SSteve French 	bool fsc:1;	/* enable fscache */
23038c8a9a5SSteve French 	bool mfsymlinks:1; /* use Minshall+French Symlinks */
23138c8a9a5SSteve French 	bool multiuser:1;
23238c8a9a5SSteve French 	bool rwpidforward:1; /* pid forward for read/write operations */
23338c8a9a5SSteve French 	bool nosharesock:1;
23438c8a9a5SSteve French 	bool persistent:1;
23538c8a9a5SSteve French 	bool nopersistent:1;
23638c8a9a5SSteve French 	bool resilient:1; /* noresilient not required since not fored for CA */
23738c8a9a5SSteve French 	bool domainauto:1;
23838c8a9a5SSteve French 	bool rdma:1;
23938c8a9a5SSteve French 	bool multichannel:1;
24038c8a9a5SSteve French 	bool use_client_guid:1;
24138c8a9a5SSteve French 	/* reuse existing guid for multichannel */
24238c8a9a5SSteve French 	u8 client_guid[SMB2_CLIENT_GUID_SIZE];
24338c8a9a5SSteve French 	unsigned int bsize;
24438c8a9a5SSteve French 	unsigned int rasize;
24538c8a9a5SSteve French 	unsigned int rsize;
24638c8a9a5SSteve French 	unsigned int wsize;
24738c8a9a5SSteve French 	unsigned int min_offload;
24838c8a9a5SSteve French 	bool sockopt_tcp_nodelay:1;
24938c8a9a5SSteve French 	/* attribute cache timemout for files and directories in jiffies */
25038c8a9a5SSteve French 	unsigned long acregmax;
25138c8a9a5SSteve French 	unsigned long acdirmax;
25238c8a9a5SSteve French 	/* timeout for deferred close of files in jiffies */
25338c8a9a5SSteve French 	unsigned long closetimeo;
25438c8a9a5SSteve French 	struct smb_version_operations *ops;
25538c8a9a5SSteve French 	struct smb_version_values *vals;
25638c8a9a5SSteve French 	char *prepath;
25738c8a9a5SSteve French 	struct sockaddr_storage dstaddr; /* destination address */
25838c8a9a5SSteve French 	struct sockaddr_storage srcaddr; /* allow binding to a local IP */
25938c8a9a5SSteve French 	struct nls_table *local_nls; /* This is a copy of the pointer in cifs_sb */
26038c8a9a5SSteve French 	unsigned int echo_interval; /* echo interval in secs */
26138c8a9a5SSteve French 	__u64 snapshot_time; /* needed for timewarp tokens */
26238c8a9a5SSteve French 	__u32 handle_timeout; /* persistent and durable handle timeout in ms */
26338c8a9a5SSteve French 	unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */
26438c8a9a5SSteve French 	unsigned int max_channels;
2656a50d71dSSteve French 	unsigned int max_cached_dirs;
26638c8a9a5SSteve French 	__u16 compression; /* compression algorithm 0xFFFF default 0=disabled */
26738c8a9a5SSteve French 	bool rootfs:1; /* if it's a SMB root file system */
26838c8a9a5SSteve French 	bool witness:1; /* use witness protocol */
26938c8a9a5SSteve French 	char *leaf_fullpath;
27038c8a9a5SSteve French 	struct cifs_ses *dfs_root_ses;
271*390c08fdSPaulo Alcantara 	bool dfs_automount:1; /* set for dfs automount only */
27238c8a9a5SSteve French };
27338c8a9a5SSteve French 
27438c8a9a5SSteve French extern const struct fs_parameter_spec smb3_fs_parameters[];
27538c8a9a5SSteve French 
27638c8a9a5SSteve French extern int smb3_init_fs_context(struct fs_context *fc);
27738c8a9a5SSteve French extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx);
27838c8a9a5SSteve French extern void smb3_cleanup_fs_context(struct smb3_fs_context *ctx);
27938c8a9a5SSteve French 
28038c8a9a5SSteve French static inline struct smb3_fs_context *smb3_fc2context(const struct fs_context *fc)
28138c8a9a5SSteve French {
28238c8a9a5SSteve French 	return fc->fs_private;
28338c8a9a5SSteve French }
28438c8a9a5SSteve French 
28538c8a9a5SSteve French extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx);
28638c8a9a5SSteve French extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb);
28738c8a9a5SSteve French 
28838c8a9a5SSteve French /*
28938c8a9a5SSteve French  * max deferred close timeout (jiffies) - 2^30
29038c8a9a5SSteve French  */
29138c8a9a5SSteve French #define SMB3_MAX_DCLOSETIMEO (1 << 30)
29238c8a9a5SSteve French #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */
2936a50d71dSSteve French #define MAX_CACHED_FIDS 16
29438c8a9a5SSteve French extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp);
29538c8a9a5SSteve French 
29638c8a9a5SSteve French #endif
297