s4-mkrelease: Update for waf.
[sfrench/samba-autobuild/.git] / source3 / lib / util_sid.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Samba utility functions
4    Copyright (C) Andrew Tridgell                1992-1998
5    Copyright (C) Luke Kenneth Caseson Leighton  1998-1999
6    Copyright (C) Jeremy Allison                 1999
7    Copyright (C) Stefan (metze) Metzmacher      2002
8    Copyright (C) Simo Sorce                     2002
9    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2005
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 "../librpc/gen_ndr/ndr_security.h"
27 #include "../librpc/gen_ndr/netlogon.h"
28 #include "../libcli/security/dom_sid.h"
29
30 /*
31  * Some useful sids, more well known sids can be found at
32  * http://support.microsoft.com/kb/243330/EN-US/
33  */
34
35
36 const struct dom_sid global_sid_World_Domain =               /* Everyone domain */
37 { 1, 0, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
38 const struct dom_sid global_sid_World =                      /* Everyone */
39 { 1, 1, {0,0,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
40 const struct dom_sid global_sid_Creator_Owner_Domain =       /* Creator Owner domain */
41 { 1, 0, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
42 const struct dom_sid global_sid_NT_Authority =                  /* NT Authority */
43 { 1, 0, {0,0,0,0,0,5}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
44 const struct dom_sid global_sid_System =                        /* System */
45 { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
46 const struct dom_sid global_sid_NULL =                          /* NULL sid */
47 { 1, 1, {0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
48 const struct dom_sid global_sid_Authenticated_Users =   /* All authenticated rids */
49 { 1, 1, {0,0,0,0,0,5}, {11,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
50 #if 0
51 /* for documentation */
52 const struct dom_sid global_sid_Restriced =                     /* Restriced Code */
53 { 1, 1, {0,0,0,0,0,5}, {12,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
54 #endif
55 const struct dom_sid global_sid_Network =                       /* Network rids */
56 { 1, 1, {0,0,0,0,0,5}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
57
58 const struct dom_sid global_sid_Creator_Owner =         /* Creator Owner */
59 { 1, 1, {0,0,0,0,0,3}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
60 const struct dom_sid global_sid_Creator_Group =         /* Creator Group */
61 { 1, 1, {0,0,0,0,0,3}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
62 const struct dom_sid global_sid_Anonymous =                     /* Anonymous login */
63 { 1, 1, {0,0,0,0,0,5}, {7,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
64
65 const struct dom_sid global_sid_Builtin =                       /* Local well-known domain */
66 { 1, 1, {0,0,0,0,0,5}, {32,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
67 const struct dom_sid global_sid_Builtin_Administrators =        /* Builtin administrators */
68 { 1, 2, {0,0,0,0,0,5}, {32,544,0,0,0,0,0,0,0,0,0,0,0,0,0}};
69 const struct dom_sid global_sid_Builtin_Users =         /* Builtin users */
70 { 1, 2, {0,0,0,0,0,5}, {32,545,0,0,0,0,0,0,0,0,0,0,0,0,0}};
71 const struct dom_sid global_sid_Builtin_Guests =                /* Builtin guest users */
72 { 1, 2, {0,0,0,0,0,5}, {32,546,0,0,0,0,0,0,0,0,0,0,0,0,0}};
73 const struct dom_sid global_sid_Builtin_Power_Users =   /* Builtin power users */
74 { 1, 2, {0,0,0,0,0,5}, {32,547,0,0,0,0,0,0,0,0,0,0,0,0,0}};
75 const struct dom_sid global_sid_Builtin_Account_Operators =     /* Builtin account operators */
76 { 1, 2, {0,0,0,0,0,5}, {32,548,0,0,0,0,0,0,0,0,0,0,0,0,0}};
77 const struct dom_sid global_sid_Builtin_Server_Operators =      /* Builtin server operators */
78 { 1, 2, {0,0,0,0,0,5}, {32,549,0,0,0,0,0,0,0,0,0,0,0,0,0}};
79 const struct dom_sid global_sid_Builtin_Print_Operators =       /* Builtin print operators */
80 { 1, 2, {0,0,0,0,0,5}, {32,550,0,0,0,0,0,0,0,0,0,0,0,0,0}};
81 const struct dom_sid global_sid_Builtin_Backup_Operators =      /* Builtin backup operators */
82 { 1, 2, {0,0,0,0,0,5}, {32,551,0,0,0,0,0,0,0,0,0,0,0,0,0}};
83 const struct dom_sid global_sid_Builtin_Replicator =            /* Builtin replicator */
84 { 1, 2, {0,0,0,0,0,5}, {32,552,0,0,0,0,0,0,0,0,0,0,0,0,0}};
85 const struct dom_sid global_sid_Builtin_PreWin2kAccess =        /* Builtin pre win2k access */
86 { 1, 2, {0,0,0,0,0,5}, {32,554,0,0,0,0,0,0,0,0,0,0,0,0,0}};
87
88 const struct dom_sid global_sid_Unix_Users =                    /* Unmapped Unix users */
89 { 1, 1, {0,0,0,0,0,22}, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
90 const struct dom_sid global_sid_Unix_Groups =                   /* Unmapped Unix groups */
91 { 1, 1, {0,0,0,0,0,22}, {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
92
93 /* Unused, left here for documentary purposes */
94 #if 0
95 #define SECURITY_NULL_SID_AUTHORITY    0
96 #define SECURITY_WORLD_SID_AUTHORITY   1
97 #define SECURITY_LOCAL_SID_AUTHORITY   2
98 #define SECURITY_CREATOR_SID_AUTHORITY 3
99 #define SECURITY_NT_AUTHORITY          5
100 #endif
101
102 static struct dom_sid system_sid_array[1] =
103 { { 1, 1, {0,0,0,0,0,5}, {18,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} };
104 static const struct security_token system_token = {
105         .num_sids       = ARRAY_SIZE(system_sid_array),
106         .sids           = system_sid_array,
107         .privilege_mask = SE_ALL_PRIVS
108 };
109
110 /****************************************************************************
111  Lookup string names for SID types.
112 ****************************************************************************/
113
114 static const struct {
115         enum lsa_SidType sid_type;
116         const char *string;
117 } sid_name_type[] = {
118         {SID_NAME_USER, "User"},
119         {SID_NAME_DOM_GRP, "Domain Group"},
120         {SID_NAME_DOMAIN, "Domain"},
121         {SID_NAME_ALIAS, "Local Group"},
122         {SID_NAME_WKN_GRP, "Well-known Group"},
123         {SID_NAME_DELETED, "Deleted Account"},
124         {SID_NAME_INVALID, "Invalid Account"},
125         {SID_NAME_UNKNOWN, "UNKNOWN"},
126         {SID_NAME_COMPUTER, "Computer"},
127
128         {(enum lsa_SidType)0, NULL}
129 };
130
131 const char *sid_type_lookup(uint32 sid_type) 
132 {
133         int i = 0;
134
135         /* Look through list */
136         while(sid_name_type[i].sid_type != 0) {
137                 if (sid_name_type[i].sid_type == sid_type)
138                         return sid_name_type[i].string;
139                 i++;
140         }
141
142         /* Default return */
143         return "SID *TYPE* is INVALID";
144 }
145
146 /**************************************************************************
147  Create the SYSTEM token.
148 ***************************************************************************/
149
150 const struct security_token *get_system_token(void)
151 {
152         return &system_token;
153 }
154
155 /*****************************************************************
156  Convert a SID to an ascii string.
157 *****************************************************************/
158
159 char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid)
160 {
161         char *str = sid_string_talloc(talloc_tos(), sid);
162         fstrcpy(sidstr_out, str);
163         TALLOC_FREE(str);
164         return sidstr_out;
165 }
166
167 /*****************************************************************
168  Essentially a renamed dom_sid_string from
169  ../libcli/security/dom_sid.c with a panic if it didn't work.
170 *****************************************************************/
171
172 char *sid_string_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
173 {
174         char *result = dom_sid_string(mem_ctx, sid);
175         SMB_ASSERT(result != NULL);
176         return result;
177 }
178
179 /*****************************************************************
180  Useful function for debug lines.
181 *****************************************************************/
182
183 char *sid_string_dbg(const struct dom_sid *sid)
184 {
185         return sid_string_talloc(talloc_tos(), sid);
186 }
187
188 /*****************************************************************
189  Use with care!
190 *****************************************************************/
191
192 char *sid_string_tos(const struct dom_sid *sid)
193 {
194         return sid_string_talloc(talloc_tos(), sid);
195 }
196
197 bool sid_compose(struct dom_sid *dst, const struct dom_sid *domain_sid, uint32 rid)
198 {
199         sid_copy(dst, domain_sid);
200         return sid_append_rid(dst, rid);
201 }
202
203 /*****************************************************************
204  Removes the last rid from the end of a sid
205 *****************************************************************/  
206
207 bool sid_split_rid(struct dom_sid *sid, uint32 *rid)
208 {
209         if (sid->num_auths > 0) {
210                 sid->num_auths--;
211                 *rid = sid->sub_auths[sid->num_auths];
212                 return True;
213         }
214         return False;
215 }
216
217 /*****************************************************************
218  Return the last rid from the end of a sid
219 *****************************************************************/  
220
221 bool sid_peek_rid(const struct dom_sid *sid, uint32 *rid)
222 {
223         if (!sid || !rid)
224                 return False;           
225
226         if (sid->num_auths > 0) {
227                 *rid = sid->sub_auths[sid->num_auths - 1];
228                 return True;
229         }
230         return False;
231 }
232
233 /*****************************************************************
234  Return the last rid from the end of a sid
235  and check the sid against the exp_dom_sid  
236 *****************************************************************/  
237
238 bool sid_peek_check_rid(const struct dom_sid *exp_dom_sid, const struct dom_sid *sid, uint32 *rid)
239 {
240         if (!exp_dom_sid || !sid || !rid)
241                 return False;
242
243         if (sid->num_auths != (exp_dom_sid->num_auths+1)) {
244                 return False;
245         }
246
247         if (sid_compare_domain(exp_dom_sid, sid)!=0){
248                 *rid=(-1);
249                 return False;
250         }
251
252         return sid_peek_rid(sid, rid);
253 }
254
255 /*****************************************************************
256  Copies a sid
257 *****************************************************************/  
258
259 void sid_copy(struct dom_sid *dst, const struct dom_sid *src)
260 {
261         int i;
262
263         ZERO_STRUCTP(dst);
264
265         dst->sid_rev_num = src->sid_rev_num;
266         dst->num_auths = src->num_auths;
267
268         memcpy(&dst->id_auth[0], &src->id_auth[0], sizeof(src->id_auth));
269
270         for (i = 0; i < src->num_auths; i++)
271                 dst->sub_auths[i] = src->sub_auths[i];
272 }
273
274 /*****************************************************************
275  Write a sid out into on-the-wire format.
276 *****************************************************************/  
277
278 bool sid_linearize(char *outbuf, size_t len, const struct dom_sid *sid)
279 {
280         size_t i;
281
282         if (len < ndr_size_dom_sid(sid, 0))
283                 return False;
284
285         SCVAL(outbuf,0,sid->sid_rev_num);
286         SCVAL(outbuf,1,sid->num_auths);
287         memcpy(&outbuf[2], sid->id_auth, 6);
288         for(i = 0; i < sid->num_auths; i++)
289                 SIVAL(outbuf, 8 + (i*4), sid->sub_auths[i]);
290
291         return True;
292 }
293
294 /*****************************************************************
295  Parse a on-the-wire SID to a struct dom_sid.
296 *****************************************************************/  
297
298 bool sid_parse(const char *inbuf, size_t len, struct dom_sid *sid)
299 {
300         enum ndr_err_code ndr_err;
301         DATA_BLOB in = data_blob_const(inbuf, len);
302         ndr_err = ndr_pull_struct_blob_all(&in, NULL, sid,
303                                            (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
304         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
305                 return false;
306         }
307         return true;
308 }
309
310 /*****************************************************************
311  Compare the auth portion of two sids.
312 *****************************************************************/  
313
314 static int sid_compare_auth(const struct dom_sid *sid1, const struct dom_sid *sid2)
315 {
316         int i;
317
318         if (sid1 == sid2)
319                 return 0;
320         if (!sid1)
321                 return -1;
322         if (!sid2)
323                 return 1;
324
325         if (sid1->sid_rev_num != sid2->sid_rev_num)
326                 return sid1->sid_rev_num - sid2->sid_rev_num;
327
328         for (i = 0; i < 6; i++)
329                 if (sid1->id_auth[i] != sid2->id_auth[i])
330                         return sid1->id_auth[i] - sid2->id_auth[i];
331
332         return 0;
333 }
334
335 /*****************************************************************
336  Compare two sids.
337 *****************************************************************/  
338
339 int sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid2)
340 {
341         int i;
342
343         if (sid1 == sid2)
344                 return 0;
345         if (!sid1)
346                 return -1;
347         if (!sid2)
348                 return 1;
349
350         /* Compare most likely different rids, first: i.e start at end */
351         if (sid1->num_auths != sid2->num_auths)
352                 return sid1->num_auths - sid2->num_auths;
353
354         for (i = sid1->num_auths-1; i >= 0; --i)
355                 if (sid1->sub_auths[i] != sid2->sub_auths[i])
356                         return sid1->sub_auths[i] - sid2->sub_auths[i];
357
358         return sid_compare_auth(sid1, sid2);
359 }
360
361 /*****************************************************************
362  See if 2 SIDs are in the same domain
363  this just compares the leading sub-auths
364 *****************************************************************/  
365
366 int sid_compare_domain(const struct dom_sid *sid1, const struct dom_sid *sid2)
367 {
368         int n, i;
369
370         n = MIN(sid1->num_auths, sid2->num_auths);
371
372         for (i = n-1; i >= 0; --i)
373                 if (sid1->sub_auths[i] != sid2->sub_auths[i])
374                         return sid1->sub_auths[i] - sid2->sub_auths[i];
375
376         return sid_compare_auth(sid1, sid2);
377 }
378
379 /*****************************************************************
380  Compare two sids.
381 *****************************************************************/  
382
383 bool sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2)
384 {
385         return sid_compare(sid1, sid2) == 0;
386 }
387
388 /*****************************************************************
389  Returns true if SID is internal (and non-mappable).
390 *****************************************************************/
391
392 bool non_mappable_sid(struct dom_sid *sid)
393 {
394         struct dom_sid dom;
395         uint32 rid;
396
397         sid_copy(&dom, sid);
398         sid_split_rid(&dom, &rid);
399
400         if (sid_equal(&dom, &global_sid_Builtin))
401                 return True;
402
403         if (sid_equal(&dom, &global_sid_NT_Authority))
404                 return True;
405
406         return False;
407 }
408
409 /*****************************************************************
410  Return the binary string representation of a struct dom_sid.
411  Caller must free.
412 *****************************************************************/
413
414 char *sid_binstring(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
415 {
416         uint8_t *buf;
417         char *s;
418         int len = ndr_size_dom_sid(sid, 0);
419         buf = talloc_array(mem_ctx, uint8_t, len);
420         if (!buf) {
421                 return NULL;
422         }
423         sid_linearize((char *)buf, len, sid);
424         s = binary_string_rfc2254(mem_ctx, buf, len);
425         TALLOC_FREE(buf);
426         return s;
427 }
428
429 /*****************************************************************
430  Return the binary string representation of a struct dom_sid.
431  Caller must free.
432 *****************************************************************/
433
434 char *sid_binstring_hex(const struct dom_sid *sid)
435 {
436         char *buf, *s;
437         int len = ndr_size_dom_sid(sid, 0);
438         buf = (char *)SMB_MALLOC(len);
439         if (!buf)
440                 return NULL;
441         sid_linearize(buf, len, sid);
442         s = binary_string(buf, len);
443         free(buf);
444         return s;
445 }
446
447 /*******************************************************************
448  Tallocs a duplicate SID. 
449 ********************************************************************/ 
450
451 struct dom_sid *sid_dup_talloc(TALLOC_CTX *ctx, const struct dom_sid *src)
452 {
453         struct dom_sid *dst;
454
455         if (src == NULL) {
456                 return NULL;
457         }
458         dst = talloc_zero(ctx, struct dom_sid);
459         if (dst == NULL) {
460                 return NULL;
461         }
462         sid_copy(dst, src);
463         return dst;
464 }
465
466 /********************************************************************
467  Add SID to an array SIDs
468 ********************************************************************/
469
470 NTSTATUS add_sid_to_array(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
471                           struct dom_sid **sids, uint32_t *num)
472 {
473         *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, struct dom_sid,
474                                              (*num)+1);
475         if (*sids == NULL) {
476                 *num = 0;
477                 return NT_STATUS_NO_MEMORY;
478         }
479
480         sid_copy(&((*sids)[*num]), sid);
481         *num += 1;
482
483         return NT_STATUS_OK;
484 }
485
486
487 /********************************************************************
488  Add SID to an array SIDs ensuring that it is not already there
489 ********************************************************************/
490
491 NTSTATUS add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
492                                  struct dom_sid **sids, uint32_t *num_sids)
493 {
494         size_t i;
495
496         for (i=0; i<(*num_sids); i++) {
497                 if (sid_compare(sid, &(*sids)[i]) == 0)
498                         return NT_STATUS_OK;
499         }
500
501         return add_sid_to_array(mem_ctx, sid, sids, num_sids);
502 }
503
504 /********************************************************************
505  Remove SID from an array
506 ********************************************************************/
507
508 void del_sid_from_array(const struct dom_sid *sid, struct dom_sid **sids, size_t *num)
509 {
510         struct dom_sid *sid_list = *sids;
511         size_t i;
512
513         for ( i=0; i<*num; i++ ) {
514
515                 /* if we find the SID, then decrement the count
516                    and break out of the loop */
517
518                 if ( sid_equal(sid, &sid_list[i]) ) {
519                         *num -= 1;
520                         break;
521                 }
522         }
523
524         /* This loop will copy the remainder of the array 
525            if i < num of sids ni the array */
526
527         for ( ; i<*num; i++ ) 
528                 sid_copy( &sid_list[i], &sid_list[i+1] );
529
530         return;
531 }
532
533 bool add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
534                                     uint32 rid, uint32 **pp_rids, size_t *p_num)
535 {
536         size_t i;
537
538         for (i=0; i<*p_num; i++) {
539                 if ((*pp_rids)[i] == rid)
540                         return True;
541         }
542
543         *pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
544
545         if (*pp_rids == NULL) {
546                 *p_num = 0;
547                 return False;
548         }
549
550         (*pp_rids)[*p_num] = rid;
551         *p_num += 1;
552         return True;
553 }
554
555 bool is_null_sid(const struct dom_sid *sid)
556 {
557         static const struct dom_sid null_sid = {0};
558         return sid_equal(sid, &null_sid);
559 }
560
561 bool is_sid_in_token(const struct security_token *token, const struct dom_sid *sid)
562 {
563         int i;
564
565         for (i=0; i<token->num_sids; i++) {
566                 if (sid_compare(sid, &token->sids[i]) == 0)
567                         return true;
568         }
569         return false;
570 }
571
572 NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
573                               const struct netr_SamInfo3 *info3,
574                               struct dom_sid **user_sids,
575                               uint32_t *num_user_sids,
576                               bool include_user_group_rid,
577                               bool skip_ressource_groups)
578 {
579         NTSTATUS status;
580         struct dom_sid sid;
581         struct dom_sid *sid_array = NULL;
582         uint32_t num_sids = 0;
583         int i;
584
585         if (include_user_group_rid) {
586                 if (!sid_compose(&sid, info3->base.domain_sid, info3->base.rid)) {
587                         DEBUG(3, ("could not compose user SID from rid 0x%x\n",
588                                   info3->base.rid));
589                         return NT_STATUS_INVALID_PARAMETER;
590                 }
591                 status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
592                 if (!NT_STATUS_IS_OK(status)) {
593                         DEBUG(3, ("could not append user SID from rid 0x%x\n",
594                                   info3->base.rid));
595                         return status;
596                 }
597         }
598
599         if (!sid_compose(&sid, info3->base.domain_sid, info3->base.primary_gid)) {
600                 DEBUG(3, ("could not compose group SID from rid 0x%x\n",
601                           info3->base.primary_gid));
602                 return NT_STATUS_INVALID_PARAMETER;
603         }
604         status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
605         if (!NT_STATUS_IS_OK(status)) {
606                 DEBUG(3, ("could not append group SID from rid 0x%x\n",
607                           info3->base.rid));
608                 return status;
609         }
610
611         for (i = 0; i < info3->base.groups.count; i++) {
612                 /* Don't add the primary group sid twice. */
613                 if (info3->base.primary_gid == info3->base.groups.rids[i].rid) {
614                         continue;
615                 }
616                 if (!sid_compose(&sid, info3->base.domain_sid,
617                                  info3->base.groups.rids[i].rid)) {
618                         DEBUG(3, ("could not compose SID from additional group "
619                                   "rid 0x%x\n", info3->base.groups.rids[i].rid));
620                         return NT_STATUS_INVALID_PARAMETER;
621                 }
622                 status = add_sid_to_array(mem_ctx, &sid, &sid_array, &num_sids);
623                 if (!NT_STATUS_IS_OK(status)) {
624                         DEBUG(3, ("could not append SID from additional group "
625                                   "rid 0x%x\n", info3->base.groups.rids[i].rid));
626                         return status;
627                 }
628         }
629
630         /* Copy 'other' sids.  We need to do sid filtering here to
631            prevent possible elevation of privileges.  See:
632
633            http://www.microsoft.com/windows2000/techinfo/administration/security/sidfilter.asp
634          */
635
636         for (i = 0; i < info3->sidcount; i++) {
637
638                 if (skip_ressource_groups &&
639                     (info3->sids[i].attributes & SE_GROUP_RESOURCE)) {
640                         continue;
641                 }
642
643                 status = add_sid_to_array(mem_ctx, info3->sids[i].sid,
644                                       &sid_array, &num_sids);
645                 if (!NT_STATUS_IS_OK(status)) {
646                         DEBUG(3, ("could not add SID to array: %s\n",
647                                   sid_string_dbg(info3->sids[i].sid)));
648                         return status;
649                 }
650         }
651
652         *user_sids = sid_array;
653         *num_user_sids = num_sids;
654
655         return NT_STATUS_OK;
656 }