default SID map now reads in "trusted domains" from smb.conf.
authorLuke Leighton <lkcl@samba.org>
Thu, 2 Dec 1999 16:31:24 +0000 (16:31 +0000)
committerLuke Leighton <lkcl@samba.org>
Thu, 2 Dec 1999 16:31:24 +0000 (16:31 +0000)
source/include/proto.h
source/lib/sids.c
source/lib/util_pwdb.c
source/lib/util_sid.c
source/libsmb/namequery.c
source/rpc_client/cli_use.c
source/rpcclient/rpcclient.c

index fc7653009f5097ada23abc63b1ccc8de5262fe30..eb898c44de6156a513e469e15138f3e39bf203cc 100644 (file)
@@ -295,9 +295,12 @@ char *rep_inet_ntoa(struct in_addr ip);
 
 /*The following definitions come from  lib/sids.c  */
 
+struct sid_map* add_sidmap_to_array(uint32 *len, struct sid_map ***array,
+                               const struct sid_map *name);
 void get_sam_domain_name(void);
 BOOL get_member_domain_sid(void);
 void generate_wellknown_sids(void);
+BOOL create_sidmap_table(void);
 BOOL generate_sam_sid(char *domain_name, DOM_SID *sid);
 BOOL map_domain_name_to_sid(DOM_SID *sid, char **nt_domain);
 BOOL map_domain_sid_to_name(DOM_SID *sid, char *nt_domain);
index c18734c7051eacbc9d9badfd7d943d99d83445db..e46d3782cbf3f3049c48b36ef966a55ca3f90a63 100644 (file)
@@ -69,13 +69,14 @@ DOM_SID global_sid_S_1_1;    /* everyone */
 DOM_SID global_sid_S_1_3;    /* Creator Owner */
 DOM_SID global_sid_S_1_5;    /* NT Authority */
 
-static struct sid_name_map_info
+struct sid_map
 {
        DOM_SID *sid;
        char *name;
 
-}
-sid_name_map[] =
+};
+
+struct sid_map static_sid_name_map[] =
 {
        { &global_sid_S_1_5_20, "BUILTIN" },
        { &global_sid_S_1_1   , "Everyone" },
@@ -86,6 +87,65 @@ sid_name_map[] =
        { NULL                , NULL      }
 };
 
+struct sid_map **sid_name_map = NULL;
+uint32 num_maps = 0;
+
+static struct sid_map *sid_map_dup(const struct sid_map *from)
+{
+       if (from != NULL)
+       {
+               struct sid_map *copy = (struct sid_map *)
+                                       malloc(sizeof(struct sid_map));
+               if (copy != NULL)
+               {
+                       ZERO_STRUCTP(copy);
+                       if (from->name != NULL)
+                       {
+                               copy->name  = strdup(from->name );
+                       }
+                       if (from->sid != NULL)
+                       {
+                               copy->sid = sid_dup(from->sid);
+                       }
+               }
+               return copy;
+       }
+       return NULL;
+}
+
+static void sid_map_free(struct sid_map *map)
+{
+       if (map->name != NULL)
+       {
+               free(map->name);
+       }
+       if (map->sid != NULL)
+       {
+               free(map->sid);
+       }
+       free(map);
+}
+
+/****************************************************************************
+free a sid map array
+****************************************************************************/
+static void free_sidmap_array(uint32 num_entries, struct sid_map **entries)
+{
+       void(*fn)(void*) = (void(*)(void*))&sid_map_free;
+       free_void_array(num_entries, (void**)entries, *fn);
+}
+
+/****************************************************************************
+add a sid map state to the array
+****************************************************************************/
+struct sid_map* add_sidmap_to_array(uint32 *len, struct sid_map ***array,
+                               const struct sid_map *name)
+{
+       void*(*fn)(const void*) = (void*(*)(const void*))&sid_map_dup;
+       return (struct sid_map*)add_copy_to_array(len,
+                            (void***)array, (const void*)name, *fn, False);
+                               
+}
 /****************************************************************************
  sets up the name associated with the SAM database for which we are responsible
 ****************************************************************************/
@@ -155,6 +215,54 @@ void generate_wellknown_sids(void)
        string_to_sid(&global_sid_S_1_5   , "S-1-5"   );
 }
 
+/****************************************************************************
+ create a sid map table
+****************************************************************************/
+BOOL create_sidmap_table(void)
+{
+       int i;
+       char **doms = NULL;
+       uint32 num_doms = 0;
+
+       for (i = 0; static_sid_name_map[i].name != NULL; i++)
+       {
+               add_sidmap_to_array(&num_maps, &sid_name_map,
+                                   &static_sid_name_map[i]);
+       }
+
+       enumtrustdoms(&doms, &num_doms);
+
+       for (i = 0; i < num_doms; i++)
+       {
+               struct sid_map map;
+               DOM_SID sid;
+
+               map.name = doms[i];
+               map.sid  = &sid;
+
+               if (!read_sid(map.name, map.sid))
+               {
+                       DEBUG(0,("Could not read Domain SID %s\n", map.name));
+                       return False;
+               }
+               add_sidmap_to_array(&num_maps, &sid_name_map, &map);
+       }
+
+
+       for (i = 0; i < num_maps; i++)
+       {
+               fstring sidstr;
+               sid_to_string(sidstr, sid_name_map[i]->sid);
+               DEBUG(10,("Map:\tDomain:\t%s\tSID:\t%s\n",
+                        sid_name_map[i]->name, sidstr));
+       }
+
+
+       free_char_array(num_doms, doms);
+
+       return True;
+}
+
 /****************************************************************************
  Generate the global machine sid. Look for the DOMAINNAME.SID file first, if
  not found then look in smb.conf and use it to create the DOMAINNAME.SID file.
@@ -275,18 +383,17 @@ BOOL map_domain_name_to_sid(DOM_SID *sid, char **nt_domain)
 
        DEBUG(5,("map_domain_name_to_sid: %s\n", (*nt_domain)));
 
-       while (sid_name_map[i].name != NULL)
+       for (i = 0; sid_name_map[i]->name != NULL; i++)
        {
-               DEBUG(5,("compare: %s\n", sid_name_map[i].name));
-               if (strequal(sid_name_map[i].name, (*nt_domain)))
+               DEBUG(5,("compare: %s\n", sid_name_map[i]->name));
+               if (strequal(sid_name_map[i]->name, (*nt_domain)))
                {
                        fstring sid_str;
-                       sid_copy(sid, sid_name_map[i].sid);
-                       sid_to_string(sid_str, sid_name_map[i].sid);
+                       sid_copy(sid, sid_name_map[i]->sid);
+                       sid_to_string(sid_str, sid_name_map[i]->sid);
                        DEBUG(5,("found %s\n", sid_str));
                        return True;
                }
-               i++;
        }
 
        DEBUG(0,("map_domain_name_to_sid: mapping to %s NOT IMPLEMENTED\n",
@@ -311,17 +418,16 @@ BOOL map_domain_sid_to_name(DOM_SID *sid, char *nt_domain)
                return False;
        }
 
-       while (sid_name_map[i].sid != NULL)
+       for (i = 0; sid_name_map[i]->sid != NULL; i++)
        {
-               sid_to_string(sid_str, sid_name_map[i].sid);
+               sid_to_string(sid_str, sid_name_map[i]->sid);
                DEBUG(5,("compare: %s\n", sid_str));
-               if (sid_equal(sid_name_map[i].sid, sid))
+               if (sid_equal(sid_name_map[i]->sid, sid))
                {
-                       fstrcpy(nt_domain, sid_name_map[i].name);
+                       fstrcpy(nt_domain, sid_name_map[i]->name);
                        DEBUG(5,("found %s\n", nt_domain));
                        return True;
                }
-               i++;
        }
 
        DEBUG(0,("map_domain_sid_to_name: mapping NOT IMPLEMENTED\n"));
@@ -367,7 +473,7 @@ BOOL split_domain_name(const char *fullname, char *domain, char *name)
 }
 
 /**************************************************************************
- enumerates all domains for which the SAM server is responsible
+ enumerates all trusted domains
 ***************************************************************************/
 BOOL enumtrustdoms(char ***doms, uint32 *num_entries)
 {
@@ -381,7 +487,9 @@ BOOL enumtrustdoms(char ***doms, uint32 *num_entries)
        {
                do
                {
-                       add_chars_to_array(num_entries, doms, tmp);
+                       fstring domain;
+                       split_at_first_component(tmp, domain, '=', NULL);
+                       add_chars_to_array(num_entries, doms, domain);
 
                } while (next_token(NULL, tmp, NULL, sizeof(tmp)));
        }
index d80ec5f6892c0b0c69762b52685a5d4f93509706..006a68b2c1239ad6c83186465a2e6d3ac7200aa1 100644 (file)
@@ -641,6 +641,8 @@ BOOL pwdb_initialise(BOOL is_server)
                }
        }
 
+       create_sidmap_table();
+
        return initialise_password_db();
 }
 
index b497a1e455197d7076b6b2b604cefa95f13add84..a96648448419dbbcf0e1df29b9f97a96369e1de5 100644 (file)
@@ -270,7 +270,7 @@ static BOOL read_sid_from_file(int fd, char *sid_file, DOM_SID *sid)
 
   fline[sizeof(fline)-1] = '\0';
   if (!string_to_sid(sid, fline)) {
-    DEBUG(0,("unable to generate machine SID.\n"));
+    DEBUG(0,("unable to read sid.\n"));
     return False;
   }
 
@@ -289,15 +289,12 @@ BOOL read_sid(char *domain_name, DOM_SID *sid)
        int fd;
        char *p;
        pstring sid_file;
-       fstring sid_string;
        fstring file_name;
        SMB_STRUCT_STAT st;
 
        pstrcpy(sid_file, lp_smb_passwd_file());
-       sid_to_string(sid_string, sid);
 
-       DEBUG(10,("read_sid: Domain: %s SID: %s\n", domain_name, sid_string));
-       fstrcat(sid_string, "\n");
+       DEBUG(10,("read_sid: Domain: %s\n", domain_name));
 
        if (sid_file[0] == 0)
        {
index e774dbae15af5d3703885bda632ce2e4f01037ab..8aaeb165cd7c80da6c16662dc056d2fd19e8738a 100644 (file)
@@ -665,6 +665,8 @@ BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
                                struct in_addr *ip)
 {
        BOOL ret;
+       const char *sv_name = srv_name;
+
        DEBUG(10,("resolve_srv_name: %s\n", srv_name));
 
        if (srv_name == NULL || strequal("\\\\.", srv_name))
@@ -674,12 +676,12 @@ BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
                return True;
        }
 
-       if (!strnequal("\\\\", srv_name, 2))
+       if (strnequal("\\\\", srv_name, 2))
        {
-               return False;
+               sv_name = &srv_name[2];
        }
 
-       fstrcpy(dest_host, &srv_name[2]);
+       fstrcpy(dest_host, sv_name);
        ret = resolve_name(dest_host, ip, 0x20);
        
        if (is_ip_address(dest_host))
index 99cdb129f75dc6df4f7afe8c370e29a11efe05fb..69e46c081bd1d75801cea3a08cbbf0a0aa5a9b9b 100644 (file)
@@ -43,9 +43,15 @@ terminate client connection
 ****************************************************************************/
 static void cli_use_free(struct cli_use *cli)
 {
-       cli_ulogoff(cli->cli);
-       cli_shutdown(cli->cli);
-       free(cli->cli);
+       if (cli->cli != NULL)
+       {
+               if (cli->cli->initialised)
+               {
+                       cli_ulogoff(cli->cli);
+                       cli_shutdown(cli->cli);
+               }
+               free(cli->cli);
+       }
 
        free(cli);
 }
index ba40920a406f3680876fe6e6df59eafeb3f4c7cb..8b1710d3684329ebbaac2d0ea4d863770d7b2d03 100644 (file)
@@ -1913,6 +1913,8 @@ void readline_init(void)
 
        DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
 
+       pwdb_initialise(False);
+
        process(&cli_info, NULL);
 
        free_connections();