diff options
author | Volker Lendecke <vl@sernet.de> | 2007-11-24 17:27:54 +0100 |
---|---|---|
committer | Volker Lendecke <vl@sernet.de> | 2007-12-05 14:39:07 +0100 |
commit | 78c6ee0090f4122bc25baaacb5546517ad4b7bc6 (patch) | |
tree | 7b45cf85ff927e70552782b65bd73e50a637195f /source3 | |
parent | 66af0700396a5a5245aa25c95d70a620025b29c9 (diff) | |
download | samba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.tar.gz samba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.tar.bz2 samba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.zip |
Remove some globals
(This used to be commit 31d0a846db08d845e6cdfd85def4ac1c34031e02)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/include/includes.h | 3 | ||||
-rw-r--r-- | source3/lib/util_str.c | 73 | ||||
-rw-r--r-- | source3/libads/dns.c | 2 | ||||
-rw-r--r-- | source3/libgpo/gpo_util.c | 4 | ||||
-rw-r--r-- | source3/libsmb/dsgetdcname.c | 3 | ||||
-rw-r--r-- | source3/libsmb/namecache.c | 6 | ||||
-rw-r--r-- | source3/libsmb/namequery.c | 2 | ||||
-rw-r--r-- | source3/libsmb/trustdom_cache.c | 2 | ||||
-rw-r--r-- | source3/param/loadparm.c | 7 | ||||
-rw-r--r-- | source3/rpc_server/srv_wkssvc_nt.c | 8 | ||||
-rw-r--r-- | source3/utils/net_conf.c | 6 | ||||
-rw-r--r-- | source3/web/swat.c | 17 | ||||
-rw-r--r-- | source3/winbindd/winbindd_util.c | 8 |
13 files changed, 91 insertions, 50 deletions
diff --git a/source3/include/includes.h b/source3/include/includes.h index 9079c3aa82..22530f76af 100644 --- a/source3/include/includes.h +++ b/source3/include/includes.h @@ -1042,6 +1042,9 @@ int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0); +int asprintf_strupper_m(char **strp, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); +char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3); + /* we used to use these fns, but now we have good replacements for snprintf and vsnprintf */ #define slprintf snprintf diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b862299519..f26c8b8a77 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -506,21 +506,6 @@ int strwicmp(const char *psz1, const char *psz2) return (*psz1 - *psz2); } - -/** - Convert a string to upper case, but don't modify it. -**/ - -char *strupper_static(const char *s) -{ - static char *str = NULL; - - SAFE_FREE(str); - str = SMB_STRDUP(s); - strupper_m(str); - return str; -} - /** Convert a string to "normal" form. **/ @@ -1147,7 +1132,7 @@ bool in_list(const char *s, const char *list, bool casesensitive) } /* this is used to prevent lots of mallocs of size 1 */ -static const char *null_string = ""; +static const char null_string[] = ""; /** Set a string value, allocing the space for the string @@ -1561,13 +1546,17 @@ static void split_at_last_component(char *path, char *front, char sep, Write an octal as a string. **/ -const char *octal_string(int i) +char *octal_string(int i) { - static char ret[64]; - if (i == -1) - return "-1"; - slprintf(ret, sizeof(ret)-1, "0%o", i); - return ret; + char *result; + if (i == -1) { + result = talloc_strdup(talloc_tos(), "-1"); + } + else { + result = talloc_asprintf(talloc_tos(), "0%o", i); + } + SMB_ASSERT(result != NULL); + return result; } @@ -2552,7 +2541,7 @@ void rfc1738_unescape(char *buf) } } -static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /** * Decode a base64 string into a DATA_BLOB - simple and slow algorithm @@ -2861,6 +2850,44 @@ void sprintf_append(TALLOC_CTX *mem_ctx, char **string, ssize_t *len, } /* + * asprintf into a string and strupper_m it after that. + */ + +int asprintf_strupper_m(char **strp, const char *fmt, ...) +{ + va_list ap; + char *result; + int ret; + + va_start(ap, fmt); + ret = vasprintf(&result, fmt, ap); + va_end(ap); + + if (ret == -1) + return -1; + + strupper_m(result); + *strp = result; + return ret; +} + +char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start(ap, fmt); + ret = talloc_vasprintf(t, fmt, ap); + va_end(ap); + + if (ret == NULL) { + return NULL; + } + strupper_m(ret); + return ret; +} + +/* Returns the substring from src between the first occurrence of the char "front" and the first occurence of the char "back". Mallocs the return string which must be freed. Not for use diff --git a/source3/libads/dns.c b/source3/libads/dns.c index cdc4b448cf..3239892814 100644 --- a/source3/libads/dns.c +++ b/source3/libads/dns.c @@ -709,7 +709,7 @@ static char *sitename_key(const char *realm) { char *keystr; - if (asprintf(&keystr, SITENAME_KEY, strupper_static(realm)) == -1) { + if (asprintf_strupper_m(&keystr, SITENAME_KEY, realm) == -1) { return NULL; } diff --git a/source3/libgpo/gpo_util.c b/source3/libgpo/gpo_util.c index 126b44cc97..cd532da48b 100644 --- a/source3/libgpo/gpo_util.c +++ b/source3/libgpo/gpo_util.c @@ -693,8 +693,8 @@ NTSTATUS gp_find_file(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } - tmp = talloc_asprintf(mem_ctx, "%s/%s/%s", filename, - strupper_static(path), suffix); + tmp = talloc_asprintf_strupper_m(mem_ctx, "%s/%s/%s", filename, path, + suffix); NT_STATUS_HAVE_NO_MEMORY(tmp); if (sys_stat(tmp, &sbuf) == 0) { diff --git a/source3/libsmb/dsgetdcname.c b/source3/libsmb/dsgetdcname.c index b0870e249e..f8089cbd6a 100644 --- a/source3/libsmb/dsgetdcname.c +++ b/source3/libsmb/dsgetdcname.c @@ -265,8 +265,7 @@ static char *DsGetDcName_cache_key(TALLOC_CTX *mem_ctx, const char *domain) return NULL; } - return talloc_asprintf(mem_ctx, DSGETDCNAME_FMT, - strupper_static(domain)); + return talloc_asprintf_strupper_m(mem_ctx, DSGETDCNAME_FMT, domain); } /**************************************************************** diff --git a/source3/libsmb/namecache.c b/source3/libsmb/namecache.c index 6a675d2ef2..ba706e5ee2 100644 --- a/source3/libsmb/namecache.c +++ b/source3/libsmb/namecache.c @@ -98,7 +98,7 @@ static char* namecache_key(const char *name, int name_type) { char *keystr; - asprintf(&keystr, NBTKEY_FMT, strupper_static(name), name_type); + asprintf_strupper_m(&keystr, NBTKEY_FMT, name, name_type); return keystr; } @@ -318,8 +318,8 @@ static char *namecache_status_record_key(const char *name, char *keystr; print_sockaddr(addr, sizeof(addr), keyip); - asprintf(&keystr, "NBT/%s#%02X.%02X.%s", - strupper_static(name), name_type1, name_type2, addr); + asprintf_strupper_m(&keystr, "NBT/%s#%02X.%02X.%s", name, + name_type1, name_type2, addr); return keystr; } diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index 71d7096914..04db3322ca 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -39,7 +39,7 @@ static char *saf_key(const char *domain) { char *keystr; - asprintf( &keystr, SAFKEY_FMT, strupper_static(domain) ); + asprintf_strupper_m(&keystr, SAFKEY_FMT, domain); return keystr; } diff --git a/source3/libsmb/trustdom_cache.c b/source3/libsmb/trustdom_cache.c index f350cd0bc8..be73381aa3 100644 --- a/source3/libsmb/trustdom_cache.c +++ b/source3/libsmb/trustdom_cache.c @@ -90,7 +90,7 @@ bool trustdom_cache_shutdown(void) static char* trustdom_cache_key(const char* name) { char* keystr = NULL; - asprintf(&keystr, TDOMKEY_FMT, strupper_static(name)); + asprintf_strupper_m(&keystr, TDOMKEY_FMT, name); return keystr; } diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 16c6c59c7d..dcb9b243f4 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -4240,9 +4240,12 @@ static void print_parameter(struct parm_struct *p, void *ptr, FILE * f) fprintf(f, "%c", *(char *)ptr); break; - case P_OCTAL: - fprintf(f, "%s", octal_string(*(int *)ptr)); + case P_OCTAL: { + char *o = octal_string(*(int *)ptr); + fprintf(f, "%s", o); + TALLOC_FREE(o); break; + } case P_LIST: if ((char ***)ptr && *(char ***)ptr) { diff --git a/source3/rpc_server/srv_wkssvc_nt.c b/source3/rpc_server/srv_wkssvc_nt.c index 70cf80c20a..1e43b5ae99 100644 --- a/source3/rpc_server/srv_wkssvc_nt.c +++ b/source3/rpc_server/srv_wkssvc_nt.c @@ -36,10 +36,10 @@ static void create_wks_info_100(struct wkssvc_NetWkstaInfo100 *info100) info100->version_major = lp_major_announce_version(); info100->version_minor = lp_minor_announce_version(); - info100->server_name = talloc_strdup( - info100, strupper_static(global_myname())); - info100->domain_name = talloc_strdup( - info100, strupper_static(lp_workgroup())); + info100->server_name = talloc_asprintf_strupper_m( + info100, "%s", global_myname()); + info100->domain_name = talloc_asprintf_strupper_m( + info100, "%s", lp_workgroup()); return; } diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 6a601d8871..4ff4bd9a29 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -494,9 +494,11 @@ static char *parm_valstr(TALLOC_CTX *ctx, struct parm_struct *parm, } } break; - case P_OCTAL: - valstr = talloc_asprintf(ctx, "%s", octal_string(*(int *)ptr)); + case P_OCTAL: { + char *o = octal_string(*(int *)ptr); + valstr = talloc_move(ctx, &o); break; + } case P_LIST: valstr = talloc_strdup(ctx, ""); if ((char ***)ptr && *(char ***)ptr) { diff --git a/source3/web/swat.c b/source3/web/swat.c index b36168f71f..75a7f1939a 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -324,12 +324,19 @@ static void show_parameter(int snum, struct parm_struct *parm) _("Set Default"), make_parm_name(parm->label),(int)(parm->def.ivalue)); break; - case P_OCTAL: - printf("<input type=text size=8 name=\"parm_%s\" value=%s>", make_parm_name(parm->label), octal_string(*(int *)ptr)); - printf("<input type=button value=\"%s\" onClick=\"swatform.parm_%s.value=\'%s\'\">", - _("Set Default"), make_parm_name(parm->label), - octal_string((int)(parm->def.ivalue))); + case P_OCTAL: { + char *o; + o = octal_string(*(int *)ptr); + printf("<input type=text size=8 name=\"parm_%s\" value=%s>", + make_parm_name(parm->label), o); + TALLOC_FREE(o); + o = octal_string((int)(parm->def.ivalue)); + printf("<input type=button value=\"%s\" " + "onClick=\"swatform.parm_%s.value=\'%s\'\">", + _("Set Default"), make_parm_name(parm->label), o); + TALLOC_FREE(o); break; + } case P_ENUM: printf("<select name=\"parm_%s\">",make_parm_name(parm->label)); diff --git a/source3/winbindd/winbindd_util.c b/source3/winbindd/winbindd_util.c index 5c8c8ea13d..56ae4f27bb 100644 --- a/source3/winbindd/winbindd_util.c +++ b/source3/winbindd/winbindd_util.c @@ -1466,8 +1466,8 @@ static void winbindd_set_locator_kdc_env(const struct winbindd_domain *domain) return; } - if (asprintf(&var, "%s_%s", WINBINDD_LOCATOR_KDC_ADDRESS, - strupper_static(domain->alt_name)) == -1) { + if (asprintf_strupper_m(&var, "%s_%s", WINBINDD_LOCATOR_KDC_ADDRESS, + domain->alt_name) == -1) { return; } @@ -1503,8 +1503,8 @@ void winbindd_unset_locator_kdc_env(const struct winbindd_domain *domain) return; } - if (asprintf(&var, "%s_%s", WINBINDD_LOCATOR_KDC_ADDRESS, - strupper_static(domain->alt_name)) == -1) { + if (asprintf_strupper_m(&var, "%s_%s", WINBINDD_LOCATOR_KDC_ADDRESS, + domain->alt_name) == -1) { return; } |