From 610f530aee4da9b63cb1cb9005650d27e4846bc0 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 10 Jan 2002 06:20:03 +0000 Subject: A big tidyup while thinking about getting trusted domains being re-read when they are added or removed on the PDC. - renamed GETPWNAM_FROM_{UID,USER} constants and functions to GETPW{NAM,UID} - renamed GETGRNAM_FROM_{GID,GROUP} constants and functions to GETGR{NAM,GID} - use SIGUSR2 in winbindd for debugging/logging instead of SIGUSR1 in preparation for moving to smbcontrol type messages (not sure whether to ditch this altogether or not) - tidy debugging messages in top level winbind user and group routines - convert talloc_init() to talloc_init_named() - make enumerations of the domain list use the same local variable names (This used to be commit eeb8af9c1a66bfcd80823d7b406acbab79857a16) --- source3/nsswitch/winbindd_group.c | 114 +++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 58 deletions(-) (limited to 'source3/nsswitch/winbindd_group.c') diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c index 6e22a8b559..ff15611fba 100644 --- a/source3/nsswitch/winbindd_group.c +++ b/source3/nsswitch/winbindd_group.c @@ -60,19 +60,19 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx; NTSTATUS status; - if (!(mem_ctx = talloc_init())) + if (!(mem_ctx = talloc_init_named("fill_grent_mem(%s)", domain->name))) return False; /* Initialise group membership information */ - DEBUG(10, ("fill_grent_mem(): group %s rid 0x%x\n", - domain ? domain->name : "NULL", group_rid)); + DEBUG(10, ("group %s rid 0x%x\n", domain ? domain->name : "NULL", + group_rid)); *num_gr_mem = 0; if (group_name_type != SID_NAME_DOM_GRP) { - DEBUG(1, ("fill_grent_mem(): rid %d in domain %s isn't a " - "domain group\n", group_rid, domain->name)); + DEBUG(1, ("rid %d in domain %s isn't a " "domain group\n", + group_rid, domain->name)); goto done; } @@ -80,14 +80,13 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, status = domain->methods->lookup_groupmem(domain, mem_ctx, group_rid, &num_names, &rid_mem, &names, &name_types); if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("fill_grent_mem(): could not lookup membership " - "for group rid %d in domain %s\n", + DEBUG(1, ("could not lookup membership for group rid %d in domain %s\n", group_rid, domain->name)); goto done; } - DEBUG(10, ("fill_grent_mem(): looked up %d names\n", num_names)); + DEBUG(10, ("looked up %d names\n", num_names)); if (DEBUGLEVEL >= 10) { for (i = 0; i < num_names; i++) @@ -109,24 +108,21 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, the_name = names[i]; - DEBUG(10, ("fill_grent_mem(): processing name %s\n", - the_name)); + DEBUG(10, ("processing name %s\n", the_name)); /* FIXME: need to cope with groups within groups. These occur in Universal groups on a Windows 2000 native mode server. */ if (name_types[i] != SID_NAME_USER) { - DEBUG(3, ("fill_grent_mem(): name %s isn't a domain " - "user\n", the_name)); + DEBUG(3, ("name %s isn't a domain user\n", the_name)); continue; } /* Don't bother with machine accounts */ if (the_name[strlen(the_name) - 1] == '$') { - DEBUG(10, ("fill_grent_mem(): %s is machine account\n", - the_name)); + DEBUG(10, ("%s is machine account\n", the_name)); continue; } @@ -142,11 +138,9 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, if (!buf) { buf_len += len + 1; /* List is comma separated */ (*num_gr_mem)++; - DEBUG(10, ("fill_grent_mem(): buf_len + %d = %d\n", len + 1, - buf_len)); + DEBUG(10, ("buf_len + %d = %d\n", len + 1, buf_len)); } else { - DEBUG(10, ("fill_grent_mem(): appending %s at index %d\n", - name, len)); + DEBUG(10, ("appending %s at ndx %d\n", name, len)); safe_strcpy(&buf[buf_ndx], name, len); buf_ndx += len; buf[buf_ndx] = ','; @@ -158,7 +152,7 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, if (!buf) { if (!(buf = malloc(buf_len))) { - DEBUG(1, ("fill_grent_mem(): out of memory\n")); + DEBUG(1, ("out of memory\n")); result = False; goto done; } @@ -173,23 +167,22 @@ static BOOL fill_grent_mem(struct winbindd_domain *domain, *gr_mem = buf; *gr_mem_len = buf_len; - DEBUG(10, ("fill_grent_mem(): num_mem = %d, len = %d, mem = %s\n", - *num_gr_mem, buf_len, *num_gr_mem ? buf : "NULL")); - + DEBUG(10, ("num_mem = %d, len = %d, mem = %s\n", *num_gr_mem, + buf_len, *num_gr_mem ? buf : "NULL")); result = True; done: talloc_destroy(mem_ctx); - DEBUG(10, ("fill_grent_mem(): returning %d\n", result)); + DEBUG(10, ("fill_grent_mem returning %d\n", result)); return result; } /* Return a group structure from a group name */ -enum winbindd_result winbindd_getgrnam_from_group(struct winbindd_cli_state *state) +enum winbindd_result winbindd_getgrnam(struct winbindd_cli_state *state) { DOM_SID group_sid; struct winbindd_domain *domain; @@ -214,8 +207,8 @@ enum winbindd_result winbindd_getgrnam_from_group(struct winbindd_cli_state *sta /* Get info for the domain */ if ((domain = find_domain_from_name(name_domain)) == NULL) { - DEBUG(0, ("getgrname_from_group(): could not get domain " - "sid for domain %s\n", name_domain)); + DEBUG(0, ("could not get domain sid for domain %s\n", + name_domain)); return WINBINDD_ERROR; } @@ -223,15 +216,16 @@ enum winbindd_result winbindd_getgrnam_from_group(struct winbindd_cli_state *sta /* Get rid and name type from name */ - if (!winbindd_lookup_sid_by_name(domain, name, &group_sid, &name_type)) { + if (!winbindd_lookup_sid_by_name(domain, name, &group_sid, + &name_type)) { DEBUG(1, ("group %s in domain %s does not exist\n", name_group, name_domain)); return WINBINDD_ERROR; } if ((name_type != SID_NAME_ALIAS) && (name_type != SID_NAME_DOM_GRP)) { - DEBUG(1, ("from_group: name '%s' is not a local or domain " - "group: %d\n", name_group, name_type)); + DEBUG(1, ("name '%s' is not a local or domain group: %d\n", + name_group, name_type)); return WINBINDD_ERROR; } @@ -240,7 +234,7 @@ enum winbindd_result winbindd_getgrnam_from_group(struct winbindd_cli_state *sta sid_split_rid(&group_sid, &group_rid); if (!winbindd_idmap_get_gid_from_rid(domain->name, group_rid, &gid)) { - DEBUG(1, ("error sursing unix gid for sid\n")); + DEBUG(1, ("error converting unix gid to sid\n")); return WINBINDD_ERROR; } @@ -264,8 +258,7 @@ enum winbindd_result winbindd_getgrnam_from_group(struct winbindd_cli_state *sta /* Return a group structure from a gid number */ -enum winbindd_result winbindd_getgrnam_from_gid(struct winbindd_cli_state - *state) +enum winbindd_result winbindd_getgrgid(struct winbindd_cli_state *state) { struct winbindd_domain *domain; DOM_SID group_sid; @@ -288,7 +281,7 @@ enum winbindd_result winbindd_getgrnam_from_gid(struct winbindd_cli_state if (!winbindd_idmap_get_rid_from_gid(state->request.data.gid, &group_rid, &domain)) { - DEBUG(1, ("Could not convert gid %d to rid\n", + DEBUG(1, ("could not convert gid %d to rid\n", state->request.data.gid)); return WINBINDD_ERROR; } @@ -299,7 +292,7 @@ enum winbindd_result winbindd_getgrnam_from_gid(struct winbindd_cli_state sid_append_rid(&group_sid, group_rid); if (!winbindd_lookup_name_by_sid(&group_sid, group_name, &name_type)) { - DEBUG(1, ("Could not lookup sid\n")); + DEBUG(1, ("could not lookup sid\n")); return WINBINDD_ERROR; } @@ -309,8 +302,8 @@ enum winbindd_result winbindd_getgrnam_from_gid(struct winbindd_cli_state if (!((name_type == SID_NAME_ALIAS) || (name_type == SID_NAME_DOM_GRP))) { - DEBUG(1, ("from_gid: name '%s' is not a local or domain " - "group: %d\n", group_name, name_type)); + DEBUG(1, ("name '%s' is not a local or domain group: %d\n", + group_name, name_type)); return WINBINDD_ERROR; } @@ -341,7 +334,7 @@ enum winbindd_result winbindd_getgrnam_from_gid(struct winbindd_cli_state enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state) { - struct winbindd_domain *tmp; + struct winbindd_domain *domain; DEBUG(3, ("[%5d]: setgrent\n", state->pid)); @@ -362,14 +355,14 @@ enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state) if (domain_list == NULL) get_domain_info(); - for (tmp = domain_list; tmp != NULL; tmp = tmp->next) { + for (domain = domain_list; domain != NULL; domain = domain->next) { struct getent_state *domain_state; /* Skip domains other than WINBINDD_DOMAIN environment variable */ if ((strcmp(state->request.domain, "") != 0) && - !check_domain_env(state->request.domain, tmp->name)) + !check_domain_env(state->request.domain, domain->name)) continue; /* Create a state record for this domain */ @@ -380,7 +373,7 @@ enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state) ZERO_STRUCTP(domain_state); - domain_state->domain = tmp; + domain_state->domain = domain; /* Add to list of open domains */ @@ -421,7 +414,8 @@ static BOOL get_sam_group_entries(struct getent_state *ent) if (ent->got_sam_entries) return False; - if (!(mem_ctx = talloc_init())) + if (!(mem_ctx = talloc_init_named("get_sam_group_entries(%s)", + ent->domain->name))) return False; /* Free any existing group info */ @@ -510,7 +504,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) tryagain: - DEBUG(10, ("getgrent(): entry_index = %d, num_entries = %d\n", + DEBUG(10, ("entry_index = %d, num_entries = %d\n", ent->sam_entry_index, ent->num_sam_entries)); if (ent->num_sam_entries == ent->sam_entry_index) { @@ -518,8 +512,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) while(ent && !get_sam_group_entries(ent)) { struct getent_state *next_ent; - DEBUG(10, ("getgrent(): freeing state info for " - "domain %s\n", ent->domain->name)); + DEBUG(10, ("freeing state info for domain %s\n", ent->domain->name)); /* Free state information for this domain */ @@ -547,14 +540,14 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) name_list[ent->sam_entry_index].rid, &group_gid)) { - DEBUG(1, ("getgrent(): could not look up gid for group %s\n", + DEBUG(1, ("could not look up gid for group %s\n", name_list[ent->sam_entry_index].acct_name)); ent->sam_entry_index++; goto tryagain; } - DEBUG(10, ("getgrent(): got gid %d for group %x\n", group_gid, + DEBUG(10, ("got gid %d for group %x\n", group_gid, name_list[ent->sam_entry_index].rid)); /* Fill in group entry */ @@ -585,13 +578,13 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) gr_mem_list_len + gr_mem_len); if (!new_gr_mem_list && (group_list[group_list_ndx].num_gr_mem != 0)) { - DEBUG(0, ("getgrent(): out of memory\n")); + DEBUG(0, ("out of memory\n")); SAFE_FREE(gr_mem_list); gr_mem_list_len = 0; break; } - DEBUG(10, ("getgrent(): list_len = %d, mem_len = %d\n", + DEBUG(10, ("list_len = %d, mem_len = %d\n", gr_mem_list_len, gr_mem_len)); gr_mem_list = new_gr_mem_list; @@ -613,7 +606,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) if (result) { - DEBUG(10, ("getgrent(): adding group num_entries = %d\n", + DEBUG(10, ("adding group num_entries = %d\n", state->response.data.num_entries)); group_list_ndx++; @@ -656,7 +649,7 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state) state->response.length += gr_mem_list_len; - DEBUG(10, ("getgrent(): returning %d groups, length = %d\n", + DEBUG(10, ("returning %d groups, length = %d\n", group_list_ndx, gr_mem_list_len)); /* Out of domains */ @@ -714,8 +707,7 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state) ted = Realloc(extra_data, sizeof(fstring) * total_entries); if (!ted) { - DEBUG(0,("winbindd_list_groups: failed to enlarge " - "buffer!\n")); + DEBUG(0,("failed to enlarge buffer!\n")); SAFE_FREE(extra_data); return WINBINDD_ERROR; } else @@ -773,7 +765,8 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) DEBUG(3, ("[%5d]: getgroups %s\n", state->pid, state->request.data.username)); - if (!(mem_ctx = talloc_init())) + if (!(mem_ctx = talloc_init_named("winbindd_getgroups(%s)", + state->request.data.username))) return WINBINDD_ERROR; /* Parse domain and username */ @@ -794,14 +787,15 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) /* Get rid and name type from name. The following costs 1 packet */ - if (!winbindd_lookup_sid_by_name(domain, name, &user_sid, &name_type)) { + if (!winbindd_lookup_sid_by_name(domain, name, &user_sid, + &name_type)) { DEBUG(1, ("user '%s' does not exist\n", name_user)); goto done; } if (name_type != SID_NAME_USER) { - DEBUG(1, ("name '%s' is not a user name: %d\n", name_user, - name_type)); + DEBUG(1, ("name '%s' is not a user name: %d\n", + name_user, name_type)); goto done; } @@ -819,8 +813,12 @@ enum winbindd_result winbindd_getgroups(struct winbindd_cli_state *state) goto done; for (i = 0; i < num_groups; i++) { - if (!winbindd_idmap_get_gid_from_rid(domain->name, user_gids[i], &gid_list[num_gids])) { - DEBUG(1, ("unable to convert group rid %d to gid\n", user_gids[i])); + if (!winbindd_idmap_get_gid_from_rid(domain->name, + user_gids[i], + &gid_list[num_gids])) { + + DEBUG(1, ("unable to convert group rid %d to gid\n", + user_gids[i])); continue; } -- cgit