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,41 **** --- 32,42 ---- * $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,62 **** #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")); --- 47,58 ----
*** 77,98 **** return (error); error = smb_ctx_scan_argv(ctx, argc, argv, SMBL_SERVER, SMBL_SERVER, USE_WILDCARD); if (error) ! return (error); error = smb_ctx_readrc(ctx); if (error) ! return (error); while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) { if (opt == '?') view_usage(); error = smb_ctx_opt(ctx, opt, optarg); if (error) ! return (error); } smb_ctx_setshare(ctx, "IPC$", USE_IPC); /* --- 73,94 ---- return (error); error = smb_ctx_scan_argv(ctx, argc, argv, SMBL_SERVER, SMBL_SERVER, USE_WILDCARD); if (error) ! goto out; error = smb_ctx_readrc(ctx); if (error) ! goto out; while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) { if (opt == '?') view_usage(); error = smb_ctx_opt(ctx, opt, optarg); if (error) ! goto out; } smb_ctx_setshare(ctx, "IPC$", USE_IPC); /*
*** 99,109 **** * Resolve the server address, * setup derived defaults. */ error = smb_ctx_resolve(ctx); if (error) ! return (error); /* * Have server, share, etc. from above: * smb_ctx_scan_argv, option settings. * Get the session and tree. --- 95,105 ---- * Resolve the server address, * setup derived defaults. */ error = smb_ctx_resolve(ctx); if (error) ! goto out; /* * Have server, share, etc. from above: * smb_ctx_scan_argv, option settings. * Get the session and tree.
*** 116,145 **** goto again; } if (error) { smb_error(gettext("//%s: login failed"), error, ctx->ct_fullserver); ! return (error); } 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); } /* * Have IPC$ tcon, now list shares. - * This prints its own errors. */ ! error = enum_shares(ctx); ! if (error) ! return (error); smb_ctx_free(ctx); ! return (0); } #ifdef I18N /* not defined, put here so xgettext(1) can find strings */ static char *shtype[] = { gettext("disk"), --- 112,139 ---- goto again; } if (error) { smb_error(gettext("//%s: login failed"), error, ctx->ct_fullserver); ! 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); ! goto out; } /* * Have IPC$ tcon, now list shares. */ ! error = share_enum_rpc(ctx, ctx->ct_fullserver); + out: smb_ctx_free(ctx); ! return (error); } #ifdef I18N /* not defined, put here so xgettext(1) can find strings */ static char *shtype[] = { gettext("disk"),
*** 156,205 **** "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... */ - 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) { ! struct share_info *ep; ! int i; 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); } - printf(gettext("\n%d shares listed from %d available\n"), - entries, total); ! free(share_info); } --- 150,180 ---- "IPC", /* IPC Inter process communication */ "unknown" }; #endif ! /* ! * Print one line of the share list, or ! * if SHARE is null, print the header line. */ void ! view_print_share(char *share, int type, char *comment) { ! char *stname; ! int stindex; + if (share == NULL) { printf(gettext("Share Type Comment\n")); printf("-------------------------------\n"); ! return; } ! 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); }