From 7072cc0c9d6b64f286bdb325bdc78aa7dba62ada Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 3 Apr 2010 22:11:08 +0200 Subject: [PATCH] libwbclient: Make wbcListTrusts not use talloc --- nsswitch/libwbclient/wbc_util.c | 48 ++++++++++++++------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/nsswitch/libwbclient/wbc_util.c b/nsswitch/libwbclient/wbc_util.c index 77eabbf939f..75b0093a208 100644 --- a/nsswitch/libwbclient/wbc_util.c +++ b/nsswitch/libwbclient/wbc_util.c @@ -273,21 +273,13 @@ wbcErr wbcResolveWinsByIP(const char *ip, char **name) /** */ -static wbcErr process_domain_info_string(TALLOC_CTX *ctx, - struct wbcDomainInfo *info, +static wbcErr process_domain_info_string(struct wbcDomainInfo *info, char *info_string) { wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; char *r = NULL; char *s = NULL; - if (!info || !info_string) { - wbc_status = WBC_ERR_INVALID_PARAM; - BAIL_ON_WBC_ERROR(wbc_status); - } - - ZERO_STRUCTP(info); - r = info_string; /* Short Name */ @@ -298,7 +290,7 @@ static wbcErr process_domain_info_string(TALLOC_CTX *ctx, *s = '\0'; s++; - info->short_name = talloc_strdup(ctx, r); + info->short_name = strdup(r); BAIL_ON_PTR_ERROR(info->short_name, wbc_status); @@ -311,7 +303,7 @@ static wbcErr process_domain_info_string(TALLOC_CTX *ctx, *s = '\0'; s++; - info->dns_name = talloc_strdup(ctx, r); + info->dns_name = strdup(r); BAIL_ON_PTR_ERROR(info->dns_name, wbc_status); /* SID */ @@ -404,15 +396,24 @@ static wbcErr process_domain_info_string(TALLOC_CTX *ctx, return wbc_status; } +static void wbcDomainInfoListDestructor(void *ptr) +{ + struct wbcDomainInfo *i = (struct wbcDomainInfo *)ptr; + + while (i->short_name != NULL) { + free(i->short_name); + free(i->dns_name); + i += 1; + } +} + /* Enumerate the domain trusts known by Winbind */ wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains) { struct winbindd_response response; wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE; char *p = NULL; - char *q = NULL; char *extra_data = NULL; - int count = 0; struct wbcDomainInfo *d_list = NULL; int i = 0; @@ -440,18 +441,9 @@ wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains) BAIL_ON_WBC_ERROR(wbc_status); } - /* Count number of domains */ - - count = 0; - while (p) { - count++; - - if ((q = strchr(p, '\n')) != NULL) - q++; - p = q; - } - - d_list = talloc_array(NULL, struct wbcDomainInfo, count); + d_list = (struct wbcDomainInfo *)wbcAllocateMemory( + sizeof(struct wbcDomainInfo), response.data.num_entries + 1, + wbcDomainInfoListDestructor); BAIL_ON_PTR_ERROR(d_list, wbc_status); extra_data = strdup((char*)response.extra_data.data); @@ -461,7 +453,7 @@ wbcErr wbcListTrusts(struct wbcDomainInfo **domains, size_t *num_domains) /* Outer loop processes the list of domain information */ - for (i=0; i