Print this page
    
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/smbutil.c
          +++ new/usr/src/cmd/fs.d/smbclnt/smbutil/smbutil.c
   1    1  /*
   2    2   * Copyright (c) 2000, Boris Popov
   3    3   * All rights reserved.
   4    4   *
   5    5   * Redistribution and use in source and binary forms, with or without
   6    6   * modification, are permitted provided that the following conditions
   7    7   * are met:
   8    8   * 1. Redistributions of source code must retain the above copyright
   9    9   *    notice, this list of conditions and the following disclaimer.
  10   10   * 2. Redistributions in binary form must reproduce the above copyright
  11   11   *    notice, this list of conditions and the following disclaimer in the
  12   12   *    documentation and/or other materials provided with the distribution.
  13   13   * 3. All advertising materials mentioning features or use of this software
  14   14   *    must display the following acknowledgement:
  15   15   *    This product includes software developed by Boris Popov.
  16   16   * 4. Neither the name of the author nor the names of any co-contributors
  17   17   *    may be used to endorse or promote products derived from this software
  18   18   *    without specific prior written permission.
  19   19   *
  20   20   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21   21   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22   22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23   23   * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  24   24   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25   25   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  
    | 
      ↓ open down ↓ | 
    25 lines elided | 
    
      ↑ open up ↑ | 
  
  26   26   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  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  
  33   33  /*
  34   34   * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  35   35   * Use is subject to license terms.
       36 + *
       37 + * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  36   38   */
  37   39  
  38   40  #include <sys/param.h>
  39   41  #include <sys/time.h>
  40   42  #include <stdio.h>
  41   43  #include <string.h>
  42   44  #include <unistd.h>
  43   45  #include <stdlib.h>
  44   46  #include <err.h>
  45   47  #include <sysexits.h>
  46   48  #include <locale.h>
  47   49  #include <libintl.h>
  48   50  
  49   51  #include <netsmb/smb_lib.h>
  50   52  
  51   53  #include "common.h"
  52   54  
  53   55  #ifndef EX_DATAERR
  54   56  #define EX_DATAERR 1
  55   57  #endif
  56   58  
  57   59  static void help(void);
  58   60  
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
  59   61  
  60   62  typedef int cmd_fn_t (int argc, char *argv[]);
  61   63  typedef void cmd_usage_t (void);
  62   64  
  63   65  #define CMDFL_NO_KMOD   0x0001
  64   66  
  65   67  static struct commands {
  66   68          const char      *name;
  67   69          cmd_fn_t        *fn;
  68   70          cmd_usage_t     *usage;
  69      -        int             flags;
       71 +        int             flags;
  70   72  } commands[] = {
  71   73          {"crypt",       cmd_crypt,      NULL, CMDFL_NO_KMOD},
       74 +        {"discon",      cmd_discon,     discon_usage, 0},
  72   75          {"help",        cmd_help,       help_usage, CMDFL_NO_KMOD},
       76 +        {"info",        cmd_info,       info_usage, 0},
  73   77          {"login",       cmd_login,      login_usage, 0},
  74   78          {"logout",      cmd_logout,     logout_usage, 0},
  75   79          {"logoutall",   cmd_logoutall,  logoutall_usage, 0},
  76   80          {"lookup",      cmd_lookup,     lookup_usage, CMDFL_NO_KMOD},
  77   81          {"print",       cmd_print,      print_usage, 0},
  78   82          {"status",      cmd_status,     status_usage, CMDFL_NO_KMOD},
  79   83          {"view",        cmd_view,       view_usage, 0},
  80   84          {NULL, NULL, NULL, 0}
  81   85  };
  82   86  
  83   87  static struct commands *
  84   88  lookupcmd(const char *name)
  85   89  {
  86   90          struct commands *cmd;
  87   91  
  88   92          for (cmd = commands; cmd->name; cmd++) {
  89   93                  if (strcmp(cmd->name, name) == 0)
  90   94                          return (cmd);
  91   95          }
  92   96          return (NULL);
  93   97  }
  94   98  
  95   99  int
  96  100  cmd_crypt(int argc, char *argv[])
  97  101  {
  98  102          char *cp, *psw;
  99  103  
 100  104          if (argc < 2)
 101  105                  psw = getpassphrase(gettext("Password:"));
 102  106          else
 103  107                  psw = argv[1];
 104  108          /* XXX Better to embed malloc/free in smb_simplecrypt? */
 105  109          cp = malloc(4 + 2 * strlen(psw));
 106  110          if (cp == NULL)
 107  111                  errx(EX_DATAERR, gettext("out of memory"));
 108  112          smb_simplecrypt(cp, psw);
 109  113          printf("%s\n", cp);
 110  114          free(cp);
 111  115          return (0);
 112  116  }
 113  117  
 114  118  int
 115  119  cmd_help(int argc, char *argv[])
 116  120  {
 117  121          struct commands *cmd;
 118  122          char *cp;
 119  123  
 120  124          if (argc < 2)
 121  125                  help_usage();
 122  126          cp = argv[1];
 123  127          cmd = lookupcmd(cp);
 124  128          if (cmd == NULL)
 125  129                  errx(EX_DATAERR, gettext("unknown command %s"), cp);
 126  130          if (cmd->usage == NULL)
 127  131                  errx(EX_DATAERR,
 128  132                      gettext("no specific help for command %s"), cp);
 129  133          cmd->usage();
 130  134          return (0);
 131  135  }
 132  136  
 133  137  int
 134  138  main(int argc, char *argv[])
 135  139  {
 136  140          struct commands *cmd;
 137  141          char *cp;
 138  142          int err, opt;
 139  143  
 140  144          (void) setlocale(LC_ALL, "");
 141  145          (void) textdomain(TEXT_DOMAIN);
 142  146  
 143  147  #ifdef APPLE
 144  148          dropsuid(); /* see libsmbfs */
 145  149  #endif
 146  150  
 147  151          if (argc < 2)
 148  152                  help();
 149  153  
 150  154          while ((opt = getopt(argc, argv, "dhv")) != EOF) {
 151  155                  switch (opt) {
 152  156                  case 'd':
 153  157                          smb_debug++;
 154  158                          break;
 155  159                  case 'h':
 156  160                          help();
 157  161                          /* NOTREACHED */
 158  162                  case 'v':
 159  163                          smb_verbose++;
 160  164                          break;
 161  165                  default:
 162  166                          help();
 163  167                          /* NOTREACHED */
 164  168                  }
 165  169          }
 166  170          if (optind >= argc)
 167  171                  help();
 168  172  
 169  173          cp = argv[optind];
 170  174          cmd = lookupcmd(cp);
 171  175          if (cmd == NULL)
 172  176                  errx(EX_DATAERR, gettext("unknown command %s"), cp);
 173  177  
 174  178          if ((cmd->flags & CMDFL_NO_KMOD) == 0 && smb_lib_init() != 0)
 175  179                  exit(1);
 176  180  
 177  181          argc -= optind;
 178  182          argv += optind;
 179  183          optind = 1;
 180  184          err = cmd->fn(argc, argv);
  
    | 
      ↓ open down ↓ | 
    98 lines elided | 
    
      ↑ open up ↑ | 
  
 181  185          return ((err) ? 1 : 0);
 182  186  }
 183  187  
 184  188  static void
 185  189  help(void) {
 186  190          printf("\n");
 187  191          printf(gettext("usage: %s [-hv] subcommand [args]\n"), __progname);
 188  192          printf(gettext("where subcommands are:\n"
 189  193          " crypt         slightly obscure password\n"
 190  194          " help          display help on specified subcommand\n"
 191      -        /* " lc                 display active connections\n" */
      195 +        /* " lc         display active connections\n" */
      196 +        " info          display server type and version\n"
 192  197          " login         login to specified host\n"
 193      -        " logout        logout from specified host\n"
      198 +        " logout        logout from specified host\n"
 194  199          " logoutall     logout all users (requires privilege)\n"
 195      -        " lookup        resolve NetBIOS name to IP address\n"
      200 +        " lookup        resolve NetBIOS name to IP address\n"
 196  201          " print         print file to the specified remote printer\n"
 197      -        " status        resolve IP address or DNS name to NetBIOS names\n"
      202 +        " status        resolve IP address or DNS name to NetBIOS names\n"
 198  203          " view          list resources on specified host\n"
 199  204          "\n"));
 200  205          exit(1);
 201  206  }
 202  207  
 203  208  void
 204  209  help_usage(void) {
 205  210          printf(gettext("usage: smbutil help command\n"));
 206  211          exit(1);
 207  212  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX