From a0913929ef6f1e34ff2654e8773c8bf45c6230af Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Feb 2003 00:27:38 +0000 Subject: base64_decode() with heimdal libs, so I've renamed it base64_decode_inplace(). (This used to be commit 8c69212eeb4a0ec144b960d76319fd4940b8c239) --- source3/lib/util_str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 8fe04f0f58..cc4b6fe5c5 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1585,7 +1585,7 @@ DATA_BLOB base64_decode_data_blob(const char *s) /** * Decode a base64 string in-place - wrapper for the above **/ -void base64_decode(char *s) +void base64_decode_inplace(char *s) { DATA_BLOB decoded = base64_decode_data_blob(s); memcpy(s, decoded.data, decoded.length); -- cgit From 1f1125577c000ab72754af00cd83c57fadcc85f1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Feb 2003 11:33:35 +0000 Subject: Move to a in-memory ccache for winbind, and replace setenv() properly. (According to the manpages, you cannot put a stack variable into putenv()). Yes, this leaks memory. Andrew Bartlett (This used to be commit 50bced1e26434ecc7474964062746e2831e5f433) --- source3/lib/replace.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/replace.c b/source3/lib/replace.c index cd48b8d160..0c62ec9bfa 100644 --- a/source3/lib/replace.c +++ b/source3/lib/replace.c @@ -447,3 +447,21 @@ char *rep_inet_ntoa(struct in_addr ip) return t; } #endif + +#ifndef HAVE_SETENV + int setenv(const char *name, const char *value, int overwrite) +{ + char *p = NULL; + int ret = -1; + + asprintf(&p, "%s=%s", name, value); + + if (overwrite || getenv(name)) { + if (p) ret = putenv(p); + } else { + ret = 0; + } + + return ret; +} +#endif -- cgit From 8d8a8c9633ea04d269d70b1fa8f4393cc73f7bbd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 20 Feb 2003 22:26:28 +0000 Subject: Make init_module() and thus smb_load_module() return an int. modules/developer.c: init_module() should return an int (This used to be commit 7f59703550378ff2333e3c851bf1a77037510abd) --- source3/lib/module.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/module.c b/source3/lib/module.c index 6febe8a9f1..dd94f79950 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -22,11 +22,11 @@ #include "includes.h" #ifdef HAVE_DLOPEN -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) { void *handle; init_module_function *init; - NTSTATUS nt_status; + int status; const char *error; /* Always try to use LAZY symbol resolving; if the plugin has @@ -37,7 +37,7 @@ NTSTATUS smb_load_module(const char *module_name) if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); - return NT_STATUS_UNSUCCESSFUL; + return False; } init = sys_dlsym(handle, "init_module"); @@ -47,14 +47,14 @@ NTSTATUS smb_load_module(const char *module_name) error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); - return NT_STATUS_UNSUCCESSFUL; + return False; } - nt_status = init(); + status = init(); DEBUG(2, ("Module '%s' loaded\n", module_name)); - return nt_status; + return status; } /* Load all modules in list and return number of @@ -65,7 +65,7 @@ int smb_load_modules(const char **modules) int success = 0; for(i = 0; modules[i]; i++){ - if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { + if(smb_load_module(modules[i])) { success++; } } @@ -77,10 +77,10 @@ int smb_load_modules(const char **modules) #else /* HAVE_DLOPEN */ -NTSTATUS smb_load_module(const char *module_name) +int smb_load_module(const char *module_name) { DEBUG(0,("This samba executable has not been build with plugin support")); - return NT_STATUS_NOT_SUPPORTED; + return False; } int smb_load_modules(const char **modules) -- cgit From 1fc2976e14f8b79c85514d7947744bc495513670 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 21 Feb 2003 03:05:55 +0000 Subject: Doxygen janitor (This used to be commit 367997562998adb3f80602596c770d9ac319065b) --- source3/lib/util_unistr.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 5c9b4c783b..522ab7eb40 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -95,9 +95,14 @@ static int check_dos_char(smb_ucs2_t c) return (c == c2); } -/******************************************************************* -load the valid character map table -********************************************************************/ +/** + * Load the valid character map table from valid.dat or + * create from the configured codepage. + * + * This function is called whenever the configuration is reloaded. + * However, the valid character table is not changed if it's loaded + * from a file, because we can't unmap files. + **/ void init_valid_table(void) { static int initialised; @@ -114,6 +119,7 @@ void init_valid_table(void) return; } + /* Otherwise, using a dynamically loaded one. */ if (valid_table) free(valid_table); DEBUG(2,("creating default valid table\n")); @@ -128,6 +134,7 @@ void init_valid_table(void) } + /******************************************************************* Write a string in (little-endian) unicode format. src is in the current DOS codepage. len is the length in bytes of the -- cgit From 7e110f782a55d4dca1fb3fedd95bf059c9ec0638 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 22 Feb 2003 12:22:06 +0000 Subject: More signed/unsigned fixes (yes, I run with funny compiler options) and make x_fwrite() match fwrite() in returning a size_t. Andrew Bartlett (This used to be commit 2943c695787b742e9a96b2eefe2d75f681bacf7c) --- source3/lib/hash.c | 10 +++++----- source3/lib/pidfile.c | 2 +- source3/lib/time.c | 2 +- source3/lib/util_file.c | 2 +- source3/lib/util_seaccess.c | 2 +- source3/lib/xfile.c | 7 ++++--- 6 files changed, 13 insertions(+), 12 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/hash.c b/source3/lib/hash.c index 6b7a8476b1..95af485707 100644 --- a/source3/lib/hash.c +++ b/source3/lib/hash.c @@ -28,7 +28,7 @@ #include "includes.h" static BOOL enlarge_hash_table(hash_table *table); -static int primes[] = +static unsigned primes[] = {17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411}; /**************************************************************************** @@ -47,9 +47,9 @@ static int primes[] = **************************************************************************** */ -BOOL hash_table_init(hash_table *table, int num_buckets, compare_function compare_func) +BOOL hash_table_init(hash_table *table, unsigned num_buckets, compare_function compare_func) { - int i; + unsigned i; ubi_dlList *bucket; table->num_elements = 0; @@ -118,7 +118,7 @@ static hash_element *hash_chain_find(hash_table *table, ubi_dlList *hash_chain, { hash_element *hash_elem; ubi_dlNodePtr lru_item; - int i = 0; + unsigned int i = 0; for (hash_elem = (hash_element *)(ubi_dlFirst(hash_chain)); i < hash_chain->count; i++, hash_elem = (hash_element *)(ubi_dlNext(hash_elem))) { @@ -299,7 +299,7 @@ static BOOL enlarge_hash_table(hash_table *table) void hash_clear(hash_table *table) { - int i; + unsigned int i; ubi_dlList *bucket = table->buckets; hash_element *hash_elem; for (i = 0; i < table->size; bucket++, i++) { diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c index 16a12656b3..1a462bf128 100644 --- a/source3/lib/pidfile.c +++ b/source3/lib/pidfile.c @@ -100,7 +100,7 @@ void pidfile_create(const char *name) memset(buf, 0, sizeof(buf)); slprintf(buf, sizeof(buf) - 1, "%u\n", (unsigned int) sys_getpid()); - if (write(fd, buf, strlen(buf)) != strlen(buf)) { + if (write(fd, buf, strlen(buf)) != (ssize_t)strlen(buf)) { DEBUG(0,("ERROR: can't write to file %s: %s\n", pidFile, strerror(errno))); exit(1); diff --git a/source3/lib/time.c b/source3/lib/time.c index ea5c6837bf..f76a1bdc0d 100644 --- a/source3/lib/time.c +++ b/source3/lib/time.c @@ -479,7 +479,7 @@ check if it's a null mtime ****************************************************************************/ BOOL null_mtime(time_t mtime) { - if (mtime == 0 || mtime == 0xFFFFFFFF || mtime == (time_t)-1) + if (mtime == 0 || mtime == (time_t)0xFFFFFFFF || mtime == (time_t)-1) return(True); return(False); } diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 4babab8931..02acbd4d7e 100644 --- a/source3/lib/util_file.c +++ b/source3/lib/util_file.c @@ -593,7 +593,7 @@ BOOL file_save(const char *fname, void *packet, size_t length) if (fd == -1) { return False; } - if (write(fd, packet, length) != length) { + if (write(fd, packet, length) != (size_t)length) { return False; } close(fd); diff --git a/source3/lib/util_seaccess.c b/source3/lib/util_seaccess.c index 21d7fe8599..eba8cab7fb 100644 --- a/source3/lib/util_seaccess.c +++ b/source3/lib/util_seaccess.c @@ -343,7 +343,7 @@ SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr, SEC_DESC *sd; SEC_ACL *new_dacl, *the_acl; SEC_ACE *new_ace_list = NULL; - int new_ace_list_ndx = 0, i; + unsigned int new_ace_list_ndx = 0, i; size_t size; /* Currently we only process the dacl when creating the child. The diff --git a/source3/lib/xfile.c b/source3/lib/xfile.c index 57f3e27638..1534dd855e 100644 --- a/source3/lib/xfile.c +++ b/source3/lib/xfile.c @@ -140,9 +140,10 @@ int x_fclose(XFILE *f) } /* simulate fwrite() */ -int x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) +size_t x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) { - int ret, total=0; + ssize_t ret; + size_t total=0; /* we might be writing unbuffered */ if (f->buftype == X_IONBF || @@ -154,7 +155,7 @@ int x_fwrite(const void *p, size_t size, size_t nmemb, XFILE *f) while (total < size*nmemb) { - int n = f->bufsize - f->bufused; + size_t n = f->bufsize - f->bufused; n = MIN(n, (size*nmemb)-total); if (n == 0) { -- cgit From bfc5f0ba8e7fed1f95f83cb1ee43631e307927fb Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 23 Feb 2003 17:40:43 +0000 Subject: move genparser to use talloc contexts instead of [m|c|re]alloc() and free()s (This used to be commit 70fce680c01fa1baa65fb3cbc83dfaf822fdadd7) --- source3/lib/genparser.c | 233 ++++++++++++++++++++++-------------------- source3/lib/genparser_samba.c | 82 +++++++-------- 2 files changed, 163 insertions(+), 152 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/genparser.c b/source3/lib/genparser.c index 9fa9dbd33b..233050b432 100644 --- a/source3/lib/genparser.c +++ b/source3/lib/genparser.c @@ -34,12 +34,12 @@ static int all_zero(const char *ptr, unsigned size) } /* encode a buffer of bytes into a escaped string */ -static char *encode_bytes(const char *ptr, unsigned len) +static char *encode_bytes(TALLOC_CTX *mem_ctx, const char *ptr, unsigned len) { const char *hexdig = "0123456789abcdef"; char *ret, *p; unsigned i; - ret = malloc(len*3 + 1); /* worst case size */ + ret = talloc(mem_ctx, len*3 + 1); /* worst case size */ if (!ret) return NULL; for (p=ret,i=0;i 255) { - free(ret); return NULL; } *(unsigned char *)p = v; @@ -96,11 +100,11 @@ static char *decode_bytes(const char *s, unsigned *len) parse_string */ /* allocate more space if needed */ -static int addgen_alloc(struct parse_string *p, int n) +static int addgen_alloc(TALLOC_CTX *mem_ctx, struct parse_string *p, int n) { if (p->length + n <= p->allocated) return 0; p->allocated = p->length + n + 200; - p->s = realloc(p->s, p->allocated); + p->s = talloc_realloc(mem_ctx, p->s, p->allocated); if (!p->s) { errno = ENOMEM; return -1; @@ -109,9 +113,9 @@ static int addgen_alloc(struct parse_string *p, int n) } /* add a character to the buffer */ -static int addchar(struct parse_string *p, char c) +static int addchar(TALLOC_CTX *mem_ctx, struct parse_string *p, char c) { - if (addgen_alloc(p, 2) != 0) { + if (addgen_alloc(mem_ctx, p, 2) != 0) { return -1; } p->s[p->length++] = c; @@ -120,10 +124,10 @@ static int addchar(struct parse_string *p, char c) } /* add a string to the buffer */ -int addstr(struct parse_string *p, const char *s) +int addstr(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *s) { int len = strlen(s); - if (addgen_alloc(p, len+1) != 0) { + if (addgen_alloc(mem_ctx, p, len+1) != 0) { return -1; } memcpy(p->s + p->length, s, len+1); @@ -132,10 +136,10 @@ int addstr(struct parse_string *p, const char *s) } /* add a string to the buffer with a tab prefix */ -static int addtabbed(struct parse_string *p, const char *s, unsigned indent) +static int addtabbed(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *s, unsigned indent) { int len = strlen(s); - if (addgen_alloc(p, indent+len+1) != 0) { + if (addgen_alloc(mem_ctx, p, indent+len+1) != 0) { return -1; } while (indent--) { @@ -147,7 +151,7 @@ static int addtabbed(struct parse_string *p, const char *s, unsigned indent) } /* note! this can only be used for results up to 60 chars wide! */ -int addshort(struct parse_string *p, const char *fmt, ...) +int addshort(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *fmt, ...) { char buf[60]; int n; @@ -155,7 +159,7 @@ int addshort(struct parse_string *p, const char *fmt, ...) va_start(ap, fmt); n = vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - if (addgen_alloc(p, n + 1) != 0) { + if (addgen_alloc(mem_ctx, p, n + 1) != 0) { return -1; } if (n != 0) { @@ -170,7 +174,7 @@ int addshort(struct parse_string *p, const char *fmt, ...) this is here to make it easier for people to write dump functions for their own types */ -int gen_addgen(struct parse_string *p, const char *fmt, ...) +int gen_addgen(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *fmt, ...) { char *buf = NULL; int n; @@ -178,7 +182,7 @@ int gen_addgen(struct parse_string *p, const char *fmt, ...) va_start(ap, fmt); n = vasprintf(&buf, fmt, ap); va_end(ap); - if (addgen_alloc(p, n + 1) != 0) { + if (addgen_alloc(mem_ctx, p, n + 1) != 0) { if (buf) free(buf); return -1; } @@ -192,7 +196,8 @@ int gen_addgen(struct parse_string *p, const char *fmt, ...) } /* dump a enumerated type */ -int gen_dump_enum(const struct enum_struct *einfo, +int gen_dump_enum(TALLOC_CTX *mem_ctx, + const struct enum_struct *einfo, struct parse_string *p, const char *ptr, unsigned indent) @@ -201,36 +206,37 @@ int gen_dump_enum(const struct enum_struct *einfo, int i; for (i=0;einfo[i].name;i++) { if (v == einfo[i].value) { - addstr(p, einfo[i].name); + addstr(mem_ctx, p, einfo[i].name); return 0; } } /* hmm, maybe we should just fail? */ - return gen_dump_unsigned(p, ptr, indent); + return gen_dump_unsigned(mem_ctx, p, ptr, indent); } /* dump a single non-array element, hanlding struct and enum */ -static int gen_dump_one(struct parse_string *p, - const struct parse_struct *pinfo, - const char *ptr, - unsigned indent) +static int gen_dump_one(TALLOC_CTX *mem_ctx, + struct parse_string *p, + const struct parse_struct *pinfo, + const char *ptr, + unsigned indent) { if (pinfo->dump_fn == gen_dump_char && pinfo->ptr_count == 1) { - char *s = encode_bytes(ptr, strlen(ptr)); - if (addchar(p,'{') || - addstr(p, s) || - addstr(p, "}")) { - free(s); + char *s = encode_bytes(mem_ctx, ptr, strlen(ptr)); + if (addchar(mem_ctx, p,'{') || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}")) { return -1; } return 0; } - return pinfo->dump_fn(p, ptr, indent); + return pinfo->dump_fn(mem_ctx, p, ptr, indent); } /* handle dumping of an array of arbitrary type */ -static int gen_dump_array(struct parse_string *p, +static int gen_dump_array(TALLOC_CTX *mem_ctx, + struct parse_string *p, const struct parse_struct *pinfo, const char *ptr, int array_len, @@ -242,13 +248,12 @@ static int gen_dump_array(struct parse_string *p, if (array_len != 0 && pinfo->ptr_count == 0 && pinfo->dump_fn == gen_dump_char) { - char *s = encode_bytes(ptr, array_len); + char *s = encode_bytes(mem_ctx, ptr, array_len); if (!s) return -1; - if (addtabbed(p, pinfo->name, indent) || - addstr(p, " = {") || - addstr(p, s) || - addstr(p, "}\n")) { - free(s); + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addstr(mem_ctx, p, " = {") || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}\n")) { return -1; } free(s); @@ -272,23 +277,23 @@ static int gen_dump_array(struct parse_string *p, continue; } if (count == 0) { - if (addtabbed(p, pinfo->name, indent) || - addshort(p, " = %u:", i)) { + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addshort(mem_ctx, p, " = %u:", i)) { return -1; } } else { - if (addshort(p, ", %u:", i) != 0) { + if (addshort(mem_ctx, p, ", %u:", i) != 0) { return -1; } } - if (gen_dump_one(p, pinfo, p2, indent) != 0) { + if (gen_dump_one(mem_ctx, p, pinfo, p2, indent) != 0) { return -1; } ptr += size; count++; } if (count) { - return addstr(p, "\n"); + return addstr(mem_ctx, p, "\n"); } return 0; } @@ -325,36 +330,35 @@ static int find_var(const struct parse_struct *pinfo, } -int gen_dump_struct(const struct parse_struct *pinfo, +int gen_dump_struct(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, struct parse_string *p, const char *ptr, unsigned indent) { - char *s = gen_dump(pinfo, ptr, indent+1); + char *s = gen_dump(mem_ctx, pinfo, ptr, indent+1); if (!s) return -1; - if (addstr(p, "{\n") || - addstr(p,s) || - addtabbed(p,"}", indent)) { - free(s); + if (addstr(mem_ctx, p, "{\n") || + addstr(mem_ctx, p, s) || + addtabbed(mem_ctx, p, "}", indent)) { return -1; } - free(s); return 0; } -static int gen_dump_string(struct parse_string *p, +static int gen_dump_string(TALLOC_CTX *mem_ctx, + struct parse_string *p, const struct parse_struct *pinfo, const char *data, unsigned indent) { const char *ptr = *(char **)data; - char *s = encode_bytes(ptr, strlen(ptr)); - if (addtabbed(p, pinfo->name, indent) || - addstr(p, " = ") || - addchar(p,'{') || - addstr(p, s) || - addstr(p, "}\n")) { - free(s); + char *s = encode_bytes(mem_ctx, ptr, strlen(ptr)); + if (addtabbed(mem_ctx, p, pinfo->name, indent) || + addstr(mem_ctx, p, " = ") || + addchar(mem_ctx, p, '{') || + addstr(mem_ctx, p, s) || + addstr(mem_ctx, p, "}\n")) { return -1; } return 0; @@ -370,7 +374,7 @@ static int len_nullterm(const char *ptr, int size, int array_len) if (size == 1) { len = strnlen(ptr, array_len); } else { - for (len=0;lenparse_fn == gen_parse_char && pinfo->ptr_count==1) { unsigned len; - char *s = decode_bytes(str, &len); + char *s = decode_bytes(mem_ctx, str, &len); if (!s) return -1; *(char **)ptr = s; return 0; } if (pinfo->ptr_count) { + unsigned size = pinfo->ptr_count>1?sizeof(void *):pinfo->size; struct parse_struct p2 = *pinfo; - *(void **)ptr = calloc(1, pinfo->ptr_count>1?sizeof(void *):pinfo->size); + *(void **)ptr = talloc(mem_ctx, size); if (! *(void **)ptr) { return -1; } + memset(*(void **)ptr, 0, size); ptr = *(char **)ptr; p2.ptr_count--; - return gen_parse_base(&p2, ptr, str); + return gen_parse_base(mem_ctx, &p2, ptr, str); } - return pinfo->parse_fn(ptr, str); + return pinfo->parse_fn(mem_ctx, ptr, str); } /* parse a generic array */ -static int gen_parse_array(const struct parse_struct *pinfo, - char *ptr, - const char *str, - int array_len) +static int gen_parse_array(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, + char *ptr, + const char *str, + int array_len) { char *p, *p2; unsigned size = pinfo->size; @@ -564,11 +574,10 @@ static int gen_parse_array(const struct parse_struct *pinfo, pinfo->ptr_count == 0 && pinfo->dump_fn == gen_dump_char) { unsigned len = 0; - char *s = decode_bytes(str, &len); - if (!s) return -1; + char *s = decode_bytes(mem_ctx, str, &len); + if (!s || (len > array_len)) return -1; memset(ptr, 0, array_len); memcpy(ptr, s, len); - free(s); return 0; } @@ -593,7 +602,7 @@ static int gen_parse_array(const struct parse_struct *pinfo, p[strlen(p)-1] = 0; } - if (gen_parse_base(pinfo, ptr + idx*size, p) != 0) { + if (gen_parse_base(mem_ctx, pinfo, ptr + idx*size, p) != 0) { return -1; } @@ -605,7 +614,8 @@ static int gen_parse_array(const struct parse_struct *pinfo, } /* parse one element, hanlding dynamic and static arrays */ -static int gen_parse_one(const struct parse_struct *pinfo, +static int gen_parse_one(TALLOC_CTX *mem_ctx, + const struct parse_struct *pinfo, const char *name, char *data, const char *str) @@ -621,7 +631,8 @@ static int gen_parse_one(const struct parse_struct *pinfo, } if (pinfo[i].array_len) { - return gen_parse_array(&pinfo[i], data+pinfo[i].offset, + return gen_parse_array(mem_ctx, &pinfo[i], + data+pinfo[i].offset, str, pinfo[i].array_len); } @@ -632,33 +643,33 @@ static int gen_parse_one(const struct parse_struct *pinfo, return -1; } if (len > 0) { - unsigned size; struct parse_struct p2 = pinfo[i]; char *ptr; - size = pinfo[i].ptr_count>1?sizeof(void*):pinfo[i].size; - ptr = calloc(len, size); + unsigned size = pinfo[i].ptr_count>1?sizeof(void*):pinfo[i].size; + ptr = talloc(mem_ctx, len*size); if (!ptr) { errno = ENOMEM; return -1; } + memset(ptr, 0, len*size); *((char **)(data + pinfo[i].offset)) = ptr; p2.ptr_count--; p2.dynamic_len = NULL; - return gen_parse_array(&p2, ptr, str, len); + return gen_parse_array(mem_ctx, &p2, ptr, str, len); } return 0; } - return gen_parse_base(&pinfo[i], data + pinfo[i].offset, str); + return gen_parse_base(mem_ctx, &pinfo[i], data + pinfo[i].offset, str); } -int gen_parse_struct(const struct parse_struct *pinfo, char *ptr, const char *str) +int gen_parse_struct(TALLOC_CTX * mem_ctx, const struct parse_struct *pinfo, char *ptr, const char *str) { - return gen_parse(pinfo, ptr, str); + return gen_parse(mem_ctx, pinfo, ptr, str); } /* the main parse routine */ -int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) +int gen_parse(TALLOC_CTX *mem_ctx, const struct parse_struct *pinfo, char *data, const char *s) { char *str, *s0; @@ -694,7 +705,7 @@ int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) *str++ = 0; - if (gen_parse_one(pinfo, name, data, value) != 0) { + if (gen_parse_one(mem_ctx, pinfo, name, data, value) != 0) { free(s0); return -1; } @@ -708,68 +719,68 @@ int gen_parse(const struct parse_struct *pinfo, char *data, const char *s) /* for convenience supply some standard dumpers and parsers here */ -int gen_parse_char(char *ptr, const char *str) +int gen_parse_char(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(unsigned char *)ptr = atoi(str); return 0; } -int gen_parse_int(char *ptr, const char *str) +int gen_parse_int(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(int *)ptr = atoi(str); return 0; } -int gen_parse_unsigned(char *ptr, const char *str) +int gen_parse_unsigned(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(unsigned *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_time_t(char *ptr, const char *str) +int gen_parse_time_t(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(time_t *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_double(char *ptr, const char *str) +int gen_parse_double(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(double *)ptr = atof(str); return 0; } -int gen_parse_float(char *ptr, const char *str) +int gen_parse_float(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(float *)ptr = atof(str); return 0; } -int gen_dump_char(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_char(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(unsigned char *)(ptr)); + return addshort(mem_ctx, p, "%u", *(unsigned char *)(ptr)); } -int gen_dump_int(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_int(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%d", *(int *)(ptr)); + return addshort(mem_ctx, p, "%d", *(int *)(ptr)); } -int gen_dump_unsigned(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_unsigned(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(unsigned *)(ptr)); + return addshort(mem_ctx, p, "%u", *(unsigned *)(ptr)); } -int gen_dump_time_t(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_time_t(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(time_t *)(ptr)); + return addshort(mem_ctx, p, "%u", *(time_t *)(ptr)); } -int gen_dump_double(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_double(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%lg", *(double *)(ptr)); + return addshort(mem_ctx, p, "%lg", *(double *)(ptr)); } -int gen_dump_float(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_float(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%g", *(float *)(ptr)); + return addshort(mem_ctx, p, "%g", *(float *)(ptr)); } diff --git a/source3/lib/genparser_samba.c b/source3/lib/genparser_samba.c index 6c700d1094..bece587747 100644 --- a/source3/lib/genparser_samba.c +++ b/source3/lib/genparser_samba.c @@ -22,25 +22,25 @@ /* PARSE functions */ -int gen_parse_uint8(char *ptr, const char *str) +int gen_parse_uint8(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint8 *)ptr = atoi(str); return 0; } -int gen_parse_uint16(char *ptr, const char *str) +int gen_parse_uint16(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint16 *)ptr = atoi(str); return 0; } -int gen_parse_uint32(char *ptr, const char *str) +int gen_parse_uint32(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { *(uint32 *)ptr = strtoul(str, NULL, 10); return 0; } -int gen_parse_NTTIME(char *ptr, const char *str) +int gen_parse_NTTIME(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(sscanf(str, "%u,%u", &(((NTTIME *)(ptr))->high), &(((NTTIME *)(ptr))->low)) != 2) { errno = EINVAL; @@ -49,19 +49,19 @@ int gen_parse_NTTIME(char *ptr, const char *str) return 0; } -int gen_parse_DOM_SID(char *ptr, const char *str) +int gen_parse_DOM_SID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(!string_to_sid((DOM_SID *)ptr, str)) return -1; return 0; } -int gen_parse_SEC_ACCESS(char *ptr, const char *str) +int gen_parse_SEC_ACCESS(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { ((SEC_ACCESS *)ptr)->mask = strtoul(str, NULL, 10); return 0; } -int gen_parse_GUID(char *ptr, const char *str) +int gen_parse_GUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { int info[GUID_SIZE]; int i; @@ -89,27 +89,27 @@ int gen_parse_GUID(char *ptr, const char *str) return 0; } -int gen_parse_SEC_ACE(char *ptr, const char *str) +int gen_parse_SEC_ACE(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_ace_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_ace_info, ptr, str); } -int gen_parse_SEC_ACL(char *ptr, const char *str) +int gen_parse_SEC_ACL(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_acl_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_acl_info, ptr, str); } -int gen_parse_SEC_DESC(char *ptr, const char *str) +int gen_parse_SEC_DESC(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_security_descriptor_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_security_descriptor_info, ptr, str); } -int gen_parse_LUID_ATTR(char *ptr, const char *str) +int gen_parse_LUID_ATTR(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { - return gen_parse_struct(pinfo_luid_attr_info, ptr, str); + return gen_parse_struct(mem_ctx, pinfo_luid_attr_info, ptr, str); } -int gen_parse_LUID(char *ptr, const char *str) +int gen_parse_LUID(TALLOC_CTX *mem_ctx, char *ptr, const char *str) { if(sscanf(str, "%u,%u", &(((LUID *)(ptr))->high), &(((LUID *)(ptr))->low)) != 2) { errno = EINVAL; @@ -122,79 +122,79 @@ int gen_parse_LUID(char *ptr, const char *str) /* DUMP functions */ -int gen_dump_uint8(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint8(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint8 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint8 *)(ptr)); } -int gen_dump_uint16(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint16(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint16 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint16 *)(ptr)); } -int gen_dump_uint32(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_uint32(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", *(uint32 *)(ptr)); + return addshort(mem_ctx, p, "%u", *(uint32 *)(ptr)); } -int gen_dump_NTTIME(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_NTTIME(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { uint32 low, high; high = ((NTTIME *)(ptr))->high; low = ((NTTIME *)(ptr))->low; - return addshort(p, "%u,%u", high, low); + return addshort(mem_ctx, p, "%u,%u", high, low); } -int gen_dump_DOM_SID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_DOM_SID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { fstring sidstr; sid_to_string(sidstr, (DOM_SID *)ptr); - return addstr(p, sidstr); + return addstr(mem_ctx, p, sidstr); } -int gen_dump_SEC_ACCESS(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACCESS(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return addshort(p, "%u", ((SEC_ACCESS *)ptr)->mask); + return addshort(mem_ctx, p, "%u", ((SEC_ACCESS *)ptr)->mask); } -int gen_dump_GUID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_GUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { int i, r; for (i = 0; i < (GUID_SIZE - 1); i++) { - if (!(r = addshort(p, "%d,", ((GUID *)ptr)->info[i]))) return r; + if (!(r = addshort(mem_ctx, p, "%d,", ((GUID *)ptr)->info[i]))) return r; } - return addshort(p, "%d", ((GUID *)ptr)->info[i]); + return addshort(mem_ctx, p, "%d", ((GUID *)ptr)->info[i]); } -int gen_dump_SEC_ACE(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACE(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_ace_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_ace_info, p, ptr, indent); } -int gen_dump_SEC_ACL(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_ACL(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_acl_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_acl_info, p, ptr, indent); } -int gen_dump_SEC_DESC(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_SEC_DESC(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_security_descriptor_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_security_descriptor_info, p, ptr, indent); } -int gen_dump_LUID_ATTR(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_LUID_ATTR(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { - return gen_dump_struct(pinfo_luid_attr_info, p, ptr, indent); + return gen_dump_struct(mem_ctx, pinfo_luid_attr_info, p, ptr, indent); } -int gen_dump_LUID(struct parse_string *p, const char *ptr, unsigned indent) +int gen_dump_LUID(TALLOC_CTX *mem_ctx, struct parse_string *p, const char *ptr, unsigned indent) { uint32 low, high; high = ((LUID *)(ptr))->high; low = ((LUID *)(ptr))->low; - return addshort(p, "%u,%u", high, low); + return addshort(mem_ctx, p, "%u,%u", high, low); } -- cgit From e68684aa65b579081163c175d681b7867a0828bf Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 01:13:31 +0000 Subject: Fix 2 off-by-one bugs in the use of malloc()ed strings and safe_strcpy(). safe_strcpy() isn't particularly safe (this has been noted before) as it does not take the size of the buffer, but instead the size of the buffer *minus 1* The locking.c fix was causing segfaults on machines running with --enable-developer, and was tracked down thanks to the fact that vance's build farm machine runs with such an option, and smbtorture's DIR1 test hits this bug very well. (The --enable-developer code writes to the last byte of the string, to check for incorrect use of safe_strcpy()). Andrew Bartlett (This used to be commit e908fd164d1b11b6f76a6fdffb22e139813cb3c0) --- source3/lib/hash.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/hash.c b/source3/lib/hash.c index 95af485707..c7b1493b4c 100644 --- a/source3/lib/hash.c +++ b/source3/lib/hash.c @@ -171,6 +171,7 @@ hash_element *hash_insert(hash_table *table, char *value, char *key) hash_element *hash_elem; ubi_dlNodePtr lru_item; ubi_dlList *bucket; + size_t string_length; /* * If the hash table size has not reached the MAX_HASH_TABLE_SIZE, @@ -204,12 +205,13 @@ hash_element *hash_insert(hash_table *table, char *value, char *key) * string. */ - if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + strlen(key)))) { + string_length = strlen(key); + if(!(hash_elem = (hash_element *) malloc(sizeof(hash_element) + string_length))) { DEBUG(0,("hash_insert: malloc fail !\n")); return (hash_element *)NULL; } - safe_strcpy((char *) hash_elem->key, key, strlen(key)+1); + safe_strcpy((char *) hash_elem->key, key, string_length); hash_elem->value = (char *)value; hash_elem->bucket = bucket; -- cgit From ded88da1ea1fdcd6da017de2e1378578971f7645 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 02:11:32 +0000 Subject: Add const (This used to be commit ffaa608be01d72075942ca3aff2325c6364e0556) --- source3/lib/util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 13f5b17781..3958600cbd 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -309,9 +309,9 @@ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, const gid_t *groups) Like atoi but gets the value up to the separator character. ****************************************************************************/ -static char *Atoic(char *p, int *n, char *c) +static const char *Atoic(const char *p, int *n, const char *c) { - if (!isdigit((int)*p)) { + if (!isdigit((const int)*p)) { DEBUG(5, ("Atoic: malformed number\n")); return NULL; } @@ -333,7 +333,7 @@ static char *Atoic(char *p, int *n, char *c) Reads a list of numbers. *************************************************************************/ -char *get_numlist(char *p, uint32 **num, int *count) +const char *get_numlist(const char *p, uint32 **num, int *count) { int val; @@ -2400,7 +2400,7 @@ static BOOL unix_do_match(char *regexp, char *str) Simple case insensitive interface to a UNIX wildcard matcher. *******************************************************************/ -BOOL unix_wild_match(char *pattern, char *string) +BOOL unix_wild_match(const char *pattern, const char *string) { pstring p2, s2; char *p; -- cgit From 5b5453e6c799cbf3fa7638950825e3b1c276cdc2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 24 Feb 2003 04:42:24 +0000 Subject: Merge documentation from 3_0. (This used to be commit 5002555a9719987ccdc887ffff64ea8d02c9881d) --- source3/lib/charcnv.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index bffa2a378c..a8df003f8b 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -22,17 +22,24 @@ */ #include "includes.h" -static pstring cvtbuf; - -static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; - /** * @file * - * Character set conversion routines. + * @brief Character-set conversion routines built on our iconv. + * + * @note Samba's internal character set (at least in the 3.0 series) + * is always the same as the one for the Unix filesystem. It is + * not necessarily UTF-8 and may be different on machines that + * need i18n filenames to be compatible with Unix software. It does + * have to be a superset of ASCII. All multibyte sequences must start + * with a byte with the high bit set. * * @sa lib/iconv.c - **/ + */ + +static pstring cvtbuf; + +static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; /** -- cgit From 426cd68f74bb0490df54da500d3d9c1ea475e16f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 24 Feb 2003 11:23:15 +0000 Subject: Move off-by-one buggy malloc()/safe_strcpy() combination to strdup() instead. Andrew Bartlett (This used to be commit c26881633d8a7f6d9b9ed9c6a97ce2b45bf2b317) --- source3/lib/util_getent.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_getent.c b/source3/lib/util_getent.c index 7d45287bba..32641dbf83 100644 --- a/source3/lib/util_getent.c +++ b/source3/lib/util_getent.c @@ -224,18 +224,16 @@ static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_he for (i = 0; i < num_users; i++) { struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry)); - size_t len = strlen(grp->gr_mem[i])+1; if (entry == NULL) { free_userlist(list_head); return NULL; } - entry->unix_name = (char *)malloc(len); + entry->unix_name = (char *)strdup(grp->gr_mem[i]); if (entry->unix_name == NULL) { SAFE_FREE(entry); free_userlist(list_head); return NULL; } - safe_strcpy(entry->unix_name, grp->gr_mem[i],len); DLIST_ADD(list_head, entry); } return list_head; -- cgit From f7bb6982980abf32b98fee8e2624bb5932554dfe Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 26 Feb 2003 06:19:16 +0000 Subject: init_valid_table: Fix a memory leak that would lose the dynamically-created valid table every time the configuration was reloaded. (This used to be commit e42b237d980461caf2dd2a8f82c17bf674facb7d) --- source3/lib/util_unistr.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 522ab7eb40..c666155f9f 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -105,27 +105,34 @@ static int check_dos_char(smb_ucs2_t c) **/ void init_valid_table(void) { - static int initialised; static int mapped_file; int i; const char *allowed = ".!#$%&'()_-@^`~"; + uint8 *valid_file; - if (initialised && mapped_file) return; - initialised = 1; + if (mapped_file) { + /* Can't unmap files, so stick with what we have */ + return; + } - valid_table = map_file(lib_path("valid.dat"), 0x10000); - if (valid_table) { + valid_file = map_file(lib_path("valid.dat"), 0x10000); + if (valid_file) { + valid_table = valid_file; mapped_file = 1; return; } - /* Otherwise, using a dynamically loaded one. */ + /* Otherwise, we're using a dynamically created valid_table. + * It might need to be regenerated if the code page changed. + * We know that we're not using a mapped file, so we can + * free() the old one. */ if (valid_table) free(valid_table); DEBUG(2,("creating default valid table\n")); valid_table = malloc(0x10000); - for (i=0;i<128;i++) valid_table[i] = isalnum(i) || - strchr(allowed,i); + for (i=0;i<128;i++) + valid_table[i] = isalnum(i) || strchr(allowed,i); + for (;i<0x10000;i++) { smb_ucs2_t c; SSVAL(&c, 0, i); -- cgit From d21b15ff57aa39337e76a06da74a55e48f4b0696 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 27 Feb 2003 01:54:41 +0000 Subject: - Rename 'modules = ' to 'preload modules = ' - Add smb_probe_module() - Add init_modules() - Call these functions (This used to be commit f8f21653225792c0001d183c6efe8b7d89a0785d) --- source3/lib/module.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/module.c b/source3/lib/module.c index dd94f79950..4e2fe48af7 100644 --- a/source3/lib/module.c +++ b/source3/lib/module.c @@ -75,18 +75,47 @@ int smb_load_modules(const char **modules) return success; } +int smb_probe_module(const char *subsystem, const char *module) +{ + pstring full_path; + + /* Check for absolute path */ + if(module[0] == '/')return smb_load_module(module); + + pstrcpy(full_path, lib_path(subsystem)); + pstrcat(full_path, "/"); + pstrcat(full_path, module); + pstrcat(full_path, "."); + pstrcat(full_path, shlib_ext()); + + return smb_load_module(full_path); +} + #else /* HAVE_DLOPEN */ int smb_load_module(const char *module_name) { - DEBUG(0,("This samba executable has not been build with plugin support")); + DEBUG(0,("This samba executable has not been built with plugin support")); return False; } int smb_load_modules(const char **modules) { - DEBUG(0,("This samba executable has not been build with plugin support")); - return -1; + DEBUG(0,("This samba executable has not been built with plugin support")); + return False; +} + +int smb_probe_module(const char *subsystem, const char *module) +{ + DEBUG(0,("This samba executable has not been built with plugin support, not probing")); + return False; } #endif /* HAVE_DLOPEN */ + +void init_modules(void) +{ + if(lp_preload_modules()) + smb_load_modules(lp_preload_modules()); + /* FIXME: load static modules */ +} -- cgit From 5c82d3f00a2973b7f0881606d94ed36f0d0aa6be Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Thu, 27 Feb 2003 05:53:25 +0000 Subject: Doxygen janitor (This used to be commit 67bf36c69d19463c28066b276d74ac4784b26bed) --- source3/lib/iconv.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 5292e9cf0a..f622704853 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -90,11 +90,12 @@ static size_t sys_iconv(void *cd, #endif } -/* - this is a simple portable iconv() implementaion. It only knows about - a very small number of character sets - just enough that Samba works - on systems that don't have iconv - */ +/** + * This is a simple portable iconv() implementaion. + * + * It only knows about a very small number of character sets - just + * enough that Samba works on systems that don't have iconv. + **/ size_t smb_iconv(smb_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) -- cgit From 97e7d2ffae74c9c07b38143c8fb028ee91b153bd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 27 Feb 2003 21:21:02 +0000 Subject: additional fix for CR 601 * distinguish WinXP from Win2k * add a 1/3 of a second delay in OpenPrinter in order to trigger a LAN/WAN optimization in 2k clients. (This used to be commit 96570699d1b715f47c35aa211da6ec18f6fc4109) --- source3/lib/util.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 3958600cbd..15b75356a8 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1764,6 +1764,9 @@ void set_remote_arch(enum remote_arch_types type) case RA_WIN2K: fstrcpy(remote_arch, "Win2K"); return; + case RA_WINXP: + fstrcpy(remote_arch, "WinXP"); + return; case RA_SAMBA: fstrcpy(remote_arch,"Samba"); return; -- cgit From 921e569ed50408d42ddab5d524cf39a86429d488 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 03:51:25 +0000 Subject: Add a comment about the meaning of samba's internal character set and how this interacts with it. (This used to be commit eb876ee9cf24eda04e0856899b232d060c669c0c) --- source3/lib/iconv.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index f622704853..6786003de5 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -21,6 +21,30 @@ #include "includes.h" + +/** + * @file + * + * @brief Samba wrapper/stub for iconv character set conversion. + * + * iconv is the XPG2 interface for converting between character + * encodings. This file provides a Samba wrapper around it, and also + * a simple reimplementation that is used if the system does not + * implement iconv. + * + * Samba only works with encodings that are supersets of ASCII: ascii + * characters like whitespace can be tested for directly, multibyte + * sequences start with a byte with the high bit set, and strings are + * terminated by \0. + * + * Note that the only function provided by iconv is conversion between + * characters. It doesn't directly support operations like + * uppercasing or comparison. We have to convert to UCS-2 and compare + * there. + * + * @sa Samba Developers Guide + **/ + static size_t ascii_pull(void *,char **, size_t *, char **, size_t *); static size_t ascii_push(void *,char **, size_t *, char **, size_t *); static size_t utf8_pull(void *,char **, size_t *, char **, size_t *); -- cgit From f5f59e866e5b761a6b0c95d29bb2d1ec0136652f Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:17:30 +0000 Subject: Doxygen janitor: fix parameter names, grammar, tag names. (This used to be commit 42d9ec28cd55dbcfda546c84fb842938aeda544d) --- source3/lib/gencache.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 7260e477b8..5c8ad1339b 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -94,12 +94,12 @@ BOOL gencache_shutdown(void) * Set an entry in the cache file. If there's no such * one, then add it. * - * @param key string that represents a key of this entry + * @param keystr string that represents a key of this entry * @param value text representation value being cached * @param timeout time when the value is expired * - * @return true when entry is successfuly stored or - * false on the attempt's failure + * @retval true when entry is successfuly stored + * @retval false on failure **/ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) @@ -134,12 +134,12 @@ BOOL gencache_set(const char *keystr, const char *value, time_t timeout) /** * Set existing entry to the cache file. * - * @param key string that represents a key of this entry - * @param value text representation value being cached + * @param keystr string that represents a key of this entry + * @param valstr text representation value being cached * @param timeout time when the value is expired * - * @return true when entry is successfuly set or - * false on the attempt's failure + * @retval true when entry is successfuly set + * @retval false on failure **/ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) @@ -189,10 +189,10 @@ BOOL gencache_set_only(const char *keystr, const char *valstr, time_t timeout) /** * Delete one entry from the cache file. * - * @param key string that represents a key of this entry + * @param keystr string that represents a key of this entry * - * @return true upon successful deletion or - * false in case of failure + * @retval true upon successful deletion + * @retval false in case of failure **/ BOOL gencache_del(const char *keystr) @@ -218,14 +218,14 @@ BOOL gencache_del(const char *keystr) /** * Get existing entry from the cache file. * - * @param key string that represents a key of this entry - * @param value buffer that is allocated and filled with the entry value + * @param keystr string that represents a key of this entry + * @param valstr buffer that is allocated and filled with the entry value * buffer's disposing must be done outside * @param timeout pointer to a time_t that is filled with entry's * timeout * - * @return true when entry is successfuly fetched or - * false on the failure + * @retval true when entry is successfuly fetched + * @retval False for failure **/ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) -- cgit From 481b4e6d6ceeab644b5c4d1ee11bc221d8035202 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 04:21:55 +0000 Subject: Doxygen janitor (This used to be commit 9af07173152c5e861d13b33a8d4aee8167a50b66) --- source3/lib/iconv.c | 2 +- source3/lib/messages.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/iconv.c b/source3/lib/iconv.c index 6786003de5..8b360a14c6 100644 --- a/source3/lib/iconv.c +++ b/source3/lib/iconv.c @@ -35,7 +35,7 @@ * Samba only works with encodings that are supersets of ASCII: ascii * characters like whitespace can be tested for directly, multibyte * sequences start with a byte with the high bit set, and strings are - * terminated by \0. + * terminated by a nul byte. * * Note that the only function provided by iconv is conversion between * characters. It doesn't directly support operations like diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 3603758e9f..5ff0e45c61 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -21,11 +21,11 @@ */ /** - @defgroups messages Internal messaging framework - @{ - @file messages.c - - This module is used for internal messaging between Samba daemons. + @defgroup messages Internal messaging framework + @{ + @file messages.c + + @brief Module for internal messaging between Samba daemons. The idea is that if a part of Samba wants to do communication with another Samba process then it will do a message_register() of a @@ -36,7 +36,7 @@ use that to reply by message_send_pid(). See ping_message() for a simple example. - *NOTE*: Dispatch functions must be able to cope with incoming + @caution Dispatch functions must be able to cope with incoming messages on an *odd* byte boundary. This system doesn't have any inherent size limitations but is not @@ -524,7 +524,7 @@ static int traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void * @param n_sent Set to the number of messages sent. This should be * equal to the number of processes, but be careful for races. * - * @return True for success. + * @retval True for success. **/ BOOL message_send_all(TDB_CONTEXT *conn_tdb, int msg_type, const void *buf, size_t len, -- cgit From e443560789b5fc1d47e4008680e0484e002ad15d Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 28 Feb 2003 05:34:19 +0000 Subject: Doxygen janitor: add note that strequal is in fact case-insensitive. (This used to be commit a4b9c5c2576c80a5f60d47d178b9b8c50d348893) --- source3/lib/util_str.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index cc4b6fe5c5..070c59c1b2 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -164,9 +164,10 @@ int StrnCaseCmp(const char *s, const char *t, size_t n) } /** - Compare 2 strings. -**/ - + * Compare 2 strings. + * + * @note The comparison is case-insensitive. + **/ BOOL strequal(const char *s1, const char *s2) { if (s1 == s2) @@ -178,9 +179,10 @@ BOOL strequal(const char *s1, const char *s2) } /** - Compare 2 strings up to and including the nth char. -**/ - + * Compare 2 strings up to and including the nth char. + * + * @note The comparison is case-insensitive. + **/ BOOL strnequal(const char *s1,const char *s2,size_t n) { if (s1 == s2) -- cgit From f434f039e606c368eacb995e30c859daa85c64eb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Mar 2003 19:53:04 +0000 Subject: dlsym takes a const char *. Jeremy. (This used to be commit ff3827a62b37342b13fd8b4eafd256d91428c02b) --- source3/lib/system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/system.c b/source3/lib/system.c index 18cccda935..6ff97b88da 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -1192,7 +1192,7 @@ void *sys_dlopen(const char *name, int flags) #endif } -void *sys_dlsym(void *handle, char *symbol) +void *sys_dlsym(void *handle, const char *symbol) { #if defined(HAVE_DLSYM) return dlsym(handle, symbol); -- cgit From 8a751c019c21b1925fd352639f8237cf0a6ebac9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 7 Mar 2003 18:26:24 +0000 Subject: Some progress towards gums and tdbsam2 genparser works fine, and it is a marvelous tool to store objects in tdb :) (This used to be commit 4c6d461a8572f03cd33cba95500cc837638b732c) --- source3/lib/util_sid.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util_sid.c b/source3/lib/util_sid.c index 824987f189..81d17ae3f2 100644 --- a/source3/lib/util_sid.c +++ b/source3/lib/util_sid.c @@ -629,3 +629,21 @@ void print_guid(GUID *guid) d_printf("%02x", guid->info[i]); d_printf("\n"); } + +/******************************************************************* + Tallocs a duplicate SID. +********************************************************************/ + +DOM_SID *sid_dup_talloc(TALLOC_CTX *ctx, DOM_SID *src) +{ + DOM_SID *dst; + + if(!src) + return NULL; + + if((dst = talloc_zero(ctx, sizeof(DOM_SID))) != NULL) { + sid_copy( dst, src); + } + + return dst; +} -- cgit From 01289b14a7cbe0e1a1e135349037b0e7ba5fe70b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 8 Mar 2003 10:22:50 +0000 Subject: Make sure that the 'remote' machine name can only be set once. For some weird reason, during a Win2003 installation, when you select 'domain join' it sends one machine name in the name exchange, and litraly 'machinename' during the NTLMSSP login. Also fix up winbindd's logfile handling, so that it matches smbd and nmbd. (This helps me, by seperating the logs by pid). Andrew Bartlett (This used to be commit afe5a3832f79131fb74461577f1db0e5e8bf4b6d) --- source3/lib/substitute.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 2d1b2ab1fa..1e3f51e2d8 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -29,9 +29,20 @@ fstring remote_proto="UNKNOWN"; static fstring remote_machine; static fstring smb_user_name; +/** + * Set the 'local' machine name + * @param local_name the name we are being called + * @param if this is the 'final' name for us, not be be changed again + */ -void set_local_machine_name(const char* local_name) +void set_local_machine_name(const char* local_name, BOOL perm) { + static BOOL already_perm = False; + if (already_perm) + return; + + already_perm = perm; + fstring tmp_local_machine; fstrcpy(tmp_local_machine,local_name); @@ -40,8 +51,20 @@ void set_local_machine_name(const char* local_name) alpha_strcpy(local_machine,tmp_local_machine,SAFE_NETBIOS_CHARS,sizeof(local_machine)-1); } -void set_remote_machine_name(const char* remote_name) +/** + * Set the 'remote' machine name + * @param remote_name the name our client wants to be called by + * @param if this is the 'final' name for them, not be be changed again + */ + +void set_remote_machine_name(const char* remote_name, BOOL perm) { + static BOOL already_perm = False; + if (already_perm) + return; + + already_perm = perm; + fstring tmp_remote_machine; fstrcpy(tmp_remote_machine,remote_name); @@ -57,6 +80,10 @@ const char* get_remote_machine_name(void) const char* get_local_machine_name(void) { + if (!*local_machine) { + return global_myname(); + } + return local_machine; } -- cgit From 8ccff3e99527b7303e75f860e50d74bb83fdfb15 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 8 Mar 2003 23:39:44 +0000 Subject: This is C, not C++ (This used to be commit 25d210b90b6c0377046d89a1dce7a32f94fd7859) --- source3/lib/substitute.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/substitute.c b/source3/lib/substitute.c index 1e3f51e2d8..ef68bce985 100644 --- a/source3/lib/substitute.c +++ b/source3/lib/substitute.c @@ -38,13 +38,13 @@ static fstring smb_user_name; void set_local_machine_name(const char* local_name, BOOL perm) { static BOOL already_perm = False; + fstring tmp_local_machine; + if (already_perm) return; already_perm = perm; - fstring tmp_local_machine; - fstrcpy(tmp_local_machine,local_name); trim_string(tmp_local_machine," "," "); strlower(tmp_local_machine); @@ -60,13 +60,13 @@ void set_local_machine_name(const char* local_name, BOOL perm) void set_remote_machine_name(const char* remote_name, BOOL perm) { static BOOL already_perm = False; + fstring tmp_remote_machine; + if (already_perm) return; already_perm = perm; - fstring tmp_remote_machine; - fstrcpy(tmp_remote_machine,remote_name); trim_string(tmp_remote_machine," "," "); strlower(tmp_remote_machine); -- cgit From de6b39d898d5fb3106d7ed80249be7f74f83caf6 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 10 Mar 2003 01:10:45 +0000 Subject: Clobber strings with 0xf1f1f1f1 before writing to them to check buffer lengths are correct. Attempts to pstrcpy into an fstring or allocated string should fail in developer builds. This builds on abartlet's earlier overflow probe for safe_strcpy, but by clobbering the whole string with a nonzero value is more likely to find overflows on the stack. This is only used in -DDEVELOPER mode. Reviewed by abartlet, tpot. (This used to be commit 8d915e266cd8ccc8b27e9c7ea8e9d003d05f8182) --- source3/lib/util_str.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 070c59c1b2..924cf9d921 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -430,6 +430,27 @@ BOOL str_is_all(const char *s,char c) return True; } + +/** + * In developer builds, clobber a region of memory. + * + * If we think a string buffer is longer than it really is, this ought + * to make the failure obvious, by segfaulting (if in the heap) or by + * killing the return address (on the stack), or by trapping under a + * memory debugger. + * + * This is meant to catch possible string overflows, even if the + * actual string copied is not big enough to cause an overflow. + **/ +void clobber_region(char *dest, size_t len) +{ +#ifdef DEVELOPER + /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ + memset(dest, 0xF1, len); +#endif +} + + /** Safe string copy into a known length string. maxlength does not include the terminating zero. @@ -444,13 +465,7 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength) return NULL; } -#ifdef DEVELOPER - /* We intentionally write out at the extremity of the destination - * string. If the destination is too short (e.g. pstrcpy into mallocd - * or fstring) then this should cause an error under a memory - * checker. */ - dest[maxlength] = '\0'; -#endif + clobber_region(dest, maxlength+1); if (!src) { *dest = 0; @@ -490,6 +505,8 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength) src_len = strlen(src); dest_len = strlen(dest); + clobber_region(dest + dest_len, maxlength + 1 - dest_len); + if (src_len + dest_len > maxlength) { DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n", (int)(src_len + dest_len - maxlength), src)); @@ -499,7 +516,7 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength) dest[maxlength] = 0; return NULL; } - + memcpy(&dest[dest_len], src, src_len); dest[dest_len + src_len] = 0; return dest; @@ -516,6 +533,8 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si { size_t len, i; + clobber_region(dest, maxlength); + if (!dest) { DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n")); return NULL; @@ -554,8 +573,12 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si char *StrnCpy(char *dest,const char *src,size_t n) { char *d = dest; + + clobber_region(dest, n+1); + if (!dest) return(NULL); + if (!src) { *dest = 0; return(dest); @@ -576,6 +599,8 @@ char *strncpyn(char *dest, const char *src, size_t n, char c) char *p; size_t str_len; + clobber_region(dest, n+1); + p = strchr_m(src, c); if (p == NULL) { DEBUG(5, ("strncpyn: separator character (%c) not found\n", c)); -- cgit From 2e01ef5957bcdecb057d94122529b7cbd7f40ec2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 11 Mar 2003 07:25:48 +0000 Subject: Remove valgrind_strlen function, hopefully no longer needed with recent Valgrind relases and clashing with -DVALGRIND. (This used to be commit 98479f1315cf8968152e1566966ac57e171008c3) --- source3/lib/util_str.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 924cf9d921..7dd5ee4242 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1667,12 +1667,3 @@ char * base64_encode_data_blob(DATA_BLOB data) return result; } -#ifdef VALGRIND -size_t valgrind_strlen(const char *s) -{ - size_t count; - for(count = 0; *s++; count++) - ; - return count; -} -#endif -- cgit From 3b580ff000d9f258c581efded52d5d7c55375173 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 11 Mar 2003 11:28:59 +0000 Subject: This patch attemptes to clean up winbindd's mutex locking. The current locking scheme in winbind is a complete mess - indeed, the next step should be to push the locking into cli_full_connection(), but I'll leave it for now. This patch works on the noted behaviour that 2 parts of the connection process need protection - and independent protection. Tim Potter did some work on this a little while back, verifying the second case. The two cases are: - between connect() and first session setup - during the auth2 phase of the netlogon pipe setup. I've removed the counter on the lock, as I fail to see what it gains us. This patch also adds 'anonymous fallback' to our winbindd -> DC connection. If the authenticated connection fails (wbinfo -A specifed) - say that account isn't trusted by a trusted DC - then we try an anonymous. Both tpot and mbp like the patch. Andrew Bartlett (This used to be commit 0620320002082298a15cbba72bd79aecfc607947) --- source3/lib/server_mutex.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index 878e5497d8..3e5512c734 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -30,8 +30,6 @@ like the single-connection that NT makes. */ static char *mutex_server_name; -/* FIXME. ref_count should be allocated per name... JRA. */ -size_t ref_count; BOOL grab_server_mutex(const char *name) { @@ -40,7 +38,7 @@ BOOL grab_server_mutex(const char *name) DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name)); return False; } - if (!secrets_named_mutex(mutex_server_name, 10, &ref_count)) { + if (!secrets_named_mutex(mutex_server_name, 10)) { DEBUG(10,("grab_server_mutex: failed for %s\n", name)); SAFE_FREE(mutex_server_name); return False; @@ -52,7 +50,7 @@ BOOL grab_server_mutex(const char *name) void release_server_mutex(void) { if (mutex_server_name) { - secrets_named_mutex_release(mutex_server_name, &ref_count); + secrets_named_mutex_release(mutex_server_name); SAFE_FREE(mutex_server_name); } } -- cgit From f4a8417d6fa058ec33753a4df1222131a73add3e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 12 Mar 2003 11:00:02 +0000 Subject: Add const (This used to be commit 147a0c8b13d20e06c557fb817a36fddf9a920d65) --- source3/lib/crc32.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/crc32.c b/source3/lib/crc32.c index bd4f1633e5..da3aeaa901 100644 --- a/source3/lib/crc32.c +++ b/source3/lib/crc32.c @@ -8,7 +8,7 @@ #include "includes.h" -static unsigned long CRCTable[256] = +static const unsigned long CRCTable[256] = { 0x00000000,0x77073096,0xEE0E612C,0x990951BA,0x076DC419,0x706AF48F, 0xE963A535,0x9E6495A3,0x0EDB8832,0x79DCB8A4,0xE0D5E91E,0x97D2D988, @@ -55,7 +55,7 @@ static unsigned long CRCTable[256] = 0xB40BBE37,0xC30C8EA1,0x5A05DF1B,0x2D02EF8D }; -uint32 crc32_calc_buffer( char *buffer, uint32 count) +uint32 crc32_calc_buffer( const char *buffer, uint32 count) { uint32 crc=0xffffffff, i; for(i=0;i Date: Wed, 12 Mar 2003 15:40:43 +0000 Subject: adding some initiaial code to sert %a to Win2K3 (using Native LanMan string from .NET RC2) (This used to be commit 4c823e61d14a33344deb887043b60b2e3c83416f) --- source3/lib/util.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 15b75356a8..8d62db5ebb 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1767,6 +1767,9 @@ void set_remote_arch(enum remote_arch_types type) case RA_WINXP: fstrcpy(remote_arch, "WinXP"); return; + case RA_WIN2K3: + fstrcpy(remote_arch, "Win2K3"); + return; case RA_SAMBA: fstrcpy(remote_arch,"Samba"); return; -- cgit From 7ae555c43c55ab95f75fb4afdd3d2bcb403ad3b3 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 14 Mar 2003 23:11:19 +0000 Subject: fix WinXP & Win2K3 remote_arch and check pointer in ntlmssp code before dereferencing (This used to be commit 2487480228b99183cab9e34ab497997e0c144ed6) --- source3/lib/util.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 8d62db5ebb..77ffa70a47 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1740,6 +1740,22 @@ BOOL is_myworkgroup(const char *s) return(ret); } +/******************************************************************* + we distinguish between 2K and XP by the "Native Lan Manager" string + WinXP => "Windows 2002 5.1" + Win2k => "Windows 2000 5.0" + NT4 => "Windows NT 4.0" + Win9x => "Windows 4.0" +********************************************************************/ + +void ra_lanman_string( const char *native_lanman ) +{ + if ( 0 == strcmp( native_lanman, "Windows 2002 5.1" ) ) + set_remote_arch( RA_WINXP ); + else if ( 0 == strcmp( native_lanman, "Windows .NET 5.2" ) ) + set_remote_arch( RA_WIN2K3 ); +} + /******************************************************************* Set the horrid remote_arch string based on an enum. ********************************************************************/ -- cgit From 3b5bc93e9db4df6ded2eef7b32bda74328b04811 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Mar 2003 07:14:55 +0000 Subject: String handling parinoia fixes. This patch enables the compile-time checking of strings assable by means of sizeof(). (Original code had the configure check reversed). This is extended to all safe_strcpy() users, push_string and pull_string, as well as the cli and srv derivitives. There is an attempt to cap strings at the end of the cli buffer, and clobber_region() of the speified length (when not -1 :-). Becouse of the way they are declared, the 'overmalloc a string' users of safe_strcpy() have been changed to use overmalloc_safe_strcpy() (which skips some of the checks). This whole ball of mud worked fine, until I pulled out my 'fix' for our statcache. When jeremy fixes that, we should be able to get back to testing this stuff. This patch also includes a 'marker' of the last caller to clobber_region (ie, the function that called pstrcpy() that called clobber_region) to assist in debugging problems that may have smashed the stack. This is printed at smb_panic() time. (Original idea and patch by metze). It also removes some unsused functions, and #if 0's some others that are unused but probably should be used in the near future. For now, this patch gives us some confidence on one class of trivial parsing error in our code. Andrew Bartlett (This used to be commit 31f4827acc2a2f00399a5528fc83a0dae5cebaf4) --- source3/lib/charcnv.c | 83 +++++++++----------------------------------------- source3/lib/util.c | 16 +++++++++- source3/lib/util_str.c | 72 ++++++++++++++++++------------------------- 3 files changed, 59 insertions(+), 112 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index a8df003f8b..76d77ddd67 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -186,7 +186,7 @@ size_t convert_string(charset_t from, charset_t to, * @returns Size in bytes of the converted string; or -1 in case of error. **/ -size_t convert_string_allocate(charset_t from, charset_t to, +static size_t convert_string_allocate(charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { size_t i_len, o_len, destlen; @@ -265,7 +265,7 @@ convert: * * @returns Size in bytes of the converted string; or -1 in case of error. **/ -size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, +static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to, void const *src, size_t srclen, void **dest) { void *alloced_string; @@ -303,7 +303,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) } -size_t ucs2_align(const void *base_ptr, const void *p, int flags) +static size_t ucs2_align(const void *base_ptr, const void *p, int flags) { if (flags & (STR_NOALIGN|STR_ASCII)) return 0; @@ -356,11 +356,6 @@ size_t push_ascii_pstring(void *dest, const char *src) return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); } -size_t push_pstring(void *dest, const char *src) -{ - return push_ascii(dest, src, sizeof(pstring), STR_TERMINATE); -} - /** * Copy a string from a dos codepage source to a unix char* destination. * @@ -507,7 +502,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src) is -1 then no maxiumum is used. **/ -size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) +static size_t push_utf8(void *dest, const char *src, size_t dest_len, int flags) { size_t src_len = strlen(src); pstring tmpbuf; @@ -533,11 +528,6 @@ size_t push_utf8_fstring(void *dest, const char *src) return push_utf8(dest, src, sizeof(fstring), STR_TERMINATE); } -size_t push_utf8_pstring(void *dest, const char *src) -{ - return push_utf8(dest, src, sizeof(pstring), STR_TERMINATE); -} - /** * Copy a string from a unix char* src to a UTF-8 destination, allocating a buffer using talloc * @@ -666,7 +656,7 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) The resulting string in "dest" is always null terminated. **/ -size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +static size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { size_t ret; @@ -690,16 +680,7 @@ size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, i return src_len; } - -size_t pull_utf8_pstring(char *dest, const void *src) -{ - return pull_utf8(dest, src, sizeof(pstring), -1, STR_TERMINATE); -} - -size_t pull_utf8_fstring(char *dest, const void *src) -{ - return pull_utf8(dest, src, sizeof(fstring), -1, STR_TERMINATE); -} +#endif /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc @@ -745,8 +726,11 @@ size_t pull_utf8_allocate(void **dest, const char *src) is -1 then no maxiumum is used. **/ -size_t push_string(const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) +size_t push_string_fn(const char *function, unsigned int line, const void *base_ptr, void *dest, const char *src, size_t dest_len, int flags) { + if (dest_len != (size_t)-1) + clobber_region(function, line, dest, dest_len); + if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { @@ -770,8 +754,11 @@ size_t push_string(const void *base_ptr, void *dest, const char *src, size_t des The resulting string in "dest" is always null terminated. **/ -size_t pull_string(const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) +size_t pull_string_fn(const char *function, unsigned int line, const void *base_ptr, char *dest, const void *src, size_t dest_len, size_t src_len, int flags) { + if (dest_len != (size_t)-1) + clobber_region(function, line, dest, dest_len); + if (!(flags & STR_ASCII) && \ ((flags & STR_UNICODE || \ (SVAL(base_ptr, smb_flg2) & FLAGS2_UNICODE_STRINGS)))) { @@ -790,27 +777,6 @@ size_t align_string(const void *base_ptr, const char *p, int flags) return 0; } -/** - Convert from ucs2 to unix charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -char *acnv_u2ux(const smb_ucs2_t *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); - dlen = convert_string_allocate(CH_UCS2, CH_UNIX, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} - /** Convert from unix to ucs2 charset and return the allocated and converted string or NULL if an error occurred. @@ -832,27 +798,6 @@ smb_ucs2_t *acnv_uxu2(const char *src) return dest; } -/** - Convert from ucs2 to dos charset and return the - allocated and converted string or NULL if an error occurred. - You must provide a zero terminated string. - The returning string will be zero terminated. -**/ - -char *acnv_u2dos(const smb_ucs2_t *src) -{ - size_t slen; - size_t dlen; - void *dest; - - slen = (strlen_w(src) + 1) * sizeof(smb_ucs2_t); - dlen = convert_string_allocate(CH_UCS2, CH_DOS, src, slen, &dest); - if (dlen == (size_t)-1) - return NULL; - else - return dest; -} - /** Convert from dos to ucs2 charset and return the allocated and converted string or NULL if an error occurred. diff --git a/source3/lib/util.c b/source3/lib/util.c index 77ffa70a47..1f300a2815 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1398,9 +1398,23 @@ gid_t nametogid(const char *name) void smb_panic(const char *why) { - char *cmd = lp_panic_action(); + char *cmd; int result; +#ifdef DEVELOPER + { + extern char *global_clobber_region_function; + extern unsigned int global_clobber_region_line; + + if (global_clobber_region_function) { + DEBUG(0,("smb_panic: clobber_region() last called from [%s(%u)]\n", + global_clobber_region_function, + global_clobber_region_line)); + } + } +#endif + + cmd = lp_panic_action(); if (cmd && *cmd) { DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmd)); result = system(cmd); diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 7dd5ee4242..7643c2807e 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -21,6 +21,11 @@ #include "includes.h" +#ifdef DEVELOPER +const char *global_clobber_region_function; +unsigned int global_clobber_region_line; +#endif + /** * Get the next token from a string, return False if none found. * Handles double-quotes. @@ -73,7 +78,7 @@ parameter so you can pass NULL. This is useful for user interface code but beware the fact that it is not re-entrant! **/ -static char *last_ptr=NULL; +static const char *last_ptr=NULL; BOOL next_token_nr(const char **ptr,char *buff, const char *sep, size_t bufsize) { @@ -409,28 +414,6 @@ size_t count_chars(const char *s,char c) return(count); } -/** -Return True if a string consists only of one particular character. -**/ - -BOOL str_is_all(const char *s,char c) -{ - smb_ucs2_t *ptr; - - if(s == NULL) - return False; - if(!*s) - return False; - - push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE); - for(ptr=tmpbuf;*ptr;ptr++) - if(*ptr!=UCS2_CHAR(c)) - return False; - - return True; -} - - /** * In developer builds, clobber a region of memory. * @@ -442,11 +425,13 @@ BOOL str_is_all(const char *s,char c) * This is meant to catch possible string overflows, even if the * actual string copied is not big enough to cause an overflow. **/ -void clobber_region(char *dest, size_t len) +void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) { #ifdef DEVELOPER /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ memset(dest, 0xF1, len); + global_clobber_region_function = fn; + global_clobber_region_line = line; #endif } @@ -456,7 +441,7 @@ void clobber_region(char *dest, size_t len) include the terminating zero. **/ -char *safe_strcpy(char *dest,const char *src, size_t maxlength) +char *safe_strcpy_fn(const char *fn, int line, char *dest,const char *src, size_t maxlength) { size_t len; @@ -465,7 +450,7 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength) return NULL; } - clobber_region(dest, maxlength+1); + clobber_region(fn,line,dest, maxlength+1); if (!src) { *dest = 0; @@ -489,8 +474,7 @@ char *safe_strcpy(char *dest,const char *src, size_t maxlength) Safe string cat into a string. maxlength does not include the terminating zero. **/ - -char *safe_strcat(char *dest, const char *src, size_t maxlength) +char *safe_strcat_fn(const char *fn, int line, char *dest, const char *src, size_t maxlength) { size_t src_len, dest_len; @@ -505,8 +489,8 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength) src_len = strlen(src); dest_len = strlen(dest); - clobber_region(dest + dest_len, maxlength + 1 - dest_len); - + clobber_region(fn, line, dest + dest_len, maxlength + 1 - dest_len); + if (src_len + dest_len > maxlength) { DEBUG(0,("ERROR: string overflow by %d in safe_strcat [%.50s]\n", (int)(src_len + dest_len - maxlength), src)); @@ -528,12 +512,11 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength) and replaces with '_'. Deliberately does *NOT* check for multibyte characters. Don't change it ! **/ - -char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength) +char *alpha_strcpy_fn(const char *fn, int line, char *dest, const char *src, const char *other_safe_chars, size_t maxlength) { size_t len, i; - clobber_region(dest, maxlength); + clobber_region(fn, line, dest, maxlength); if (!dest) { DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n")); @@ -569,13 +552,12 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si Like strncpy but always null terminates. Make sure there is room! The variable n should always be one less than the available size. **/ - -char *StrnCpy(char *dest,const char *src,size_t n) +char *StrnCpy_fn(const char *fn, int line,char *dest,const char *src,size_t n) { char *d = dest; - clobber_region(dest, n+1); - + clobber_region(fn, line, dest, n+1); + if (!dest) return(NULL); @@ -589,12 +571,13 @@ char *StrnCpy(char *dest,const char *src,size_t n) return(dest); } +#if 0 /** Like strncpy but copies up to the character marker. always null terminates. returns a pointer to the character marker in the source string (src). **/ -char *strncpyn(char *dest, const char *src, size_t n, char c) +static char *strncpyn(char *dest, const char *src, size_t n, char c) { char *p; size_t str_len; @@ -613,6 +596,7 @@ char *strncpyn(char *dest, const char *src, size_t n, char c) return p; } +#endif /** Routine to get hex characters and turn them into a 16 byte array. @@ -923,7 +907,7 @@ void all_string_sub(char *s,const char *pattern,const char *insert, size_t len) Use with caution! **/ -smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *pattern, +static smb_ucs2_t *all_string_sub_w(const smb_ucs2_t *s, const smb_ucs2_t *pattern, const smb_ucs2_t *insert) { smb_ucs2_t *r, *rp; @@ -981,11 +965,12 @@ smb_ucs2_t *all_string_sub_wa(smb_ucs2_t *s, const char *pattern, return all_string_sub_w(s, p, i); } +#if 0 /** Splits out the front and back at a separator. **/ -void split_at_last_component(char *path, char *front, char sep, char *back) +static void split_at_last_component(char *path, char *front, char sep, char *back) { char *p = strrchr_m(path, sep); @@ -1004,6 +989,7 @@ void split_at_last_component(char *path, char *front, char sep, char *back) back[0] = 0; } } +#endif /** Write an octal as a string. @@ -1023,7 +1009,7 @@ const char *octal_string(int i) Truncate a string at a specified length. **/ -char *string_truncate(char *s, int length) +char *string_truncate(char *s, unsigned int length) { if (s && strlen(s) > length) s[length] = 0; @@ -1182,11 +1168,12 @@ char *binary_string(char *buf, int len) return ret; } +#if 0 /** Just a typesafety wrapper for snprintf into a fstring. **/ - int fstr_sprintf(fstring s, const char *fmt, ...) +static int fstr_sprintf(fstring s, const char *fmt, ...) { va_list ap; int ret; @@ -1196,6 +1183,7 @@ char *binary_string(char *buf, int len) va_end(ap); return ret; } +#endif #ifndef HAVE_STRNDUP /** -- cgit From f1d333ea35a4fed92e2d51aafa4e758f577e5cf1 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 15 Mar 2003 08:03:11 +0000 Subject: Remove an unused function and fix the build. Andrew Bartlett (This used to be commit 67a0319d268dfc0e2154d3ab0f8bf866e3cbb6db) --- source3/lib/charcnv.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 76d77ddd67..fa646573d8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -646,42 +646,6 @@ size_t pull_ucs2_allocate(void **dest, const smb_ucs2_t *src) return convert_string_allocate(CH_UCS2, CH_UNIX, src, src_len, dest); } -/** - Copy a string from a utf-8 source to a unix char* destination. - Flags can have: - STR_TERMINATE means the string in src is null terminated. - if STR_TERMINATE is set then src_len is ignored. - src_len is the length of the source area in bytes - Return the number of bytes occupied by the string in src. - The resulting string in "dest" is always null terminated. -**/ - -static size_t pull_utf8(char *dest, const void *src, size_t dest_len, size_t src_len, int flags) -{ - size_t ret; - - if (dest_len == (size_t)-1) - dest_len = sizeof(pstring); - - if (flags & STR_TERMINATE) { - if (src_len == (size_t)-1) { - src_len = strlen(src) + 1; - } else { - size_t len = strnlen(src, src_len); - if (len < src_len) - len++; - src_len = len; - } - } - - ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); - if (dest_len) - dest[MIN(ret, dest_len-1)] = 0; - - return src_len; -} -#endif - /** * Copy a string from a UTF-8 src to a unix char * destination, allocating a buffer using talloc * -- cgit From 400bb4bfab01a6c262b15658dee5c0d011d0e883 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 16 Mar 2003 13:21:12 +0000 Subject: - Make ReadDirName return a const char*. - Consequential changes from that - mark our fstring/pstring assumptions in function prototypes Andrew Bartlett (This used to be commit fe2bc64bc439b27387b8f326b0f4f3bfcc3d04a1) --- source3/lib/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util.c b/source3/lib/util.c index 1f300a2815..4216310335 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -1435,7 +1435,7 @@ void smb_panic(const char *why) A readdir wrapper which just returns the file name. ********************************************************************/ -char *readdirname(DIR *p) +const char *readdirname(DIR *p) { SMB_STRUCT_DIRENT *ptr; char *dname; -- cgit From eb8374894061e9dc3bc83e397a92248d23b99f22 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 18 Mar 2003 05:00:02 +0000 Subject: global_globber_region_function/line ought to be recorded before clobbering the region, just in case clobbering causes us to crash immediately. (That might happen if we just shot ourselves in the stack and strcpy was not inlined.) Also, in DEVELOPER mode and when Valgrind is available, mark the clobbered region as uninitialized. This is an even stronger protection than clobbering with 0xf1. (This used to be commit 5653a42ae695f4b8f4c14d3184ca76523d38b51b) --- source3/lib/util_str.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 7643c2807e..b734452867 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -424,15 +424,27 @@ size_t count_chars(const char *s,char c) * * This is meant to catch possible string overflows, even if the * actual string copied is not big enough to cause an overflow. + * + * In addition, under Valgrind the buffer is marked as uninitialized. **/ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) { #ifdef DEVELOPER - /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ - memset(dest, 0xF1, len); global_clobber_region_function = fn; global_clobber_region_line = line; -#endif + + /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ + memset(dest, 0xF1, len); +#ifdef VALGRIND + /* Even though we just wrote to this, from the application's + * point of view it is not initialized. + * + * (This is not redundant with the clobbering above. The + * marking might not actually take effect if we're not running + * under valgrind or not with --client-perms.) */ + VALGRIND_MAKE_WRITABLE(dest, len); +#endif /* VALGRIND */ +#endif /* DEVELOPER */ } -- cgit From 556fea4e1e68d9d0c711a87905d9be310add7f83 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 18 Mar 2003 05:30:15 +0000 Subject: Update comment: Valgrind 1.9.4 seems to always respect client requests, without needing --client-perms=yes. (This used to be commit 412a8780c35ee9449c9682e3ef73afb2c4933285) --- source3/lib/util_str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b734452867..3836d42872 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -441,7 +441,7 @@ void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) * * (This is not redundant with the clobbering above. The * marking might not actually take effect if we're not running - * under valgrind or not with --client-perms.) */ + * under valgrind.) */ VALGRIND_MAKE_WRITABLE(dest, len); #endif /* VALGRIND */ #endif /* DEVELOPER */ -- cgit From a084f06fe33eb9903489763bc34c7092080a0a5e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 18 Mar 2003 07:09:23 +0000 Subject: Split "clobber" function and variables into its own file before it grows too much larger. (This used to be commit 4bbddbfc6a97ebb11e299aa7bd07ebebeab42c65) --- source3/lib/clobber.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ source3/lib/util_str.c | 39 -------------------------------- 2 files changed, 60 insertions(+), 39 deletions(-) create mode 100644 source3/lib/clobber.c (limited to 'source3/lib') diff --git a/source3/lib/clobber.c b/source3/lib/clobber.c new file mode 100644 index 0000000000..fb3a0dc281 --- /dev/null +++ b/source3/lib/clobber.c @@ -0,0 +1,60 @@ +/* + Unix SMB/CIFS implementation. + Samba utility functions + Copyright (C) Martin Pool 2003 + Copyright (C) Andrew Bartlett 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#ifdef DEVELOPER +const char *global_clobber_region_function; +unsigned int global_clobber_region_line; +#endif + +/** + * In developer builds, clobber a region of memory. + * + * If we think a string buffer is longer than it really is, this ought + * to make the failure obvious, by segfaulting (if in the heap) or by + * killing the return address (on the stack), or by trapping under a + * memory debugger. + * + * This is meant to catch possible string overflows, even if the + * actual string copied is not big enough to cause an overflow. + * + * In addition, under Valgrind the buffer is marked as uninitialized. + **/ +void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) +{ +#ifdef DEVELOPER + global_clobber_region_function = fn; + global_clobber_region_line = line; + + /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ + memset(dest, 0xF1, len); +#ifdef VALGRIND + /* Even though we just wrote to this, from the application's + * point of view it is not initialized. + * + * (This is not redundant with the clobbering above. The + * marking might not actually take effect if we're not running + * under valgrind.) */ + VALGRIND_MAKE_WRITABLE(dest, len); +#endif /* VALGRIND */ +#endif /* DEVELOPER */ +} diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 3836d42872..8ef4ddade6 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -21,11 +21,6 @@ #include "includes.h" -#ifdef DEVELOPER -const char *global_clobber_region_function; -unsigned int global_clobber_region_line; -#endif - /** * Get the next token from a string, return False if none found. * Handles double-quotes. @@ -414,40 +409,6 @@ size_t count_chars(const char *s,char c) return(count); } -/** - * In developer builds, clobber a region of memory. - * - * If we think a string buffer is longer than it really is, this ought - * to make the failure obvious, by segfaulting (if in the heap) or by - * killing the return address (on the stack), or by trapping under a - * memory debugger. - * - * This is meant to catch possible string overflows, even if the - * actual string copied is not big enough to cause an overflow. - * - * In addition, under Valgrind the buffer is marked as uninitialized. - **/ -void clobber_region(const char *fn, unsigned int line, char *dest, size_t len) -{ -#ifdef DEVELOPER - global_clobber_region_function = fn; - global_clobber_region_line = line; - - /* F1 is odd and 0xf1f1f1f1 shouldn't be a valid pointer */ - memset(dest, 0xF1, len); -#ifdef VALGRIND - /* Even though we just wrote to this, from the application's - * point of view it is not initialized. - * - * (This is not redundant with the clobbering above. The - * marking might not actually take effect if we're not running - * under valgrind.) */ - VALGRIND_MAKE_WRITABLE(dest, len); -#endif /* VALGRIND */ -#endif /* DEVELOPER */ -} - - /** Safe string copy into a known length string. maxlength does not include the terminating zero. -- cgit