Print this page
3328 smbutil view does't work with Win2008 and later
requires 1575 untangle libmlrpc ...
*** 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 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
*** 46,61 ****
#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] //"
--- 47,59 ----
#include <sysexits.h>
#include <libintl.h>
#include <netsmb/smb.h>
#include <netsmb/smb_lib.h>
#include "common.h"
! static int use_rap;
void
view_usage(void)
{
printf(gettext("usage: smbutil view [connection options] //"
*** 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);
/*
--- 75,105 ----
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();
+ /*
+ * 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;
}
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.
--- 106,116 ----
* 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,143 ****
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 */
--- 123,152 ----
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.
! * 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);
+ out:
smb_ctx_free(ctx);
return (0);
}
#ifdef I18N /* not defined, put here so xgettext(1) can find strings */
*** 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);
}
--- 165,195 ----
"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);
}