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