X-Git-Url: http://git.samba.org/samba.git/?p=ira%2Fwip.git;a=blobdiff_plain;f=source3%2Flib%2Futil.c;h=6caa605066367e5ffef7713dfa833e36ef660f6d;hp=af0a6bda71896785f64c5d38c9be65c86a5818e8;hb=0e0c24b40d38515ca7110b357f74feb21b2459f5;hpb=d9d7f023d8d11943ca0375e1573e6ec9921889bc diff --git a/source3/lib/util.c b/source3/lib/util.c index af0a6bda718..6caa6050663 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -4,6 +4,7 @@ Samba utility functions Copyright (C) Andrew Tridgell 1992-1998 Copyright (C) Jeremy Allison 2001 + Copyright (C) Simo Sorce 2001 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 @@ -92,26 +93,26 @@ char **my_netbios_names; /**************************************************************************** find a suitable temporary directory. The result should be copied immediately - as it may be overwritten by a subsequent call + as it may be overwritten by a subsequent call. ****************************************************************************/ char *tmpdir(void) { char *p; - if ((p = getenv("TMPDIR"))) { + if ((p = getenv("TMPDIR"))) return p; - } return "/tmp"; } /**************************************************************************** -determine whether we are in the specified group + Determine whether we are in the specified group. ****************************************************************************/ BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups) { int i; - if (group == current_gid) return(True); + if (group == current_gid) + return(True); for (i=0;i'): + case UCS2_CHAR('"'): + return True; + } + } + return False; +} + /******************************************************************* a wrapper that handles case sensitivity and the special handling of the ".." name @@ -1931,10 +2086,43 @@ BOOL unix_wild_match(char *pattern, char *string) return unix_do_match(p2, s2) == 0; } +/******************************************************************* + free() a data blob +*******************************************************************/ +static void free_data_blob(DATA_BLOB *d) +{ + if ((d) && (d->free)) { + SAFE_FREE(d->data); + } +} + /******************************************************************* construct a data blob, must be freed with data_blob_free() + you can pass NULL for p and get a blank data blob *******************************************************************/ -DATA_BLOB data_blob(void *p, size_t length) +DATA_BLOB data_blob(const void *p, size_t length) +{ + DATA_BLOB ret; + + if (!length) { + ZERO_STRUCT(ret); + return ret; + } + + if (p) { + ret.data = smb_xmemdup(p, length); + } else { + ret.data = smb_xmalloc(length); + } + ret.length = length; + ret.free = free_data_blob; + return ret; +} + +/******************************************************************* + construct a data blob, using supplied TALLOC_CTX +*******************************************************************/ +DATA_BLOB data_blob_talloc(TALLOC_CTX *mem_ctx, const void *p, size_t length) { DATA_BLOB ret; @@ -1943,8 +2131,12 @@ DATA_BLOB data_blob(void *p, size_t length) return ret; } - ret.data = xmemdup(p, length); + ret.data = talloc_memdup(mem_ctx, p, length); + if (ret.data == NULL) + smb_panic("data_blob_talloc: talloc_memdup failed.\n"); + ret.length = length; + ret.free = NULL; return ret; } @@ -1953,9 +2145,32 @@ free a data blob *******************************************************************/ void data_blob_free(DATA_BLOB *d) { - SAFE_FREE(d->data); + if (d) { + if (d->free) { + (d->free)(d); + } + ZERO_STRUCTP(d); + } +} + +/******************************************************************* +clear a DATA_BLOB's contents +*******************************************************************/ +void data_blob_clear(DATA_BLOB *d) +{ + if (d->data) { + memset(d->data, 0, d->length); + } } +/******************************************************************* +free a data blob and clear its contents +*******************************************************************/ +void data_blob_clear_free(DATA_BLOB *d) +{ + data_blob_clear(d); + data_blob_free(d); +} #ifdef __INSURE__ @@ -1969,7 +2184,9 @@ int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6) static int (*fn)(); int ret; char pidstr[10]; - pstring cmd = "/usr/X11R6/bin/xterm -display :0 -T Panic -n Panic -e /bin/sh -c 'cat /tmp/ierrs.*.%d ; gdb /proc/%d/exe %d'"; + /* you can get /usr/bin/backtrace from + http://samba.org/ftp/unpacked/junkcode/backtrace */ + pstring cmd = "/usr/bin/backtrace %d"; slprintf(pidstr, sizeof(pidstr)-1, "%d", sys_getpid()); pstring_sub(cmd, "%d", pidstr);