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>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
          +++ new/usr/src/cmd/fs.d/smbclnt/smbutil/view.c
↓ open down ↓ 26 lines elided ↑ open up ↑
  27   27   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28   28   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29   29   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30   30   * SUCH DAMAGE.
  31   31   *
  32   32   * $Id: view.c,v 1.9 2004/12/13 00:25:39 lindak Exp $
  33   33   */
  34   34  
  35   35  /*
  36   36   * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
       37 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  37   38   */
  38   39  
  39   40  #include <sys/types.h>
  40   41  #include <errno.h>
  41   42  #include <stdio.h>
  42   43  #include <err.h>
  43   44  #include <unistd.h>
  44   45  #include <strings.h>
  45   46  #include <stdlib.h>
  46   47  #include <sysexits.h>
  47   48  #include <libintl.h>
  48   49  
  49   50  #include <netsmb/smb.h>
  50   51  #include <netsmb/smb_lib.h>
  51      -#include <netsmb/smb_netshareenum.h>
  52      -
  53   52  #include "common.h"
  54   53  
  55      -int enum_shares(smb_ctx_t *);
  56      -void print_shares(int, int, struct share_info *);
  57      -
  58   54  void
  59   55  view_usage(void)
  60   56  {
  61   57          printf(gettext("usage: smbutil view [connection options] //"
  62   58              "[workgroup;][user[:password]@]server\n"));
  63   59          exit(1);
  64   60  }
  65   61  
  66   62  int
  67   63  cmd_view(int argc, char *argv[])
↓ open down ↓ 4 lines elided ↑ open up ↑
  72   68          if (argc < 2)
  73   69                  view_usage();
  74   70  
  75   71          error = smb_ctx_alloc(&ctx);
  76   72          if (error)
  77   73                  return (error);
  78   74  
  79   75          error = smb_ctx_scan_argv(ctx, argc, argv,
  80   76              SMBL_SERVER, SMBL_SERVER, USE_WILDCARD);
  81   77          if (error)
  82      -                return (error);
       78 +                goto out;
  83   79  
  84   80          error = smb_ctx_readrc(ctx);
  85   81          if (error)
  86      -                return (error);
       82 +                goto out;
  87   83  
  88   84          while ((opt = getopt(argc, argv, STDPARAM_OPT)) != EOF) {
  89   85                  if (opt == '?')
  90   86                          view_usage();
  91   87                  error = smb_ctx_opt(ctx, opt, optarg);
  92   88                  if (error)
  93      -                        return (error);
       89 +                        goto out;
  94   90          }
  95   91  
  96   92          smb_ctx_setshare(ctx, "IPC$", USE_IPC);
  97   93  
  98   94          /*
  99   95           * Resolve the server address,
 100   96           * setup derived defaults.
 101   97           */
 102   98          error = smb_ctx_resolve(ctx);
 103   99          if (error)
 104      -                return (error);
      100 +                goto out;
 105  101  
 106  102          /*
 107  103           * Have server, share, etc. from above:
 108  104           * smb_ctx_scan_argv, option settings.
 109  105           * Get the session and tree.
 110  106           */
 111  107  again:
 112  108          error = smb_ctx_get_ssn(ctx);
 113  109          if (error == EAUTH) {
 114  110                  err2 = smb_get_authentication(ctx);
 115  111                  if (err2 == 0)
 116  112                          goto again;
 117  113          }
 118  114          if (error) {
 119  115                  smb_error(gettext("//%s: login failed"),
 120  116                      error, ctx->ct_fullserver);
 121      -                return (error);
      117 +                goto out;
 122  118          }
 123  119  
 124  120          error = smb_ctx_get_tree(ctx);
 125  121          if (error) {
 126  122                  smb_error(gettext("//%s/%s: tree connect failed"),
 127  123                      error, ctx->ct_fullserver, ctx->ct_origshare);
 128      -                return (error);
      124 +                goto out;
 129  125          }
 130  126  
 131  127          /*
 132  128           * Have IPC$ tcon, now list shares.
 133      -         * This prints its own errors.
 134  129           */
 135      -        error = enum_shares(ctx);
 136      -        if (error)
 137      -                return (error);
      130 +        error = share_enum_rpc(ctx, ctx->ct_fullserver);
 138  131  
      132 +out:
 139  133          smb_ctx_free(ctx);
 140      -        return (0);
      134 +        return (error);
 141  135  }
 142  136  
 143  137  #ifdef I18N     /* not defined, put here so xgettext(1) can find strings */
 144  138  static char *shtype[] = {
 145  139          gettext("disk"),
 146  140          gettext("printer"),
 147  141          gettext("device"),      /* Communications device */
 148      -        gettext("IPC"),         /* Inter process communication */
      142 +        gettext("IPC"),         /* Inter process communication */
 149  143          gettext("unknown")
 150  144  };
 151  145  #else
 152  146  static char *shtype[] = {
 153  147          "disk",
 154  148          "printer",
 155  149          "device",               /* Communications device */
 156      -        "IPC",                  /* IPC Inter process communication */
      150 +        "IPC",                  /* IPC Inter process communication */
 157  151          "unknown"
 158  152  };
 159  153  #endif
 160  154  
 161      -int
 162      -enum_shares(smb_ctx_t *ctx)
      155 +/*
      156 + * Print one line of the share list, or
      157 + * if SHARE is null, print the header line.
      158 + */
      159 +void
      160 +view_print_share(char *share, int type, char *comment)
 163  161  {
 164      -        struct share_info *share_info;
 165      -        int error, entries, total;
      162 +        char *stname;
      163 +        int stindex;
 166  164  
 167      -        /*
 168      -         * XXX: Later, try RPC first,
 169      -         * then fall back to RAP...
 170      -         */
 171      -        error = smb_netshareenum(ctx, &entries, &total, &share_info);
 172      -        if (error) {
 173      -                smb_error(gettext("//%s failed to list shares"),
 174      -                    error, ctx->ct_fullserver);
 175      -                return (error);
      165 +        if (share == NULL) {
      166 +                printf(gettext("Share        Type       Comment\n"));
      167 +                printf("-------------------------------\n");
      168 +                return;
 176  169          }
 177      -        print_shares(entries, total, share_info);
 178      -        return (0);
 179      -}
 180  170  
 181      -void
 182      -print_shares(int entries, int total,
 183      -        struct share_info *share_info)
 184      -{
 185      -        struct share_info *ep;
 186      -        int i;
      171 +        stindex = type & STYPE_MASK;
      172 +        if (stindex > STYPE_UNKNOWN)
      173 +                stindex = STYPE_UNKNOWN;
      174 +        stname = gettext(shtype[stindex]);
 187  175  
 188      -        printf(gettext("Share        Type       Comment\n"));
 189      -        printf("-------------------------------\n");
      176 +        if (comment == NULL)
      177 +                comment = "";
 190  178  
 191      -        for (ep = share_info, i = 0; i < entries; i++, ep++) {
 192      -                int sti = ep->type & STYPE_MASK;
 193      -                if (sti > STYPE_UNKNOWN)
 194      -                        sti = STYPE_UNKNOWN;
 195      -                printf("%-12s %-10s %s\n", ep->netname,
 196      -                    gettext(shtype[sti]),
 197      -                    ep->remark ? ep->remark : "");
 198      -                free(ep->netname);
 199      -                free(ep->remark);
 200      -        }
 201      -        printf(gettext("\n%d shares listed from %d available\n"),
 202      -            entries, total);
 203      -
 204      -        free(share_info);
      179 +        printf("%-12s %-10s %s\n", share, stname, comment);
 205  180  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX