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 Opt_unicode, 139 140 /* Mount options which take numeric value */ 141 Opt_backupuid, 142 Opt_backupgid, 143 Opt_uid, 144 Opt_cruid, 145 Opt_gid, 146 Opt_port, 147 Opt_file_mode, 148 Opt_dirmode, 149 Opt_min_enc_offload, 150 Opt_retrans, 151 Opt_blocksize, 152 Opt_rasize, 153 Opt_rsize, 154 Opt_wsize, 155 Opt_actimeo, 156 Opt_acdirmax, 157 Opt_acregmax, 158 Opt_closetimeo, 159 Opt_echo_interval, 160 Opt_max_credits, 161 Opt_max_cached_dirs, 162 Opt_snapshot, 163 Opt_max_channels, 164 Opt_handletimeout, 165 166 /* Mount options which take string value */ 167 Opt_source, 168 Opt_user, 169 Opt_pass, 170 Opt_pass2, 171 Opt_ip, 172 Opt_domain, 173 Opt_srcaddr, 174 Opt_iocharset, 175 Opt_netbiosname, 176 Opt_servern, 177 Opt_nbsessinit, 178 Opt_ver, 179 Opt_vers, 180 Opt_sec, 181 Opt_cache, 182 Opt_reparse, 183 Opt_upcalltarget, 184 Opt_nativesocket, 185 Opt_symlink, 186 Opt_symlinkroot, 187 188 /* Mount options to be ignored */ 189 Opt_ignore, 190 191 Opt_err 192 }; 193 194 struct smb3_fs_context { 195 bool forceuid_specified; 196 bool forcegid_specified; 197 bool uid_specified; 198 bool cruid_specified; 199 bool gid_specified; 200 bool sloppy; 201 bool got_ip; 202 bool got_version; 203 bool got_rsize; 204 bool got_wsize; 205 bool got_bsize; 206 unsigned short port; 207 208 char *username; 209 char *password; 210 char *password2; 211 char *domainname; 212 char *source; 213 char *server_hostname; 214 char *UNC; 215 char *nodename; 216 char workstation_name[CIFS_MAX_WORKSTATION_LEN]; 217 char *iocharset; /* local code page for mapping to and from Unicode */ 218 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */ 219 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */ 220 int rfc1001_sessinit; 221 kuid_t cred_uid; 222 kuid_t linux_uid; 223 kgid_t linux_gid; 224 kuid_t backupuid; 225 kgid_t backupgid; 226 umode_t file_mode; 227 umode_t dir_mode; 228 enum securityEnum sectype; /* sectype requested via mnt opts */ 229 enum upcall_target_enum upcall_target; /* where to upcall for mount */ 230 bool sign; /* was signing requested via mnt opts? */ 231 bool ignore_signature:1; 232 bool retry:1; 233 bool intr:1; 234 bool setuids:1; 235 bool setuidfromacl:1; 236 bool override_uid:1; 237 bool override_gid:1; 238 bool dynperm:1; 239 bool noperm:1; 240 bool nodelete:1; 241 bool mode_ace:1; 242 bool no_psx_acl:1; /* set if posix acl support should be disabled */ 243 bool cifs_acl:1; 244 bool backupuid_specified; /* mount option backupuid is specified */ 245 bool backupgid_specified; /* mount option backupgid is specified */ 246 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/ 247 bool server_ino:1; /* use inode numbers from server ie UniqueId */ 248 bool direct_io:1; 249 bool strict_io:1; /* strict cache behavior */ 250 bool cache_ro:1; 251 bool cache_rw:1; 252 bool remap:1; /* set to remap seven reserved chars in filenames */ 253 bool sfu_remap:1; /* remap seven reserved chars ala SFU */ 254 bool posix_paths:1; /* unset to not ask for posix pathnames. */ 255 bool no_linux_ext:1; 256 bool linux_ext:1; 257 bool sfu_emul:1; 258 bool nullauth:1; /* attempt to authenticate with null user */ 259 bool nocase:1; /* request case insensitive filenames */ 260 bool nobrl:1; /* disable sending byte range locks to srv */ 261 bool nohandlecache:1; /* disable caching dir handles if srvr probs */ 262 bool mand_lock:1; /* send mandatory not posix byte range lock reqs */ 263 bool seal:1; /* request transport encryption on share */ 264 bool nodfs:1; /* Do not request DFS, even if available */ 265 bool local_lease:1; /* check leases only on local system, not remote */ 266 bool noblocksnd:1; 267 bool noautotune:1; 268 bool nostrictsync:1; /* do not force expensive SMBflush on every sync */ 269 bool no_lease:1; /* disable requesting leases */ 270 bool no_sparse:1; /* do not attempt to set files sparse */ 271 bool fsc:1; /* enable fscache */ 272 bool mfsymlinks:1; /* use Minshall+French Symlinks */ 273 bool multiuser:1; 274 bool rwpidforward:1; /* pid forward for read/write operations */ 275 bool nosharesock:1; 276 bool persistent:1; 277 bool nopersistent:1; 278 bool resilient:1; /* noresilient not required since not fored for CA */ 279 bool domainauto:1; 280 bool rdma:1; 281 bool multichannel:1; 282 bool use_client_guid:1; 283 /* reuse existing guid for multichannel */ 284 u8 client_guid[SMB2_CLIENT_GUID_SIZE]; 285 /* User-specified original r/wsize value */ 286 unsigned int vol_rsize; 287 unsigned int vol_wsize; 288 unsigned int bsize; 289 unsigned int rasize; 290 unsigned int rsize; 291 unsigned int wsize; 292 unsigned int min_offload; 293 unsigned int retrans; 294 bool sockopt_tcp_nodelay:1; 295 /* attribute cache timeout for files and directories in jiffies */ 296 unsigned long acregmax; 297 unsigned long acdirmax; 298 /* timeout for deferred close of files in jiffies */ 299 unsigned long closetimeo; 300 struct smb_version_operations *ops; 301 struct smb_version_values *vals; 302 char *prepath; 303 struct sockaddr_storage dstaddr; /* destination address */ 304 struct sockaddr_storage srcaddr; /* allow binding to a local IP */ 305 struct nls_table *local_nls; /* This is a copy of the pointer in cifs_sb */ 306 unsigned int echo_interval; /* echo interval in secs */ 307 __u64 snapshot_time; /* needed for timewarp tokens */ 308 __u32 handle_timeout; /* persistent and durable handle timeout in ms */ 309 unsigned int max_credits; /* smb3 max_credits 10 < credits < 60000 */ 310 unsigned int max_channels; 311 unsigned int max_cached_dirs; 312 bool compress; /* enable SMB2 messages (READ/WRITE) de/compression */ 313 bool rootfs:1; /* if it's a SMB root file system */ 314 bool witness:1; /* use witness protocol */ 315 int unicode; 316 char *leaf_fullpath; 317 struct cifs_ses *dfs_root_ses; 318 bool dfs_automount:1; /* set for dfs automount only */ 319 enum cifs_reparse_type reparse_type; 320 enum cifs_symlink_type symlink_type; 321 bool nonativesocket:1; 322 bool dfs_conn:1; /* set for dfs mounts */ 323 char *dns_dom; 324 char *symlinkroot; /* top level directory for native SMB symlinks in absolute format */ 325 }; 326 327 extern const struct fs_parameter_spec smb3_fs_parameters[]; 328 329 extern enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb); 330 331 extern int smb3_init_fs_context(struct fs_context *fc); 332 extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx); 333 extern void smb3_cleanup_fs_context(struct smb3_fs_context *ctx); 334 335 static inline struct smb3_fs_context *smb3_fc2context(const struct fs_context *fc) 336 { 337 return fc->fs_private; 338 } 339 340 extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx); 341 extern int smb3_sync_session_ctx_passwords(struct cifs_sb_info *cifs_sb, struct cifs_ses *ses); 342 extern void smb3_update_mnt_flags(struct cifs_sb_info *cifs_sb); 343 344 /* 345 * max deferred close timeout (jiffies) - 2^30 346 */ 347 #define SMB3_MAX_DCLOSETIMEO (1 << 30) 348 #define SMB3_DEF_DCLOSETIMEO (1 * HZ) /* even 1 sec enough to help eg open/write/close/open/read */ 349 #define MAX_CACHED_FIDS 16 350 extern char *cifs_sanitize_prepath(char *prepath, gfp_t gfp); 351 352 extern struct mutex cifs_mount_mutex; 353 354 static inline void cifs_mount_lock(void) 355 { 356 mutex_lock(&cifs_mount_mutex); 357 } 358 359 static inline void cifs_mount_unlock(void) 360 { 361 mutex_unlock(&cifs_mount_mutex); 362 } 363 364 #endif 365