r2599: avoid free()ing our static unalloceted memory that ends up in memory corruption.
[ira/wip.git] / source3 / lib / util_sid.c
index edd59ae109447c17db0bc0205b2531cbf88b51e1..6b27fc84ddb31604dcb73b78ba1b996e0db28c21 100644 (file)
@@ -79,9 +79,9 @@ NT_USER_TOKEN system_token = {
  Lookup string names for SID types.
 ****************************************************************************/
 
-const static struct {
+static const struct {
        enum SID_NAME_USE sid_type;
-       char *string;
+       const char *string;
 } sid_name_type[] = {
        {SID_NAME_USER, "User"},
        {SID_NAME_DOM_GRP, "Domain Group"},
@@ -91,8 +91,9 @@ const static struct {
        {SID_NAME_DELETED, "Deleted Account"},
        {SID_NAME_INVALID, "Invalid Account"},
        {SID_NAME_UNKNOWN, "UNKNOWN"},
+       {SID_NAME_COMPUTER, "Computer"},
 
-       {SID_NAME_USE_NONE, NULL}
+       {(enum SID_NAME_USE)0, NULL}
 };
 
 const char *sid_type_lookup(uint32 sid_type) 
@@ -173,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.
@@ -181,7 +195,8 @@ NT_USER_TOKEN *get_system_token(void)
 void split_domain_name(const char *fullname, char *domain, char *name)
 {
        pstring full_name;
-       char *p, *sep;
+       const char *sep;
+       char *p;
 
        sep = lp_winbind_separator();
 
@@ -199,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);
        }
 
@@ -389,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);
@@ -612,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;
 }