Print this page
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/common/smbclnt/smbfs_ntacl.c
          +++ new/usr/src/common/smbclnt/smbfs_ntacl.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  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  /*
  23   23   * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * ACL conversion support for smbfs
  28   29   * (To/from NT/ZFS-style ACLs.)
  29   30   */
  30   31  
  31   32  #include <sys/types.h>
  32   33  #include <sys/errno.h>
  33   34  #include <sys/acl.h>
  34   35  #include <sys/byteorder.h>
  35   36  
  36      -#ifdef _KERNEL
       37 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
  37   38  
  38   39  #include <sys/cred.h>
  39   40  #include <sys/cmn_err.h>
  40   41  #include <sys/kmem.h>
  41   42  #include <sys/sunddi.h>
  42   43  #include <sys/vnode.h>
  43   44  #include <sys/vfs.h>
  44   45  
  45      -#include <sys/kidmap.h>
  46      -
  47   46  #else   /* _KERNEL */
  48   47  
  49   48  #include <stdio.h>
  50   49  #include <stdlib.h>
  51   50  #include <strings.h>
  52   51  
  53      -#include <idmap.h>
       52 +#endif  /* _KERNEL */
  54   53  
       54 +#ifdef _KERNEL
       55 +#include <sys/kidmap.h>
       56 +#else   /* _KERNEL */
       57 +#include <idmap.h>
  55   58  #endif  /* _KERNEL */
  56   59  
  57   60  #include <netsmb/mchain.h>
  58   61  #include <netsmb/smb.h>
  59   62  #include "smbfs_ntacl.h"
  60   63  
  61   64  #define NT_SD_REVISION  1
  62   65  #define NT_ACL_REVISION 2
  63   66  
  64      -#ifdef _KERNEL
       67 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
  65   68  #define MALLOC(size) kmem_alloc(size, KM_SLEEP)
  66   69  #define FREESZ(p, sz) kmem_free(p, sz)
  67   70  #else   /* _KERNEL */
  68   71  #define MALLOC(size) malloc(size)
  69   72  /*
  70   73   * Define FREESZ() as inline function so the compiler will not
  71   74   * trigger variable set but not used warning for sz in calling function.
  72   75   */
  73   76  /* ARGSUSED */
  74   77  static inline void
↓ open down ↓ 805 lines elided ↑ open up ↑
 880  883   * Convert an internal SD to a ZFS-style ACL.
 881  884   * Note optional args: vsa/acl, uidp, gidp.
 882  885   *
 883  886   * This makes two passes over the SD, the first building a
 884  887   * "batch" request for idmap with results in mapinfo, the
 885  888   * second building a ZFS-style ACL using the idmap results.
 886  889   */
 887  890  int
 888  891  smbfs_acl_sd2zfs(
 889  892          i_ntsd_t *sd,
 890      -#ifdef  _KERNEL
      893 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
 891  894          vsecattr_t *acl_info,
 892  895  #else /* _KERNEL */
 893  896          acl_t *acl_info,
 894  897  #endif /* _KERNEL */
 895  898          uid_t *uidp, gid_t *gidp)
 896  899  {
 897  900          struct mapinfo2uid *mip, *mapinfo = NULL;
 898  901          int error, i, mapcnt, zacecnt, zacl_size;
 899  902          ace_t *zacep0, *zacep;
 900  903          uid_t own_uid = (uid_t)-1;
 901  904          gid_t own_gid = (gid_t)-1;
 902  905          i_ntacl_t *ntacl;
 903  906          i_ntace_t **ntacep;
 904  907          idmap_get_handle_t *idmap_gh = NULL;
 905  908          idmap_stat      idms;
 906  909  
 907  910          /*
 908  911           * sanity checks
 909  912           */
 910  913          if (acl_info) {
 911      -#ifndef _KERNEL
      914 +#if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
 912  915                  if (acl_info->acl_type != ACE_T ||
 913  916                      acl_info->acl_aclp != NULL ||
 914  917                      acl_info->acl_entry_size != sizeof (ace_t))
 915  918                          return (EINVAL);
 916      -#endif /* _KERNEL */
      919 +#endif /* !_KERNEL */
 917  920                  if ((sd->sd_flags & SD_DACL_PRESENT) == 0)
 918  921                          return (EINVAL);
 919  922          }
 920  923  
 921  924          /*
 922  925           * How many SID mappings will we need?
 923  926           */
 924  927          mapcnt = 0;
 925  928          if (sd->sd_owner)
 926  929                  mapcnt++;
↓ open down ↓ 183 lines elided ↑ open up ↑
1110 1113                   * at least one ACE, so add one giving
1111 1114                   * the owner the usual implied access.
1112 1115                   */
1113 1116                  zacep->a_who = (uid_t)-1;
1114 1117                  zacep->a_access_mask = ACE_READ_ATTRIBUTES | \
1115 1118                      ACE_READ_ACL | ACE_WRITE_ACL;
1116 1119                  zacep->a_flags = ACE_OWNER;
1117 1120                  zacep->a_type = ACCESS_ALLOWED_ACE_TYPE;
1118 1121          }
1119 1122  
1120      -#ifdef _KERNEL
     1123 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
1121 1124          acl_info->vsa_aclcnt = zacecnt;
1122 1125          acl_info->vsa_aclentp = zacep0;
1123 1126          acl_info->vsa_aclentsz = zacl_size;
1124 1127  #else   /* _KERNEL */
1125 1128          acl_info->acl_cnt = zacecnt;
1126 1129          acl_info->acl_aclp = zacep0;
1127 1130  #endif  /* _KERNEL */
1128 1131  
1129 1132  done:
1130 1133          error = 0;
↓ open down ↓ 88 lines elided ↑ open up ↑
1219 1222          err = EINVAL;
1220 1223          if (ridp != NULL)
1221 1224                  sacnt--; /* Last SA not from string */
1222 1225          p = np;
1223 1226          for (i = 0; i < sacnt; i++) {
1224 1227                  if (*p != '-') {
1225 1228                          err = EINVAL;
1226 1229                          goto out;
1227 1230                  }
1228 1231                  p++;
1229      -#ifdef  _KERNEL
     1232 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
1230 1233                  err = ddi_strtoul(p, &np, 10, &sa);
1231 1234                  if (err != 0)
1232 1235                          goto out;
1233 1236  #else   /* _KERNEL */
1234 1237                  sa = strtoul(p, &np, 10);
1235 1238                  if (p == np) {
1236 1239                          err = EINVAL;
1237 1240                          goto out;
1238 1241                  }
1239 1242  #endif  /* _KERNEL */
↓ open down ↓ 162 lines elided ↑ open up ↑
1402 1405   * Always need to pass uid+gid, either the new
1403 1406   * (when setting them) or existing, so that any
1404 1407   * owner@ or group@ ACEs can be translated.
1405 1408   *
1406 1409   * This makes two passes over the ZFS ACL.  The first builds a
1407 1410   * "batch" request for idmap with results in mapinfo, and the
1408 1411   * second builds the NT SD using the idmap SID results.
1409 1412   */
1410 1413  int
1411 1414  smbfs_acl_zfs2sd(
1412      -#ifdef  _KERNEL
     1415 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
1413 1416          vsecattr_t *acl_info,
1414 1417  #else /* _KERNEL */
1415 1418          acl_t *acl_info,
1416 1419  #endif /* _KERNEL */
1417 1420          uid_t own_uid,
1418 1421          gid_t own_gid,
1419 1422          uint32_t selector,
1420 1423          i_ntsd_t **sdp)
1421 1424  {
1422 1425          struct mapinfo2sid *mip, *mip_acl, *mapinfo = NULL;
↓ open down ↓ 25 lines elided ↑ open up ↑
1448 1451                  mapcnt++;
1449 1452          }
1450 1453          if (selector & (DACL_SECURITY_INFORMATION |
1451 1454              SACL_SECURITY_INFORMATION)) {
1452 1455                  if (acl_info == NULL)
1453 1456                          return (EINVAL);
1454 1457                  if (own_uid == (uid_t)-1)
1455 1458                          return (EINVAL);
1456 1459                  if (own_gid == (gid_t)-1)
1457 1460                          return (EINVAL);
1458      -#ifdef  _KERNEL
     1461 +#if defined(_KERNEL) || defined(_FAKE_KERNEL)
1459 1462                  if ((acl_info->vsa_mask & VSA_ACE) == 0)
1460 1463                          return (EINVAL);
1461 1464                  zacecnt = acl_info->vsa_aclcnt;
1462 1465                  zacevec = acl_info->vsa_aclentp;
1463 1466  #else   /* _KERNEL */
1464 1467                  if (acl_info->acl_type != ACE_T ||
1465 1468                      acl_info->acl_entry_size != sizeof (ace_t))
1466 1469                          return (EINVAL);
1467 1470                  zacecnt = acl_info->acl_cnt;
1468 1471                  zacevec = acl_info->acl_aclp;
↓ open down ↓ 238 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX