summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2019-03-15 13:22:00 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2019-03-15 13:22:00 +0000
commita062971fb96ae7154d88ab408f899f56aaf6df6b (patch)
tree9907dea0824c38373ef2913fd84385ed07a56c3a /usr/src/cmd
parent0b570b3cb1c0bf505f1b1bd352664d638b8cc359 (diff)
parentb4a8b33babbf9a7a5de61ea06d09e1eb537f1f6e (diff)
downloadillumos-joyent-a062971fb96ae7154d88ab408f899f56aaf6df6b.tar.gz
[illumos-gate merge]
commit b4a8b33babbf9a7a5de61ea06d09e1eb537f1f6e 10483 aac: cast between incompatible function types commit a00b240dc61ea7ab64e3881b755fca973a531e89 10146 core_pcbe_event_coverage() is missing an else commit 542a7b7f5ccc44e3c95d6dce4ec0566f60bd9ff4 7780 mdb could extract NT_PRPSINFO information from core files commit 2f7dba3e6747cbaaf1deb86e6ca1e2a5c96332ac 10524 wsdiff much slower after move from deprecated commands module 10448 wsdiff explodes on encoding error 10525 wsdiff output is not correct for a binary file 10526 wsdiff tries to spawn 4.8 threads commit adee678425979226b2b55d1a0b39ce4c989382e9 9735 Need to provide SMB 2.1 Client commit 40c0e2317898b8c774791bdc2b30bd50111ab1fa 9875 SMB client connection setup rework commit 8329232e00f1048795bae53acb230316243aadb5 9874 Add fksmbcl development tool Conflicts: usr/src/cmd/mdb/common/modules/libc/libc.c
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/fs.d/smbclnt/Makefile4
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/.dbxrc24
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/Makefile104
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/README99
-rwxr-xr-xusr/src/cmd/fs.d/smbclnt/fksmbcl/Run.sh32
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/Watch-fksmbcl.d68
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/fkdev.c98
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/fkiod_cl.c150
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/fknewvc.c143
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/fksmbcl_main.c938
-rw-r--r--usr/src/cmd/fs.d/smbclnt/fksmbcl/shares.c (renamed from usr/src/cmd/fs.d/smbclnt/test/srvenum.c)236
-rw-r--r--usr/src/cmd/fs.d/smbclnt/smbutil/Makefile4
-rw-r--r--usr/src/cmd/fs.d/smbclnt/smbutil/shares_rap.c143
-rw-r--r--usr/src/cmd/fs.d/smbclnt/smbutil/view.c19
-rw-r--r--usr/src/cmd/fs.d/smbclnt/test/Makefile85
-rw-r--r--usr/src/cmd/fs.d/smbclnt/test/srvinfo.c415
-rw-r--r--usr/src/cmd/fs.d/smbclnt/test/tconn.c171
-rw-r--r--usr/src/cmd/mdb/Makefile.common4
-rw-r--r--usr/src/cmd/mdb/Makefile.module4
-rw-r--r--usr/src/cmd/mdb/common/modules/libc/libc.c222
-rw-r--r--usr/src/cmd/mdb/common/modules/nsmb/nsmb.c98
-rw-r--r--usr/src/cmd/mdb/common/modules/smbfs/smbfs.c63
-rw-r--r--usr/src/cmd/mdb/intel/amd64/libfknsmb/Makefile49
-rw-r--r--usr/src/cmd/mdb/intel/amd64/libfksmbfs/Makefile56
-rw-r--r--usr/src/cmd/mdb/intel/ia32/libfknsmb/Makefile48
-rw-r--r--usr/src/cmd/mdb/intel/ia32/libfksmbfs/Makefile55
26 files changed, 2287 insertions, 1045 deletions
diff --git a/usr/src/cmd/fs.d/smbclnt/Makefile b/usr/src/cmd/fs.d/smbclnt/Makefile
index 5e26c570b3..e6b660643f 100644
--- a/usr/src/cmd/fs.d/smbclnt/Makefile
+++ b/usr/src/cmd/fs.d/smbclnt/Makefile
@@ -20,8 +20,8 @@
#
#
-# Copyright 2011 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.
#
#
@@ -33,7 +33,7 @@ include $(SRC)/Makefile.master
SUBDIRS_CATALOG= smbutil mount umount share
SUBDIRS= $(SUBDIRS_CATALOG) chacl lsacl \
- smbiod smbiod-svc svc test
+ smbiod smbiod-svc svc fksmbcl
# for messaging catalog files
#
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/.dbxrc b/usr/src/cmd/fs.d/smbclnt/fksmbcl/.dbxrc
new file mode 100644
index 0000000000..8c05f688c5
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/.dbxrc
@@ -0,0 +1,24 @@
+
+#
+# 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.
+#
+
+# set -o emacs
+
+# fksmbcl is always 32-bit
+setenv LD_LIBRARY_PATH ${ROOT}/usr/lib/smbfs:${ROOT}/usr/lib:${ROOT}/lib
+
+echo 'Do one of: attach ${PID}'
+echo 'or: debug ${ROOT}/usr/lib/smbfs/fksmbcl'
+echo 'then: run -v //localhost'
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/Makefile b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Makefile
new file mode 100644
index 0000000000..5ae4f56e1b
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Makefile
@@ -0,0 +1,104 @@
+#
+# 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
+# or http://www.opensolaris.org/os/licensing.
+# 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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+#
+
+PROG= fksmbcl
+
+OBJS_LOCAL = \
+ fksmbcl_main.o \
+ fkdev.o \
+ fknewvc.o \
+ fkiod_cl.o \
+ shares.o
+
+OBJS= ${OBJS_LOCAL}
+SRCS= ${OBJS_LOCAL:.o=.c}
+
+include ../../../Makefile.cmd
+include ../../../Makefile.ctf
+
+# Force SOURCEDEBUG
+CSOURCEDEBUGFLAGS = -g
+CCSOURCEDEBUGFLAGS = -g
+STRIP_STABS = :
+
+# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+# Also, like Makefile.uts, reset CPPFLAGS
+# CPPFLAGS.first += -I$(SRC)/lib/libfakekernel/common
+CPPFLAGS.first += -I$(SRC)/lib/smbclnt/libfknsmb/common
+CPPFLAGS= $(CPPFLAGS.first)
+
+INCS += -I$(SRC)/uts/common/fs/smbclnt
+INCS += -I$(SRC)/uts/common
+INCS += -I$(SRC)/common/smbclnt
+INCS += -I$(SRC)/common
+
+# Allow cpp to find libfknsmb.h etc. via
+# include <libfknsmb/common/libfknsmb.h>
+INCS += -I$(SRC)/lib/smbclnt
+INCS += -I$(SRC)/lib/libsmbfs
+INCS += -I$(SRC)/lib/libsmbfs/netsmb
+
+CPPFLAGS += $(INCS)
+CPPFLAGS += -D_REENTRANT
+CPPFLAGS += -D_FILE_OFFSET_BITS=64
+CPPFLAGS += -D_LARGEFILE64_SOURCE=1
+CPPFLAGS += -DFKSMBCL
+# Always want DEBUG here
+CPPFLAGS += -DDEBUG
+
+CSTD= $(CSTD_GNU99)
+
+CFLAGS += $(CCVERBOSE)
+CFLAGS64 += $(CCVERBOSE)
+
+LDFLAGS += $(ZNOLAZYLOAD)
+LDFLAGS += -R/usr/lib/smbfs
+LDLIBS += -L$(ROOT)/usr/lib/smbfs
+LDLIBS += -lsmbfs -lfksmbfs -lfknsmb
+LDLIBS += -lsocket
+
+ROOTSMBDDIR = $(ROOTLIB)/smbfs
+ROOTSMBDFILE = $(PROG:%=$(ROOTSMBDDIR)/%)
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(LINK.c) -o $(PROG) $(OBJS) $(LDLIBS)
+ $(POST_PROCESS)
+
+clean:
+ -$(RM) $(OBJS)
+
+# lots of lint due to mixing kernel+user stuff. give up.
+lint: # lint_SRCS
+
+include ../../../Makefile.targ
+
+install: all $(ROOTSMBDFILE)
+
+$(ROOTSMBDDIR)/%: %
+ $(INS.file)
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/README b/usr/src/cmd/fs.d/smbclnt/fksmbcl/README
new file mode 100644
index 0000000000..811401bc65
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/README
@@ -0,0 +1,99 @@
+
+#
+# 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.
+#
+
+This directory builds a program linking all of the SMB client code
+into a user-level process. The result is not a fully functional
+SMB client but is very useful for some kinds of development work.
+
+The architecture of this roughly parallels the in-kernel version,
+where the kernel modules are built as libraries including:
+ libfksmbfs, libfknsmb
+
+Just as with the kernel code, there are mdb modules that know
+how to walk data structures in libfksmbfs, etc.
+
+For debugging, etc. it's easiest to run this as a normal user,
+i.e. yourself (not root)
+
+Now you can run fksmbcl from the proto area using this script:
+ ./Run.sh -df
+
+You can also run it under dbx (see the .dbxrc file).
+To run it under mdb (with mdb modules build here):
+ mdb -L $ROOT/usr/lib/mdb/proc:/usr/lib/mdb/proc ...
+where ... is one of: fksmbcl, core.nnn, -p $PID
+
+There are also some dtrace scripts in here, and in ../dtrace
+for watching either all activity or only selected areas.
+Run these like: dtrace -s Watch-all.d -p $PID -o output
+
+These two (from over in ../dtrace) also work with fksmbcl:
+ dtrace -s fksmbcl.d -p `pgrep fksmbcl` -o output
+
+Here is the help output:
+
+ > help
+ Commands:
+ help
+ exit
+ logon [user [dom [pass]]]
+ logoff [close-driver]
+ shares
+ mount {share} [optstr]
+ umount
+ unmount
+ statfs
+ dir {rdir} [lfile]
+ dirx {rdir} [lfile]
+ get {rfile} [lfile]
+ put {lfile} [rfile]
+ mv {from} {to}
+ rm {rfile}
+ mkdir {rfile}
+ rmdir {rfile}
+ opt {option}
+
+
+Here is an example of how to connect, mount, and list a directory:
+
+ $ ./Run.sh //myserver
+ # Start with:
+ > logon [user [dom [pw]]]
+ > shares
+ > mount {share}
+
+ > logon test test test
+ > shares
+ open pipe: /srvsvc
+ enum strings
+ junk
+ c$
+ Default Share
+ test1
+ ipc$
+ Remote IPC
+ test
+ > mount test
+ > dir
+ 1224750917 .
+ 1224750917 ..
+ 900818955 test9.dat
+ 3908265151 lock1.txt
+ 2452346625 test_dir
+ > umount
+ > logoff
+ > exit
+ $
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/Run.sh b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Run.sh
new file mode 100755
index 0000000000..df731bf733
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Run.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+#
+# 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 program to run fksmbd (user-space smbd for debugging)
+# using binaries from the proto area.
+
+[ -n "$ROOT" ] || {
+ echo "Need a bldenv to set ROOT=..."
+ exit 1;
+}
+
+# OK, setup env. to run it.
+
+LD_LIBRARY_PATH=$ROOT/usr/lib/smbfs:$ROOT/usr/lib:$ROOT/lib
+export LD_LIBRARY_PATH
+
+# run with the passed options
+exec $ROOT/usr/lib/smbfs/fksmbcl "$@"
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/Watch-fksmbcl.d b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Watch-fksmbcl.d
new file mode 100644
index 0000000000..b36fd13d6f
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/Watch-fksmbcl.d
@@ -0,0 +1,68 @@
+#!/usr/sbin/dtrace -s
+/*
+ * 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 2018 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * User-level dtrace for fksmbcl
+ * Usage: dtrace -s Watch-fksmbcl.d -p $PID
+ */
+
+/*
+ * If traced, print entry/return
+ */
+pid$target:fksmbcl::entry,
+pid$target:libsmbfs.so.1::entry,
+pid$target:libfksmbfs.so.1::entry,
+pid$target:libfknsmb.so.1::entry,
+pid$target:libfakekernel.so.1::entry
+{
+ printf("\t0x%x", arg0);
+ printf("\t0x%x", arg1);
+ printf("\t0x%x", arg2);
+ printf("\t0x%x", arg3);
+ printf("\t0x%x", arg4);
+ printf("\t0x%x", arg5);
+}
+
+pid$target:fksmbcl::return,
+pid$target:libsmbfs.so.1::return,
+pid$target:libfksmbfs.so.1::return,
+pid$target:libfknsmb.so.1::return,
+pid$target:libfakekernel.so.1::entry
+{
+ printf("\t0x%x", arg1);
+}
+
+pid$target::smbfslookup:entry
+{
+ printf("\tname = %s\n", copyinstr(arg1));
+}
+
+pid$target:libfknsmb.so.1:smb_dtrace2:entry
+/copyinstr(arg0) == "debugmsg2"/
+{
+ this->f = copyinstr(arg1);
+ this->m = copyinstr(arg2);
+ printf("\n\t debugmsg2: %s: %s ", this->f, this->m);
+}
+
+pid$target:libfknsmb.so.1:smb_dtrace3:entry
+/copyinstr(arg0) == "debugmsg3"/
+{
+ this->f = copyinstr(arg1);
+ this->m = copyinstr(arg2);
+ printf("\n\t debugmsg3: %s: %s ", this->f, this->m);
+ trace(arg3);
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkdev.c b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkdev.c
new file mode 100644
index 0000000000..34da749e78
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkdev.c
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+/*
+ * This file implements device open/close/ioctl wrappers that
+ * redirect access from the real "nsmb" device to the in-process
+ * device simulation in libfknsmb.
+ */
+
+#include <sys/param.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/mount.h>
+#include <sys/types.h>
+#include <sys/byteorder.h>
+
+#include <fcntl.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <grp.h>
+#include <unistd.h>
+#include <libintl.h>
+#include <assert.h>
+#include <nss_dbdefs.h>
+
+#include <cflib.h>
+#include <netsmb/smb_lib.h>
+#include <netsmb/netbios.h>
+#include <netsmb/nb_lib.h>
+#include <netsmb/smb_dev.h>
+
+#include <libfknsmb/common/libfknsmb.h>
+
+#include "smb/charsets.h"
+#include "smb/private.h"
+
+int
+smb_open_driver(void)
+{
+ dev32_t dev;
+ int fd;
+ int rc;
+
+ rc = nsmb_drv_open(&dev, 0, 0);
+ if (rc != 0) {
+ errno = rc;
+ return (-1);
+ }
+
+ assert((dev & 0xFFFF0000) != 0);
+ fd = (int)dev;
+
+ return (fd);
+}
+
+int
+nsmb_ioctl(int fd, int cmd, void *arg)
+{
+ dev32_t dev;
+ int err;
+
+ dev = (dev32_t)fd;
+ assert((dev & 0xFFFF0000) != 0);
+ err = nsmb_drv_ioctl(dev, cmd, (intptr_t)arg, 0);
+ if (err != 0) {
+ errno = err;
+ return (-1);
+ }
+ return (0);
+}
+
+int
+nsmb_close(int fd)
+{
+ dev32_t dev;
+
+ dev = (dev32_t)fd;
+ assert((dev & 0xFFFF0000) != 0);
+ (void) nsmb_drv_close(dev, 0, 0);
+ return (0);
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkiod_cl.c b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkiod_cl.c
new file mode 100644
index 0000000000..be26854bd3
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fkiod_cl.c
@@ -0,0 +1,150 @@
+/*
+ * 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
+ * or http://www.opensolaris.org/os/licensing.
+ * 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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * Client-side interface to the IO Daemon (IOD)
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <libintl.h>
+#include <thread.h>
+
+#include <sys/byteorder.h>
+#include <sys/types.h>
+#include <sys/fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+
+#include <netsmb/smb_lib.h>
+#include <netsmb/netbios.h>
+#include <netsmb/nb_lib.h>
+#include <netsmb/smb_dev.h>
+
+#include <assert.h>
+
+#include "smb/charsets.h"
+#include "smb/private.h"
+
+/*
+ * Make sure we don't call the real IOD here.
+ */
+int
+smb_iod_open_door(int *fdp)
+{
+ *fdp = -1;
+ return (ENOTSUP);
+}
+
+/*
+ * Get a door handle to the IOD...
+ */
+int
+smb_iod_start(smb_ctx_t *ctx)
+{
+ return (0);
+}
+
+void *
+iod_work(void *arg)
+{
+ smb_ctx_t *ctx = arg;
+ (void) smb_iod_work(ctx);
+ smb_ctx_free(ctx);
+ return (NULL);
+}
+
+/*
+ * Ask the IOD to connect using the info in ctx.
+ * Called by newvc.
+ *
+ * This function largely follows smbiod.c : iod_newvc()
+ */
+int
+smb_iod_cl_newvc(smb_ctx_t *cl_ctx)
+{
+ smb_ctx_t *ctx;
+ thread_t tid;
+ int err = 0;
+
+ /*
+ * Clone the context, like in smbiod.c
+ */
+ err = smb_ctx_alloc(&ctx);
+ if (err)
+ return (err);
+ bcopy(&cl_ctx->ct_iod_ssn, &ctx->ct_iod_ssn,
+ sizeof (ctx->ct_iod_ssn));
+
+ /*
+ * Create the driver session first...
+ */
+ if ((err = smb_ctx_gethandle(ctx)) != 0)
+ goto out;
+ if (nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_SSN_CREATE, &ctx->ct_ssn) < 0) {
+ err = errno;
+ if (err == EEXIST)
+ err = 0; /* see above */
+ goto out;
+ }
+
+ /*
+ * Do the initial connection setup here, so we can
+ * report the outcome to the door client.
+ */
+ err = smb_iod_connect(ctx);
+ if (err != 0) {
+ fprintf(stderr, "smb_iod_connect, err=%d\n", err);
+ goto out;
+ }
+
+ /* The rest happens in the iod_work thread. */
+ err = thr_create(NULL, 0, iod_work, ctx, THR_DETACHED, &tid);
+ if (err == 0) {
+ /*
+ * Given to the new thread.
+ * free at end of iod_work
+ */
+ ctx = NULL;
+ }
+
+out:
+ if (ctx != NULL)
+ smb_ctx_free(ctx);
+
+ return (err);
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/fknewvc.c b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fknewvc.c
new file mode 100644
index 0000000000..7f66b3b5bb
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fknewvc.c
@@ -0,0 +1,143 @@
+/*
+ * 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
+ * or http://www.opensolaris.org/os/licensing.
+ * 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 2009 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * Create a new VC given a list of addresses.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <libintl.h>
+#include <xti.h>
+#include <assert.h>
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/byteorder.h>
+#include <sys/socket.h>
+#include <sys/fcntl.h>
+
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+
+#include <netsmb/smb.h>
+#include <netsmb/smb_lib.h>
+#include <netsmb/netbios.h>
+#include <netsmb/nb_lib.h>
+#include <netsmb/smb_dev.h>
+
+#include "smb/charsets.h"
+#include "smb/private.h"
+
+/*
+ * Ask the IOD to create a VC with this IP address.
+ */
+static int
+fknewvc(struct smb_ctx *ctx, struct addrinfo *ai)
+{
+ char host[256];
+ char svc[32];
+ smbioc_ossn_t *ssn = &ctx->ct_ssn;
+ int err;
+
+ if (smb_debug) {
+ err = getnameinfo(ai->ai_addr, ai->ai_addrlen,
+ host, sizeof (host), svc, sizeof (svc),
+ AI_NUMERICHOST);
+ if (err != 0) {
+ strlcpy(host, "(?)", sizeof (host));
+ strlcpy(svc, "?", sizeof (host));
+ }
+ printf("fknewvc: Try AF=%d %s:%s\n",
+ ai->ai_family, host, svc);
+ }
+
+ /*
+ * Copy the passed address into ssn_srvaddr,
+ * but first sanity-check lengths. Also,
+ * zero it first to avoid trailing junk.
+ */
+ if (ai->ai_addrlen > sizeof (ssn->ssn_srvaddr))
+ return (EINVAL);
+ bzero(&ssn->ssn_srvaddr, sizeof (ssn->ssn_srvaddr));
+ bcopy(ai->ai_addr, &ssn->ssn_srvaddr, ai->ai_addrlen);
+
+ /* Ask the IOD to connect using the info in ctx. */
+ err = smb_iod_cl_newvc(ctx);
+ if (smb_debug) {
+ printf("fknewvc: iod_cl_newvc err=%d\n", err);
+ }
+
+ return (err);
+}
+
+/*
+ * Setup a new VC via the IOD.
+ * Similar to findvc.c
+ */
+int
+smb_ctx_newvc(struct smb_ctx *ctx)
+{
+ struct addrinfo *ai;
+ int err;
+
+ /* Should already have the address list. */
+ if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
+ return (EINVAL);
+
+ err = EPROTONOSUPPORT; /* in case no AF match */
+ for (ai = ctx->ct_addrinfo; ai; ai = ai->ai_next) {
+
+ switch (ai->ai_family) {
+
+ case AF_INET:
+ case AF_INET6:
+ case AF_NETBIOS:
+ err = fknewvc(ctx, ai);
+ if (err == 0)
+ return (0);
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ /*
+ * In the error case, the caller may try again
+ * with new auth. info, so keep the door open.
+ * Error return will close in smb_ctx_done.
+ */
+ return (err);
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/fksmbcl/fksmbcl_main.c b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fksmbcl_main.c
new file mode 100644
index 0000000000..8b1757ea62
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/fksmbcl_main.c
@@ -0,0 +1,938 @@
+/*
+ * 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 2018 Nexenta Systems, Inc. All rights reserved.
+ */
+
+/*
+ * Test & debug program for the SMB client
+ *
+ * This implements a simple command reader which accepts
+ * commands to simulate system calls into the file system.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <sys/dirent.h>
+#include <sys/strlog.h> /* SL_NOTE */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <unistd.h>
+
+#include <sys/fs/smbfs_mount.h>
+#include <netsmb/smb_lib.h>
+#include <libfknsmb/common/libfknsmb.h>
+#include <libfksmbfs/common/libfksmbfs.h>
+
+#if _FILE_OFFSET_BITS != 64
+#error "This calls (fake) VFS code which requires 64-bit off_t"
+#endif
+
+extern int list_shares(struct smb_ctx *);
+
+#define MAXARG 10
+
+struct cmd_tbl_ent {
+ void (*ce_func)(int, char **);
+ const char *ce_name;
+ const char *ce_argdesc;
+};
+static struct cmd_tbl_ent cmd_tbl[];
+
+static struct smb_ctx *ctx = NULL;
+static char *server = NULL;
+
+static vfs_t *vfsp = NULL;
+
+static void show_dents(vnode_t *, offset_t *, char *, int);
+static void run_cli(void);
+
+#define TBUFSZ 8192
+static char tbuf[TBUFSZ];
+
+static void
+fksmbcl_usage(void)
+{
+ printf("usage: fksmbcl //user@server (like smbutil)\n");
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int error, opt;
+
+ /*
+ * Initializations
+ */
+ nsmb_drv_load();
+ nsmb_drv_init();
+ fksmbfs_init();
+
+ while ((opt = getopt(argc, argv, "dv")) != -1) {
+ switch (opt) {
+ case 'd':
+ smb_debug++;
+ break;
+ case 'v':
+ smb_verbose++;
+ break;
+ case '?':
+ fksmbcl_usage();
+ break;
+ }
+ }
+ if (optind >= argc)
+ fksmbcl_usage();
+ server = argv[optind];
+
+ /*
+ * Setup the libsmbfs context
+ */
+ error = smb_ctx_alloc(&ctx);
+ if (error) {
+ fprintf(stderr, "%s: smb_ctx_alloc failed (%d)\n",
+ argv[0], error);
+ return (1);
+ }
+
+ error = smb_ctx_scan_argv(ctx, argc, argv,
+ SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
+ if (error) {
+ fprintf(stderr, "logon: smb_ctx_scan_argv, error %d\n", error);
+ return (1);
+ }
+ error = smb_ctx_readrc(ctx);
+ if (error) {
+ fprintf(stderr, "logon: smb_ctx_readrc, error %d\n", error);
+ return (1);
+ }
+
+ /* Do smb_ctx_setshare later, and smb_ctx_resolve. */
+
+ /*
+ * Next would be smb_ctx_get_ssn() but don't do that until
+ * the "logon" command so one can set breakpoints etc.
+ */
+
+ /*
+ * Run the CLI
+ */
+ run_cli();
+
+ /*
+ * Cleanup
+ */
+ fksmbfs_fini();
+ nsmb_drv_fini();
+
+ return (0);
+}
+
+static void
+run_cli()
+{
+ static char cmdbuf[100];
+ int argc, i;
+ char *argv[MAXARG];
+ char *cmd;
+ char *savep = NULL;
+ char *sep = " \t\n";
+ char *prompt = NULL;
+ struct cmd_tbl_ent *ce;
+
+ if (isatty(0)) {
+ fputs("# Start with:\n"
+ "> logon [user [dom [pw]]]\n"
+ "> shares\n"
+ "> mount {share}\n\n",
+ stdout);
+ prompt = "> ";
+ }
+
+ for (;;) {
+ if (prompt) {
+ fputs(prompt, stdout);
+ fflush(stdout);
+ }
+
+ cmd = fgets(cmdbuf, sizeof (cmdbuf), stdin);
+ if (cmd == NULL)
+ break;
+ if (cmd[0] == '#')
+ continue;
+
+ if (prompt == NULL) {
+ /* Put commands in the output too. */
+ fprintf(stdout, "+ %s", cmdbuf);
+ }
+
+ argv[0] = strtok_r(cmd, sep, &savep);
+ if (argv[0] == NULL)
+ continue;
+ for (argc = 1; argc < MAXARG; argc++) {
+ argv[argc] = strtok_r(NULL, sep, &savep);
+ if (argv[argc] == NULL)
+ break;
+ }
+ for (i = argc; i < MAXARG; i++)
+ argv[i++] = NULL;
+
+ for (ce = cmd_tbl; ce->ce_name != NULL; ce++)
+ if (strcmp(ce->ce_name, argv[0]) == 0)
+ break;
+ if (ce->ce_name != NULL) {
+ ce->ce_func(argc, argv);
+ } else {
+ fprintf(stderr, "%s unknown command. Try help\n",
+ argv[0]);
+ }
+ }
+}
+
+/*
+ * Command handlers
+ */
+
+static void
+do_exit(int argc, char **argv)
+{
+ exit(0);
+}
+
+static void
+do_help(int argc, char **argv)
+{
+ struct cmd_tbl_ent *ce;
+
+ printf("Commands:\n");
+ for (ce = cmd_tbl; ce->ce_func != NULL; ce++)
+ printf("%s %s\n", ce->ce_name, ce->ce_argdesc);
+}
+
+static void
+do_logon(int argc, char **argv)
+{
+ int error;
+
+ if (argc > 1) {
+ if (argv[1][0] == '-') {
+ smb_ctx_setuser(ctx, "", B_TRUE);
+ ctx->ct_flags |= SMBCF_NOPWD;
+ } else {
+ smb_ctx_setuser(ctx, argv[1], B_TRUE);
+ }
+ }
+ if (argc > 2)
+ smb_ctx_setdomain(ctx, argv[2], B_TRUE);
+ if (argc > 3)
+ smb_ctx_setpassword(ctx, argv[3], NULL);
+
+ /*
+ * Resolve the server address, setup derived defaults.
+ */
+ error = smb_ctx_resolve(ctx);
+ if (error) {
+ fprintf(stderr, "logon: smb_ctx_resolve, error %d\n", error);
+ return;
+ }
+
+ /*
+ * Have server, share, etc. now.
+ * Get the logon session.
+ */
+again:
+ error = smb_ctx_get_ssn(ctx);
+ if (error == EAUTH) {
+ int err2;
+ err2 = smb_get_authentication(ctx);
+ if (err2 == 0)
+ goto again;
+ }
+ if (error) {
+ fprintf(stderr, "//%s: login failed, error %d\n",
+ ctx->ct_fullserver, error);
+ }
+}
+
+/*
+ * Drop session created by the "logon" command.
+ */
+static void
+do_logoff(int argc, char **argv)
+{
+
+ (void) nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_SSN_RELE, NULL);
+ if (argc > 1) {
+ smb_ctx_done(ctx);
+ (void) smb_ctx_init(ctx);
+ }
+}
+
+/*
+ * List shares
+ */
+static void
+do_shares(int argc, char **argv)
+{
+ int error;
+
+ smb_ctx_setshare(ctx, "IPC$", USE_IPC);
+ error = smb_ctx_get_tree(ctx);
+ if (error) {
+ fprintf(stderr, "shares, tcon IPC$, error=%d\n", error);
+ return;
+ }
+
+ error = list_shares(ctx);
+ if (error) {
+ fprintf(stderr, "shares, enum, error=%d\n", error);
+ }
+
+ (void) nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_TREE_RELE, NULL);
+}
+
+char mnt_opt_buf[MAX_MNTOPT_STR];
+char mnt_resource[MAXPATHLEN];
+
+/*
+ * Minimal excerpt from vfs.c:domount()
+ */
+void
+do_mount(int argc, char **argv)
+{
+ struct smbfs_args mdata;
+ struct mounta ma;
+ char *shrname;
+ int error;
+
+ if (vfsp != NULL) {
+ fprintf(stderr, "Already mounted\n");
+ return;
+ }
+
+ if (argc < 2) {
+ fprintf(stderr, "%s: missing share name\n", argv[0]);
+ return;
+ }
+ shrname = argv[1];
+ if (argc > 2)
+ strlcpy(mnt_opt_buf, argv[2], sizeof (mnt_opt_buf));
+ else
+ memset(mnt_opt_buf, 0, sizeof (mnt_opt_buf));
+
+ smb_ctx_setshare(ctx, shrname, USE_DISKDEV);
+ error = smb_ctx_get_tree(ctx);
+ if (error) {
+ fprintf(stderr, "//%s/%s: tree connect failed, %d\n",
+ server, shrname, error);
+ return;
+ }
+
+ (void) snprintf(mnt_resource, sizeof (mnt_resource),
+ "//%s/%s", ctx->ct_fullserver, shrname);
+
+ bzero(&mdata, sizeof (mdata));
+ mdata.version = SMBFS_VERSION; /* smbfs mount version */
+ mdata.file_mode = S_IRWXU;
+ mdata.dir_mode = S_IRWXU;
+ mdata.devfd = ctx->ct_dev_fd;
+
+ /* Build mount args */
+ bzero(&ma, sizeof (ma));
+ ma.spec = mnt_resource;
+ ma.dir = "/";
+ ma.flags = MS_DATA | MS_OPTIONSTR | MS_NOSPLICE | MS_NOSUID;
+ ma.fstype = "smbfs";
+ ma.dataptr = (void *) &mdata;
+ ma.datalen = sizeof (mdata);
+ ma.optptr = mnt_opt_buf;
+ ma.optlen = sizeof (mnt_opt_buf);
+
+ error = fake_domount("smbfs", &ma, &vfsp);
+ if (error != 0) {
+ fprintf(stderr, "domount error=%d\n", error);
+ }
+
+ /* Mount takes a ref, so always rele here. */
+ (void) nsmb_ioctl(ctx->ct_dev_fd, SMBIOC_TREE_RELE, NULL);
+}
+
+void
+do_unmount(int argc, char **argv)
+{
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "Not mounted\n");
+ return;
+ }
+
+ error = fake_dounmount(vfsp, 0);
+ if (error != 0) {
+ fprintf(stderr, "dounmount error=%d\n", error);
+ return;
+ }
+ vfsp = NULL;
+}
+
+void
+do_statfs(int argc, char **argv)
+{
+ statvfs64_t st;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "Not mounted\n");
+ return;
+ }
+
+ error = fsop_statfs(vfsp, &st);
+ if (error != 0) {
+ fprintf(stderr, "df error=%d\n", error);
+ return;
+ }
+ printf("bsize=%ld\n", st.f_bsize);
+ printf("frsize=%ld\n", st.f_frsize);
+ printf("blocks=%" PRIu64 "\n", st.f_blocks);
+ printf(" bfree=%" PRIu64 "\n", st.f_bfree);
+ printf("bavail=%" PRIu64 "\n", st.f_bavail);
+}
+
+void
+do_dir(int argc, char **argv)
+{
+ char *rdir;
+ vnode_t *vp = NULL;
+ offset_t off;
+ int cnt;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc > 1)
+ rdir = argv[1];
+ else
+ rdir = "";
+
+ error = vn_open(rdir, 0, FREAD, 0, &vp, 0, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_dir, vn_open error=%d\n", error);
+ return;
+ }
+
+ off = 0;
+ do {
+ cnt = fake_getdents(vp, &off, tbuf, TBUFSZ);
+ if (cnt < 0) {
+ fprintf(stderr, "do_dir, getdents %d\n", -cnt);
+ break;
+ }
+ show_dents(vp, &off, tbuf, cnt);
+ } while (cnt > 0);
+
+ if (vp != NULL)
+ vn_close_rele(vp, 0);
+}
+
+void
+do_dirx(int argc, char **argv)
+{
+ char *rdir;
+ vnode_t *vp = NULL;
+ offset_t off;
+ int cnt;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc > 1)
+ rdir = argv[1];
+ else
+ rdir = "";
+
+ error = vn_open(rdir, 0, FREAD|FXATTRDIROPEN, 0, &vp, 0, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_dirx, vn_open error=%d\n", error);
+ return;
+ }
+
+ off = 0;
+ do {
+ cnt = fake_getdents(vp, &off, tbuf, TBUFSZ);
+ if (cnt < 0) {
+ fprintf(stderr, "do_dirx, getdents %d\n", -cnt);
+ break;
+ }
+ show_dents(vp, &off, tbuf, cnt);
+ } while (cnt > 0);
+
+ if (vp != NULL)
+ vn_close_rele(vp, 0);
+}
+
+static void
+show_dents(vnode_t *dvp, offset_t *offp, char *buf, int cnt)
+{
+ char time_buf[40];
+ struct stat64 st;
+ vnode_t *vp;
+ char *p;
+ dirent_t *d;
+ offset_t offset = (offset_t)-1L;
+ int error;
+ uint_t mode;
+ char type;
+
+ p = buf;
+ while (p < (buf + cnt)) {
+ d = (dirent_t *)(void *)p;
+ p += d->d_reclen;
+ offset = d->d_off;
+
+ error = fake_lookup(dvp, d->d_name, &vp);
+ if (error != 0) {
+ fprintf(stderr, "%s: lookup error=%d\n",
+ d->d_name, error);
+ continue;
+ }
+ error = fake_stat(vp, &st, 0);
+ vn_rele(vp);
+ if (error != 0) {
+ fprintf(stderr, "%s: stat error=%d\n",
+ d->d_name, error);
+ continue;
+ }
+
+ /*
+ * Print type, mode, size, name
+ * First mode (only dir, file expected here)
+ */
+ if (S_ISDIR(st.st_mode)) {
+ type = 'd';
+ } else if (S_ISREG(st.st_mode)) {
+ type = ' ';
+ } else {
+ type = '?';
+ }
+ mode = st.st_mode & 0777;
+ (void) strftime(time_buf, sizeof (time_buf),
+ "%b %e %T %Y", localtime(&st.st_mtime));
+
+ printf("%c 0%3o %9" PRIu64 " %s %s\n",
+ type, mode,
+ (uint64_t)st.st_size,
+ time_buf,
+ d->d_name);
+ }
+ *offp = offset;
+}
+
+/*
+ * get rname [lname]
+ */
+void
+do_get(int argc, char **argv)
+{
+ struct stat64 st;
+ char *rname;
+ char *lname;
+ vnode_t *vp = NULL;
+ offset_t off;
+ ssize_t cnt, x;
+ int oflg = O_RDWR | O_CREAT;
+ int lfd = -1;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "rname required\n");
+ return;
+ }
+ rname = argv[1];
+ if (argc > 2) {
+ lname = argv[2];
+ /*
+ * When local name is specified, overwrite.
+ * Convenient for scripts etc.
+ */
+ oflg |= O_TRUNC;
+ } else {
+ lname = rname;
+ /* Local file should not exist. */
+ oflg |= O_EXCL;
+ }
+
+ lfd = open(lname, oflg, 0644);
+ if (lfd < 0) {
+ perror(lname);
+ return;
+ }
+
+ error = vn_open(rname, 0, FREAD, 0, &vp, 0, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_get, vn_open error=%d\n", error);
+ goto out;
+ }
+ error = fake_stat(vp, &st, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_get, stat error=%d\n", error);
+ goto out;
+ }
+
+ off = 0;
+ do {
+ cnt = fake_pread(vp, tbuf, TBUFSZ, off);
+ if (cnt < 0) {
+ fprintf(stderr, "do_get, read %d\n", -cnt);
+ goto out;
+ }
+ x = write(lfd, tbuf, cnt);
+ if (x < 0) {
+ fprintf(stderr, "do_get, write %d\n", errno);
+ goto out;
+ }
+ off += x;
+ } while (off < st.st_size);
+
+out:
+ if (vp != NULL)
+ vn_close_rele(vp, 0);
+ if (lfd != -1)
+ close(lfd);
+}
+
+/*
+ * put lname [rname]
+ */
+void
+do_put(int argc, char **argv)
+{
+ struct stat64 rst;
+ struct stat st;
+ char *rname;
+ char *lname;
+ vnode_t *vp = NULL;
+ offset_t off;
+ ssize_t cnt, x;
+ int oflg = FREAD|FWRITE|FCREAT;
+ int lfd = -1;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "lname required\n");
+ return;
+ }
+ lname = argv[1];
+ if (argc > 2) {
+ rname = argv[2];
+ /*
+ * When remote name is specified, overwrite.
+ * Convenient for scripts etc.
+ */
+ oflg |= FTRUNC;
+ } else {
+ rname = lname;
+ /* Remote file should not exist. */
+ oflg |= FEXCL;
+ }
+
+ lfd = open(lname, O_RDONLY, 0);
+ if (lfd < 0) {
+ perror(lname);
+ return;
+ }
+ error = fstat(lfd, &st);
+ if (error != 0) {
+ fprintf(stderr, "do_put, stat error=%d\n", error);
+ goto out;
+ }
+
+ error = vn_open(rname, 0, oflg, 0, &vp, 0, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_put, vn_open error=%d\n", error);
+ goto out;
+ }
+
+ off = 0;
+ do {
+ cnt = pread(lfd, tbuf, TBUFSZ, off);
+ if (cnt < 0) {
+ fprintf(stderr, "do_put, read %d\n", errno);
+ goto out;
+ }
+ x = fake_pwrite(vp, tbuf, cnt, off);
+ if (x < 0) {
+ fprintf(stderr, "do_put, write %d\n", -x);
+ goto out;
+ }
+ off += cnt;
+ } while (off < st.st_size);
+
+ /* This getattr should go OtW. */
+ error = fake_stat(vp, &rst, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_put, stat error=%d\n", error);
+ goto out;
+ }
+ if (rst.st_size != st.st_size) {
+ fprintf(stderr, "do_put, wrong size?\n");
+ }
+
+out:
+ if (vp != NULL)
+ vn_close_rele(vp, 0);
+ if (lfd != -1)
+ close(lfd);
+}
+
+/*
+ * rm rname
+ */
+void
+do_rm(int argc, char **argv)
+{
+ char *rname;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "rname required\n");
+ return;
+ }
+ rname = argv[1];
+
+ error = fake_unlink(rname, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_rm, unlink error=%d\n", error);
+ }
+}
+
+/*
+ * mv fromname toname
+ */
+void
+do_mv(int argc, char **argv)
+{
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 3) {
+ fprintf(stderr, "from_name to_name required\n");
+ return;
+ }
+
+ error = fake_rename(argv[1], argv[2]);
+ if (error != 0) {
+ fprintf(stderr, "do_mv, rename error=%d\n", error);
+ }
+}
+
+/*
+ * mkdir rname
+ */
+void
+do_mkdir(int argc, char **argv)
+{
+ char *rname;
+ vnode_t *vp = NULL;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "rname required\n");
+ return;
+ }
+ rname = argv[1];
+
+ error = vn_open(rname, 0, FCREAT, 0, &vp, CRMKDIR, 0);
+ if (error != 0) {
+ fprintf(stderr, "do_mkdir, vn_open error=%d\n", error);
+ }
+
+ if (vp != NULL)
+ vn_close_rele(vp, 0);
+}
+
+/*
+ * rmdir rname
+ */
+void
+do_rmdir(int argc, char **argv)
+{
+ char *rname;
+ int error;
+
+ if (vfsp == NULL) {
+ fprintf(stderr, "mnt required first\n");
+ return;
+ }
+ if (argc < 2) {
+ fprintf(stderr, "rname required\n");
+ return;
+ }
+ rname = argv[1];
+
+ error = fake_unlink(rname, AT_REMOVEDIR);
+ if (error != 0) {
+ fprintf(stderr, "do_rmdir, unlink error=%d\n", error);
+ }
+}
+
+/*
+ * Simple option setting
+ *
+ * Each arg is handled as one line in .nsmbrc [default]
+ */
+void
+do_opt(int argc, char **argv)
+{
+ static char template[20] = "/tmp/fksmbclXXXXXX";
+ static char rcname[30];
+ char *tdname;
+ char *save_home;
+ FILE *fp;
+ int err, i;
+
+ if (argc < 2) {
+ fprintf(stderr, "opt {key}[=value]\n");
+ return;
+ }
+
+ tdname = mkdtemp(template);
+ if (tdname == NULL) {
+ perror("mkdtemp");
+ return;
+ }
+ (void) snprintf(rcname, sizeof (rcname),
+ "%s/.nsmbrc", tdname);
+
+ fp = fopen(rcname, "w");
+ if (fp == NULL) {
+ perror(rcname);
+ goto out;
+ }
+ fprintf(fp, "[default]\n");
+ for (i = 1; i < argc; i++)
+ fprintf(fp, "%s\n", argv[i]);
+ fclose(fp);
+
+ save_home = ctx->ct_home;
+ ctx->ct_home = tdname;
+ err = smb_ctx_readrc(ctx);
+ ctx->ct_home = save_home;
+
+ if (err != 0)
+ fprintf(stderr, "readrc, err=%d\n", err);
+
+out:
+ (void) unlink(rcname);
+ (void) rmdir(tdname);
+}
+
+/*
+ * Command table
+ */
+static struct cmd_tbl_ent
+cmd_tbl[] = {
+ { do_help, "help", "" },
+ { do_exit, "exit", "" },
+ { do_logon, "logon", "[user [dom [pass]]]" },
+ { do_logoff, "logoff", "[close-driver]" },
+ { do_shares, "shares", "" },
+ { do_mount, "mount", "{share} [optstr]" },
+ { do_unmount, "umount", "" },
+ { do_unmount, "unmount", "" },
+ { do_statfs, "statfs", "" },
+ { do_dir, "dir", "{rdir} [lfile]" },
+ { do_dirx, "dirx", "{rdir} [lfile]" },
+ { do_get, "get", "{rfile} [lfile]" },
+ { do_put, "put", "{lfile} [rfile]" },
+ { do_mv, "mv", "{from} {to}" },
+ { do_rm, "rm", "{rfile}" },
+ { do_mkdir, "mkdir", "{rfile}" },
+ { do_rmdir, "rmdir", "{rfile}" },
+ { do_opt, "opt", "{option}" },
+ { NULL, NULL, NULL }
+};
+
+/*
+ * Provide a real function (one that prints something) to replace
+ * the stub in libfakekernel. This prints cmn_err() messages.
+ */
+void
+fakekernel_putlog(char *msg, size_t len, int flags)
+{
+
+ /*
+ * [CE_CONT, CE_NOTE, CE_WARN, CE_PANIC] maps to
+ * [SL_NOTE, SL_NOTE, SL_WARN, SL_FATAL]
+ */
+ if (smb_debug == 0 && (flags & SL_NOTE))
+ return;
+ (void) fwrite(msg, 1, len, stdout);
+ (void) fflush(stdout);
+}
+
+/*
+ * Print nsmb debug messages via driver smb_debugmsg()
+ */
+void
+smb_debugmsg(const char *func, char *msg)
+{
+ if (smb_debug < 2)
+ return;
+ printf("[kmod] %s: %s\n", func, msg);
+}
+
+/*
+ * Enable libumem debugging
+ */
+const char *
+_umem_debug_init(void)
+{
+ return ("default,verbose"); /* $UMEM_DEBUG setting */
+}
+
+const char *
+_umem_logging_init(void)
+{
+ return ("fail,contents"); /* $UMEM_LOGGING setting */
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/test/srvenum.c b/usr/src/cmd/fs.d/smbclnt/fksmbcl/shares.c
index ee3aeba014..2d8d0cf6da 100644
--- a/usr/src/cmd/fs.d/smbclnt/test/srvenum.c
+++ b/usr/src/cmd/fs.d/smbclnt/fksmbcl/shares.c
@@ -21,7 +21,7 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
@@ -36,27 +36,17 @@
#include <string.h>
#include <unistd.h>
#include <libintl.h>
+#include <ctype.h>
-#include <netsmb/smbfs_api.h>
+#include <netsmb/smb_lib.h>
/*
* This is a quick hack for testing client-side named pipes.
- * Its purpose is to test the ability to connect to a server,
- * open a pipe, send and receive data. The "hack" aspect is
- * the use of hand-crafted RPC messages, which allows testing
- * of the named pipe API separately from the RPC libraries.
- *
- * I captured the two small name pipe messages sent when
- * requesting a share list via RPC over /pipe/srvsvc and
- * dropped them into the arrays below (bind and enum).
- * This program sends the two messages (with adjustments)
- * and just dumps whatever comes back over the pipe.
- * Use wireshark if you want to see decoded messages.
+ * Its purpose is to test SMB named-pipe interface separately
+ * from the RPC implementation. It's a "hack" because it uses
+ * hand-crafted RPC messages (extracted from network traffic).
*/
-extern char *optarg;
-extern int optind, opterr, optopt;
-
/* This is a DCE/RPC bind call for "srvsvc". */
static const uchar_t
srvsvc_bind[] = {
@@ -95,175 +85,35 @@ srvsvc_enum2[] = {
static uchar_t sendbuf[1024];
static uchar_t recvbuf[4096];
-static char *server;
-
-static int pipetest(struct smb_ctx *);
+/*
+ * Print strings found in the buffer.
+ */
static void
-srvenum_usage(void)
+pstrings(const uchar_t *buf, int len)
{
- printf("usage: srvenum [-d domain][-u user][-p passwd] server\n");
- exit(1);
-}
-
-int
-main(int argc, char *argv[])
-{
- int c, error;
- struct smb_ctx *ctx = NULL;
- char *dom = NULL;
- char *usr = NULL;
- char *pw = NULL;
-
- while ((c = getopt(argc, argv, "vd:u:p:")) != -1) {
- switch (c) {
- case 'v':
- smb_verbose = 1;
- break;
-
- case 'd':
- dom = optarg;
- break;
- case 'u':
- usr = optarg;
- break;
- case 'p':
- pw = optarg;
- break;
- case '?':
- srvenum_usage();
- break;
+ const uchar_t *p = buf;
+ uint16_t u2;
+ boolean_t instr = B_FALSE;
+
+ while (len > 2) {
+ u2 = *p++;
+ u2 |= (*p++) << 8;
+ len -= 2;
+
+ if ((u2 & 0xFF80) == 0 && isprint(u2)) {
+ /* printable */
+ instr = B_TRUE;
+ putchar(u2);
+ } else {
+ /* not printalbe */
+ if (instr)
+ putchar('\n');
+ instr = B_FALSE;
}
}
- if (optind >= argc)
- srvenum_usage();
- server = argv[optind];
-
- if (pw != NULL && (dom == NULL || usr == NULL)) {
- fprintf(stderr, "%s: -p arg requires -d dom -u usr\n",
- argv[0]);
- srvenum_usage();
- }
-
- /*
- * This section is intended to demonstrate how an
- * RPC client library might use this interface.
- */
- error = smb_ctx_alloc(&ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_alloc failed\n", argv[0]);
- goto out;
- }
-
- /*
- * Set server, share, domain, user
- * (in the ctx handle).
- */
- smb_ctx_setfullserver(ctx, server);
- smb_ctx_setshare(ctx, "IPC$", USE_IPC);
- if (dom)
- smb_ctx_setdomain(ctx, dom, B_TRUE);
- if (usr)
- smb_ctx_setuser(ctx, usr, B_TRUE);
- if (pw)
- smb_ctx_setpassword(ctx, pw, NULL);
-
-
- /*
- * If this code were in smbutil or mount_smbfs, it would
- * get system and $HOME/.nsmbrc settings here, like this:
- */
-#if 0
- error = smb_ctx_readrc(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_readrc failed\n", argv[0]);
- goto out;
- }
-#endif
-
- /*
- * Resolve the server address,
- * setup derived defaults.
- */
- error = smb_ctx_resolve(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_resolve failed\n", argv[0]);
- goto out;
- }
-
- /*
- * Get the session and tree.
- */
- error = smb_ctx_get_ssn(ctx);
- if (error) {
- fprintf(stderr, "//%s: login failed, error %d\n",
- server, error);
- goto out;
- }
- error = smb_ctx_get_tree(ctx);
- if (error) {
- fprintf(stderr, "//%s/%s: tree connect failed, %d\n",
- server, "IPC$", error);
- goto out;
- }
-
- /*
- * Do some named pipe I/O.
- */
- error = pipetest(ctx);
- if (error) {
- fprintf(stderr, "pipetest, %d\n", error);
- goto out;
- }
-
-out:
- smb_ctx_free(ctx);
-
- return ((error) ? 1 : 0);
-}
-
-static void
-hexdump(const uchar_t *buf, int len) {
- int idx;
- char ascii[24];
- char *pa = ascii;
-
- memset(ascii, '\0', sizeof (ascii));
-
- idx = 0;
- while (len--) {
- if ((idx & 15) == 0) {
- printf("[%04X] ", idx);
- pa = ascii;
- }
- if (*buf > ' ' && *buf <= '~')
- *pa++ = *buf;
- else
- *pa++ = '.';
- printf("%02x ", *buf++);
-
- idx++;
- if ((idx & 7) == 0) {
- *pa++ = ' ';
- putchar(' ');
- }
- if ((idx & 15) == 0) {
- *pa = '\0';
- printf("%s\n", ascii);
- }
- }
-
- if ((idx & 15) != 0) {
- *pa = '\0';
- /* column align the last ascii row */
- do {
- printf(" ");
- idx++;
- if ((idx & 7) == 0)
- putchar(' ');
- } while ((idx & 15) != 0);
- printf("%s\n", ascii);
- }
+ if (instr)
+ putchar('\n');
}
/*
@@ -309,10 +159,6 @@ do_bind(int fid)
printf("xact bind, err=%d\n", err);
return (err);
}
- if (smb_verbose) {
- printf("bind ack, len=%d\n", len);
- hexdump(recvbuf, len);
- }
if (more > 0) {
if (more > sizeof (recvbuf)) {
printf("bogus more=%d\n", more);
@@ -325,17 +171,13 @@ do_bind(int fid)
printf("read enum resp, err=%d\n", err);
return (err);
}
- if (smb_verbose) {
- printf("bind ack (more), len=%d\n", len);
- hexdump(recvbuf, len);
- }
}
return (0);
}
static int
-do_enum(int fid)
+do_enum(char *server, int fid)
{
int err, len, rlen, wlen;
uchar_t *p;
@@ -393,18 +235,22 @@ do_enum(int fid)
return (err);
}
- /* Just dump the response data. */
- printf("enum recv, len=%d\n", rlen);
- hexdump(recvbuf, rlen);
+ /*
+ * Just dump strings found in the response data.
+ * Skip the first 0x90 (RPC wrappers).
+ */
+ printf("enum strings\n");
+ pstrings(recvbuf + 0x90, rlen - 0x90);
return (0);
}
-static int
-pipetest(struct smb_ctx *ctx)
+int
+list_shares(struct smb_ctx *ctx)
{
static char path[] = "/srvsvc";
static uchar_t key[16];
+ char *server = ctx->ct_srvname;
int err, fd;
printf("open pipe: %s\n", path);
@@ -426,7 +272,7 @@ pipetest(struct smb_ctx *ctx)
printf("do_bind: %d\n", err);
goto out;
}
- err = do_enum(fd);
+ err = do_enum(server, fd);
if (err)
printf("do_enum: %d\n", err);
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile b/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
index ae9dd15817..3a852c6978 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
@@ -23,7 +23,7 @@
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
-# Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+# Copyright 2018 Nexenta Systems, Inc. All rights reserved.
# Copyright (c) 2018, Joyent, Inc.
#
@@ -34,7 +34,7 @@
PROG= smbutil
OBJS= smbutil.o discon.o info.o login.o lookup.o print.o status.o view.o \
- shares_rap.o shares_rpc.o srvsvc1_clnt.o srvsvc1_ndr.o
+ shares_rpc.o srvsvc1_clnt.o srvsvc1_ndr.o
SRCS= $(OBJS:%.o=%.c)
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/shares_rap.c b/usr/src/cmd/fs.d/smbclnt/smbutil/shares_rap.c
deleted file mode 100644
index f2235e2880..0000000000
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/shares_rap.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright (c) 2000-2002, Boris Popov
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by Boris Popov.
- * 4. Neither the name of the author nor the names of any co-contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: Id: view.c,v 1.9 2002/02/20 09:26:42 bp Exp
- */
-
-/*
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <netsmb/mchain.h> /* letohs, etc. */
-#include <netsmb/smb.h>
-#include <netsmb/smb_lib.h>
-#include <netsmb/smb_rap.h>
-
-#include "common.h"
-
-/*
- * Enumerate shares using Remote Administration Protocol (RAP)
- * Was in libsmbfs netshareenum.c
- */
-
-struct smb_share_info_1 {
- char shi1_netname[13];
- char shi1_pad;
- uint16_t shi1_type;
- uint32_t shi1_remark; /* char * */
-};
-
-static int
-smb_rap_NetShareEnum(struct smb_ctx *ctx, int sLevel, void *pbBuffer,
- int *cbBuffer, int *pcEntriesRead, int *pcTotalAvail)
-{
- struct smb_rap *rap;
- long lval = -1;
- int error;
-
- error = smb_rap_create(0, "WrLeh", "B13BWz", &rap);
- if (error)
- return (error);
- smb_rap_setNparam(rap, sLevel); /* W - sLevel */
- smb_rap_setPparam(rap, pbBuffer); /* r - pbBuffer */
- smb_rap_setNparam(rap, *cbBuffer); /* L - cbBuffer */
- error = smb_rap_request(rap, ctx);
- if (error == 0) {
- *pcEntriesRead = rap->r_entries;
- error = smb_rap_getNparam(rap, &lval);
- *pcTotalAvail = lval;
- /* Copy the data length into the IN/OUT variable. */
- *cbBuffer = rap->r_rcvbuflen;
- }
- error = smb_rap_error(rap, error);
- smb_rap_done(rap);
- return (error);
-}
-
-int
-share_enum_rap(smb_ctx_t *ctx)
-{
- struct smb_share_info_1 *shi;
- void *rpbuf;
- char *cp;
- int error, bufsize, i, rcnt, total;
- int lbound, rbound;
- uint16_t type;
-
- bufsize = 0xffe0; /* samba notes win2k bug for 65535 */
- rpbuf = malloc(bufsize);
- if (rpbuf == NULL)
- return (errno);
-
- error = smb_rap_NetShareEnum(ctx, 1, rpbuf, &bufsize, &rcnt, &total);
- if (error &&
- error != (ERROR_MORE_DATA | SMB_RAP_ERROR))
- goto out;
-
- /*
- * Bounds for offsets to comments strings.
- * After the array, and before the end.
- */
- lbound = rcnt * (sizeof (struct smb_share_info_1));
- rbound = bufsize;
-
- /* Print the header line. */
- view_print_share(NULL, 0, NULL);
-
- for (shi = rpbuf, i = 0; i < rcnt; i++, shi++) {
- type = letohs(shi->shi1_type);
-
- shi->shi1_pad = '\0'; /* ensure null termination */
-
- /*
- * Offsets to comment strings can be trash.
- * Only print when the offset is valid.
- */
- if (shi->shi1_remark >= lbound &&
- shi->shi1_remark < rbound) {
- cp = (char *)rpbuf + shi->shi1_remark;
- } else
- cp = NULL;
-
- /* Convert from OEM to local codeset? */
- view_print_share(shi->shi1_netname, type, cp);
- }
- error = 0;
-
-out:
- free(rpbuf);
- return (error);
-}
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/view.c b/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
index bf3397c166..18f0488ad3 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
@@ -34,7 +34,7 @@
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
@@ -51,8 +51,6 @@
#include <netsmb/smb_lib.h>
#include "common.h"
-static int use_rap;
-
void
view_usage(void)
{
@@ -86,15 +84,6 @@ cmd_view(int argc, char *argv[])
while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
if (opt == '?')
view_usage();
- /*
- * This is an undocumented option, just for testing.
- * Use the old LanMan Remote API Protocol (RAP) for
- * enumerating shares.
- */
- if (opt == 'B') {
- use_rap++;
- continue;
- }
error = smb_ctx_opt(ctx, opt, optarg);
if (error)
goto out;
@@ -137,12 +126,8 @@ again:
/*
* Have IPC$ tcon, now list shares.
- * Try RPC; if that fails, do RAP.
*/
- if (!use_rap)
- error = share_enum_rpc(ctx, ctx->ct_fullserver);
- if (error || use_rap)
- error = share_enum_rap(ctx);
+ error = share_enum_rpc(ctx, ctx->ct_fullserver);
out:
smb_ctx_free(ctx);
diff --git a/usr/src/cmd/fs.d/smbclnt/test/Makefile b/usr/src/cmd/fs.d/smbclnt/test/Makefile
deleted file mode 100644
index affd6d9a00..0000000000
--- a/usr/src/cmd/fs.d/smbclnt/test/Makefile
+++ /dev/null
@@ -1,85 +0,0 @@
-#
-# 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
-# or http://www.opensolaris.org/os/licensing.
-# 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 2009 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
-# Copyright 2013 Nexenta Systems, Inc. All rights reserved.
-# Copyright (c) 2019, Joyent, Inc.
-#
-
-include $(SRC)/cmd/Makefile.cmd
-
-PROG= srvenum srvinfo tconn
-OBJS = $(PROG:%=%.o)
-SRCS = $(OBJS:%.o=%.c)
-
-# ROOTFS_PROG= $(LIBPROG)
-# include ../../Makefile.fstype
-
-ROOTOPTPKG = $(ROOT)/opt/smbcl-tests
-TESTDIR = $(ROOTOPTPKG)/tests
-INST_CMDS = $(PROG:%=$(TESTDIR)/%)
-
-# OBJS= $(LIBPROG).o
-# SRCS= $(LIBPROG).c $(FSLIBSRC)
-
-CPPFLAGS += -I../../../../uts/common
-CPPFLAGS += -I../../../../lib/libsmbfs
-
-LDLIBS += -R'$$ORIGIN/../../../usr/lib'
-LDLIBS += -lsmbfs
-LINTLIBS= -L$(ROOTLIB) -lsmbfs
-
-CFLAGS += $(CCVERBOSE)
-CERRWARN += -_gcc=-Wno-unused-variable
-CSTD= $(CSTD_GNU99)
-
-# not linted
-SMATCH=off
-
-LINTFLAGS += -erroff=E_FUNC_RET_ALWAYS_IGNOR2
-
-# CLOBBERFILES += $(LIBPROG)
-
-all: $(PROG)
-
-install: all $(ROOTOPTPKG) $(TESTDIR) $(INST_CMDS)
-
-lint:
- for f in $(SRCS); do ;\
- $(LINT.c) $$f $(LINTLIBS) ; done
-
-clobber: clean
- -$(RM) $(PROG)
-
-clean:
- -$(RM) $(OBJS)
-
-$(ROOTOPTPKG):
- $(INS.dir)
-
-$(TESTDIR):
- $(INS.dir)
-
-$(TESTDIR)/%: %
- $(INS.file)
-
-.KEEP_STATE:
diff --git a/usr/src/cmd/fs.d/smbclnt/test/srvinfo.c b/usr/src/cmd/fs.d/smbclnt/test/srvinfo.c
deleted file mode 100644
index 81ba8c9afc..0000000000
--- a/usr/src/cmd/fs.d/smbclnt/test/srvinfo.c
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * 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
- * or http://www.opensolaris.org/os/licensing.
- * 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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
- */
-
-/*
- * Test program for the smbfs named pipe API.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <libintl.h>
-
-#include <netsmb/smbfs_api.h>
-
-/*
- * This is a quick hack for testing client-side named pipes.
- * Its purpose is to test the ability to connect to a server,
- * open a pipe, send and receive data. The "hack" aspect is
- * the use of hand-crafted RPC messages, which allows testing
- * of the named pipe API separately from the RPC libraries.
- *
- * I captured the two small name pipe messages sent when
- * requesting a server info via RPC over /pipe/srvsvc and
- * dropped them into the arrays below (bind and info).
- * This program sends the two messages (with adjustments)
- * and just dumps whatever comes back over the pipe.
- * Use wireshark if you want to see decoded messages.
- */
-
-extern char *optarg;
-extern int optind, opterr, optopt;
-
-/* This is a DCE/RPC bind call for "srvsvc". */
-static const uchar_t
-srvsvc_bind[] = {
- 0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
- 0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
- 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
- 0xc8, 0x4f, 0x32, 0x4b, 0x70, 0x16, 0xd3, 0x01,
- 0x12, 0x78, 0x5a, 0x47, 0xbf, 0x6e, 0xe1, 0x88,
- 0x03, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
- 0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
- 0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00 };
-
-/* This is a srvsvc "get server info" call, in two parts */
-static const uchar_t
-srvsvc_info[] = {
- 0x05, 0x00, 0x00, 0x03, 0x10, 0x00, 0x00, 0x00,
-#define INFO_RPCLEN_OFF 8
- /* V - RPC frag length */
- 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- /* ... and the operation number is: VVVV */
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x15, 0x00,
-#define INFO_SLEN1_OFF 28
-#define INFO_SLEN2_OFF 36
- /* server name, length 14 vv ... */
- 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00 };
- /* UNC server here, i.e.: "\\192.168.1.6" */
-
-static uchar_t sendbuf[1024];
-static uchar_t recvbuf[1024];
-static char *server;
-
-static int pipetest(struct smb_ctx *);
-
-static void
-srvinfo_usage(void)
-{
- printf("usage: srvinfo [-d domain][-u user][-p passwd] server\n");
- exit(1);
-}
-
-int
-main(int argc, char *argv[])
-{
- int c, error;
- struct smb_ctx *ctx = NULL;
- char *dom = NULL;
- char *usr = NULL;
- char *pw = NULL;
-
- while ((c = getopt(argc, argv, "vd:u:p:")) != -1) {
- switch (c) {
- case 'v':
- smb_verbose = 1;
- break;
-
- case 'd':
- dom = optarg;
- break;
- case 'u':
- usr = optarg;
- break;
- case 'p':
- pw = optarg;
- break;
- case '?':
- srvinfo_usage();
- break;
- }
- }
- if (optind >= argc)
- srvinfo_usage();
- server = argv[optind];
-
- if (pw != NULL && (dom == NULL || usr == NULL)) {
- fprintf(stderr, "%s: -p arg requires -d dom -u usr\n",
- argv[0]);
- srvinfo_usage();
- }
-
- /*
- * This section is intended to demonstrate how an
- * RPC client library might use this interface.
- */
- error = smb_ctx_alloc(&ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_alloc failed\n", argv[0]);
- goto out;
- }
-
- /*
- * Set server, share, domain, user
- * (in the ctx handle).
- */
- smb_ctx_setfullserver(ctx, server);
- smb_ctx_setshare(ctx, "IPC$", USE_IPC);
- if (dom)
- smb_ctx_setdomain(ctx, dom, B_TRUE);
- if (usr)
- smb_ctx_setuser(ctx, usr, B_TRUE);
- if (pw)
- smb_ctx_setpassword(ctx, pw, NULL);
-
-
- /*
- * If this code were in smbutil or mount_smbfs, it would
- * get system and $HOME/.nsmbrc settings here, like this:
- */
-#if 0
- error = smb_ctx_readrc(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_readrc failed\n", argv[0]);
- goto out;
- }
-#endif
-
- /*
- * Resolve the server address,
- * setup derived defaults.
- */
- error = smb_ctx_resolve(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_resolve failed\n", argv[0]);
- goto out;
- }
-
- /*
- * Get the session and tree.
- */
- error = smb_ctx_get_ssn(ctx);
- if (error) {
- fprintf(stderr, "//%s: login failed, error %d\n",
- server, error);
- goto out;
- }
- error = smb_ctx_get_tree(ctx);
- if (error) {
- fprintf(stderr, "//%s/%s: tree connect failed, %d\n",
- server, "IPC$", error);
- goto out;
- }
-
- /*
- * Do some named pipe I/O.
- */
- error = pipetest(ctx);
- if (error) {
- fprintf(stderr, "pipetest, %d\n", error);
- goto out;
- }
-
-out:
- smb_ctx_free(ctx);
-
- return ((error) ? 1 : 0);
-}
-
-static void
-hexdump(const uchar_t *buf, int len) {
- int ofs = 0;
-
- while (len--) {
- if (ofs % 16 == 0)
- printf("\n%02X: ", ofs);
- printf("%02x ", *buf++);
- ofs++;
- }
- printf("\n");
-}
-
-/*
- * Put a unicode UNC server name, including the null.
- * Quick-n-dirty, just for this test...
- */
-static int
-put_uncserver(const char *s, uchar_t *buf)
-{
- uchar_t *p = buf;
- char c;
-
- *p++ = '\\'; *p++ = '\0';
- *p++ = '\\'; *p++ = '\0';
-
- do {
- c = *s++;
- if (c == '/')
- c = '\\';
- *p++ = c;
- *p++ = '\0';
-
- } while (c != 0);
-
- return (p - buf);
-}
-
-/* Get a little-endian int. Just for testing. */
-static int
-getint(const uchar_t *p)
-{
- return (p[0] + (p[1]<<8) + (p[2]<<16) + (p[3]<<24));
-}
-
-/*
- * Send the bind and read the ack.
- * This tests smb_fh_xactnp.
- */
-static int
-do_bind(int fid)
-{
- int err, len, more;
-
- more = 0;
- len = sizeof (recvbuf);
- err = smb_fh_xactnp(fid,
- sizeof (srvsvc_bind), (char *)srvsvc_bind,
- &len, (char *)recvbuf, &more);
- if (err) {
- printf("xact bind, err=%d\n", err);
- return (err);
- }
- if (smb_verbose) {
- printf("bind ack, len=%d\n", len);
- hexdump(recvbuf, len);
- }
- if (more > 0) {
- if (more > sizeof (recvbuf)) {
- printf("bogus more=%d\n", more);
- more = sizeof (recvbuf);
- }
- len = smb_fh_read(fid, 0,
- more, (char *)recvbuf);
- if (len == -1) {
- err = EIO;
- printf("read info resp, err=%d\n", err);
- return (err);
- }
- if (smb_verbose) {
- printf("bind ack (more), len=%d\n", len);
- hexdump(recvbuf, len);
- }
- }
-
- return (0);
-}
-
-static int
-do_info(int fid)
-{
- int err, len, rlen, wlen, x;
- uchar_t *p;
-
- /*
- * Build the info request - two parts.
- * See above: srvsvc_info
- *
- * First part: RPC header, etc.
- */
- p = sendbuf;
- len = sizeof (srvsvc_info); /* 40 */
- memcpy(p, srvsvc_info, len);
- p += len;
-
- /* Second part: UNC server name */
- len = put_uncserver(server, p);
- p += len;
- sendbuf[INFO_SLEN1_OFF] = len / 2;
- sendbuf[INFO_SLEN2_OFF] = len / 2;
-
- /* Third part: level, etc. (align4) */
- for (len = (p - sendbuf) & 3; len; len--)
- *p++ = '\0';
- *p++ = 101; /* the "level" */
- *p++ = 0; *p++ = 0; *p++ = 0;
-
- /*
- * Compute total length, and fixup RPC header.
- */
- len = p - sendbuf;
- sendbuf[INFO_RPCLEN_OFF] = len;
-
- /*
- * Send the info request, read the response.
- * This tests smb_fh_write, smb_fh_read.
- */
- wlen = smb_fh_write(fid, 0, len, (char *)sendbuf);
- if (wlen == -1) {
- err = errno;
- printf("write info req, err=%d\n", err);
- return (err);
- }
- if (wlen != len) {
- printf("write info req, short write %d\n", wlen);
- return (EIO);
- }
-
- rlen = smb_fh_read(fid, 0,
- sizeof (recvbuf), (char *)recvbuf);
- if (rlen == -1) {
- err = errno;
- printf("read info resp, err=%d\n", err);
- return (err);
- }
-
- if (smb_verbose) {
- printf("info recv, len=%d\n", rlen);
- hexdump(recvbuf, rlen);
- }
-
- x = getint(recvbuf + 4);
- if (x != 0x10) {
- printf("Data representation 0x%x not supported\n", x);
- return (ENOTSUP);
- }
- printf("Platform Id: %d\n", getint(recvbuf + 0x20));
- printf("Version Major: %d\n", getint(recvbuf + 0x28));
- printf("Version Minor: %d\n", getint(recvbuf + 0x2c));
- printf("Srv type flags: 0x%x\n", getint(recvbuf + 0x30));
-
- return (0);
-}
-
-static int
-pipetest(struct smb_ctx *ctx)
-{
- static char path[] = "/srvsvc";
- static uchar_t key[16];
- int err, fd;
-
- printf("open pipe: %s\n", path);
- fd = smb_fh_open(ctx, path, O_RDWR);
- if (fd < 0) {
- perror(path);
- return (errno);
- }
-
- /* Test this too. */
- err = smb_fh_getssnkey(fd, key, sizeof (key));
- if (err) {
- printf("getssnkey: %d\n", err);
- goto out;
- }
-
- err = do_bind(fd);
- if (err) {
- printf("do_bind: %d\n", err);
- goto out;
- }
- err = do_info(fd);
- if (err)
- printf("do_info: %d\n", err);
-
-out:
- smb_fh_close(fd);
- return (err);
-}
diff --git a/usr/src/cmd/fs.d/smbclnt/test/tconn.c b/usr/src/cmd/fs.d/smbclnt/test/tconn.c
deleted file mode 100644
index bfeac98fe0..0000000000
--- a/usr/src/cmd/fs.d/smbclnt/test/tconn.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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
- * or http://www.opensolaris.org/os/licensing.
- * 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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
- */
-
-/*
- * Test program for opening an SMB connection directly.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <libintl.h>
-
-#include <netsmb/smb_lib.h>
-
-extern char *optarg;
-extern int optind, opterr, optopt;
-extern int smb_iod_connect(struct smb_ctx *);
-
-static char *server;
-
-static void
-tconn_usage(void)
-{
- printf("usage: tconn [-d domain][-u user][-p passwd] server\n");
- exit(1);
-}
-
-int
-main(int argc, char *argv[])
-{
- int c, error, aflags;
- struct smb_ctx *ctx = NULL;
- char *dom = NULL;
- char *usr = NULL;
- char *pw = NULL;
- char *secopt = NULL;
- struct addrinfo *ai;
-
- while ((c = getopt(argc, argv, "vd:p:s:u:")) != -1) {
- switch (c) {
- case 'v':
- smb_debug = 1;
- smb_verbose = 1;
- break;
-
- case 'd':
- dom = optarg;
- break;
- case 'u':
- usr = optarg;
- break;
- case 'p':
- pw = optarg;
- break;
- case 's':
- secopt = optarg;
- break;
- case '?':
- tconn_usage();
- break;
- }
- }
- if (optind >= argc)
- tconn_usage();
- server = argv[optind];
-
- if (pw != NULL && (dom == NULL || usr == NULL)) {
- fprintf(stderr, "%s: -p arg requires -d dom -u usr\n",
- argv[0]);
- tconn_usage();
- }
-
- /*
- * This section is intended to demonstrate how an
- * RPC client library might use this interface.
- */
- error = smb_ctx_alloc(&ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_alloc failed\n", argv[0]);
- goto out;
- }
-
- /*
- * Set server, share, domain, user
- * (in the ctx handle).
- */
- smb_ctx_setfullserver(ctx, server);
- smb_ctx_setshare(ctx, "IPC$", USE_IPC);
- if (dom)
- smb_ctx_setdomain(ctx, dom, B_TRUE);
- if (usr)
- smb_ctx_setuser(ctx, usr, B_TRUE);
- if (pw)
- smb_ctx_setpassword(ctx, pw, NULL);
-
- /*
- * Hackish option to override the Authentication Type flags.
- * Sorry about exposing the flag values here, but this is
- * really a programmer's test tool. See smbfs_api.h for
- * the SMB_AT_... flag values.
- */
- if (secopt != NULL) {
- aflags = atoi(secopt);
- if (aflags < 1 || aflags > 0x1f) {
- fprintf(stderr, "%s: -s {0..31}\n", argv[0]);
- tconn_usage();
- }
- smb_ctx_setauthflags(ctx, aflags);
- }
-
- /*
- * Resolve the server address,
- * setup derived defaults.
- */
- error = smb_ctx_resolve(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_ctx_resolve failed\n", argv[0]);
- goto out;
- }
-
- if ((ai = ctx->ct_addrinfo) == NULL) {
- fprintf(stderr, "%s: no ct_addrinfo\n", argv[0]);
- goto out;
- }
- memcpy(&ctx->ct_srvaddr, ai->ai_addr, ai->ai_addrlen);
-
- /*
- * If this code were in smbutil or mount_smbfs, it would
- * get system and $HOME/.nsmbrc settings here, like this:
- */
- error = smb_iod_connect(ctx);
- if (error) {
- fprintf(stderr, "%s: smb_iod_connect failed\n", argv[0]);
- goto out;
- }
-
- printf("Yea, we connected!\n");
-
-out:
- smb_ctx_free(ctx);
-
- return ((error) ? 1 : 0);
-}
diff --git a/usr/src/cmd/mdb/Makefile.common b/usr/src/cmd/mdb/Makefile.common
index b1f8835acd..79b49c8ce2 100644
--- a/usr/src/cmd/mdb/Makefile.common
+++ b/usr/src/cmd/mdb/Makefile.common
@@ -22,7 +22,7 @@
#
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
# Copyright 2016 Joyent, Inc.
-# Copyright 2016 Nexenta Systems, Inc.
+# Copyright 2017 Nexenta Systems, Inc.
#
#
@@ -35,6 +35,8 @@ COMMON_MODULES_PROC = \
libavl \
libc \
libcmdutils \
+ libfknsmb \
+ libfksmbfs \
libfksmbsrv \
libnvpair \
libproc \
diff --git a/usr/src/cmd/mdb/Makefile.module b/usr/src/cmd/mdb/Makefile.module
index 5bfdbf8434..7da9b0c586 100644
--- a/usr/src/cmd/mdb/Makefile.module
+++ b/usr/src/cmd/mdb/Makefile.module
@@ -24,6 +24,8 @@
#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright (c) 2018, Joyent, Inc.
+# Copyright (c) 2019 Carlos Neira <cneirabustos@gmail.com>
+# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
#
.KEEP_STATE:
@@ -177,7 +179,7 @@ lint: $$(LINTFILES)
$(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
$(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \
- $(MODOBJS) -o $@ $(LDLIBS) -lc
+ $(MODOBJS) -o $@ $(LDLIBS) -lc -lproc
$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
$(POST_PROCESS_SO)
diff --git a/usr/src/cmd/mdb/common/modules/libc/libc.c b/usr/src/cmd/mdb/common/modules/libc/libc.c
index a075638ddd..b9de1dc936 100644
--- a/usr/src/cmd/mdb/common/modules/libc/libc.c
+++ b/usr/src/cmd/mdb/common/modules/libc/libc.c
@@ -23,6 +23,8 @@
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012 by Delphix. All rights reserved.
* Copyright 2019, Joyent, Inc.
+ * Copyright (c) 2019 Carlos Neira <cneirabustos@gmail.com>
+ * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
*/
#include <sys/mdb_modapi.h>
@@ -36,6 +38,7 @@
#include <string.h>
#include <thr_uberdata.h>
#include "findstack.h"
+#include <libproc.h>
static const char *
stack_flags(const stack_t *sp)
@@ -1200,6 +1203,223 @@ d_errno(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
}
mdb_printf("%d\n", errval);
+
+ return (DCMD_OK);
+}
+
+/*
+ * Print percent from 16-bit binary fraction [0 .. 1]
+ * Round up .01 to .1 to indicate some small percentage (the 0x7000 below).
+ *
+ * Note: This routine was copied from elfdump/common/corenote.c and modified.
+ *
+ */
+static uint_t
+pct_value(ushort_t pct)
+{
+ uint_t value = pct;
+
+ value = ((value * 1000) + 0x7000) >> 15; /* [0 .. 1000] */
+ if (value >= 1000)
+ value = 999;
+
+ return (value);
+}
+
+static void
+psinfo_raw(psinfo_t psinfo)
+{
+ const int minspaces = 2;
+ const int spbcols = 20;
+ char sysname[SYS2STR_MAX];
+ uint_t cpu, mem;
+ char buff[32];
+ int bufflen;
+
+ mdb_printf("[ NT_PRPSINFO ]\n");
+
+ mdb_printf("\tpr_state: %d\t\t\tpr_sname: %c\n",
+ psinfo.pr_lwp.pr_state, psinfo.pr_lwp.pr_sname);
+
+ mdb_printf("\tpr_zomb: %d\t\t\tpr_nice: %d\n",
+ psinfo.pr_nzomb, psinfo.pr_lwp.pr_nice);
+
+ mdb_printf("\tpr_uid: %u\t\t\tpr_gid: %u\n",
+ psinfo.pr_uid, psinfo.pr_gid);
+
+ mdb_snprintf(buff, sizeof (buff),
+ "%d", psinfo.pr_pid);
+
+ bufflen = strlen(buff);
+ mdb_printf("\tpr_pid: %s%*spr_ppid: %d\n",
+ buff, strlen(buff) > spbcols ? minspaces : (spbcols - bufflen), " ",
+ psinfo.pr_ppid);
+
+ mdb_printf("\tpr_pgid: %u\t\t\tpr_sid: %d\n",
+ psinfo.pr_gid, psinfo.pr_sid);
+
+ mdb_snprintf(buff, sizeof (buff),
+ "0x%lx", (ulong_t)psinfo.pr_addr);
+
+ bufflen = strlen(buff);
+
+ mdb_printf("\tpr_addr: %s%*spr_size: %#x\n",
+ buff, strlen(buff) > spbcols ? minspaces : (spbcols - bufflen), " ",
+ (ulong_t)psinfo.pr_size);
+
+ mdb_printf("\tpr_rssize: %#lx\t\tpr_wchan: %#lx\n",
+ (ulong_t)psinfo.pr_rssize, (ulong_t)psinfo.pr_lwp.pr_wchan);
+
+ mdb_printf("\tpr_start:\n\t tv_sec: %ld\t\ttv_nsec: %ld\n",
+ psinfo.pr_start.tv_sec, psinfo.pr_start.tv_nsec);
+
+ mdb_printf("\tpr_time:\n\t tv_sec: %ld\t\t\ttv_nsec: %ld\n",
+ psinfo.pr_time.tv_sec, psinfo.pr_time.tv_nsec);
+
+ mdb_printf("\tpr_pri: %d\t\t\tpr_oldpri: %d\n",
+ psinfo.pr_lwp.pr_pri, psinfo.pr_lwp.pr_oldpri);
+
+ mdb_printf("\tpr_cpu: %d\n", psinfo.pr_lwp.pr_cpu);
+
+ mdb_printf("\tpr_clname: %s\n", psinfo.pr_lwp.pr_clname);
+
+ mdb_printf("\tpr_fname: %s\n", psinfo.pr_fname);
+
+ mdb_printf("\tpr_psargs: %s\n", psinfo.pr_psargs);
+
+
+ mdb_printf("\tpr_syscall: [ %s ]\n",
+ proc_sysname(psinfo.pr_lwp.pr_syscall, sysname,
+ sizeof (sysname)));
+
+ mdb_printf("\tpr_ctime:\n\t tv_sec: %ld\t\t\ttv_nsec: %ld\n",
+ psinfo.pr_ctime.tv_sec, psinfo.pr_ctime.tv_nsec);
+
+ mdb_printf("\tpr_argc: %d\t\t\tpr_argv: 0x%lx\n",
+ psinfo.pr_argc, (ulong_t)psinfo.pr_argv);
+
+ mdb_snprintf(buff, sizeof (buff), "0x%lx", (ulong_t)psinfo.pr_envp);
+
+ bufflen = strlen(buff);
+
+ mdb_printf("\tpr_envp: %s%*spr_wstat: %d\n",
+ buff, strlen(buff) > spbcols ? minspaces : (spbcols - bufflen), " ",
+ psinfo.pr_wstat);
+
+ cpu = pct_value(psinfo.pr_pctcpu);
+ mem = pct_value(psinfo.pr_pctmem);
+
+ mdb_printf("\tpr_pctcpu: %u.%u%%\t\tpr_pctmem: %u.%u%%\n",
+ cpu / 10, cpu % 10, mem / 10, mem % 10);
+
+ mdb_printf("\tpr_euid: %u\t\t\tpr_egid: %u\n",
+ psinfo.pr_euid, psinfo.pr_egid);
+
+ mdb_printf("\tpr_dmodel: [%s]\n",
+ proc_dmodelname(psinfo.pr_dmodel, buff, sizeof (buff)));
+}
+
+static void
+psinfo_sum(psinfo_t psinfo)
+{
+ const int minspaces = 2;
+ const int spbcols = 23;
+ char buff[64];
+ int bufflen;
+ int ms;
+
+ mdb_printf("PID: %6d (process id)\t\t"
+ "UID: %4u (real user id)\n",
+ psinfo.pr_pid, psinfo.pr_uid);
+
+ mdb_printf("PPID: %6d (parent process id)\tEUID: %4d"
+ " (effective user id)\n", psinfo.pr_ppid, psinfo.pr_euid);
+
+ mdb_printf("PGID: %6d (process group id)\tGID: %4u"
+ " (real group id)\n", psinfo.pr_pgid, psinfo.pr_gid);
+
+ mdb_printf("SID: %6d (session id)\t\tEGID: %4u"
+ " (effective group id)\n",
+ psinfo.pr_sid, psinfo.pr_egid);
+
+ mdb_printf("ZONEID: %6d\t\t\t\tCONTRACT:%4d\n",
+ psinfo.pr_zoneid, psinfo.pr_contract);
+
+ mdb_printf("PROJECT:%6d \t\t\t\tTASK: %4d\n\n",
+ psinfo.pr_projid, psinfo.pr_taskid);
+
+ mdb_printf("START: %Y (wall timestamp when the process started)\n",
+ psinfo.pr_start);
+
+ ms = NSEC2MSEC(psinfo.pr_time.tv_nsec);
+
+ mdb_snprintf(buff, sizeof (buff), "%ld.%d seconds",
+ psinfo.pr_time.tv_sec, ms);
+
+ bufflen = strlen(buff);
+
+ mdb_printf("TIME: %s%*s"
+ "(CPU time used by this process)\n",
+ buff, bufflen > spbcols ? minspaces : (spbcols - bufflen), " ");
+
+ ms = NSEC2MSEC(psinfo.pr_ctime.tv_nsec);
+
+ mdb_snprintf(buff, sizeof (buff), "%ld.%d seconds",
+ psinfo.pr_ctime.tv_sec, ms);
+
+ mdb_printf("CTIME: %s%*s"
+ "(CPU time used by child processes)\n",
+ buff, bufflen > spbcols ? minspaces : (spbcols - bufflen), " ");
+
+ mdb_snprintf(buff, sizeof (buff), "%s", psinfo.pr_fname);
+ bufflen = strlen(buff);
+
+ mdb_printf("FNAME: %s%*s(name of the program executed)\n",
+ buff, bufflen > spbcols ? minspaces : (spbcols - bufflen), " ");
+
+ mdb_printf("PSARGS: \"%s\"\n", psinfo.pr_psargs);
+}
+
+void
+d_psinfo_dcmd_help(void)
+{
+ mdb_printf(
+ "Prints relevant fields from psinfo_t data and\n"
+ "most fields from NT_PRPSINFO note section\n\n"
+ "Usage: ::psinfo [-v]\n"
+ "Options:\n"
+ " -v verbose output\n");
+}
+
+static int
+d_psinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
+{
+ psinfo_t psinfo;
+ uint_t opt_v = FALSE;
+ ssize_t nbytes;
+
+ if (mdb_getopts(argc, argv, 'v',
+ MDB_OPT_SETBITS, TRUE, &opt_v, NULL) != argc)
+ return (DCMD_USAGE);
+
+ nbytes = mdb_get_xdata("psinfo", NULL, 0);
+
+ if (nbytes <= 0) {
+ mdb_warn("information not available for analysis");
+ return (DCMD_ERR);
+ }
+
+ if (mdb_get_xdata("psinfo", &psinfo, nbytes) != nbytes) {
+ mdb_warn("failed to read psinfo information");
+ return (DCMD_ERR);
+ }
+
+ if (opt_v) {
+ psinfo_raw(psinfo);
+ } else {
+ psinfo_sum(psinfo);
+ }
+
return (DCMD_OK);
}
@@ -1215,6 +1435,8 @@ static const mdb_dcmd_t dcmds[] = {
{ "ulwp", ":", "print ulwp_t structure", d_ulwp, NULL },
{ "uberdata", ":", "print uberdata_t structure", d_uberdata, NULL },
{ "tsd", ":-k key", "print tsd for this thread", d_tsd, NULL },
+ { "psinfo", "[-v]", "prints relevant psinfo_t data", d_psinfo,
+ d_psinfo_dcmd_help },
{ NULL }
};
diff --git a/usr/src/cmd/mdb/common/modules/nsmb/nsmb.c b/usr/src/cmd/mdb/common/modules/nsmb/nsmb.c
index 3b350a19ba..24e690f98a 100644
--- a/usr/src/cmd/mdb/common/modules/nsmb/nsmb.c
+++ b/usr/src/cmd/mdb/common/modules/nsmb/nsmb.c
@@ -20,9 +20,10 @@
*/
/*
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/
@@ -35,6 +36,12 @@
#include <netsmb/smb_rq.h>
#include <netsmb/smb_pass.h>
+#ifdef _KERNEL
+#define NSMB_OBJNAME "nsmb"
+#else
+#define NSMB_OBJNAME "libfknsmb.so.1"
+#endif
+
#define OPT_VERBOSE 0x0001 /* Be [-v]erbose in dcmd's */
#define OPT_RECURSE 0x0002 /* recursive display */
@@ -66,12 +73,13 @@ print_str(uintptr_t addr)
*/
typedef struct smb_co_walk_data {
uintptr_t pp;
- int level; /* SMBL_SM, SMBL_VC, SMBL_SHARE */
+ int level; /* SMBL_SM, SMBL_VC, SMBL_SHARE, ... */
int size; /* sizeof (union member) */
union co_u {
smb_connobj_t co; /* copy of the list element */
smb_vc_t vc;
smb_share_t ss;
+ smb_fh_t fh;
} u;
} smb_co_walk_data_t;
@@ -108,6 +116,9 @@ smb_co_walk_init(mdb_walk_state_t *wsp, int level)
case SMBL_SHARE:
smbw->size = sizeof (smbw->u.ss);
break;
+ case SMBL_FH:
+ smbw->size = sizeof (smbw->u.fh);
+ break;
default:
smbw->size = sizeof (smbw->u);
break;
@@ -146,7 +157,7 @@ smb_vc_walk_init(mdb_walk_state_t *wsp)
}
/* Locate the VC list head. */
- if (mdb_lookup_by_obj("nsmb", "smb_vclist", &sym)) {
+ if (mdb_lookup_by_obj(NSMB_OBJNAME, "smb_vclist", &sym)) {
mdb_warn("failed to lookup `smb_vclist'\n");
return (WALK_ERR);
}
@@ -174,6 +185,24 @@ smb_ss_walk_init(mdb_walk_state_t *wsp)
}
/*
+ * Walk the file hande list below some share.
+ */
+int
+smb_fh_walk_init(mdb_walk_state_t *wsp)
+{
+
+ /*
+ * Initial walk_addr is address of parent (share)
+ */
+ if (wsp->walk_addr == 0) {
+ mdb_warn("::walk smb_fh does not support global walks\n");
+ return (WALK_ERR);
+ }
+
+ return (smb_co_walk_init(wsp, SMBL_FH));
+}
+
+/*
* Common walk_step for walking structs inherited
* from smb_connobj_t (smb_vc_t, smb_share_t)
*/
@@ -215,6 +244,30 @@ typedef struct smb_co_cbdata {
} smb_co_cbdata_t;
/*
+ * Call-back function for walking a file handle list.
+ */
+/* ARGSUSED */
+int
+smb_fh_cb(uintptr_t addr, const void *data, void *arg)
+{
+ const smb_fh_t *fhp = data;
+ // smb_co_cbdata_t *cbd = arg;
+
+ mdb_inc_indent(2);
+ mdb_printf(" %-p", addr);
+ if (fhp->fh_fid2.fid_volatile != 0) {
+ mdb_printf("\t0x%llx\n",
+ (long long) fhp->fh_fid2.fid_volatile);
+ } else {
+ mdb_printf("\t0x%x\n", fhp->fh_fid1);
+ }
+
+ mdb_dec_indent(2);
+
+ return (WALK_NEXT);
+}
+
+/*
* Call-back function for walking a share list.
*/
int
@@ -222,12 +275,20 @@ smb_ss_cb(uintptr_t addr, const void *data, void *arg)
{
const smb_share_t *ssp = data;
smb_co_cbdata_t *cbd = arg;
+ uint32_t tid;
- mdb_printf(" %-p\t%s\n", addr, ssp->ss_name);
+ tid = ssp->ss2_tree_id;
+ if (tid == 0)
+ tid = ssp->ss_tid;
- if (cbd->flags & OPT_VERBOSE) {
+ mdb_printf(" %-p\t0x%x\t%s\n", addr, tid, ssp->ss_name);
+
+ if (cbd->flags & OPT_RECURSE) {
mdb_inc_indent(2);
- /* Anything wanted here? */
+ if (mdb_pwalk("nsmb_fh", smb_fh_cb, cbd, addr) < 0) {
+ mdb_warn("failed to walk 'nsmb_fh'");
+ /* Don't: return (WALK_ERR); */
+ }
mdb_dec_indent(2);
}
@@ -408,6 +469,7 @@ rqlist_walk_step(mdb_walk_state_t *wsp)
typedef struct rqlist_cbdata {
int printed_header;
+ int vcflags;
uintptr_t uid; /* optional filtering by UID */
} rqlist_cbdata_t;
@@ -423,8 +485,13 @@ rqlist_cb(uintptr_t addr, const void *data, void *arg)
}
mdb_printf(" %-p", addr); /* smb_rq_t */
- mdb_printf(" x%04x", rq->sr_mid);
- mdb_printf(" x%02x", rq->sr_cmd);
+ if ((cbd->vcflags & SMBV_SMB2) != 0) {
+ mdb_printf(" x%04llx", (long long)rq->sr2_messageid);
+ mdb_printf(" x%02x", rq->sr2_command);
+ } else {
+ mdb_printf(" x%04x", rq->sr_mid);
+ mdb_printf(" x%02x", rq->sr_cmd);
+ }
mdb_printf(" %d", rq->sr_state);
mdb_printf(" x%x", rq->sr_flags);
mdb_printf("\n");
@@ -437,9 +504,20 @@ int
rqlist_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
{
rqlist_cbdata_t cbd;
+ smb_vc_t *vcp;
+ size_t vcsz;
memset(&cbd, 0, sizeof (cbd));
+ /* Need the VC again to get */
+ vcsz = sizeof (*vcp);
+ vcp = mdb_alloc(vcsz, UM_SLEEP | UM_GC);
+ if (mdb_vread(vcp, vcsz, addr) != vcsz) {
+ mdb_warn("cannot read VC from %p", addr);
+ return (DCMD_ERR);
+ }
+ cbd.vcflags = vcp->vc_flags;
+
/*
* Initial walk_addr is address of parent (VC)
*/
@@ -471,7 +549,7 @@ pwtree_walk_init(mdb_walk_state_t *wsp)
return (WALK_ERR);
}
- if (mdb_lookup_by_obj("nsmb", "smb_ptd", &sym) == -1) {
+ if (mdb_lookup_by_obj(NSMB_OBJNAME, "smb_ptd", &sym) == -1) {
mdb_warn("failed to find symbol 'smb_ptd'");
return (WALK_ERR);
}
@@ -600,6 +678,8 @@ static const mdb_walker_t walkers[] = {
smb_vc_walk_init, smb_co_walk_step, NULL },
{ "nsmb_ss", "walk nsmb share list for some VC",
smb_ss_walk_init, smb_co_walk_step, NULL },
+ { "nsmb_fh", "walk nsmb share list for some VC",
+ smb_fh_walk_init, smb_co_walk_step, NULL },
{ "nsmb_rqlist", "walk request list for some VC",
rqlist_walk_init, rqlist_walk_step, NULL },
{ "nsmb_pwtree", "walk passord AVL tree",
diff --git a/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c b/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c
index 6be9e2a0c4..e787fd86e5 100644
--- a/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c
+++ b/usr/src/cmd/mdb/common/modules/smbfs/smbfs.c
@@ -20,13 +20,19 @@
*/
/*
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
-#include <sys/mdb_modapi.h>
#include <sys/types.h>
+#include <sys/mdb_modapi.h>
+
+#ifdef _USER
+#include "../genunix/avl.h"
+#define _FAKE_KERNEL
+#endif
+
#include <sys/refstr_impl.h>
#include <sys/vnode.h>
#include <sys/vfs.h>
@@ -149,7 +155,7 @@ smbfs_vfs_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
}
if (!(flags & DCMD_ADDRSPEC)) {
- if (mdb_walk("genunix`vfs", smbfs_vfs_cb, cbd)
+ if (mdb_walk("vfs", smbfs_vfs_cb, cbd)
== -1) {
mdb_warn("can't walk smbfs vfs");
return (DCMD_ERR);
@@ -238,7 +244,7 @@ smbfs_node_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
}
addr += OFFSETOF(smbmntinfo_t, smi_hash_avl);
- if (mdb_pwalk("genunix`avl", smbfs_node_cb, cbd, addr) == -1) {
+ if (mdb_pwalk("avl", smbfs_node_cb, cbd, addr) == -1) {
mdb_warn("cannot walk smbfs nodes");
return (DCMD_ERR);
}
@@ -267,10 +273,59 @@ static const mdb_dcmd_t dcmds[] = {
{NULL}
};
+#ifdef _USER
+/*
+ * Sadly, can't just compile ../genunix/vfs.c with this since
+ * it has become a catch-all for FS-specific headers etc.
+ */
+int
+vfs_walk_init(mdb_walk_state_t *wsp)
+{
+ if (wsp->walk_addr == NULL &&
+ mdb_readvar(&wsp->walk_addr, "rootvfs") == -1) {
+ mdb_warn("failed to read 'rootvfs'");
+ return (WALK_ERR);
+ }
+
+ wsp->walk_data = (void *)wsp->walk_addr;
+ return (WALK_NEXT);
+}
+
+int
+vfs_walk_step(mdb_walk_state_t *wsp)
+{
+ vfs_t vfs;
+ int status;
+
+ if (mdb_vread(&vfs, sizeof (vfs), wsp->walk_addr) == -1) {
+ mdb_warn("failed to read vfs_t at %p", wsp->walk_addr);
+ return (WALK_DONE);
+ }
+
+ status = wsp->walk_callback(wsp->walk_addr, &vfs, wsp->walk_cbdata);
+
+ if (vfs.vfs_next == wsp->walk_data)
+ return (WALK_DONE);
+
+ wsp->walk_addr = (uintptr_t)vfs.vfs_next;
+
+ return (status);
+}
+#endif // _USER
+
static const mdb_walker_t walkers[] = {
+#ifdef _USER
+ /* from avl.c */
+ { AVL_WALK_NAME, AVL_WALK_DESC,
+ avl_walk_init, avl_walk_step, avl_walk_fini },
+ /* from vfs.c */
+ { "vfs", "walk file system list",
+ vfs_walk_init, vfs_walk_step },
+#endif // _USER
{NULL}
};
+
static const mdb_modinfo_t modinfo = {
MDB_API_VERSION,
dcmds,
diff --git a/usr/src/cmd/mdb/intel/amd64/libfknsmb/Makefile b/usr/src/cmd/mdb/intel/amd64/libfknsmb/Makefile
new file mode 100644
index 0000000000..e6c6109a50
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/amd64/libfknsmb/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (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
+# or http://www.opensolaris.org/os/licensing.
+# 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 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libfknsmb.so
+MDBTGT = proc
+
+MODSRCS = nsmb.c
+
+include ../../../../Makefile.cmd
+include ../../../../Makefile.cmd.64
+include ../../Makefile.amd64
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/nsmb
+
+# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+CPPFLAGS.first += -I$(SRC)/lib/smbclnt/libfknsmb/common
+CPPFLAGS.first += -I$(SRC)/lib/libfakekernel/common
+
+CPPFLAGS += -I$(SRC)/uts/common/fs/smbclnt/
+CPPFLAGS += -I$(SRC)/uts/common
+CPPFLAGS += -D_FAKE_KERNEL
+
+CSTD= $(CSTD_GNU99)
diff --git a/usr/src/cmd/mdb/intel/amd64/libfksmbfs/Makefile b/usr/src/cmd/mdb/intel/amd64/libfksmbfs/Makefile
new file mode 100644
index 0000000000..51b6d01c6d
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/amd64/libfksmbfs/Makefile
@@ -0,0 +1,56 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (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
+# or http://www.opensolaris.org/os/licensing.
+# 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 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libfksmbfs.so
+MDBTGT = proc
+
+MODSRCS = smbfs.c avl.c
+
+include ../../../../Makefile.cmd
+include ../../../../Makefile.cmd.64
+include ../../Makefile.amd64
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/smbfs
+GENUNIX_DIR = ../../../common/modules/genunix
+
+# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+CPPFLAGS.first += -I$(SRC)/lib/smbsrv/libfksmbsrv/common
+CPPFLAGS.first += -I$(SRC)/lib/libfakekernel/common
+
+CPPFLAGS += -I$(SRC)/uts/common/fs/smbclnt/
+CPPFLAGS += -I$(SRC)/uts/common
+
+CSTD= $(CSTD_GNU99)
+
+dmod/%.o: $(GENUNIX_DIR)/%.c
+ $(COMPILE.c) -o $@ $<
+ $(CTFCONVERT_O)
+
+dmod/%.ln: $(GENUNIX_DIR)/%.c
+ $(LINT.c) -c $<
diff --git a/usr/src/cmd/mdb/intel/ia32/libfknsmb/Makefile b/usr/src/cmd/mdb/intel/ia32/libfknsmb/Makefile
new file mode 100644
index 0000000000..c50ac1c69d
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/ia32/libfknsmb/Makefile
@@ -0,0 +1,48 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (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
+# or http://www.opensolaris.org/os/licensing.
+# 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 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libfknsmb.so
+MDBTGT = proc
+
+MODSRCS = nsmb.c
+
+include ../../../../Makefile.cmd
+include ../../Makefile.ia32
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/nsmb
+
+# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+CPPFLAGS.first += -I$(SRC)/lib/smbclnt/libfknsmb/common
+CPPFLAGS.first += -I$(SRC)/lib/libfakekernel/common
+
+CPPFLAGS += -I$(SRC)/uts/common/fs/smbclnt/
+CPPFLAGS += -I$(SRC)/uts/common
+CPPFLAGS += -D_FAKE_KERNEL
+
+CSTD= $(CSTD_GNU99)
diff --git a/usr/src/cmd/mdb/intel/ia32/libfksmbfs/Makefile b/usr/src/cmd/mdb/intel/ia32/libfksmbfs/Makefile
new file mode 100644
index 0000000000..892908da7a
--- /dev/null
+++ b/usr/src/cmd/mdb/intel/ia32/libfksmbfs/Makefile
@@ -0,0 +1,55 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (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
+# or http://www.opensolaris.org/os/licensing.
+# 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 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# Copyright 2017 Nexenta Systems, Inc. All rights reserved.
+#
+
+MODULE = libfksmbfs.so
+MDBTGT = proc
+
+MODSRCS = smbfs.c avl.c
+
+include ../../../../Makefile.cmd
+include ../../Makefile.ia32
+include ../../../Makefile.module
+
+MODSRCS_DIR = ../../../common/modules/smbfs
+GENUNIX_DIR = ../../../common/modules/genunix
+
+# Note: need our sys includes _before_ ENVCPPFLAGS, proto etc.
+CPPFLAGS.first += -I$(SRC)/lib/smbsrv/libfksmbsrv/common
+CPPFLAGS.first += -I$(SRC)/lib/libfakekernel/common
+
+CPPFLAGS += -I$(SRC)/uts/common/fs/smbclnt/
+CPPFLAGS += -I$(SRC)/uts/common
+
+CSTD= $(CSTD_GNU99)
+
+dmod/%.o: $(GENUNIX_DIR)/%.c
+ $(COMPILE.c) -o $@ $<
+ $(CTFCONVERT_O)
+
+dmod/%.ln: $(GENUNIX_DIR)/%.c
+ $(LINT.c) -c $<