Print this page
1575 untangle libmlrpc from SMB server
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
NEX-15052 Need a way to add appliance local user/group ACE from Windows
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-15052 Need a way to add appliance local user/group ACE from Windows
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-3106 ACL editor crash in Windows 2012 R2
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
re #12435 rb3958 r10 is added 2 times to panic info
re #12393 rb3935 Kerberos and smbd disagree about who is our AD server

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/smbsrv/libmlsvc/common/samr_svc.c
          +++ new/usr/src/lib/smbsrv/libmlsvc/common/samr_svc.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) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  24      - * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
       24 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  25   25   */
  26   26  
  27   27  /*
  28   28   * Security Accounts Manager RPC (SAMR) server-side interface.
  29   29   *
  30   30   * The SAM is a hierarchical database:
  31   31   * - If you want to talk to the SAM you need a SAM handle.
  32   32   * - If you want to work with a domain, use the SAM handle.
  33   33   *   to obtain a domain handle.
  34   34   * - Use domain handles to obtain user handles etc.
  35   35   */
  36   36  
  37   37  #include <strings.h>
  38   38  #include <unistd.h>
  39   39  #include <netdb.h>
  40   40  #include <assert.h>
  41   41  #include <grp.h>
       42 +#include <libmlrpc/libmlrpc.h>
  42   43  #include <smbsrv/libsmb.h>
  43      -#include <smbsrv/libmlrpc.h>
  44   44  #include <smbsrv/libmlsvc.h>
  45   45  #include <smbsrv/smbinfo.h>
  46   46  #include <smbsrv/nmpipes.h>
  47   47  #include <smbsrv/ndl/samrpc.ndl>
  48   48  #include <samlib.h>
  49   49  
  50   50  /*
  51   51   * The keys associated with the various handles dispensed by the SAMR
  52   52   * server.  These keys can be used to validate client activity.
  53   53   * These values are never passed over the wire so security shouldn't
↓ open down ↓ 41 lines elided ↑ open up ↑
  95   95  
  96   96  #define SAMR_VALID_DISPLEVEL(lvl) \
  97   97          (((lvl) >= DomainDisplayUser) && ((lvl) <= DomainDisplayOemGroup))
  98   98  
  99   99  #define SAMR_SUPPORTED_DISPLEVEL(lvl) (lvl == DomainDisplayUser)
 100  100  
 101  101  static ndr_hdid_t *samr_hdalloc(ndr_xa_t *, samr_key_t, smb_domain_type_t,
 102  102      DWORD);
 103  103  static void samr_hdfree(ndr_xa_t *, ndr_hdid_t *);
 104  104  static ndr_handle_t *samr_hdlookup(ndr_xa_t *, ndr_hdid_t *, samr_key_t);
      105 +static ndr_handle_t *samr_hdlookup_any(ndr_xa_t *, ndr_hdid_t *);
 105  106  static int samr_call_stub(ndr_xa_t *mxa);
 106  107  static DWORD samr_s_enum_local_domains(struct samr_EnumLocalDomain *,
 107  108      ndr_xa_t *);
 108  109  
 109  110  static ndr_stub_table_t samr_stub_table[];
 110  111  
 111  112  static ndr_service_t samr_service = {
 112  113          "SAMR",                         /* name */
 113  114          "Security Accounts Manager",    /* desc */
 114  115          "\\samr",                       /* endpoint */
↓ open down ↓ 92 lines elided ↑ open up ↑
 207  208          if ((data = (samr_keydata_t *)hd->nh_data) == NULL)
 208  209                  return (NULL);
 209  210  
 210  211          if (data->kd_key != key)
 211  212                  return (NULL);
 212  213  
 213  214          return (hd);
 214  215  }
 215  216  
 216  217  /*
      218 + * Handle lookup wrapper to validate the local context,
      219 + * but don't limit to one type.
      220 + */
      221 +static ndr_handle_t *
      222 +samr_hdlookup_any(ndr_xa_t *mxa, ndr_hdid_t *id)
      223 +{
      224 +        ndr_handle_t *hd;
      225 +
      226 +        if ((hd = ndr_hdlookup(mxa, id)) == NULL)
      227 +                return (NULL);
      228 +
      229 +        if (hd->nh_data == NULL)
      230 +                return (NULL);
      231 +
      232 +        return (hd);
      233 +}
      234 +
      235 +/*
 217  236   * samr_s_Connect
 218  237   *
 219  238   * This is a request to connect to the local SAM database. We don't
 220  239   * support any form of update request and our database doesn't
 221  240   * contain any private information, so there is little point in
 222  241   * doing any access access checking here.
 223  242   *
 224  243   * Return a handle for use with subsequent SAM requests.
 225  244   */
 226  245  static int
↓ open down ↓ 27 lines elided ↑ open up ↑
 254  273          ndr_hdid_t *id = (ndr_hdid_t *)&param->handle;
 255  274  
 256  275          samr_hdfree(mxa, id);
 257  276  
 258  277          bzero(&param->result_handle, sizeof (samr_handle_t));
 259  278          param->status = 0;
 260  279          return (NDR_DRC_OK);
 261  280  }
 262  281  
 263  282  /*
      283 + * samr_s_QuerySecObject
      284 + */
      285 +static int
      286 +samr_s_QuerySecObject(void *arg, ndr_xa_t *mxa)
      287 +{
      288 +        struct samr_QuerySecObject      *param = arg;
      289 +        ndr_hdid_t                      *id;
      290 +        uint32_t                        status;
      291 +        struct samr_sec_desc            *sd;
      292 +
      293 +        id = (ndr_hdid_t *)&param->obj_handle;
      294 +        if (samr_hdlookup_any(mxa, id) == NULL) {
      295 +                status = NT_STATUS_INVALID_HANDLE;
      296 +                goto QuerySecObjectError;
      297 +        }
      298 +
      299 +        param->sd = NDR_MALLOC(mxa, sizeof (samr_sd_t));
      300 +        if (param->sd == NULL) {
      301 +                status = NT_STATUS_NO_MEMORY;
      302 +                goto QuerySecObjectError;
      303 +        }
      304 +        param->sd->length = sizeof (struct samr_sec_desc);
      305 +
      306 +        sd = NDR_MALLOC(mxa, param->sd->length);
      307 +        if (sd == NULL) {
      308 +                status = NT_STATUS_NO_MEMORY;
      309 +                goto QuerySecObjectError;
      310 +        }
      311 +        bzero(sd, param->sd->length);
      312 +        sd->Revision = 1;
      313 +        sd->Control = SE_SELF_RELATIVE;
      314 +
      315 +        param->sd->data = (void *)sd;
      316 +        param->status = NT_STATUS_SUCCESS;
      317 +        return (NDR_DRC_OK);
      318 +
      319 +QuerySecObjectError:
      320 +        bzero(param, sizeof (struct samr_QuerySecObject));
      321 +        param->status = NT_SC_ERROR(status);
      322 +        return (NDR_DRC_OK);
      323 +}
      324 +
      325 +/*
 264  326   * samr_s_LookupDomain
 265  327   *
 266  328   * This is a request to map a domain name to a domain SID. We can map
 267  329   * the primary domain name, our local domain name (hostname) and the
 268  330   * builtin domain names to the appropriate SID. Anything else will be
 269  331   * rejected.
 270  332   */
 271  333  static int
 272  334  samr_s_LookupDomain(void *arg, ndr_xa_t *mxa)
 273  335  {
↓ open down ↓ 408 lines elided ↑ open up ↑
 682  744   *
 683  745   * Returns:
 684  746   * NT_STATUS_SUCCESS
 685  747   * NT_STATUS_ACCESS_DENIED
 686  748   * NT_STATUS_INVALID_INFO_CLASS
 687  749   */
 688  750  /*ARGSUSED*/
 689  751  static int
 690  752  samr_s_QueryUserInfo(void *arg, ndr_xa_t *mxa)
 691  753  {
 692      -        static uint16_t                 owf_buf[8];
 693      -        static uint8_t                  hour_buf[SAMR_SET_USER_HOURS_SZ];
 694  754          struct samr_QueryUserInfo       *param = arg;
 695  755          struct samr_QueryUserInfo21     *all_info;
 696  756          ndr_hdid_t                      *id;
 697  757          ndr_handle_t                    *hd;
 698  758          samr_keydata_t                  *data;
 699  759          smb_domain_t                    di;
 700  760          smb_account_t                   account;
 701  761          smb_sid_t                       *sid;
 702  762          uint32_t                        status;
 703  763  
↓ open down ↓ 21 lines elided ↑ open up ↑
 725  785          }
 726  786  
 727  787          if (smb_sam_lookup_sid(sid, &account) != NT_STATUS_SUCCESS) {
 728  788                  status = NT_STATUS_ACCESS_DENIED;
 729  789                  goto QueryUserInfoError;
 730  790          }
 731  791  
 732  792          all_info = &param->ru.info21;
 733  793          bzero(all_info, sizeof (struct samr_QueryUserInfo21));
 734  794  
 735      -        all_info->WhichFields = SAMR_USER_ALL_USERNAME | SAMR_USER_ALL_USERID;
      795 +        all_info->WhichFields = SAMR_USER_ALL_USERNAME | SAMR_USER_ALL_USERID |
      796 +            SAMR_USER_ALL_FULLNAME | SAMR_USER_ALL_USERACCOUNTCONTROL |
      797 +            SAMR_USER_ALL_ADMINCOMMENT;
 736  798  
 737  799          (void) NDR_MSTRING(mxa, account.a_name,
 738  800              (ndr_mstring_t *)&all_info->UserName);
      801 +        (void) NDR_MSTRING(mxa, account.a_name,
      802 +            (ndr_mstring_t *)&all_info->FullName);
      803 +        (void) NDR_MSTRING(mxa, "",
      804 +            (ndr_mstring_t *)&all_info->AdminComment);
      805 +
 739  806          all_info->UserId = data->kd_rid;
      807 +        all_info->UserAccountControl = SAMR_AF_NORMAL_ACCOUNT |
      808 +            SAMR_AF_DONT_EXPIRE_PASSWD;
      809 +        if ((account.a_flags & SMB_PWF_DISABLE) != 0)
      810 +                all_info->UserAccountControl |= SAMR_AF_ACCOUNTDISABLE;
 740  811  
 741      -        all_info->LmOwfPassword.length = 16;
 742      -        all_info->LmOwfPassword.maxlen = 16;
 743      -        all_info->LmOwfPassword.buf = owf_buf;
 744      -        all_info->NtOwfPassword.length = 16;
 745      -        all_info->NtOwfPassword.maxlen = 16;
 746      -        all_info->NtOwfPassword.buf = owf_buf;
 747      -        all_info->LogonHours.units_per_week = SAMR_HOURS_PER_WEEK;
 748      -        all_info->LogonHours.hours = hour_buf;
 749      -
 750  812          param->address = 1;
 751  813          param->switch_index = SAMR_QUERY_USER_ALL_INFO;
 752  814          param->status = NT_STATUS_SUCCESS;
 753  815          smb_account_free(&account);
 754  816          smb_sid_free(sid);
 755  817          return (NDR_DRC_OK);
 756  818  
 757  819  QueryUserInfoError:
 758  820          smb_sid_free(sid);
 759  821          bzero(param, sizeof (struct samr_QueryUserInfo));
↓ open down ↓ 1084 lines elided ↑ open up ↑
1844 1906  {
1845 1907          struct samr_Connect5 *param = arg;
1846 1908  
1847 1909          bzero(param, sizeof (struct samr_Connect5));
1848 1910          return (NDR_DRC_FAULT_REQUEST_OPNUM_INVALID);
1849 1911  }
1850 1912  
1851 1913  static ndr_stub_table_t samr_stub_table[] = {
1852 1914          { samr_s_Connect,               SAMR_OPNUM_Connect },
1853 1915          { samr_s_CloseHandle,           SAMR_OPNUM_CloseHandle },
     1916 +        { samr_s_QuerySecObject,        SAMR_OPNUM_QuerySecObject },
1854 1917          { samr_s_LookupDomain,          SAMR_OPNUM_LookupDomain },
1855 1918          { samr_s_EnumLocalDomains,      SAMR_OPNUM_EnumLocalDomains },
1856 1919          { samr_s_OpenDomain,            SAMR_OPNUM_OpenDomain },
1857 1920          { samr_s_QueryDomainInfo,       SAMR_OPNUM_QueryDomainInfo },
1858 1921          { samr_s_QueryInfoDomain2,      SAMR_OPNUM_QueryInfoDomain2 },
1859 1922          { samr_s_LookupNames,           SAMR_OPNUM_LookupNames },
1860 1923          { samr_s_OpenUser,              SAMR_OPNUM_OpenUser },
1861 1924          { samr_s_DeleteUser,            SAMR_OPNUM_DeleteUser },
1862 1925          { samr_s_QueryUserInfo,         SAMR_OPNUM_QueryUserInfo },
1863 1926          { samr_s_QueryUserGroups,       SAMR_OPNUM_QueryUserGroups },
↓ open down ↓ 104 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX