LCOV - code coverage report
Current view: top level - source3/rpc_client - cli_lsarpc.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 166 297 55.9 %
Date: 2023-11-21 12:31:41 Functions: 10 13 76.9 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    RPC pipe client
       4             :    Copyright (C) Tim Potter                        2000-2001,
       5             :    Copyright (C) Andrew Tridgell              1992-1997,2000,
       6             :    Copyright (C) Rafal Szczesniak                       2002
       7             :    Copyright (C) Jeremy Allison                         2005.
       8             :    Copyright (C) Michael Adam                           2007.
       9             :    Copyright (C) Guenther Deschner                      2008.
      10             : 
      11             :    This program is free software; you can redistribute it and/or modify
      12             :    it under the terms of the GNU General Public License as published by
      13             :    the Free Software Foundation; either version 3 of the License, or
      14             :    (at your option) any later version.
      15             : 
      16             :    This program is distributed in the hope that it will be useful,
      17             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19             :    GNU General Public License for more details.
      20             : 
      21             :    You should have received a copy of the GNU General Public License
      22             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "includes.h"
      26             : #include "rpc_client/rpc_client.h"
      27             : #include "../librpc/gen_ndr/ndr_lsa_c.h"
      28             : #include "rpc_client/cli_lsarpc.h"
      29             : #include "rpc_client/init_lsa.h"
      30             : #include "../libcli/security/security.h"
      31             : #include "lsa.h"
      32             : 
      33             : /** @defgroup lsa LSA - Local Security Architecture
      34             :  *  @ingroup rpc_client
      35             :  *
      36             :  * @{
      37             :  **/
      38             : 
      39             : /**
      40             :  * @file cli_lsarpc.c
      41             :  *
      42             :  * RPC client routines for the LSA RPC pipe.  LSA means "local
      43             :  * security authority", which is half of a password database.
      44             :  **/
      45             : 
      46        8500 : NTSTATUS dcerpc_lsa_open_policy(struct dcerpc_binding_handle *h,
      47             :                                 TALLOC_CTX *mem_ctx,
      48             :                                 bool sec_qos,
      49             :                                 uint32_t des_access,
      50             :                                 struct policy_handle *pol,
      51             :                                 NTSTATUS *result)
      52             : {
      53        8500 :         struct lsa_ObjectAttribute attr = { .len = 0x18, };
      54           0 :         struct lsa_QosInfo qos;
      55        8500 :         uint16_t system_name = '\\';
      56             : 
      57        8500 :         if (sec_qos) {
      58        7556 :                 qos.len                 = 0xc;
      59        7556 :                 qos.impersonation_level = 2;
      60        7556 :                 qos.context_mode        = 1;
      61        7556 :                 qos.effective_only      = 0;
      62             : 
      63        7556 :                 attr.sec_qos            = &qos;
      64             :         }
      65             : 
      66        8500 :         return dcerpc_lsa_OpenPolicy(h,
      67             :                                      mem_ctx,
      68             :                                      &system_name,
      69             :                                      &attr,
      70             :                                      des_access,
      71             :                                      pol,
      72             :                                      result);
      73             : }
      74             : 
      75             : /** Open a LSA policy handle
      76             :  *
      77             :  * @param cli Handle on an initialised SMB connection */
      78             : 
      79        8500 : NTSTATUS rpccli_lsa_open_policy(struct rpc_pipe_client *cli,
      80             :                                 TALLOC_CTX *mem_ctx,
      81             :                                 bool sec_qos, uint32_t des_access,
      82             :                                 struct policy_handle *pol)
      83             : {
      84           0 :         NTSTATUS status;
      85        8500 :         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
      86             : 
      87        8500 :         status = dcerpc_lsa_open_policy(cli->binding_handle,
      88             :                                         mem_ctx,
      89             :                                         sec_qos,
      90             :                                         des_access,
      91             :                                         pol,
      92             :                                         &result);
      93        8500 :         if (!NT_STATUS_IS_OK(status)) {
      94           0 :                 return status;
      95             :         }
      96             : 
      97        8500 :         return result;
      98             : }
      99             : 
     100          40 : NTSTATUS dcerpc_lsa_open_policy2(struct dcerpc_binding_handle *h,
     101             :                                  TALLOC_CTX *mem_ctx,
     102             :                                  const char *srv_name_slash,
     103             :                                  bool sec_qos,
     104             :                                  uint32_t des_access,
     105             :                                  struct policy_handle *pol,
     106             :                                  NTSTATUS *result)
     107             : {
     108          40 :         struct lsa_ObjectAttribute attr = { .len = 0x18, };
     109           0 :         struct lsa_QosInfo qos;
     110             : 
     111          40 :         if (sec_qos) {
     112          40 :                 qos.len                 = 0xc;
     113          40 :                 qos.impersonation_level = 2;
     114          40 :                 qos.context_mode        = 1;
     115          40 :                 qos.effective_only      = 0;
     116             : 
     117          40 :                 attr.sec_qos            = &qos;
     118             :         }
     119             : 
     120          40 :         return dcerpc_lsa_OpenPolicy2(h,
     121             :                                       mem_ctx,
     122             :                                       srv_name_slash,
     123             :                                       &attr,
     124             :                                       des_access,
     125             :                                       pol,
     126             :                                       result);
     127             : }
     128             : 
     129             : /** Open a LSA policy handle
     130             :   *
     131             :   * @param cli Handle on an initialised SMB connection
     132             :   */
     133             : 
     134          40 : NTSTATUS rpccli_lsa_open_policy2(struct rpc_pipe_client *cli,
     135             :                                  TALLOC_CTX *mem_ctx, bool sec_qos,
     136             :                                  uint32_t des_access, struct policy_handle *pol)
     137             : {
     138           0 :         NTSTATUS status;
     139          40 :         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     140             : 
     141          40 :         status = dcerpc_lsa_open_policy2(cli->binding_handle,
     142             :                                          mem_ctx,
     143          40 :                                          cli->srv_name_slash,
     144             :                                          sec_qos,
     145             :                                          des_access,
     146             :                                          pol,
     147             :                                          &result);
     148          40 :         if (!NT_STATUS_IS_OK(status)) {
     149           0 :                 return status;
     150             :         }
     151             : 
     152          40 :         return result;
     153             : }
     154             : 
     155             : /* Lookup a list of sids
     156             :  *
     157             :  * internal version withOUT memory allocation of the target arrays.
     158             :  * this assumes sufficiently sized arrays to store domains, names and types. */
     159             : 
     160        7078 : static NTSTATUS dcerpc_lsa_lookup_sids_noalloc(struct dcerpc_binding_handle *h,
     161             :                                                TALLOC_CTX *mem_ctx,
     162             :                                                TALLOC_CTX *domains_ctx,
     163             :                                                TALLOC_CTX *names_ctx,
     164             :                                                struct policy_handle *pol,
     165             :                                                int num_sids,
     166             :                                                const struct dom_sid *sids,
     167             :                                                enum lsa_LookupNamesLevel level,
     168             :                                                char **domains,
     169             :                                                char **names,
     170             :                                                enum lsa_SidType *types,
     171             :                                                bool use_lookupsids3,
     172             :                                                NTSTATUS *presult)
     173             : {
     174           0 :         NTSTATUS status;
     175        7078 :         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     176           0 :         struct lsa_SidArray sid_array;
     177        7078 :         struct lsa_RefDomainList *ref_domains = NULL;
     178        7078 :         struct lsa_TransNameArray lsa_names = { .count = 0, };
     179        7078 :         uint32_t count = 0;
     180           0 :         int i;
     181             : 
     182        7078 :         sid_array.num_sids = num_sids;
     183        7078 :         sid_array.sids = talloc_array(mem_ctx, struct lsa_SidPtr, num_sids);
     184        7078 :         if (sid_array.sids == NULL) {
     185           0 :                 return NT_STATUS_NO_MEMORY;
     186             :         }
     187             : 
     188       14164 :         for (i = 0; i<num_sids; i++) {
     189        7086 :                 sid_array.sids[i].sid = dom_sid_dup(mem_ctx, &sids[i]);
     190        7086 :                 if (!sid_array.sids[i].sid) {
     191           0 :                         return NT_STATUS_NO_MEMORY;
     192             :                 }
     193             :         }
     194             : 
     195        7078 :         if (use_lookupsids3) {
     196           0 :                 struct lsa_TransNameArray2 lsa_names2;
     197           0 :                 uint32_t n;
     198             : 
     199           0 :                 ZERO_STRUCT(lsa_names2);
     200             : 
     201           0 :                 status = dcerpc_lsa_LookupSids3(h,
     202             :                                                 mem_ctx,
     203             :                                                 &sid_array,
     204             :                                                 &ref_domains,
     205             :                                                 &lsa_names2,
     206             :                                                 level,
     207             :                                                 &count,
     208             :                                                 LSA_LOOKUP_OPTION_SEARCH_ISOLATED_NAMES,
     209             :                                                 LSA_CLIENT_REVISION_2,
     210             :                                                 &result);
     211           0 :                 if (!NT_STATUS_IS_OK(status)) {
     212           0 :                         return status;
     213             :                 }
     214             : 
     215           0 :                 if (!NT_STATUS_LOOKUP_ERR(result)) {
     216           0 :                         lsa_names.count = lsa_names2.count;
     217           0 :                         lsa_names.names = talloc_array(mem_ctx,
     218             :                                                        struct lsa_TranslatedName,
     219             :                                                        lsa_names.count);
     220           0 :                         if (lsa_names.names == NULL) {
     221           0 :                                 return NT_STATUS_NO_MEMORY;
     222             :                         }
     223           0 :                         for (n=0; n < lsa_names.count; n++) {
     224           0 :                                 lsa_names.names[n].sid_type     = lsa_names2.names[n].sid_type;
     225           0 :                                 lsa_names.names[n].name         = lsa_names2.names[n].name;
     226           0 :                                 lsa_names.names[n].sid_index    = lsa_names2.names[n].sid_index;
     227             :                         }
     228             :                 }
     229             : 
     230             :         } else {
     231        7078 :                 status = dcerpc_lsa_LookupSids(h,
     232             :                                                mem_ctx,
     233             :                                                pol,
     234             :                                                &sid_array,
     235             :                                                &ref_domains,
     236             :                                                &lsa_names,
     237             :                                                level,
     238             :                                                &count,
     239             :                                                &result);
     240             :         }
     241             : 
     242        7078 :         DEBUG(10, ("LSA_LOOKUPSIDS returned status: '%s', result: '%s', "
     243             :                    "mapped count = %d'\n",
     244             :                    nt_errstr(status), nt_errstr(result), count));
     245             : 
     246        7078 :         if (!NT_STATUS_IS_OK(status)) {
     247           0 :                 return status;
     248             :         }
     249             : 
     250        7078 :         if (NT_STATUS_LOOKUP_ERR(result)) {
     251           0 :                 *presult = result;
     252           0 :                 return status;
     253             :         }
     254             : 
     255             :         /* Return output parameters */
     256        7078 :         if (NT_STATUS_EQUAL(result, NT_STATUS_NONE_MAPPED) ||
     257        7078 :             (count == 0))
     258             :         {
     259           0 :                 for (i = 0; i < num_sids; i++) {
     260           0 :                         (names)[i] = NULL;
     261           0 :                         (domains)[i] = NULL;
     262           0 :                         (types)[i] = SID_NAME_UNKNOWN;
     263             :                 }
     264           0 :                 *presult = NT_STATUS_NONE_MAPPED;
     265           0 :                 return status;
     266             :         }
     267             : 
     268       14164 :         for (i = 0; i < num_sids; i++) {
     269           0 :                 const char *name, *dom_name;
     270           0 :                 uint32_t dom_idx;
     271             : 
     272        7086 :                 if (i >= lsa_names.count) {
     273           0 :                         *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     274           0 :                         return status;
     275             :                 }
     276             : 
     277        7086 :                 dom_idx = lsa_names.names[i].sid_index;
     278             : 
     279             :                 /* Translate optimised name through domain index array */
     280             : 
     281        7086 :                 if (dom_idx != 0xffffffff) {
     282        7078 :                         if (ref_domains == NULL) {
     283           0 :                                 *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     284           0 :                                 return status;
     285             :                         }
     286        7078 :                         if (dom_idx >= ref_domains->count) {
     287           0 :                                 *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     288           0 :                                 return status;
     289             :                         }
     290             : 
     291        7078 :                         dom_name = ref_domains->domains[dom_idx].name.string;
     292        7078 :                         name = lsa_names.names[i].name.string;
     293             : 
     294        7078 :                         if (name) {
     295        7078 :                                 (names)[i] = talloc_strdup(names_ctx, name);
     296        7078 :                                 if ((names)[i] == NULL) {
     297           0 :                                         DEBUG(0, ("cli_lsa_lookup_sids_noalloc(): out of memory\n"));
     298           0 :                                         *presult = NT_STATUS_UNSUCCESSFUL;
     299           0 :                                         return status;
     300             :                                 }
     301             :                         } else {
     302           0 :                                 (names)[i] = NULL;
     303             :                         }
     304        7078 :                         domains[i] = talloc_strdup(domains_ctx,
     305             :                                                    dom_name ? dom_name : "");
     306        7078 :                         (types)[i] = lsa_names.names[i].sid_type;
     307        7078 :                         if ((domains)[i] == NULL) {
     308           0 :                                 DEBUG(0, ("cli_lsa_lookup_sids_noalloc(): out of memory\n"));
     309           0 :                                 *presult = NT_STATUS_UNSUCCESSFUL;
     310           0 :                                 return status;
     311             :                         }
     312             : 
     313             :                 } else {
     314           8 :                         (names)[i] = NULL;
     315           8 :                         (domains)[i] = NULL;
     316           8 :                         (types)[i] = SID_NAME_UNKNOWN;
     317             :                 }
     318             :         }
     319             : 
     320        7078 :         *presult = NT_STATUS_OK;
     321        7078 :         return status;
     322             : }
     323             : 
     324             : /* Lookup a list of sids
     325             :  *
     326             :  * do it the right way: there is a limit (of 20480 for w2k3) entries
     327             :  * returned by this call. when the sids list contains more entries,
     328             :  * empty lists are returned. This version of lsa_lookup_sids passes
     329             :  * the list of sids in hunks of LOOKUP_SIDS_HUNK_SIZE to the lsa call. */
     330             : 
     331             : /* This constant defines the limit of how many sids to look up
     332             :  * in one call (maximum). the limit from the server side is
     333             :  * at 20480 for win2k3, but we keep it at a save 1000 for now. */
     334             : #define LOOKUP_SIDS_HUNK_SIZE 1000
     335             : 
     336        7078 : NTSTATUS dcerpc_lsa_lookup_sids_generic(struct dcerpc_binding_handle *h,
     337             :                                         TALLOC_CTX *mem_ctx,
     338             :                                         struct policy_handle *pol,
     339             :                                         int num_sids,
     340             :                                         const struct dom_sid *sids,
     341             :                                         enum lsa_LookupNamesLevel level,
     342             :                                         char ***pdomains,
     343             :                                         char ***pnames,
     344             :                                         enum lsa_SidType **ptypes,
     345             :                                         bool use_lookupsids3,
     346             :                                         NTSTATUS *presult)
     347             : {
     348        7078 :         NTSTATUS status = NT_STATUS_OK;
     349        7078 :         NTSTATUS result = NT_STATUS_OK;
     350        7078 :         int sids_left = 0;
     351        7078 :         int sids_processed = 0;
     352        7078 :         const struct dom_sid *hunk_sids = sids;
     353           0 :         char **hunk_domains;
     354           0 :         char **hunk_names;
     355           0 :         enum lsa_SidType *hunk_types;
     356        7078 :         char **domains = NULL;
     357        7078 :         char **names = NULL;
     358        7078 :         enum lsa_SidType *types = NULL;
     359        7078 :         bool have_mapped = false;
     360        7078 :         bool have_unmapped = false;
     361             : 
     362        7078 :         if (num_sids) {
     363        7078 :                 domains = talloc_zero_array(mem_ctx, char *, num_sids);
     364        7078 :                 if (domains == NULL) {
     365           0 :                         DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
     366           0 :                         status = NT_STATUS_NO_MEMORY;
     367           0 :                         goto fail;
     368             :                 }
     369             : 
     370        7078 :                 names = talloc_zero_array(mem_ctx, char *, num_sids);
     371        7078 :                 if (names == NULL) {
     372           0 :                         DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
     373           0 :                         status = NT_STATUS_NO_MEMORY;
     374           0 :                         goto fail;
     375             :                 }
     376             : 
     377        7078 :                 types = talloc_zero_array(mem_ctx, enum lsa_SidType, num_sids);
     378        7078 :                 if (types == NULL) {
     379           0 :                         DEBUG(0, ("rpccli_lsa_lookup_sids(): out of memory\n"));
     380           0 :                         status = NT_STATUS_NO_MEMORY;
     381           0 :                         goto fail;
     382             :                 }
     383             :         }
     384             : 
     385        7078 :         sids_left = num_sids;
     386        7078 :         hunk_domains = domains;
     387        7078 :         hunk_names = names;
     388        7078 :         hunk_types = types;
     389             : 
     390       14156 :         while (sids_left > 0) {
     391           0 :                 int hunk_num_sids;
     392        7078 :                 NTSTATUS hunk_result = NT_STATUS_UNSUCCESSFUL;
     393             : 
     394        7078 :                 hunk_num_sids = ((sids_left > LOOKUP_SIDS_HUNK_SIZE)
     395             :                                 ? LOOKUP_SIDS_HUNK_SIZE
     396             :                                 : sids_left);
     397             : 
     398        7078 :                 DEBUG(10, ("rpccli_lsa_lookup_sids: processing items "
     399             :                            "%d -- %d of %d.\n",
     400             :                            sids_processed,
     401             :                            sids_processed + hunk_num_sids - 1,
     402             :                            num_sids));
     403             : 
     404        7078 :                 status = dcerpc_lsa_lookup_sids_noalloc(h,
     405             :                                                         mem_ctx,
     406             :                                                         (TALLOC_CTX *)domains,
     407             :                                                         (TALLOC_CTX *)names,
     408             :                                                         pol,
     409             :                                                         hunk_num_sids,
     410             :                                                         hunk_sids,
     411             :                                                         level,
     412             :                                                         hunk_domains,
     413             :                                                         hunk_names,
     414             :                                                         hunk_types,
     415             :                                                         use_lookupsids3,
     416             :                                                         &hunk_result);
     417        7078 :                 if (!NT_STATUS_IS_OK(status)) {
     418           0 :                         goto fail;
     419             :                 }
     420             : 
     421        7078 :                 if (!NT_STATUS_IS_OK(hunk_result) &&
     422           0 :                     !NT_STATUS_EQUAL(hunk_result, STATUS_SOME_UNMAPPED) &&
     423           0 :                     !NT_STATUS_EQUAL(hunk_result, NT_STATUS_NONE_MAPPED))
     424             :                 {
     425             :                         /* An actual error occurred */
     426           0 :                         *presult = hunk_result;
     427           0 :                         goto fail;
     428             :                 }
     429             : 
     430        7078 :                 if (NT_STATUS_IS_OK(hunk_result)) {
     431        7078 :                         have_mapped = true;
     432             :                 }
     433        7078 :                 if (NT_STATUS_EQUAL(hunk_result, NT_STATUS_NONE_MAPPED)) {
     434           0 :                         have_unmapped = true;
     435             :                 }
     436        7078 :                 if (NT_STATUS_EQUAL(hunk_result, STATUS_SOME_UNMAPPED)) {
     437             :                         int i;
     438           0 :                         for (i=0; i<hunk_num_sids; i++) {
     439           0 :                                 if (hunk_types[i] == SID_NAME_UNKNOWN) {
     440           0 :                                         have_unmapped = true;
     441             :                                 } else {
     442           0 :                                         have_mapped = true;
     443             :                                 }
     444             :                         }
     445             :                 }
     446             : 
     447        7078 :                 sids_left -= hunk_num_sids;
     448        7078 :                 sids_processed += hunk_num_sids;
     449        7078 :                 hunk_sids += hunk_num_sids;
     450        7078 :                 hunk_domains += hunk_num_sids;
     451        7078 :                 hunk_names += hunk_num_sids;
     452        7078 :                 hunk_types += hunk_num_sids;
     453             :         }
     454             : 
     455        7078 :         *pdomains = domains;
     456        7078 :         *pnames = names;
     457        7078 :         *ptypes = types;
     458             : 
     459        7078 :         if (!have_mapped) {
     460           0 :                 result = NT_STATUS_NONE_MAPPED;
     461             :         }
     462        7078 :         if (have_unmapped) {
     463           0 :                 result = STATUS_SOME_UNMAPPED;
     464             :         }
     465        7078 :         *presult = result;
     466             : 
     467        7078 :         return status;
     468             : 
     469           0 : fail:
     470           0 :         TALLOC_FREE(domains);
     471           0 :         TALLOC_FREE(names);
     472           0 :         TALLOC_FREE(types);
     473             : 
     474           0 :         return status;
     475             : }
     476             : 
     477           0 : NTSTATUS dcerpc_lsa_lookup_sids(struct dcerpc_binding_handle *h,
     478             :                                 TALLOC_CTX *mem_ctx,
     479             :                                 struct policy_handle *pol,
     480             :                                 int num_sids,
     481             :                                 const struct dom_sid *sids,
     482             :                                 char ***pdomains,
     483             :                                 char ***pnames,
     484             :                                 enum lsa_SidType **ptypes,
     485             :                                 NTSTATUS *result)
     486             : {
     487           0 :         enum lsa_LookupNamesLevel level = LSA_LOOKUP_NAMES_ALL;
     488           0 :         return dcerpc_lsa_lookup_sids_generic(h,
     489             :                                               mem_ctx,
     490             :                                               pol,
     491             :                                               num_sids,
     492             :                                               sids,
     493             :                                               level,
     494             :                                               pdomains,
     495             :                                               pnames,
     496             :                                               ptypes,
     497             :                                               false,
     498             :                                               result);
     499             : }
     500             : 
     501        7076 : NTSTATUS rpccli_lsa_lookup_sids(struct rpc_pipe_client *cli,
     502             :                                 TALLOC_CTX *mem_ctx,
     503             :                                 struct policy_handle *pol,
     504             :                                 int num_sids,
     505             :                                 const struct dom_sid *sids,
     506             :                                 char ***pdomains,
     507             :                                 char ***pnames,
     508             :                                 enum lsa_SidType **ptypes)
     509             : {
     510           0 :         NTSTATUS status;
     511        7076 :         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     512        7076 :         enum lsa_LookupNamesLevel level = LSA_LOOKUP_NAMES_ALL;
     513             : 
     514        7076 :         status = dcerpc_lsa_lookup_sids_generic(cli->binding_handle,
     515             :                                                 mem_ctx,
     516             :                                                 pol,
     517             :                                                 num_sids,
     518             :                                                 sids,
     519             :                                                 level,
     520             :                                                 pdomains,
     521             :                                                 pnames,
     522             :                                                 ptypes,
     523             :                                                 false,
     524             :                                                 &result);
     525        7076 :         if (!NT_STATUS_IS_OK(status)) {
     526           0 :                 return status;
     527             :         }
     528             : 
     529        7076 :         return result;
     530             : }
     531             : 
     532           0 : NTSTATUS dcerpc_lsa_lookup_sids3(struct dcerpc_binding_handle *h,
     533             :                                  TALLOC_CTX *mem_ctx,
     534             :                                  struct policy_handle *pol,
     535             :                                  int num_sids,
     536             :                                  const struct dom_sid *sids,
     537             :                                  char ***pdomains,
     538             :                                  char ***pnames,
     539             :                                  enum lsa_SidType **ptypes,
     540             :                                  NTSTATUS *result)
     541             : {
     542           0 :         enum lsa_LookupNamesLevel level = LSA_LOOKUP_NAMES_ALL;
     543           0 :         return dcerpc_lsa_lookup_sids_generic(h,
     544             :                                               mem_ctx,
     545             :                                               pol,
     546             :                                               num_sids,
     547             :                                               sids,
     548             :                                               level,
     549             :                                               pdomains,
     550             :                                               pnames,
     551             :                                               ptypes,
     552             :                                               true,
     553             :                                               result);
     554             : }
     555             : 
     556             : /** Lookup a list of names */
     557             : 
     558        1664 : NTSTATUS dcerpc_lsa_lookup_names_generic(struct dcerpc_binding_handle *h,
     559             :                                          TALLOC_CTX *mem_ctx,
     560             :                                          struct policy_handle *pol,
     561             :                                          uint32_t num_names,
     562             :                                          const char **names,
     563             :                                          const char ***dom_names,
     564             :                                          enum lsa_LookupNamesLevel level,
     565             :                                          struct dom_sid **sids,
     566             :                                          enum lsa_SidType **types,
     567             :                                          bool use_lookupnames4,
     568             :                                          NTSTATUS *presult)
     569             : {
     570           0 :         NTSTATUS status;
     571        1664 :         struct lsa_String *lsa_names = NULL;
     572        1664 :         struct lsa_RefDomainList *domains = NULL;
     573        1664 :         struct lsa_TransSidArray sid_array = { .count = 0, };
     574        1664 :         struct lsa_TransSidArray3 sid_array3 = { .count = 0, };
     575        1664 :         uint32_t count = 0;
     576           0 :         uint32_t i;
     577             : 
     578        1664 :         lsa_names = talloc_array(mem_ctx, struct lsa_String, num_names);
     579        1664 :         if (lsa_names == NULL) {
     580           0 :                 return NT_STATUS_NO_MEMORY;
     581             :         }
     582             : 
     583        3328 :         for (i = 0; i < num_names; i++) {
     584        1664 :                 init_lsa_String(&lsa_names[i], names[i]);
     585             :         }
     586             : 
     587        1664 :         if (use_lookupnames4) {
     588           0 :                 status = dcerpc_lsa_LookupNames4(h,
     589             :                                                  mem_ctx,
     590             :                                                  num_names,
     591             :                                                  lsa_names,
     592             :                                                  &domains,
     593             :                                                  &sid_array3,
     594             :                                                  level,
     595             :                                                  &count,
     596             :                                                  LSA_LOOKUP_OPTION_SEARCH_ISOLATED_NAMES,
     597             :                                                  LSA_CLIENT_REVISION_2,
     598             :                                                  presult);
     599             :         } else {
     600        1664 :                 status = dcerpc_lsa_LookupNames(h,
     601             :                                                 mem_ctx,
     602             :                                                 pol,
     603             :                                                 num_names,
     604             :                                                 lsa_names,
     605             :                                                 &domains,
     606             :                                                 &sid_array,
     607             :                                                 level,
     608             :                                                 &count,
     609             :                                                 presult);
     610             :         }
     611        1664 :         if (!NT_STATUS_IS_OK(status)) {
     612           0 :                 goto done;
     613             :         }
     614             : 
     615        1664 :         if (!NT_STATUS_IS_OK(*presult) &&
     616          22 :             !NT_STATUS_EQUAL(*presult, STATUS_SOME_UNMAPPED)) {
     617             :                 /* An actual error occurred */
     618          22 :                 goto done;
     619             :         }
     620             : 
     621             :         /* Return output parameters */
     622        1642 :         if (count == 0) {
     623           0 :                 *presult = NT_STATUS_NONE_MAPPED;
     624           0 :                 goto done;
     625             :         }
     626             : 
     627        1642 :         if (num_names) {
     628        1642 :                 *sids = talloc_zero_array(mem_ctx, struct dom_sid, num_names);
     629        1642 :                 if (*sids == NULL) {
     630           0 :                         DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
     631           0 :                         *presult = NT_STATUS_NO_MEMORY;
     632           0 :                         goto done;
     633             :                 }
     634             : 
     635        1642 :                 *types = talloc_zero_array(mem_ctx, enum lsa_SidType, num_names);
     636        1642 :                 if (*types == NULL) {
     637           0 :                         DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
     638           0 :                         *presult = NT_STATUS_NO_MEMORY;
     639           0 :                         goto done;
     640             :                 }
     641             : 
     642        1642 :                 if (dom_names != NULL) {
     643           0 :                         *dom_names = talloc_zero_array(mem_ctx, const char *, num_names);
     644           0 :                         if (*dom_names == NULL) {
     645           0 :                                 DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
     646           0 :                                 *presult = NT_STATUS_NO_MEMORY;
     647           0 :                                 goto done;
     648             :                         }
     649             :                 }
     650             :         } else {
     651           0 :                 *sids = NULL;
     652           0 :                 *types = NULL;
     653           0 :                 if (dom_names != NULL) {
     654           0 :                         *dom_names = NULL;
     655             :                 }
     656             :         }
     657             : 
     658        3284 :         for (i = 0; i < num_names; i++) {
     659           0 :                 uint32_t dom_idx;
     660        1642 :                 struct dom_sid *sid = &(*sids)[i];
     661             : 
     662        1642 :                 if (use_lookupnames4) {
     663           0 :                         if (i >= sid_array3.count) {
     664           0 :                                 *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     665           0 :                                 goto done;
     666             :                         }
     667             : 
     668           0 :                         dom_idx         = sid_array3.sids[i].sid_index;
     669           0 :                         (*types)[i]     = sid_array3.sids[i].sid_type;
     670             :                 } else {
     671        1642 :                         if (i >= sid_array.count) {
     672           0 :                                 *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     673           0 :                                 goto done;
     674             :                         }
     675             : 
     676        1642 :                         dom_idx         = sid_array.sids[i].sid_index;
     677        1642 :                         (*types)[i]     = sid_array.sids[i].sid_type;
     678             :                 }
     679             : 
     680             :                 /* Translate optimised sid through domain index array */
     681             : 
     682        1642 :                 if (dom_idx == 0xffffffff) {
     683             :                         /* Nothing to do, this is unknown */
     684           0 :                         ZERO_STRUCTP(sid);
     685           0 :                         (*types)[i] = SID_NAME_UNKNOWN;
     686           0 :                         continue;
     687             :                 }
     688        1642 :                 if (domains == NULL) {
     689           0 :                         *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     690           0 :                         goto done;
     691             :                 }
     692        1642 :                 if (dom_idx >= domains->count) {
     693           0 :                         *presult = NT_STATUS_INVALID_NETWORK_RESPONSE;
     694           0 :                         goto done;
     695             :                 }
     696             : 
     697        1642 :                 if (use_lookupnames4) {
     698           0 :                         sid_copy(sid, sid_array3.sids[i].sid);
     699             :                 } else {
     700        1642 :                         sid_copy(sid, domains->domains[dom_idx].sid);
     701             : 
     702        1642 :                         if (sid_array.sids[i].rid != 0xffffffff) {
     703        1604 :                                 sid_append_rid(sid, sid_array.sids[i].rid);
     704             :                         }
     705             :                 }
     706             : 
     707        1642 :                 if (dom_names == NULL) {
     708        1642 :                         continue;
     709             :                 }
     710             : 
     711           0 :                 (*dom_names)[i] = domains->domains[dom_idx].name.string;
     712             :         }
     713             : 
     714        1642 :  done:
     715        1664 :         return status;
     716             : }
     717             : 
     718        1664 : NTSTATUS dcerpc_lsa_lookup_names(struct dcerpc_binding_handle *h,
     719             :                                  TALLOC_CTX *mem_ctx,
     720             :                                  struct policy_handle *pol,
     721             :                                  uint32_t num_names,
     722             :                                  const char **names,
     723             :                                  const char ***dom_names,
     724             :                                  enum lsa_LookupNamesLevel level,
     725             :                                  struct dom_sid **sids,
     726             :                                  enum lsa_SidType **types,
     727             :                                  NTSTATUS *result)
     728             : {
     729        1664 :         return dcerpc_lsa_lookup_names_generic(h,
     730             :                                                mem_ctx,
     731             :                                                pol,
     732             :                                                num_names,
     733             :                                                names,
     734             :                                                dom_names,
     735             :                                                level,
     736             :                                                sids,
     737             :                                                types,
     738             :                                                false,
     739             :                                                result);
     740             : }
     741             : 
     742        1664 : NTSTATUS rpccli_lsa_lookup_names(struct rpc_pipe_client *cli,
     743             :                                  TALLOC_CTX *mem_ctx,
     744             :                                  struct policy_handle *pol,
     745             :                                  int num_names,
     746             :                                  const char **names,
     747             :                                  const char ***dom_names,
     748             :                                  int level,
     749             :                                  struct dom_sid **sids,
     750             :                                  enum lsa_SidType **types)
     751             : {
     752           0 :         NTSTATUS status;
     753        1664 :         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
     754             : 
     755        1664 :         status = dcerpc_lsa_lookup_names(cli->binding_handle,
     756             :                                          mem_ctx,
     757             :                                          pol,
     758             :                                          num_names,
     759             :                                          names,
     760             :                                          dom_names,
     761             :                                          level,
     762             :                                          sids,
     763             :                                          types,
     764             :                                          &result);
     765        1664 :         if (!NT_STATUS_IS_OK(status)) {
     766           0 :                 return status;
     767             :         }
     768             : 
     769        1664 :         return result;
     770             : }
     771             : 
     772           0 : NTSTATUS dcerpc_lsa_lookup_names4(struct dcerpc_binding_handle *h,
     773             :                                   TALLOC_CTX *mem_ctx,
     774             :                                   struct policy_handle *pol,
     775             :                                   uint32_t num_names,
     776             :                                   const char **names,
     777             :                                   const char ***dom_names,
     778             :                                   enum lsa_LookupNamesLevel level,
     779             :                                   struct dom_sid **sids,
     780             :                                   enum lsa_SidType **types,
     781             :                                   NTSTATUS *result)
     782             : {
     783           0 :         return dcerpc_lsa_lookup_names_generic(h,
     784             :                                                mem_ctx,
     785             :                                                pol,
     786             :                                                num_names,
     787             :                                                names,
     788             :                                                dom_names,
     789             :                                                level,
     790             :                                                sids,
     791             :                                                types,
     792             :                                                true,
     793             :                                                result);
     794             : }

Generated by: LCOV version 1.14