Print this page
3328 smbutil view does't work with Win2008 and later
requires 1575 untangle libmlrpc ...

@@ -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 2013 Nexenta Systems, Inc.  All rights reserved.
  */
 
 #include <sys/types.h>
 #include <errno.h>
 #include <stdio.h>

@@ -46,16 +47,13 @@
 #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 *);
+static int use_rap;
 
 void
 view_usage(void)
 {
         printf(gettext("usage: smbutil view [connection options] //"

@@ -77,22 +75,31 @@
                 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();
+                /*
+                 * 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)
-                        return (error);
+                        goto out;
         }
 
         smb_ctx_setshare(ctx, "IPC$", USE_IPC);
 
         /*

@@ -99,11 +106,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,28 +123,30 @@
                         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.
+         * Try RPC; if that fails, do RAP.
          */
-        error = enum_shares(ctx);
-        if (error)
-                return (error);
+        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,50 +165,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);
 }