summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-11-22 08:31:50 +0000
committerJeremy Allison <jra@samba.org>2001-11-22 08:31:50 +0000
commit1db30a338cf862c4c4e848472551fde9c8a64e41 (patch)
tree85a5d19164e7e947592dcc679e62c5cc746b9fb1
parent609cdbfe37712b26a3cb52d711da986a13ccba7b (diff)
downloadsamba-1db30a338cf862c4c4e848472551fde9c8a64e41.tar.gz
samba-1db30a338cf862c4c4e848472551fde9c8a64e41.tar.bz2
samba-1db30a338cf862c4c4e848472551fde9c8a64e41.zip
Got positive and negative name caching working correctly with lookupname/lookupsid.
There was a bug in cli_lsa_lookup_name/lookup_sid where NT_STATUS_NONE_MAPPED was being mapped to NT_STATUS_OK, and also the *wrong* number of entries mapped was being returned. The correct field is mapped_count, *NOT* num_entries. Jeremy. (This used to be commit 9f8c644abc455510c06dbd5dbac49c6270746560)
-rw-r--r--source3/libsmb/cli_lsarpc.c46
-rw-r--r--source3/nsswitch/winbindd_util.c90
2 files changed, 71 insertions, 65 deletions
diff --git a/source3/libsmb/cli_lsarpc.c b/source3/libsmb/cli_lsarpc.c
index 046422abc6..4850e2a8bb 100644
--- a/source3/libsmb/cli_lsarpc.c
+++ b/source3/libsmb/cli_lsarpc.c
@@ -255,36 +255,37 @@ NTSTATUS cli_lsa_lookup_sids(struct cli_state *cli, TALLOC_CTX *mem_ctx,
result = r.status;
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_FILES_OPEN) &&
- NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_NONE_MAPPED)) {
-
+ if (!NT_STATUS_IS_OK(result) &&
+ NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_FILES_OPEN)) {
/* An actual error occured */
goto done;
}
- result = NT_STATUS_OK;
/* Return output parameters */
- (*num_names) = r.names->num_entries;
-
- if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
- r.names->num_entries))) {
+ if (r.mapped_count == 0) {
+ result = NT_STATUS_NONE_MAPPED;
+ goto done;
+ }
+
+ (*num_names) = r.mapped_count;
+ result = NT_STATUS_OK;
+
+ if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) * r.mapped_count))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- r.names->num_entries))) {
+ if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- for (i = 0; i < r.names->num_entries; i++) {
+ for (i = 0; i < r.mapped_count; i++) {
fstring name, dom_name, full_name;
uint32 dom_idx = t_names.name[i].domain_idx;
@@ -361,35 +362,36 @@ NTSTATUS cli_lsa_lookup_names(struct cli_state *cli, TALLOC_CTX *mem_ctx,
result = r.status;
- if (!NT_STATUS_IS_OK(result) &&
- NT_STATUS_V(result) != NT_STATUS_V(NT_STATUS_NONE_MAPPED)) {
-
+ if (!NT_STATUS_IS_OK(result)) {
/* An actual error occured */
goto done;
}
- result = NT_STATUS_OK;
/* Return output parameters */
- (*num_sids) = r.num_entries;
+ if (r.mapped_count == 0) {
+ result = NT_STATUS_NONE_MAPPED;
+ goto done;
+ }
+
+ (*num_sids) = r.mapped_count;
+ result = NT_STATUS_OK;
- if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
- r.num_entries)))) {
+ if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.mapped_count)))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- r.num_entries)))) {
+ if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.mapped_count)))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- for (i = 0; i < r.num_entries; i++) {
+ for (i = 0; i < r.mapped_count; i++) {
DOM_RID2 *t_rids = r.dom_rid;
uint32 dom_idx = t_rids[i].rid_idx;
uint32 dom_rid = t_rids[i].rid;
diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index 4f50c80c10..457a914e5c 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -76,35 +76,33 @@ struct winbindd_domain *find_domain_from_sid(DOM_SID *sid)
static struct winbindd_domain *add_trusted_domain(char *domain_name,
DOM_SID *domain_sid)
{
- struct winbindd_domain *domain, *tmp;
+ struct winbindd_domain *domain, *tmp;
- for (tmp = domain_list; tmp != NULL; tmp = tmp->next) {
- if (strcmp(domain_name, tmp->name) == 0) {
- DEBUG(3, ("domain %s already in domain list\n",
- domain_name));
- return tmp;
- }
- }
+ for (tmp = domain_list; tmp != NULL; tmp = tmp->next) {
+ if (strcmp(domain_name, tmp->name) == 0) {
+ DEBUG(3, ("domain %s already in domain list\n", domain_name));
+ return tmp;
+ }
+ }
- DEBUG(1, ("adding domain %s\n", domain_name));
+ DEBUG(1, ("adding domain %s\n", domain_name));
- /* Create new domain entry */
+ /* Create new domain entry */
- if ((domain = (struct winbindd_domain *)
- malloc(sizeof(*domain))) == NULL)
- return NULL;
+ if ((domain = (struct winbindd_domain *)malloc(sizeof(*domain))) == NULL)
+ return NULL;
- /* Fill in fields */
+ /* Fill in fields */
- ZERO_STRUCTP(domain);
- fstrcpy(domain->name, domain_name);
- sid_copy(&domain->sid, domain_sid);
+ ZERO_STRUCTP(domain);
+ fstrcpy(domain->name, domain_name);
+ sid_copy(&domain->sid, domain_sid);
- /* Link to domain list */
+ /* Link to domain list */
- DLIST_ADD(domain_list, domain);
+ DLIST_ADD(domain_list, domain);
- return domain;
+ return domain;
}
/* Look up global info for the winbind daemon */
@@ -168,21 +166,21 @@ BOOL get_domain_info(void)
void free_domain_info(void)
{
- struct winbindd_domain *domain;
+ struct winbindd_domain *domain;
- /* Free list of domains */
+ /* Free list of domains */
- if (domain_list) {
- struct winbindd_domain *next_domain;
+ if (domain_list) {
+ struct winbindd_domain *next_domain;
- domain = domain_list;
+ domain = domain_list;
- while(domain) {
- next_domain = domain->next;
- free(domain);
- domain = next_domain;
- }
- }
+ while(domain) {
+ next_domain = domain->next;
+ SAFE_FREE(domain);
+ domain = next_domain;
+ }
+ }
}
/* Connect to a domain controller using get_any_dc_name() to discover
@@ -273,6 +271,9 @@ static void store_sid_by_name_in_cache(fstring name, DOM_SID *sid, enum SID_NAME
sid_to_string(sid_val.sid, sid);
sid_val.type = (int)type;
+ DEBUG(10,("store_sid_by_name_in_cache: storing cache entry %s -> SID %s\n",
+ name, sid_val.sid ));
+
winbindd_store_sid_cache_entry(domain, name, &sid_val);
}
@@ -327,6 +328,9 @@ static void store_name_by_sid_in_cache(DOM_SID *sid, fstring name, enum SID_NAME
fstrcpy( name_val.name, name );
name_val.type = (int)type;
+ DEBUG(10,("store_name_by_sid_in_cache: storing cache entry SID %s -> %s\n",
+ sid_str, name_val.name ));
+
winbindd_store_name_cache_entry(domain, sid_str, &name_val);
}
@@ -715,24 +719,24 @@ BOOL winbindd_lookup_groupmem(struct winbindd_domain *domain,
void free_getent_state(struct getent_state *state)
{
- struct getent_state *temp;
+ struct getent_state *temp;
- /* Iterate over state list */
+ /* Iterate over state list */
- temp = state;
+ temp = state;
- while(temp != NULL) {
- struct getent_state *next;
+ while(temp != NULL) {
+ struct getent_state *next;
- /* Free sam entries then list entry */
+ /* Free sam entries then list entry */
- SAFE_FREE(state->sam_entries);
- DLIST_REMOVE(state, state);
- next = temp->next;
+ SAFE_FREE(state->sam_entries);
+ DLIST_REMOVE(state, state);
+ next = temp->next;
- SAFE_FREE(temp);
- temp = next;
- }
+ SAFE_FREE(temp);
+ temp = next;
+ }
}
/* Parse list of arguments to winbind uid or winbind gid parameters */