r25027: Fix more warnings.
[jelmer/samba4-debian.git] / source / libcli / security / dom_sid.c
index 39841e5a7038be3a4e62b09c426b36e9b06f610a..1ba3edd9bf57f79d400487fd9223d113ad4cf37b 100644 (file)
@@ -8,7 +8,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,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "librpc/gen_ndr/security.h"
+#include "libcli/security/security.h"
 
 /*****************************************************************
  Compare the auth portion of two sids.
@@ -79,7 +79,7 @@ static int dom_sid_compare(const struct dom_sid *sid1, const struct dom_sid *sid
  Compare two sids.
 *****************************************************************/  
 
-BOOL dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2)
+bool dom_sid_equal(const struct dom_sid *sid1, const struct dom_sid *sid2)
 {
        return dom_sid_compare(sid1, sid2) == 0;
 }
@@ -215,6 +215,30 @@ struct dom_sid *dom_sid_add_rid(TALLOC_CTX *mem_ctx,
        return sid;
 }
 
+/*
+  Split up a SID into its domain and RID part
+*/
+NTSTATUS dom_sid_split_rid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
+                          struct dom_sid **domain, uint32_t *rid)
+{
+       if (sid->num_auths == 0) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       if (domain) {
+               if (!(*domain = dom_sid_dup(mem_ctx, sid))) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               (*domain)->num_auths -= 1;
+       }
+
+       if (rid) {
+               *rid = sid->sub_auths[sid->num_auths - 1];
+       }
+
+       return NT_STATUS_OK;
+}
 
 /*
   return True if the 2nd sid is in the domain given by the first sid
@@ -255,7 +279,7 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
        }
 
        maxlen = sid->num_auths * 11 + 25;
-       ret = talloc_size(mem_ctx, maxlen);
+       ret = talloc_array(mem_ctx, char, maxlen);
        if (!ret) return talloc_strdup(mem_ctx, "(SID ERR)");
 
        ia = (sid->id_auth[5]) +
@@ -264,7 +288,7 @@ char *dom_sid_string(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
                (sid->id_auth[2] << 24);
 
        ofs = snprintf(ret, maxlen, "S-%u-%lu", 
-                      (uint_t)sid->sid_rev_num, (unsigned long)ia);
+                      (unsigned int)sid->sid_rev_num, (unsigned long)ia);
 
        for (i = 0; i < sid->num_auths; i++) {
                ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]);