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