/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/pathname.h>
#include <sys/extdirent.h>
#include <smbsrv/smb_kproto.h>
#include <smbsrv/smb_vops.h>
#include <smbsrv/smb_fsops.h>
/*
* CATIA support
*
* CATIA V4 is a UNIX product and uses characters in filenames that
* are considered invalid by Windows. CATIA V5 is available on both
* UNIX and Windows. Thus, as CATIA customers migrate from V4 to V5,
* some V4 files could become inaccessible to windows clients if the
* filename contains the characters that are considered illegal in
* Windows. In order to address this issue an optional character
* translation is applied to filenames at the smb_vop interface.
*
* Character Translation Table
* ----------------------------------
* Unix-char (v4) | Windows-char (v5)
* ----------------------------------
* * | 0x00a4 Currency Sign
* | | 0x00a6 Broken Bar
* " | 0x00a8 Diaeresis
* < | 0x00ab Left-Pointing Double Angle Quotation Mark
* > | 0x00bb Right-Pointing Double Angle Quotation Mark
* ? | 0x00bf Inverted Question mark
* : | 0x00f7 Division Sign
* / | 0x00f8 Latin Small Letter o with stroke
* \ | 0x00ff Latin Small Letter Y with Diaeresis
*
*
* Two lookup tables are used to perform the character translation:
*
* smb_catia_v5_lookup - provides the mapping between UNIX ASCII (v4)
* characters and equivalent or translated wide characters.
* It is indexed by the decimal value of the ASCII character (0-127).
*
* smb_catia_v4_lookup - provides the mapping between wide characters
* in the range from 0x00A4 to 0x00FF and their UNIX (v4) equivalent
* (in wide character format). It is indexed by the decimal value of
* the wide character (164-255) with an offset of -164.
* If this translation produces a filename containing a '/' create, mkdir
* or rename (to the '/' name) operations will not be permitted. It is
* not valid to create a filename with a '/' in it. However, if such a
* file already exists other operations (e.g, lookup, delete, rename)
* are permitted on it.
*/
/* number of characters mapped */
/* Windows Characters used in special character mapping */
#define SMB_CATIA_V4_LOOKUP_MAX \
typedef struct smb_catia_map
{
{
{'"', SMB_CATIA_WIN_DIAERESIS},
{'*', SMB_CATIA_WIN_CURRENCY},
{':', SMB_CATIA_WIN_DIVISION},
{'<', SMB_CATIA_WIN_LEFT_ANGLE},
{'>', SMB_CATIA_WIN_RIGHT_ANGLE},
{'?', SMB_CATIA_WIN_INVERTED_QUESTION},
{'\\', SMB_CATIA_WIN_LATIN_Y},
{'/', SMB_CATIA_WIN_LATIN_O},
{'|', SMB_CATIA_WIN_BROKEN_BAR}
};
static void smb_vop_catia_init();
extern sysid_t lm_alloc_sysidt();
0,
};
/*
* smb_vop_init
*
* This function is not multi-thread safe. The caller must make sure only one
* thread makes the call.
*/
int
smb_vop_init(void)
{
if (smb_vop_initialized)
return (0);
/*
* The caller_context will be used primarily for range locking.
* Since the CIFS server is mapping its locks to POSIX locks,
* only one pid is used for operations originating from the
* CIFS server (to represent CIFS in the VOP_FRLOCK routines).
*
* XXX: Should smb_ct be per-zone?
*/
return (ENOMEM);
return (0);
}
/*
* smb_vop_fini
*
* This function is not multi-thread safe. The caller must make sure only one
* thread makes the call.
*/
void
smb_vop_fini(void)
{
if (!smb_vop_initialized)
return;
}
/*
* The smb_ct will be used primarily for range locking.
* Since the CIFS server is mapping its locks to POSIX locks,
* only one pid is used for operations originating from the
* CIFS server (to represent CIFS in the VOP_FRLOCK routines).
*/
int
{
}
void
{
}
int
{
}
/*
* The smb_vop_* functions have minimal knowledge of CIFS semantics and
* serve as an interface to the VFS layer.
*
* Only smb_fsop_* layer functions should call smb_vop_* layer functions.
* (Higher-level CIFS service code should never skip the smb_fsop_* layer
* to call smb_vop_* layer functions directly.)
*/
/*
* XXX - Extended attributes support in the file system assumed.
* This is needed for full NT Streams functionality.
*/
int
{
int error;
return (error);
}
int
{
int error;
return (error);
}
/*
* smb_vop_getattr()
*
* smb_fsop_getattr()/smb_vop_getattr() should always be called from the CIFS
* service (instead of calling VOP_GETATTR directly) to retrieve attributes
* due to special processing needed for streams files.
*
* All attributes are retrieved.
*
* When vp denotes a named stream, then unnamed_vp should be passed in (denoting
* the corresponding unnamed stream).
* A named stream's attributes (as far as CIFS is concerned) are those of the
* unnamed stream (minus the size attribute, and the type), plus the size of
* the named stream, and a type value of VREG.
* Although the file system may store other attributes with the named stream,
* these should not be used by CIFS for any purpose.
*
* File systems without VFSFT_XVATTR do not support DOS attributes or create
* time (crtime). In this case the mtime is used as the crtime.
* Likewise if VOP_GETATTR doesn't return any system attributes the dosattr
* is 0 and the mtime is used as the crtime.
*/
int
{
int error;
if (unnamed_vp)
use_vp = unnamed_vp;
else
if (error != 0)
return (error);
ret_attr->sa_dosattr = 0;
(xoap->xoa_readonly)) {
}
(xoap->xoa_hidden)) {
}
(xoap->xoa_system)) {
}
(xoap->xoa_archive)) {
}
(xoap->xoa_reparse)) {
ret_attr->sa_dosattr |=
}
(xoap->xoa_offline)) {
}
(xoap->xoa_sparse)) {
ret_attr->sa_dosattr |=
}
} else {
}
} else {
/*
* Support for file systems without VFSFT_XVATTR
*/
if (error != 0)
return (error);
ret_attr->sa_dosattr = 0;
}
if (unnamed_vp) {
if (error != 0)
return (error);
}
}
return (error);
}
/*
* smb_vop_setattr()
*
* smb_fsop_setattr()/smb_vop_setattr() should always be used instead of
* VOP_SETATTR() when calling from the CIFS service, due to special processing
* for streams files.
*
* Streams have a size but otherwise do not have separate attributes from
* the (unnamed stream) file, i.e., the security and ownership of the file
* applies to the stream. In contrast, extended attribute files, which are
* used to implement streams, are independent objects with their own
* attributes.
*
* For compatibility with streams, we set the size on the extended attribute
* file and apply other attributes to the (unnamed stream) file. The one
* exception is that the UID and GID can be set on the stream by passing a
* NULL unnamed_vp, which allows callers to synchronize stream ownership
* with the (unnamed stream) file.
*/
int
{
int error = 0;
int at_size = 0;
attr->sa_dosattr &=
}
if (unnamed_vp) {
use_vp = unnamed_vp;
at_size = 1;
}
} else {
}
/*
* The caller should not be setting sa_vattr.va_mask,
* but rather sa_mask.
*/
} else {
}
return (error);
if (at_size) {
zone_kcred(), &smb_ct);
}
return (error);
}
int
{
int error;
return (error);
}
/*
* smb_vop_access
*
* This is a wrapper round VOP_ACCESS. VOP_ACCESS checks the given mode
* against file's ACL or Unix permissions. CIFS on the other hand needs to
* know if the requested operation can succeed for the given object, this
* requires more checks in case of DELETE bit since permissions on the parent
* directory are important as well. Based on Windows rules if parent's ACL
* grant FILE_DELETE_CHILD a file can be delete regardless of the file's
* permissions.
*/
int
{
int error = 0;
if (mode == 0)
return (0);
if (dir_vp) {
if (error == 0)
mode &= ~ACE_DELETE;
}
}
if (mode) {
}
return (error);
}
/*
* smb_vop_lookup
*
* dvp: directory vnode (in)
* name: name of file to be looked up (in)
* vpp: looked-up vnode (out)
* od_name: on-disk name of file (out).
* This parameter is optional. If a pointer is passed in, it
* must be allocated with MAXNAMELEN bytes
* rootvp: vnode of the tree root (in)
* This parameter is always passed in non-NULL except at the time
* of share set up.
* direntflags: dirent flags returned from VOP_LOOKUP
*/
int
char *name,
char *od_name,
int flags,
int *direntflags,
{
int error = 0;
int option_flags = 0;
if (*name == '\0')
return (EINVAL);
*direntflags = 0;
return (0);
}
/*
* Set dvp and check for races with forced unmount
* (see lookuppnvp())
*/
return (EIO);
}
}
}
if (flags & SMB_IGNORE_CASE)
if (error == 0) {
if (od_name) {
else
}
zone_kcred());
}
}
return (error);
}
int
{
int error;
int option_flags = 0;
if (flags & SMB_IGNORE_CASE)
} else {
}
return (EILSEQ);
}
return (error);
}
int
{
int error;
int option_flags = 0;
if (flags & SMB_IGNORE_CASE)
return (error);
}
/*
* smb_vop_link(target-dir-vp, source-file-vp, target-name)
*
* Create a link - same tree (identical TID) only.
*/
int
{
int option_flags = 0;
int rc;
if (flags & SMB_IGNORE_CASE)
return (EILSEQ);
}
return (rc);
}
return (rc);
}
/*
* smb_vop_rename()
*
* The rename is for files in the same tree (identical TID) only.
*/
int
{
int error;
int option_flags = 0;
if (flags & SMB_IGNORE_CASE)
return (EILSEQ);
}
&smb_ct, option_flags);
return (error);
}
&smb_ct, option_flags);
return (error);
}
int
{
int error;
int option_flags = 0;
if (flags & SMB_IGNORE_CASE)
} else {
}
return (EILSEQ);
}
return (error);
}
/*
* smb_vop_rmdir()
*
* Only simple rmdir supported, consistent with NT semantics
* (can only remove an empty directory).
*
* The third argument to VOP_RMDIR is the current directory of
* the process. It allows rmdir wants to EINVAL if one tries to
* remove ".". Since SMB servers do not know what their clients'
* current directories are, we fake it by supplying a vnode known
* to exist and illegal to remove (rootdir).
*/
int
{
int error;
int option_flags = 0;
if (flags & SMB_IGNORE_CASE)
return (error);
}
int
{
}
/*
* Some code in smb_node.c needs to know which DOS attributes
* we can actually store. Let's define a mask here of all the
* DOS attribute flags supported by the following function.
*/
const uint32_t
static void
{
/*
* Initialize xvattr, including bzero
*/
/*
* Copy caller-specified classic attributes to xvattr.
* First save xvattr's mask (set in xva_init()), which
* contains AT_XVATTR. This is |'d in later if needed.
*/
/*
* Do not set ctime (only the file system can do it)
*/
/*
* "|" in the original xva_mask, which contains
* AT_XVATTR
*/
/*
* smb_attr->sa_dosattr: If a given bit is not set,
* that indicates that the corresponding field needs
* to be updated with a "0" value. This is done
* implicitly as the xoap->xoa_* fields were bzero'd.
*/
}
/*
* "|" in the original xva_mask, which contains
* AT_XVATTR
*/
}
}
/*
* smb_vop_readdir()
*
* Collects an SMB_MINLEN_RDDIR_BUF "page" of directory entries.
* The directory entries are returned in an fs-independent format by the
* underlying file system. That is, the "page" of information returned is
* not literally stored on-disk in the format returned.
* If the file system supports extended directory entries (has features
* VFSFT_DIRENTFLAGS), set V_RDDIR_ENTFLAGS to cause the buffer to be
* filled with edirent_t structures, instead of dirent64_t structures.
* If the file system supports access based enumeration (abe), set
* V_RDDIR_ACCFILTER to filter directory entries based on user cred.
*/
int
{
int error = 0;
int flags = 0;
int rdirent_size;
return (ENOTDIR);
rdirent_size = sizeof (edirent_t);
} else {
rdirent_size = sizeof (dirent64_t);
}
if (*count < rdirent_size)
return (EINVAL);
if (rddir_flag & SMB_ABE)
if (error == 0)
return (error);
}
/*
* smb_sa_to_va_mask
*
* Set va_mask by running through the SMB_AT_* #define's and
* setting those bits that correspond to the SMB_AT_* bits
* set in sa_mask.
*/
void
{
int i;
if (smask & 1)
*(va_maskp) |= smb_attrmap[i];
smask >>= 1;
}
}
/*
* smb_vop_stream_lookup()
*
* The name returned in od_name is the on-disk name of the stream with the
* SMB_STREAM_PREFIX stripped off. od_name should be allocated to MAXNAMELEN
* by the caller.
*/
int
char *stream_name,
char *od_name,
int flags,
{
char *solaris_stream_name;
char *name;
return (error);
/*
* Prepend SMB_STREAM_PREFIX to stream name
*/
/*
* "name" will hold the on-disk name returned from smb_vop_lookup
* for the stream, including the SMB_STREAM_PREFIX.
*/
} else {
}
return (error);
}
int
{
char *solaris_stream_name;
int error;
return (error);
/*
* Prepend SMB_STREAM_PREFIX to stream name
*/
return (error);
}
int
{
char *solaris_stream_name;
int error;
if (error != 0)
return (error);
/*
* Prepend SMB_STREAM_PREFIX to stream name
*/
/* XXX might have to use kcred */
return (error);
}
int
{
int error;
return (error);
}
/*
* smb_vop_traverse_check()
*
* This function checks to see if the passed-in vnode has a file system
* mounted on it. If it does, the mount point is "traversed" and the
* vnode for the root of the file system is returned.
*/
int
{
int error;
if (vn_mountedvfs(*vpp) == 0)
return (0);
/*
* traverse() may return a different held vnode, even in the error case.
* If it returns a different vnode, it will have released the original.
*/
return (error);
}
int /*ARGSUSED*/
{
int error;
return (error);
}
/*
* smb_vop_acl_read
*
* Reads the ACL of the specified file into 'aclp'.
* acl_type is the type of ACL which the filesystem supports.
*
* Caller has to free the allocated memory for aclp by calling
* acl_free().
*/
int
{
int error;
switch (acl_type) {
case ACLENT_T:
break;
case ACE_T:
break;
default:
return (EINVAL);
}
return (error);
return (0);
}
/*
* smb_vop_acl_write
*
* Writes the given ACL in aclp for the specified file.
*/
int
{
int error;
int aclbsize;
if (error == 0) {
}
return (error);
}
/*
* smb_vop_acl_type
*
* Determines the ACL type for the given vnode.
* ACLENT_T is a Posix ACL and ACE_T is a ZFS ACL.
*/
{
int error;
zone_kcred(), NULL);
if (error != 0) {
/*
* If we got an error, then the filesystem
* likely does not understand the _PC_ACL_ENABLED
* pathconf. In this case, we fall back to trying
* POSIX-draft (aka UFS-style) ACLs.
*/
}
/*
* If the file system supports neither ACE nor
* ACLENT ACLs we will fall back to UFS-style ACLs
* like we did above if there was an error upon
* calling VOP_PATHCONF.
*
* ACE and ACLENT type ACLs are the only interfaces
* supported thus far. If any other bits are set on
* 'whichacl' upon return from VOP_PATHCONF, we will
* ignore them.
*/
}
if (whichacl == _ACL_ACLENT_ENABLED)
return (ACLENT_T);
return (ACE_T);
}
static const int zfs_perms[] = {
};
/*
* smb_vop_eaccess
*
* Returns the effective permission of the given credential for the
* specified object.
*
*/
void
{
int error, i;
int pnum;
*mode = 0;
if (flags == V_ACE_MASK) {
for (i = 0; i < pnum; i++) {
if (error == 0)
}
} else {
pnum = sizeof (unix_perms) / sizeof (int);
for (i = 0; i < pnum; i++) {
if (error == 0)
*mode |= unix_perms[i];
}
}
}
/*
* See comments for smb_fsop_shrlock()
*/
int
{
short new_access = 0;
short deny = 0;
int flag = 0;
int cmd;
/*
* share locking is not supported for non-regular
* objects in NBMAND mode.
*/
if (nbl_need_check(vp)) {
return (0);
} else {
}
if ((desired_access & FILE_DATA_ALL) == 0) {
/* metadata access only */
new_access |= F_MDACC;
} else {
new_access |= F_RDACC;
}
ACE_ADD_FILE)) {
new_access |= F_WRACC;
}
if (SMB_DENY_READ(share_access)) {
}
if (SMB_DENY_WRITE(share_access)) {
}
if (cmd == F_SHARE_NBMAND) {
if (desired_access & ACE_DELETE)
new_access |= F_RMACC;
if (SMB_DENY_DELETE(share_access)) {
}
}
}
}
int
{
/*
* share locking is not supported for non-regular
* objects in NBMAND mode.
*/
return (0);
/*
* For s_access and s_deny, we do not need to pass in the original
* values.
*/
}
int
{
}
static callb_cpr_t *
/* ARGSUSED */
{
return (0);
}
/*
* smb_vop_catia_init_v4_lookup
* Initialize mapping between wide characters in the range from
* 0x00A4 to 0x00FF and their UNIX (v4) equivalent (wide character).
* Indexed by the decimal value of the wide character (164-255)
* with an offset of -164.
*/
static void
{
for (i = 0; i < SMB_CATIA_V4_LOOKUP_MAX; i++)
for (i = 0; i < SMB_CATIA_NUM_MAPS; i++) {
}
}
/*
* smb_vop_catia_init_v5_lookup
* Initialize mapping between UNIX ASCII (v4) characters and equivalent
* or translated wide characters.
* Indexed by the decimal value of the ASCII character (0-127).
*/
static void
{
int i, idx;
for (i = 0; i < SMB_CATIA_V5_LOOKUP_MAX; i++)
smb_catia_v5_lookup[i] = (smb_wchar_t)i;
for (i = 0; i < SMB_CATIA_NUM_MAPS; i++) {
}
}
static void
{
}
/*
* smb_vop_catia_v5tov4
* (windows (v5) to unix (v4))
*
* Traverse each character in the given source filename and convert the
* multibyte that is equivalent to any special Windows character listed
* in the catia_maps table to the Unix ASCII character if any is
* encountered in the filename. The translated name is returned in buf.
*
* If an error occurs the conversion terminates and name is returned,
* otherwise buf is returned.
*/
char *
{
return (name);
while (*src) {
return (name);
if (wc < SMB_CATIA_V4_LOOKUP_LOW ||
p = src;
} else {
/* Lookup required. */
p = mbstring;
}
if (space_left < inc)
return (name);
space_left -= inc;
}
return (buf);
}
/*
* smb_vop_catia_v4tov5
* (unix (v4) to windows (v5))
*
* Traverse each character in the given filename 'srcbuf' and convert
* the special Unix character that is listed in the catia_maps table to
* the UTF-8 encoding of the corresponding Windows character if any is
* encountered in the filename.
*
* The translated name is returned in buf.
* If an error occurs the conversion terminates and the original name
* is returned in buf.
*/
void
{
return;
while (*src) {
if (smb_isascii(*src)) {
/* Lookup required */
if (space_left < numbytes)
break;
} else {
MTS_MB_CHAR_MAX)) < 0)
break;
if (space_left < numbytes)
break;
}
space_left -= numbytes;
}
if (*src)
}