Print this page
NEX-16824 SMB client connection setup rework
NEX-17232 SMB client reconnect failures
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (improve debug)
NEX-16805 Add smbutil discon command
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
3328 smbutil view does't work with Win2008 and later
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
@@ -32,10 +32,11 @@
* $Id: view.c,v 1.9 2004/12/13 00:25:39 lindak Exp $
*/
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
@@ -46,17 +47,12 @@
#include <sysexits.h>
#include <libintl.h>
#include <netsmb/smb.h>
#include <netsmb/smb_lib.h>
-#include <netsmb/smb_netshareenum.h>
-
#include "common.h"
-int enum_shares(smb_ctx_t *);
-void print_shares(int, int, struct share_info *);
-
void
view_usage(void)
{
printf(gettext("usage: smbutil view [connection options] //"
"[workgroup;][user[:password]@]server\n"));
@@ -77,22 +73,22 @@
return (error);
error = smb_ctx_scan_argv(ctx, argc, argv,
SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
if (error)
- return (error);
+ goto out;
error = smb_ctx_readrc(ctx);
if (error)
- return (error);
+ goto out;
while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
if (opt == '?')
view_usage();
error = smb_ctx_opt(ctx, opt, optarg);
if (error)
- return (error);
+ goto out;
}
smb_ctx_setshare(ctx, "IPC$", USE_IPC);
/*
@@ -99,11 +95,11 @@
* Resolve the server address,
* setup derived defaults.
*/
error = smb_ctx_resolve(ctx);
if (error)
- return (error);
+ goto out;
/*
* Have server, share, etc. from above:
* smb_ctx_scan_argv, option settings.
* Get the session and tree.
@@ -116,30 +112,28 @@
goto again;
}
if (error) {
smb_error(gettext("//%s: login failed"),
error, ctx->ct_fullserver);
- return (error);
+ goto out;
}
error = smb_ctx_get_tree(ctx);
if (error) {
smb_error(gettext("//%s/%s: tree connect failed"),
error, ctx->ct_fullserver, ctx->ct_origshare);
- return (error);
+ goto out;
}
/*
* Have IPC$ tcon, now list shares.
- * This prints its own errors.
*/
- error = enum_shares(ctx);
- if (error)
- return (error);
+ error = share_enum_rpc(ctx, ctx->ct_fullserver);
+out:
smb_ctx_free(ctx);
- return (0);
+ return (error);
}
#ifdef I18N /* not defined, put here so xgettext(1) can find strings */
static char *shtype[] = {
gettext("disk"),
@@ -156,50 +150,31 @@
"IPC", /* IPC Inter process communication */
"unknown"
};
#endif
-int
-enum_shares(smb_ctx_t *ctx)
-{
- struct share_info *share_info;
- int error, entries, total;
-
- /*
- * XXX: Later, try RPC first,
- * then fall back to RAP...
+/*
+ * Print one line of the share list, or
+ * if SHARE is null, print the header line.
*/
- error = smb_netshareenum(ctx, &entries, &total, &share_info);
- if (error) {
- smb_error(gettext("//%s failed to list shares"),
- error, ctx->ct_fullserver);
- return (error);
- }
- print_shares(entries, total, share_info);
- return (0);
-}
-
void
-print_shares(int entries, int total,
- struct share_info *share_info)
+view_print_share(char *share, int type, char *comment)
{
- struct share_info *ep;
- int i;
+ char *stname;
+ int stindex;
+ if (share == NULL) {
printf(gettext("Share Type Comment\n"));
printf("-------------------------------\n");
-
- for (ep = share_info, i = 0; i < entries; i++, ep++) {
- int sti = ep->type & STYPE_MASK;
- if (sti > STYPE_UNKNOWN)
- sti = STYPE_UNKNOWN;
- printf("%-12s %-10s %s\n", ep->netname,
- gettext(shtype[sti]),
- ep->remark ? ep->remark : "");
- free(ep->netname);
- free(ep->remark);
+ return;
}
- printf(gettext("\n%d shares listed from %d available\n"),
- entries, total);
- free(share_info);
+ stindex = type & STYPE_MASK;
+ if (stindex > STYPE_UNKNOWN)
+ stindex = STYPE_UNKNOWN;
+ stname = gettext(shtype[stindex]);
+
+ if (comment == NULL)
+ comment = "";
+
+ printf("%-12s %-10s %s\n", share, stname, comment);
}