summaryrefslogtreecommitdiff
path: root/usr/src/uts/common
diff options
context:
space:
mode:
authorGordon Ross <gwr@nexenta.com>2017-08-12 10:54:18 -0400
committerGordon Ross <gwr@nexenta.com>2019-03-14 10:38:30 -0400
commit8329232e00f1048795bae53acb230316243aadb5 (patch)
tree0d9a71c0dd22bd5288debd1dcc2cd3f0e7131d67 /usr/src/uts/common
parentebee07ff4f102cbd3179db7c5070283da35a79f3 (diff)
downloadillumos-joyent-8329232e00f1048795bae53acb230316243aadb5.tar.gz
9874 Add fksmbcl development tool
Reviewed by: Evan Layton <evan.layton@nexenta.com> Reviewed by: Matt Barden <matt.barden@nexenta.com> Approved by: Joshua M. Clulow <josh@sysmgr.org>
Diffstat (limited to 'usr/src/uts/common')
-rw-r--r--usr/src/uts/common/Makefile.files2
-rw-r--r--usr/src/uts/common/fs/fs_subr.h2
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/nsmb_sign_kcf.c180
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_dev.c125
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c10
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h39
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_sign.c126
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_signing.h73
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c3
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c6
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_tran.h5
-rw-r--r--usr/src/uts/common/fs/smbclnt/netsmb/smb_trantcp.c9
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_client.c4
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c3
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_smb.c12
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr2.c7
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vfsops.c112
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vnops.c88
-rw-r--r--usr/src/uts/common/fs/smbclnt/smbfs/smbfs_xattr.c2
-rw-r--r--usr/src/uts/common/netsmb/mchain.h20
-rw-r--r--usr/src/uts/common/sys/conf.h10
-rw-r--r--usr/src/uts/common/sys/debug.h4
-rw-r--r--usr/src/uts/common/sys/dirent.h2
-rw-r--r--usr/src/uts/common/sys/dnlc.h6
-rw-r--r--usr/src/uts/common/sys/file.h15
-rw-r--r--usr/src/uts/common/sys/model.h2
-rw-r--r--usr/src/uts/common/sys/modhash.h2
-rw-r--r--usr/src/uts/common/sys/poll.h2
-rw-r--r--usr/src/uts/common/sys/share.h2
-rw-r--r--usr/src/uts/common/sys/signal.h2
-rw-r--r--usr/src/uts/common/sys/stream.h6
-rw-r--r--usr/src/uts/common/sys/strsubr.h17
32 files changed, 724 insertions, 174 deletions
diff --git a/usr/src/uts/common/Makefile.files b/usr/src/uts/common/Makefile.files
index df5e864377..98a01e9993 100644
--- a/usr/src/uts/common/Makefile.files
+++ b/usr/src/uts/common/Makefile.files
@@ -1272,7 +1272,7 @@ VSCAN_OBJS += vscan_drv.o vscan_svc.o vscan_door.o
NSMB_OBJS += smb_conn.o smb_dev.o smb_iod.o smb_pass.o \
smb_rq.o smb_sign.o smb_smb.o smb_subrs.o \
smb_time.o smb_tran.o smb_trantcp.o smb_usr.o \
- subr_mchain.o
+ subr_mchain.o nsmb_sign_kcf.o
SMBFS_COMMON_OBJS += smbfs_ntacl.o
SMBFS_OBJS += smbfs_vfsops.o smbfs_vnops.o smbfs_node.o \
diff --git a/usr/src/uts/common/fs/fs_subr.h b/usr/src/uts/common/fs/fs_subr.h
index bbcdca71b2..27c9e3d830 100644
--- a/usr/src/uts/common/fs/fs_subr.h
+++ b/usr/src/uts/common/fs/fs_subr.h
@@ -48,7 +48,7 @@ extern "C" {
* Utilities shared among file system implementations.
*/
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
extern int fs_nosys();
extern int fs_inval();
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/nsmb_sign_kcf.c b/usr/src/uts/common/fs/smbclnt/netsmb/nsmb_sign_kcf.c
new file mode 100644
index 0000000000..2be033a8fc
--- /dev/null
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/nsmb_sign_kcf.c
@@ -0,0 +1,180 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * Helper functions for SMB signing using the
+ * Kernel Cryptographic Framework (KCF)
+ *
+ * There are two implementations of these functions:
+ * This one (for kernel) and another for user space:
+ * See: lib/smbclnt/libfknsmb/common/fksmb_sign_pkcs.c
+ */
+
+#include <sys/types.h>
+#include <sys/kmem.h>
+#include <sys/sunddi.h>
+#include <sys/crypto/api.h>
+#include <netsmb/smb_signing.h>
+
+/*
+ * SMB1 signing helpers:
+ * (getmech, init, update, final)
+ */
+
+int
+smb_md5_getmech(smb_sign_mech_t *mech)
+{
+ crypto_mech_type_t t;
+
+ t = crypto_mech2id(SUN_CKM_MD5);
+ if (t == CRYPTO_MECH_INVALID)
+ return (-1);
+ mech->cm_type = t;
+ return (0);
+}
+
+/*
+ * Start the KCF session, load the key
+ */
+int
+smb_md5_init(smb_sign_ctx_t *ctxp, smb_sign_mech_t *mech)
+{
+ int rv;
+
+ rv = crypto_digest_init(mech, ctxp, NULL);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
+
+/*
+ * Digest one segment
+ */
+int
+smb_md5_update(smb_sign_ctx_t ctx, void *buf, size_t len)
+{
+ crypto_data_t data;
+ int rv;
+
+ bzero(&data, sizeof (data));
+ data.cd_format = CRYPTO_DATA_RAW;
+ data.cd_length = len;
+ data.cd_raw.iov_base = buf;
+ data.cd_raw.iov_len = len;
+
+ rv = crypto_digest_update(ctx, &data, 0);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
+
+/*
+ * Get the final digest.
+ */
+int
+smb_md5_final(smb_sign_ctx_t ctx, uint8_t *digest16)
+{
+ crypto_data_t out;
+ int rv;
+
+ bzero(&out, sizeof (out));
+ out.cd_format = CRYPTO_DATA_RAW;
+ out.cd_length = MD5_DIGEST_LENGTH;
+ out.cd_raw.iov_len = MD5_DIGEST_LENGTH;
+ out.cd_raw.iov_base = (void *)digest16;
+
+ rv = crypto_digest_final(ctx, &out, 0);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
+
+/*
+ * SMB2 signing helpers:
+ * (getmech, init, update, final)
+ */
+
+int
+smb2_hmac_getmech(smb_sign_mech_t *mech)
+{
+ crypto_mech_type_t t;
+
+ t = crypto_mech2id(SUN_CKM_SHA256_HMAC);
+ if (t == CRYPTO_MECH_INVALID)
+ return (-1);
+ mech->cm_type = t;
+ return (0);
+}
+
+/*
+ * Start the KCF session, load the key
+ */
+int
+smb2_hmac_init(smb_sign_ctx_t *ctxp, smb_sign_mech_t *mech,
+ uint8_t *key, size_t key_len)
+{
+ crypto_key_t ckey;
+ int rv;
+
+ bzero(&ckey, sizeof (ckey));
+ ckey.ck_format = CRYPTO_KEY_RAW;
+ ckey.ck_data = key;
+ ckey.ck_length = key_len * 8; /* in bits */
+
+ rv = crypto_mac_init(mech, &ckey, NULL, ctxp, NULL);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
+
+/*
+ * Digest one segment
+ */
+int
+smb2_hmac_update(smb_sign_ctx_t ctx, uint8_t *in, size_t len)
+{
+ crypto_data_t data;
+ int rv;
+
+ bzero(&data, sizeof (data));
+ data.cd_format = CRYPTO_DATA_RAW;
+ data.cd_length = len;
+ data.cd_raw.iov_base = (void *)in;
+ data.cd_raw.iov_len = len;
+
+ rv = crypto_mac_update(ctx, &data, 0);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
+
+/*
+ * Note, the SMB2 signature is the first 16 bytes of the
+ * 32-byte SHA256 HMAC digest.
+ */
+int
+smb2_hmac_final(smb_sign_ctx_t ctx, uint8_t *digest16)
+{
+ uint8_t full_digest[SHA256_DIGEST_LENGTH];
+ crypto_data_t out;
+ int rv;
+
+ bzero(&out, sizeof (out));
+ out.cd_format = CRYPTO_DATA_RAW;
+ out.cd_length = SHA256_DIGEST_LENGTH;
+ out.cd_raw.iov_len = SHA256_DIGEST_LENGTH;
+ out.cd_raw.iov_base = (void *)full_digest;
+
+ rv = crypto_mac_final(ctx, &out, 0);
+ if (rv == CRYPTO_SUCCESS)
+ bcopy(full_digest, digest16, 16);
+
+ return (rv == CRYPTO_SUCCESS ? 0 : -1);
+}
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_dev.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_dev.c
index 489a1756ec..9f718a7bfc 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_dev.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_dev.c
@@ -31,9 +31,10 @@
*/
/*
- * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
@@ -73,6 +74,14 @@
#include <netsmb/smb_dev.h>
#include <netsmb/smb_pass.h>
+#ifndef _KERNEL
+#include <libfknsmb.h>
+
+#define _init(v) nsmb_drv_init(v)
+#define _fini(v) nsmb_drv_fini(v)
+
+#endif /* _KERNEL */
+
#define NSMB_MIN_MINOR 1
#define NSMB_MAX_MINOR L_MAXMIN32
@@ -82,14 +91,8 @@ const uint32_t nsmb_version = NSMB_VERSION;
static void *statep;
static major_t nsmb_major;
static minor_t last_minor = NSMB_MIN_MINOR;
-static dev_info_t *nsmb_dip;
static kmutex_t dev_lck;
-/* Zone support */
-zone_key_t nsmb_zone_key;
-extern void nsmb_zone_shutdown(zoneid_t zoneid, void *data);
-extern void nsmb_zone_destroy(zoneid_t zoneid, void *data);
-
/*
* cb_ops device operations.
*/
@@ -99,6 +102,15 @@ static int nsmb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
cred_t *credp, int *rvalp);
static int nsmb_close2(smb_dev_t *sdp, cred_t *cr);
+#ifdef _KERNEL
+
+static dev_info_t *nsmb_dip;
+
+/* Zone support */
+zone_key_t nsmb_zone_key;
+extern void nsmb_zone_shutdown(zoneid_t zoneid, void *data);
+extern void nsmb_zone_destroy(zoneid_t zoneid, void *data);
+
/* smbfs cb_ops */
static struct cb_ops nsmb_cbops = {
nsmb_open, /* open */
@@ -160,10 +172,14 @@ static struct modlinkage nsmb_modlinkage = {
NULL
};
+#endif /* _KERNEL */
+
int
_init(void)
{
+#ifdef _KERNEL
int error;
+#endif /* _KERNEL */
(void) ddi_soft_state_init(&statep, sizeof (smb_dev_t), 1);
@@ -182,6 +198,7 @@ _init(void)
/* Initialize crypto mechanisms. */
smb_crypto_mech_init();
+#ifdef _KERNEL
zone_key_create(&nsmb_zone_key, NULL, nsmb_zone_shutdown,
nsmb_zone_destroy);
@@ -200,6 +217,11 @@ _init(void)
return (error);
}
+#else /* _KERNEL */
+ streams_msg_init();
+ /* No attach, so need to set major. */
+ nsmb_major = 1;
+#endif /* _KERNEL */
return (0);
}
@@ -218,6 +240,7 @@ _fini(void)
if ((status = smb_pkey_idle()) != 0)
return (status);
+#ifdef _KERNEL
/*
* Remove the module. Do this before destroying things,
* to prevent new entrances while we're destorying.
@@ -227,6 +250,7 @@ _fini(void)
}
(void) zone_key_delete(nsmb_zone_key);
+#endif /* _KERNEL */
/* Time conversion stuff. */
smb_time_fini();
@@ -242,6 +266,8 @@ _fini(void)
return (status);
}
+#ifdef _KERNEL
+
int
_info(struct modinfo *modinfop)
{
@@ -315,6 +341,65 @@ nsmb_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
return (DDI_SUCCESS);
}
+#else /* _KERNEL */
+
+/*
+ * Wrappers for libfknsmb: ioctl, open, close, load
+ */
+
+/*ARGSUSED*/
+int
+nsmb_drv_ioctl(dev32_t dev32, int cmd, intptr_t arg, int flags)
+{
+ dev_t dev = expldev(dev32);
+ cred_t *cr = CRED();
+ int err;
+
+ err = nsmb_ioctl(dev, cmd, arg, flags, cr, NULL);
+ return (err);
+}
+
+/*ARGSUSED*/
+int
+nsmb_drv_open(dev32_t *dev32p, int flags, int otyp)
+{
+ dev_t dev = expldev(*dev32p);
+ int err;
+
+ err = nsmb_open(&dev, flags, otyp, CRED());
+ if (err == 0) {
+ /*
+ * We have NSMB_MAX_MINOR == L_MAXMIN32
+ * therefore cmpldev never fails.
+ */
+ VERIFY(cmpldev(dev32p, dev) != 0);
+ }
+ return (err);
+}
+
+/*ARGSUSED*/
+int
+nsmb_drv_close(dev32_t dev32, int flags, int otyp)
+{
+ dev_t dev = expldev(dev32);
+ int err;
+
+ err = nsmb_close(dev, flags, otyp, CRED());
+ return (err);
+}
+
+/*
+ * This function intentionally does nothing. It's used only to
+ * force libfknsmb to load at program start so one can set
+ * breakpoints etc. without debugger "force load" tricks.
+ */
+void
+nsmb_drv_load(void)
+{
+}
+
+#endif /* _KERNEL */
+
/*ARGSUSED*/
static int
nsmb_ioctl(dev_t dev, int cmd, intptr_t arg, int flags, /* model.h */
@@ -325,7 +410,7 @@ nsmb_ioctl(dev_t dev, int cmd, intptr_t arg, int flags, /* model.h */
sdp = ddi_get_soft_state(statep, getminor(dev));
if (sdp == NULL) {
- return (DDI_FAILURE);
+ return (EBADF);
}
if ((sdp->sd_flags & NSMBFL_OPEN) == 0) {
return (EBADF);
@@ -566,8 +651,10 @@ nsmb_close2(smb_dev_t *sdp, cred_t *cr)
int
smb_usr_dup_dev(smb_dev_t *sdp, intptr_t arg, int flags)
{
+#ifdef _KERNEL
file_t *fp = NULL;
vnode_t *vp;
+#endif /* _KERNEL */
smb_dev_t *from_sdp;
dev_t dev;
int32_t ufd;
@@ -582,16 +669,24 @@ smb_usr_dup_dev(smb_dev_t *sdp, intptr_t arg, int flags)
*/
if (ddi_copyin((void *) arg, &ufd, sizeof (ufd), flags))
return (EFAULT);
+#ifdef _KERNEL
if ((fp = getf(ufd)) == NULL)
return (EBADF);
/* rele fp below */
vp = fp->f_vnode;
dev = vp->v_rdev;
+#else /* _KERNEL */
+ /*
+ * No getf(ufd) -- ufd is really a dev32_t
+ */
+ dev = expldev((dev32_t)ufd);
+#endif /* _KERNEL */
if (dev == 0 || dev == NODEV ||
getmajor(dev) != nsmb_major) {
err = EINVAL;
goto out;
}
+
from_sdp = ddi_get_soft_state(statep, getminor(dev));
if (from_sdp == NULL) {
err = EINVAL;
@@ -609,8 +704,10 @@ smb_usr_dup_dev(smb_dev_t *sdp, intptr_t arg, int flags)
err = 0;
out:
+#ifdef _KERNEL
if (fp)
releasef(ufd);
+#endif /* _KERNEL */
return (err);
}
@@ -621,19 +718,27 @@ out:
int
smb_dev2share(int fd, struct smb_share **sspp)
{
+#ifdef _KERNEL
file_t *fp = NULL;
vnode_t *vp;
+#endif /* _KERNEL */
smb_dev_t *sdp;
smb_share_t *ssp;
dev_t dev;
int err;
+#ifdef _KERNEL
if ((fp = getf(fd)) == NULL)
return (EBADF);
/* rele fp below */
-
vp = fp->f_vnode;
dev = vp->v_rdev;
+#else /* _KERNEL */
+ /*
+ * No getf(ufd) -- fd is really a dev32_t
+ */
+ dev = expldev((dev32_t)fd);
+#endif /* _KERNEL */
if (dev == 0 || dev == NODEV ||
getmajor(dev) != nsmb_major) {
err = EINVAL;
@@ -660,7 +765,9 @@ smb_dev2share(int fd, struct smb_share **sspp)
err = 0;
out:
+#ifdef _KERNEL
if (fp)
releasef(fd);
+#endif /* _KERNEL */
return (err);
}
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
index db82fa0958..1e83a87806 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
@@ -35,6 +35,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#ifdef DEBUG
@@ -75,6 +77,10 @@
int smb_iod_send_echo(smb_vc_t *);
+#ifdef _FAKE_KERNEL
+extern void tsignal(kthread_t *, int);
+#endif
+
/*
* This is set/cleared when smbfs loads/unloads
* No locks should be necessary, because smbfs
@@ -752,7 +758,7 @@ smb_iod_waitrq(struct smb_rq *rqp)
rc = cv_wait_sig(&rqp->sr_cond, &rqp->sr_lock);
rqp->sr_flags &= ~SMBR_SENDWAIT;
if (rc == 0) {
- SMBIODEBUG("EINTR in sendwait, rqp=%p\n", rqp);
+ SMBIODEBUG("EINTR in sendwait, rq=%p\n", (void *)rqp);
error = EINTR;
goto out;
}
@@ -791,7 +797,7 @@ smb_iod_waitrq(struct smb_rq *rqp)
goto out;
}
if (tr < 0) {
-#ifdef DTRACE_PROBE
+#ifdef DTRACE_PROBE1
DTRACE_PROBE1(smb_iod_waitrq1,
(smb_rq_t *), rqp);
#endif
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h b/usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h
index 712acb6f3b..aef9e70e27 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h
@@ -1,16 +1,35 @@
-#pragma ident "%Z%%M% %I% %E% SMI"
+/*
+ * Copyright (c) 2001 - 2012 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ *
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
/*
* Code corresponding to smb_apple.h
- * XXX: Could merge this into smb_subr.h
- * as long as that doesn't break smbfs
*/
#ifndef _NETSMB_SMB_OSDEP_H_
#define _NETSMB_SMB_OSDEP_H_
#ifndef PRIVSYM
-#define PRIVSYM
+#define PRIVSYM
#endif
#ifndef min
@@ -65,8 +84,14 @@ typedef uint32_t u_int32_t;
typedef uint16_t u_int16_t;
typedef uint8_t u_int8_t;
-typedef const char * c_caddr_t;
-typedef uint64_t user_addr_t;
+typedef const char *c_caddr_t;
+typedef uint64_t user_addr_t;
+typedef ssize_t user_ssize_t;
+typedef size_t user_size_t;
+
+#ifdef _FAKE_KERNEL
+#define ddi_get_cred() CRED()
+#endif
/*
* Time related calls.
@@ -75,7 +100,7 @@ typedef uint64_t user_addr_t;
/* BEGIN CSTYLED */
#define timespeccmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
- ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
+ ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \
((tvp)->tv_sec cmp (uvp)->tv_sec))
/* END CSTYLED */
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_sign.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_sign.c
index cf06e75767..d0f3e493ef 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_sign.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_sign.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -37,8 +38,6 @@
#include <sys/md5.h>
#include <sys/des.h>
#include <sys/kmem.h>
-#include <sys/crypto/api.h>
-#include <sys/crypto/common.h>
#include <sys/cmn_err.h>
#include <sys/stream.h>
#include <sys/strsun.h>
@@ -50,6 +49,7 @@
#include <netsmb/smb_subr.h>
#include <netsmb/smb_dev.h>
#include <netsmb/smb_rq.h>
+#include <netsmb/smb_signing.h>
#ifdef DEBUG
/*
@@ -60,16 +60,16 @@ int nsmb_signing_fudge = 0;
#endif
/* Mechanism definitions */
-static crypto_mechanism_t crypto_mech_md5 = { CRYPTO_MECH_INVALID };
+static smb_sign_mech_t smb_mech_md5;
void
smb_crypto_mech_init(void)
{
- crypto_mech_md5.cm_type = crypto_mech2id(SUN_CKM_MD5);
+ if (smb_md5_getmech(&smb_mech_md5) != 0)
+ cmn_err(CE_NOTE, "nsmb can't get md5 mech");
}
-
#define SMBSIGLEN 8 /* SMB signature length */
#define SMBSIGOFF 14 /* SMB signature offset */
@@ -83,12 +83,12 @@ static int
smb_compute_MAC(struct smb_vc *vcp, mblk_t *mp,
uint32_t seqno, uchar_t *signature)
{
- crypto_context_t crypto_ctx;
- crypto_data_t key;
- crypto_data_t data;
- crypto_data_t digest;
- uchar_t mac[16];
- int status;
+ uchar_t digest[MD5_DIGEST_LENGTH];
+ smb_sign_ctx_t ctx = 0;
+ mblk_t *m = mp;
+ int size;
+ int rc;
+
/*
* This union is a little bit of trickery to:
* (1) get the sequence number int aligned, and
@@ -109,78 +109,66 @@ smb_compute_MAC(struct smb_vc *vcp, mblk_t *mp,
} s;
} smbhdr;
- ASSERT(mp != NULL);
- ASSERT(MBLKL(mp) >= SMB_HDRLEN);
- ASSERT(vcp->vc_mackey != NULL);
+ /* Later: check vcp->sign_mech == NULL */
+ if (vcp->vc_mackey == NULL)
+ return (-1);
+
+ if ((rc = smb_md5_init(&ctx, &smb_mech_md5)) != 0)
+ return (rc);
+
+ /* Digest the MAC Key */
+ rc = smb_md5_update(ctx, vcp->vc_mackey, vcp->vc_mackeylen);
+ if (rc != 0)
+ return (rc);
+
+ ASSERT(m != NULL);
+ ASSERT(MBLKL(m) >= SMB_HDRLEN);
/*
- * Make an aligned copy of the SMB header
- * and fill in the sequence number.
+ * Make an aligned copy of the SMB header,
+ * fill in the sequence number, and digest.
*/
- bcopy(mp->b_rptr, smbhdr.r.raw, SMB_HDRLEN);
+ size = SMB_HDRLEN;
+ if (MBLKL(m) < size)
+ (void) pullupmsg(m, size);
+ bcopy(m->b_rptr, smbhdr.r.raw, size);
smbhdr.s.sig[0] = htolel(seqno);
smbhdr.s.sig[1] = 0;
+ rc = smb_md5_update(ctx, &smbhdr.r.raw, size);
+ if (rc != 0)
+ return (rc);
+
/*
- * Compute the MAC: MD5(concat(Key, message))
+ * Digest the rest of the SMB header packet, starting at
+ * the data just after the SMB header.
*/
- if (crypto_mech_md5.cm_type == CRYPTO_MECH_INVALID) {
- SMBSDEBUG("crypto_mech_md5 invalid\n");
- return (CRYPTO_MECHANISM_INVALID);
- }
- status = crypto_digest_init(&crypto_mech_md5, &crypto_ctx, 0);
- if (status != CRYPTO_SUCCESS)
- return (status);
-
- /* Digest the MAC Key */
- key.cd_format = CRYPTO_DATA_RAW;
- key.cd_offset = 0;
- key.cd_length = vcp->vc_mackeylen;
- key.cd_miscdata = 0;
- key.cd_raw.iov_base = (char *)vcp->vc_mackey;
- key.cd_raw.iov_len = vcp->vc_mackeylen;
- status = crypto_digest_update(crypto_ctx, &key, 0);
- if (status != CRYPTO_SUCCESS)
- return (status);
-
- /* Digest the (copied) SMB header */
- data.cd_format = CRYPTO_DATA_RAW;
- data.cd_offset = 0;
- data.cd_length = SMB_HDRLEN;
- data.cd_miscdata = 0;
- data.cd_raw.iov_base = (char *)smbhdr.r.raw;
- data.cd_raw.iov_len = SMB_HDRLEN;
- status = crypto_digest_update(crypto_ctx, &data, 0);
- if (status != CRYPTO_SUCCESS)
- return (status);
+ size = MBLKL(m) - SMB_HDRLEN;
+ rc = smb_md5_update(ctx, m->b_rptr + SMB_HDRLEN, size);
+ if (rc != 0)
+ return (rc);
+ m = m->b_cont;
/* Digest rest of the SMB message. */
- data.cd_format = CRYPTO_DATA_MBLK;
- data.cd_offset = SMB_HDRLEN;
- data.cd_length = msgdsize(mp) - SMB_HDRLEN;
- data.cd_miscdata = 0;
- data.cd_mp = mp;
- status = crypto_digest_update(crypto_ctx, &data, 0);
- if (status != CRYPTO_SUCCESS)
- return (status);
-
- /* Final */
- digest.cd_format = CRYPTO_DATA_RAW;
- digest.cd_offset = 0;
- digest.cd_length = sizeof (mac);
- digest.cd_miscdata = 0;
- digest.cd_raw.iov_base = (char *)mac;
- digest.cd_raw.iov_len = sizeof (mac);
- status = crypto_digest_final(crypto_ctx, &digest, 0);
- if (status != CRYPTO_SUCCESS)
- return (status);
+ while (m != NULL) {
+ size = MBLKL(m);
+ if (size > 0) {
+ rc = smb_md5_update(ctx, m->b_rptr, size);
+ if (rc != 0)
+ return (rc);
+ }
+ m = m->b_cont;
+ }
+ rc = smb_md5_final(ctx, digest);
+ if (rc != 0)
+ return (rc);
/*
* Finally, store the signature.
* (first 8 bytes of the mac)
*/
if (signature)
- bcopy(mac, signature, SMBSIGLEN);
+ bcopy(digest, signature, SMBSIGLEN);
return (0);
}
@@ -221,7 +209,7 @@ smb_rq_sign(struct smb_rq *rqp)
* directly into the message at sigloc.
*/
status = smb_compute_MAC(vcp, mp, rqp->sr_seqno, sigloc);
- if (status != CRYPTO_SUCCESS) {
+ if (status != 0) {
SMBSDEBUG("Crypto error %d", status);
bzero(sigloc, SMBSIGLEN);
}
@@ -267,7 +255,7 @@ smb_rq_verify(struct smb_rq *rqp)
*/
rsn = rqp->sr_rseqno;
status = smb_compute_MAC(vcp, mp, rsn, sigbuf);
- if (status != CRYPTO_SUCCESS) {
+ if (status != 0) {
SMBSDEBUG("Crypto error %d", status);
/*
* If we can't compute a MAC, then there's
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_signing.h b/usr/src/uts/common/fs/smbclnt/netsmb/smb_signing.h
new file mode 100644
index 0000000000..e1799e3383
--- /dev/null
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_signing.h
@@ -0,0 +1,73 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+ */
+
+#ifndef _SMB_SIGNING_H_
+#define _SMB_SIGNING_H_
+
+/*
+ * SMB signing routines used in {smb,smb2}_sign.c
+ * Two implementations of these (kernel/user) in:
+ * uts/common/fs/smbclnt/netsmb/smb_sign_kcf.c
+ * lib/smbclnt/libfknsmb/common/fksmb_sign_pkcs.c
+ */
+
+#ifdef _KERNEL
+#include <sys/crypto/api.h>
+#else
+#include <security/cryptoki.h>
+#include <security/pkcs11.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MD5_DIGEST_LENGTH 16 /* MD5 digest length in bytes */
+#define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
+#define SMB2_SIG_SIZE 16
+
+#ifdef _KERNEL
+/* KCF variant */
+typedef crypto_mechanism_t smb_sign_mech_t;
+typedef crypto_context_t smb_sign_ctx_t;
+#else /* _KERNEL */
+/* PKCS11 variant */
+typedef CK_MECHANISM smb_sign_mech_t;
+typedef CK_SESSION_HANDLE smb_sign_ctx_t;
+#endif /* _KERNEL */
+
+/*
+ * SMB signing routines used in smb_signing.c
+ */
+
+int smb_md5_getmech(smb_sign_mech_t *);
+int smb_md5_init(smb_sign_ctx_t *, smb_sign_mech_t *);
+int smb_md5_update(smb_sign_ctx_t, void *, size_t);
+int smb_md5_final(smb_sign_ctx_t, uint8_t *);
+
+/*
+ * SMB2 signing routines used in smb2_signing.c
+ */
+
+int smb2_hmac_getmech(smb_sign_mech_t *);
+int smb2_hmac_init(smb_sign_ctx_t *, smb_sign_mech_t *, uint8_t *, size_t);
+int smb2_hmac_update(smb_sign_ctx_t, uint8_t *, size_t);
+int smb2_hmac_final(smb_sign_ctx_t, uint8_t *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _SMB_SIGNING_H_ */
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c
index 6016f5061a..efb7e9a03d 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_smb.c
@@ -33,8 +33,8 @@
*/
/*
- * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -49,6 +49,7 @@
#include <sys/uio.h>
#include <sys/random.h>
#include <sys/note.h>
+#include <sys/errno.h>
#include <sys/cmn_err.h>
#include <netsmb/smb_osdep.h>
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c
index e29a96631a..a581aa3533 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_subrs.c
@@ -34,6 +34,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/param.h>
@@ -97,10 +98,13 @@ smb_credinit(struct smb_cred *scred, cred_t *cr)
/* cr arg is optional */
if (cr == NULL)
cr = ddi_get_cred();
+#ifdef _KERNEL
if (is_system_labeled()) {
cr = crdup(cr);
(void) setpflags(NET_MAC_AWARE, 1, cr);
- } else {
+ } else
+#endif
+ {
crhold(cr);
}
scred->scr_cred = cr;
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_tran.h b/usr/src/uts/common/fs/smbclnt/netsmb/smb_tran.h
index f954056a79..fd8f91eb1c 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_tran.h
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_tran.h
@@ -35,6 +35,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _NETSMB_SMB_TRAN_H_
@@ -42,6 +44,9 @@
#include <sys/socket.h>
#include <sys/stream.h>
+#ifndef _KERNEL
+struct file;
+#endif
/*
* Known transports
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_trantcp.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_trantcp.c
index 4f101a4f5f..0b44cf879f 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_trantcp.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_trantcp.c
@@ -34,7 +34,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/param.h>
@@ -163,7 +164,7 @@ nb_getmsg_mlen(struct nbpcb *nbp, mblk_t **mpp, size_t mlen)
case T_DISCON_IND:
/* Peer disconnected. */
NBDEBUG("T_DISCON_IND: reason=%d",
- pptr->discon_ind.DISCON_reason);
+ (int)pptr->discon_ind.DISCON_reason);
goto discon;
case T_ORDREL_IND:
/* Peer disconnecting. */
@@ -176,11 +177,11 @@ nb_getmsg_mlen(struct nbpcb *nbp, mblk_t **mpp, size_t mlen)
goto discon;
default:
NBDEBUG("T_OK_ACK/prim=%d",
- pptr->ok_ack.CORRECT_prim);
+ (int)pptr->ok_ack.CORRECT_prim);
goto discon;
}
default:
- NBDEBUG("M_PROTO/type=%d", pptr->type);
+ NBDEBUG("M_PROTO/type=%d", (int)pptr->type);
goto discon;
}
break; /* M_PROTO, M_PCPROTO */
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_client.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_client.c
index 44319e6682..b9226e56d0 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_client.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_client.c
@@ -24,6 +24,8 @@
*
* Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
* All rights reserved.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/param.h>
@@ -60,6 +62,7 @@
#include <smbfs/smbfs_node.h>
#include <smbfs/smbfs_subr.h>
+#ifdef _KERNEL
#include <vm/hat.h>
#include <vm/as.h>
#include <vm/page.h>
@@ -67,6 +70,7 @@
#include <vm/seg.h>
#include <vm/seg_map.h>
#include <vm/seg_vn.h>
+#endif // _KERNEL
#define ATTRCACHE_VALID(vp) (gethrtime() < VTOSMB(vp)->r_attrtime)
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c
index 5bbbae860e..163a5a4504 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_node.c
@@ -35,11 +35,14 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/cred.h>
+#include <sys/errno.h>
#include <sys/time.h>
#include <sys/vfs.h>
#include <sys/vnode.h>
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_smb.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_smb.c
index db920f21b8..b8a91ef94a 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_smb.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_smb.c
@@ -33,13 +33,15 @@
*/
/*
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/param.h>
#include <sys/systm.h>
+#include <sys/inttypes.h>
#include <sys/time.h>
#include <sys/vnode.h>
#include <sys/sunddi.h>
@@ -623,9 +625,8 @@ smbfs_smb_seteof(struct smb_share *ssp, uint16_t fid, uint64_t newsize,
}
int
-smbfs_smb_setdisp(struct smbnode *np,
- uint16_t fid, uint8_t newdisp,
- struct smb_cred *scrp)
+smbfs_smb_setdisp(struct smbnode *np, uint16_t fid, uint8_t newdisp,
+ struct smb_cred *scrp)
{
struct smb_t2rq *t2p;
struct smb_share *ssp = np->n_mount->smi_share;
@@ -2376,6 +2377,9 @@ smbfs_smb_findclose(struct smbfs_fctx *ctx, struct smb_cred *scrp)
case ft_XA:
error = smbfs_xa_findclose(ctx);
break;
+ default:
+ error = ENOSYS;
+ break;
}
if (ctx->f_rname)
kmem_free(ctx->f_rname, ctx->f_rnamelen);
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr2.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr2.c
index 798c26a09b..deb8d8f182 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr2.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_subr2.c
@@ -27,6 +27,7 @@
*/
/*
* Copyright (c) 2017 by Delphix. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -39,7 +40,9 @@
#include <sys/systm.h>
#include <sys/time.h>
#include <sys/vnode.h>
+#include <sys/atomic.h>
#include <sys/bitmap.h>
+#include <sys/buf.h>
#include <sys/dnlc.h>
#include <sys/kmem.h>
#include <sys/sunddi.h>
@@ -1231,7 +1234,7 @@ smbfs_subrinit(void)
nsmbnode_max = (ulong_t)((kmem_maxavail() >> 2) /
sizeof (struct smbnode));
if (nsmbnode > nsmbnode_max || (nsmbnode == 0 && ncsize == 0)) {
- zcmn_err(GLOBAL_ZONEID, CE_NOTE,
+ cmn_err(CE_NOTE,
"setting nsmbnode to max value of %ld", nsmbnode_max);
nsmbnode = nsmbnode_max;
}
@@ -1249,7 +1252,7 @@ smbfs_subrinit(void)
* Assign unique major number for all smbfs mounts
*/
if ((smbfs_major = getudev()) == -1) {
- zcmn_err(GLOBAL_ZONEID, CE_WARN,
+ cmn_err(CE_WARN,
"smbfs: init: can't get unique device number");
smbfs_major = 0;
}
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vfsops.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vfsops.c
index 0122d52115..7dad8d2a70 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vfsops.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vfsops.c
@@ -34,9 +34,9 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright 2013, Joyent, Inc. All rights reserved.
* Copyright (c) 2016 by Delphix. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/systm.h>
@@ -76,6 +76,17 @@
#include <smbfs/smbfs_node.h>
#include <smbfs/smbfs_subr.h>
+#ifndef _KERNEL
+
+#include <libfksmbfs.h>
+
+#define STRUCT_DECL(s, a) struct s a
+#define STRUCT_FGET(handle, field) ((handle).field)
+#define _init(v) fksmbfs_init(v)
+#define _fini(v) fksmbfs_fini(v)
+
+#endif /* !_KERNEL */
+
/*
* Should smbfs mount enable "-o acl" by default? There are good
* arguments for both. The most common use case is individual users
@@ -98,7 +109,10 @@ int smbfs_tq_nthread = 1;
*/
int smbfsinit(int fstyp, char *name);
void smbfsfini();
+
+#ifdef _KERNEL
static int smbfs_mount_label_policy(vfs_t *, void *, int, cred_t *);
+#endif /* _KERNEL */
/*
* SMBFS Mount options table for MS_OPTIONSTR
@@ -123,7 +137,11 @@ static mntopt_t mntopts[] = {
{ MNTOPT_ACL, acl_cancel, NULL, 0, 0 },
{ MNTOPT_NOACL, noacl_cancel, NULL, 0, 0 },
{ MNTOPT_XATTR, xattr_cancel, NULL, MO_DEFAULT, 0 },
- { MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, 0 }
+ { MNTOPT_NOXATTR, noxattr_cancel, NULL, 0, 0 },
+#ifndef _KERNEL
+ /* See vfs_optionisset MNTOPT_NOAC below. */
+ { MNTOPT_NOAC, NULL, NULL, 0, 0 },
+#endif /* !_KERNEL */
};
static mntopts_t smbfs_mntopts = {
@@ -141,6 +159,7 @@ static vfsdef_t vfw = {
&smbfs_mntopts /* mount options table prototype */
};
+#ifdef _KERNEL
static struct modlfs modlfs = {
&mod_fsops,
"SMBFS filesystem",
@@ -150,6 +169,7 @@ static struct modlfs modlfs = {
static struct modlinkage modlinkage = {
MODREV_1, (void *)&modlfs, NULL
};
+#endif /* _KERNEL */
/*
* Mutex to protect the following variables:
@@ -222,7 +242,12 @@ _init(void)
return (error);
}
+#ifdef _KERNEL
error = mod_install((struct modlinkage *)&modlinkage);
+#else /* _KERNEL */
+ error = fake_installfs(&vfw);
+#endif /* _KERNEL */
+
return (error);
}
@@ -244,7 +269,11 @@ _fini(void)
if (smbfs_mountcount)
return (EBUSY);
+#ifdef _KERNEL
error = mod_remove(&modlinkage);
+#else /* _KERNEL */
+ error = fake_removefs(&vfw);
+#endif /* _KERNEL */
if (error)
return (error);
@@ -267,17 +296,19 @@ _fini(void)
/*
* Return information about the module
*/
+#ifdef _KERNEL
int
_info(struct modinfo *modinfop)
{
return (mod_info((struct modlinkage *)&modlinkage, modinfop));
}
+#endif /* _KERNEL */
/*
* Initialize the vfs structure
*/
-int smbfsfstyp;
+int smbfs_fstyp;
vfsops_t *smbfs_vfsops = NULL;
static const fs_operation_def_t smbfs_vfsops_template[] = {
@@ -292,6 +323,10 @@ static const fs_operation_def_t smbfs_vfsops_template[] = {
{ NULL, NULL }
};
+/*
+ * This is the VFS switch initialization routine, normally called
+ * via vfssw[x].vsw_init by vfsinit() or mod_install
+ */
int
smbfsinit(int fstyp, char *name)
{
@@ -299,7 +334,7 @@ smbfsinit(int fstyp, char *name)
error = vfs_setfsops(fstyp, smbfs_vfsops_template, &smbfs_vfsops);
if (error != 0) {
- zcmn_err(GLOBAL_ZONEID, CE_WARN,
+ cmn_err(CE_WARN,
"smbfsinit: bad vfs ops template");
return (error);
}
@@ -307,12 +342,12 @@ smbfsinit(int fstyp, char *name)
error = vn_make_ops(name, smbfs_vnodeops_template, &smbfs_vnodeops);
if (error != 0) {
(void) vfs_freevfsops_by_type(fstyp);
- zcmn_err(GLOBAL_ZONEID, CE_WARN,
+ cmn_err(CE_WARN,
"smbfsinit: bad vnode ops template");
return (error);
}
- smbfsfstyp = fstyp;
+ smbfs_fstyp = fstyp;
return (0);
}
@@ -321,7 +356,7 @@ void
smbfsfini()
{
if (smbfs_vfsops) {
- (void) vfs_freevfsops_by_type(smbfsfstyp);
+ (void) vfs_freevfsops_by_type(smbfs_fstyp);
smbfs_vfsops = NULL;
}
if (smbfs_vnodeops) {
@@ -336,8 +371,10 @@ smbfs_free_smi(smbmntinfo_t *smi)
if (smi == NULL)
return;
+#ifdef _KERNEL
if (smi->smi_zone_ref.zref_zone != NULL)
zone_rele_ref(&smi->smi_zone_ref, ZONE_REF_SMBFS);
+#endif /* _KERNEL */
if (smi->smi_share != NULL)
smb_share_rele(smi->smi_share);
@@ -364,16 +401,21 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
dev_t smbfs_dev;
int version;
int devfd;
- zone_t *zone = curproc->p_zone;
+ zone_t *zone = curzone;
+#ifdef _KERNEL
zone_t *mntzone = NULL;
+#else /* _KERNEL */
+ short minclsyspri = MINCLSYSPRI;
+#endif /* _KERNEL */
smb_share_t *ssp = NULL;
smb_cred_t scred;
int flags, sec;
-
STRUCT_DECL(smbfs_args, args); /* smbfs mount arguments */
+#ifdef _KERNEL
if ((error = secpolicy_fs_mount(cr, mvp, vfsp)) != 0)
return (error);
+#endif /* _KERNEL */
if (mvp->v_type != VDIR)
return (ENOTDIR);
@@ -384,11 +426,17 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
* uap->datalen might be different from sizeof (args)
* in a compatible situation.
*/
+#ifdef _KERNEL
STRUCT_INIT(args, get_udatamodel());
bzero(STRUCT_BUF(args), SIZEOF_STRUCT(smbfs_args, DATAMODEL_NATIVE));
if (copyin(data, STRUCT_BUF(args), MIN(uap->datalen,
SIZEOF_STRUCT(smbfs_args, DATAMODEL_NATIVE))))
return (EFAULT);
+#else /* _KERNEL */
+ bzero(&args, sizeof (args));
+ if (copyin(data, &args, MIN(uap->datalen, sizeof (args))))
+ return (EFAULT);
+#endif /* _KERNEL */
/*
* Check mount program version
@@ -439,6 +487,7 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
* See: ssp, smi, rtnp, mntzone
*/
+#ifdef _KERNEL
/*
* Determine the zone we're being mounted into.
*/
@@ -482,6 +531,7 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
vfs_setmntopt(vfsp, MNTOPT_RO, NULL, 0);
}
}
+#endif /* _KERNEL */
/* Prevent unload. */
atomic_inc_32(&smbfs_mountcount);
@@ -504,6 +554,7 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
smi->smi_share = ssp;
ssp = NULL;
+#ifdef _KERNEL
/*
* Convert the anonymous zone hold acquired via zone_hold() above
* into a zone reference.
@@ -512,15 +563,22 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
zone_hold_ref(mntzone, &smi->smi_zone_ref, ZONE_REF_SMBFS);
zone_rele(mntzone);
mntzone = NULL;
+#else /* _KERNEL */
+ smi->smi_zone_ref.zref_zone = curzone;
+#endif /* _KERNEL */
/*
* Initialize option defaults
*/
- smi->smi_flags = SMI_LLOCK;
smi->smi_acregmin = SEC2HR(SMBFS_ACREGMIN);
smi->smi_acregmax = SEC2HR(SMBFS_ACREGMAX);
smi->smi_acdirmin = SEC2HR(SMBFS_ACDIRMIN);
smi->smi_acdirmax = SEC2HR(SMBFS_ACDIRMAX);
+ smi->smi_flags = SMI_LLOCK;
+#ifndef _KERNEL
+ /* Always direct IO with fakekernel */
+ smi->smi_flags |= SMI_DIRECTIO;
+#endif /* _KERNEL */
/*
* All "generic" mount options have already been
@@ -541,10 +599,30 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
* starting with args.flags (SMBFS_MF_xxx)
*/
flags = STRUCT_FGET(args, flags);
- smi->smi_uid = STRUCT_FGET(args, uid);
- smi->smi_gid = STRUCT_FGET(args, gid);
smi->smi_fmode = STRUCT_FGET(args, file_mode) & 0777;
smi->smi_dmode = STRUCT_FGET(args, dir_mode) & 0777;
+#ifdef _KERNEL
+ smi->smi_uid = STRUCT_FGET(args, uid);
+ smi->smi_gid = STRUCT_FGET(args, gid);
+#else /* _KERNEL */
+ /*
+ * Need uid/gid to match our fake cred we'll fail in
+ * smbfs_access_rwx later.
+ */
+ smi->smi_uid = crgetuid(cr);
+ smi->smi_gid = crgetgid(cr);
+
+ /*
+ * Our user-level do_mount() passes the mount options sting
+ * as-is, where the real mount program would convert some
+ * of those options to bits set in smbfs_args.flags.
+ * To avoid replicating all that conversion code, this
+ * uses the generic vfs option support to handle those
+ * option flag bits we need, i.e.: "noac"
+ */
+ if (vfs_optionisset(vfsp, MNTOPT_NOAC, NULL))
+ flags |= SMBFS_MF_NOAC;
+#endif /* _KERNEL */
/*
* Hande the SMBFS_MF_xxx flags.
@@ -615,9 +693,9 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
mutex_exit(&smbfs_minor_lock);
vfsp->vfs_dev = smbfs_dev;
- vfs_make_fsid(&vfsp->vfs_fsid, smbfs_dev, smbfsfstyp);
+ vfs_make_fsid(&vfsp->vfs_fsid, smbfs_dev, smbfs_fstyp);
vfsp->vfs_data = (caddr_t)smi;
- vfsp->vfs_fstype = smbfsfstyp;
+ vfsp->vfs_fstype = smbfs_fstyp;
vfsp->vfs_bsize = MAXBSIZE;
vfsp->vfs_bcount = 0;
@@ -657,6 +735,7 @@ smbfs_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
*/
return (0);
+#ifdef _KERNEL
errout:
vfsp->vfs_data = NULL;
if (smi != NULL)
@@ -669,6 +748,7 @@ errout:
smb_share_rele(ssp);
return (error);
+#endif /* _KERNEL */
}
/*
@@ -682,8 +762,10 @@ smbfs_unmount(vfs_t *vfsp, int flag, cred_t *cr)
smi = VFTOSMI(vfsp);
+#ifdef _KERNEL
if (secpolicy_fs_unmount(cr, vfsp) != 0)
return (EPERM);
+#endif /* _KERNEL */
if ((flag & MS_FORCE) == 0) {
smbfs_rflush(vfsp, cr);
@@ -976,6 +1058,7 @@ smbfs_freevfs(vfs_t *vfsp)
atomic_dec_32(&smbfs_mountcount);
}
+#ifdef _KERNEL
/*
* smbfs_mount_label_policy:
* Determine whether the mount is allowed according to MAC check,
@@ -1066,3 +1149,4 @@ out:
label_rele(zlabel);
return (retv);
}
+#endif /* _KERNEL */
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vnops.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vnops.c
index 23c9f8f15d..707238e5ad 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vnops.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_vnops.c
@@ -34,6 +34,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -60,8 +61,9 @@
#include <sys/sdt.h>
#include <sys/taskq_impl.h>
#include <sys/zone.h>
-#include <sys/vmsystm.h>
+#ifdef _KERNEL
+#include <sys/vmsystm.h> // for desfree
#include <vm/hat.h>
#include <vm/as.h>
#include <vm/page.h>
@@ -70,6 +72,7 @@
#include <vm/seg_map.h>
#include <vm/seg_kpm.h>
#include <vm/seg_vn.h>
+#endif // _KERNEL
#include <netsmb/smb_osdep.h>
#include <netsmb/smb.h>
@@ -83,6 +86,10 @@
#include <sys/fs/smbfs_ioctl.h>
#include <fs/fs_subr.h>
+#ifndef MAXOFF32_T
+#define MAXOFF32_T 0x7fffffff
+#endif
+
/*
* We assign directory offsets like the NFS client, where the
* offset increments by _one_ after each directory entry.
@@ -140,15 +147,11 @@ static int smbfs_readvdir(vnode_t *vp, uio_t *uio, cred_t *cr, int *eofp,
static void smbfs_rele_fid(smbnode_t *, struct smb_cred *);
static uint32_t xvattr_to_dosattr(smbnode_t *, struct vattr *);
-static int smbfs_rdwrlbn(vnode_t *, page_t *, u_offset_t, size_t, int,
- cred_t *);
-static int smbfs_bio(struct buf *, int, cred_t *);
-static int smbfs_writenp(smbnode_t *np, caddr_t base, int tcount,
- struct uio *uiop, int pgcreated);
-
static int smbfs_fsync(vnode_t *, int, cred_t *, caller_context_t *);
+
static int smbfs_putpage(vnode_t *, offset_t, size_t, int, cred_t *,
caller_context_t *);
+#ifdef _KERNEL
static int smbfs_getapage(vnode_t *, u_offset_t, size_t, uint_t *,
page_t *[], size_t, struct seg *, caddr_t,
enum seg_rw, cred_t *);
@@ -156,6 +159,13 @@ static int smbfs_putapage(vnode_t *, page_t *, u_offset_t *, size_t *,
int, cred_t *);
static void smbfs_delmap_async(void *);
+static int smbfs_rdwrlbn(vnode_t *, page_t *, u_offset_t, size_t, int,
+ cred_t *);
+static int smbfs_bio(struct buf *, int, cred_t *);
+static int smbfs_writenp(smbnode_t *np, caddr_t base, int tcount,
+ struct uio *uiop, int pgcreated);
+#endif // _KERNEL
+
/*
* Error flags used to pass information about certain special errors
* which need to be handled specially.
@@ -562,12 +572,6 @@ smbfs_read(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
ssize_t past_eof;
int error;
- caddr_t base;
- u_offset_t off;
- size_t n;
- int on;
- uint_t flags;
-
np = VTOSMB(vp);
smi = VTOSMI(vp);
ssp = smi->smi_share;
@@ -648,8 +652,15 @@ smbfs_read(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
return (error);
}
+#ifdef _KERNEL
/* (else) Do I/O through segmap. */
do {
+ caddr_t base;
+ u_offset_t off;
+ size_t n;
+ int on;
+ uint_t flags;
+
off = uiop->uio_loffset & MAXBMASK; /* mapping offset */
on = uiop->uio_loffset & MAXBOFFSET; /* Relative offset */
n = MIN(MAXBSIZE - on, uiop->uio_resid);
@@ -698,6 +709,9 @@ smbfs_read(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
}
}
} while (!error && uiop->uio_resid > 0);
+#else // _KERNEL
+ error = ENOSYS;
+#endif // _KERNEL
/* undo adjustment of resid */
uiop->uio_resid += past_eof;
@@ -719,14 +733,11 @@ smbfs_write(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
offset_t endoff, limit;
ssize_t past_limit;
int error, timo;
- caddr_t base;
- u_offset_t off;
- size_t n;
- int on;
- uint_t flags;
u_offset_t last_off;
size_t last_resid;
+#ifdef _KERNEL
uint_t bsize;
+#endif
np = VTOSMB(vp);
smi = VTOSMI(vp);
@@ -789,12 +800,14 @@ smbfs_write(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
limit = MAXOFFSET_T;
if (uiop->uio_loffset >= limit) {
+#ifdef _KERNEL
proc_t *p = ttoproc(curthread);
mutex_enter(&p->p_lock);
(void) rctl_action(rctlproc_legacy[RLIMIT_FSIZE],
p->p_rctls, p, RCA_UNSAFE_SIGINFO);
mutex_exit(&p->p_lock);
+#endif // _KERNEL
return (EFBIG);
}
if (endoff > limit) {
@@ -813,7 +826,9 @@ smbfs_write(vnode_t *vp, struct uio *uiop, int ioflag, cred_t *cr,
np->r_mapcnt == 0 && np->r_inmap == 0 &&
!vn_has_cached_data(vp))) {
+#ifdef _KERNEL
smbfs_fwrite:
+#endif // _KERNEL
if (np->r_flags & RSTALE) {
last_resid = uiop->uio_resid;
last_off = uiop->uio_loffset;
@@ -865,10 +880,17 @@ smbfs_fwrite:
return (error);
}
+#ifdef _KERNEL
/* (else) Do I/O through segmap. */
bsize = vp->v_vfsp->vfs_bsize;
do {
+ caddr_t base;
+ u_offset_t off;
+ size_t n;
+ int on;
+ uint_t flags;
+
off = uiop->uio_loffset & MAXBMASK; /* mapping offset */
on = uiop->uio_loffset & MAXBOFFSET; /* Relative offset */
n = MIN(MAXBSIZE - on, uiop->uio_resid);
@@ -993,6 +1015,11 @@ smbfs_fwrite:
goto smbfs_fwrite;
}
} while (!error && uiop->uio_resid > 0);
+#else // _KERNEL
+ last_resid = uiop->uio_resid;
+ last_off = uiop->uio_loffset;
+ error = ENOSYS;
+#endif // _KERNEL
bottom:
/* undo adjustment of resid */
@@ -1006,6 +1033,8 @@ bottom:
return (error);
}
+#ifdef _KERNEL
+
/*
* Like nfs_client.c: writerp()
*
@@ -1361,6 +1390,7 @@ smbfs_bio(struct buf *bp, int sync, cred_t *cr)
return (error);
}
+#endif // _KERNEL
/*
* Here NFS has: nfs3write, nfs3read
@@ -3692,6 +3722,8 @@ smbfs_seek(vnode_t *vp, offset_t ooff, offset_t *noffp, caller_context_t *ct)
/* mmap support ******************************************************** */
+#ifdef _KERNEL
+
#ifdef DEBUG
static int smbfs_lostpage = 0; /* number of times we lost original page */
#endif
@@ -4011,6 +4043,8 @@ again:
* No read-ahead in smbfs yet.
*/
+#endif // _KERNEL
+
/*
* Flags are composed of {B_INVAL, B_FREE, B_DONTNEED, B_FORCE}
* If len == 0, do from off to EOF.
@@ -4026,6 +4060,7 @@ static int
smbfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
caller_context_t *ct)
{
+#ifdef _KERNEL
smbnode_t *np;
smbmntinfo_t *smi;
page_t *pp;
@@ -4157,8 +4192,14 @@ smbfs_putpage(vnode_t *vp, offset_t off, size_t len, int flags, cred_t *cr,
}
return (error);
+
+#else // _KERNEL
+ return (ENOSYS);
+#endif // _KERNEL
}
+#ifdef _KERNEL
+
/*
* Write out a single page, possibly klustering adjacent dirty pages.
*
@@ -4331,6 +4372,9 @@ smbfs_putapage(vnode_t *vp, page_t *pp, u_offset_t *offp, size_t *lenp,
return (error);
}
+#endif // _KERNEL
+
+
/*
* NFS has this in nfs_client.c (shared by v2,v3,...)
* We have it here so smbfs_putapage can be file scope.
@@ -4355,8 +4399,10 @@ smbfs_invalidate_pages(vnode_t *vp, u_offset_t off, cred_t *cr)
/* Here NFSv3 has np->r_truncaddr = off; */
mutex_exit(&np->r_statelock);
+#ifdef _KERNEL
(void) pvn_vplist_dirty(vp, off, smbfs_putapage,
B_INVAL | B_TRUNC, cr);
+#endif // _KERNEL
mutex_enter(&np->r_statelock);
np->r_flags &= ~RTRUNCATE;
@@ -4364,6 +4410,8 @@ smbfs_invalidate_pages(vnode_t *vp, u_offset_t off, cred_t *cr)
mutex_exit(&np->r_statelock);
}
+#ifdef _KERNEL
+
/* Like nfs3_map */
/* ARGSUSED */
@@ -4659,6 +4707,8 @@ smbfs_delmap_async(void *varg)
/* No smbfs_pageio() or smbfs_dispose() ops. */
+#endif // _KERNEL
+
/* misc. ******************************************************** */
@@ -4961,11 +5011,13 @@ const fs_operation_def_t smbfs_vnodeops_template[] = {
VOPNAME_FRLOCK, { .vop_frlock = smbfs_frlock },
VOPNAME_SPACE, { .vop_space = smbfs_space },
VOPNAME_REALVP, { .vop_realvp = smbfs_realvp },
+#ifdef _KERNEL
VOPNAME_GETPAGE, { .vop_getpage = smbfs_getpage },
VOPNAME_PUTPAGE, { .vop_putpage = smbfs_putpage },
VOPNAME_MAP, { .vop_map = smbfs_map },
VOPNAME_ADDMAP, { .vop_addmap = smbfs_addmap },
VOPNAME_DELMAP, { .vop_delmap = smbfs_delmap },
+#endif // _KERNEL
VOPNAME_PATHCONF, { .vop_pathconf = smbfs_pathconf },
VOPNAME_SETSECATTR, { .vop_setsecattr = smbfs_setsecattr },
VOPNAME_GETSECATTR, { .vop_getsecattr = smbfs_getsecattr },
diff --git a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_xattr.c b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_xattr.c
index 75241cc1f0..5a36306283 100644
--- a/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_xattr.c
+++ b/usr/src/uts/common/fs/smbclnt/smbfs/smbfs_xattr.c
@@ -21,6 +21,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -29,6 +30,7 @@
*/
#include <sys/systm.h>
+#include <sys/inttypes.h>
#include <sys/cred.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
diff --git a/usr/src/uts/common/netsmb/mchain.h b/usr/src/uts/common/netsmb/mchain.h
index c5c8512fd7..4f236d6b52 100644
--- a/usr/src/uts/common/netsmb/mchain.h
+++ b/usr/src/uts/common/netsmb/mchain.h
@@ -35,6 +35,8 @@
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
#ifndef _MCHAIN_H_
@@ -70,10 +72,10 @@
#else /* (BYTE_ORDER == LITTLE_ENDIAN) */
/* little-endian values on big-endian (swap) */
-#define letohs(x) BSWAP_16(x)
-#define htoles(x) BSWAP_16(x)
-#define letohl(x) BSWAP_32(x)
-#define htolel(x) BSWAP_32(x)
+#define letohs(x) BSWAP_16(x)
+#define htoles(x) BSWAP_16(x)
+#define letohl(x) BSWAP_32(x)
+#define htolel(x) BSWAP_32(x)
#define letohq(x) BSWAP_64(x)
#define htoleq(x) BSWAP_64(x)
@@ -93,7 +95,7 @@
* wrappers for streams functions. See: subr_mchain.c
*/
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* BSD-style mbuf "shim" for kernel code. Note, this
@@ -112,9 +114,9 @@ typedef mblk_t mbuf_t;
* m_data ... (m_data + m_len)
* In Unix STREAMS, the mblk payload is:
* b_rptr ... b_wptr
- *
+ *
* Here are some handy conversion notes:
- *
+ *
* struct mbuf struct mblk
* m->m_next m->b_cont
* m->m_nextpkt m->b_next
@@ -124,7 +126,7 @@ typedef mblk_t mbuf_t;
* &m->m_dat[MLEN] m->b_datap->db_lim
* M_TRAILINGSPACE(m) MBLKTAIL(m)
* m_freem(m) freemsg(m)
- *
+ *
* Note that mbufs chains also have a special "packet" header,
* which has the length of the whole message. In STREAMS one
* typically just calls msgdsize(m) to get that.
@@ -177,7 +179,7 @@ void m_freem(mbuf_t *);
#define MB_MZERO 3 /* bzero(), mb_put_mem only */
#define MB_MCUSTOM 4 /* use an user defined function */
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
struct mbchain {
mblk_t *mb_top;
diff --git a/usr/src/uts/common/sys/conf.h b/usr/src/uts/common/sys/conf.h
index 4bf3d5c7e3..148104f83a 100644
--- a/usr/src/uts/common/sys/conf.h
+++ b/usr/src/uts/common/sys/conf.h
@@ -41,11 +41,11 @@
extern "C" {
#endif
-#define FMNAMESZ 8 /* used by struct fmodsw */
+#define FMNAMESZ 8 /* used by struct fmodsw */
#if !defined(_XPG4_2) || defined(__EXTENSIONS__)
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* XXX Given that drivers need to include this file,
@@ -53,10 +53,14 @@ extern "C" {
* it legitimizes (aka provides prototypes for)
* all sorts of functions that aren't in the DKI/SunDDI
*/
+#include <sys/types.h>
#include <sys/systm.h>
+
+#endif /* _KERNEL || _FAKE_KERNEL */
+#ifdef _KERNEL
+
#include <sys/devops.h>
#include <sys/model.h>
-#include <sys/types.h>
#include <sys/buf.h>
#include <sys/cred.h>
#include <sys/uio.h>
diff --git a/usr/src/uts/common/sys/debug.h b/usr/src/uts/common/sys/debug.h
index e4a959205a..9c91905af2 100644
--- a/usr/src/uts/common/sys/debug.h
+++ b/usr/src/uts/common/sys/debug.h
@@ -138,12 +138,12 @@ _NOTE(CONSTCOND) } while (0)
#define __CTASSERT(x, y) \
typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1] __unused
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
extern void abort_sequence_enter(char *);
extern void debug_enter(char *);
-#endif /* _KERNEL */
+#endif /* _KERNEL || _FAKE_KERNEL */
#if defined(DEBUG) && !defined(__sun)
/* CSTYLED */
diff --git a/usr/src/uts/common/sys/dirent.h b/usr/src/uts/common/sys/dirent.h
index 114fcf6e30..c079fb983a 100644
--- a/usr/src/uts/common/sys/dirent.h
+++ b/usr/src/uts/common/sys/dirent.h
@@ -76,7 +76,7 @@ typedef struct dirent64 {
#endif /* _LARGEFILE64_SOURCE */
#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#define DIRENT64_RECLEN(namelen) \
((offsetof(dirent64_t, d_name[0]) + 1 + (namelen) + 7) & ~ 7)
#define DIRENT64_NAMELEN(reclen) \
diff --git a/usr/src/uts/common/sys/dnlc.h b/usr/src/uts/common/sys/dnlc.h
index bf947659d0..4a5c20d6d0 100644
--- a/usr/src/uts/common/sys/dnlc.h
+++ b/usr/src/uts/common/sys/dnlc.h
@@ -76,7 +76,7 @@ extern "C" {
* storing full names, then we are ok. The space savings are worth it.
*/
typedef struct ncache {
- struct ncache *hash_next; /* hash chain, MUST BE FIRST */
+ struct ncache *hash_next; /* hash chain, MUST BE FIRST */
struct ncache *hash_prev;
struct vnode *vp; /* vnode the name refers to */
struct vnode *dp; /* vnode of parent of name */
@@ -169,7 +169,7 @@ struct nc_stats {
(namlen) = Xcp - (name); \
}
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#include <sys/vfs.h>
#include <sys/vnode.h>
@@ -205,7 +205,7 @@ void dnlc_reduce_cache(void *);
*/
typedef struct dcfree {
uint64_t df_handle; /* fs supplied handle */
- struct dcfree *df_next; /* link to next free entry in bucket */
+ struct dcfree *df_next; /* link to next free entry in bucket */
uint_t df_len; /* length of free entry */
} dcfree_t;
diff --git a/usr/src/uts/common/sys/file.h b/usr/src/uts/common/sys/file.h
index c2243ef17b..ec0741fe08 100644
--- a/usr/src/uts/common/sys/file.h
+++ b/usr/src/uts/common/sys/file.h
@@ -119,7 +119,7 @@ typedef struct fpollinfo {
#define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* This is a flag that is set on f_flag2, but is never user-visible
@@ -188,7 +188,7 @@ typedef struct fpollinfo {
extern int flock(int, int);
#endif
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* Routines dealing with user per-open file flags and
@@ -197,14 +197,15 @@ extern int flock(int, int);
struct proc; /* forward reference for function prototype */
struct vnodeops;
struct vattr;
+struct uf_info;
extern file_t *getf(int);
extern void releasef(int);
-extern void areleasef(int, uf_info_t *);
+extern void areleasef(int, struct uf_info *);
#ifndef _BOOT
-extern void closeall(uf_info_t *);
+extern void closeall(struct uf_info *);
#endif
-extern void flist_fork(uf_info_t *, uf_info_t *);
+extern void flist_fork(struct uf_info *, struct uf_info *);
extern int closef(file_t *);
extern int closeandsetf(int, file_t *);
extern int ufalloc_file(int, file_t *);
@@ -221,8 +222,8 @@ extern void f_setfd(int, char);
extern int f_getfl(int, int *);
extern int f_badfd(int, int *, int);
extern int fassign(struct vnode **, int, int *);
-extern void fcnt_add(uf_info_t *, int);
-extern void close_exec(uf_info_t *);
+extern void fcnt_add(struct uf_info *, int);
+extern void close_exec(struct uf_info *);
extern void clear_stale_fd(void);
extern void clear_active_fd(int);
extern void free_afd(afd_t *afd);
diff --git a/usr/src/uts/common/sys/model.h b/usr/src/uts/common/sys/model.h
index fab96bbe00..0569c086f5 100644
--- a/usr/src/uts/common/sys/model.h
+++ b/usr/src/uts/common/sys/model.h
@@ -37,7 +37,7 @@ extern "C" {
#include <sys/isa_defs.h>
-#if defined(_KERNEL) || defined(_KMEMUSER)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
/*
* These bits are used in various places to specify the data model
diff --git a/usr/src/uts/common/sys/modhash.h b/usr/src/uts/common/sys/modhash.h
index 68d1c4dedd..7f7103ecb9 100644
--- a/usr/src/uts/common/sys/modhash.h
+++ b/usr/src/uts/common/sys/modhash.h
@@ -34,7 +34,7 @@
extern "C" {
#endif
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#include <sys/types.h>
diff --git a/usr/src/uts/common/sys/poll.h b/usr/src/uts/common/sys/poll.h
index 4434a8551a..558edbfba9 100644
--- a/usr/src/uts/common/sys/poll.h
+++ b/usr/src/uts/common/sys/poll.h
@@ -96,7 +96,7 @@ typedef unsigned long nfds_t;
#endif /* _KERNEL */
-#if defined(_KERNEL) || defined(_KMEMUSER)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER)
#include <sys/thread.h>
diff --git a/usr/src/uts/common/sys/share.h b/usr/src/uts/common/sys/share.h
index 4de5f5ce65..1a8aead065 100644
--- a/usr/src/uts/common/sys/share.h
+++ b/usr/src/uts/common/sys/share.h
@@ -63,7 +63,7 @@ struct shrlocklist {
struct shrlocklist *next;
};
-#if defined(_KERNEL)
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
struct flock64;
extern int add_share(struct vnode *, struct shrlock *);
diff --git a/usr/src/uts/common/sys/signal.h b/usr/src/uts/common/sys/signal.h
index 2ff27d7d7f..aece147bec 100644
--- a/usr/src/uts/common/sys/signal.h
+++ b/usr/src/uts/common/sys/signal.h
@@ -245,7 +245,7 @@ struct sigstack {
#include <sys/ucontext.h>
#endif /* defined(_XPG4_2) */
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#include <sys/t_lock.h>
extern const k_sigset_t nullsmask; /* a null signal mask */
diff --git a/usr/src/uts/common/sys/stream.h b/usr/src/uts/common/sys/stream.h
index 4e3482dadc..4be8d794fc 100644
--- a/usr/src/uts/common/sys/stream.h
+++ b/usr/src/uts/common/sys/stream.h
@@ -35,7 +35,7 @@
* For source compatibility
*/
#include <sys/isa_defs.h>
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
#include <sys/kmem.h>
#include <sys/uio.h>
#endif
@@ -640,7 +640,7 @@ struct stroptions {
#define SO_MAXBLK 0x100000 /* set maximum message block size */
#define SO_TAIL 0x200000 /* set the extra allocated space */
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* Structure for rw (read/write) procedure calls. A pointer
* to a struiod_t is passed as a parameter to the rwnext() call.
@@ -768,7 +768,7 @@ typedef struct cmdblk {
*/
#define bpsize(bp) ((unsigned int)(bp->b_datap->db_lim - bp->b_datap->db_base))
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
/*
* For two-byte M_ERROR messages: indication that a side does not have an error
diff --git a/usr/src/uts/common/sys/strsubr.h b/usr/src/uts/common/sys/strsubr.h
index 064fdf5b09..ce86badfc1 100644
--- a/usr/src/uts/common/sys/strsubr.h
+++ b/usr/src/uts/common/sys/strsubr.h
@@ -39,6 +39,7 @@
*/
#include <sys/stream.h>
#include <sys/stropts.h>
+#include <sys/vnode.h>
#include <sys/kstat.h>
#include <sys/uio.h>
#include <sys/proc.h>
@@ -114,7 +115,7 @@ extern "C" {
/*
* Function types for the parameterized stream head.
* The msgfunc_t takes the parameters:
- * msgfunc(vnode_t *vp, mblk_t *mp, strwakeup_t *wakeups,
+ * msgfunc(vnode_t *vp, mblk_t *mp, strwakeup_t *wakeups,
* strsigset_t *firstmsgsigs, strsigset_t *allmsgsigs,
* strpollset_t *pollwakeups);
* It returns an optional message to be processed by the stream head.
@@ -129,7 +130,7 @@ typedef short strpollset_t;
typedef uintptr_t callbparams_id_t;
typedef mblk_t *(*msgfunc_t)(vnode_t *, mblk_t *, strwakeup_t *,
strsigset_t *, strsigset_t *, strpollset_t *);
-typedef int (*errfunc_t)(vnode_t *, int, int *);
+typedef int (*errfunc_t)(vnode_t *, int, int *);
/*
* Per stream sd_lock in putnext may be replaced by per cpu stream_putlocks
@@ -275,7 +276,7 @@ typedef struct stdata {
/* 0x00020000 unused */
/* 0x00040000 unused */
#define STRTOSTOP 0x00080000 /* block background writes */
-#define STRCMDWAIT 0x00100000 /* someone is doing an _I_CMD */
+#define STRCMDWAIT 0x00100000 /* someone is doing an _I_CMD */
/* 0x00200000 unused */
#define STRMOUNT 0x00400000 /* stream is mounted */
#define STRNOTATMARK 0x00800000 /* Not at mark (when empty read q) */
@@ -409,7 +410,7 @@ typedef struct stdata {
*
* The new way is:
*
- * mutex_enter(SQLOCK(sq));
+ * mutex_enter(SQLOCK(sq));
* count = sq->sq_count;
* SQ_PUTLOCKS_ENTER(sq);
* SUM_SQ_PUTCOUNTS(sq, count);
@@ -458,8 +459,8 @@ struct syncq {
*/
uint16_t sq_type; /* type (concurrency) of syncq */
uint16_t sq_rmqcount; /* # threads inside removeq() */
- kcondvar_t sq_wait; /* block on this sync queue */
- kcondvar_t sq_exitwait; /* waiting for thread to leave the */
+ kcondvar_t sq_wait; /* block on this sync queue */
+ kcondvar_t sq_exitwait; /* waiting for thread to leave the */
/* inner perimeter */
/*
* Handling synchronous callbacks such as qtimeout and qbufcall
@@ -1023,7 +1024,7 @@ typedef struct str_stack str_stack_t;
/*
* Copy modes for tty and I_STR ioctls
*/
-#define U_TO_K 01 /* User to Kernel */
+#define U_TO_K 01 /* User to Kernel */
#define K_TO_K 02 /* Kernel to Kernel */
/*
@@ -1076,7 +1077,7 @@ typedef struct str_stack str_stack_t;
#define STRUNLOCKMATES(X) mutex_exit(&((X)->sd_lock)); \
mutex_exit(&(((X)->sd_mate)->sd_lock))
-#ifdef _KERNEL
+#if defined(_KERNEL) || defined(_FAKE_KERNEL)
extern void strinit(void);
extern int strdoioctl(struct stdata *, struct strioctl *, int, int,