Print this page
NEX-14666 Need to provide SMB 2.1 Client
NEX-17187 panic in smbfs_acl_store
NEX-17231 smbfs create xattr files finds wrong file
NEX-17224 smbfs lookup EINVAL should be ENOENT
NEX-17260 SMB1 client fails to list directory after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
and: (cleanup)
NEX-16818 Add fksmbcl development tool
NEX-17264 SMB client test tp_smbutil_013 fails after NEX-14666
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
and: (fix ref leaks)

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libsmbfs/smb/rcfile.c
          +++ new/usr/src/lib/libsmbfs/smb/rcfile.c
↓ open down ↓ 23 lines elided ↑ open up ↑
  24   24   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25   25   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  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   * $Id: rcfile.c,v 1.1.1.2 2001/07/06 22:38:43 conrad Exp $
  33   33   */
       34 +/*
       35 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
       36 + */
  34   37  
  35   38  #include <fcntl.h>
  36   39  #include <sys/types.h>
  37   40  #include <sys/queue.h>
  38   41  #include <sys/stat.h>
  39   42  
  40   43  #include <ctype.h>
  41   44  #include <errno.h>
  42   45  #include <stdio.h>
  43   46  #include <string.h>
↓ open down ↓ 6 lines elided ↑ open up ↑
  50   53  
  51   54  #include <cflib.h>
  52   55  #include "rcfile_priv.h"
  53   56  
  54   57  #include <assert.h>
  55   58  
  56   59  #if 0 /* before SMF */
  57   60  #define SMB_CFG_FILE    "/etc/nsmb.conf"
  58   61  #define OLD_SMB_CFG_FILE        "/usr/local/etc/nsmb.conf"
  59   62  #endif
  60      -#define SMBFS_SHARECTL_CMD      "/usr/sbin/sharectl get smbfs"
  61   63  
  62   64  extern int smb_debug;
  63   65  
  64   66  static struct rcfile *rc_cachelookup(const char *filename);
  65   67  static struct rcsection *rc_findsect(struct rcfile *rcp, const char *sectname);
  66   68  static struct rcsection *rc_addsect(struct rcfile *rcp, const char *sectname);
  67   69  static int              rc_freesect(struct rcfile *rcp, struct rcsection *rsp);
  68   70  static struct rckey *rc_sect_findkey(struct rcsection *rsp, const char *key);
  69   71  static struct rckey *rc_sect_addkey(struct rcsection *rsp, const char *name,
  70   72      const char *value);
↓ open down ↓ 69 lines elided ↑ open up ↑
 140  142                  insecure_nsmbrc = 1;
 141  143          t = rcp->rf_f;
 142  144          rcp->rf_f = f;
 143  145          rc_parse(rcp);
 144  146          rcp->rf_f = t;
 145  147          fclose(f);
 146  148          return (0);
 147  149  }
 148  150  
 149  151  /*
 150      - * Like rc_open, but does popen of command:
 151      - * sharectl get smbfs
      152 + * Like rc_open, but creates a temporary file and
      153 + * reads the sharectl settings into it.
      154 + * The file is deleted when we close it.
 152  155   */
 153  156  static int
 154      -rc_popen_cmd(const char *command, struct rcfile **rcfile)
      157 +rc_open_sharectl(struct rcfile **rcfile)
 155  158  {
 156      -        struct rcfile *rcp;
 157      -        FILE *f;
      159 +        static char template[24] = "/tmp/smbfsXXXXXX";
      160 +        struct rcfile *rcp = NULL;
      161 +        FILE *fp = NULL;
      162 +        int err;
      163 +        int fd = -1;
 158  164  
 159  165          assert(MUTEX_HELD(&rcfile_mutex));
 160  166  
 161      -        f = popen(command, "r");
 162      -        if (f == NULL)
 163      -                return (errno);
 164      -        insecure_nsmbrc = 0;
      167 +        fd = mkstemp(template);
      168 +        if (fd < 0) {
      169 +                err = errno;
      170 +                goto errout;
      171 +        }
 165  172  
      173 +        fp = fdopen(fd, "w+");
      174 +        if (fp == NULL) {
      175 +                err = errno;
      176 +                close(fd);
      177 +                goto errout;
      178 +        }
      179 +        fd = -1; /* The fp owns this fd now. */
      180 +
      181 +        /*
      182 +         * Get smbfs sharectl settings into the file.
      183 +         */
      184 +        if ((err = rc_scf_get_sharectl(fp)) != 0)
      185 +                goto errout;
      186 +
 166  187          rcp = malloc(sizeof (struct rcfile));
 167  188          if (rcp == NULL) {
 168      -                fclose(f);
 169      -                return (ENOMEM);
      189 +                err = ENOMEM;
      190 +                goto errout;
 170  191          }
 171  192          bzero(rcp, sizeof (struct rcfile));
 172      -        rcp->rf_name = strdup(command);
 173      -        rcp->rf_f = f;
      193 +
      194 +        rcp->rf_name = strdup(template);
      195 +        if (rcp->rf_name == NULL) {
      196 +                err = ENOMEM;
      197 +                goto errout;
      198 +        }
      199 +        rcp->rf_f = fp;
      200 +        rcp->rf_flags = RCFILE_DELETE_ON_CLOSE;
      201 +
 174  202          SLIST_INSERT_HEAD(&pf_head, rcp, rf_next);
      203 +        insecure_nsmbrc = 0;
 175  204          rc_parse(rcp);
 176  205          *rcfile = rcp;
 177  206          /* fclose(f) in rc_close */
 178  207          return (0);
      208 +
      209 +errout:
      210 +        if (rcp != NULL)
      211 +                free(rcp);
      212 +        if (fp != NULL) {
      213 +                fclose(fp);
      214 +                fd = -1;
      215 +        }
      216 +        if (fd != -1)
      217 +                close(fd);
      218 +
      219 +        return (err);
 179  220  }
 180  221  
      222 +
 181  223  static int
 182  224  rc_close(struct rcfile *rcp)
 183  225  {
 184  226          struct rcsection *p, *n;
 185  227  
 186  228          mutex_lock(&rcfile_mutex);
 187  229  
 188  230          fclose(rcp->rf_f);
      231 +        if (rcp->rf_flags & RCFILE_DELETE_ON_CLOSE)
      232 +                (void) unlink(rcp->rf_name);
      233 +
 189  234          for (p = SLIST_FIRST(&rcp->rf_sect); p; ) {
 190  235                  n = p;
 191  236                  p = SLIST_NEXT(p, rs_next);
 192  237                  rc_freesect(rcp, n);
 193  238          }
 194  239          free(rcp->rf_name);
 195  240          SLIST_REMOVE(&pf_head, rcp, rcfile, rf_next);
 196  241          free(rcp);
 197  242  
 198  243          mutex_unlock(&rcfile_mutex);
↓ open down ↓ 137 lines elided ↑ open up ↑
 336  381  /*
 337  382   * Ensure that "minauth" is set to the highest level
 338  383   */
 339  384  /*ARGSUSED*/
 340  385  static void
 341  386  set_value(struct rcfile *rcp, struct rcsection *rsp, struct rckey *rkp,
 342  387      char *ptr)
 343  388  {
 344  389          int now, new;
 345  390  #ifdef DEBUG
 346      -        char *from;
      391 +        char *from = "SMF";
 347  392  
 348      -        if (smb_debug)
 349      -                from = (home_nsmbrc) ?
 350      -                    "user file" : "SMF";
      393 +        if (home_nsmbrc != 0)
      394 +                from = "user file";
 351  395  #endif
 352  396  
 353  397          if (strcmp(rkp->rk_name, "minauth") == 0) {
 354  398                  now = eval_minauth(rkp->rk_value);
 355  399                  new = eval_minauth(ptr);
 356  400                  if (new <= now) {
 357  401  #ifdef DEBUG
 358  402                          if (smb_debug)
 359  403                                  fprintf(stderr,
 360  404                                      "set_value: rejecting %s=%s"
↓ open down ↓ 293 lines elided ↑ open up ↑
 654  698          char *fn;
 655  699          int len, error = 0;
 656  700  
 657  701          mutex_lock(&rcfile_mutex);
 658  702  
 659  703          smb_rc = NULL;
 660  704  #if 0   /* before SMF */
 661  705          fn = SMB_CFG_FILE;
 662  706          error = rc_open(fn, &smb_rc);
 663  707  #else
 664      -        fn = SMBFS_SHARECTL_CMD;
 665      -        error = rc_popen_cmd(fn, &smb_rc);
      708 +        fn = "(sharectl get smbfs)";
      709 +        error = rc_open_sharectl(&smb_rc);
 666  710  #endif
 667  711          if (error != 0 && error != ENOENT) {
 668  712                  /* Error from fopen. strerror is OK. */
 669  713                  fprintf(stderr, dgettext(TEXT_DOMAIN,
 670  714                      "Can't open %s: %s\n"), fn, strerror(errno));
 671  715          }
 672  716  #ifdef DEBUG
 673  717          if (smb_debug)
 674  718                  dump_props(fn);
 675  719  #endif
↓ open down ↓ 43 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX