9472 Add smbutil discon command
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Reviewed by: Ken Mays <kmays2000@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
diff --git a/usr/src/cmd/fs.d/smbclnt/smbiod-svc/smbiod-svc.c b/usr/src/cmd/fs.d/smbclnt/smbiod-svc/smbiod-svc.c
index d99e04b..23c0e4d 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbiod-svc/smbiod-svc.c
+++ b/usr/src/cmd/fs.d/smbclnt/smbiod-svc/smbiod-svc.c
@@ -560,14 +560,14 @@
x = WEXITSTATUS(status);
if (x != 0) {
fprintf(stderr,
- "uid %d, pid %d exit %d",
+ "uid %d, pid %d exit %d\n",
uid, (int)pid, x);
}
}
if (WIFSIGNALED(status)) {
x = WTERMSIG(status);
fprintf(stderr,
- "uid %d, pid %d signal %d",
+ "uid %d, pid %d signal %d\n",
uid, (int)pid, x);
}
}
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile b/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
index e20054c..f15dcc8 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/Makefile
@@ -32,7 +32,7 @@
PROG= smbutil
-OBJS= smbutil.o info.o login.o lookup.o print.o status.o view.o \
+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
SRCS= $(OBJS:%.o=%.c)
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/common.h b/usr/src/cmd/fs.d/smbclnt/smbutil/common.h
index aea093c..74a8011 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/common.h
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/common.h
@@ -45,6 +45,7 @@
#include <stdlib.h>
int cmd_crypt(int argc, char *argv[]);
+int cmd_discon(int argc, char *argv[]);
int cmd_help(int argc, char *argv[]);
int cmd_info(int argc, char *argv[]);
int cmd_login(int argc, char *argv[]);
@@ -56,6 +57,7 @@
int cmd_view(int argc, char *argv[]);
void crypt_usage(void);
+void discon_usage(void);
void help_usage(void);
void info_usage(void);
void login_usage(void);
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/discon.c b/usr/src/cmd/fs.d/smbclnt/smbutil/discon.c
new file mode 100644
index 0000000..84b94a03
--- /dev/null
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/discon.c
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+/*
+ * smbutil "discon" sub-command to disconnect a session
+ * (mostly for usr/src/test/smbclient-tests)
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <stdio.h>
+#include <err.h>
+#include <unistd.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <sysexits.h>
+#include <libintl.h>
+
+#include <netsmb/smb.h>
+#include <netsmb/smb_lib.h>
+#include "common.h"
+
+void
+discon_usage(void)
+{
+ printf(gettext("usage: smbutil discon [connection options] "
+ "//[workgroup;][user@]server\n"));
+ exit(1);
+}
+
+int
+cmd_discon(int argc, char *argv[])
+{
+ struct smb_ctx *ctx;
+ int error, opt;
+
+ if (argc < 2)
+ discon_usage();
+
+ error = smb_ctx_alloc(&ctx);
+ if (error != 0)
+ return (error);
+
+ error = smb_ctx_scan_argv(ctx, argc, argv,
+ SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
+ if (error != 0)
+ goto out;
+
+ error = smb_ctx_readrc(ctx);
+ if (error != 0)
+ goto out;
+
+ while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
+ if (opt == '?')
+ discon_usage();
+ error = smb_ctx_opt(ctx, opt, optarg);
+ if (error != 0)
+ goto out;
+ }
+
+ /*
+ * Resolve the server address,
+ * setup derived defaults.
+ */
+ error = smb_ctx_resolve(ctx);
+ if (error != 0)
+ goto out;
+
+ /*
+ * Have server, user, etc. from above:
+ * smb_ctx_scan_argv, option settings.
+ *
+ * Lookup a session without creating.
+ * (First part of smb_ctx_get_ssn)
+ * If we find the session, kill it.
+ */
+ error = smb_ctx_findvc(ctx);
+ if (error == ENOENT) {
+ /* Already gone. We're done. */
+ if (smb_debug)
+ fprintf(stderr, "session not found\n");
+ error = 0;
+ goto out;
+ }
+ if (error == 0) {
+ /* Found session. Kill it. */
+ error = smb_ctx_kill(ctx);
+ }
+
+ if (error != 0) {
+ smb_error(gettext("//%s: discon failed"),
+ error, ctx->ct_fullserver);
+ }
+
+out:
+ smb_ctx_free(ctx);
+ return (error);
+}
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c b/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
index 9b09b87..aa10f99 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
@@ -70,6 +70,7 @@
int flags;
} commands[] = {
{"crypt", cmd_crypt, NULL, CMDFL_NO_KMOD},
+ {"discon", cmd_discon, discon_usage, 0},
{"help", cmd_help, help_usage, CMDFL_NO_KMOD},
{"info", cmd_info, info_usage, 0},
{"login", cmd_login, login_usage, 0},
@@ -184,7 +185,8 @@
}
static void
-help(void) {
+help(void)
+{
printf("\n");
printf(gettext("usage: %s [-hv] subcommand [args]\n"), __progname);
printf(gettext("where subcommands are:\n"
@@ -204,7 +206,8 @@
}
void
-help_usage(void) {
+help_usage(void)
+{
printf(gettext("usage: smbutil help command\n"));
exit(1);
}
diff --git a/usr/src/cmd/fs.d/smbclnt/smbutil/view.c b/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
index 8622fb1..bf3397c 100644
--- a/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
+++ b/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
@@ -146,7 +146,7 @@
out:
smb_ctx_free(ctx);
- return (0);
+ return (error);
}
#ifdef I18N /* not defined, put here so xgettext(1) can find strings */
diff --git a/usr/src/lib/libsmbfs/smb/ctx.c b/usr/src/lib/libsmbfs/smb/ctx.c
index e68213b..9455a92 100644
--- a/usr/src/lib/libsmbfs/smb/ctx.c
+++ b/usr/src/lib/libsmbfs/smb/ctx.c
@@ -910,7 +910,7 @@
{ "ntlm", SMB_AT_NTLM1 },
{ "ntlm2", SMB_AT_NTLM2 },
{ "krb5", SMB_AT_KRB5 },
- { NULL, 0 },
+ { NULL, 0 },
};
int
smb_parse_secopts(struct smb_ctx *ctx, const char *arg)
@@ -1212,11 +1212,6 @@
if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
return (EINVAL);
- if (ctx->ct_dev_fd < 0) {
- if ((err = smb_ctx_gethandle(ctx)))
- return (err);
- }
-
/*
* Check whether the driver already has a VC
* we can use. If so, we're done!
diff --git a/usr/src/lib/libsmbfs/smb/findvc.c b/usr/src/lib/libsmbfs/smb/findvc.c
index cfe2cad..63c6cce 100644
--- a/usr/src/lib/libsmbfs/smb/findvc.c
+++ b/usr/src/lib/libsmbfs/smb/findvc.c
@@ -96,6 +96,11 @@
if ((ctx->ct_flags & SMBCF_RESOLVED) == 0)
return (EINVAL);
+ if (ctx->ct_dev_fd < 0) {
+ if ((err = smb_ctx_gethandle(ctx)))
+ return (err);
+ }
+
for (ai = ctx->ct_addrinfo; ai; ai = ai->ai_next) {
switch (ai->ai_family) {
diff --git a/usr/src/lib/libsmbfs/smb/mapfile-vers b/usr/src/lib/libsmbfs/smb/mapfile-vers
index 68b38f4..8f0c390 100644
--- a/usr/src/lib/libsmbfs/smb/mapfile-vers
+++ b/usr/src/lib/libsmbfs/smb/mapfile-vers
@@ -64,6 +64,7 @@
smb_ctx_alloc;
smb_ctx_done;
+ smb_ctx_findvc;
smb_ctx_flags2;
smb_ctx_free;
smb_ctx_get_ssn;
diff --git a/usr/src/man/man1/smbutil.1 b/usr/src/man/man1/smbutil.1
index ad3cc6d..06a77c5 100644
--- a/usr/src/man/man1/smbutil.1
+++ b/usr/src/man/man1/smbutil.1
@@ -1,12 +1,13 @@
'\" te
.\" Copyright (c) 2009, Sun Microsystems, Inc. All Right Reserved.
+.\" Copyright 2018 Nexenta Systems, Inc. All rights reserved.
.\" Portions Copyright 1994-2008 The FreeBSD Project. 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. THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``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 FREEBSD PROJECT 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.
-.TH SMBUTIL 1 "Jun 24, 2009"
+.TH SMBUTIL 1 "Apr 11, 2018"
.SH NAME
smbutil \- Solaris CIFS client utility
.SH SYNOPSIS
@@ -17,6 +18,11 @@
.LP
.nf
+\fB/usr/bin/smbutil discon //[\fIdomain\fR;][\fIuser\fR@]\fIserver\fR\fR
+.fi
+
+.LP
+.nf
\fB/usr/bin/smbutil login [-c] [[\fIdomain\fR/]\fIuser\fR]\fR
.fi
@@ -66,12 +72,10 @@
.fi
.SH DESCRIPTION
-.sp
.LP
The \fBsmbutil\fR command controls the Solaris CIFS client and issues various
commands.
.SS "Subcommands"
-.sp
.LP
The \fBsmbutil\fR command supports the following subcommands:
.sp
@@ -97,6 +101,19 @@
.sp
.ne 2
.na
+\fB\fBdiscon -U \fIuser\fR]
+//[\fIdomain\fR;][\fIuser\fR\fIserver\fR\fR\fR
+.ad
+.sp .6
+.RS 4n
+Disconnects the specified SMB session to \fIserver\fR.
+Usage is similar to the \fB\fBview\fR\fR subcommand.
+This subcommand is primarily for use in tests.
+.RE
+
+.sp
+.ne 2
+.na
\fB\fBlogin [-c] [ [[\fIdomain\fR/]\fIuser\fR] | [\fIuser\fR[@\fIdomain\fR]
]\fR\fR
.ad
@@ -202,7 +219,6 @@
.RE
.SH OPTIONS
-.sp
.LP
The following global options are supported:
.sp
@@ -408,7 +424,6 @@
.sp
.SH FILES
-.sp
.ne 2
.na
\fB\fB$HOME/.nsmbrc\fR\fR
@@ -420,7 +435,6 @@
.RE
.SH ATTRIBUTES
-.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
@@ -439,16 +453,13 @@
.LP
The output is Uncommitted. The rest of the interface is Committed.
.SH SEE ALSO
-.sp
.LP
\fBmount_smbfs\fR(1M), \fBnsmbrc\fR(4), \fBattributes\fR(5), \fBsmbfs\fR(7FS)
.SH AUTHORS
-.sp
.LP
This manual page contains material originally authored by Boris Popov,
\fBbp@butya.kz\fR, \fBbp@FreeBSD.org\fR.
.SH NOTES
-.sp
.LP
The Solaris CIFS client always attempts to use \fBgethostbyname()\fR to resolve
host names. If the host name cannot be resolved, the CIFS client uses NetBIOS
diff --git a/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c b/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
index 353ecad..db82fa0 100644
--- a/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
+++ b/usr/src/uts/common/fs/smbclnt/netsmb/smb_iod.c
@@ -177,18 +177,6 @@
* the server will take care of the logoff.
*/
SMB_TRAN_DISCONNECT(vcp);
-
- /*
- * If we have an IOD, it should immediately notice
- * that its connection has closed. But in case
- * it doesn't, let's also send it a signal.
- */
- SMB_VC_LOCK(vcp);
- if (vcp->iod_thr != NULL &&
- vcp->iod_thr != curthread) {
- tsignal(vcp->iod_thr, SIGKILL);
- }
- SMB_VC_UNLOCK(vcp);
}
/*