if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) &&
symroot && symname[0] == '/') { /* * This is a request to create an absolute symlink on the server * which does not support POSIX paths, and expects symlink in * NT-style path. So convert absolute Linux symlink target path * to the absolute NT-style path. Root of the NT-style path for * symlinks is specified in "symlinkroot" mount option. This will * ensure compatibility of this symlink stored in absolute form * on the SMB server.
*/ if (!strstarts(symname, symroot)) { /* * If the absolute Linux symlink target path is not * inside "symlinkroot" location then there is no way * to convert such Linux symlink to NT-style path.
*/
cifs_dbg(VFS, "absolute symlink '%s' cannot be converted to NT format " "because it is outside of symlinkroot='%s'\n",
symname, symroot);
rc = -EINVAL; goto out;
}
len = strlen(symroot); if (symroot[len - 1] != '/')
len++; if (symname[len] >= 'a' && symname[len] <= 'z' &&
(symname[len+1] == '/' || symname[len+1] == '\0')) { /* * Symlink points to Linux target /symlinkroot/x/path/... * where 'x' is the lowercase local Windows drive. * NT-style path for 'x' has common form \??\X:\path\... * with uppercase local Windows drive.
*/ int common_path_len = strlen(symname+len+1)+1;
sym = kzalloc(6+common_path_len, GFP_KERNEL); if (!sym) {
rc = -ENOMEM; goto out;
}
memcpy(sym, "\\??\\", 4);
sym[4] = symname[len] - ('a'-'A');
sym[5] = ':';
memcpy(sym+6, symname+len+1, common_path_len);
} else { /* Unhandled absolute symlink. Report an error. */
cifs_dbg(
VFS, "absolute symlink '%s' cannot be converted to NT format " "because it points to unknown target\n",
symname);
rc = -EINVAL; goto out;
}
} else { /* * This is request to either create an absolute symlink on * server which expects POSIX paths or it is an request to * create a relative symlink from the current directory. * These paths have same format as relative SMB symlinks, * so no conversion is needed. So just take symname as-is.
*/
sym = kstrdup(symname, GFP_KERNEL); if (!sym) {
rc = -ENOMEM; goto out;
}
}
if (sep == '\\')
convert_delimiter(sym, sep);
/* * For absolute NT symlinks it is required to pass also leading * backslash and to not mangle NT object prefix "\\??\\" and not to * mangle colon in drive letter. But cifs_convert_path_to_utf16() * removes leading backslash and replaces '?' and ':'. So temporary * mask these characters in NT object prefix by '_' and then change * them back.
*/ if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) && symname[0] == '/')
sym[0] = sym[1] = sym[2] = sym[5] = '_';
/* * SMB distinguish between symlink to directory and symlink to file. * They cannot be exchanged (symlink of file type which points to * directory cannot be resolved and vice-versa). Try to detect if * the symlink target could be a directory or not. When detection * fails then treat symlink as a file (non-directory) symlink.
*/
directory = false;
rc = detect_directory_symlink_target(cifs_sb, xid, full_path, symname, &directory); if (rc < 0) goto out;
slen = 2 * UniStrnlen((wchar_t *)path, REPARSE_SYM_PATH_MAX);
poff = 0;
plen = slen; if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) && symname[0] == '/') { /* * For absolute NT symlinks skip leading "\\??\\" in PrintName as * PrintName is user visible location in DOS/Win32 format (not in NT format).
*/
poff = 4;
plen -= 2 * poff;
}
len = sizeof(*buf) + plen + slen;
buf = kzalloc(len, GFP_KERNEL); if (!buf) {
rc = -ENOMEM; goto out;
}
/* * First do some simple check. If the original Linux symlink target ends * with slash, or last path component is dot or dot-dot then it is for * sure symlink to the directory.
*/
basename = kbasename(symname);
basename_len = strlen(basename); if (basename_len == 0 || /* symname ends with slash */
(basename_len == 1 && basename[0] == '.') || /* last component is "." */
(basename_len == 2 && basename[0] == '.' && basename[1] == '.')) { /* or ".." */
*directory = true; return 0;
}
/* * For absolute symlinks it is not possible to determine * if it should point to directory or file.
*/ if (symname[0] == '/') {
cifs_dbg(FYI, "%s: cannot determinate if the symlink target path '%s' " "is directory or not, creating '%s' as file symlink\n",
__func__, symname, full_path); return 0;
}
/* * If it was not detected as directory yet and the symlink is relative * then try to resolve the path on the SMB server, check if the path * exists and determinate if it is a directory or not.
*/
/* Try to open as a directory (NOT_FILE) */
oplock = 0;
oparms.create_options = cifs_create_options(cifs_sb,
CREATE_NOT_FILE | OPEN_REPARSE_POINT);
open_rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL); if (open_rc == 0) { /* Successful open means that the target path is definitely a directory. */
*directory = true;
tcon->ses->server->ops->close(xid, tcon, &fid);
} elseif (open_rc == -ENOTDIR) { /* -ENOTDIR means that the target path is definitely a file. */
*directory = false;
} elseif (open_rc == -ENOENT) { /* -ENOENT means that the target path does not exist. */
cifs_dbg(FYI, "%s: symlink target path '%s' does not exist, " "creating '%s' as file symlink\n",
__func__, symname, full_path);
} else { /* Try to open as a file (NOT_DIR) */
oplock = 0;
oparms.create_options = cifs_create_options(cifs_sb,
CREATE_NOT_DIR | OPEN_REPARSE_POINT);
open_rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL); if (open_rc == 0) { /* Successful open means that the target path is definitely a file. */
*directory = false;
tcon->ses->server->ops->close(xid, tcon, &fid);
} elseif (open_rc == -EISDIR) { /* -EISDIR means that the target path is definitely a directory. */
*directory = true;
} else { /* * This code branch is called when we do not have a permission to * open the resolved_path or some other client/process denied * opening the resolved_path. * * TODO: Try to use ops->query_dir_first on the parent directory * of resolved_path, search for basename of resolved_path and * check if the ATTR_DIRECTORY is set in fi.Attributes. In some * case this could work also when opening of the path is denied.
*/
cifs_dbg(FYI, "%s: cannot determinate if the symlink target path '%s' " "is directory or not, creating '%s' as file symlink\n",
__func__, symname, full_path);
}
}
/* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ staticint parse_reparse_nfs(struct reparse_nfs_data_buffer *buf, struct cifs_sb_info *cifs_sb, struct cifs_open_info_data *data)
{ unsignedint len;
u64 type;
len = le16_to_cpu(buf->ReparseDataLength); if (len < sizeof(buf->InodeType)) {
cifs_dbg(VFS, "srv returned malformed nfs buffer\n"); return -EIO;
}
len -= sizeof(buf->InodeType);
switch ((type = le64_to_cpu(buf->InodeType))) { case NFS_SPECFILE_LNK: if (len == 0 || (len % 2)) {
cifs_dbg(VFS, "srv returned malformed nfs symlink buffer\n"); return -EIO;
} /* * Check that buffer does not contain UTF-16 null codepoint * because Linux cannot process symlink with null byte.
*/ if (UniStrnlen((wchar_t *)buf->DataBuffer, len/2) != len/2) {
cifs_dbg(VFS, "srv returned null byte in nfs symlink target location\n"); return -EIO;
}
data->symlink_target = cifs_strndup_from_utf16(buf->DataBuffer,
len, true,
cifs_sb->local_nls); if (!data->symlink_target) return -ENOMEM;
cifs_dbg(FYI, "%s: target path: %s\n",
__func__, data->symlink_target); break; case NFS_SPECFILE_CHR: case NFS_SPECFILE_BLK: /* DataBuffer for block and char devices contains two 32-bit numbers */ if (len != 8) {
cifs_dbg(VFS, "srv returned malformed nfs buffer for type: 0x%llx\n", type); return -EIO;
} break; case NFS_SPECFILE_FIFO: case NFS_SPECFILE_SOCK: /* DataBuffer for fifos and sockets is empty */ if (len != 0) {
cifs_dbg(VFS, "srv returned malformed nfs buffer for type: 0x%llx\n", type); return -EIO;
} break; default:
cifs_dbg(VFS, "%s: unhandled inode type: 0x%llx\n",
__func__, type); return -EOPNOTSUPP;
} return 0;
}
int smb2_parse_native_symlink(char **target, constchar *buf, unsignedint len, bool relative, constchar *full_path, struct cifs_sb_info *cifs_sb)
{ constchar *symroot = cifs_sb->ctx->symlinkroot; char sep = CIFS_DIR_SEP(cifs_sb); char *linux_target = NULL; char *smb_target = NULL; int symlinkroot_len; int abs_path_len; char *abs_path; int levels; int rc; int i;
/* Check that length it valid */ if (!len || (len % 2)) {
cifs_dbg(VFS, "srv returned malformed symlink buffer\n");
rc = -EIO; goto out;
}
/* * Check that buffer does not contain UTF-16 null codepoint * because Linux cannot process symlink with null byte.
*/ if (UniStrnlen((wchar_t *)buf, len/2) != len/2) {
cifs_dbg(VFS, "srv returned null byte in native symlink target location\n");
rc = -EIO; goto out;
}
if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS) &&
symroot && !relative) { /* * This is an absolute symlink from the server which does not * support POSIX paths, so the symlink is in NT-style path. * So convert it to absolute Linux symlink target path. Root of * the NT-style path for symlinks is specified in "symlinkroot" * mount option. * * Root of the DOS and Win32 paths is at NT path \??\ * It means that DOS/Win32 path C:\folder\file.txt is * NT path \??\C:\folder\file.txt * * NT systems have some well-known object symlinks in their NT * hierarchy, which is needed to take into account when resolving * other symlinks. Most commonly used symlink paths are: * \?? -> \GLOBAL?? * \DosDevices -> \?? * \GLOBAL??\GLOBALROOT -> \ * \GLOBAL??\Global -> \GLOBAL?? * \GLOBAL??\NUL -> \Device\Null * \GLOBAL??\UNC -> \Device\Mup * \GLOBAL??\PhysicalDrive0 -> \Device\Harddisk0\DR0 (for each harddisk) * \GLOBAL??\A: -> \Device\Floppy0 (if A: is the first floppy) * \GLOBAL??\C: -> \Device\HarddiskVolume1 (if C: is the first harddisk) * \GLOBAL??\D: -> \Device\CdRom0 (if D: is first cdrom) * \SystemRoot -> \Device\Harddisk0\Partition1\WINDOWS (or where is NT system installed) * \Volume{...} -> \Device\HarddiskVolume1 (where ... is system generated guid) * * In most common cases, absolute NT symlinks points to path on * DOS/Win32 drive letter, system-specific Volume or on UNC share. * Here are few examples of commonly used absolute NT symlinks * created by mklink.exe tool: * \??\C:\folder\file.txt * \??\\C:\folder\file.txt * \??\UNC\server\share\file.txt * \??\\UNC\server\share\file.txt * \??\Volume{b75e2c83-0000-0000-0000-602f00000000}\folder\file.txt * * It means that the most common path prefix \??\ is also NT path * symlink (to \GLOBAL??). It is less common that second path * separator is double backslash, but it is valid. * * Volume guid is randomly generated by the target system and so * only the target system knows the mapping between guid and the * hardisk number. Over SMB it is not possible to resolve this * mapping, therefore symlinks pointing to target location of * volume guids are totally unusable over SMB. * * For now parse only symlink paths available for DOS and Win32. * Those are paths with \??\ prefix or paths which points to \??\ * via other NT symlink (\DosDevices\, \GLOBAL??\, ...).
*/
abs_path = smb_target;
globalroot: if (strstarts(abs_path, "\\??\\"))
abs_path += sizeof("\\??\\")-1; elseif (strstarts(abs_path, "\\DosDevices\\"))
abs_path += sizeof("\\DosDevices\\")-1; elseif (strstarts(abs_path, "\\GLOBAL??\\"))
abs_path += sizeof("\\GLOBAL??\\")-1; else goto out_unhandled_target;
/* Sometimes path separator after \?? is double backslash */ if (abs_path[0] == '\\')
abs_path++;
while (strstarts(abs_path, "Global\\"))
abs_path += sizeof("Global\\")-1;
if (strstarts(abs_path, "GLOBALROOT\\")) { /* Label globalroot requires path with leading '\\', so do not trim '\\' */
abs_path += sizeof("GLOBALROOT")-1; goto globalroot;
}
/* For now parse only paths to drive letters */ if (((abs_path[0] >= 'A' && abs_path[0] <= 'Z') ||
(abs_path[0] >= 'a' && abs_path[0] <= 'z')) &&
abs_path[1] == ':' &&
(abs_path[2] == '\\' || abs_path[2] == '\0')) { /* Convert drive letter to lowercase and drop colon */ char drive_letter = abs_path[0]; if (drive_letter >= 'A' && drive_letter <= 'Z')
drive_letter += 'a'-'A';
abs_path++;
abs_path[0] = drive_letter;
} else { goto out_unhandled_target;
}
abs_path_len = strlen(abs_path)+1;
symlinkroot_len = strlen(symroot); if (symroot[symlinkroot_len - 1] == '/')
symlinkroot_len--;
linux_target = kmalloc(symlinkroot_len + 1 + abs_path_len, GFP_KERNEL); if (!linux_target) {
rc = -ENOMEM; goto out;
}
memcpy(linux_target, symroot, symlinkroot_len);
linux_target[symlinkroot_len] = '/';
memcpy(linux_target + symlinkroot_len + 1, abs_path, abs_path_len);
} elseif (smb_target[0] == sep && relative) { /* * This is a relative SMB symlink from the top of the share, * which is the top level directory of the Linux mount point. * Linux does not support such relative symlinks, so convert * it to the relative symlink from the current directory. * full_path is the SMB path to the symlink (from which is * extracted current directory) and smb_target is the SMB path * where symlink points, therefore full_path must always be on * the SMB share.
*/ int smb_target_len = strlen(smb_target)+1;
levels = 0; for (i = 1; full_path[i]; i++) { /* i=1 to skip leading sep */ if (full_path[i] == sep)
levels++;
}
linux_target = kmalloc(levels*3 + smb_target_len, GFP_KERNEL); if (!linux_target) {
rc = -ENOMEM; goto out;
} for (i = 0; i < levels; i++) {
linux_target[i*3 + 0] = '.';
linux_target[i*3 + 1] = '.';
linux_target[i*3 + 2] = sep;
}
memcpy(linux_target + levels*3, smb_target+1, smb_target_len); /* +1 to skip leading sep */
} else { /* * This is either an absolute symlink in POSIX-style format * or relative SMB symlink from the current directory. * These paths have same format as Linux symlinks, so no * conversion is needed.
*/
out_unhandled_target:
linux_target = smb_target;
smb_target = NULL;
}
if (sep == '\\')
convert_delimiter(linux_target, '/');
staticint parse_reparse_wsl_symlink(struct reparse_wsl_symlink_data_buffer *buf, struct cifs_sb_info *cifs_sb, struct cifs_open_info_data *data)
{ int len = le16_to_cpu(buf->ReparseDataLength); int data_offset = offsetof(typeof(*buf), Target) - offsetof(typeof(*buf), Version); int symname_utf8_len;
__le16 *symname_utf16; int symname_utf16_len;
if (len <= data_offset) {
cifs_dbg(VFS, "srv returned malformed wsl symlink buffer\n"); return -EIO;
}
/* MS-FSCC 2.1.2.7 defines layout of the Target field only for Version 2. */ if (le32_to_cpu(buf->Version) != 2) {
cifs_dbg(VFS, "srv returned unsupported wsl symlink version %u\n", le32_to_cpu(buf->Version)); return -EIO;
}
/* Target for Version 2 is in UTF-8 but without trailing null-term byte */
symname_utf8_len = len - data_offset; /* * Check that buffer does not contain null byte * because Linux cannot process symlink with null byte.
*/ if (strnlen(buf->Target, symname_utf8_len) != symname_utf8_len) {
cifs_dbg(VFS, "srv returned null byte in wsl symlink target location\n"); return -EIO;
}
symname_utf16 = kzalloc(symname_utf8_len * 2, GFP_KERNEL); if (!symname_utf16) return -ENOMEM;
symname_utf16_len = utf8s_to_utf16s(buf->Target, symname_utf8_len,
UTF16_LITTLE_ENDIAN,
(wchar_t *) symname_utf16, symname_utf8_len * 2); if (symname_utf16_len < 0) {
kfree(symname_utf16); return symname_utf16_len;
}
symname_utf16_len *= 2; /* utf8s_to_utf16s() returns number of u16 items, not byte length */
switch (tag) { case IO_REPARSE_TAG_LX_SYMLINK:
fattr->cf_mode |= S_IFLNK; break; case IO_REPARSE_TAG_LX_FIFO:
fattr->cf_mode |= S_IFIFO; break; case IO_REPARSE_TAG_AF_UNIX:
fattr->cf_mode |= S_IFSOCK; break; case IO_REPARSE_TAG_LX_CHR:
fattr->cf_mode |= S_IFCHR; break; case IO_REPARSE_TAG_LX_BLK:
fattr->cf_mode |= S_IFBLK; break;
}
if (!data->wsl.eas_len) goto out;
ea = (struct smb2_file_full_ea_info *)data->wsl.eas; do { constchar *name; void *v;
u8 nlen;
ea = (void *)((u8 *)ea + next);
next = le32_to_cpu(ea->next_entry_offset); if (!le16_to_cpu(ea->ea_value_length)) continue;
name = ea->ea_data;
nlen = ea->ea_name_length;
v = (void *)((u8 *)ea->ea_data + ea->ea_name_length + 1);
if (!strncmp(name, SMB2_WSL_XATTR_UID, nlen))
fattr->cf_uid = wsl_make_kuid(cifs_sb, v); elseif (!strncmp(name, SMB2_WSL_XATTR_GID, nlen))
fattr->cf_gid = wsl_make_kgid(cifs_sb, v); elseif (!strncmp(name, SMB2_WSL_XATTR_MODE, nlen)) { /* File type in reparse point tag and in xattr mode must match. */ if (S_DT(fattr->cf_mode) != S_DT(le32_to_cpu(*(__le32 *)v))) returnfalse;
fattr->cf_mode = (umode_t)le32_to_cpu(*(__le32 *)v);
} elseif (!strncmp(name, SMB2_WSL_XATTR_DEV, nlen)) {
fattr->cf_rdev = reparse_mkdev(v);
have_xattr_dev = true;
}
} while (next);
out:
/* Major and minor numbers for char and block devices are mandatory. */ if (!have_xattr_dev && (tag == IO_REPARSE_TAG_LX_CHR || tag == IO_REPARSE_TAG_LX_BLK)) returnfalse;
switch (tag) { case IO_REPARSE_TAG_LX_SYMLINK: case IO_REPARSE_TAG_LX_FIFO: case IO_REPARSE_TAG_AF_UNIX: case IO_REPARSE_TAG_LX_CHR: case IO_REPARSE_TAG_LX_BLK:
ok = wsl_to_fattr(data, cifs_sb, tag, fattr); if (!ok) returnfalse; break; case IO_REPARSE_TAG_NFS:
ok = posix_reparse_to_fattr(cifs_sb, fattr, data); if (!ok) returnfalse; break; case 0: /* SMB1 symlink */ case IO_REPARSE_TAG_SYMLINK:
fattr->cf_mode |= S_IFLNK; break; default: if (!(fattr->cf_cifsattrs & ATTR_DIRECTORY)) returnfalse; if (!IS_REPARSE_TAG_NAME_SURROGATE(tag) &&
tag != IO_REPARSE_TAG_INTERNAL) returnfalse; /* See cifs_create_junction_fattr() */
fattr->cf_mode = S_IFDIR | 0711; break;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.