diff options
author | Luke Leighton <lkcl@samba.org> | 1999-12-02 16:31:24 +0000 |
---|---|---|
committer | Luke Leighton <lkcl@samba.org> | 1999-12-02 16:31:24 +0000 |
commit | e9b8c7743a45b4d045892f9039075fb8cfbd84e5 (patch) | |
tree | f4375c000f75eca421511fca65bd376989361cfc | |
parent | 10b82d30b782ad990fc3386a8f0101641780a14e (diff) | |
download | samba-e9b8c7743a45b4d045892f9039075fb8cfbd84e5.tar.gz samba-e9b8c7743a45b4d045892f9039075fb8cfbd84e5.tar.bz2 samba-e9b8c7743a45b4d045892f9039075fb8cfbd84e5.zip |
default SID map now reads in "trusted domains" from smb.conf.
(This used to be commit f0946d1ccafeb5f541935b41f2d54bcbc06797ed)
-rw-r--r-- | source3/include/proto.h | 3 | ||||
-rw-r--r-- | source3/lib/sids.c | 140 | ||||
-rw-r--r-- | source3/lib/util_pwdb.c | 2 | ||||
-rw-r--r-- | source3/lib/util_sid.c | 7 | ||||
-rw-r--r-- | source3/libsmb/namequery.c | 8 | ||||
-rw-r--r-- | source3/rpc_client/cli_use.c | 12 | ||||
-rw-r--r-- | source3/rpcclient/rpcclient.c | 2 |
7 files changed, 147 insertions, 27 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index fc7653009f..eb898c44de 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -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); diff --git a/source3/lib/sids.c b/source3/lib/sids.c index c18734c705..e46d3782cb 100644 --- a/source3/lib/sids.c +++ b/source3/lib/sids.c @@ -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 ****************************************************************************/ @@ -156,6 +216,54 @@ void generate_wellknown_sids(void) } /**************************************************************************** + 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))); } diff --git a/source3/lib/util_pwdb.c b/source3/lib/util_pwdb.c index d80ec5f689..006a68b2c1 100644 --- a/source3/lib/util_pwdb.c +++ b/source3/lib/util_pwdb.c @@ -641,6 +641,8 @@ BOOL pwdb_initialise(BOOL is_server) } } + create_sidmap_table(); + return initialise_password_db(); } diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index b497a1e455..a966484484 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -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) { diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index e774dbae15..8aaeb165cd 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -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)) diff --git a/source3/rpc_client/cli_use.c b/source3/rpc_client/cli_use.c index 99cdb129f7..69e46c081b 100644 --- a/source3/rpc_client/cli_use.c +++ b/source3/rpc_client/cli_use.c @@ -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); } diff --git a/source3/rpcclient/rpcclient.c b/source3/rpcclient/rpcclient.c index ba40920a40..8b1710d368 100644 --- a/source3/rpcclient/rpcclient.c +++ b/source3/rpcclient/rpcclient.c @@ -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(); |