r23779: Change from v2 or later to v3 or later.
[amitay/samba.git] / source3 / lib / util_sid.c
index 09fe30f81bbd0a2f1119135357e7cdc0dcf34f47..1473190abd5e77df2508350e4a4f32e6a6ce5a56 100644 (file)
@@ -10,7 +10,7 @@
       
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -110,7 +110,7 @@ NT_USER_TOKEN system_token = { 1, system_sid_array, SE_ALL_PRIVS };
 ****************************************************************************/
 
 static const struct {
-       enum SID_NAME_USE sid_type;
+       enum lsa_SidType sid_type;
        const char *string;
 } sid_name_type[] = {
        {SID_NAME_USER, "User"},
@@ -123,7 +123,7 @@ static const struct {
        {SID_NAME_UNKNOWN, "UNKNOWN"},
        {SID_NAME_COMPUTER, "Computer"},
 
-       {(enum SID_NAME_USE)0, NULL}
+       {(enum lsa_SidType)0, NULL}
 };
 
 const char *sid_type_lookup(uint32 sid_type) 
@@ -531,7 +531,7 @@ char *sid_binstring(const DOM_SID *sid)
 {
        char *buf, *s;
        int len = sid_size(sid);
-       buf = SMB_MALLOC(len);
+       buf = (char *)SMB_MALLOC(len);
        if (!buf)
                return NULL;
        sid_linearize(buf, len, sid);
@@ -549,7 +549,7 @@ char *sid_binstring_hex(const DOM_SID *sid)
 {
        char *buf, *s;
        int len = sid_size(sid);
-       buf = SMB_MALLOC(len);
+       buf = (char *)SMB_MALLOC(len);
        if (!buf)
                return NULL;
        sid_linearize(buf, len, sid);
@@ -580,24 +580,20 @@ DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src)
  Add SID to an array SIDs
 ********************************************************************/
 
-void add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid, 
+BOOL add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid, 
                      DOM_SID **sids, size_t *num)
 {
-       if (mem_ctx != NULL) {
-               *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID,
+       *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID,
                                             (*num)+1);
-       } else {
-               *sids = SMB_REALLOC_ARRAY(*sids, DOM_SID, (*num)+1);
-       }
-
        if (*sids == NULL) {
-               return;
+               *num = 0;
+               return False;
        }
 
        sid_copy(&((*sids)[*num]), sid);
        *num += 1;
 
-       return;
+       return True;
 }
 
 
@@ -605,17 +601,17 @@ void add_sid_to_array(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
  Add SID to an array SIDs ensuring that it is not already there
 ********************************************************************/
 
-void add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
+BOOL add_sid_to_array_unique(TALLOC_CTX *mem_ctx, const DOM_SID *sid,
                             DOM_SID **sids, size_t *num_sids)
 {
        size_t i;
 
        for (i=0; i<(*num_sids); i++) {
                if (sid_compare(sid, &(*sids)[i]) == 0)
-                       return;
+                       return True;
        }
 
-       add_sid_to_array(mem_ctx, sid, sids, num_sids);
+       return add_sid_to_array(mem_ctx, sid, sids, num_sids);
 }
 
 /********************************************************************
@@ -647,23 +643,26 @@ void del_sid_from_array(const DOM_SID *sid, DOM_SID **sids, size_t *num)
        return;
 }
 
-void add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
+BOOL add_rid_to_array_unique(TALLOC_CTX *mem_ctx,
                                    uint32 rid, uint32 **pp_rids, size_t *p_num)
 {
        size_t i;
 
        for (i=0; i<*p_num; i++) {
                if ((*pp_rids)[i] == rid)
-                       return;
+                       return True;
        }
        
        *pp_rids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_rids, uint32, *p_num+1);
 
-       if (*pp_rids == NULL)
-               return;
+       if (*pp_rids == NULL) {
+               *p_num = 0;
+               return False;
+       }
 
        (*pp_rids)[*p_num] = rid;
        *p_num += 1;
+       return True;
 }
 
 BOOL is_null_sid(const DOM_SID *sid)