Print this page
NEX-2807 Restoring previous versions from snapshots doesn't work with nested folders.
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-9808 SMB3 persistent handles
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-9808 SMB3 persistent handles
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-4538 SMB1 create file should support extended_response format (2)
NEX-6116 Failures in smbtorture raw.open
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Include this commit if upstreaming/backporting any of:
NEX-4540 SMB server declines EA support incorrectly
NEX-4239 smbtorture create failures re. allocation size
(illumos) 6398 SMB should support path names longer than 1024
NEX-5082 panic getting Mac attributes for a 255 character file name
Reviewed by: Bayard Bell <bayard.bell@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Matt Barden <Matt.Barden@nexenta.com>
Conflicts:
        usr/src/uts/common/fs/smbsrv/smb_pathname.c
NEX-3611 CLONE NEX-3550 Replace smb2_enable with max_protocol
Reviewed by: Yuri Pankov <Yuri.Pankov@nexenta.com>
SMB-115 Support SMB path names with length > 1024
SMB-100 Internal error if filename is too long
Approved by: Gordon Ross <gwr@nexenta.com>
SMB-136 Snapshots not visible in Windows previous versions
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)
SMB-65 SMB server in non-global zones (use zone_kcred())
re #13470 rb4432 Sync some SMB differences from illumos
re #6854 FindFirstFile,FindFirstFileEx,... are not working correctly on Nexenta CIFS-shares
re #6813 rb1757 port 2976 Child folder visibility through shares

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/smbsrv/smb_pathname.c
          +++ new/usr/src/uts/common/fs/smbsrv/smb_pathname.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
       23 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
  24   24   */
  25   25  
  26   26  #include <smbsrv/smb_kproto.h>
  27   27  #include <smbsrv/smb_fsops.h>
  28   28  #include <sys/pathname.h>
  29   29  #include <sys/sdt.h>
  30   30  
  31   31  static char *smb_pathname_catia_v5tov4(smb_request_t *, char *, char *, int);
  32   32  static char *smb_pathname_catia_v4tov5(smb_request_t *, char *, char *, int);
  33   33  static int smb_pathname_lookup(pathname_t *, pathname_t *, int,
↓ open down ↓ 110 lines elided ↑ open up ↑
 144  144  smb_pathname_reduce(
 145  145      smb_request_t       *sr,
 146  146      cred_t              *cred,
 147  147      const char          *path,
 148  148      smb_node_t          *share_root_node,
 149  149      smb_node_t          *cur_node,
 150  150      smb_node_t          **dir_node,
 151  151      char                *last_component)
 152  152  {
 153  153          smb_node_t      *root_node;
 154      -        pathname_t      ppn;
      154 +        pathname_t      ppn, mnt_pn;
 155  155          char            *usepath;
 156  156          int             lookup_flags = FOLLOW;
 157  157          int             trailing_slash = 0;
 158  158          int             err = 0;
 159  159          int             len;
 160      -        smb_node_t      *vss_cur_node;
 161      -        smb_node_t      *vss_root_node;
      160 +        smb_node_t      *vss_node;
 162  161          smb_node_t      *local_cur_node;
 163  162          smb_node_t      *local_root_node;
      163 +        boolean_t       chk_vss;
      164 +        char            *gmttoken;
 164  165  
 165  166          ASSERT(dir_node);
 166  167          ASSERT(last_component);
 167  168  
 168  169          *dir_node = NULL;
 169  170          *last_component = '\0';
 170      -        vss_cur_node = NULL;
 171      -        vss_root_node = NULL;
      171 +        vss_node = NULL;
      172 +        gmttoken = NULL;
      173 +        chk_vss = B_FALSE;
 172  174  
 173  175          if (sr && sr->tid_tree) {
 174  176                  if (STYPE_ISIPC(sr->tid_tree->t_res_type))
 175  177                          return (EACCES);
 176  178          }
 177  179  
 178  180          if (SMB_TREE_IS_CASEINSENSITIVE(sr))
 179  181                  lookup_flags |= FIGNORECASE;
 180  182  
 181  183          if (path == NULL)
↓ open down ↓ 35 lines elided ↑ open up ↑
 217  219                              SMB_MAXPATHLEN);
 218  220                          if (err != 0) {
 219  221                                  kmem_free(usepath, SMB_MAXPATHLEN);
 220  222                                  return (err);
 221  223                          }
 222  224                          len = strlen(usepath);
 223  225                  }
 224  226          }
 225  227  
 226  228          if (sr != NULL) {
 227      -                boolean_t chk_vss;
 228      -                if (sr->session->dialect >= SMB_VERS_2_BASE)
      229 +                if (sr->session->dialect >= SMB_VERS_2_BASE) {
 229  230                          chk_vss = sr->arg.open.create_timewarp;
 230      -                else
      231 +                } else {
 231  232                          chk_vss = (sr->smb_flg2 &
 232  233                              SMB_FLAGS2_REPARSE_PATH) != 0;
 233      -                if (chk_vss) {
 234      -                        err = smb_vss_lookup_nodes(sr, root_node, cur_node,
 235      -                            usepath, &vss_cur_node, &vss_root_node);
 236      -                        if (err != 0) {
 237      -                                kmem_free(usepath, SMB_MAXPATHLEN);
 238      -                                return (err);
 239      -                        }
 240  234  
 241      -                        len = strlen(usepath);
 242      -                        local_cur_node = vss_cur_node;
 243      -                        local_root_node = vss_root_node;
      235 +                        if (chk_vss) {
      236 +                                gmttoken = kmem_alloc(SMB_VSS_GMT_SIZE,
      237 +                                    KM_SLEEP);
      238 +                                err = smb_vss_extract_gmttoken(usepath,
      239 +                                    gmttoken);
      240 +                                if (err != 0) {
      241 +                                        kmem_free(usepath, SMB_MAXPATHLEN);
      242 +                                        kmem_free(gmttoken, SMB_VSS_GMT_SIZE);
      243 +                                        return (err);
      244 +                                }
      245 +                                len = strlen(usepath);
      246 +                        }
 244  247                  }
      248 +                if (chk_vss)
      249 +                        (void) pn_alloc(&mnt_pn);
 245  250          }
 246  251  
 247  252          if (usepath[len - 1] == '/')
 248  253                  trailing_slash = 1;
 249  254  
 250  255          (void) strcanon(usepath, "/");
 251  256  
 252  257          (void) pn_alloc_sz(&ppn, SMB_MAXPATHLEN);
 253  258  
 254  259          if ((err = pn_set(&ppn, usepath)) != 0) {
 255  260                  (void) pn_free(&ppn);
 256  261                  kmem_free(usepath, SMB_MAXPATHLEN);
 257      -                if (vss_cur_node != NULL)
 258      -                        (void) smb_node_release(vss_cur_node);
 259      -                if (vss_root_node != NULL)
 260      -                        (void) smb_node_release(vss_root_node);
      262 +                if (chk_vss)
      263 +                        (void) pn_free(&mnt_pn);
      264 +                if (gmttoken != NULL)
      265 +                        kmem_free(gmttoken, SMB_VSS_GMT_SIZE);
 261  266                  return (err);
 262  267          }
 263  268  
 264  269          /*
 265  270           * If a path does not have a trailing slash, strip off the
 266  271           * last component.  (We only need to return an smb_node for
 267  272           * the second to last component; a name is returned for the
 268  273           * last component.)
      274 +         *
      275 +         * For VSS requests, the last component might be a filesystem of its
      276 +         * own, and we need to discover that before exiting this function,
      277 +         * so allow the lookup to happen on the last component.
      278 +         * We'll correct this later when we convert to the snapshot.
 269  279           */
 270  280  
 271      -        if (trailing_slash) {
 272      -                (void) strlcpy(last_component, ".", MAXNAMELEN);
 273      -        } else {
 274      -                (void) pn_setlast(&ppn);
 275      -                (void) strlcpy(last_component, ppn.pn_path, MAXNAMELEN);
 276      -                ppn.pn_path[0] = '\0';
      281 +        if (!chk_vss) {
      282 +                if (trailing_slash) {
      283 +                        (void) strlcpy(last_component, ".", MAXNAMELEN);
      284 +                } else {
      285 +                        (void) pn_setlast(&ppn);
      286 +                        (void) strlcpy(last_component, ppn.pn_path, MAXNAMELEN);
      287 +                        ppn.pn_path[0] = '\0';
      288 +                }
 277  289          }
 278  290  
 279  291          if ((strcmp(ppn.pn_buf, "/") == 0) || (ppn.pn_buf[0] == '\0')) {
 280  292                  smb_node_ref(local_cur_node);
 281  293                  *dir_node = local_cur_node;
 282  294          } else {
 283  295                  err = smb_pathname(sr, ppn.pn_buf, lookup_flags,
 284      -                    local_root_node, local_cur_node, NULL, dir_node, cred);
      296 +                    local_root_node, local_cur_node, NULL, dir_node, cred,
      297 +                    chk_vss ? &mnt_pn : NULL);
 285  298          }
 286  299  
 287  300          (void) pn_free(&ppn);
 288  301          kmem_free(usepath, SMB_MAXPATHLEN);
 289  302  
 290  303          /*
      304 +         * We need to try and convert to snapshots, even on error.
      305 +         * This is to handle the following cases:
      306 +         * - We're on the lowest level filesystem, but a directory got renamed
      307 +         *   on the live version. We'll get ENOENT, but can still find it in
      308 +         *   the snapshot.
      309 +         * - The last component was actually a file. We need to leave the last
      310 +         *   component in in case it is, itself, a mountpoint, but that means
      311 +         *   we might get ENOTDIR if it's not actually a directory.
      312 +         *
      313 +         * Note that if you change the share-relative name of a mountpoint,
      314 +         * you won't be able to access previous versions of files under it.
      315 +         */
      316 +        if (chk_vss && *dir_node != NULL) {
      317 +                if ((err = smb_vss_lookup_nodes(sr, *dir_node, &vss_node,
      318 +                    gmttoken)) == 0) {
      319 +                        char *p = mnt_pn.pn_path;
      320 +                        size_t pathleft;
      321 +
      322 +                        smb_node_release(*dir_node);
      323 +                        *dir_node = NULL;
      324 +                        pathleft = pn_pathleft(&mnt_pn);
      325 +
      326 +                        if (pathleft == 0 || trailing_slash) {
      327 +                                (void) strlcpy(last_component, ".", MAXNAMELEN);
      328 +                        } else {
      329 +                                (void) pn_setlast(&mnt_pn);
      330 +                                (void) strlcpy(last_component, mnt_pn.pn_path,
      331 +                                    MAXNAMELEN);
      332 +                                mnt_pn.pn_path[0] = '\0';
      333 +                                pathleft -= strlen(last_component);
      334 +                        }
      335 +
      336 +                        if (pathleft != 0) {
      337 +                                err = smb_pathname(sr, p, lookup_flags,
      338 +                                    vss_node, vss_node, NULL, dir_node, cred,
      339 +                                    NULL);
      340 +                        } else {
      341 +                                *dir_node = vss_node;
      342 +                                vss_node = NULL;
      343 +                        }
      344 +                }
      345 +        }
      346 +
      347 +        if (chk_vss)
      348 +                (void) pn_free(&mnt_pn);
      349 +        if (gmttoken != NULL)
      350 +                kmem_free(gmttoken, SMB_VSS_GMT_SIZE);
      351 +
      352 +        /*
 291  353           * Prevent traversal to another file system if mount point
 292  354           * traversal is disabled.
 293  355           *
 294  356           * Note that we disregard whether the traversal of the path went
 295  357           * outside of the file system and then came back (say via a link).
 296  358           * This means that only symlinks that are expressed relatively to
 297  359           * the share root work.
 298  360           *
 299  361           * share_root_node is NULL when mapping a share, so we disregard
 300  362           * that case.
↓ open down ↓ 10 lines elided ↑ open up ↑
 311  373          }
 312  374  
 313  375          if (err) {
 314  376                  if (*dir_node) {
 315  377                          (void) smb_node_release(*dir_node);
 316  378                          *dir_node = NULL;
 317  379                  }
 318  380                  *last_component = 0;
 319  381          }
 320  382  
 321      -        if (vss_cur_node != NULL)
 322      -                (void) smb_node_release(vss_cur_node);
 323      -        if (vss_root_node != NULL)
 324      -                (void) smb_node_release(vss_root_node);
 325      -
      383 +        if (vss_node != NULL)
      384 +                (void) smb_node_release(vss_node);
 326  385          return (err);
 327  386  }
 328  387  
 329  388  /*
 330  389   * smb_pathname()
 331  390   * wrapper to lookuppnvp().  Handles name unmangling.
 332  391   *
 333  392   * *dir_node is the true directory of the target *node.
 334  393   *
 335  394   * If any component but the last in the path is not found, ENOTDIR instead of
↓ open down ↓ 14 lines elided ↑ open up ↑
 350  409   * file system to return "first match" in the event of a case collision.
 351  410   *
 352  411   * If CATIA character translation is enabled it is applied to each
 353  412   * component before passing the component to smb_pathname_lookup().
 354  413   * After smb_pathname_lookup() the reverse translation is applied.
 355  414   */
 356  415  
 357  416  int
 358  417  smb_pathname(smb_request_t *sr, char *path, int flags,
 359  418      smb_node_t *root_node, smb_node_t *cur_node, smb_node_t **dir_node,
 360      -    smb_node_t **ret_node, cred_t *cred)
      419 +    smb_node_t **ret_node, cred_t *cred, pathname_t *mnt_pn)
 361  420  {
 362  421          char            *component, *real_name, *namep;
 363  422          pathname_t      pn, rpn, upn, link_pn;
 364      -        smb_node_t      *dnode, *fnode;
      423 +        smb_node_t      *dnode, *fnode, *mnt_node;
 365  424          smb_attr_t      attr;
 366  425          vnode_t         *rootvp, *vp;
 367  426          size_t          pathleft;
 368  427          int             err = 0;
 369  428          int             nlink = 0;
 370  429          int             local_flags;
 371  430          uint32_t        abe_flag = 0;
 372  431          char            namebuf[MAXNAMELEN];
      432 +        vnode_t *fsrootvp = NULL;
 373  433  
 374  434          if (path == NULL)
 375  435                  return (EINVAL);
 376  436  
 377  437          ASSERT(root_node);
 378  438          ASSERT(cur_node);
 379  439          ASSERT(ret_node);
 380  440  
 381  441          *ret_node = NULL;
 382  442  
 383  443          if (dir_node)
 384  444                  *dir_node = NULL;
 385  445  
 386  446          (void) pn_alloc_sz(&upn, SMB_MAXPATHLEN);
 387  447  
 388  448          if ((err = pn_set(&upn, path)) != 0) {
 389  449                  (void) pn_free(&upn);
 390  450                  return (err);
 391  451          }
 392  452  
      453 +        if (mnt_pn != NULL && (err = pn_set(mnt_pn, path) != 0)) {
      454 +                (void) pn_free(&upn);
      455 +                return (err);
      456 +        }
      457 +
 393  458          if (SMB_TREE_SUPPORTS_ABE(sr))
 394  459                  abe_flag = SMB_ABE;
 395  460  
 396  461          (void) pn_alloc(&pn);
 397  462          (void) pn_alloc(&rpn);
 398  463  
 399  464          component = kmem_alloc(MAXNAMELEN, KM_SLEEP);
 400  465          real_name = kmem_alloc(MAXNAMELEN, KM_SLEEP);
 401  466  
      467 +        if (mnt_pn != NULL) {
      468 +                mnt_node = cur_node;
      469 +                smb_node_ref(cur_node);
      470 +        } else
      471 +                mnt_node = NULL;
 402  472          fnode = NULL;
 403  473          dnode = cur_node;
 404  474          smb_node_ref(dnode);
 405  475          rootvp = root_node->vp;
 406  476  
 407  477          while ((pathleft = pn_pathleft(&upn)) != 0) {
 408  478                  if (fnode) {
 409  479                          smb_node_release(dnode);
 410  480                          dnode = fnode;
 411  481                          fnode = NULL;
↓ open down ↓ 4 lines elided ↑ open up ↑
 416  486  
 417  487                  if ((namep = smb_pathname_catia_v5tov4(sr, component,
 418  488                      namebuf, sizeof (namebuf))) == NULL) {
 419  489                          err = EILSEQ;
 420  490                          break;
 421  491                  }
 422  492  
 423  493                  if ((err = pn_set(&pn, namep)) != 0)
 424  494                          break;
 425  495  
      496 +                /* We want the DOS attributes. */
      497 +                bzero(&attr, sizeof (attr));
      498 +                attr.sa_mask = SMB_AT_DOSATTR;
      499 +
 426  500                  local_flags = flags & FIGNORECASE;
 427  501                  err = smb_pathname_lookup(&pn, &rpn, local_flags,
 428  502                      &vp, rootvp, dnode->vp, &attr, cred);
 429  503  
 430  504                  if (err) {
 431  505                          if (!SMB_TREE_SUPPORTS_SHORTNAMES(sr) ||
 432  506                              !smb_maybe_mangled(component))
 433  507                                  break;
 434  508  
 435  509                          if ((err = smb_unmangle(dnode, component,
↓ open down ↓ 84 lines elided ↑ open up ↑
 520  594                                  err = ENOMEM;
 521  595                                  break;
 522  596                          }
 523  597                  }
 524  598  
 525  599                  while (upn.pn_path[0] == '/') {
 526  600                          upn.pn_path++;
 527  601                          upn.pn_pathlen--;
 528  602                  }
 529  603  
      604 +                /*
      605 +                 * If the node we looked up is the root of a filesystem,
      606 +                 * snapshot the lookup so we can replay this after discovering
      607 +                 * the lowest mounted filesystem.
      608 +                 */
      609 +                if (mnt_pn != NULL &&
      610 +                    (err = VFS_ROOT(fnode->vp->v_vfsp, &fsrootvp)) == 0) {
      611 +                        if (fsrootvp == fnode->vp) {
      612 +                                mnt_pn->pn_pathlen = pn_pathleft(&upn);
      613 +                                mnt_pn->pn_path = mnt_pn->pn_buf +
      614 +                                    ((ptrdiff_t)upn.pn_path -
      615 +                                    (ptrdiff_t)upn.pn_buf);
      616 +
      617 +                                smb_node_ref(fnode);
      618 +                                if (mnt_node != NULL)
      619 +                                        smb_node_release(mnt_node);
      620 +                                mnt_node = fnode;
      621 +
      622 +                        }
      623 +                        VN_RELE(fsrootvp);
      624 +                }
 530  625          }
 531  626  
 532  627          if ((pathleft) && (err == ENOENT))
 533  628                  err = ENOTDIR;
 534  629  
 535      -        if (err) {
      630 +        if (mnt_node == NULL)
      631 +                mnt_pn = NULL;
      632 +
      633 +        /*
      634 +         * We always want to return a node when we're doing VSS
      635 +         * (mnt_pn != NULL)
      636 +         */
      637 +        if (mnt_pn == NULL && err != 0) {
 536  638                  if (fnode)
 537  639                          smb_node_release(fnode);
 538  640                  if (dnode)
 539  641                          smb_node_release(dnode);
 540  642          } else {
 541      -                *ret_node = fnode;
      643 +                if (mnt_pn != NULL) {
      644 +                        *ret_node = mnt_node;
      645 +                        if (fnode != NULL)
      646 +                                smb_node_release(fnode);
      647 +                } else {
      648 +                        *ret_node = fnode;
      649 +                }
 542  650  
 543  651                  if (dir_node)
 544  652                          *dir_node = dnode;
 545  653                  else
 546  654                          smb_node_release(dnode);
 547  655          }
 548  656  
 549  657          kmem_free(component, MAXNAMELEN);
 550  658          kmem_free(real_name, MAXNAMELEN);
 551  659          (void) pn_free(&pn);
↓ open down ↓ 348 lines elided ↑ open up ↑
 900 1008                  return (B_FALSE);
 901 1009          }
 902 1010  
 903 1011          /* If there are wildcards in pn->pn_pname -> OBJECT_NAME_INVALID */
 904 1012          if (pn->pn_pname && smb_contains_wildcards(pn->pn_pname)) {
 905 1013                  smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
 906 1014                      ERRDOS, ERROR_INVALID_NAME);
 907 1015                  return (B_FALSE);
 908 1016          }
 909 1017  
 910      -        /* If fname is "." -> INVALID_OBJECT_NAME */
     1018 +        /* If fname is "." -> OBJECT_NAME_INVALID */
 911 1019          if (pn->pn_fname && (strcmp(pn->pn_fname, ".") == 0)) {
 912 1020                  smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
 913      -                    ERRDOS, ERROR_PATH_NOT_FOUND);
     1021 +                    ERRDOS, ERROR_INVALID_NAME);
 914 1022                  return (B_FALSE);
 915 1023          }
 916 1024  
 917 1025          return (B_TRUE);
 918 1026  }
 919 1027  
 920 1028  /*
 921 1029   * smb_validate_dirname
 922 1030   *
 923 1031   * smb_pathname_validate() should have already been performed on pn.
↓ open down ↓ 53 lines elided ↑ open up ↑
 977 1085                  return (smb_validate_stream_name(sr, pn));
 978 1086  
 979 1087          return (B_TRUE);
 980 1088  }
 981 1089  
 982 1090  /*
 983 1091   * smb_stream_parse_name
 984 1092   *
 985 1093   * smb_stream_parse_name should only be called for a path that
 986 1094   * contains a valid named stream.  Path validation should have
 987      - * been performed before this function is called.
     1095 + * been performed before this function is called, typically by
     1096 + * calling smb_is_stream_name() just before this.
 988 1097   *
 989 1098   * Find the last component of path and split it into filename
 990 1099   * and stream name.
 991 1100   *
 992 1101   * On return the named stream type will be present.  The stream
 993 1102   * type defaults to ":$DATA", if it has not been defined
 994      - * For exmaple, 'stream' contains :<sname>:$DATA
     1103 + * For example, 'stream' contains :<sname>:$DATA
     1104 + *
     1105 + * Output args: filename, stream both MAXNAMELEN
 995 1106   */
 996 1107  void
 997 1108  smb_stream_parse_name(char *path, char *filename, char *stream)
 998 1109  {
 999 1110          char *fname, *sname, *stype;
     1111 +        size_t flen, slen;
1000 1112  
1001 1113          ASSERT(path);
1002 1114          ASSERT(filename);
1003 1115          ASSERT(stream);
1004 1116  
1005 1117          fname = strrchr(path, '\\');
1006 1118          fname = (fname == NULL) ? path : fname + 1;
1007      -        (void) strlcpy(filename, fname, MAXNAMELEN);
     1119 +        sname = strchr(fname, ':');
     1120 +        /* Caller makes sure there is a ':' in path. */
     1121 +        VERIFY(sname != NULL);
     1122 +        /* LINTED: possible ptrdiff_t overflow */
     1123 +        flen = sname - fname;
     1124 +        slen = strlen(sname);
1008 1125  
1009      -        sname = strchr(filename, ':');
1010      -        (void) strlcpy(stream, sname, MAXNAMELEN);
1011      -        *sname = '\0';
     1126 +        if (flen > (MAXNAMELEN-1))
     1127 +                flen = (MAXNAMELEN-1);
     1128 +        (void) strncpy(filename, fname, flen);
     1129 +        filename[flen] = '\0';
1012 1130  
     1131 +        if (slen > (MAXNAMELEN-1))
     1132 +                slen = (MAXNAMELEN-1);
     1133 +        (void) strncpy(stream, sname, slen);
     1134 +        stream[slen] = '\0';
     1135 +
     1136 +        /* Add a "stream type" if there isn't one. */
1013 1137          stype = strchr(stream + 1, ':');
1014 1138          if (stype == NULL)
1015 1139                  (void) strlcat(stream, ":$DATA", MAXNAMELEN);
1016 1140          else
1017 1141                  (void) smb_strupr(stype);
1018 1142  }
1019 1143  
1020 1144  /*
1021 1145   * smb_is_stream_name
1022 1146   *
↓ open down ↓ 20 lines elided ↑ open up ↑
1043 1167          if ((colonp == NULL) || (*(colonp+1) == '\0'))
1044 1168                  return (B_FALSE);
1045 1169  
1046 1170          if (strstr(path, "::"))
1047 1171                  return (B_FALSE);
1048 1172  
1049 1173          return (B_TRUE);
1050 1174  }
1051 1175  
1052 1176  /*
     1177 + * Is this stream node a "restricted" type?
     1178 + */
     1179 +boolean_t
     1180 +smb_strname_restricted(char *strname)
     1181 +{
     1182 +        char *stype;
     1183 +
     1184 +        stype = strrchr(strname, ':');
     1185 +        if (stype == NULL)
     1186 +                return (B_FALSE);
     1187 +
     1188 +        /*
     1189 +         * Only ":$CA" is restricted (for now).
     1190 +         */
     1191 +        if (strcmp(stype, ":$CA") == 0)
     1192 +                return (B_TRUE);
     1193 +
     1194 +        return (B_FALSE);
     1195 +}
     1196 +
     1197 +/*
1053 1198   * smb_validate_stream_name
1054 1199   *
1055 1200   * B_FALSE will be returned, and the error status ser in the sr, if:
1056 1201   * - the path is not a stream name
1057 1202   * - a path is specified but the fname is ommitted.
1058 1203   * - the stream_type is specified but not valid.
1059 1204   *
1060 1205   * Note: the stream type is case-insensitive.
1061 1206   */
1062 1207  boolean_t
1063 1208  smb_validate_stream_name(smb_request_t *sr, smb_pathname_t *pn)
1064 1209  {
1065 1210          static char *strmtype[] = {
     1211 +                "$CA",
1066 1212                  "$DATA",
1067 1213                  "$INDEX_ALLOCATION"
1068 1214          };
1069 1215          int i;
1070 1216  
1071 1217          ASSERT(pn);
1072 1218          ASSERT(pn->pn_sname);
1073 1219  
1074 1220          if ((!(pn->pn_sname)) ||
1075 1221              ((pn->pn_pname) && !(pn->pn_fname))) {
↓ open down ↓ 53 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX