From 14ef4cdec1ab6be55c97d0f32780cbddbcdde218 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 15 Dec 2007 22:00:39 +0100 Subject: Replace sid_string_static with sid_to_string This adds 28 fstrings on the stack, but I think an fstring on the stack is still far better than a static one. (This used to be commit c7c885078be8fd3024c186044ac28275d7609679) --- source3/winbindd/idmap_cache.c | 5 ++++- source3/winbindd/idmap_tdb.c | 12 +++++++++--- source3/winbindd/winbindd_async.c | 3 ++- source3/winbindd/winbindd_cache.c | 36 ++++++++++++++++++++++++------------ source3/winbindd/winbindd_group.c | 6 ++++-- 5 files changed, 43 insertions(+), 19 deletions(-) (limited to 'source3/winbindd') diff --git a/source3/winbindd/idmap_cache.c b/source3/winbindd/idmap_cache.c index 6455f5ee69..4e286f88c0 100644 --- a/source3/winbindd/idmap_cache.c +++ b/source3/winbindd/idmap_cache.c @@ -77,7 +77,10 @@ void idmap_cache_shutdown(struct idmap_cache_ctx *cache) NTSTATUS idmap_cache_build_sidkey(TALLOC_CTX *ctx, char **sidkey, const struct id_map *id) { - *sidkey = talloc_asprintf(ctx, "IDMAP/SID/%s", sid_string_static(id->sid)); + fstring sidstr; + + *sidkey = talloc_asprintf(ctx, "IDMAP/SID/%s", + sid_to_string(sidstr, id->sid)); if ( ! *sidkey) { DEBUG(1, ("failed to build sidkey, OOM?\n")); return NT_STATUS_NO_MEMORY; diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c index 1ec7085a3b..d693c357f7 100644 --- a/source3/winbindd/idmap_tdb.c +++ b/source3/winbindd/idmap_tdb.c @@ -712,8 +712,10 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_tdb_context *ctx, struct id_map TDB_DATA data; char *keystr; unsigned long rec_id = 0; + fstring tmp; - if ((keystr = talloc_asprintf(ctx, "%s", sid_string_static(map->sid))) == NULL) { + if ((keystr = talloc_asprintf(ctx, "%s", + sid_to_string(tmp, map->sid))) == NULL) { DEBUG(0, ("Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; goto done; @@ -864,6 +866,7 @@ static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, const struct id_ NTSTATUS ret; TDB_DATA ksid, kid, data; char *ksidstr, *kidstr; + fstring tmp; /* make sure we initialized */ if ( ! dom->initialized) { @@ -905,7 +908,8 @@ static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, const struct id_ goto done; } - if ((ksidstr = talloc_asprintf(ctx, "%s", sid_string_static(map->sid))) == NULL) { + if ((ksidstr = talloc_asprintf( + ctx, "%s", sid_to_string(tmp, map->sid))) == NULL) { DEBUG(0, ("Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; goto done; @@ -977,6 +981,7 @@ static NTSTATUS idmap_tdb_remove_mapping(struct idmap_domain *dom, const struct NTSTATUS ret; TDB_DATA ksid, kid, data; char *ksidstr, *kidstr; + fstring tmp; /* make sure we initialized */ if ( ! dom->initialized) { @@ -1018,7 +1023,8 @@ static NTSTATUS idmap_tdb_remove_mapping(struct idmap_domain *dom, const struct goto done; } - if ((ksidstr = talloc_asprintf(ctx, "%s", sid_string_static(map->sid))) == NULL) { + if ((ksidstr = talloc_asprintf( + ctx, "%s", sid_to_string(tmp, map->sid))) == NULL) { DEBUG(0, ("Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; goto done; diff --git a/source3/winbindd/winbindd_async.c b/source3/winbindd/winbindd_async.c index 1c30558058..0971476f44 100644 --- a/source3/winbindd/winbindd_async.c +++ b/source3/winbindd/winbindd_async.c @@ -458,8 +458,9 @@ bool print_sidlist(TALLOC_CTX *mem_ctx, const DOM_SID *sids, *len = 0; *result = NULL; for (i=0; itdb) { @@ -966,7 +966,7 @@ NTSTATUS wcache_cached_creds_exist(struct winbindd_domain *domain, const DOM_SID return NT_STATUS_INVALID_SID; } - fstr_sprintf(key_str, "CRED/%s", sid_string_static(sid)); + fstr_sprintf(key_str, "CRED/%s", sid_to_string(tmp, sid)); data = tdb_fetch(cache->tdb, string_tdb_data(key_str)); if (!data.dptr) { @@ -991,6 +991,7 @@ NTSTATUS wcache_get_creds(struct winbindd_domain *domain, NTSTATUS status; time_t t; uint32 rid; + fstring tmp; if (!cache->tdb) { return NT_STATUS_INTERNAL_DB_ERROR; @@ -1007,7 +1008,8 @@ NTSTATUS wcache_get_creds(struct winbindd_domain *domain, /* Try and get a salted cred first. If we can't fall back to an unsalted cred. */ - centry = wcache_fetch(cache, domain, "CRED/%s", sid_string_static(sid)); + centry = wcache_fetch(cache, domain, "CRED/%s", + sid_to_string(tmp, sid)); if (!centry) { DEBUG(10,("wcache_get_creds: entry for [CRED/%s] not found\n", sid_string_dbg(sid))); @@ -1555,6 +1557,7 @@ static NTSTATUS rids_to_names(struct winbindd_domain *domain, for (i=0; itdb) goto do_query; - centry = wcache_fetch(cache, domain, "U/%s", sid_string_static(user_sid)); + centry = wcache_fetch(cache, domain, "U/%s", + sid_to_string(tmp, user_sid)); /* If we have an access denied cache entry and a cached info3 in the samlogon cache then do a query. This will force the rpc back end @@ -1852,8 +1857,9 @@ static NTSTATUS lookup_useraliases(struct winbindd_domain *domain, * resulting might come from any of the SIDs. */ for (i=0; itdb, string_tdb_data(key_str)); @@ -3526,6 +3533,8 @@ static int pack_tdc_domains( struct winbindd_tdc_domain *domains, /* now pack each domain trust record */ for ( i=0; i 0 ) { DEBUG(10,("pack_tdc_domains: Packing domain %s (%s)\n", domains[i].domain_name, @@ -3535,7 +3544,7 @@ static int pack_tdc_domains( struct winbindd_tdc_domain *domains, len += tdb_pack( buffer+len, buflen-len, "fffddd", domains[i].domain_name, domains[i].dns_name, - sid_string_static(&domains[i].sid), + sid_to_string(tmp, &domains[i].sid), domains[i].trust_flags, domains[i].trust_attribs, domains[i].trust_type ); @@ -3806,6 +3815,7 @@ static void wcache_save_user_pwinfo(struct winbindd_domain *domain, uint32 gid) { struct cache_entry *centry; + fstring tmp; if ( (centry = centry_start(domain, status)) == NULL ) return; @@ -3815,7 +3825,7 @@ static void wcache_save_user_pwinfo(struct winbindd_domain *domain, centry_put_string( centry, gecos ); centry_put_uint32( centry, gid ); - centry_end(centry, "NSS/PWINFO/%s", sid_string_static(user_sid) ); + centry_end(centry, "NSS/PWINFO/%s", sid_to_string(tmp, user_sid) ); DEBUG(10,("wcache_save_user_pwinfo: %s\n", sid_string_dbg(user_sid) )); @@ -3832,11 +3842,13 @@ NTSTATUS nss_get_info_cached( struct winbindd_domain *domain, struct winbind_cache *cache = get_cache(domain); struct cache_entry *centry = NULL; NTSTATUS nt_status; + fstring tmp; if (!cache->tdb) goto do_query; - centry = wcache_fetch(cache, domain, "NSS/PWINFO/%s", sid_string_static(user_sid)); + centry = wcache_fetch(cache, domain, "NSS/PWINFO/%s", + sid_to_string(tmp, user_sid)); if (!centry) goto do_query; diff --git a/source3/winbindd/winbindd_group.c b/source3/winbindd/winbindd_group.c index dc8cebf92f..49562a112c 100644 --- a/source3/winbindd/winbindd_group.c +++ b/source3/winbindd/winbindd_group.c @@ -1648,7 +1648,8 @@ static void getusersids_recv(void *private_data, bool success, DOM_SID *sids, /* work out the response size */ for (i = 0; i < num_sids; i++) { - const char *s = sid_string_static(&sids[i]); + fstring s; + sid_to_string(s, &sids[i]); ret_size += strlen(s) + 1; } @@ -1661,7 +1662,8 @@ static void getusersids_recv(void *private_data, bool success, DOM_SID *sids, } ofs = 0; for (i = 0; i < num_sids; i++) { - const char *s = sid_string_static(&sids[i]); + fstring s; + sid_to_string(s, &sids[i]); safe_strcpy(ret + ofs, s, ret_size - ofs - 1); ofs += strlen(ret+ofs) + 1; } -- cgit