r2599: avoid free()ing our static unalloceted memory that ends up in memory corruption.
[ira/wip.git] / source3 / lib / util_sid.c
index 9e5ae6b441560b02e0c516e880420eb0483a566b..6b27fc84ddb31604dcb73b78ba1b996e0db28c21 100644 (file)
@@ -93,7 +93,7 @@ static const struct {
        {SID_NAME_UNKNOWN, "UNKNOWN"},
        {SID_NAME_COMPUTER, "Computer"},
 
-       {0, NULL}
+       {(enum SID_NAME_USE)0, NULL}
 };
 
 const char *sid_type_lookup(uint32 sid_type) 
@@ -174,6 +174,19 @@ NT_USER_TOKEN *get_system_token(void)
        return &system_token;
 }
 
+/******************************************************************
+ get the default domain/netbios name to be used when dealing 
+ with our passdb list of accounts
+******************************************************************/
+
+const char *get_global_sam_name(void) 
+{
+       if ((lp_server_role() == ROLE_DOMAIN_PDC) || (lp_server_role() == ROLE_DOMAIN_BDC)) {
+               return lp_workgroup();
+       }
+       return global_myname();
+}
+
 /**************************************************************************
  Splits a name of format \DOMAIN\name or name into its two components.
  Sets the DOMAIN name to global_myname() if it has not been specified.
@@ -201,7 +214,7 @@ void split_domain_name(const char *fullname, char *domain, char *name)
                fstrcpy(domain, full_name);
                fstrcpy(name, p+1);
        } else {
-               fstrcpy(domain, global_myname());
+               fstrcpy(domain, get_global_sam_name());
                fstrcpy(name, full_name);
        }
 
@@ -391,6 +404,9 @@ BOOL sid_peek_check_rid(const DOM_SID *exp_dom_sid, const DOM_SID *sid, uint32 *
        if (!exp_dom_sid || !sid || !rid)
                return False;
                        
+       if (sid->num_auths != (exp_dom_sid->num_auths+1)) {
+               return False;
+       }
 
        if (sid_compare_domain(exp_dom_sid, sid)!=0){
                *rid=(-1);
@@ -614,19 +630,20 @@ char *sid_binstring(const DOM_SID *sid)
        return s;
 }
 
+/*******************************************************************
+ Tallocs a duplicate SID. 
+********************************************************************/ 
 
-/*****************************************************************
- Print a GUID structure for debugging.
-*****************************************************************/
-
-void print_guid(GUID *guid)
+DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, const DOM_SID *src)
 {
-       int i;
-
-       d_printf("%08x-%04x-%04x", 
-                IVAL(guid->info, 0), SVAL(guid->info, 4), SVAL(guid->info, 6));
-       d_printf("-%02x%02x-", guid->info[8], guid->info[9]);
-       for (i=10;i<GUID_SIZE;i++)
-               d_printf("%02x", guid->info[i]);
-       d_printf("\n");
+       DOM_SID *dst;
+       
+       if(!src)
+               return NULL;
+       
+       if((dst = talloc_zero(ctx, sizeof(DOM_SID))) != NULL) {
+               sid_copy( dst, src);
+       }
+       
+       return dst;
 }