return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = smb_xmalloc(sizeof(struct auth_init_function_entry));
+ entry = SMB_XMALLOC_P(struct auth_init_function_entry);
entry->name = smb_xstrdup(name);
entry->init = init;
mem_ctx = talloc_init("authentication context");
- *auth_context = talloc(mem_ctx, sizeof(**auth_context));
+ *auth_context = TALLOC_P(mem_ctx, struct auth_context);
if (!*auth_context) {
DEBUG(0,("make_auth_context: talloc failed!\n"));
talloc_destroy(mem_ctx);
mem_ctx = talloc_init("AUTH NTLMSSP context");
- *auth_ntlmssp_state = talloc_zero(mem_ctx, sizeof(**auth_ntlmssp_state));
+ *auth_ntlmssp_state = TALLOC_ZERO_P(mem_ctx, AUTH_NTLMSSP_STATE);
if (!*auth_ntlmssp_state) {
DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
talloc_destroy(mem_ctx);
DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
- *user_info = malloc(sizeof(**user_info));
+ *user_info = SMB_MALLOC_P(auth_usersupplied_info);
if (!user_info) {
DEBUG(0,("malloc failed for user_info (size %lu)\n", (unsigned long)sizeof(*user_info)));
return NT_STATUS_NO_MEMORY;
DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
- (*user_info)->smb_name.str = strdup(smb_name);
+ (*user_info)->smb_name.str = SMB_STRDUP(smb_name);
if ((*user_info)->smb_name.str) {
(*user_info)->smb_name.len = strlen(smb_name);
} else {
return NT_STATUS_NO_MEMORY;
}
- (*user_info)->internal_username.str = strdup(internal_username);
+ (*user_info)->internal_username.str = SMB_STRDUP(internal_username);
if ((*user_info)->internal_username.str) {
(*user_info)->internal_username.len = strlen(internal_username);
} else {
return NT_STATUS_NO_MEMORY;
}
- (*user_info)->domain.str = strdup(domain);
+ (*user_info)->domain.str = SMB_STRDUP(domain);
if ((*user_info)->domain.str) {
(*user_info)->domain.len = strlen(domain);
} else {
return NT_STATUS_NO_MEMORY;
}
- (*user_info)->client_domain.str = strdup(client_domain);
+ (*user_info)->client_domain.str = SMB_STRDUP(client_domain);
if ((*user_info)->client_domain.str) {
(*user_info)->client_domain.len = strlen(client_domain);
} else {
return NT_STATUS_NO_MEMORY;
}
- (*user_info)->wksta_name.str = strdup(wksta_name);
+ (*user_info)->wksta_name.str = SMB_STRDUP(wksta_name);
if ((*user_info)->wksta_name.str) {
(*user_info)->wksta_name.len = strlen(wksta_name);
} else {
int i;
int sid_ndx;
- if ((ptoken = malloc( sizeof(NT_USER_TOKEN) ) ) == NULL) {
+ if ((ptoken = SMB_MALLOC_P(NT_USER_TOKEN)) == NULL) {
DEBUG(0, ("create_nt_token: Out of memory allocating token\n"));
nt_status = NT_STATUS_NO_MEMORY;
return nt_status;
ptoken->num_sids = n_groupSIDs + 5;
- if ((ptoken->user_sids = (DOM_SID *)malloc( sizeof(DOM_SID) * ptoken->num_sids )) == NULL) {
+ if ((ptoken->user_sids = SMB_MALLOC_ARRAY( DOM_SID, ptoken->num_sids )) == NULL) {
DEBUG(0, ("create_nt_token: Out of memory allocating SIDs\n"));
nt_status = NT_STATUS_NO_MEMORY;
return nt_status;
return NULL;
}
- group_sids = malloc(sizeof(DOM_SID) * ngroups);
+ group_sids = SMB_MALLOC_ARRAY(DOM_SID, ngroups);
if (!group_sids) {
DEBUG(0, ("create_nt_token: malloc() failed for DOM_SID list!\n"));
return NULL;
if (n_unix_groups > 0) {
- *groups = malloc(sizeof(DOM_SID) * n_unix_groups);
+ *groups = SMB_MALLOC_ARRAY(DOM_SID, n_unix_groups);
if (!*groups) {
DEBUG(0, ("get_user_group: malloc() failed for DOM_SID list!\n"));
static NTSTATUS make_server_info(auth_serversupplied_info **server_info)
{
- *server_info = malloc(sizeof(**server_info));
+ *server_info = SMB_MALLOC_P(auth_serversupplied_info);
if (!*server_info) {
DEBUG(0,("make_server_info: malloc failed!\n"));
return NT_STATUS_NO_MEMORY;
/* Create a 'combined' list of all SIDs we might want in the SD */
- all_group_SIDs = malloc(sizeof(DOM_SID) * (info3->num_groups2 + info3->num_other_sids + n_lgroupSIDs));
+ all_group_SIDs = SMB_MALLOC_ARRAY(DOM_SID,info3->num_groups2 + info3->num_other_sids + n_lgroupSIDs);
if (!all_group_SIDs) {
DEBUG(0, ("malloc() failed for DOM_SID list!\n"));
smb_panic("make_auth_methods: pointer to auth_method pointer is NULL!\n");
}
- *auth_method = talloc(auth_context->mem_ctx, sizeof(**auth_method));
+ *auth_method = TALLOC_P(auth_context->mem_ctx, auth_methods);
if (!*auth_method) {
DEBUG(0,("make_auth_method: malloc failed!\n"));
return False;
if (!ptoken)
return NULL;
- if ((token = (NT_USER_TOKEN *)malloc( sizeof(NT_USER_TOKEN) ) ) == NULL)
+ if ((token = SMB_MALLOC_P(NT_USER_TOKEN)) == NULL)
return NULL;
ZERO_STRUCTP(token);
{
reset_do_list_queue();
do_list_queue_size = 1024;
- do_list_queue = malloc(do_list_queue_size);
+ do_list_queue = SMB_MALLOC(do_list_queue_size);
if (do_list_queue == 0) {
d_printf("malloc fail for size %d\n",
(int)do_list_queue_size);
do_list_queue_size *= 2;
DEBUG(4,("enlarging do_list_queue to %d\n",
(int)do_list_queue_size));
- dlq = Realloc(do_list_queue, do_list_queue_size);
+ dlq = SMB_REALLOC(do_list_queue, do_list_queue_size);
if (! dlq) {
d_printf("failure enlarging do_list_queue to %d bytes\n",
(int)do_list_queue_size);
DEBUG(1,("getting file %s of size %.0f as %s ",
rname, (double)size, lname));
- if(!(data = (char *)malloc(read_size))) {
+ if(!(data = (char *)SMB_MALLOC(read_size))) {
d_printf("malloc fail for size %d\n", read_size);
cli_close(cli, fnum);
return 1;
DEBUG(1,("putting file %s as %s ",lname,
rname));
- buf = (char *)malloc(maxwrite);
+ buf = (char *)SMB_MALLOC(maxwrite);
if (!buf) {
d_printf("ERROR: Not enough memory!\n");
return 1;
return -1;
}
}
- entry = (struct file_list *) malloc(sizeof (struct file_list));
+ entry = SMB_MALLOC_P(struct file_list);
if (!entry) {
d_printf("Out of memory in file_find\n");
closedir(dir);
if ((info->count < MAX_COMPLETIONS - 1) && (strncmp(info->text, f->name, info->len) == 0) && (strcmp(f->name, ".") != 0) && (strcmp(f->name, "..") != 0)) {
if ((info->dirmask[0] == 0) && !(f->mode & aDIR))
- info->matches[info->count] = strdup(f->name);
+ info->matches[info->count] = SMB_STRDUP(f->name);
else {
pstring tmp;
pstrcat(tmp, f->name);
if (f->mode & aDIR)
pstrcat(tmp, "/");
- info->matches[info->count] = strdup(tmp);
+ info->matches[info->count] = SMB_STRDUP(tmp);
}
if (info->matches[info->count] == NULL)
return;
if (len >= PATH_MAX)
return(NULL);
- info.matches = (char **)malloc(sizeof(info.matches[0])*MAX_COMPLETIONS);
+ info.matches = SMB_MALLOC_ARRAY(char *,MAX_COMPLETIONS);
if (!info.matches) return NULL;
info.matches[0] = NULL;
goto cleanup;
if (info.count == 2)
- info.matches[0] = strdup(info.matches[1]);
+ info.matches[0] = SMB_STRDUP(info.matches[1]);
else {
- info.matches[0] = malloc(info.samelen+1);
+ info.matches[0] = SMB_MALLOC(info.samelen+1);
if (!info.matches[0])
goto cleanup;
strncpy(info.matches[0], info.matches[1], info.samelen);
char **matches;
int i, len, samelen = 0, count=1;
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
if (!matches) {
return NULL;
}
len = strlen(text);
for (i=0;commands[i].fn && count < MAX_COMPLETIONS-1;i++) {
if (strncmp(text, commands[i].name, len) == 0) {
- matches[count] = strdup(commands[i].name);
+ matches[count] = SMB_STRDUP(commands[i].name);
if (!matches[count])
goto cleanup;
if (count == 1)
case 1:
goto cleanup;
case 2:
- matches[0] = strdup(matches[1]);
+ matches[0] = SMB_STRDUP(matches[1]);
break;
default:
- matches[0] = malloc(samelen+1);
+ matches[0] = SMB_MALLOC(samelen+1);
if (!matches[0])
goto cleanup;
strncpy(matches[0], matches[1], samelen);
{
char *tmp;
- tmp = (char *)malloc(size+1);
+ tmp = (char *)SMB_MALLOC(size+1);
if (tmp == NULL) {
DEBUG(0, ("Out of memory in string_create_s\n"));
if (l+2 >= NAMSIZ) {
/* write a GNU tar style long header */
char *b;
- b = (char *)malloc(l+TBLOCK+100);
+ b = (char *)SMB_MALLOC(l+TBLOCK+100);
if (!b) {
DEBUG(0,("out of memory\n"));
exit(1);
{
/* initialize tar buffer */
tbufsiz=blocksize*TBLOCK;
- tarbuf=malloc(tbufsiz); /* FIXME: We might not get the buffer */
+ tarbuf=SMB_MALLOC(tbufsiz); /* FIXME: We might not get the buffer */
/* reset tar buffer pointer and tar file counter and total dumped */
tp=0; ntarf=0; ttarf=0;
/* finfo.size here is the length of the filename as written by the "/./@LongLink" name
* header call. */
int namesize = finfo.size + strlen(cur_dir) + 2;
- char *longname = malloc(namesize);
+ char *longname = SMB_MALLOC(namesize);
int offset = 0, left = finfo.size;
BOOL first = True;
while ((! error) && (x_fgets(buf, sizeof(buf)-1, inclusion))) {
if (inclusion_buffer == NULL) {
inclusion_buffer_size = 1024;
- if ((inclusion_buffer = malloc(inclusion_buffer_size)) == NULL) {
+ if ((inclusion_buffer = SMB_MALLOC(inclusion_buffer_size)) == NULL) {
DEBUG(0,("failure allocating buffer to read inclusion file\n"));
error = 1;
break;
if ((strlen(buf) + 1 + inclusion_buffer_sofar) >= inclusion_buffer_size) {
char *ib;
inclusion_buffer_size *= 2;
- ib = Realloc(inclusion_buffer,inclusion_buffer_size);
+ ib = SMB_REALLOC(inclusion_buffer,inclusion_buffer_size);
if (! ib) {
DEBUG(0,("failure enlarging inclusion buffer to %d bytes\n",
inclusion_buffer_size));
if (! error) {
/* Allocate an array of clipn + 1 char*'s for cliplist */
- cliplist = malloc((clipn + 1) * sizeof(char *));
+ cliplist = SMB_MALLOC_ARRAY(char *, clipn + 1);
if (cliplist == NULL) {
DEBUG(0,("failure allocating memory for cliplist\n"));
error = 1;
/* set current item to NULL so array will be null-terminated even if
* malloc fails below. */
cliplist[i] = NULL;
- if ((tmpstr = (char *)malloc(strlen(p)+1)) == NULL) {
+ if ((tmpstr = (char *)SMB_MALLOC(strlen(p)+1)) == NULL) {
DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", i));
error = 1;
} else {
clipn=argc-Optind-1;
clipcount = clipn;
- if ((tmplist=malloc(clipn*sizeof(char *))) == NULL) {
+ if ((tmplist=SMB_MALLOC_ARRAY(char *,clipn)) == NULL) {
DEBUG(0, ("Could not allocate space to process cliplist, count = %i\n", clipn));
return 0;
}
DEBUG(5, ("Processing an item, %s\n", cliplist[clipcount]));
- if ((tmpstr = (char *)malloc(strlen(cliplist[clipcount])+1)) == NULL) {
+ if ((tmpstr = (char *)SMB_MALLOC(strlen(cliplist[clipcount])+1)) == NULL) {
DEBUG(0, ("Could not allocate space for a cliplist item, # %i\n", clipcount));
return 0;
}
#ifdef HAVE_REGEX_H
int errcode;
- if ((preg = (regex_t *)malloc(65536)) == NULL) {
+ if ((preg = (regex_t *)SMB_MALLOC(65536)) == NULL) {
DEBUG(0, ("Could not allocate buffer for regular expression search\n"));
return;
decode_sid_name_use(group_type, map.sid_name_use);
DEBUG(11,("enum_group_mapping: returning group %s of type %s\n", map.nt_name ,group_type));
- mapt=(GROUP_MAP *)Realloc((*rmap), (entries+1)*sizeof(GROUP_MAP));
+ mapt= SMB_REALLOC_ARRAY((*rmap), GROUP_MAP, entries+1);
if (!mapt) {
DEBUG(0,("enum_group_mapping: Unable to enlarge group map!\n"));
SAFE_FREE(*rmap);
asprintf(&new_memberstring, "%s %s", (char *)(dbuf.dptr),
string_sid);
} else {
- new_memberstring = strdup(string_sid);
+ new_memberstring = SMB_STRDUP(string_sid);
}
if (new_memberstring == NULL)
return tdb_delete(tdb, kbuf) == 0 ?
NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
- member_string = strdup("");
+ member_string = SMB_STRDUP("");
if (member_string == NULL) {
SAFE_FREE(sids);
if (*num_aliases > max_entries)
*num_aliases = max_entries;
- *info = malloc(sizeof(struct acct_info) * (*num_aliases));
+ *info = SMB_MALLOC_ARRAY(struct acct_info, *num_aliases);
for (i=0; i<*num_aliases; i++) {
fstrcpy((*info)[i].acct_name, map[i+start_idx].nt_name);
#define _BOOL /* So we don't typedef BOOL again in vfs.h */
#endif
-/* limiting size of ipc replies */
-#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
-
#define SIZEOFWORD 2
#ifndef DEF_CREATE_MASK
#define SAFE_NETBIOS_CHARS ". -_"
/* generic iconv conversion structure */
-typedef struct {
+typedef struct _smb_iconv_t {
size_t (*direct)(void *cd, const char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft);
size_t (*pull)(void *cd, const char **inbuf, size_t *inbytesleft,
#define IS_DC (lp_server_role()==ROLE_DOMAIN_PDC || lp_server_role()==ROLE_DOMAIN_BDC)
+/*****************************************************************************
+ Safe allocation macros.
+*****************************************************************************/
+
+#define SMB_MALLOC_ARRAY(type,count) (type *)malloc_array(sizeof(type),(count))
+#define SMB_REALLOC(p,s) Realloc((p),(s))
+#define SMB_REALLOC_ARRAY(p,type,count) (type *)realloc_array((p),sizeof(type),(count))
+#define SMB_CALLOC_ARRAY(type,count) (type *)calloc_array(sizeof(type),(count))
+#define SMB_XMALLOC_P(type) (type *)smb_xmalloc_array(sizeof(type),1)
+#define SMB_XMALLOC_ARRAY(type,count) (type *)smb_xmalloc_array(sizeof(type),(count))
+
+/* limiting size of ipc replies */
+#define SMB_REALLOC_LIMIT(ptr,size) SMB_REALLOC(ptr,MAX((size),4*1024))
+
+/* #define PARANOID_MALLOC_CHECKER 1 */
+
+#if defined(PARANOID_MALLOC_CHECKER)
+
+#define TALLOC(ctx, size) talloc_((ctx),(size))
+#define TALLOC_P(ctx, type) (type *)talloc_((ctx),sizeof(type))
+#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array_((ctx),sizeof(type),(count))
+#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup_((ctx),(ptr),(size))
+#define TALLOC_ZERO(ctx, size) talloc_zero_((ctx),(size))
+#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero_((ctx),sizeof(type))
+#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array_((ctx),sizeof(type),(count))
+#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc_((ctx),(ptr),(count))
+#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array_((ctx),(ptr),sizeof(type),(count))
+
+#define PRS_ALLOC_MEM(ps, type, count) (type *)prs_alloc_mem_((ps),sizeof(type),(count))
+
+/* Get medieval on our ass about malloc.... */
+
+/* Restrictions on malloc/realloc/calloc. */
+#ifdef malloc
+#undef malloc
+#endif
+#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
+
+#ifdef realloc
+#undef realloc
+#endif
+#define realloc(p,s) __ERROR_DONT_USE_REALLOC_DIRECTLY
+
+#ifdef calloc
+#undef calloc
+#endif
+#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY
+
+#ifdef strndup
+#undef strndup
+#endif
+#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
+
+#ifdef strdup
+#undef strdup
+#endif
+#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY
+
+#define SMB_MALLOC(s) malloc_(s)
+#define SMB_MALLOC_P(type) (type *)malloc_(sizeof(type))
+
+#define SMB_STRDUP(s) smb_xstrdup(s)
+#define SMB_STRNDUP(s,n) smb_xstrndup(s,n)
+
+#else
+
+#define TALLOC(ctx, size) talloc((ctx),(size))
+#define TALLOC_P(ctx, type) (type *)talloc((ctx),sizeof(type))
+#define TALLOC_ARRAY(ctx, type, count) (type *)talloc_array((ctx),sizeof(type),(count))
+#define TALLOC_MEMDUP(ctx, ptr, size) talloc_memdup((ctx),(ptr),(size))
+#define TALLOC_ZERO(ctx, size) talloc_zero((ctx),(size))
+#define TALLOC_ZERO_P(ctx, type) (type *)talloc_zero((ctx),sizeof(type))
+#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)talloc_zero_array((ctx),sizeof(type),(count))
+#define TALLOC_REALLOC(ctx, ptr, count) talloc_realloc((ctx),(ptr),(count))
+#define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)talloc_realloc_array((ctx),(ptr),sizeof(type),(count))
+
+#define PRS_ALLOC_MEM(ps, type, count) (type *)prs_alloc_mem((ps),sizeof(type),(count))
+
+/* Regular malloc code. */
+
+#define SMB_MALLOC(s) malloc(s)
+#define SMB_MALLOC_P(type) (type *)malloc(sizeof(type))
+
+#define SMB_STRDUP(s) strdup(s)
+#define SMB_STRNDUP(s,n) strndup(s,n)
+
+#endif
+
#endif /* _SMB_MACROS_H */
strerror(errno)));
goto done;
}
- current_lang = strdup(lang);
+ current_lang = SMB_STRDUP(lang);
result = True;
goto done;
}
tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL));
}
- current_lang = strdup(lang);
+ current_lang = SMB_STRDUP(lang);
result = True;
done:
count++;
}
- if (!(msgid_quoted = malloc(strlen(msgid) + count + 1)))
+ if (!(msgid_quoted = SMB_MALLOC(strlen(msgid) + count + 1)))
return msgid;
/* string_sub() is unsuitable here as it replaces some punctuation
/* if the message isn't found then we still need to return a pointer
that can be freed. Pity. */
if (!data.dptr)
- return strdup(msgid);
+ return SMB_STRDUP(msgid);
return (const char *)data.dptr;
}
DEBUG(0,("Unable to get default yp domain.\n"));
return False;
}
- if (!(hostname = strdup(s))) {
+ if (!(hostname = SMB_STRDUP(s))) {
DEBUG(1,("out of memory for strdup!\n"));
return False;
}
len += strlen(account_policy_names[i].string) + 1;
}
len++;
- nl = malloc(len);
+ nl = SMB_MALLOC(len);
if (!nl) {
return NULL;
}
{
SORTED_TREE *tree = NULL;
- if ( !(tree = (SORTED_TREE*)malloc( sizeof(SORTED_TREE) )) )
+ if ( !(tree = SMB_MALLOC_P(SORTED_TREE)) )
return NULL;
ZERO_STRUCTP( tree );
tree->compare = cmp_fn;
tree->free_func = free_fn;
- if ( !(tree->root = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) ) {
+ if ( !(tree->root = SMB_MALLOC_P(TREE_NODE)) ) {
SAFE_FREE( tree );
return NULL;
}
TREE_NODE **siblings;
int i;
- if ( !(infant = (TREE_NODE*)malloc( sizeof(TREE_NODE) )) )
+ if ( !(infant = SMB_MALLOC_P(TREE_NODE)) )
return NULL;
ZERO_STRUCTP( infant );
- infant->key = strdup( key );
+ infant->key = SMB_STRDUP( key );
infant->parent = node;
- siblings = Realloc( node->children, sizeof(TREE_NODE*)*(node->num_children+1) );
+ siblings = SMB_REALLOC_ARRAY( node->children, TREE_NODE *, node->num_children+1 );
if ( siblings )
node->children = siblings;
/* move past the first '/' */
path++;
- path2 = strdup( path );
+ path2 = SMB_STRDUP( path );
if ( !path2 ) {
DEBUG(0,("sorted_tree_add: strdup() failed on string [%s]!?!?!\n", path));
return False;
/* make a copy to play with */
if ( *key == '/' )
- keystr = strdup( key+1 );
+ keystr = SMB_STRDUP( key+1 );
else
- keystr = strdup( key );
+ keystr = SMB_STRDUP( key );
if ( !keystr ) {
DEBUG(0,("sorted_tree_find: strdup() failed on string [%s]!?!?!\n", key));
{
struct bitmap *bm;
- bm = (struct bitmap *)malloc(sizeof(*bm));
+ bm = SMB_MALLOC_P(struct bitmap);
if (!bm) return NULL;
bm->n = n;
- bm->b = (uint32 *)malloc(sizeof(bm->b[0])*(n+31)/32);
+ bm->b = SMB_MALLOC_ARRAY(uint32, (n+31)/32);
if (!bm->b) {
SAFE_FREE(bm);
return NULL;
if (!mem_ctx) return NULL;
- bm = (struct bitmap *)talloc(mem_ctx, sizeof(*bm));
+ bm = TALLOC_P(mem_ctx, struct bitmap);
if (!bm) return NULL;
bm->n = n;
- bm->b = (uint32 *)talloc(mem_ctx, sizeof(bm->b[0])*(n+31)/32);
+ bm->b = TALLOC_ARRAY(mem_ctx, uint32, (n+31)/32);
if (!bm->b) {
return NULL;
}
}
if (ctx)
- ob = (char *)talloc_realloc(ctx, ob, destlen);
+ ob = (char *)TALLOC_REALLOC(ctx, ob, destlen);
else
- ob = (char *)Realloc(ob, destlen);
+ ob = (char *)SMB_REALLOC(ob, destlen);
if (!ob) {
DEBUG(0, ("convert_string_allocate: realloc failed!\n"));
destlen = destlen - o_len;
if (ctx)
- *dest = (char *)talloc_realloc(ctx,ob,destlen);
+ *dest = (char *)TALLOC_REALLOC(ctx,ob,destlen);
else
- *dest = (char *)Realloc(ob,destlen);
+ *dest = (char *)SMB_REALLOC(ob,destlen);
if (destlen && !*dest) {
DEBUG(0, ("convert_string_allocate: out of memory!\n"));
if (!ctx)
}
}
- return strdup(out_buffer);
+ return SMB_STRDUP(out_buffer);
}
size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
if (p) {
ret.data = smb_xmemdup(p, length);
} else {
- ret.data = smb_xmalloc(length);
+ ret.data = SMB_XMALLOC_ARRAY(char, length);
}
ret.length = length;
ret.free = free_data_blob;
}
if (p) {
- ret.data = talloc_memdup(mem_ctx, p, length);
+ ret.data = TALLOC_MEMDUP(mem_ctx, p, length);
if (ret.data == NULL)
smb_panic("data_blob_talloc: talloc_memdup failed.\n");
} else {
- ret.data = talloc(mem_ctx, length);
+ ret.data = TALLOC(mem_ctx, length);
if (ret.data == NULL)
smb_panic("data_blob_talloc: talloc failed.\n");
}
if (DEBUGLEVEL_CLASS == &debug_all_class_hack)
return NULL;
- list = calloc(debug_num_classes + 1, sizeof(char *));
+ list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1);
if (!list)
return NULL;
}
/* create single string list - add space for newline */
- b = buf = malloc(dim+1);
+ b = buf = SMB_MALLOC(dim+1);
if (!buf) {
err = True;
goto done;
/* Initial loading... */
new_ptr = NULL;
}
- new_ptr = Realloc(new_ptr, sizeof(int) * (debug_num_classes + 1));
+ new_ptr = SMB_REALLOC_ARRAY(new_ptr, int, debug_num_classes + 1);
if (!new_ptr)
return -1;
DEBUGLEVEL_CLASS = new_ptr;
if (new_ptr == &debug_all_class_isset_hack) {
new_ptr = NULL;
}
- new_ptr = Realloc(new_ptr, sizeof(BOOL) * (debug_num_classes + 1));
+ new_ptr = SMB_REALLOC_ARRAY(new_ptr, BOOL, debug_num_classes + 1);
if (!new_ptr)
return -1;
DEBUGLEVEL_CLASS_ISSET = new_ptr;
DEBUGLEVEL_CLASS_ISSET[ndx] = False;
- new_ptr = Realloc(classname_table,
- sizeof(char *) * (debug_num_classes + 1));
+ new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1);
if (!new_ptr)
return -1;
classname_table = new_ptr;
- classname_table[ndx] = strdup(classname);
+ classname_table[ndx] = SMB_STRDUP(classname);
if (! classname_table[ndx])
return -1;
charset, but beware of it growing */
maxlen = ret*2;
again:
- p2 = malloc(maxlen);
+ p2 = SMB_MALLOC(maxlen);
if (!p2) {
SAFE_FREE(p);
return -1;
if (!valstr)
return False;
- keybuf.dptr = strdup(keystr);
+ keybuf.dptr = SMB_STRDUP(keystr);
keybuf.dsize = strlen(keystr)+1;
- databuf.dptr = strdup(valstr);
+ databuf.dptr = SMB_STRDUP(valstr);
databuf.dsize = strlen(valstr)+1;
DEBUG(10, ("Adding cache entry with key = %s; value = %s and timeout ="
" %s (%d seconds %s)\n", keybuf.dptr, value,ctime(&timeout),
= %s\n", keystr, old_valstr, ctime(&old_timeout)));
asprintf(&datastr, CACHE_DATA_FMT, (int)timeout, valstr);
- keybuf.dptr = strdup(keystr);
+ keybuf.dptr = SMB_STRDUP(keystr);
keybuf.dsize = strlen(keystr)+1;
- databuf.dptr = strdup(datastr);
+ databuf.dptr = SMB_STRDUP(datastr);
databuf.dsize = strlen(datastr)+1;
DEBUGADD(10, ("New value = %s, new timeout = %s (%d seconds %s)", valstr,
ctime(&timeout), (int)(timeout - time(NULL)),
if (!gencache_init()) return False;
- keybuf.dptr = strdup(keystr);
+ keybuf.dptr = SMB_STRDUP(keystr);
keybuf.dsize = strlen(keystr)+1;
DEBUG(10, ("Deleting cache entry (key = %s)\n", keystr));
ret = tdb_delete(cache, keybuf);
if (!gencache_init())
return False;
- keybuf.dptr = strdup(keystr);
+ keybuf.dptr = SMB_STRDUP(keystr);
keybuf.dsize = strlen(keystr)+1;
databuf = tdb_fetch(cache, keybuf);
SAFE_FREE(keybuf.dptr);
if (databuf.dptr && databuf.dsize > TIMEOUT_LEN) {
- char* entry_buf = strndup(databuf.dptr, databuf.dsize);
+ char* entry_buf = SMB_STRNDUP(databuf.dptr, databuf.dsize);
char *v;
time_t t;
- v = (char*)malloc(sizeof(char) *
- (databuf.dsize - TIMEOUT_LEN));
+ v = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN);
SAFE_FREE(databuf.dptr);
sscanf(entry_buf, CACHE_DATA_FMT, (int*)&t, v);
while (node) {
/* ensure null termination of the key string */
- keystr = strndup(node->node_key.dptr, node->node_key.dsize);
+ keystr = SMB_STRNDUP(node->node_key.dptr, node->node_key.dsize);
/*
* We don't use gencache_get function, because we need to iterate through
node = node->next;
continue;
}
- entry = strndup(databuf.dptr, databuf.dsize);
+ entry = SMB_STRNDUP(databuf.dptr, databuf.dsize);
SAFE_FREE(databuf.dptr);
- valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN));
+ valstr = SMB_MALLOC(databuf.dsize - TIMEOUT_LEN);
sscanf(entry, CACHE_DATA_FMT, (int*)(&timeout), valstr);
DEBUG(10, ("Calling function with arguments (key = %s, value = %s, timeout = %s)\n",
from = charsets;
to = charsets;
- ret = (smb_iconv_t)malloc(sizeof(*ret));
+ ret = SMB_MALLOC_P(struct _smb_iconv_t);
if (!ret) {
errno = ENOMEM;
return (smb_iconv_t)-1;
}
- memset(ret, 0, sizeof(*ret));
+ memset(ret, 0, sizeof(struct _smb_iconv_t));
- ret->from_name = strdup(fromcode);
- ret->to_name = strdup(tocode);
+ ret->from_name = SMB_STRDUP(fromcode);
+ ret->to_name = SMB_STRDUP(tocode);
/* check for the simplest null conversion */
if (strcasecmp(fromcode, tocode) == 0) {
return;
}
- iface = (struct interface *)malloc(sizeof(*iface));
+ iface = SMB_MALLOC_P(struct interface);
if (!iface) return;
ZERO_STRUCTPN(iface);
if (ptr) {
while (*ptr) {
- char *ptr_cpy = strdup(*ptr);
+ char *ptr_cpy = SMB_STRDUP(*ptr);
if (ptr_cpy) {
interpret_interface(ptr_cpy);
free(ptr_cpy);
char *escape_ldap_string_alloc(const char *s)
{
size_t len = strlen(s)+1;
- char *output = malloc(len);
+ char *output = SMB_MALLOC(len);
char *output_tmp;
const char *sub;
int i = 0;
if (sub) {
len = len + 3;
- output_tmp = realloc(output, len);
+ output_tmp = SMB_REALLOC(output, len);
if (!output_tmp) {
SAFE_FREE(output);
return NULL;
kbuf = message_key_pid(pid);
- dbuf.dptr = (void *)malloc(len + sizeof(rec));
+ dbuf.dptr = (void *)SMB_MALLOC(len + sizeof(rec));
if (!dbuf.dptr)
return False;
{
struct dispatch_fns *dfn;
- dfn = (struct dispatch_fns *)malloc(sizeof(*dfn));
+ dfn = SMB_MALLOC_P(struct dispatch_fns);
if (dfn != NULL) {
return SMB_EVENT_ID_INVALID;
}
- event = (struct smb_idle_list_ent *)malloc(sizeof(struct smb_idle_list_ent));
+ event = SMB_MALLOC_P(struct smb_idle_list_ent);
if (!event) {
DEBUG(0,("malloc() failed!\n"));
return SMB_EVENT_ID_INVALID;
return SMB_EVENT_ID_INVALID;
}
- event = (struct smb_exit_list_ent *)malloc(sizeof(struct smb_exit_list_ent));
+ event = SMB_MALLOC_P(struct smb_exit_list_ent);
if (!event) {
DEBUG(0,("malloc() failed!\n"));
return SMB_EVENT_ID_INVALID;
}
if (count != 0) {
- max_n = calloc(sizeof(struct max_n), count);
+ max_n = SMB_CALLOC_ARRAY(struct max_n, count);
if (!max_n) {
return -1;
}
if ( !old_la )
return NT_STATUS_OK;
- *new_la = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR));
+ *new_la = TALLOC_P(mem_ctx, LUID_ATTR);
ALLOC_CHECK(new_la, ret, done, "dupalloc_luid_attr");
(*new_la)->luid.high = old_la->luid.high;
TALLOC_CTX *mem_ctx = talloc_init("privilege set");
ALLOC_CHECK(mem_ctx, ret, done, "init_privilege");
- *priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET));
+ *priv_set = TALLOC_ZERO_P(mem_ctx, PRIVILEGE_SET);
ALLOC_CHECK(*priv_set, ret, done, "init_privilege");
(*priv_set)->mem_ctx = mem_ctx;
{
NTSTATUS ret;
- *priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET));
+ *priv_set = TALLOC_ZERO_P(mem_ctx, PRIVILEGE_SET);
ALLOC_CHECK(*priv_set, ret, done, "init_privilege");
(*priv_set)->mem_ctx = mem_ctx;
/* we can allocate memory to add the new privilege */
- new_set = (LUID_ATTR *)talloc_realloc(priv_set->mem_ctx, priv_set->set, (priv_set->count + 1) * (sizeof(LUID_ATTR)));
+ new_set = TALLOC_REALLOC_ARRAY(priv_set->mem_ctx, priv_set->set, LUID_ATTR, priv_set->count + 1);
ALLOC_CHECK(new_set, ret, done, "add_privilege");
new_set[priv_set->count].luid.high = set.luid.high;
old_set = priv_set->set;
- new_set = (LUID_ATTR *)talloc(priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR)));
+ new_set = TALLOC_ARRAY(priv_set->mem_ctx, LUID_ATTR, priv_set->count - 1);
ALLOC_CHECK(new_set, ret, done, "remove_privilege");
for (i=0, j=0; i < priv_set->count; i++) {
old_set = priv_set->set;
- new_set = (LUID_ATTR *)talloc(new_priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR)));
+ new_set = TALLOC_ARRAY(new_priv_set->mem_ctx, LUID_ATTR, priv_set->count - 1);
ALLOC_CHECK(new_set, ret, done, "dup_priv_set");
for (i=0; i < priv_set->count; i++) {
*num += 1;
- if((new[0] = (SEC_ACE *) talloc_zero(ctx, (*num) * sizeof(SEC_ACE))) == 0)
+ if((new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0)
return NT_STATUS_NO_MEMORY;
for (i = 0; i < *num - 1; i ++)
if (!ctx || !new || !old || !sid || !num) return NT_STATUS_INVALID_PARAMETER;
- if((new[0] = (SEC_ACE *) talloc_zero(ctx, (*num) * sizeof(SEC_ACE))) == 0)
+ if((new[0] = TALLOC_ZERO_ARRAY(ctx, SEC_ACE, *num )) == 0)
return NT_STATUS_NO_MEMORY;
for (i = 0; i < *num; i ++) {
SEC_ACL *dst;
int i;
- if((dst = (SEC_ACL *)talloc_zero(ctx,sizeof(SEC_ACL))) == NULL)
+ if((dst = TALLOC_ZERO_P(ctx,SEC_ACL)) == NULL)
return NULL;
dst->revision = revision;
positive number. */
if ((num_aces) &&
- ((dst->ace = (SEC_ACE *)talloc(ctx, sizeof(SEC_ACE) * num_aces))
+ ((dst->ace = TALLOC_ARRAY(ctx, SEC_ACE, num_aces))
== NULL)) {
return NULL;
}
*sd_size = 0;
- if(( dst = (SEC_DESC *)talloc_zero(ctx, sizeof(SEC_DESC))) == NULL)
+ if(( dst = TALLOC_ZERO_P(ctx, SEC_DESC)) == NULL)
return NULL;
dst->revision = revision;
{
SEC_DESC_BUF *dst;
- if((dst = (SEC_DESC_BUF *)talloc_zero(ctx, sizeof(SEC_DESC_BUF))) == NULL)
+ if((dst = TALLOC_ZERO_P(ctx, SEC_DESC_BUF)) == NULL)
return NULL;
/* max buffer size (allocated size) */
the_acl = parent_ctr->dacl;
- if (!(new_ace_list = talloc(ctx, sizeof(SEC_ACE) * the_acl->num_aces)))
+ if (!(new_ace_list = TALLOC_ARRAY(ctx, SEC_ACE, the_acl->num_aces)))
return NULL;
for (i = 0; the_acl && i < the_acl->num_aces; i++) {
BOOL grab_server_mutex(const char *name)
{
- mutex_server_name = strdup(name);
+ mutex_server_name = SMB_STRDUP(name);
if (!mutex_server_name) {
DEBUG(0,("grab_server_mutex: malloc failed for %s\n", name));
return False;
i++;
i++;
- names = (char**)malloc( sizeof(char*)*i );
+ names = SMB_MALLOC_ARRAY( char*, i );
if ( !names ) {
DEBUG(0,("get_attr_list: out of memory\n"));
return NULL;
i = 0;
while ( table[i].attrib != LDAP_ATTR_LIST_END ) {
- names[i] = strdup( table[i].name );
+ names[i] = SMB_STRDUP( table[i].name );
i++;
}
names[i] = NULL;
if (!size) {
/* Upgrade 2.2 style entry */
char *p;
- char* old_style_key = strdup(*dn);
+ char* old_style_key = SMB_STRDUP(*dn);
char *data;
fstring old_style_pw;
#endif
if (mods == NULL) {
- mods = (LDAPMod **) malloc(sizeof(LDAPMod *));
+ mods = SMB_MALLOC_P(LDAPMod *);
if (mods == NULL) {
DEBUG(0, ("make_a_mod: out of memory!\n"));
return;
}
if (mods[i] == NULL) {
- mods = (LDAPMod **) Realloc (mods, (i + 2) * sizeof (LDAPMod *));
+ mods = SMB_REALLOC_ARRAY (mods, LDAPMod *, i + 2);
if (mods == NULL) {
DEBUG(0, ("make_a_mod: out of memory!\n"));
return;
}
- mods[i] = (LDAPMod *) malloc(sizeof(LDAPMod));
+ mods[i] = SMB_MALLOC_P(LDAPMod);
if (mods[i] == NULL) {
DEBUG(0, ("make_a_mod: out of memory!\n"));
return;
}
mods[i]->mod_op = modop;
mods[i]->mod_values = NULL;
- mods[i]->mod_type = strdup(attribute);
+ mods[i]->mod_type = SMB_STRDUP(attribute);
mods[i + 1] = NULL;
}
if (mods[i]->mod_values != NULL) {
for (; mods[i]->mod_values[j] != NULL; j++);
}
- mods[i]->mod_values = (char **)Realloc(mods[i]->mod_values,
- (j + 2) * sizeof (char *));
+ mods[i]->mod_values = SMB_REALLOC_ARRAY(mods[i]->mod_values, char *, j + 2);
if (mods[i]->mod_values == NULL) {
DEBUG (0, ("make_a_mod: Memory allocation failure!\n"));
return;
}
- t = smb_xmalloc(sizeof(*t));
+ t = SMB_XMALLOC_P(struct smbldap_state_lookup);
ZERO_STRUCTP(t);
DLIST_ADD_END(smbldap_state_lookup_list, t, tmp);
DEBUG(5,("rebind_proc_with_state: Rebinding as \"%s\"\n",
ldap_state->bind_dn));
- *whop = strdup(ldap_state->bind_dn);
+ *whop = SMB_STRDUP(ldap_state->bind_dn);
if (!*whop) {
return LDAP_NO_MEMORY;
}
- *credp = strdup(ldap_state->bind_secret);
+ *credp = SMB_STRDUP(ldap_state->bind_secret);
if (!*credp) {
SAFE_FREE(*whop);
return LDAP_NO_MEMORY;
NTSTATUS smbldap_init(TALLOC_CTX *mem_ctx, const char *location, struct smbldap_state **smbldap_state)
{
- *smbldap_state = talloc_zero(mem_ctx, sizeof(**smbldap_state));
+ *smbldap_state = TALLOC_ZERO_P(mem_ctx, struct smbldap_state);
if (!*smbldap_state) {
DEBUG(0, ("talloc() failed for ldapsam private_data!\n"));
return NT_STATUS_NO_MEMORY;
r = p + 3;
copylen = q - r;
- envname = (char *)malloc(copylen + 1 + 4); /* reserve space for use later add %$() chars */
+ envname = (char *)SMB_MALLOC(copylen + 1 + 4); /* reserve space for use later add %$() chars */
if (envname == NULL) return NULL;
strncpy(envname,r,copylen);
envname[copylen] = '\0';
return NULL;
}
- a_string = strdup(str);
+ a_string = SMB_STRDUP(str);
if (a_string == NULL) {
DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));
return NULL;
t = realloc_string_sub(t, "%U", r);
break;
case 'G' :
- r = strdup(smb_name);
+ r = SMB_STRDUP(smb_name);
if (r == NULL) goto error;
if ((pass = Get_Pwnam(r))!=NULL) {
t = realloc_string_sub(t, "%G", gidtoname(pass->pw_gid));
char *a_string, *ret_string;
char *b, *p, *s, *t;
- a_string = strdup(input_string);
+ a_string = SMB_STRDUP(input_string);
if (a_string == NULL) {
DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));
return NULL;
char *a_string, *ret_string;
char *b, *p, *s, *t, *h;
- a_string = strdup(str);
+ a_string = SMB_STRDUP(str);
if (a_string == NULL) {
DEBUG(0, ("alloc_sub_specified: Out of memory!\n"));
return NULL;
for( argcl = 1; ptr; ptr = strtok(NULL, " \t"))
argcl++;
- if((argl = (char **)malloc((argcl + 1) * sizeof(char *))) == NULL)
+ if((argl = (char **)SMB_MALLOC((argcl + 1) * sizeof(char *))) == NULL)
return NULL;
/*
goto err_exit;
}
- if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL)
+ if((entry = SMB_MALLOC_P(popen_list)) == NULL)
goto err_exit;
ZERO_STRUCTP(entry);
return -1;
}
- gids_saved = (gid_t *)malloc(sizeof(gid_t) * (ngrp_saved+1));
+ gids_saved = SMB_MALLOC_ARRAY(gid_t, ngrp_saved+1);
if (!gids_saved) {
errno = ENOMEM;
return -1;
int i;
max_grp = groups_max();
- temp_groups = (gid_t *)malloc(sizeof(gid_t) * max_grp);
+ temp_groups = SMB_MALLOC_ARRAY(gid_t, max_grp);
if (! temp_groups) {
return False;
}
gid_t *groups_tmp;
- groups_tmp = Realloc(temp_groups, sizeof(gid_t) * max_grp);
+ groups_tmp = SMB_REALLOC_ARRAY(temp_groups, gid_t, max_grp);
if (!groups_tmp) {
SAFE_FREE(temp_groups);
smb_panic("primary group missing");
}
- *sids = malloc(sizeof(**sids) * *num_groups);
+ *sids = SMB_MALLOC_ARRAY(DOM_SID, *num_groups);
if (*sids == NULL) {
SAFE_FREE(gids);
#include "includes.h"
+/* Max allowable allococation - 256mb - 0x10000000 */
+#define MAX_TALLOC_SIZE (1024*1024*256)
/**
* Start of linked list of all talloc pools.
{
TALLOC_CTX *t;
- t = (TALLOC_CTX *)malloc(sizeof(TALLOC_CTX));
+ t = (TALLOC_CTX *)SMB_MALLOC(sizeof(TALLOC_CTX));
if (t) {
t->list = NULL;
t->total_alloc_size = 0;
/** Allocate a bit of memory from the specified pool **/
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_(TALLOC_CTX *t, size_t size)
+#else
void *talloc(TALLOC_CTX *t, size_t size)
+#endif
{
void *p;
struct talloc_chunk *tc;
if (!t || size == 0) return NULL;
- p = malloc(size);
+ p = SMB_MALLOC(size);
if (p) {
- tc = malloc(sizeof(*tc));
+ tc = SMB_MALLOC(sizeof(*tc));
if (tc) {
tc->ptr = p;
tc->size = size;
return p;
}
+/** Allocate an array of count elements of size x */
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_array_(TALLOC_CTX *ctx, size_t el_size, unsigned int count)
+#else
+void *talloc_array(TALLOC_CTX *ctx, size_t el_size, unsigned int count)
+#endif
+{
+ if (count >= MAX_TALLOC_SIZE/el_size) {
+ return NULL;
+ }
+ return TALLOC(ctx, el_size * count);
+}
+
/** A talloc version of realloc */
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_realloc_(TALLOC_CTX *t, void *ptr, size_t size)
+#else
void *talloc_realloc(TALLOC_CTX *t, void *ptr, size_t size)
+#endif
{
struct talloc_chunk *tc;
void *new_ptr;
/* realloc(NULL) is equavalent to malloc() */
if (ptr == NULL)
- return talloc(t, size);
+ return TALLOC(t, size);
for (tc=t->list; tc; tc=tc->next) {
if (tc->ptr == ptr) {
- new_ptr = Realloc(ptr, size);
+ new_ptr = SMB_REALLOC(ptr, size);
if (new_ptr) {
t->total_alloc_size += (size - tc->size);
tc->size = size;
return NULL;
}
+/** Re-allocate an array of count elements of size x */
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_realloc_array_(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count)
+#else
+void *talloc_realloc_array(TALLOC_CTX *ctx, void *ptr, size_t el_size, unsigned int count)
+#endif
+{
+ if (count >= MAX_TALLOC_SIZE/el_size) {
+ return NULL;
+ }
+ return TALLOC_REALLOC(ctx, ptr, el_size * count);
+}
+
/** Destroy all the memory allocated inside @p t, but not @p t
* itself. */
void talloc_destroy_pool(TALLOC_CTX *t)
/** talloc and zero memory. */
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_zero_(TALLOC_CTX *t, size_t size)
+#else
void *talloc_zero(TALLOC_CTX *t, size_t size)
+#endif
{
- void *p = talloc(t, size);
+ void *p = TALLOC(t, size);
if (p)
memset(p, '\0', size);
return p;
}
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_zero_array_(TALLOC_CTX *t, size_t el_size, unsigned int count)
+#else
+void *talloc_zero_array(TALLOC_CTX *t, size_t el_size, unsigned int count)
+#endif
+{
+#if defined(PARANOID_MALLOC_CHECKER)
+ void *p = talloc_array_(t, el_size, count);
+#else
+ void *p = talloc_array(t, el_size, count);
+#endif
+
+ if (p)
+ memset(p, '\0', el_size*count);
+
+ return p;
+}
+
/** memdup with a talloc. */
+#if defined(PARANOID_MALLOC_CHECKER)
+void *talloc_memdup_(TALLOC_CTX *t, const void *p, size_t size)
+#else
void *talloc_memdup(TALLOC_CTX *t, const void *p, size_t size)
+#endif
{
- void *newp = talloc(t,size);
+ void *newp = TALLOC(t,size);
if (newp)
memcpy(newp, p, size);
char *talloc_strdup(TALLOC_CTX *t, const char *p)
{
if (p)
- return talloc_memdup(t, p, strlen(p) + 1);
+ return TALLOC_MEMDUP(t, p, strlen(p) + 1);
else
return NULL;
}
smb_ucs2_t *talloc_strdup_w(TALLOC_CTX *t, const smb_ucs2_t *p)
{
if (p)
- return talloc_memdup(t, p, (strlen_w(p) + 1) * sizeof(smb_ucs2_t));
+ return TALLOC_MEMDUP(t, p, (strlen_w(p) + 1) * sizeof(smb_ucs2_t));
else
return NULL;
}
len = vsnprintf(NULL, 0, fmt, ap2);
- ret = talloc(t, len+1);
+ ret = TALLOC(t, len+1);
if (ret) {
VA_COPY(ap2, ap);
vsnprintf(ret, len+1, fmt, ap2);
s_len = strlen(s);
len = vsnprintf(NULL, 0, fmt, ap2);
- s = talloc_realloc(t, s, s_len + len+1);
+ s = TALLOC_REALLOC(t, s, s_len + len+1);
if (!s) return NULL;
VA_COPY(ap2, ap);
time_t low,high;
zone = TimeZone(t);
- tdt = (struct dst_table *)Realloc(dst_table,
- sizeof(dst_table[0])*(i+1));
+ tdt = SMB_REALLOC_ARRAY(dst_table, struct dst_table, i+1);
if (!tdt) {
DEBUG(0,("TimeZoneFaster: out of memory!\n"));
SAFE_FREE(dst_table);
#include "includes.h"
+/* Max allowable allococation - 256mb - 0x10000000 */
+#define MAX_ALLOC_SIZE (1024*1024*256)
+
#if (defined(HAVE_NETGROUP) && defined (WITH_AUTOMOUNT))
#ifdef WITH_NISPLUS_HOME
#ifdef BROKEN_NISPLUS_INCLUDE_FILES
BOOL set_global_myname(const char *myname)
{
SAFE_FREE(smb_myname);
- smb_myname = strdup(myname);
+ smb_myname = SMB_STRDUP(myname);
if (!smb_myname)
return False;
strupper_m(smb_myname);
BOOL set_global_myworkgroup(const char *myworkgroup)
{
SAFE_FREE(smb_myworkgroup);
- smb_myworkgroup = strdup(myworkgroup);
+ smb_myworkgroup = SMB_STRDUP(myworkgroup);
if (!smb_myworkgroup)
return False;
strupper_m(smb_myworkgroup);
BOOL set_global_scope(const char *scope)
{
SAFE_FREE(smb_scope);
- smb_scope = strdup(scope);
+ smb_scope = SMB_STRDUP(scope);
if (!smb_scope)
return False;
strupper_m(smb_scope);
free_netbios_names_array();
smb_num_netbios_names = number + 1;
- smb_my_netbios_names = (char **)malloc( sizeof(char *) * smb_num_netbios_names );
+ smb_my_netbios_names = SMB_MALLOC_ARRAY( char *, smb_num_netbios_names );
if (!smb_my_netbios_names)
return False;
{
SAFE_FREE(smb_my_netbios_names[i]);
- smb_my_netbios_names[i] = strdup(name);
+ smb_my_netbios_names[i] = SMB_STRDUP(name);
if (!smb_my_netbios_names[i])
return False;
strupper_m(smb_my_netbios_names[i]);
return;
}
- *gids = Realloc(*gids, (*num+1) * sizeof(gid_t));
+ *gids = SMB_REALLOC_ARRAY(*gids, gid_t, *num+1);
if (*gids == NULL)
return;
while ((p = Atoic(p, &val, ":,")) != NULL && (*p) != ':') {
uint32 *tn;
- tn = Realloc((*num), ((*count)+1) * sizeof(uint32));
+ tn = SMB_REALLOC_ARRAY((*num), uint32, (*count)+1);
if (tn == NULL) {
SAFE_FREE(*num);
return NULL;
size_t num_to_read_thistime;
size_t num_written = 0;
- if ((buf = malloc(TRANSFER_BUF_SIZE)) == NULL)
+ if ((buf = SMB_MALLOC(TRANSFER_BUF_SIZE)) == NULL)
return -1;
while (total < n) {
return(False);
}
+#if defined(PARANOID_MALLOC_CHECKER)
+
+/****************************************************************************
+ Internal malloc wrapper. Externally visible.
+****************************************************************************/
+
+void *malloc_(size_t size)
+{
+#undef malloc
+ /* If we don't add an amount here the glibc memset seems to write
+ one byte over. */
+ return malloc(size+16);
+#define malloc(s) __ERROR_DONT_USE_MALLOC_DIRECTLY
+}
+
+/****************************************************************************
+ Internal calloc wrapper. Not externally visible.
+****************************************************************************/
+
+static void *calloc_(size_t count, size_t size)
+{
+#undef calloc
+ /* If we don't add an amount here the glibc memset seems to write
+ one byte over. */
+ return calloc(count+1, size);
+#define calloc(n,s) __ERROR_DONT_USE_CALLOC_DIRECTLY
+}
+
+/****************************************************************************
+ Internal realloc wrapper. Not externally visible.
+****************************************************************************/
+
+static void *realloc_(void *ptr, size_t size)
+{
+#undef realloc
+ /* If we don't add an amount here the glibc memset seems to write
+ one byte over. */
+ return realloc(ptr, size+16);
+#define realloc(p,s) __ERROR_DONT_USE_RELLOC_DIRECTLY
+}
+
+#endif /* PARANOID_MALLOC_CHECKER */
+
+/****************************************************************************
+ Type-safe malloc.
+****************************************************************************/
+
+void *malloc_array(size_t el_size, unsigned int count)
+{
+ if (count >= MAX_ALLOC_SIZE/el_size) {
+ return NULL;
+ }
+
+#if defined(PARANOID_MALLOC_CHECKER)
+ return malloc_(el_size*count);
+#else
+ return malloc(el_size*count);
+#endif
+}
+
+/****************************************************************************
+ Type-safe calloc.
+****************************************************************************/
+
+void *calloc_array(size_t size, size_t nmemb)
+{
+ if (nmemb >= MAX_ALLOC_SIZE/size) {
+ return NULL;
+ }
+#if defined(PARANOID_MALLOC_CHECKER)
+ return calloc_(nmemb, size);
+#else
+ return calloc(nmemb, size);
+#endif
+}
+
/****************************************************************************
Expand a pointer to be a particular size.
****************************************************************************/
return NULL;
}
+#if defined(PARANOID_MALLOC_CHECKER)
+ if (!p)
+ ret = (void *)malloc_(size);
+ else
+ ret = (void *)realloc_(p,size);
+#else
if (!p)
ret = (void *)malloc(size);
else
ret = (void *)realloc(p,size);
+#endif
if (!ret)
DEBUG(0,("Memory allocation error: failed to expand to %d bytes\n",(int)size));
return(ret);
}
-void *Realloc_zero(void *ptr, size_t size)
+/****************************************************************************
+ Type-safe realloc.
+****************************************************************************/
+
+void *realloc_array(void *p,size_t el_size, unsigned int count)
{
- void *tptr = NULL;
-
- tptr = Realloc(ptr, size);
- if(tptr == NULL)
+ if (count >= MAX_ALLOC_SIZE/el_size) {
return NULL;
-
- memset((char *)tptr,'\0',size);
-
- return tptr;
+ }
+ return Realloc(p,el_size*count);
}
/****************************************************************************
if(num_entries == 0)
return;
- if(( (*ppname_array) = (name_compare_entry *)malloc(
- (num_entries + 1) * sizeof(name_compare_entry))) == NULL) {
+ if(( (*ppname_array) = SMB_MALLOC_ARRAY(name_compare_entry, num_entries + 1)) == NULL) {
DEBUG(0,("set_namearray: malloc fail\n"));
return;
}
break;
(*ppname_array)[i].is_wild = ms_has_wild(nameptr);
- if(((*ppname_array)[i].name = strdup(nameptr)) == NULL) {
+ if(((*ppname_array)[i].name = SMB_STRDUP(nameptr)) == NULL) {
DEBUG(0,("set_namearray: malloc fail (1)\n"));
return;
}
malloc that aborts with smb_panic on fail or zero size.
*****************************************************************/
-void *smb_xmalloc(size_t size)
+void *smb_xmalloc_array(size_t size, unsigned int count)
{
void *p;
if (size == 0)
- smb_panic("smb_xmalloc: called with zero size.\n");
- if ((p = malloc(size)) == NULL) {
- DEBUG(0, ("smb_xmalloc() failed to allocate %lu bytes\n", (unsigned long)size));
- smb_panic("smb_xmalloc: malloc fail.\n");
+ smb_panic("smb_xmalloc_array: called with zero size.\n");
+ if (count >= MAX_ALLOC_SIZE/size) {
+ smb_panic("smb_xmalloc: alloc size too large.\n");
+ }
+ if ((p = SMB_MALLOC(size*count)) == NULL) {
+ DEBUG(0, ("smb_xmalloc_array failed to allocate %lu * %lu bytes\n",
+ (unsigned long)size, (unsigned long)count));
+ smb_panic("smb_xmalloc_array: malloc fail.\n");
}
return p;
}
void *smb_xmemdup(const void *p, size_t size)
{
void *p2;
- p2 = smb_xmalloc(size);
+ p2 = SMB_XMALLOC_ARRAY(unsigned char,size);
memcpy(p2, p, size);
return p2;
}
char *smb_xstrdup(const char *s)
{
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef strdup
+#undef strdup
+#endif
+#endif
char *s1 = strdup(s);
+#if defined(PARANOID_MALLOC_CHECKER)
+#define strdup(s) __ERROR_DONT_USE_STRDUP_DIRECTLY
+#endif
if (!s1)
smb_panic("smb_xstrdup: malloc fail\n");
return s1;
+
}
/**
char *smb_xstrndup(const char *s, size_t n)
{
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef strndup
+#undef strndup
+#endif
+#endif
char *s1 = strndup(s, n);
+#if defined(PARANOID_MALLOC_CHECKER)
+#define strndup(s,n) __ERROR_DONT_USE_STRNDUP_DIRECTLY
+#endif
if (!s1)
smb_panic("smb_xstrndup: malloc fail\n");
return s1;
void *p2;
if (size == 0)
return NULL;
- p2 = malloc(size);
+ p2 = SMB_MALLOC(size);
if (!p2)
return NULL;
memcpy(p2, p, size);
if (!s2) {
maxlen = MIN(maxlen,8);
- s = (char *)malloc(maxlen);
+ s = (char *)SMB_MALLOC(maxlen);
}
if (!s) {
char *t;
maxlen *= 2;
- t = (char *)Realloc(s,maxlen);
+ t = (char *)SMB_REALLOC(s,maxlen);
if (!t) {
DEBUG(0,("fgets_slash: failed to expand buffer!\n"));
SAFE_FREE(s);
total = 0;
while ((n = read(fd, buf, sizeof(buf))) > 0) {
- tp = Realloc(p, total + n + 1);
+ tp = SMB_REALLOC(p, total + n + 1);
if (!tp) {
DEBUG(0,("file_pload: failed to expand buffer!\n"));
close(fd);
return NULL;
}
- p = (char *)malloc(sbuf.st_size+1);
+ p = (char *)SMB_MALLOC(sbuf.st_size+1);
if (!p) {
return NULL;
}
if (s[0] == '\n') i++;
}
- ret = (char **)malloc(sizeof(ret[0])*(i+2));
+ ret = SMB_MALLOC_ARRAY(char *, i+2);
if (!ret) {
SAFE_FREE(p);
return NULL;
struct sys_grent *gent;
struct group *grp;
- gent = (struct sys_grent *) malloc(sizeof(struct sys_grent));
+ gent = SMB_MALLOC_P(struct sys_grent);
if (gent == NULL) {
DEBUG (0, ("Out of memory in getgrent_list!\n"));
return NULL;
int i,num;
if (grp->gr_name) {
- if ((gent->gr_name = strdup(grp->gr_name)) == NULL)
+ if ((gent->gr_name = SMB_STRDUP(grp->gr_name)) == NULL)
goto err;
}
if (grp->gr_passwd) {
- if ((gent->gr_passwd = strdup(grp->gr_passwd)) == NULL)
+ if ((gent->gr_passwd = SMB_STRDUP(grp->gr_passwd)) == NULL)
goto err;
}
gent->gr_gid = grp->gr_gid;
;
/* alloc space for gr_mem string pointers */
- if ((gent->gr_mem = (char **) malloc((num+1) * sizeof(char *))) == NULL)
+ if ((gent->gr_mem = SMB_MALLOC_ARRAY(char *, num+1)) == NULL)
goto err;
memset(gent->gr_mem, '\0', (num+1) * sizeof(char *));
for (i=0; i < num; i++) {
- if ((gent->gr_mem[i] = strdup(grp->gr_mem[i])) == NULL)
+ if ((gent->gr_mem[i] = SMB_STRDUP(grp->gr_mem[i])) == NULL)
goto err;
}
gent->gr_mem[num] = NULL;
grp = getgrent();
if (grp) {
- gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent));
+ gent->next = SMB_MALLOC_P(struct sys_grent);
if (gent->next == NULL)
goto err;
gent = gent->next;
struct sys_pwent *pent;
struct passwd *pwd;
- pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
+ pent = SMB_MALLOC_P(struct sys_pwent);
if (pent == NULL) {
DEBUG (0, ("Out of memory in getpwent_list!\n"));
return NULL;
while (pwd != NULL) {
memset(pent, '\0', sizeof(struct sys_pwent));
if (pwd->pw_name) {
- if ((pent->pw_name = strdup(pwd->pw_name)) == NULL)
+ if ((pent->pw_name = SMB_STRDUP(pwd->pw_name)) == NULL)
goto err;
}
if (pwd->pw_passwd) {
- if ((pent->pw_passwd = strdup(pwd->pw_passwd)) == NULL)
+ if ((pent->pw_passwd = SMB_STRDUP(pwd->pw_passwd)) == NULL)
goto err;
}
pent->pw_uid = pwd->pw_uid;
pent->pw_gid = pwd->pw_gid;
if (pwd->pw_gecos) {
- if ((pent->pw_gecos = strdup(pwd->pw_gecos)) == NULL)
+ if ((pent->pw_gecos = SMB_STRDUP(pwd->pw_gecos)) == NULL)
goto err;
}
if (pwd->pw_dir) {
- if ((pent->pw_dir = strdup(pwd->pw_dir)) == NULL)
+ if ((pent->pw_dir = SMB_STRDUP(pwd->pw_dir)) == NULL)
goto err;
}
if (pwd->pw_shell) {
- if ((pent->pw_shell = strdup(pwd->pw_shell)) == NULL)
+ if ((pent->pw_shell = SMB_STRDUP(pwd->pw_shell)) == NULL)
goto err;
}
pwd = getpwent();
if (pwd) {
- pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent));
+ pent->next = SMB_MALLOC_P(struct sys_pwent);
if (pent->next == NULL)
goto err;
pent = pent->next;
;
for (i = 0; i < num_users; i++) {
- struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry));
+ struct sys_userlist *entry = SMB_MALLOC_P(struct sys_userlist);
if (entry == NULL) {
free_userlist(list_head);
return NULL;
}
- entry->unix_name = (char *)strdup(grp->gr_mem[i]);
+ entry->unix_name = (char *)SMB_STRDUP(grp->gr_mem[i]);
if (entry->unix_name == NULL) {
SAFE_FREE(entry);
free_userlist(list_head);
static struct passwd *alloc_copy_passwd(const struct passwd *from)
{
- struct passwd *ret = smb_xmalloc(sizeof(struct passwd));
+ struct passwd *ret = SMB_XMALLOC_P(struct passwd);
ZERO_STRUCTP(ret);
ret->pw_name = smb_xstrdup(from->pw_name);
ret->pw_passwd = smb_xstrdup(from->pw_passwd);
memset((char *)sidout, '\0', sizeof(DOM_SID));
- p = q = strdup(sidstr + 2);
+ p = q = SMB_STRDUP(sidstr + 2);
if (p == NULL) {
DEBUG(0, ("string_to_sid: out of memory!\n"));
return False;
{
char *buf, *s;
int len = sid_size(sid);
- buf = malloc(len);
+ buf = SMB_MALLOC(len);
if (!buf)
return NULL;
sid_linearize(buf, len, sid);
if(!src)
return NULL;
- if((dst = talloc_zero(ctx, sizeof(DOM_SID))) != NULL) {
+ if((dst = TALLOC_ZERO_P(ctx, DOM_SID)) != NULL) {
sid_copy( dst, src);
}
timeout *= 1000; /* convert to microseconds */
- sockets = malloc(num_addrs * sizeof(*sockets));
+ sockets = SMB_MALLOC_ARRAY(int, num_addrs);
if (sockets == NULL)
return False;
*ctok=ictok;
s=(char *)last_ptr;
- if (!(ret=iret=malloc((ictok+1)*sizeof(char *))))
+ if (!(ret=iret=SMB_MALLOC_ARRAY(char *,ictok+1)))
return NULL;
while(ictok--) {
int i;
char *hex_buffer;
- *out_hex_buffer = smb_xmalloc((len*2)+1);
+ *out_hex_buffer = SMB_XMALLOC_ARRAY(char, (len*2)+1);
hex_buffer = *out_hex_buffer;
for (i = 0; i < len; i++)
if (l == 0) {
if (!null_string) {
- if((null_string = (char *)malloc(1)) == NULL) {
+ if((null_string = (char *)SMB_MALLOC(1)) == NULL) {
DEBUG(0,("string_init: malloc fail for null_string.\n"));
return False;
}
}
*dest = null_string;
} else {
- (*dest) = strdup(src);
+ (*dest) = SMB_STRDUP(src);
if ((*dest) == NULL) {
DEBUG(0,("Out of memory in string_init\n"));
return False;
s = string;
- in = strdup(insert);
+ in = SMB_STRDUP(insert);
if (!in) {
DEBUG(0, ("realloc_string_sub: out of memory!\n"));
return NULL;
while ((p = strstr_m(s,pattern))) {
if (ld > 0) {
int offset = PTR_DIFF(s,string);
- char *t = Realloc(string, ls + ld + 1);
+ char *t = SMB_REALLOC(string, ls + ld + 1);
if (!t) {
DEBUG(0, ("realloc_string_sub: out of memory!\n"));
SAFE_FREE(in);
}
}
- r = rp = (smb_ucs2_t *)malloc((lt + 1)*(sizeof(smb_ucs2_t)));
+ r = rp = SMB_MALLOC_ARRAY(smb_ucs2_t, lt + 1);
if (!r) {
DEBUG(0, ("all_string_sub_w: out of memory!\n"));
return NULL;
char *s;
int i, j;
const char *hex = "0123456789ABCDEF";
- s = malloc(len * 3 + 1);
+ s = SMB_MALLOC(len * 3 + 1);
if (!s)
return NULL;
for (j=i=0;i<len;i++) {
char *ret;
n = strnlen(s, n);
- ret = malloc(n+1);
+ ret = SMB_MALLOC(n+1);
if (!ret)
return NULL;
memcpy(ret, s, n);
if (!string || !*string)
return NULL;
- s = strdup(string);
+ s = SMB_STRDUP(string);
if (!s) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
return NULL;
while (next_token(&str, tok, sep, sizeof(tok))) {
if (num == lsize) {
lsize += S_LIST_ABS;
- rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
if (!rlist) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
str_list_free(&list);
memset (&list[num], 0, ((sizeof(char**)) * (S_LIST_ABS +1)));
}
- list[num] = strdup(tok);
+ list[num] = SMB_STRDUP(tok);
if (!list[num]) {
DEBUG(0,("str_list_make: Unable to allocate memory"));
str_list_free(&list);
while (src[num]) {
if (num == lsize) {
lsize += S_LIST_ABS;
- rlist = (char **)Realloc(list, ((sizeof(char **)) * (lsize +1)));
+ rlist = SMB_REALLOC_ARRAY(list, char *, lsize +1);
if (!rlist) {
DEBUG(0,("str_list_copy: Unable to re-allocate memory"));
str_list_free(&list);
memset (&list[num], 0, ((sizeof(char **)) * (S_LIST_ABS +1)));
}
- list[num] = strdup(src[num]);
+ list[num] = SMB_STRDUP(src[num]);
if (!list[num]) {
DEBUG(0,("str_list_copy: Unable to allocate memory"));
str_list_free(&list);
t = *list;
d = p -t;
if (ld) {
- t = (char *) malloc(ls +ld +1);
+ t = (char *) SMB_MALLOC(ls +ld +1);
if (!t) {
DEBUG(0,("str_list_substitute: Unable to allocate memory"));
return False;
return 0;
count = count_chars(ipstr_list, IPSTR_LIST_CHAR) + 1;
- if ( (*ip_list = (struct ip_service*)malloc(count * sizeof(struct ip_service))) == NULL ) {
+ if ( (*ip_list = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
DEBUG(0,("ipstr_list_parse: malloc failed for %lu entries\n", (unsigned long)count));
return 0;
}
size_t out_cnt = 0;
size_t len = data.length;
size_t output_len = data.length * 2;
- char *result = malloc(output_len); /* get us plenty of space */
+ char *result = SMB_MALLOC(output_len); /* get us plenty of space */
while (len-- && out_cnt < (data.length * 2) - 5) {
int c = (unsigned char) *(data.data++);
int new_len = strlen(right) + 1;
if (*left == NULL) {
- *left = malloc(new_len);
+ *left = SMB_MALLOC(new_len);
*left[0] = '\0';
} else {
new_len += strlen(*left);
- *left = Realloc(*left, new_len);
+ *left = SMB_REALLOC(*left, new_len);
}
if (*left == NULL)
not available */
if (!upcase_table) {
DEBUG(1,("creating lame upcase table\n"));
- upcase_table = malloc(0x20000);
+ upcase_table = SMB_MALLOC(0x20000);
for (i=0;i<0x10000;i++) {
smb_ucs2_t v;
SSVAL(&v, 0, i);
if (!lowcase_table) {
DEBUG(1,("creating lame lowcase table\n"));
- lowcase_table = malloc(0x20000);
+ lowcase_table = SMB_MALLOC(0x20000);
for (i=0;i<0x10000;i++) {
smb_ucs2_t v;
SSVAL(&v, 0, i);
if (valid_table) free(valid_table);
DEBUG(2,("creating default valid table\n"));
- valid_table = malloc(0x10000);
+ valid_table = SMB_MALLOC(0x10000);
for (i=0;i<128;i++)
valid_table[i] = isalnum(i) || strchr(allowed,i);
char *s;
int maxlen = (str->uni_str_len+1)*4;
if (!str->buffer) return NULL;
- s = (char *)talloc(ctx, maxlen); /* convervative */
+ s = (char *)TALLOC(ctx, maxlen); /* convervative */
if (!s) return NULL;
pull_ucs2(NULL, s, str->buffer, maxlen, str->uni_str_len*2,
STR_NOALIGN);
smb_ucs2_t *dest;
if (!len) len = strlen_w(src);
- dest = (smb_ucs2_t *)malloc((len + 1) * sizeof(smb_ucs2_t));
+ dest = SMB_MALLOC_ARRAY(smb_ucs2_t, len + 1);
if (!dest) {
DEBUG(0,("strdup_w: out of memory!\n"));
return NULL;
/* allocate UNISTR2 destination if not given */
if (!dst) {
- dst = (UNISTR2*) talloc(ctx, sizeof(UNISTR2));
+ dst = TALLOC_P(ctx, UNISTR2);
if (!dst)
return NULL;
}
if (!dst->buffer) {
- dst->buffer = (uint16*) talloc(ctx, sizeof(uint16) * (len + 1));
+ dst->buffer = TALLOC_ARRAY(ctx, uint16, len + 1);
if (!dst->buffer)
return NULL;
}
{
char *keystr = NULL, *wins_ip_addr = NULL, *src_ip_addr = NULL;
- wins_ip_addr = strdup(inet_ntoa(wins_ip));
- src_ip_addr = strdup(inet_ntoa(src_ip));
+ wins_ip_addr = SMB_STRDUP(inet_ntoa(wins_ip));
+ src_ip_addr = SMB_STRDUP(inet_ntoa(src_ip));
if ( !wins_ip_addr || !src_ip_addr ) {
DEBUG(0,("wins_srv_keystr: malloc error\n"));
if (lp_wins_support()) {
/* give the caller something to chew on. This makes
the rest of the logic simpler (ie. less special cases) */
- ret = (char **)malloc(sizeof(char *)*2);
+ ret = SMB_MALLOC_ARRAY(char *, 2);
if (!ret) return NULL;
- ret[0] = strdup("*");
+ ret[0] = SMB_STRDUP("*");
ret[1] = NULL;
return ret;
}
}
/* add it to the list */
- ret = (char **)Realloc(ret, (count+2) * sizeof(char *));
- ret[count] = strdup(t_ip.tag);
+ ret = SMB_REALLOC_ARRAY(ret, char *, count+2);
+ ret[count] = SMB_STRDUP(t_ip.tag);
if (!ret[count]) break;
count++;
}
{
if (f->buf) return 1;
if (f->bufsize == 0) return 0;
- f->buf = malloc(f->bufsize);
+ f->buf = SMB_MALLOC(f->bufsize);
if (!f->buf) return 0;
f->next = f->buf;
return 1;
{
XFILE *ret;
- ret = (XFILE *)malloc(sizeof(XFILE));
+ ret = SMB_MALLOC_P(XFILE);
if (!ret) return NULL;
memset(ret, 0, sizeof(XFILE));
char *ret;
int len;
- r = strdup(realm);
+ r = SMB_STRDUP(realm);
if (!r || !*r)
return r;
len = (numbits+1)*(strlen(field)+1) + strlen(r) + 1;
- ret = malloc(len);
+ ret = SMB_MALLOC(len);
if (!ret)
return NULL;
{
ADS_STRUCT *ads;
- ads = (ADS_STRUCT *)smb_xmalloc(sizeof(*ads));
+ ads = SMB_XMALLOC_P(ADS_STRUCT);
ZERO_STRUCTP(ads);
- ads->server.realm = realm? strdup(realm) : NULL;
- ads->server.workgroup = workgroup ? strdup(workgroup) : NULL;
- ads->server.ldap_server = ldap_server? strdup(ldap_server) : NULL;
+ ads->server.realm = realm? SMB_STRDUP(realm) : NULL;
+ ads->server.workgroup = workgroup ? SMB_STRDUP(workgroup) : NULL;
+ ads->server.ldap_server = ldap_server? SMB_STRDUP(ldap_server) : NULL;
/* we need to know if this is a foreign realm */
if (realm && *realm && !strequal(lp_realm(), realm)) {
return False;
if (UNMARSHALLING(ps) && type_10->len) {
- type_10->username = (uint16 *) prs_alloc_mem(ps, type_10->len);
+ type_10->username = PRS_ALLOC_MEM(ps, uint16, type_10->len);
if (!type_10->username) {
DEBUG(3, ("No memory available\n"));
return False;
depth++;
if (UNMARSHALLING(ps)) {
- sid_and_attr->sid =
- (DOM_SID2 * ) prs_alloc_mem(ps, sizeof(DOM_SID2));
+ sid_and_attr->sid = PRS_ALLOC_MEM(ps, DOM_SID2, 1);
if (!sid_and_attr->sid) {
DEBUG(3, ("No memory available\n"));
return False;
return False;
if (UNMARSHALLING(ps)) {
- array->krb_sid_and_attrs = (KRB_SID_AND_ATTRS *)
- prs_alloc_mem(ps, sizeof(KRB_SID_AND_ATTRS) * num);
+ array->krb_sid_and_attrs = PRS_ALLOC_MEM(ps, KRB_SID_AND_ATTRS, num);
if (!array->krb_sid_and_attrs) {
DEBUG(3, ("No memory available\n"));
return False;
return False;
if (UNMARSHALLING(ps)) {
- array->group_membership = (GROUP_MEMBERSHIP *)
- prs_alloc_mem(ps, sizeof(GROUP_MEMBERSHIP) * num);
+ array->group_membership = PRS_ALLOC_MEM(ps, GROUP_MEMBERSHIP, num);
if (!array->group_membership) {
DEBUG(3, ("No memory available\n"));
return False;
if (!prs_uint32("type", ps, depth, &data->type))
return False;
if (UNMARSHALLING(ps)) {
- data->signature = (unsigned char *)prs_alloc_mem(ps, siglen);
+ data->signature = PRS_ALLOC_MEM(ps, unsigned char, siglen);
if (!data->signature) {
DEBUG(3, ("No memory available\n"));
return False;
}
if (UNMARSHALLING(ps) && hdr->size > 0) {
- hdr->ctr = (PAC_INFO_CTR *)
- prs_alloc_mem(ps, sizeof(PAC_INFO_CTR));
+ hdr->ctr = PRS_ALLOC_MEM(ps, PAC_INFO_CTR, 1);
if (!hdr->ctr) {
DEBUG(3, ("No memory available\n"));
return False;
case PAC_TYPE_LOGON_INFO:
DEBUG(5, ("PAC_TYPE_LOGON_INFO\n"));
if (UNMARSHALLING(ps))
- hdr->ctr->pac.logon_info = (PAC_LOGON_INFO *)
- prs_alloc_mem(ps, sizeof(PAC_LOGON_INFO));
+ hdr->ctr->pac.logon_info = PRS_ALLOC_MEM(ps, PAC_LOGON_INFO, 1);
if (!hdr->ctr->pac.logon_info) {
DEBUG(3, ("No memory available\n"));
return False;
case PAC_TYPE_SERVER_CHECKSUM:
DEBUG(5, ("PAC_TYPE_SERVER_CHECKSUM\n"));
if (UNMARSHALLING(ps))
- hdr->ctr->pac.srv_cksum = (PAC_SIGNATURE_DATA *)
- prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA));
+ hdr->ctr->pac.srv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1);
if (!hdr->ctr->pac.srv_cksum) {
DEBUG(3, ("No memory available\n"));
return False;
case PAC_TYPE_PRIVSVR_CHECKSUM:
DEBUG(5, ("PAC_TYPE_PRIVSVR_CHECKSUM\n"));
if (UNMARSHALLING(ps))
- hdr->ctr->pac.privsrv_cksum = (PAC_SIGNATURE_DATA *)
- prs_alloc_mem(ps, sizeof(PAC_SIGNATURE_DATA));
+ hdr->ctr->pac.privsrv_cksum = PRS_ALLOC_MEM(ps, PAC_SIGNATURE_DATA, 1);
if (!hdr->ctr->pac.privsrv_cksum) {
DEBUG(3, ("No memory available\n"));
return False;
case PAC_TYPE_UNKNOWN_10:
DEBUG(5, ("PAC_TYPE_UNKNOWN_10\n"));
if (UNMARSHALLING(ps))
- hdr->ctr->pac.type_10 = (UNKNOWN_TYPE_10 *)
- prs_alloc_mem(ps, sizeof(UNKNOWN_TYPE_10));
+ hdr->ctr->pac.type_10 = PRS_ALLOC_MEM(ps, UNKNOWN_TYPE_10, 1);
if (!hdr->ctr->pac.type_10) {
DEBUG(3, ("No memory available\n"));
return False;
return False;
if (UNMARSHALLING(ps) && data->num_buffers > 0) {
- if ((data->pac_info_hdr_ptr = (PAC_INFO_HDR *)
- prs_alloc_mem(ps, sizeof(PAC_INFO_HDR) *
- data->num_buffers)) == NULL) {
+ if ((data->pac_info_hdr_ptr = PRS_ALLOC_MEM(ps, PAC_INFO_HDR, data->num_buffers)) == NULL) {
return False;
}
}
data_blob_free(&pac_data_blob);
- pac_data = (PAC_DATA *) talloc_zero(ctx, sizeof(PAC_DATA));
+ pac_data = TALLOC_ZERO_P(ctx, PAC_DATA);
pac_io_pac_data("pac data", pac_data, &ps, 0);
prs_mem_free(&ps);
if (!found) {
goto done;
}
- oldEntries = (char **) malloc(found * sizeof(char *));
+ oldEntries = SMB_MALLOC_ARRAY(char *, found );
if (!oldEntries) {
DEBUG(1,("ads_keytab_create_default: Failed to allocate space to store the old keytab entries (malloc failed?).\n"));
ret = -1;
for (i=0;enctypes[i];i++) {
krb5_keyblock *key = NULL;
- if (!(key = (krb5_keyblock *)malloc(sizeof(*key)))) {
+ if (!(key = SMB_MALLOC_P(krb5_keyblock))) {
goto out;
}
DATA_BLOB ret;
- princ = strdup(principal);
+ princ = SMB_STRDUP(principal);
if ((c = strchr_m(princ, '/')) == NULL) {
c = princ;
return ret;
}
- packet->data = (char *)malloc(ap_req->length + cipherpw.length + 6);
+ packet->data = (char *)SMB_MALLOC(ap_req->length + cipherpw.length + 6);
if (!packet->data)
return -1;
free(chpw_req.data);
chpw_rep.length = 1500;
- chpw_rep.data = (char *) malloc(chpw_rep.length);
+ chpw_rep.data = (char *) SMB_MALLOC(chpw_rep.length);
if (!chpw_rep.data) {
close(sock);
free(ap_req.data);
/* We have to obtain an INITIAL changepw ticket for changing password */
asprintf(&chpw_princ, "kadmin/changepw@%s",
(char *) krb5_princ_realm(context, princ));
- password = strdup(oldpw);
+ password = SMB_STRDUP(oldpw);
ret = krb5_get_init_creds_password(context, &creds, princ, password,
kerb_prompter, NULL,
0, chpw_princ, &opts);
DEBUG(5,("ads_try_connect: trying ldap server '%s' port %u\n", server, port));
/* this copes with inet_ntoa brokenness */
- srv = strdup(server);
+ srv = SMB_STRDUP(server);
ads->ld = ldap_open_with_timeout(srv, port, lp_ldap_timeout());
if (!ads->ld) {
}
if (!ads->auth.realm) {
- ads->auth.realm = strdup(ads->config.realm);
+ ads->auth.realm = SMB_STRDUP(ads->config.realm);
}
if (!ads->auth.kdc_server) {
- ads->auth.kdc_server = strdup(inet_ntoa(ads->ldap_ip));
+ ads->auth.kdc_server = SMB_STRDUP(inet_ntoa(ads->ldap_ip));
}
#if KRB5_DNS_HACK
if (!in_val) return NULL;
- value = talloc_zero(ctx, sizeof(struct berval));
+ value = TALLOC_ZERO_P(ctx, struct berval);
if (value == NULL)
return NULL;
if (in_val->bv_len == 0) return value;
value->bv_len = in_val->bv_len;
- value->bv_val = talloc_memdup(ctx, in_val->bv_val, in_val->bv_len);
+ value->bv_val = TALLOC_MEMDUP(ctx, in_val->bv_val, in_val->bv_len);
return value;
}
int i;
if (!in_vals) return NULL;
- for (i=0; in_vals[i]; i++); /* count values */
- values = (struct berval **) talloc_zero(ctx,
- (i+1)*sizeof(struct berval *));
+ for (i=0; in_vals[i]; i++)
+ ; /* count values */
+ values = TALLOC_ZERO_ARRAY(ctx, struct berval *, i+1);
if (!values) return NULL;
for (i=0; in_vals[i]; i++) {
int i;
if (!in_vals) return NULL;
- for (i=0; in_vals[i]; i++); /* count values */
- values = (char ** ) talloc_zero(ctx, (i+1)*sizeof(char *));
+ for (i=0; in_vals[i]; i++)
+ ; /* count values */
+ values = TALLOC_ZERO_ARRAY(ctx, char *, i+1);
if (!values) return NULL;
for (i=0; in_vals[i]; i++) {
int i;
if (!in_vals) return NULL;
- for (i=0; in_vals[i]; i++); /* count values */
- values = (char **) talloc_zero(ctx, (i+1)*sizeof(char *));
+ for (i=0; in_vals[i]; i++)
+ ; /* count values */
+ values = TALLOC_ZERO_ARRAY(ctx, char *, i+1);
if (!values) return NULL;
for (i=0; in_vals[i]; i++) {
#define ADS_MODLIST_ALLOC_SIZE 10
LDAPMod **mods;
- if ((mods = (LDAPMod **) talloc_zero(ctx, sizeof(LDAPMod *) *
- (ADS_MODLIST_ALLOC_SIZE + 1))))
+ if ((mods = TALLOC_ZERO_ARRAY(ctx, LDAPMod *, ADS_MODLIST_ALLOC_SIZE + 1)))
/* -1 is safety to make sure we don't go over the end.
need to reset it to NULL before doing ldap modify */
mods[ADS_MODLIST_ALLOC_SIZE] = (LDAPMod *) -1;
for (curmod=0; modlist[curmod] && modlist[curmod] != (LDAPMod *) -1;
curmod++);
if (modlist[curmod] == (LDAPMod *) -1) {
- if (!(modlist = talloc_realloc(ctx, modlist,
- (curmod+ADS_MODLIST_ALLOC_SIZE+1)*sizeof(LDAPMod *))))
+ if (!(modlist = TALLOC_REALLOC_ARRAY(ctx, modlist, LDAPMod *,
+ curmod+ADS_MODLIST_ALLOC_SIZE+1)))
return ADS_ERROR(LDAP_NO_MEMORY);
memset(&modlist[curmod], 0,
ADS_MODLIST_ALLOC_SIZE*sizeof(LDAPMod *));
*mods = modlist;
}
- if (!(modlist[curmod] = talloc_zero(ctx, sizeof(LDAPMod))))
+ if (!(modlist[curmod] = TALLOC_ZERO_P(ctx, LDAPMod)))
return ADS_ERROR(LDAP_NO_MEMORY);
modlist[curmod]->mod_type = talloc_strdup(ctx, name);
if (mod_op & LDAP_MOD_BVALUES) {
ret = ads_default_ou_string(ads, WELL_KNOWN_GUID_COMPUTERS);
/* samba4 might not yet respond to a wellknownobject-query */
- return ret ? ret : strdup("cn=Computers");
+ return ret ? ret : SMB_STRDUP("cn=Computers");
}
if (strequal(org_unit, "Computers")) {
- return strdup("cn=Computers");
+ return SMB_STRDUP("cn=Computers");
}
return ads_build_path(org_unit, "\\/", "ou=", 1);
for (i=1; i < new_ln; i++) {
char *s;
asprintf(&s, "%s,%s", ret, wkn_dn_exp[i]);
- ret = strdup(s);
+ ret = SMB_STRDUP(s);
free(s);
}
char *machine;
/* machine name must be lowercase */
- machine = strdup(machine_name);
+ machine = SMB_STRDUP(machine_name);
strlower_m(machine);
/*
int rc;
/* hostname must be lowercase */
- host = strdup(hostname);
+ host = SMB_STRDUP(hostname);
strlower_m(host);
status = ads_find_machine_acct(ads, &res, host);
if (!(mods = ads_init_mods(ctx))) return ADS_ERROR(LDAP_NO_MEMORY);
bval.bv_len = prs_offset(&ps_wire);
- bval.bv_val = talloc(ctx, bval.bv_len);
+ bval.bv_val = TALLOC(ctx, bval.bv_len);
if (!bval.bv_val) {
ret = ADS_ERROR(LDAP_NO_MEMORY);
goto ads_set_sd_error;
*num_values = ldap_count_values(values);
- ret = talloc(mem_ctx, sizeof(char *) * (*num_values+1));
+ ret = TALLOC_ARRAY(mem_ctx, char *, *num_values + 1);
if (!ret) {
ldap_value_free(values);
return NULL;
return NULL;
}
- strings = talloc_realloc(mem_ctx, current_strings,
- sizeof(*current_strings) *
- (*num_strings + num_new_strings));
+ strings = TALLOC_REALLOC_ARRAY(mem_ctx, current_strings, char *,
+ *num_strings + num_new_strings);
if (strings == NULL) {
ldap_memfree(range_attr);
for (i=0; values[i]; i++)
/* nop */ ;
- (*sids) = talloc(mem_ctx, sizeof(DOM_SID) * i);
+ (*sids) = TALLOC_ARRAY(mem_ctx, DOM_SID, i);
if (!(*sids)) {
ldap_value_free_len(values);
return 0;
SAFE_FREE(ads->config.ldap_server_name);
- ads->config.ldap_server_name = strdup(p+1);
+ ads->config.ldap_server_name = SMB_STRDUP(p+1);
p = strchr(ads->config.ldap_server_name, '$');
if (!p || p[1] != '@') {
talloc_destroy(ctx);
SAFE_FREE(ads->config.realm);
SAFE_FREE(ads->config.bind_path);
- ads->config.realm = strdup(p+2);
+ ads->config.realm = SMB_STRDUP(p+2);
ads->config.bind_path = ads_build_dn(ads->config.realm);
DEBUG(3,("got ldap server name %s@%s, using bind path: %s\n",
};
if (num_vals) {
- str_values = talloc(ctx,
- (num_vals + 1) * sizeof(smb_ucs2_t *));
+ str_values = TALLOC_ARRAY(ctx, char *, num_vals + 1);
memset(str_values, '\0',
- (num_vals + 1) * sizeof(smb_ucs2_t *));
+ (num_vals + 1) * sizeof(char *));
cur_str = (smb_ucs2_t *) value->data_p;
for (i=0; i < num_vals; i++)
return ADS_ERROR(LDAP_SERVER_DOWN);
}
- bp = strdup(bind_path);
+ bp = SMB_STRDUP(bind_path);
if (!bp) {
return ADS_ERROR_NT(NT_STATUS_NO_MEMORY);
gss_release_buffer(&minor_status, &output_token);
- output_token.value = malloc(strlen(ads->config.bind_path) + 8);
+ output_token.value = SMB_MALLOC(strlen(ads->config.bind_path) + 8);
p = output_token.value;
*p++ = 1; /* no sign & seal selection */
if (data->has_error) return False;
if (data->length < data->ofs+len) {
uint8 *newp;
- newp = Realloc(data->data, data->ofs+len);
+ newp = SMB_REALLOC(data->data, data->ofs+len);
if (!newp) {
SAFE_FREE(data->data);
data->has_error = True;
struct nesting *nesting;
asn1_write_uint8(data, tag);
- nesting = (struct nesting *)malloc(sizeof(struct nesting));
+ nesting = SMB_MALLOC_P(struct nesting);
if (!nesting) {
data->has_error = True;
return False;
data->has_error = True;
return False;
}
- nesting = (struct nesting *)malloc(sizeof(struct nesting));
+ nesting = SMB_MALLOC_P(struct nesting);
if (!nesting) {
data->has_error = True;
return False;
asn1_end_tag(data);
- *OID = strdup(oid_str);
+ *OID = SMB_STRDUP(oid_str);
return !data->has_error;
}
data->has_error = True;
return False;
}
- *s = malloc(len+1);
+ *s = SMB_MALLOC(len+1);
if (! *s) {
data->has_error = True;
return False;
}
if (!cli) {
- cli = (struct cli_state *)malloc(sizeof(*cli));
+ cli = SMB_MALLOC_P(struct cli_state);
if (!cli)
return NULL;
ZERO_STRUCTP(cli);
cli->timeout = 20000; /* Timeout is in milliseconds. */
cli->bufsize = CLI_BUFFER_SIZE+4;
cli->max_xmit = cli->bufsize;
- cli->outbuf = (char *)malloc(cli->bufsize+SAFETY_MARGIN);
- cli->inbuf = (char *)malloc(cli->bufsize+SAFETY_MARGIN);
+ cli->outbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN);
+ cli->inbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN);
cli->oplock_handler = cli_oplock_ack;
cli->case_sensitive = False;
pstring path2;
clistr_pull(cli, path2, p,
sizeof(path2), len, STR_ASCII);
- *tmp_path = strdup(path2);
+ *tmp_path = SMB_STRDUP(path2);
}
return SVAL(cli->inbuf,smb_vwv0);
size_t ea_namelen = strlen(ea_name);
data_len = 4 + 4 + ea_namelen + 1 + ea_len;
- data = malloc(data_len);
+ data = SMB_MALLOC(data_len);
if (!data) {
return False;
}
goto out;
}
- ea_list = (struct ea_struct *)talloc(ctx, num_eas*sizeof(struct ea_struct));
+ ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
if (!ea_list) {
goto out;
}
}
/* and add them to the dirlist pool */
- tdl = Realloc(dirlist,dirlist_len + data_len);
+ tdl = SMB_REALLOC(dirlist,dirlist_len + data_len);
if (!tdl) {
DEBUG(0,("cli_list_new: Failed to expand dirlist\n"));
first = False;
- tdl = Realloc(dirlist,(num_received + received)*DIR_STRUCT_SIZE);
+ tdl = SMB_REALLOC(dirlist,(num_received + received)*DIR_STRUCT_SIZE);
if (!tdl) {
DEBUG(0,("cli_list_old: failed to expand dirlist"));
goto cleanup;
}
- if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) {
+ if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
return (-1);
}
- if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) {
+ if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
return (-1);
}
goto cleanup;
}
- if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) {
+ if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
talloc_destroy(mem_ctx);
goto cleanup;
}
- if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) {
+ if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
talloc_destroy(mem_ctx);
goto cleanup;
BOOL bigoffset = False;
if (size > cli->bufsize) {
- cli->outbuf = realloc(cli->outbuf, size + 1024);
- cli->inbuf = realloc(cli->inbuf, size + 1024);
+ cli->outbuf = SMB_REALLOC(cli->outbuf, size + 1024);
+ cli->inbuf = SMB_REALLOC(cli->inbuf, size + 1024);
if (cli->outbuf == NULL || cli->inbuf == NULL)
return False;
cli->bufsize = size + 1024;
/* allocate it */
if (total_data!=0) {
- tdata = Realloc(*data,total_data);
+ tdata = SMB_REALLOC(*data,total_data);
if (!tdata) {
DEBUG(0,("cli_receive_trans: failed to enlarge data buffer\n"));
cli_signing_trans_stop(cli);
}
if (total_param!=0) {
- tparam = Realloc(*param,total_param);
+ tparam = SMB_REALLOC(*param,total_param);
if (!tparam) {
DEBUG(0,("cli_receive_trans: failed to enlarge param buffer\n"));
cli_signing_trans_stop(cli);
/* allocate it */
if (total_data) {
- tdata = Realloc(*data,total_data);
+ tdata = SMB_REALLOC(*data,total_data);
if (!tdata) {
DEBUG(0,("cli_receive_nt_trans: failed to enlarge data buffer to %d\n",total_data));
cli_signing_trans_stop(cli);
}
if (total_param) {
- tparam = Realloc(*param,total_param);
+ tparam = SMB_REALLOC(*param,total_param);
if (!tparam) {
DEBUG(0,("cli_receive_nt_trans: failed to enlarge param buffer to %d\n", total_param));
cli_signing_trans_stop(cli);
/* Create negative lookup cache entry for this domain and controller */
- if ( !(fcc = (struct failed_connection_cache *)malloc(sizeof(struct failed_connection_cache))) )
- {
+ if ( !(fcc = SMB_MALLOC_P(struct failed_connection_cache)) ) {
DEBUG(0, ("malloc failed in add_failed_connection_entry!\n"));
return;
}
{
struct smbc_server_cache * srvcache = NULL;
- if (!(srvcache = malloc(sizeof(*srvcache)))) {
+ if (!(srvcache = SMB_MALLOC_P(struct smbc_server_cache))) {
errno = ENOMEM;
DEBUG(3, ("Not enough space for server cache allocation\n"));
return 1;
srvcache->server = new;
- srvcache->server_name = strdup(server);
+ srvcache->server_name = SMB_STRDUP(server);
if (!srvcache->server_name) {
errno = ENOMEM;
goto failed;
}
- srvcache->share_name = strdup(share);
+ srvcache->share_name = SMB_STRDUP(share);
if (!srvcache->share_name) {
errno = ENOMEM;
goto failed;
}
- srvcache->workgroup = strdup(workgroup);
+ srvcache->workgroup = SMB_STRDUP(workgroup);
if (!srvcache->workgroup) {
errno = ENOMEM;
goto failed;
}
- srvcache->username = strdup(username);
+ srvcache->username = SMB_STRDUP(username);
if (!srvcache->username) {
errno = ENOMEM;
goto failed;
return -1;
}
- f = malloc(sizeof(struct smbc_compat_fdlist));
+ f = SMB_MALLOC_P(struct smbc_compat_fdlist);
if (!f) {
errno = ENOMEM;
return -1;
}
/* make a copy of the old one */
- new_usegment = (char*)malloc( old_length * 3 + 1 );
+ new_usegment = (char*)SMB_MALLOC( old_length * 3 + 1 );
while( i < old_length ) {
int bReencode = False;
* Let's find a free server_fd
*/
- srv = (SMBCSRV *)malloc(sizeof(*srv));
+ srv = SMB_MALLOC_P(SMBCSRV);
if (!srv) {
errno = ENOMEM;
goto failed;
return NULL;
}
- ipc_srv = (SMBCSRV *)malloc(sizeof(*ipc_srv));
+ ipc_srv = SMB_MALLOC_P(SMBCSRV);
if (!ipc_srv) {
errno = ENOMEM;
cli_shutdown(ipc_cli);
}
else {
- file = malloc(sizeof(SMBCFILE));
+ file = SMB_MALLOC_P(SMBCFILE);
if (!file) {
/* Fill in file struct */
file->cli_fd = fd;
- file->fname = strdup(fname);
+ file->fname = SMB_STRDUP(fname);
file->srv = srv;
file->offset = 0;
file->file = True;
size = sizeof(struct smbc_dirent) + u_name_len + u_comment_len + 1;
- dirent = malloc(size);
+ dirent = SMB_MALLOC(size);
if (!dirent) {
if (dir->dir_list == NULL) {
- dir->dir_list = malloc(sizeof(struct smbc_dir_list));
+ dir->dir_list = SMB_MALLOC_P(struct smbc_dir_list);
if (!dir->dir_list) {
SAFE_FREE(dirent);
}
else {
- dir->dir_end->next = malloc(sizeof(struct smbc_dir_list));
+ dir->dir_end->next = SMB_MALLOC_P(struct smbc_dir_list);
if (!dir->dir_end->next) {
pstrcpy(workgroup, context->workgroup);
- dir = malloc(sizeof(*dir));
+ dir = SMB_MALLOC_P(SMBCFILE);
if (!dir) {
ZERO_STRUCTP(dir);
dir->cli_fd = 0;
- dir->fname = strdup(fname);
+ dir->fname = SMB_STRDUP(fname);
dir->srv = NULL;
dir->offset = 0;
dir->file = False;
return True;
}
- aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE));
+ aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
}
if (StrnCaseCmp(tok,"OWNER:", 6) == 0) {
- owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!owner_sid ||
!convert_string_to_sid(ipc_cli, pol,
numeric,
}
if (StrnCaseCmp(tok,"OWNER+:", 7) == 0) {
- owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!owner_sid ||
!convert_string_to_sid(ipc_cli, pol,
False,
}
if (StrnCaseCmp(tok,"GROUP:", 6) == 0) {
- grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!grp_sid ||
!convert_string_to_sid(ipc_cli, pol,
numeric,
}
if (StrnCaseCmp(tok,"GROUP+:", 7) == 0) {
- grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!grp_sid ||
!convert_string_to_sid(ipc_cli, pol,
False,
{
SMBCCTX * context;
- context = malloc(sizeof(SMBCCTX));
+ context = SMB_MALLOC_P(SMBCCTX);
if (!context) {
errno = ENOMEM;
return NULL;
ZERO_STRUCTP(context);
- context->internal = malloc(sizeof(struct smbc_internal_data));
+ context->internal = SMB_MALLOC_P(struct smbc_internal_data);
if (!context->internal) {
errno = ENOMEM;
return NULL;
*/
user = getenv("USER");
/* walk around as "guest" if no username can be found */
- if (!user) context->user = strdup("guest");
- else context->user = strdup(user);
+ if (!user) context->user = SMB_STRDUP("guest");
+ else context->user = SMB_STRDUP(user);
}
if (!context->netbios_name) {
* back on constructing our netbios name from our hostname etc
*/
if (global_myname()) {
- context->netbios_name = strdup(global_myname());
+ context->netbios_name = SMB_STRDUP(global_myname());
}
else {
/*
* Hmmm, I want to get hostname as well, but I am too lazy for the moment
*/
pid = sys_getpid();
- context->netbios_name = malloc(17);
+ context->netbios_name = SMB_MALLOC(17);
if (!context->netbios_name) {
errno = ENOMEM;
return NULL;
if (!context->workgroup) {
if (lp_workgroup()) {
- context->workgroup = strdup(lp_workgroup());
+ context->workgroup = SMB_STRDUP(lp_workgroup());
}
else {
/* TODO: Think about a decent default workgroup */
- context->workgroup = strdup("samba");
+ context->workgroup = SMB_STRDUP("samba");
}
}
if (*num_names == 0)
return NULL;
- ret = (struct node_status *)malloc(sizeof(struct node_status)* (*num_names));
+ ret = SMB_MALLOC_ARRAY(struct node_status,*num_names);
if (!ret)
return NULL;
continue;
}
- tmp_ip_list = (struct in_addr *)Realloc( ip_list, sizeof( ip_list[0] )
- * ( (*count) + nmb2->answers->rdlength/6 ) );
+ tmp_ip_list = SMB_REALLOC_ARRAY( ip_list, struct in_addr,
+ (*count) + nmb2->answers->rdlength/6 );
if (!tmp_ip_list) {
DEBUG(0,("name_query: Realloc failed.\n"));
return False;
/* copy the ip address; port will be PORT_NONE */
- if ( (*return_iplist = (struct ip_service*)malloc(count*sizeof(struct ip_service))) == NULL ) {
+ if ( (*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
DEBUG(0,("convert_ip2service: malloc failed for %d enetries!\n", count ));
return False;
}
if ((name_type2 != -1) && (name_type != name_type2))
continue;
- *return_iplist = (struct ip_service *)realloc((*return_iplist),
- sizeof(struct ip_service) * ((*return_count)+1));
+ *return_iplist = SMB_REALLOC_ARRAY((*return_iplist), struct ip_service,
+ (*return_count)+1);
if ((*return_iplist) == NULL) {
DEBUG(3,("resolve_lmhosts: malloc fail !\n"));
if (((hp = sys_gethostbyname(name)) != NULL) && (hp->h_addr != NULL)) {
struct in_addr return_ip;
putip((char *)&return_ip,(char *)hp->h_addr);
- *return_iplist = (struct ip_service *)malloc(sizeof(struct ip_service));
+ *return_iplist = SMB_MALLOC_P(struct ip_service);
if(*return_iplist == NULL) {
DEBUG(3,("resolve_hosts: malloc fail !\n"));
return False;
return False;
count = count_chars(list, ' ') + 1;
- if ( (*return_iplist = malloc(count * sizeof(struct ip_service))) == NULL ) {
+ if ( (*return_iplist = SMB_MALLOC_ARRAY(struct ip_service, count)) == NULL ) {
DEBUG(0,("resolve_hosts: malloc failed for %d entries\n", count ));
return False;
}
if (allzeros || allones || is_address) {
- if ( (*return_iplist = (struct ip_service *)malloc(sizeof(struct ip_service))) == NULL ) {
+ if ( (*return_iplist = SMB_MALLOC_P(struct ip_service)) == NULL ) {
DEBUG(0,("internal_resolve_name: malloc fail !\n"));
return False;
}
return False;
}
- if ( (return_iplist = (struct ip_service *)
- malloc(num_addresses * sizeof(struct ip_service))) == NULL ) {
+ if ( (return_iplist = SMB_MALLOC_ARRAY(struct ip_service, num_addresses)) == NULL ) {
DEBUG(3,("get_dc_list: malloc fail !\n"));
return False;
}
{
int i;
- *recs = (struct res_rec *)malloc(sizeof(**recs)*count);
+ *recs = SMB_MALLOC_ARRAY(struct res_rec, count);
if (!*recs)
return(False);
struct nmb_packet *copy_nmb;
struct packet_struct *pkt_copy;
- if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) {
+ if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL) {
DEBUG(0,("copy_nmb_packet: malloc fail.\n"));
return NULL;
}
/* Now copy any resource records. */
if (nmb->answers) {
- if((copy_nmb->answers = (struct res_rec *)
- malloc(nmb->header.ancount * sizeof(struct res_rec))) == NULL)
+ if((copy_nmb->answers = SMB_MALLOC_ARRAY(struct res_rec,nmb->header.ancount)) == NULL)
goto free_and_exit;
memcpy((char *)copy_nmb->answers, (char *)nmb->answers,
nmb->header.ancount * sizeof(struct res_rec));
}
if (nmb->nsrecs) {
- if((copy_nmb->nsrecs = (struct res_rec *)
- malloc(nmb->header.nscount * sizeof(struct res_rec))) == NULL)
+ if((copy_nmb->nsrecs = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.nscount)) == NULL)
goto free_and_exit;
memcpy((char *)copy_nmb->nsrecs, (char *)nmb->nsrecs,
nmb->header.nscount * sizeof(struct res_rec));
}
if (nmb->additional) {
- if((copy_nmb->additional = (struct res_rec *)
- malloc(nmb->header.arcount * sizeof(struct res_rec))) == NULL)
+ if((copy_nmb->additional = SMB_MALLOC_ARRAY(struct res_rec, nmb->header.arcount)) == NULL)
goto free_and_exit;
memcpy((char *)copy_nmb->additional, (char *)nmb->additional,
nmb->header.arcount * sizeof(struct res_rec));
{
struct packet_struct *pkt_copy;
- if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) {
+ if(( pkt_copy = SMB_MALLOC_P(struct packet_struct)) == NULL) {
DEBUG(0,("copy_dgram_packet: malloc fail.\n"));
return NULL;
}
struct packet_struct *p;
BOOL ok=False;
- p = (struct packet_struct *)malloc(sizeof(*p));
+ p = SMB_MALLOC_P(struct packet_struct);
if (!p)
return(NULL);
mem_ctx = talloc_init("NTLMSSP context");
- *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state));
+ *ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE);
if (!*ntlmssp_state) {
DEBUG(0,("ntlmssp_server_start: talloc failed!\n"));
talloc_destroy(mem_ctx);
mem_ctx = talloc_init("NTLMSSP Client context");
- *ntlmssp_state = talloc_zero(mem_ctx, sizeof(**ntlmssp_state));
+ *ntlmssp_state = TALLOC_ZERO_P(mem_ctx, NTLMSSP_STATE);
if (!*ntlmssp_state) {
DEBUG(0,("ntlmssp_client_start: talloc failed!\n"));
talloc_destroy(mem_ctx);
if ( data.dptr ) {
- if ( (user = (NET_USER_INFO_3*)malloc(sizeof(NET_USER_INFO_3))) == NULL )
+ if ( (user = SMB_MALLOC_P(NET_USER_INFO_3)) == NULL )
return NULL;
prs_init( &ps, 0, mem_ctx, UNMARSHALL );
}
}
- t = smb_xmalloc(sizeof(*t));
+ t = SMB_XMALLOC_P(struct outstanding_packet_lookup);
ZERO_STRUCTP(t);
t->mid = mid;
return False;
}
- data = smb_xmalloc(sizeof(*data));
+ data = SMB_XMALLOC_P(struct smb_basic_signing_context);
memset(data, '\0', sizeof(*data));
cli->sign_info.signing_context = data;
if (!cli->sign_info.doing_signing || !data)
return;
- data->trans_info = smb_xmalloc(sizeof(struct trans_info_context));
+ data->trans_info = SMB_XMALLOC_P(struct trans_info_context);
ZERO_STRUCTP(data->trans_info);
/* This ensures the sequence is pulled off the outstanding packet list */
if (!data)
return;
- data->trans_info = smb_xmalloc(sizeof(struct trans_info_context));
+ data->trans_info = SMB_XMALLOC_P(struct trans_info_context);
ZERO_STRUCTP(data->trans_info);
data->trans_info->reply_seq_num = data->send_seq_num-1;
srv_sign_info.doing_signing = True;
- data = smb_xmalloc(sizeof(*data));
+ data = SMB_XMALLOC_P(struct smb_basic_signing_context);
memset(data, '\0', sizeof(*data));
srv_sign_info.signing_context = data;
asn1_start_tag(asn1, ASN1_CONTEXT(0));
asn1_start_tag(asn1, ASN1_SEQUENCE(0));
- token->mechTypes = malloc(sizeof(*token->mechTypes));
+ token->mechTypes = SMB_MALLOC_P(char *);
for (i = 0; !asn1->has_error &&
0 < asn1_tag_remaining(asn1); i++) {
token->mechTypes =
- realloc(token->mechTypes, (i + 2) *
- sizeof(*token->mechTypes));
+ SMB_REALLOC_ARRAY(token->mechTypes, char *, i + 2);
asn1_read_OID(asn1, token->mechTypes + i);
}
token->mechTypes[i] = NULL;
}
/* no conflicts - add it to the list of locks */
- tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks));
+ tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(*locks));
if (!tp) {
status = NT_STATUS_NO_MEMORY;
goto fail;
pstrcat(fname, fsp->fsp_name);
size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1;
- p = (char *)malloc(size);
+ p = (char *)SMB_MALLOC(size);
if (!p)
return False;
data = (struct locking_data *)p;
fsp->fsp_name, data->u.num_share_mode_entries ));
size = dbuf.dsize + sizeof(share_mode_entry);
- p = malloc(size);
+ p = SMB_MALLOC(size);
if (!p) {
SAFE_FREE(dbuf.dptr);
return False;
/* we'll need to create a new record */
size = sizeof(*data) + sizeof(deferred_open_entry) + strlen(fname) + 1;
- p = (char *)malloc(size);
+ p = (char *)SMB_MALLOC(size);
if (!p)
return False;
data = (struct deferred_open_data *)p;
fname, data->u.num_deferred_open_entries ));
size = dbuf.dsize + sizeof(deferred_open_entry);
- p = malloc(size);
+ p = SMB_MALLOC(size);
if (!p) {
SAFE_FREE(dbuf.dptr);
return False;
dbuf = tdb_fetch(posix_pending_close_tdb, kbuf);
- tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(int));
+ tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(int));
if (!tp) {
DEBUG(0,("add_fd_to_close_entry: Realloc fail !\n"));
SAFE_FREE(dbuf.dptr);
pl.size = size;
pl.lock_type = lock_type;
- tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(pl));
+ tp = SMB_REALLOC(dbuf.dptr, dbuf.dsize + sizeof(pl));
if (!tp) {
DEBUG(0,("add_posix_lock_entry: Realloc fail !\n"));
goto fail;
| l_curr| | l_new |
+-------+ +---------+
**********************************************/
- struct lock_list *l_new = (struct lock_list *)talloc(ctx,
- sizeof(struct lock_list));
+ struct lock_list *l_new = TALLOC_P(ctx, struct lock_list);
if(l_new == NULL) {
DEBUG(0,("posix_lock_list: talloc fail.\n"));
return True; /* Not a fatal error. */
}
- if ((ll = (struct lock_list *)talloc(l_ctx, sizeof(struct lock_list))) == NULL) {
+ if ((ll = TALLOC_P(l_ctx, struct lock_list)) == NULL) {
DEBUG(0,("set_posix_lock: unable to talloc unlock list.\n"));
talloc_destroy(l_ctx);
return True; /* Not a fatal error. */
return True; /* Not a fatal error. */
}
- if ((ul = (struct lock_list *)talloc(ul_ctx, sizeof(struct lock_list))) == NULL) {
+ if ((ul = TALLOC_P(ul_ctx, struct lock_list)) == NULL) {
DEBUG(0,("release_posix_lock: unable to talloc unlock list.\n"));
talloc_destroy(ul_ctx);
return True; /* Not a fatal error. */
}
}
- if (!(new_list = calloc(1,
- (count == 0 ? 1 : count + 1) * sizeof(name_compare_entry))))
+ if (!(new_list = SMB_CALLOC_ARRAY(name_compare_entry, (count == 0 ? 1 : count + 1))))
return;
for (i = 0; i < count; i ++) {
- new_list[i].name = strdup(cur_list[i].name);
+ new_list[i].name = SMB_STRDUP(cur_list[i].name);
new_list[i].is_wild = cur_list[i].is_wild;
}
- new_list[i].name = strdup(APPLEDOUBLE);
+ new_list[i].name = SMB_STRDUP(APPLEDOUBLE);
new_list[i].is_wild = False;
free_namearray(*list);
mode = S_IRUSR | S_IWUSR | S_IXUSR;
- tmp_str = strdup(dname);
+ tmp_str = SMB_STRDUP(dname);
ALLOC_CHECK(tmp_str, done);
tok_str = tmp_str;
len = strlen(dname)+1;
- new_dir = (char *)malloc(len + 1);
+ new_dir = (char *)SMB_MALLOC(len + 1);
ALLOC_CHECK(new_dir, done);
*new_dir = '\0';
base = strrchr(file_name, '/');
if (base == NULL) {
base = file_name;
- path_name = strdup("/");
+ path_name = SMB_STRDUP("/");
ALLOC_CHECK(path_name, done);
}
else {
- path_name = strdup(file_name);
+ path_name = SMB_STRDUP(file_name);
ALLOC_CHECK(path_name, done);
path_name[base - file_name] = '\0';
base++;
if (recycle_keep_dir_tree(handle) == True) {
asprintf(&temp_name, "%s/%s", repository, path_name);
} else {
- temp_name = strdup(repository);
+ temp_name = SMB_STRDUP(repository);
}
ALLOC_CHECK(temp_name, done);
return NULL;
}
- dirp = (shadow_copy_Dir *)malloc(sizeof(shadow_copy_Dir));
+ dirp = SMB_MALLOC_P(shadow_copy_Dir);
if (!dirp) {
DEBUG(0,("shadow_copy_opendir: Out of memory\n"));
SMB_VFS_NEXT_CLOSEDIR(handle,conn,p);
DEBUG(10,("shadow_copy_opendir: not hide [%s]\n",d->d_name));
- r = (SMB_STRUCT_DIRENT *)Realloc(dirp->dirs,(dirp->num+1)*sizeof(SMB_STRUCT_DIRENT));
+ r = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
if (!r) {
DEBUG(0,("shadow_copy_opendir: Out of memory\n"));
break;
continue;
}
- tlabels = (SHADOW_COPY_LABEL *)talloc_realloc(shadow_copy_data->mem_ctx,
+ tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data->mem_ctx,
shadow_copy_data->labels,
(shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL));
if (tlabels == NULL) {
struct userdata_struct *userdata;
size_t size = sizeof(struct userdata_struct) + sizeof(BOOL);
- if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+ if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) {
DEBUG(0,("release_1d_name: malloc fail.\n"));
return;
}
subrec->work_changed = True;
/* Setup the userdata_struct. */
- if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+ if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) {
DEBUG(0,("become_local_master_browser: malloc fail.\n"));
return;
}
struct browse_cache_record *browc;
time_t now = time( NULL );
- browc = (struct browse_cache_record *)malloc( sizeof( *browc ) );
+ browc = SMB_MALLOC_P(struct browse_cache_record);
if( NULL == browc ) {
DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") );
/* Setup the userdata_struct - this is copied so we can use
a stack variable for this. */
- if((userdata = (struct userdata_struct *)malloc(size)) == NULL) {
+ if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) {
DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n"));
return;
}
if (namerec->data.num_ips == 1) {
prdata = rdata;
} else {
- if ((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) {
+ if ((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL) {
DEBUG(0,("process_name_query_request: malloc fail !\n"));
return;
}
struct name_record *namerec;
time_t time_now = time(NULL);
- namerec = (struct name_record *)malloc( sizeof(*namerec) );
+ namerec = SMB_MALLOC_P(struct name_record);
if( NULL == namerec ) {
DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
return( NULL );
}
memset( (char *)namerec, '\0', sizeof(*namerec) );
- namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips );
+ namerec->data.ip = SMB_MALLOC_ARRAY( struct in_addr, num_ips );
if( NULL == namerec->data.ip ) {
DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
ZERO_STRUCTP(namerec);
if( find_ip_in_name_record( namerec, new_ip ) )
return;
- new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) * sizeof(struct in_addr) );
+ new_list = SMB_MALLOC_ARRAY( struct in_addr, namerec->data.num_ips + 1);
if( NULL == new_list ) {
DEBUG(0,("add_ip_to_name_record: Malloc fail !\n"));
return;
/* Create an IP list containing all our known subnets. */
num_ips = iface_count();
- iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) );
+ iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips);
if( NULL == iplist ) {
DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n"));
return;
struct in_addr wins_ip = wins_srv_ip_tag(tag, ip);
fstring ip_str;
- userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1);
+ userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1);
if (!userdata) {
DEBUG(0,("Failed to allocate userdata structure!\n"));
return;
for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) )
num_ips++;
- if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) {
+ if((ip_list = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) {
DEBUG(0,("multihomed_register_name: malloc fail !\n"));
return;
}
struct nmb_packet *nmb = NULL;
/* Allocate the packet_struct we will return. */
- if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) {
+ if((packet = SMB_MALLOC_P(struct packet_struct)) == NULL) {
DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n"));
return NULL;
}
{
struct nmb_packet *nmb = &packet->packet.nmb;
- if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) {
+ if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) {
DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n"));
return False;
}
DEBUG(6,("Refreshing name %s IP %s with WINS server %s using tag '%s'\n",
nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag));
- userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1);
+ userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1);
if (!userdata) {
DEBUG(0,("Failed to allocate userdata structure!\n"));
return;
struct subnet_record *subrec = NULL;
int count = 0;
int num = 0;
- fd_set *pset = (fd_set *)malloc(sizeof(fd_set));
+ fd_set *pset = SMB_MALLOC_P(fd_set);
if(pset == NULL) {
DEBUG(0,("create_listen_fdset: malloc fail !\n"));
return True;
}
- if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) {
+ if((sock_array = SMB_MALLOC_ARRAY(int, (count*2) + 2)) == NULL) {
DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n"));
return True;
}
return;
}
- db_info = (struct sam_database_info *)
- malloc(sizeof(struct sam_database_info) * db_count);
+ db_info = SMB_MALLOC_ARRAY(struct sam_database_info, db_count);
if (db_info == NULL) {
DEBUG(3, ("out of memory allocating info for %d databases\n", db_count));
struct response_record *rrec;
struct nmb_packet *nmb = &p->packet.nmb;
- if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) {
+ if (!(rrec = SMB_MALLOC_P(struct response_record))) {
DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n"));
return NULL;
}
} else {
/* Primitive userdata, do a memcpy. */
if((rrec->userdata = (struct userdata_struct *)
- malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) {
+ SMB_MALLOC(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) {
DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n"));
ZERO_STRUCTP(rrec);
SAFE_FREE(rrec);
return NULL;
}
- if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) {
+ if((servrec = SMB_MALLOC_P(struct server_record)) == NULL) {
DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n"));
return NULL;
}
set_socket_options(dgram_sock,"SO_BROADCAST");
}
- subrec = (struct subnet_record *)malloc(sizeof(*subrec));
+ subrec = SMB_MALLOC_P(struct subnet_record);
if (!subrec) {
DEBUG(0,("make_subnet: malloc fail !\n"));
close(nmb_sock);
namelist_entry_compare,
ubi_trOVERWRITE );
- if((subrec->subnet_name = strdup(name)) == NULL) {
+ if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) {
DEBUG(0,("make_subnet: malloc fail for subnet name !\n"));
close(nmb_sock);
close(dgram_sock);
return;
}
- s = (struct sync_record *)malloc(sizeof(*s));
+ s = SMB_MALLOC_P(struct sync_record);
if (!s) goto done;
ZERO_STRUCTP(s);
if(num_ips == 1) {
iplist = &ip;
} else {
- if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) {
+ if((iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL) {
DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n"));
return;
}
static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata)
{
struct packet_struct *p, *copy_of_p;
- struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len );
+ struct userdata_struct *new_userdata = (struct userdata_struct *)SMB_MALLOC( userdata->userdata_len );
if(new_userdata == NULL)
return NULL;
}
/* Allocate the space for the ip_list. */
- if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) {
+ if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) {
DEBUG(0,("initialise_wins: Malloc fail !\n"));
return False;
}
return;
}
- if((prdata = (char *)malloc( num_ips * 6 )) == NULL) {
+ if((prdata = (char *)SMB_MALLOC( num_ips * 6 )) == NULL) {
DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n"));
return;
}
if( namerec->data.num_ips == 1 ) {
prdata = rdata;
} else {
- if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) {
+ if((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL) {
DEBUG(0,("send_wins_name_query_response: malloc fail !\n"));
return;
}
struct subnet_record *subrec;
int t = -1;
- if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) {
+ if((work = SMB_MALLOC_P(struct work_record)) == NULL) {
DEBUG(0,("create_workgroup: malloc fail !\n"));
return NULL;
}
/* Add group to list if necessary */
if (!is_member) {
- tgr = (gid_t *)Realloc(groups, sizeof(gid_t) * ngroups + 1);
+ tgr = SMB_REALLOC_ARRAY(groups, gid_t, ngroups + 1);
if (!tgr) {
errno = ENOMEM;
/* Create new connection structure */
- if ((state = (struct winbindd_cli_state *)
- malloc(sizeof(*state))) == NULL)
+ if ((state = SMB_MALLOC_P(struct winbindd_cli_state)) == NULL)
return;
ZERO_STRUCTP(state);
if ( num_gr_members ) {
fstring buffer;
- gr_members = (char**)smb_xmalloc(sizeof(char*)*(num_gr_members+1));
+ gr_members = SMB_XMALLOC_ARRAY(char*, num_gr_members+1);
i = 0;
while ( next_token(&str, buffer, ",", sizeof(buffer)) && i<num_gr_members ) {
member = grp->gr_mem[num_members];
}
- gr_mem_str = smb_xmalloc(size);
+ gr_mem_str = SMB_XMALLOC_ARRAY(char, size);
for ( i=0; i<num_members; i++ ) {
snprintf( &gr_mem_str[idx], size-idx, "%s,", grp->gr_mem[i] );
}
else {
/* no members */
- gr_mem_str = smb_xmalloc(sizeof(fstring));
+ gr_mem_str = SMB_XMALLOC_ARRAY(char, sizeof(fstring));
fstrcpy( gr_mem_str, "" );
}
}
/* add one new slot and keep an extra for the terminating NULL */
- members = Realloc( grp->gr_mem, (grp->num_gr_mem+2)*sizeof(char*) );
+ members = SMB_REALLOC_ARRAY( grp->gr_mem, char *, grp->num_gr_mem+2);
if ( !members )
return False;
ads->auth.password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
SAFE_FREE(ads->auth.realm);
- ads->auth.realm = strdup(lp_realm());
+ ads->auth.realm = SMB_STRDUP(lp_realm());
status = ads_connect(ads);
if (!ADS_ERR_OK(status) || !ads->config.realm) {
goto done;
}
- (*info) = talloc_zero(mem_ctx, count * sizeof(**info));
+ (*info) = TALLOC_ZERO_ARRAY(mem_ctx, WINBIND_USERINFO, count);
if (!*info) {
status = NT_STATUS_NO_MEMORY;
goto done;
continue;
}
- sid2 = talloc(mem_ctx, sizeof(*sid2));
+ sid2 = TALLOC_P(mem_ctx, DOM_SID);
if (!sid2) {
status = NT_STATUS_NO_MEMORY;
goto done;
goto done;
}
- (*info) = talloc_zero(mem_ctx, count * sizeof(**info));
+ (*info) = TALLOC_ZERO_ARRAY(mem_ctx, struct acct_info, count);
if (!*info) {
status = NT_STATUS_NO_MEMORY;
goto done;
goto done;
}
- sid2 = talloc(mem_ctx, sizeof(*sid2));
+ sid2 = TALLOC_P(mem_ctx, DOM_SID);
if (!sid2) {
status = NT_STATUS_NO_MEMORY;
goto done;
goto done;
}
- (*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1));
+ (*user_gids) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, count + 1);
(*user_gids)[0] = primary_group;
*num_groups = 1;
if (sid_equal(&group_sid, primary_group)) continue;
- (*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids));
+ (*user_gids)[*num_groups] = TALLOC_P(mem_ctx, DOM_SID);
if (!(*user_gids)[*num_groups]) {
status = NT_STATUS_NO_MEMORY;
goto done;
num_groups, user_gids);
}
- (*user_gids) = talloc_zero(mem_ctx, sizeof(**user_gids) * (count + 1));
+ (*user_gids) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, count + 1);
(*user_gids)[0] = primary_group;
*num_groups = 1;
for (i=0;i<count;i++) {
if (sid_equal(&sids[i], primary_group)) continue;
- (*user_gids)[*num_groups] = talloc(mem_ctx, sizeof(***user_gids));
+ (*user_gids)[*num_groups] = TALLOC_P(mem_ctx, DOM_SID);
if (!(*user_gids)[*num_groups]) {
status = NT_STATUS_NO_MEMORY;
goto done;
members = NULL;
num_members = 0;
- attrs = talloc(mem_ctx, 3 * sizeof(*attrs));
+ attrs = TALLOC_ARRAY(mem_ctx, const char *, 3);
attrs[1] = talloc_strdup(mem_ctx, "usnChanged");
attrs[2] = NULL;
the problem is that the members are in the form of distinguised names
*/
- (*sid_mem) = talloc_zero(mem_ctx, sizeof(**sid_mem) * num_members);
- (*name_types) = talloc_zero(mem_ctx, sizeof(**name_types) * num_members);
- (*names) = talloc_zero(mem_ctx, sizeof(**names) * num_members);
+ (*sid_mem) = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, num_members);
+ (*name_types) = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_members);
+ (*names) = TALLOC_ZERO_ARRAY(mem_ctx, char *, num_members);
for (i=0;i<num_members;i++) {
uint32 name_type;
if (dn_lookup(ads, mem_ctx, members[i], &name, &name_type, &sid)) {
(*names)[*num_names] = name;
(*name_types)[*num_names] = name_type;
- (*sid_mem)[*num_names] = talloc(mem_ctx, sizeof(***sid_mem));
+ (*sid_mem)[*num_names] = TALLOC_P(mem_ctx, DOM_SID);
if (!(*sid_mem)[*num_names]) {
status = NT_STATUS_NO_MEMORY;
goto done;
/* Allocate memory for trusted domain names and sids */
- if ( !(*names = (char **)talloc(mem_ctx, sizeof(char *) * count)) ) {
+ if ( !(*names = TALLOC_ARRAY(mem_ctx, char *, count)) ) {
DEBUG(0, ("trusted_domains: out of memory\n"));
result = NT_STATUS_NO_MEMORY;
goto done;
}
- if ( !(*alt_names = (char **)talloc(mem_ctx, sizeof(char *) * count)) ) {
+ if ( !(*alt_names = TALLOC_ARRAY(mem_ctx, char *, count)) ) {
DEBUG(0, ("trusted_domains: out of memory\n"));
result = NT_STATUS_NO_MEMORY;
goto done;
}
- if ( !(*dom_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * count)) ) {
+ if ( !(*dom_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, count)) ) {
DEBUG(0, ("trusted_domains: out of memory\n"));
result = NT_STATUS_NO_MEMORY;
goto done;
if (ret)
return ret;
- ret = smb_xmalloc(sizeof(*ret));
+ ret = SMB_XMALLOC_P(struct winbind_cache);
ZERO_STRUCTP(ret);
wcache = ret;
smb_panic("centry_string");
}
- ret = talloc(mem_ctx, len+1);
+ ret = TALLOC(mem_ctx, len+1);
if (!ret) {
smb_panic("centry_string out of memory\n");
}
DOM_SID *sid;
char *sid_string;
- sid = talloc(mem_ctx, sizeof(*sid));
+ sid = TALLOC_P(mem_ctx, DOM_SID);
if (!sid)
return NULL;
return NULL;
}
- centry = smb_xmalloc(sizeof(*centry));
+ centry = SMB_XMALLOC_P(struct cache_entry);
centry->data = (unsigned char *)data.dptr;
centry->len = data.dsize;
centry->ofs = 0;
if (centry->len - centry->ofs >= len)
return;
centry->len *= 2;
- p = realloc(centry->data, centry->len);
+ p = SMB_REALLOC(centry->data, centry->len);
if (!p) {
DEBUG(0,("out of memory: needed %d bytes in centry_expand\n", centry->len));
smb_panic("out of memory in centry_expand");
if (!wcache->tdb)
return NULL;
- centry = smb_xmalloc(sizeof(*centry));
+ centry = SMB_XMALLOC_P(struct cache_entry);
centry->len = 8192; /* reasonable default */
- centry->data = smb_xmalloc(centry->len);
+ centry->data = SMB_XMALLOC_ARRAY(char, centry->len);
centry->ofs = 0;
centry->sequence_number = domain->sequence_number;
centry_put_uint32(centry, NT_STATUS_V(status));
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, WINBIND_USERINFO, *num_entries);
if (! (*info))
smb_panic("query_user_list out of memory");
for (i=0; i<(*num_entries); i++) {
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
if (! (*info))
smb_panic("enum_dom_groups out of memory");
for (i=0; i<(*num_entries); i++) {
if (*num_entries == 0)
goto do_cached;
- (*info) = talloc(mem_ctx, sizeof(**info) * (*num_entries));
+ (*info) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_entries);
if (! (*info))
smb_panic("enum_dom_groups out of memory");
for (i=0; i<(*num_entries); i++) {
if (*num_groups == 0)
goto do_cached;
- (*user_gids) = talloc(mem_ctx, sizeof(**user_gids) * (*num_groups));
+ (*user_gids) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_groups);
if (! (*user_gids))
smb_panic("lookup_usergroups out of memory");
for (i=0; i<(*num_groups); i++) {
if (*num_names == 0)
goto do_cached;
- (*sid_mem) = talloc(mem_ctx, sizeof(**sid_mem) * (*num_names));
- (*names) = talloc(mem_ctx, sizeof(**names) * (*num_names));
- (*name_types) = talloc(mem_ctx, sizeof(**name_types) * (*num_names));
+ (*sid_mem) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_names);
+ (*names) = TALLOC_ARRAY(mem_ctx, char *, *num_names);
+ (*name_types) = TALLOC_ARRAY(mem_ctx, uint32, *num_names);
if (! (*sid_mem) || ! (*names) || ! (*name_types)) {
smb_panic("lookup_groupmem out of memory");
if (!NT_STATUS_IS_OK(check_negative_conn_cache(domain_name, dcname)))
return False;
- *dcs = talloc_realloc(mem_ctx, *dcs, ((*num)+1) * sizeof(**dcs));
+ *dcs = TALLOC_REALLOC_ARRAY(mem_ctx, *dcs, struct dc_name_ip, (*num)+1);
if (*dcs == NULL)
return False;
{
char *dup_str = talloc_strdup(mem_ctx, str);
- *array = talloc_realloc(mem_ctx, *array, ((*num)+1) * sizeof(**array));
+ *array = TALLOC_REALLOC_ARRAY(mem_ctx, *array, char *, (*num)+1);
if ((*array == NULL) || (dup_str == NULL))
return False;
struct in_addr ip, uint16 port,
struct sockaddr_in **addrs, int *num)
{
- *addrs = talloc_realloc(mem_ctx, *addrs, ((*num)+1) * sizeof(**addrs));
+ *addrs = TALLOC_REALLOC_ARRAY(mem_ctx, *addrs, struct sockaddr_in, (*num)+1);
if (*addrs == NULL)
return False;
struct winbindd_cm_conn *conn;
NTSTATUS result;
- if (!(conn = malloc(sizeof(*conn))))
+ if (!(conn = SMB_MALLOC_P(struct winbindd_cm_conn)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(conn);
if (!background_process) return;
- list = malloc(sizeof(*list));
+ list = SMB_MALLOC_P(struct dual_list);
if (!list) return;
list->next = NULL;
for ( i=0; i<num_members; i++ )
len += strlen(members[i])+1;
- *buffer = (char*)smb_xmalloc(len);
+ *buffer = SMB_XMALLOC_ARRAY(char, len);
for ( i=0; i<num_members; i++ ) {
snprintf( &(*buffer)[idx], len-idx, "%s,", members[i]);
idx += strlen(members[i])+1;
/* Allocate buffer */
if (!buf && buf_len != 0) {
- if (!(buf = malloc(buf_len))) {
+ if (!(buf = SMB_MALLOC(buf_len))) {
DEBUG(1, ("out of memory\n"));
result = False;
goto done;
}
- if ((domain_state = (struct getent_state *)
- malloc(sizeof(struct getent_state))) == NULL) {
+ if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL) {
DEBUG(1, ("winbindd_setgrent: malloc failed for domain_state!\n"));
return WINBINDD_ERROR;
}
/* Copy entries into return buffer */
if (num_entries) {
- if ( !(name_list = malloc(sizeof(struct acct_info) * num_entries)) ) {
+ if ( !(name_list = SMB_MALLOC_ARRAY(struct acct_info, num_entries)) ) {
DEBUG(0,("get_sam_group_entries: Failed to malloc memory for %d domain groups!\n",
num_entries));
result = False;
/* Copy entries into return buffer */
if ( num_entries ) {
- if ( !(tmp_name_list = Realloc( name_list, sizeof(struct acct_info) * (ent->num_sam_entries+num_entries))) )
+ if ( !(tmp_name_list = SMB_REALLOC_ARRAY( name_list, struct acct_info, ent->num_sam_entries+num_entries)) )
{
DEBUG(0,("get_sam_group_entries: Failed to realloc more memory for %d local groups!\n",
num_entries));
num_groups = MIN(MAX_GETGRENT_GROUPS, state->request.data.num_entries);
- if ((state->response.extra_data =
- malloc(num_groups * sizeof(struct winbindd_gr))) == NULL)
+ if ((state->response.extra_data = SMB_MALLOC_ARRAY(struct winbindd_gr, num_groups)) == NULL)
return WINBINDD_ERROR;
memset(state->response.extra_data, '\0',
if (result) {
/* Append to group membership list */
- new_gr_mem_list = Realloc(
- gr_mem_list,
- gr_mem_list_len + gr_mem_len);
+ new_gr_mem_list = SMB_REALLOC( gr_mem_list, gr_mem_list_len + gr_mem_len);
if (!new_gr_mem_list && (group_list[group_list_ndx].num_gr_mem != 0)) {
DEBUG(0, ("out of memory\n"));
if (group_list_ndx == 0)
goto done;
- new_extra_data = Realloc(
+ new_extra_data = SMB_REALLOC(
state->response.extra_data,
group_list_ndx * sizeof(struct winbindd_gr) + gr_mem_list_len);
/* Allocate some memory for extra data. Note that we limit
account names to sizeof(fstring) = 128 characters. */
- ted = Realloc(extra_data, sizeof(fstring) * total_entries);
+ ted = SMB_REALLOC(extra_data, sizeof(fstring) * total_entries);
if (!ted) {
DEBUG(0,("failed to enlarge buffer!\n"));
return;
}
- *sids = talloc_realloc(mem_ctx, *sids, sizeof(**sids) * (*num_sids+1));
+ *sids = TALLOC_REALLOC_ARRAY(mem_ctx, *sids, DOM_SID *, *num_sids+1);
if (*sids == NULL)
return;
- (*sids)[*num_sids] = talloc(mem_ctx, sizeof(DOM_SID));
+ (*sids)[*num_sids] = TALLOC_P(mem_ctx, DOM_SID);
sid_copy((*sids)[*num_sids], sid);
*num_sids += 1;
return;
}
/* build the reply */
- ret = malloc(ret_size);
+ ret = SMB_MALLOC(ret_size);
if (!ret) goto done;
ofs = 0;
for (i = 0; i < num_groups; i++) {
/* Add domain to list */
total_entries++;
- ted = Realloc(extra_data, sizeof(fstring) *
+ ted = SMB_REALLOC(extra_data, sizeof(fstring) *
total_entries);
if (!ted) {
state->request.domain_name[sizeof(state->request.domain_name)-1]='\0';
which_domain = state->request.domain_name;
- extra_data = strdup("");
+ extra_data = SMB_STRDUP("");
/* this makes for a very simple data format, and is easily parsable as well
if that is ever needed */
DEBUG(3, ("[%5lu]: request location of privileged pipe\n", (unsigned long)state->pid));
- state->response.extra_data = strdup(get_winbind_priv_pipe_dir());
+ state->response.extra_data = SMB_STRDUP(get_winbind_priv_pipe_dir());
if (!state->response.extra_data)
return WINBINDD_ERROR;
}
size = prs_data_size(&ps);
- state->response.extra_data = malloc(size);
+ state->response.extra_data = SMB_MALLOC(size);
if (!state->response.extra_data) {
prs_mem_free(&ps);
return NT_STATUS_NO_MEMORY;
return NT_STATUS_INVALID_PARAMETER;
}
- all_sids = talloc(mem_ctx, sizeof(DOM_SID) * num_all_sids);
+ all_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_all_sids);
if (!all_sids)
return NT_STATUS_NO_MEMORY;
if ( NT_STATUS_IS_OK(result) &&
(state->request.flags & WBFLAG_PAM_AFS_TOKEN) ) {
- char *afsname = strdup(lp_afs_username_map());
+ char *afsname = SMB_STRDUP(lp_afs_username_map());
char *cell;
if (afsname == NULL) goto no_token;
DEBUG(5, ("Setting unix username to [%s]\n", username_out));
- state->response.extra_data = strdup(username_out);
+ state->response.extra_data = SMB_STRDUP(username_out);
if (!state->response.extra_data) {
result = NT_STATUS_NO_MEMORY;
goto done;
return NT_STATUS_OK;
}
- talloced_info = (struct acct_info *)
- talloc_memdup(mem_ctx, *info,
+ talloced_info = (struct acct_info *)TALLOC_MEMDUP(mem_ctx, *info,
*num_entries * sizeof(struct acct_info));
SAFE_FREE(*info);
nt_status = secrets_get_trusted_domains(mem_ctx, &enum_ctx, 1,
&num_sec_domains,
&domains);
- *names = talloc_realloc(mem_ctx, *names,
- sizeof(*names) *
- (num_sec_domains + *num_domains));
- *alt_names = talloc_realloc(mem_ctx, *alt_names,
- sizeof(*alt_names) *
- (num_sec_domains + *num_domains));
- *dom_sids = talloc_realloc(mem_ctx, *dom_sids,
- sizeof(**dom_sids) *
- (num_sec_domains + *num_domains));
+ *names = TALLOC_REALLOC_ARRAY(mem_ctx, *names, char *,
+ num_sec_domains + *num_domains);
+ *alt_names = TALLOC_REALLOC_ARRAY(mem_ctx, *alt_names, char *,
+ num_sec_domains + *num_domains);
+ *dom_sids = TALLOC_REALLOC_ARRAY(mem_ctx, *dom_sids, DOM_SID,
+ num_sec_domains + *num_domains);
for (i=0; i< num_sec_domains; i++) {
if (pull_ucs2_talloc(mem_ctx, &(*names)[*num_domains],
*num_entries += num_dom_users;
- *info = talloc_realloc( mem_ctx, *info,
- (*num_entries) * sizeof(WINBIND_USERINFO));
+ *info = TALLOC_REALLOC_ARRAY( mem_ctx, *info, WINBIND_USERINFO, *num_entries);
if (!(*info)) {
result = NT_STATUS_NO_MEMORY;
break;
}
- (*info) = talloc_realloc(mem_ctx, *info,
- sizeof(**info) * ((*num_entries) + count));
+ (*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, struct acct_info, (*num_entries) + count);
if (! *info) {
talloc_destroy(mem_ctx2);
cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
break;
}
- (*info) = talloc_realloc(mem_ctx, *info,
- sizeof(**info) * ((*num_entries) + count));
+ (*info) = TALLOC_REALLOC_ARRAY(mem_ctx, *info, struct acct_info, (*num_entries) + count);
if (! *info) {
talloc_destroy(mem_ctx2);
cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
*num_groups = user->num_groups;
- (*user_grpsids) = talloc(mem_ctx, sizeof(DOM_SID*) * (*num_groups));
+ (*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID*, *num_groups);
for (i=0;i<(*num_groups);i++) {
(*user_grpsids)[i] = rid_to_talloced_sid(domain, mem_ctx, user->gids[i].g_rid);
}
if (!NT_STATUS_IS_OK(result) || (*num_groups) == 0)
goto done;
- (*user_grpsids) = talloc(mem_ctx, sizeof(DOM_SID*) * (*num_groups));
+ (*user_grpsids) = TALLOC_ARRAY(mem_ctx, DOM_SID *, *num_groups);
if (!(*user_grpsids)) {
result = NT_STATUS_NO_MEMORY;
goto done;
#define MAX_LOOKUP_RIDS 900
- *names = talloc_zero(mem_ctx, *num_names * sizeof(char *));
- *name_types = talloc_zero(mem_ctx, *num_names * sizeof(uint32));
- *sid_mem = talloc_zero(mem_ctx, *num_names * sizeof(DOM_SID *));
+ *names = TALLOC_ZERO_ARRAY(mem_ctx, char *, *num_names);
+ *name_types = TALLOC_ZERO_ARRAY(mem_ctx, uint32, *num_names);
+ *sid_mem = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID *, *num_names);
for (j=0;j<(*num_names);j++) {
(*sid_mem)[j] = rid_to_talloced_sid(domain, mem_ctx, (rid_mem)[j]);
/* Create a state record for this domain */
- if ((domain_state = (struct getent_state *)
- malloc(sizeof(struct getent_state))) == NULL)
+ if ((domain_state = SMB_MALLOC_P(struct getent_state)) == NULL)
return WINBINDD_ERROR;
ZERO_STRUCTP(domain_state);
if (num_entries) {
struct getpwent_user *tnl;
- tnl = (struct getpwent_user *)Realloc(name_list,
- sizeof(struct getpwent_user) *
- (ent->num_sam_entries +
- num_entries));
+ tnl = SMB_REALLOC_ARRAY(name_list, struct getpwent_user, ent->num_sam_entries + num_entries);
if (!tnl) {
DEBUG(0,("get_sam_user_entries realloc failed.\n"));
num_users = MIN(MAX_GETPWENT_USERS, state->request.data.num_entries);
- if ((state->response.extra_data =
- malloc(num_users * sizeof(struct winbindd_pw))) == NULL)
+ if ((state->response.extra_data = SMB_MALLOC_ARRAY(struct winbindd_pw, num_users)) == NULL)
return WINBINDD_ERROR;
memset(state->response.extra_data, 0, num_users *
/* Allocate some memory for extra data */
total_entries += num_entries;
- ted = Realloc(extra_data, sizeof(fstring) * total_entries);
+ ted = SMB_REALLOC(extra_data, sizeof(fstring) * total_entries);
if (!ted) {
DEBUG(0,("failed to enlarge buffer!\n"));
/* Create new domain entry */
- if ((domain = (struct winbindd_domain *)malloc(sizeof(*domain))) == NULL)
+ if ((domain = SMB_MALLOC_P(struct winbindd_domain)) == NULL)
return NULL;
/* Fill in fields */
uint32 rid)
{
DOM_SID *sid;
- sid = talloc(mem_ctx, sizeof(*sid));
+ sid = TALLOC_P(mem_ctx, DOM_SID);
if (!sid) {
smb_panic("rid_to_to_talloced_sid: talloc for DOM_SID failed!\n");
}
if (resolve_wins(name,0x20,&ret,count)) {
if ( count == 0 )
return NULL;
- if ( (return_ip = (struct in_addr *)malloc((*count)*sizeof(struct in_addr))) == NULL ) {
+ if ( (return_ip = SMB_MALLOC_ARRAY(struct in_addr, *count)) == NULL ) {
free( ret );
return NULL;
}
/* always try with wins first */
if (resolve_wins(name,0x00,&address,count)) {
- if ( (ret = (struct in_addr *)malloc(sizeof(struct in_addr))) == NULL ) {
+ if ( (ret = SMB_MALLOC_P(struct in_addr)) == NULL ) {
free( address );
return NULL;
}
if (i == iNumServices) {
service **tsp;
- tsp = (service **) Realloc(ServicePtrs,
- sizeof(service *) *
- num_to_alloc);
+ tsp = SMB_REALLOC_ARRAY(ServicePtrs, service *, num_to_alloc);
if (!tsp) {
DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
}
else {
ServicePtrs = tsp;
- ServicePtrs[iNumServices] =
- (service *) malloc(sizeof(service));
+ ServicePtrs[iNumServices] = SMB_MALLOC_P(service);
}
if (!ServicePtrs[iNumServices]) {
DEBUG(0,("add_a_service: out of memory!\n"));
if (strcmp(pdata->key, data->key) == 0) {
string_free(&pdata->value);
str_list_free(&data->list);
- pdata->value = strdup(data->value);
+ pdata->value = SMB_STRDUP(data->value);
not_added = False;
break;
}
pdata = pdata->next;
}
if (not_added) {
- paramo = smb_xmalloc(sizeof(param_opt_struct));
- paramo->key = strdup(data->key);
- paramo->value = strdup(data->value);
+ paramo = SMB_XMALLOC_P(param_opt_struct);
+ paramo->key = SMB_STRDUP(data->key);
+ paramo->value = SMB_STRDUP(data->value);
paramo->list = NULL;
DLIST_ADD(pserviceDest->param_opt, paramo);
}
}
if (!f) {
- f = (struct file_lists *)malloc(sizeof(file_lists[0]));
+ f = SMB_MALLOC_P(struct file_lists);
if (!f)
return;
f->next = file_lists;
- f->name = strdup(fname);
+ f->name = SMB_STRDUP(fname);
if (!f->name) {
SAFE_FREE(f);
return;
}
- f->subfname = strdup(subfname);
+ f->subfname = SMB_STRDUP(subfname);
if (!f->subfname) {
SAFE_FREE(f);
return;
ctime(&mod_time)));
f->modtime = mod_time;
SAFE_FREE(f->subfname);
- f->subfname = strdup(n2);
+ f->subfname = SMB_STRDUP(n2);
return (True);
}
f = f->next;
{
int i;
SAFE_FREE(pservice->copymap);
- pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS);
+ pservice->copymap = SMB_MALLOC_ARRAY(BOOL,NUMPARAMETERS);
if (!pservice->copymap)
DEBUG(0,
("Couldn't allocate copymap!! (size %d)\n",
if (strcmp(data->key, param_key) == 0) {
string_free(&data->value);
str_list_free(&data->list);
- data->value = strdup(pszParmValue);
+ data->value = SMB_STRDUP(pszParmValue);
not_added = False;
break;
}
data = data->next;
}
if (not_added) {
- paramo = smb_xmalloc(sizeof(param_opt_struct));
- paramo->key = strdup(param_key);
- paramo->value = strdup(pszParmValue);
+ paramo = SMB_XMALLOC_P(param_opt_struct);
+ paramo->key = SMB_STRDUP(param_key);
+ paramo->value = SMB_STRDUP(pszParmValue);
paramo->list = NULL;
if (snum < 0) {
DLIST_ADD(Globals.param_opt, paramo);
if (!str)
return;
- s = strdup(str);
+ s = SMB_STRDUP(str);
if (!s)
return;
case P_STRING:
case P_USTRING:
if (parm_table[i].ptr) {
- parm_table[i].def.svalue = strdup(*(char **)parm_table[i].ptr);
+ parm_table[i].def.svalue = SMB_STRDUP(*(char **)parm_table[i].ptr);
} else {
parm_table[i].def.svalue = NULL;
}
case P_GSTRING:
case P_UGSTRING:
if (parm_table[i].ptr) {
- parm_table[i].def.svalue = strdup((char *)parm_table[i].ptr);
+ parm_table[i].def.svalue = SMB_STRDUP((char *)parm_table[i].ptr);
} else {
parm_table[i].def.svalue = NULL;
}
{
char *tb;
- tb = Realloc( bufr, bSize +BUFR_INC );
+ tb = SMB_REALLOC( bufr, bSize +BUFR_INC );
if( NULL == tb )
{
DEBUG(0, ("%s Memory re-allocation failure.", func) );
{
char *tb;
- tb = Realloc( bufr, bSize + BUFR_INC );
+ tb = SMB_REALLOC( bufr, bSize + BUFR_INC );
if( NULL == tb )
{
DEBUG(0, ("%s Memory re-allocation failure.", func) );
{
char *tb;
- tb = Realloc( bufr, bSize + BUFR_INC );
+ tb = SMB_REALLOC( bufr, bSize + BUFR_INC );
if( NULL == tb )
{
DEBUG(0, ("%s Memory re-allocation failure.", func) );
int lvl = in_client?1:0;
myFILE *ret;
- ret = (myFILE *)malloc(sizeof(*ret));
+ ret = SMB_MALLOC_P(myFILE);
if (!ret) return NULL;
ret->buf = file_load(FileName, &ret->size);
else /* If we don't have a buffer */
{ /* allocate one, then parse, */
bSize = BUFR_INC; /* then free. */
- bufr = (char *)malloc( bSize );
+ bufr = (char *)SMB_MALLOC( bSize );
if( NULL == bufr )
{
DEBUG(0,("%s memory allocation failure.\n", func));
if (!login_cache_init())
return NULL;
- keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+ keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
if (!keybuf.dptr || !strlen(keybuf.dptr)) {
SAFE_FREE(keybuf.dptr);
return NULL;
databuf = tdb_fetch(cache, keybuf);
SAFE_FREE(keybuf.dptr);
- if (!(entry = malloc(sizeof(LOGIN_CACHE)))) {
+ if (!(entry = SMB_MALLOC_P(LOGIN_CACHE))) {
DEBUG(1, ("Unable to allocate cache entry buffer!\n"));
SAFE_FREE(databuf.dptr);
return NULL;
if (!login_cache_init())
return False;
- keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+ keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
if (!keybuf.dptr || !strlen(keybuf.dptr)) {
SAFE_FREE(keybuf.dptr);
return False;
entry.acct_ctrl,
entry.bad_password_count,
entry.bad_password_time);
- databuf.dptr = malloc(databuf.dsize);
+ databuf.dptr = SMB_MALLOC(databuf.dsize);
if (!databuf.dptr) {
SAFE_FREE(keybuf.dptr);
return False;
if (!login_cache_init())
return False;
- keybuf.dptr = strdup(pdb_get_nt_username(sampass));
+ keybuf.dptr = SMB_STRDUP(pdb_get_nt_username(sampass));
if (!keybuf.dptr || !strlen(keybuf.dptr)) {
SAFE_FREE(keybuf.dptr);
return False;
}
}
- pc = (struct uid_sid_cache *)malloc(sizeof(struct uid_sid_cache));
+ pc = SMB_MALLOC_P(struct uid_sid_cache);
if (!pc)
return;
pc->uid = uid;
}
}
- pc = (struct gid_sid_cache *)malloc(sizeof(struct gid_sid_cache));
+ pc = SMB_MALLOC_P(struct gid_sid_cache);
if (!pc)
return;
pc->gid = gid;
BOOL is_dc = False;
DOM_SID *sam_sid;
- if(!(sam_sid=(DOM_SID *)malloc(sizeof(DOM_SID))))
+ if(!(sam_sid=SMB_MALLOC_P(DOM_SID)))
return NULL;
generate_wellknown_sids();
return NT_STATUS_UNSUCCESSFUL;
}
- *user=(SAM_ACCOUNT *)talloc(mem_ctx, sizeof(SAM_ACCOUNT));
+ *user=TALLOC_P(mem_ctx, SAM_ACCOUNT);
if (*user==NULL) {
DEBUG(0,("pdb_init_sam_talloc: error while allocating memory\n"));
/* Change from V1 is addition of password history field. */
account_policy_get(AP_PASSWORD_HISTORY, &pwHistLen);
if (pwHistLen) {
- char *pw_hist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN);
+ char *pw_hist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN);
if (!pw_hist) {
ret = False;
goto done;
}
/* malloc the space needed */
- if ( (*buf=(uint8*)malloc(len)) == NULL) {
+ if ( (*buf=(uint8*)SMB_MALLOC(len)) == NULL) {
DEBUG(0,("init_buffer_from_sam_v2: Unable to malloc() memory for buffer!\n"));
return (-1);
}
if (current_history_len < pwHistLen) {
/* Ensure we have space for the needed history. */
- uchar *new_history = talloc(sampass->mem_ctx,
+ uchar *new_history = TALLOC(sampass->mem_ctx,
pwHistLen*PW_HISTORY_ENTRY_LEN);
/* And copy it into the new buffer. */
if (current_history_len) {
return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = smb_xmalloc(sizeof(struct pdb_init_function_entry));
+ entry = SMB_XMALLOC_P(struct pdb_init_function_entry);
entry->name = smb_xstrdup(name);
entry->init = init;
return NT_STATUS_NO_MEMORY;
}
- *context = talloc(mem_ctx, sizeof(**context));
+ *context = TALLOC_P(mem_ctx, struct pdb_context);
if (!*context) {
DEBUG(0, ("make_pdb_context: talloc failed!\n"));
return NT_STATUS_NO_MEMORY;
NTSTATUS make_pdb_methods(TALLOC_CTX *mem_ctx, PDB_METHODS **methods)
{
- *methods = talloc(mem_ctx, sizeof(struct pdb_methods));
+ *methods = TALLOC_P(mem_ctx, struct pdb_methods);
if (!*methods) {
return NT_STATUS_NO_MEMORY;
/* We can only store (sizeof(pstring)-1)/64 password history entries. */
pwHistLen = MIN(pwHistLen, ((sizeof(temp)-1)/64));
- if ((pwhist = malloc(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){
+ if ((pwhist = SMB_MALLOC(pwHistLen * PW_HISTORY_ENTRY_LEN)) == NULL){
DEBUG(0, ("init_sam_from_ldap: malloc failed!\n"));
return False;
}
;
}
- (*attr_list) = Realloc((*attr_list), sizeof(**attr_list) * (i+2));
+ (*attr_list) = SMB_REALLOC_ARRAY((*attr_list), char *, i+2);
SMB_ASSERT((*attr_list) != NULL);
- (*attr_list)[i] = strdup(new_attr);
+ (*attr_list)[i] = SMB_STRDUP(new_attr);
(*attr_list)[i+1] = NULL;
}
continue;
}
- mapt=(GROUP_MAP *)Realloc((*rmap), (entries+1)*sizeof(GROUP_MAP));
+ mapt=SMB_REALLOC_ARRAY((*rmap), GROUP_MAP, entries+1);
if (!mapt) {
DEBUG(0,("ldapsam_enum_group_mapping: Unable to enlarge group map!\n"));
SAFE_FREE(*rmap);
/* TODO: Setup private data and free */
- ldap_state = talloc_zero(pdb_context->mem_ctx, sizeof(*ldap_state));
+ ldap_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct ldapsam_privates);
if (!ldap_state) {
DEBUG(0, ("pdb_init_ldapsam_common: talloc() failed for ldapsam private_data!\n"));
return NT_STATUS_NO_MEMORY;
new_entry_length = strlen(newpwd->smb_name) + 1 + 15 + 1 + 32 + 1 + 32 + 1 +
NEW_PW_FORMAT_SPACE_PADDED_LEN + 1 + 13 + 2;
- if((new_entry = (char *)malloc( new_entry_length )) == NULL) {
+ if((new_entry = (char *)SMB_MALLOC( new_entry_length )) == NULL) {
DEBUG(0, ("format_new_smbpasswd_entry: Malloc failed adding entry for user %s.\n",
newpwd->smb_name ));
return NULL;
/* Setup private data and free function */
- privates = talloc_zero(pdb_context->mem_ctx, sizeof(struct smbpasswd_privates));
+ privates = TALLOC_ZERO_P(pdb_context->mem_ctx, struct smbpasswd_privates);
if (!privates) {
DEBUG(0, ("talloc() failed for smbpasswd private_data!\n"));
char *sql_escape_string(const char *unesc)
{
- char *esc = malloc(strlen(unesc) * 2 + 3);
+ char *esc = SMB_MALLOC(strlen(unesc) * 2 + 3);
size_t pos_unesc = 0, pos_esc = 0;
for(pos_unesc = 0; unesc[pos_unesc]; pos_unesc++) {
" VALUES (%s", query.part2);
}
- ret = strdup(query.part1);
+ ret = SMB_STRDUP(query.part1);
talloc_destroy(query.mem_ctx);
return ret;
}
struct pwent_list *ptr;
if ( strncmp(key.dptr, prefix, prefixlen) == 0 ) {
- if ( !(ptr=(struct pwent_list*)malloc(sizeof(struct pwent_list))) ) {
+ if ( !(ptr=SMB_MALLOC_P(struct pwent_list)) ) {
DEBUG(0,("tdbsam_traverse_setpwent: Failed to malloc new entry for list\n"));
/* just return 0 and let the traversal continue */
(*pdb_method)->update_sam_account = tdbsam_update_sam_account;
(*pdb_method)->delete_sam_account = tdbsam_delete_sam_account;
- tdb_state = talloc_zero(pdb_context->mem_ctx, sizeof(struct tdbsam_privates));
+ tdb_state = TALLOC_ZERO_P(pdb_context->mem_ctx, struct tdbsam_privates);
if (!tdb_state) {
DEBUG(0, ("talloc() failed for tdbsam private_data!\n"));
*count = i;
/* allocate and parse */
- *sids = malloc(sizeof(DOM_SID) * *count);
+ *sids = SMB_MALLOC_ARRAY(DOM_SID, *count);
if (! *sids) {
return NT_STATUS_NO_MEMORY;
}
}
/* allocate the maximum size that we might use */
- data.dptr = malloc(count * ((MAXSUBAUTHS*11) + 30));
+ data.dptr = SMB_MALLOC(count * ((MAXSUBAUTHS*11) + 30));
if (!data.dptr) {
return NT_STATUS_NO_MEMORY;
}
}
/* add it in */
- current_sids = Realloc(current_sids, sizeof(current_sids[0]) * (current_count+1));
+ current_sids = SMB_REALLOC_ARRAY(current_sids, DOM_SID, current_count+1);
if (!current_sids) {
privilege_unlock_right(right);
return NT_STATUS_NO_MEMORY;
right = key.dptr;
if (privilege_sid_has_right(sid, right)) {
- (*rights) = (char **)Realloc(*rights,sizeof(char *) * ((*count)+1));
+ (*rights) = SMB_REALLOC_ARRAY(*rights,char *, (*count)+1);
if (! *rights) {
safe_free(nextkey.dptr);
free(key.dptr);
return NT_STATUS_NO_MEMORY;
}
- (*rights)[*count] = strdup(right);
+ (*rights)[*count] = SMB_STRDUP(right);
(*count)++;
}
/* the trust's password */
if (pwd) {
- *pwd = strdup(pass.pass);
+ *pwd = SMB_STRDUP(pass.pass);
if (!*pwd) {
return False;
}
size_t size, packed_size = 0;
fstring dom_name;
char *packed_pass;
- struct trusted_dom_pass *pass = talloc_zero(ctx, sizeof(struct trusted_dom_pass));
+ struct trusted_dom_pass *pass = TALLOC_ZERO_P(ctx, struct trusted_dom_pass);
NTSTATUS status;
if (!secrets_init()) return NT_STATUS_ACCESS_DENIED;
DEBUG(5, ("secrets_get_trusted_domains: looking for %d domains, starting at index %d\n",
max_num_domains, *enum_ctx));
- *domains = talloc_zero(ctx, sizeof(**domains)*max_num_domains);
+ *domains = TALLOC_ZERO_ARRAY(ctx, TRUSTDOM *, max_num_domains);
/* fetching trusted domains' data and collecting them in a list */
keys = tdb_search_keys(tdb, pattern);
char *secrets_key;
/* important: ensure null-termination of the key string */
- secrets_key = strndup(k->node_key.dptr, k->node_key.dsize);
+ secrets_key = SMB_STRNDUP(k->node_key.dptr, k->node_key.dsize);
if (!secrets_key) {
DEBUG(0, ("strndup failed!\n"));
return NT_STATUS_NO_MEMORY;
SAFE_FREE(secrets_key);
if (idx >= start_idx && idx < start_idx + max_num_domains) {
- dom = talloc_zero(ctx, sizeof(*dom));
+ dom = TALLOC_ZERO_P(ctx, TRUSTDOM);
if (!dom) {
/* free returned tdb record */
return NT_STATUS_NO_MEMORY;
/* This is not lp_workgroup() for good reason:
it must stay around longer than the lp_*()
strings do */
- sid_name_map[i].name = strdup(lp_workgroup());
+ sid_name_map[i].name = SMB_STRDUP(lp_workgroup());
sid_name_map[i].known_users = NULL;
i++;
sid_name_map[i].sid = get_global_sam_sid();
- sid_name_map[i].name = strdup(global_myname());
+ sid_name_map[i].name = SMB_STRDUP(global_myname());
sid_name_map[i].known_users = NULL;
i++;
} else {
sid_name_map[i].sid = get_global_sam_sid();
- sid_name_map[i].name = strdup(global_myname());
+ sid_name_map[i].name = SMB_STRDUP(global_myname());
sid_name_map[i].known_users = NULL;
i++;
}
void add_sid_to_array(const DOM_SID *sid, DOM_SID **sids, int *num)
{
- *sids = Realloc(*sids, ((*num)+1) * sizeof(DOM_SID));
+ *sids = SMB_REALLOC_ARRAY(*sids, DOM_SID, (*num)+1);
if (*sids == NULL)
return;
{
const char *p;
int printers;
- char *str = strdup(lp_auto_services());
+ char *str = SMB_STRDUP(lp_auto_services());
if (!str) return;
msg->len, msg->notify.data);
if (buflen != len) {
- buf = talloc_realloc(send_ctx, buf, len);
+ buf = TALLOC_REALLOC(send_ctx, buf, len);
if (!buf)
return False;
buflen = len;
}
offset += 4; /* For count. */
- buf = talloc(send_ctx, offset);
+ buf = TALLOC(send_ctx, offset);
if (!buf) {
DEBUG(0,("print_notify_send_messages: Out of memory\n"));
talloc_destroy_pool(send_ctx);
memcpy( to, from, sizeof(SPOOLSS_NOTIFY_MSG) );
if ( from->len ) {
- to->notify.data = talloc_memdup(send_ctx, from->notify.data, from->len );
+ to->notify.data = TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
if ( !to->notify.data ) {
DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
return False;
/* Store the message on the pending queue. */
- pnqueue = talloc(send_ctx, sizeof(*pnqueue));
+ pnqueue = TALLOC_P(send_ctx, struct notify_queue);
if (!pnqueue) {
DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
return;
/* allocate a new msg structure and copy the fields */
- if ( !(pnqueue->msg = (SPOOLSS_NOTIFY_MSG*)talloc(send_ctx, sizeof(SPOOLSS_NOTIFY_MSG))) ) {
+ if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n",
(unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
return;
if (!create_send_ctx())
return;
- msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+ msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
if (!create_send_ctx())
return;
- msg = (struct spoolss_notify_msg *)talloc(send_ctx, sizeof(struct spoolss_notify_msg));
+ msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
if (!msg)
return;
num_pids = data.dsize / 8;
- if ((pid_list = (pid_t *)talloc(mem_ctx, sizeof(pid_t) * num_pids)) == NULL) {
+ if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
ret = False;
goto done;
}
if (ret != dbuf.dsize)
continue;
- tl = Realloc(*list, sizeof(nt_forms_struct)*(n+1));
+ tl = SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1);
if (!tl) {
DEBUG(0,("get_ntforms: Realloc fail.\n"));
return 0;
}
if (update==False) {
- if((tl=Realloc(*list, (n+1)*sizeof(nt_forms_struct))) == NULL) {
+ if((tl=SMB_REALLOC_ARRAY(*list, nt_forms_struct, n+1)) == NULL) {
DEBUG(0,("add_a_form: failed to enlarge forms list!\n"));
return False;
}
if (strncmp(kbuf.dptr, key, strlen(key)) != 0)
continue;
- if((fl = Realloc(*list, sizeof(fstring)*(total+1))) == NULL) {
+ if((fl = SMB_REALLOC_ARRAY(*list, fstring, total+1)) == NULL) {
DEBUG(0,("get_ntdrivers: failed to enlarge list!\n"));
return -1;
}
char *buf = NULL;
ssize_t byte_count;
- if ((buf=malloc(PE_HEADER_SIZE)) == NULL) {
+ if ((buf=SMB_MALLOC(PE_HEADER_SIZE)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] PE Header malloc failed bytes = %d\n",
fname, PE_HEADER_SIZE));
goto error_exit;
goto error_exit;
SAFE_FREE(buf);
- if ((buf=malloc(section_table_bytes)) == NULL) {
+ if ((buf=SMB_MALLOC(section_table_bytes)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] section table malloc failed bytes = %d\n",
fname, section_table_bytes));
goto error_exit;
goto error_exit;
SAFE_FREE(buf);
- if ((buf=malloc(section_bytes)) == NULL) {
+ if ((buf=SMB_MALLOC(section_bytes)) == NULL) {
DEBUG(0,("get_file_version: PE file [%s] version malloc failed bytes = %d\n",
fname, section_bytes));
goto error_exit;
/* Allocate a bit more space to speed up things */
SAFE_FREE(buf);
- if ((buf=malloc(VS_NE_BUF_SIZE)) == NULL) {
+ if ((buf=SMB_MALLOC(VS_NE_BUF_SIZE)) == NULL) {
DEBUG(0,("get_file_version: NE file [%s] malloc failed bytes = %d\n",
fname, PE_HEADER_SIZE));
goto error_exit;
if (len != buflen) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("add_a_printer_driver_3: failed to enlarge buffer\n!"));
ret = -1;
fstrcpy(info.configfile, "");
fstrcpy(info.helpfile, "");
- if ((info.dependentfiles=(fstring *)malloc(2*sizeof(fstring))) == NULL)
+ if ((info.dependentfiles= SMB_MALLOC_ARRAY(fstring, 2)) == NULL)
return WERR_NOMEM;
memset(info.dependentfiles, '\0', 2*sizeof(fstring));
while (len < dbuf.dsize) {
fstring *tddfs;
- tddfs = (fstring *)Realloc(driver.dependentfiles,
- sizeof(fstring)*(i+2));
+ tddfs = SMB_REALLOC_ARRAY(driver.dependentfiles, fstring, i+2);
if (tddfs == NULL) {
DEBUG(0,("get_a_printer_driver_3: failed to enlarge buffer!\n"));
break;
if (buflen != len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("update_a_printer_2: failed to enlarge buffer!\n"));
ret = WERR_NOMEM;
{
char adevice[MAXDEVICENAME];
- NT_DEVICEMODE *nt_devmode = (NT_DEVICEMODE *)malloc(sizeof(NT_DEVICEMODE));
+ NT_DEVICEMODE *nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE);
if (nt_devmode == NULL) {
DEBUG(0,("construct_nt_devicemode: malloc fail.\n"));
/* allocate another slot in the NT_PRINTER_KEY array */
- d = Realloc( data->keys, sizeof(NT_PRINTER_KEY)*(data->num_keys+1) );
+ d = SMB_REALLOC_ARRAY( data->keys, NT_PRINTER_KEY, data->num_keys+1);
if ( d )
data->keys = d;
/* initialze new key */
data->num_keys++;
- data->keys[key_index].name = strdup( name );
+ data->keys[key_index].name = SMB_STRDUP( name );
ZERO_STRUCTP( &data->keys[key_index].values );
/* found a match, so allocate space and copy the name */
- if ( !(ptr = Realloc( subkeys_ptr, (num_subkeys+2)*sizeof(fstring))) ) {
+ if ( !(ptr = SMB_REALLOC_ARRAY( subkeys_ptr, fstring, num_subkeys+2)) ) {
DEBUG(0,("get_printer_subkeys: Realloc failed for [%d] entries!\n",
num_subkeys+1));
SAFE_FREE( subkeys );
/* a multi-sz has to have a null string terminator, i.e., the last
string must be followed by two nulls */
- str_size = (strlen(multi_sz) + 2) * sizeof(smb_ucs2_t);
- conv_strs = calloc(str_size, 1);
+ str_size = strlen(multi_sz) + 2;
+ conv_strs = SMB_CALLOC_ARRAY(smb_ucs2_t, str_size);
+ if (!conv_strs) {
+ return;
+ }
+ /* Change to byte units. */
+ str_size *= sizeof(smb_ucs2_t);
push_ucs2(NULL, conv_strs, multi_sz, str_size,
STR_TERMINATE | STR_NOALIGN);
if (buflen < len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0, ("update_driver_init_2: failed to enlarge buffer!\n"));
ret = -1;
if ((ctx = talloc_init("save_driver_init_2")) == NULL)
return WERR_NOMEM;
- if ((nt_devmode = (NT_DEVICEMODE*)malloc(sizeof(NT_DEVICEMODE))) == NULL) {
+ if ((nt_devmode = SMB_MALLOC_P(NT_DEVICEMODE)) == NULL) {
status = WERR_NOMEM;
goto done;
}
if ( !printer )
return NULL;
- if ( !(copy = (NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2))) )
+ if ( !(copy = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2)) )
return NULL;
memcpy( copy, printer, sizeof(NT_PRINTER_INFO_LEVEL_2) );
switch (level) {
case 2:
- if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
+ if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
DEBUG(0,("get_a_printer: malloc fail.\n"));
return WERR_NOMEM;
}
/* save a copy in cache */
if ( print_hnd && (print_hnd->printer_type==PRINTER_HANDLE_IS_PRINTER)) {
if ( !print_hnd->printer_info )
- print_hnd->printer_info = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL));
+ print_hnd->printer_info = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL);
if ( print_hnd->printer_info ) {
/* make sure to use the handle's talloc ctx here since
{
qalloc += 16;
- temp = Realloc(queue, sizeof(print_queue_struct) * qalloc);
+ temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
if (temp == NULL)
{
qcount = 0;
ZERO_STRUCTP(status);
if (numlines)
- queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(numlines+1));
+ queue = SMB_MALLOC_ARRAY(print_queue_struct, numlines+1);
if (queue) {
memset(queue, '\0', sizeof(print_queue_struct)*(numlines+1));
if (buflen != len) {
char *tb;
- tb = (char *)Realloc(buf, len);
+ tb = (char *)SMB_REALLOC(buf, len);
if (!tb) {
DEBUG(0,("pjob_store: failed to enlarge buffer!\n"));
goto done;
queue[i].fs_file);
}
- if ((data.dptr = malloc(data.dsize)) == NULL)
+ if ((data.dptr = SMB_MALLOC(data.dsize)) == NULL)
return;
len = 0;
if (i == data.dsize) {
/* We weren't in the list. Realloc. */
- data.dptr = Realloc(data.dptr, data.dsize + 8);
+ data.dptr = SMB_REALLOC(data.dptr, data.dsize + 8);
if (!data.dptr) {
DEBUG(0,("print_notify_register_pid: Relloc fail for printer %s\n",
printername));
if (qcount == 0 && extra_count == 0)
goto out;
- if ((queue = (print_queue_struct *)malloc(sizeof(print_queue_struct)*(qcount + extra_count))) == NULL)
+ if ((queue = SMB_MALLOC_ARRAY(print_queue_struct, qcount + extra_count)) == NULL)
goto out;
/* Retrieve the linearised queue data. */
if (!p) {
/* Create one. */
- p = (struct tdb_print_db *)malloc(sizeof(struct tdb_print_db));
+ p = SMB_MALLOC_P(struct tdb_print_db);
if (!p) {
DEBUG(0,("get_print_db: malloc fail !\n"));
return NULL;
/* prepend the string with a '\' character */
len = strlen( keyname );
- if ( !(key = malloc( len + 2 )) ) {
+ if ( !(key = SMB_MALLOC( len + 2 )) ) {
DEBUG(0,("reghook_cache_find: malloc failed for string [%s] !?!?!\n",
keyname));
return NULL;
/* allocate some initial memory */
- buffer = malloc(sizeof(pstring));
+ buffer = SMB_MALLOC(sizeof(pstring));
buflen = sizeof(pstring);
len = 0;
len += tdb_pack( buffer+len, buflen-len, "f", regsubkey_ctr_specific_key(ctr, i) );
if ( len > buflen ) {
/* allocate some extra space */
- if ((tmpbuf = Realloc( buffer, len*2 )) == NULL) {
+ if ((tmpbuf = SMB_REALLOC( buffer, len*2 )) == NULL) {
DEBUG(0,("regdb_store_reg_keys: Failed to realloc memory of size [%d]\n", len*2));
ret = False;
goto done;
if ( !(s = regsubkey_ctr_specific_key( &ctr, key_index )) )
return False;
- *subkey = strdup( s );
+ *subkey = SMB_STRDUP( s );
return True;
}
/* allocate a space for the char* in the array */
if ( ctr->subkeys == 0 )
- ctr->subkeys = talloc( ctr->ctx, sizeof(char*) );
+ ctr->subkeys = TALLOC_P( ctr->ctx, char *);
else {
- pp = talloc_realloc( ctr->ctx, ctr->subkeys, sizeof(char*)*(ctr->num_subkeys+1) );
+ pp = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->subkeys, char *, ctr->num_subkeys+1);
if ( pp )
ctr->subkeys = pp;
}
/* allocate the string and save it in the array */
- ctr->subkeys[ctr->num_subkeys] = talloc( ctr->ctx, len+1 );
+ ctr->subkeys[ctr->num_subkeys] = TALLOC( ctr->ctx, len+1 );
strncpy( ctr->subkeys[ctr->num_subkeys], keyname, len+1 );
ctr->num_subkeys++;
}
if ( !val )
return NULL;
- if ( !(copy = malloc( sizeof(REGISTRY_VALUE) )) ) {
+ if ( !(copy = SMB_MALLOC_P( REGISTRY_VALUE)) ) {
DEBUG(0,("dup_registry_value: malloc() failed!\n"));
return NULL;
}
/* allocate a slot in the array of pointers */
if ( ctr->num_values == 0 )
- ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) );
+ ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *);
else {
- ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) );
+ ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 );
if ( ppreg )
ctr->values = ppreg;
}
/* allocate a new value and store the pointer in the arrya */
- ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) );
+ ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE);
/* init the value */
fstrcpy( ctr->values[ctr->num_values]->valuename, name );
ctr->values[ctr->num_values]->type = type;
- ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, data_p, size );
+ ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, data_p, size );
ctr->values[ctr->num_values]->size = size;
ctr->num_values++;
}
/* allocate a slot in the array of pointers */
if ( ctr->num_values == 0 )
- ctr->values = talloc( ctr->ctx, sizeof(REGISTRY_VALUE*) );
+ ctr->values = TALLOC_P( ctr->ctx, REGISTRY_VALUE *);
else {
- ppreg = talloc_realloc( ctr->ctx, ctr->values, sizeof(REGISTRY_VALUE*)*(ctr->num_values+1) );
+ ppreg = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->values, REGISTRY_VALUE *, ctr->num_values+1 );
if ( ppreg )
ctr->values = ppreg;
}
/* allocate a new value and store the pointer in the arrya */
- ctr->values[ctr->num_values] = talloc( ctr->ctx, sizeof(REGISTRY_VALUE) );
+ ctr->values[ctr->num_values] = TALLOC_P( ctr->ctx, REGISTRY_VALUE);
/* init the value */
fstrcpy( ctr->values[ctr->num_values]->valuename, val->valuename );
ctr->values[ctr->num_values]->type = val->type;
- ctr->values[ctr->num_values]->data_p = talloc_memdup( ctr->ctx, val->data_p, val->size );
+ ctr->values[ctr->num_values]->data_p = TALLOC_MEMDUP( ctr->ctx, val->data_p, val->size );
ctr->values[ctr->num_values]->size = val->size;
ctr->num_values++;
}
p++;
if ( *p )
- return strdup(p);
+ return SMB_STRDUP(p);
else
return NULL;
}
/* we are dealing with a subkey of "Environments */
- key2 = strdup( key );
+ key2 = SMB_STRDUP( key );
keystr = key2;
reg_split_path( keystr, &base, &new_path );
/* env */
- key2 = strdup( key );
+ key2 = SMB_STRDUP( key );
keystr = key2;
reg_split_path( keystr, &base, &new_path );
if ( !base || !new_path )
length = strlen(filename);
- buffer2 = Realloc( buffer, buffer_size + (length + 1)*sizeof(uint16) );
+ buffer2 = SMB_REALLOC( buffer, buffer_size + (length + 1)*sizeof(uint16) );
if ( !buffer2 )
break;
buffer = buffer2;
/* terminated by double NULL. Add the final one here */
- buffer2 = Realloc( buffer, buffer_size + 2 );
+ buffer2 = SMB_REALLOC( buffer, buffer_size + 2 );
if ( !buffer2 ) {
SAFE_FREE( buffer );
buffer_size = 0;
/* get information for a specific printer */
- key2 = strdup( key );
+ key2 = SMB_STRDUP( key );
keystr = key2;
reg_split_path( keystr, &base, &new_path );
goto done;
}
- key2 = strdup( key );
+ key2 = SMB_STRDUP( key );
keystr = key2;
reg_split_path( keystr, &base, &new_path );
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
q.level = level;
result = r.status;
if ( r.ptr && ctr ) {
- ctr->basic = talloc(mem_ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
+ ctr->basic = TALLOC_P(mem_ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC);
if (!ctr->basic)
goto done;
memcpy(ctr->basic, r.info.basic, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
init_q_ds_enum_domain_trusts( &q, server, flags );
int i;
*num_domains = r.num_domains;
- *trusts = (struct ds_domain_trust*)talloc(mem_ctx, r.num_domains*sizeof(**trusts));
+ *trusts = TALLOC_ARRAY(mem_ctx, struct ds_domain_trust, r.num_domains);
for ( i=0; i< *num_domains; i++ ) {
(*trusts)[i].flags = r.domains.trusts[i].flags;
return result;
}
-
-
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
/* Marshall data and send request */
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
/* Marshall data and send request */
result = True;
if (out_data) {
- *out_data = talloc(mem_ctx, size);
+ *out_data = TALLOC(mem_ctx, size);
memcpy(*out_data, r.data, size);
}
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
/* Marshall data and send request */
/* Initialise parse structures */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL)) {
+ return NT_STATUS_NO_MEMORY;
+ }
+ if (!prs_init(&rbuf, 0, mem_ctx, UNMARSHALL)) {
+ prs_mem_free(&qbuf);
+ return NT_STATUS_NO_MEMORY;
+ }
/* Marshall data and send request */
if (NT_STATUS_IS_OK(result = r.status)) {
*pol = r.pol;
#ifdef __INSURE__
- pol->marker = malloc(1);
+ pol->marker = MALLOC(1);
#endif
}
goto done;
}
- if (!((*domains) = (char **)talloc(mem_ctx, sizeof(char *) *
- num_sids))) {
+ if (!((*domains) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*names) = (char **)talloc(mem_ctx, sizeof(char *) *
- num_sids))) {
+ if (!((*names) = TALLOC_ARRAY(mem_ctx, char *, num_sids))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*types) = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- num_sids))) {
+ if (!((*types) = TALLOC_ARRAY(mem_ctx, uint32, num_sids))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
goto done;
}
- if (!((*sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
- num_names)))) {
+ if (!((*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_names)))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*types = (uint32 *)talloc(mem_ctx, sizeof(uint32) *
- num_names)))) {
+ if (!((*types = TALLOC_ARRAY(mem_ctx, uint32, num_names)))) {
DEBUG(0, ("cli_lsa_lookup_sids(): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
if (domain_sid && (r.dom.id3.buffer_dom_sid != 0)) {
- *domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+ *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
if (*domain_sid) {
sid_copy(*domain_sid, &r.dom.id3.dom_sid.sid);
}
}
if (domain_sid && (r.dom.id5.buffer_dom_sid != 0)) {
- *domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+ *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
if (*domain_sid) {
sid_copy(*domain_sid, &r.dom.id5.dom_sid.sid);
}
}
if (domain_guid) {
- *domain_guid = talloc(mem_ctx, sizeof(**domain_guid));
+ *domain_guid = TALLOC_P(mem_ctx, struct uuid);
memcpy(*domain_guid,
&r.info.dns_dom_info.dom_guid,
sizeof(struct uuid));
}
if (domain_sid && r.info.dns_dom_info.ptr_dom_sid != 0) {
- *domain_sid = talloc(mem_ctx, sizeof(**domain_sid));
+ *domain_sid = TALLOC_P(mem_ctx, DOM_SID);
if (*domain_sid) {
sid_copy(*domain_sid,
&r.info.dns_dom_info.dom_sid.sid);
/* Allocate memory for trusted domain names and sids */
- *domain_names = (char **)talloc(mem_ctx, sizeof(char *) *
- r.num_domains);
+ *domain_names = TALLOC_ARRAY(mem_ctx, char *, r.num_domains);
if (!*domain_names) {
DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
goto done;
}
- *domain_sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) *
- r.num_domains);
+ *domain_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.num_domains);
if (!domain_sids) {
DEBUG(0, ("cli_lsa_enum_trust_dom(): out of memory\n"));
result = NT_STATUS_NO_MEMORY;
*enum_context = r.enum_context;
*count = r.count;
- if (!((*privs_name = (char **)talloc(mem_ctx, sizeof(char *) * r.count)))) {
+ if (!((*privs_name = TALLOC_ARRAY(mem_ctx, char *, r.count)))) {
DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*privs_high = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
+ if (!((*privs_high = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
- if (!((*privs_low = (uint32 *)talloc(mem_ctx, sizeof(uint32) * r.count)))) {
+ if (!((*privs_low = TALLOC_ARRAY(mem_ctx, uint32, r.count)))) {
DEBUG(0, ("(cli_lsa_enum_privilege): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
/* Return output parameters */
- *sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * r.sids.num_entries);
+ *sids = TALLOC_ARRAY(mem_ctx, DOM_SID, r.sids.num_entries);
if (!*sids) {
DEBUG(0, ("(cli_lsa_enum_sids): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
if (r.count == 0)
goto done;
- if (!((*set = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR) * r.count)))) {
+ if (!((*set = TALLOC_ARRAY(mem_ctx, LUID_ATTR, r.count)))) {
DEBUG(0, ("(cli_lsa_enum_privsaccount): out of memory\n"));
result = NT_STATUS_UNSUCCESSFUL;
goto done;
goto done;
}
- *privs_name = (char **)talloc(mem_ctx, (*count) * sizeof(char **));
+ *privs_name = TALLOC_ARRAY(mem_ctx, char *, *count);
for (i=0;i<*count;i++) {
pull_ucs2_talloc(mem_ctx, &(*privs_name)[i], r.rights.strings[i].string.buffer);
}
if (r.num_entries2) {
/* allocate memory needed to return received data */
- *rids = (uint32*)talloc(mem_ctx, sizeof(uint32) * r.num_entries2);
+ *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_entries2);
if (!*rids) {
DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
return NT_STATUS_NO_MEMORY;
}
- *dom_users = (char**)talloc(mem_ctx, sizeof(char*) * r.num_entries2);
+ *dom_users = TALLOC_ARRAY(mem_ctx, char*, r.num_entries2);
if (!*dom_users) {
DEBUG(0, ("Error in cli_samr_enum_dom_users(): out of memory\n"));
return NT_STATUS_NO_MEMORY;
if (*num_dom_groups == 0)
goto done;
- if (!((*dom_groups) = (struct acct_info *)
- talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_groups))) {
+ if (!((*dom_groups) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_groups))) {
result = NT_STATUS_NO_MEMORY;
goto done;
}
if (*num_dom_aliases == 0)
goto done;
- if (!((*dom_aliases) = (struct acct_info *)
- talloc(mem_ctx, sizeof(struct acct_info) * *num_dom_aliases))) {
+ if (!((*dom_aliases) = TALLOC_ARRAY(mem_ctx, struct acct_info, *num_dom_aliases))) {
result = NT_STATUS_NO_MEMORY;
goto done;
}
goto done;
}
- if (!(*sids = talloc(mem_ctx, sizeof(DOM_SID) * *num_mem))) {
+ if (!(*sids = TALLOC_ARRAY(mem_ctx, DOM_SID, *num_mem))) {
result = NT_STATUS_UNSUCCESSFUL;
goto done;
}
}
*num_names = r.num_names1;
- *names = talloc(mem_ctx, sizeof(char *) * r.num_names1);
- *name_types = talloc(mem_ctx, sizeof(uint32) * r.num_names1);
+ *names = TALLOC_ARRAY(mem_ctx, char *, r.num_names1);
+ *name_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_names1);
for (i = 0; i < r.num_names1; i++) {
fstring tmp;
}
*num_rids = r.num_rids1;
- *rids = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
- *rid_types = talloc(mem_ctx, sizeof(uint32) * r.num_rids1);
+ *rids = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
+ *rid_types = TALLOC_ARRAY(mem_ctx, uint32, r.num_rids1);
for (i = 0; i < r.num_rids1; i++) {
(*rids)[i] = r.rids[i];
uint32 i;
PRINTER_INFO_0 *inf;
- inf=(PRINTER_INFO_0 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_0));
+ inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_0, returned);
memset(inf, 0, returned*sizeof(PRINTER_INFO_0));
prs_set_offset(&buffer->prs,0);
uint32 i;
PRINTER_INFO_1 *inf;
- inf=(PRINTER_INFO_1 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_1));
+ inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_1, returned);
memset(inf, 0, returned*sizeof(PRINTER_INFO_1));
prs_set_offset(&buffer->prs,0);
uint32 i;
PRINTER_INFO_2 *inf;
- inf=(PRINTER_INFO_2 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_2));
+ inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_2, returned);
memset(inf, 0, returned*sizeof(PRINTER_INFO_2));
prs_set_offset(&buffer->prs,0);
uint32 i;
PRINTER_INFO_3 *inf;
- inf=(PRINTER_INFO_3 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_3));
+ inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_3, returned);
memset(inf, 0, returned*sizeof(PRINTER_INFO_3));
prs_set_offset(&buffer->prs,0);
uint32 i;
PRINTER_INFO_7 *inf;
- inf=(PRINTER_INFO_7 *)talloc(mem_ctx, returned*sizeof(PRINTER_INFO_7));
+ inf=TALLOC_ARRAY(mem_ctx, PRINTER_INFO_7, returned);
memset(inf, 0, returned*sizeof(PRINTER_INFO_7));
prs_set_offset(&buffer->prs,0);
uint32 i;
PORT_INFO_1 *inf;
- inf=(PORT_INFO_1*)talloc(mem_ctx, returned*sizeof(PORT_INFO_1));
+ inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_1, returned);
memset(inf, 0, returned*sizeof(PORT_INFO_1));
prs_set_offset(&buffer->prs, 0);
uint32 i;
PORT_INFO_2 *inf;
- inf=(PORT_INFO_2*)talloc(mem_ctx, returned*sizeof(PORT_INFO_2));
+ inf=TALLOC_ARRAY(mem_ctx, PORT_INFO_2, returned);
memset(inf, 0, returned*sizeof(PORT_INFO_2));
prs_set_offset(&buffer->prs, 0);
uint32 i;
DRIVER_INFO_1 *inf;
- inf=(DRIVER_INFO_1 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_1));
+ inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_1, returned);
memset(inf, 0, returned*sizeof(DRIVER_INFO_1));
prs_set_offset(&buffer->prs,0);
uint32 i;
DRIVER_INFO_2 *inf;
- inf=(DRIVER_INFO_2 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_2));
+ inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_2, returned);
memset(inf, 0, returned*sizeof(DRIVER_INFO_2));
prs_set_offset(&buffer->prs,0);
uint32 i;
DRIVER_INFO_3 *inf;
- inf=(DRIVER_INFO_3 *)talloc(mem_ctx, returned*sizeof(DRIVER_INFO_3));
+ inf=TALLOC_ARRAY(mem_ctx, DRIVER_INFO_3, returned);
memset(inf, 0, returned*sizeof(DRIVER_INFO_3));
prs_set_offset(&buffer->prs,0);
{
DRIVER_DIRECTORY_1 *inf;
- inf=(DRIVER_DIRECTORY_1 *)talloc(mem_ctx, sizeof(DRIVER_DIRECTORY_1));
+ inf=TALLOC_P(mem_ctx, DRIVER_DIRECTORY_1);
memset(inf, 0, sizeof(DRIVER_DIRECTORY_1));
prs_set_offset(&buffer->prs, 0);
{
int i;
- *forms = (FORM_1 *)talloc(mem_ctx, num_forms * sizeof(FORM_1));
+ *forms = TALLOC_ARRAY(mem_ctx, FORM_1, num_forms);
prs_set_offset(&buffer->prs,0);
for (i = 0; i < num_forms; i++)
{
uint32 i;
- *jobs = (JOB_INFO_1 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_1));
+ *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_1, num_jobs);
prs_set_offset(&buffer->prs,0);
for (i = 0; i < num_jobs; i++)
{
uint32 i;
- *jobs = (JOB_INFO_2 *)talloc(mem_ctx, num_jobs * sizeof(JOB_INFO_2));
+ *jobs = TALLOC_ARRAY(mem_ctx, JOB_INFO_2, num_jobs);
prs_set_offset(&buffer->prs,0);
for (i = 0; i < num_jobs; i++)
/* Return output parameters */
- value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
+ value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
value->type = r.type;
value->size = r.size;
/* Return output parameters */
- value->data_p = talloc_memdup(mem_ctx, r.data, r.needed);
+ value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.needed);
value->type = r.type;
value->size = r.needed;
if (value) {
rpcstr_pull(value->valuename, r.value, sizeof(value->valuename), -1,
STR_TERMINATE);
- value->data_p = talloc_memdup(mem_ctx, r.data, r.realdatasize);
+ value->data_p = TALLOC_MEMDUP(mem_ctx, r.data, r.realdatasize);
value->type = r.type;
value->size = r.realdatasize;
}
/* Copy results */
if (keylist) {
- *keylist = (uint16 *)malloc(r.keys.buf_len * 2);
+ *keylist = SMB_MALLOC_ARRAY(uint16, r.keys.buf_len);
memcpy(*keylist, r.keys.buffer, r.keys.buf_len * 2);
if (len)
*len = r.keys.buf_len * 2;
switch(info_level) {
case 1:
- ctr->share.info1 = (SRV_SHARE_INFO_1 *)talloc(
- mem_ctx, sizeof(SRV_SHARE_INFO_1) * ctr->num_entries);
+ ctr->share.info1 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_1, ctr->num_entries);
memset(ctr->share.info1, 0, sizeof(SRV_SHARE_INFO_1));
break;
case 2:
- ctr->share.info2 = (SRV_SHARE_INFO_2 *)talloc(
- mem_ctx, sizeof(SRV_SHARE_INFO_2) * ctr->num_entries);
+ ctr->share.info2 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_2, ctr->num_entries);
memset(ctr->share.info2, 0, sizeof(SRV_SHARE_INFO_2));
break;
/* adding info-level 502 here */
case 502:
- ctr->share.info502 = (SRV_SHARE_INFO_502 *)talloc(
- mem_ctx, sizeof(SRV_SHARE_INFO_502) * ctr->num_entries);
+ ctr->share.info502 = TALLOC_ARRAY(mem_ctx, SRV_SHARE_INFO_502, ctr->num_entries);
memset(ctr->share.info502, 0, sizeof(SRV_SHARE_INFO_502));
switch(file_level) {
case 3:
- ctr->file.info3 = (SRV_FILE_INFO_3 *)talloc(
- mem_ctx, sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
+ ctr->file.info3 = TALLOC_ARRAY(mem_ctx, SRV_FILE_INFO_3, ctr->num_entries);
memset(ctr->file.info3, 0,
sizeof(SRV_FILE_INFO_3) * ctr->num_entries);
depth++;
/* should depend on whether marshalling or unmarshalling! */
if(UNMARSHALLING(ps)) {
- ctr->dfs.info1 = (DFS_INFO_1 *)prs_alloc_mem(ps, sizeof(DFS_INFO_1)*num_entries);
+ ctr->dfs.info1 = PRS_ALLOC_MEM(ps, DFS_INFO_1, num_entries);
if (!ctr->dfs.info1)
return False;
}
case 2:
depth++;
if(UNMARSHALLING(ps)) {
- ctr->dfs.info2 = (DFS_INFO_2 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_2));
+ ctr->dfs.info2 = PRS_ALLOC_MEM(ps, DFS_INFO_2, num_entries);
if (!ctr->dfs.info2)
return False;
}
case 3:
depth++;
if(UNMARSHALLING(ps)) {
- ctr->dfs.info3 = (DFS_INFO_3 *)prs_alloc_mem(ps, num_entries*sizeof(DFS_INFO_3));
+ ctr->dfs.info3 = PRS_ALLOC_MEM(ps, DFS_INFO_3, num_entries);
if (!ctr->dfs.info3)
return False;
}
depth++;
if(UNMARSHALLING(ps)) {
- info3->storages = (DFS_STORAGE_INFO *)prs_alloc_mem(ps, info3->num_storage_infos*sizeof(DFS_STORAGE_INFO));
+ info3->storages = PRS_ALLOC_MEM(ps, DFS_STORAGE_INFO, info3->num_storage_infos);
if (!info3->storages)
return False;
}
DSROLE_PRIMARY_DOMAIN_INFO_BASIC *p = *basic;
if ( UNMARSHALLING(ps) )
- p = *basic = (DSROLE_PRIMARY_DOMAIN_INFO_BASIC *)prs_alloc_mem(ps, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC));
+ p = *basic = PRS_ALLOC_MEM(ps, DSROLE_PRIMARY_DOMAIN_INFO_BASIC, 1);
if ( !p )
return False;
/* allocate the domain trusts array are parse it */
- ctr->trusts = (DS_DOMAIN_TRUSTS*)talloc(ps->mem_ctx, sizeof(DS_DOMAIN_TRUSTS)*ctr->max_count);
+ ctr->trusts = TALLOC_ARRAY(ps->mem_ctx, DS_DOMAIN_TRUSTS, ctr->max_count);
if ( !ctr->trusts )
return False;
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
return False;
if (UNMARSHALLING(ps)) {
- q_d->data = prs_alloc_mem(ps, q_d->size);
+ q_d->data = PRS_ALLOC_MEM(ps, char, q_d->size);
if (!q_d->data)
return False;
if (attr->ptr_sec_qos != 0) {
if (UNMARSHALLING(ps))
- if (!(attr->sec_qos = (LSA_SEC_QOS *)prs_alloc_mem(ps,sizeof(LSA_SEC_QOS))))
+ if (!(attr->sec_qos = PRS_ALLOC_MEM(ps,LSA_SEC_QOS,1)))
return False;
if(!lsa_io_sec_qos("sec_qos", attr->sec_qos, ps, depth))
* allocating empty arrays of unicode headers, strings
* and sids of enumerated trusted domains
*/
- if (!(r_e->hdr_domain_name = (UNIHDR2 *)talloc(ctx,sizeof(UNIHDR2) * num_domains))) {
+ if (!(r_e->hdr_domain_name = TALLOC_ARRAY(ctx,UNIHDR2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
- if (!(r_e->uni_domain_name = (UNISTR2 *)talloc(ctx,sizeof(UNISTR2) * num_domains))) {
+ if (!(r_e->uni_domain_name = TALLOC_ARRAY(ctx,UNISTR2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
- if (!(r_e->domain_sid = (DOM_SID2 *)talloc(ctx,sizeof(DOM_SID2) * num_domains))) {
+ if (!(r_e->domain_sid = TALLOC_ARRAY(ctx,DOM_SID2,num_domains))) {
r_e->status = NT_STATUS_NO_MEMORY;
return;
}
num_domains = r_e->num_domains2;
if (UNMARSHALLING(ps)) {
- if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
+ if (!(r_e->hdr_domain_name = PRS_ALLOC_MEM(ps,UNIHDR2,num_domains)))
return False;
- if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
+ if (!(r_e->uni_domain_name = PRS_ALLOC_MEM(ps,UNISTR2,num_domains)))
return False;
- if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
+ if (!(r_e->domain_sid = PRS_ALLOC_MEM(ps,DOM_SID2,num_domains)))
return False;
}
return False;
if (UNMARSHALLING(ps)) {
- d_q->auditsettings = (uint32 *)talloc_zero(ps->mem_ctx, d_q->count2 * sizeof(uint32));
+ d_q->auditsettings = TALLOC_ZERO_ARRAY(ps->mem_ctx, uint32, d_q->count2);
}
if (d_q->auditsettings == NULL) {
if (num_entries == 0) return;
- if ((sen->ptr_sid = (uint32 *)talloc_zero(mem_ctx, num_entries *
- sizeof(uint32))) == NULL) {
+ if ((sen->ptr_sid = TALLOC_ZERO_ARRAY(mem_ctx, uint32, num_entries )) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for ptr_sid\n"));
return;
}
- if ((sen->sid = (DOM_SID2 *)talloc_zero(mem_ctx, num_entries *
- sizeof(DOM_SID2))) == NULL) {
+ if ((sen->sid = TALLOC_ZERO_ARRAY(mem_ctx, DOM_SID2, num_entries)) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for sids\n"));
return;
}
/* Mallocate memory if we're unpacking from the wire */
if (UNMARSHALLING(ps)) {
- if ((sen->ptr_sid = (uint32 *)prs_alloc_mem( ps,
- sen->num_entries * sizeof(uint32))) == NULL) {
+ if ((sen->ptr_sid = PRS_ALLOC_MEM( ps, uint32, sen->num_entries)) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"ptr_sid\n"));
return False;
}
- if ((sen->sid = (DOM_SID2 *)prs_alloc_mem( ps,
- sen->num_entries * sizeof(DOM_SID2))) == NULL) {
+ if ((sen->sid = PRS_ALLOC_MEM( ps, DOM_SID2, sen->num_entries)) == NULL) {
DEBUG(3, ("init_lsa_sid_enum(): out of memory for "
"sids\n"));
return False;
return False;
if (UNMARSHALLING(ps)) {
- if ((trn->name = (LSA_TRANS_NAME *)
- prs_alloc_mem(ps, trn->num_entries *
- sizeof(LSA_TRANS_NAME))) == NULL) {
+ if ((trn->name = PRS_ALLOC_MEM(ps, LSA_TRANS_NAME, trn->num_entries)) == NULL) {
return False;
}
- if ((trn->uni_name = (UNISTR2 *)
- prs_alloc_mem(ps, trn->num_entries *
- sizeof(UNISTR2))) == NULL) {
+ if ((trn->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, trn->num_entries)) == NULL) {
return False;
}
}
q_l->num_entries2 = num_names;
q_l->lookup_level = 1;
- if ((q_l->uni_name = (UNISTR2 *)talloc_zero(
- mem_ctx, num_names * sizeof(UNISTR2))) == NULL) {
+ if ((q_l->uni_name = TALLOC_ZERO_ARRAY(mem_ctx, UNISTR2, num_names)) == NULL) {
DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
return;
}
- if ((q_l->hdr_name = (UNIHDR *)talloc_zero(
- mem_ctx, num_names * sizeof(UNIHDR))) == NULL) {
+ if ((q_l->hdr_name = TALLOC_ZERO_ARRAY(mem_ctx, UNIHDR, num_names)) == NULL) {
DEBUG(3, ("init_q_lookup_names(): out of memory\n"));
return;
}
if (UNMARSHALLING(ps)) {
if (q_r->num_entries) {
- if ((q_r->hdr_name = (UNIHDR *)prs_alloc_mem(ps,
- q_r->num_entries * sizeof(UNIHDR))) == NULL)
+ if ((q_r->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_r->num_entries)) == NULL)
return False;
- if ((q_r->uni_name = (UNISTR2 *)prs_alloc_mem(ps,
- q_r->num_entries * sizeof(UNISTR2))) == NULL)
+ if ((q_r->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_r->num_entries)) == NULL)
return False;
}
}
}
if (UNMARSHALLING(ps)) {
- if ((r_r->dom_rid = (DOM_RID2 *)prs_alloc_mem(ps, r_r->num_entries2 * sizeof(DOM_RID2)))
+ if ((r_r->dom_rid = PRS_ALLOC_MEM(ps, DOM_RID2, r_r->num_entries2))
== NULL) {
DEBUG(3, ("lsa_io_r_lookup_names(): out of memory\n"));
return False;
return False;
if (UNMARSHALLING(ps))
- if (!(r_q->privs = (LSA_PRIV_ENTRY *)prs_alloc_mem(ps, sizeof(LSA_PRIV_ENTRY) * r_q->count1)))
+ if (!(r_q->privs = PRS_ALLOC_MEM(ps, LSA_PRIV_ENTRY, r_q->count1)))
return False;
if (!lsa_io_priv_entries("", r_q->privs, r_q->count1, ps, depth))
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps,sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps,LUID_ATTR,r_c->count)))
return False;
}
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
return False;
}
if (!NT_STATUS_IS_OK(init_priv_with_ctx(ps->mem_ctx, &(r_c->set))))
return False;
- if (!(r_c->set->set = (LUID_ATTR *)prs_alloc_mem(ps, sizeof(LUID_ATTR) * r_c->count)))
+ if (!(r_c->set->set = PRS_ALLOC_MEM(ps, LUID_ATTR, r_c->count)))
return False;
}
return;
}
-
len = strlen(buf) + 1;
+ len = MAX(len,MAX_UNISTRLEN);
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+ str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
if (str->buffer == NULL)
smb_panic("init_unistr: malloc fail\n");
- rpcstr_push(str->buffer, buf, len, STR_TERMINATE);
+ rpcstr_push(str->buffer, buf, len*sizeof(uint16), STR_TERMINATE);
}
/*******************************************************************
static void create_buffer3(BUFFER3 *str, size_t len)
{
- if (len < MAX_BUFFERLEN)
- len = MAX_BUFFERLEN;
+ len = MAX(len,MAX_BUFFERLEN);
- str->buffer = talloc_zero(get_talloc_ctx(), len);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
if (str->buffer == NULL)
smb_panic("create_buffer3: talloc fail\n");
return False;
if (UNMARSHALLING(ps)) {
- buf3->buffer = (unsigned char *)prs_alloc_mem(ps, buf3->buf_max_len);
+ buf3->buffer = PRS_ALLOC_MEM(ps, unsigned char, buf3->buf_max_len);
if (buf3->buffer == NULL)
return False;
}
str->buf_len = buf != NULL ? len : 0;
if (buf != NULL) {
- if (len < MAX_BUFFERLEN)
- len = MAX_BUFFERLEN;
- str->buffer = talloc_zero(get_talloc_ctx(), len);
+ len = MAX(len,MAX_BUFFERLEN);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), len);
if (str->buffer == NULL)
smb_panic("init_buffer2: talloc fail\n");
memcpy(str->buffer, buf, MIN(str->buf_len, len));
(the the length of the source string) to prevent
reallocation of memory. */
if (str->buffer == NULL) {
- size_t len = from->uni_max_len * sizeof(uint16);
-
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
- if ((str->buffer == NULL) && (len > 0 )) {
+ size_t alloc_len = MAX(from->uni_max_len,MAX_UNISTRLEN);
+ str->buffer = (uint16 *)TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
+ if ((str->buffer == NULL)) {
smb_panic("copy_unistr2: talloc fail\n");
return;
}
void init_string2(STRING2 *str, const char *buf, int max_len, int str_len)
{
- int alloc_len = 0;
-
/* set up string lengths. */
str->str_max_len = max_len;
str->offset = 0;
/* store the string */
if(str_len != 0) {
- if (str_len < MAX_STRINGLEN)
- alloc_len = MAX_STRINGLEN;
- str->buffer = talloc_zero(get_talloc_ctx(), alloc_len);
+ int alloc_len = MAX(str_len, MAX_STRINGLEN);
+ str->buffer = TALLOC_ZERO(get_talloc_ctx(), alloc_len);
if (str->buffer == NULL)
smb_panic("init_string2: malloc fail\n");
memcpy(str->buffer, buf, str_len);
len = strlen(buf) + 1;
}
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
- len *= sizeof(uint16);
+ len = MAX(len,MAX_UNISTRLEN);
- str->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
- if ((str->buffer == NULL) && (len > 0)) {
+ str->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, len);
+ if (str->buffer == NULL) {
smb_panic("init_unistr2: malloc fail\n");
return;
}
+ /* Ensure len is the length in *bytes* */
+ len *= sizeof(uint16);
+
/*
* The UNISTR2 must be initialized !!!
* jfm, 7/7/2001.
void init_unistr2_w(TALLOC_CTX *ctx, UNISTR2 *str, const smb_ucs2_t *buf)
{
uint32 len = strlen_w(buf);
- uint32 max_len = len;
uint32 alloc_len;
ZERO_STRUCTP(str);
str->offset = 0;
str->uni_str_len = len;
- if (max_len < MAX_UNISTRLEN)
- max_len = MAX_UNISTRLEN;
+ alloc_len = MAX((len + 1), MAX_UNISTRLEN);
- alloc_len = (max_len + 1) * sizeof(uint16);
-
- str->buffer = (uint16 *)talloc_zero(ctx, alloc_len);
- if ((str->buffer == NULL) && (alloc_len > 0)) {
+ str->buffer = TALLOC_ZERO_ARRAY(ctx, uint16, alloc_len);
+ if (str->buffer == NULL) {
smb_panic("init_unistr2_w: malloc fail\n");
return;
}
to->uni_str_len = i;
/* allocate the space and copy the string buffer */
- to->buffer = (uint16 *)talloc_zero(get_talloc_ctx(), sizeof(uint16)*(to->uni_str_len));
+ to->buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, i);
if (to->buffer == NULL)
smb_panic("init_unistr2_from_unistr: malloc fail\n");
- memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
+ memcpy(to->buffer, from->buffer, i*sizeof(uint16));
return;
}
return True;
}
- array->strings = (UNISTR2_ARRAY_EL *)talloc_zero(get_talloc_ctx(), count * sizeof(UNISTR2_ARRAY_EL));
+ array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, count );
if (!array->strings) {
return False;
}
}
if (UNMARSHALLING(ps)) {
- array->strings = talloc_zero(get_talloc_ctx(), array->count * sizeof(array->strings[0]));
+ array->strings = TALLOC_ZERO_ARRAY(get_talloc_ctx(), UNISTR2_ARRAY_EL, array->count );
}
if (! array->strings) {
return False;
void init_unistr3(UNISTR3 *str, const char *buf)
{
- size_t len;
+ size_t len, alloc_len;
if (buf == NULL) {
str->uni_str_len=0;
str->uni_str_len=len;
- if (len < MAX_UNISTRLEN)
- len = MAX_UNISTRLEN;
-
- len *= sizeof(uint16);
+ alloc_len = MAX(len, MAX_UNISTRLEN);
- str->str.buffer = (uint16 *)talloc_zero(get_talloc_ctx(), len);
+ str->str.buffer = TALLOC_ZERO_ARRAY(get_talloc_ctx(), uint16, alloc_len);
if (str->str.buffer == NULL)
smb_panic("init_unistr3: malloc fail\n");
- rpcstr_push((char *)str->str.buffer, buf, len, STR_TERMINATE);
+ rpcstr_push((char *)str->str.buffer, buf, len * sizeof(uint16), STR_TERMINATE);
}
/*******************************************************************
}
/* Now allocate space for them. */
- *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
+ *ppsids = TALLOC_ZERO_ARRAY(ctx, DOM_SID2, count);
if (*ppsids == NULL)
return 0;
depth++;
if (UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, NET_ID_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
usr->num_groups2 = num_groups;
- usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * (num_groups));
+ usr->gids = TALLOC_ZERO_ARRAY(ctx,DOM_GID,num_groups);
if (usr->gids == NULL && num_groups>0)
return;
return False;
if (UNMARSHALLING(ps) && usr->num_groups2 > 0) {
- usr->gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_groups2);
+ usr->gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_groups2);
if (usr->gids == NULL)
return False;
}
if (usr->num_other_sids) {
if (UNMARSHALLING(ps)) {
- usr->other_sids = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(DOM_SID2)*usr->num_other_sids);
+ usr->other_sids = PRS_ALLOC_MEM(ps, DOM_SID2, usr->num_other_sids);
if (usr->other_sids == NULL)
return False;
}
return False;
if (UNMARSHALLING(ps) && usr->num_other_groups > 0) {
- usr->other_gids = (DOM_GID *)prs_alloc_mem(ps, sizeof(DOM_GID)*usr->num_other_groups);
+ usr->other_gids = PRS_ALLOC_MEM(ps, DOM_GID, usr->num_other_groups);
if (usr->other_gids == NULL)
return False;
}
return False;
}
- info->rids = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_members2);
+ info->rids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members2);
if (info->rids == NULL) {
DEBUG(0, ("out of memory allocating %d rids\n",
return False;
}
- info->attribs = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_members3);
+ info->attribs = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_members3);
if (info->attribs == NULL) {
DEBUG(0, ("out of memory allocating %d attribs\n",
return False;
}
- info->ptr_sids = talloc(ps->mem_ctx, sizeof(uint32) *
- info->num_sids);
+ info->ptr_sids = TALLOC_ARRAY(ps->mem_ctx, uint32, info->num_sids);
if (info->ptr_sids == NULL) {
DEBUG(0, ("out of memory allocating %d ptr_sids\n",
return False;
}
- info->sids = talloc(ps->mem_ctx, sizeof(DOM_SID2) *
- info->num_sids);
+ info->sids = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, info->num_sids);
if (info->sids == NULL) {
DEBUG(0, ("error allocating %d sids\n",
if(!prs_uint32("attribute_count", ps, depth, &info->attribute_count))
return False;
- info->attributes = talloc(ps->mem_ctx, sizeof(uint32) * info->attribute_count);
+ info->attributes = TALLOC_ARRAY(ps->mem_ctx, uint32, info->attribute_count);
for (i=0; i<info->attribute_count; i++)
if(!prs_uint32("attributes", ps, depth, &info->attributes[i]))
if(!prs_uint32("privlist_count", ps, depth, &info->privlist_count))
return False;
- info->hdr_privslist = talloc(ps->mem_ctx, sizeof(UNIHDR) * info->privlist_count);
- info->uni_privslist = talloc(ps->mem_ctx, sizeof(UNISTR2) * info->privlist_count);
+ info->hdr_privslist = TALLOC_ARRAY(ps->mem_ctx, UNIHDR, info->privlist_count);
+ info->uni_privslist = TALLOC_ARRAY(ps->mem_ctx, UNISTR2, info->privlist_count);
for (i=0; i<info->privlist_count; i++)
if(!smb_io_unihdr("hdr_privslist", &info->hdr_privslist[i], ps, depth))
}
if (r_s->num_deltas2 > 0) {
- r_s->hdr_deltas = (SAM_DELTA_HDR *)
- talloc(ps->mem_ctx, r_s->num_deltas2 *
- sizeof(SAM_DELTA_HDR));
-
+ r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas2);
if (r_s->hdr_deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d delta headers\n",
}
if (r_s->num_deltas2 > 0) {
- r_s->deltas = (SAM_DELTA_CTR *)
- talloc(ps->mem_ctx, r_s->num_deltas2 *
- sizeof(SAM_DELTA_CTR));
-
+ r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas2);
if (r_s->deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d deltas\n",
if (r_s->ptr_deltas != 0)
{
if (r_s->num_deltas > 0) {
- r_s->hdr_deltas = (SAM_DELTA_HDR *)
- talloc(ps->mem_ctx, r_s->num_deltas *
- sizeof(SAM_DELTA_HDR));
+ r_s->hdr_deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_HDR, r_s->num_deltas);
if (r_s->hdr_deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d delta headers\n",
}
if (r_s->num_deltas > 0) {
- r_s->deltas = (SAM_DELTA_CTR *)
- talloc(ps->mem_ctx, r_s->num_deltas *
- sizeof(SAM_DELTA_CTR));
-
+ r_s->deltas = TALLOC_ARRAY(ps->mem_ctx, SAM_DELTA_CTR, r_s->num_deltas);
if (r_s->deltas == NULL) {
DEBUG(0, ("error tallocating memory "
"for %d deltas\n",
if (size != 0) {
ps->buffer_size = size;
- if((ps->data_p = (char *)malloc((size_t)size)) == NULL) {
+ if((ps->data_p = (char *)SMB_MALLOC((size_t)size)) == NULL) {
DEBUG(0,("prs_init: malloc fail for %u bytes.\n", (unsigned int)size));
return False;
}
Allocate memory when unmarshalling... Always zero clears.
********************************************************************/
-char *prs_alloc_mem(prs_struct *ps, size_t size)
+#if defined(PARANOID_MALLOC_CHECKER)
+char *prs_alloc_mem_(prs_struct *ps, size_t size, unsigned int count)
+#else
+char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count)
+#endif
{
char *ret = NULL;
if (size) {
- ret = talloc(ps->mem_ctx, size);
- if (ret)
- memset(ret, '\0', size);
+ /* We can't call the type-safe version here. */
+#if defined(PARANOID_MALLOC_CHECKER)
+ ret = talloc_zero_array_(ps->mem_ctx, size, count);
+#else
+ ret = talloc_zero_array(ps->mem_ctx, size, count);
+#endif
}
return ret;
}
return prs_force_grow(ps, newsize - ps->buffer_size);
if (newsize < ps->buffer_size) {
- char *new_data_p = Realloc(ps->data_p, newsize);
+ char *new_data_p = SMB_REALLOC(ps->data_p, newsize);
/* if newsize is zero, Realloc acts like free() & returns NULL*/
if (new_data_p == NULL && newsize != 0) {
DEBUG(0,("prs_set_buffer_size: Realloc failure for size %u.\n",
new_size = MAX(MAX_PDU_FRAG_LEN,extra_space);
- if((new_data = malloc(new_size)) == NULL) {
+ if((new_data = SMB_MALLOC(new_size)) == NULL) {
DEBUG(0,("prs_grow: Malloc failure for size %u.\n", (unsigned int)new_size));
return False;
}
*/
new_size = MAX(ps->buffer_size*2, ps->buffer_size + extra_space);
- if ((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+ if ((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
return False;
}
- if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+ if((new_data = SMB_REALLOC(ps->data_p, new_size)) == NULL) {
DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
(unsigned int)new_size));
return False;
return False;
if (UNMARSHALLING(ps)) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,str->buf_len);
if (str->buffer == NULL)
return False;
}
if (UNMARSHALLING(ps)) {
if ( str->buf_len ) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->buf_len);
+ str->buffer = PRS_ALLOC_MEM(ps, uint16, str->buf_len);
if ( str->buffer == NULL )
return False;
}
return False;
if (UNMARSHALLING(ps)) {
- str->buffer = (unsigned char *)prs_alloc_mem(ps,str->str_max_len);
+ str->buffer = PRS_ALLOC_MEM(ps,unsigned char, str->str_max_len);
if (str->buffer == NULL)
return False;
}
return True;
if (UNMARSHALLING(ps)) {
- str->buffer = (uint16 *)prs_alloc_mem(ps,str->uni_max_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_max_len);
if (str->buffer == NULL)
return False;
}
return False;
if (UNMARSHALLING(ps)) {
- str->str.buffer = (uint16 *)prs_alloc_mem(ps,str->uni_str_len * sizeof(uint16));
+ str->str.buffer = PRS_ALLOC_MEM(ps,uint16,str->uni_str_len);
if (str->str.buffer == NULL)
return False;
}
alloc_len += 1;
/* should we allocate anything at all? */
- str->buffer = (uint16 *)prs_alloc_mem(ps,alloc_len * sizeof(uint16));
+ str->buffer = PRS_ALLOC_MEM(ps,uint16,alloc_len);
if ((str->buffer == NULL) && (alloc_len > 0))
return False;
return False;
if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY, r_u->num_entries2);
+ r_u->uni_acct_name = PRS_ALLOC_MEM(ps,UNISTR2, r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
if (num_entries==0)
return NT_STATUS_OK;
- sam->sam=(SAM_ENTRY1 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY1));
+ sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY1, num_entries);
if (!sam->sam)
return NT_STATUS_NO_MEMORY;
- sam->str=(SAM_STR1 *)talloc(ctx, num_entries*sizeof(SAM_STR1));
+ sam->str=TALLOC_ARRAY(ctx, SAM_STR1, num_entries);
if (!sam->str)
return NT_STATUS_NO_MEMORY;
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY1 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY1) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY1, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY1\n"));
return False;
}
- if ((sam->str = (SAM_STR1 *)
- prs_alloc_mem(ps, sizeof(SAM_STR1) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR1, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR1\n"));
return False;
}
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY2 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY2))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY2, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR2 *)talloc(ctx, num_entries*sizeof(SAM_STR2))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR2, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY2 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY2) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY2, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY2\n"));
return False;
}
- if ((sam->str = (SAM_STR2 *)
- prs_alloc_mem(ps, sizeof(SAM_STR2) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR2, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR2\n"));
return False;
}
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY3 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY3))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY3, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR3 *)talloc(ctx, num_entries*sizeof(SAM_STR3))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR3, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY3 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY3) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY3, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY3\n"));
return False;
}
- if ((sam->str = (SAM_STR3 *)
- prs_alloc_mem(ps, sizeof(SAM_STR3) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR3, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR3\n"));
return False;
}
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY4 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY4))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY4, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR4 *)talloc(ctx, num_entries*sizeof(SAM_STR4))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR4, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY4 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY4) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY4, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY4\n"));
return False;
}
- if ((sam->str = (SAM_STR4 *)
- prs_alloc_mem(ps, sizeof(SAM_STR4) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR4, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR4\n"));
return False;
}
if (num_entries==0)
return NT_STATUS_OK;
- if (!(sam->sam=(SAM_ENTRY5 *)talloc(ctx, num_entries*sizeof(SAM_ENTRY5))))
+ if (!(sam->sam=TALLOC_ARRAY(ctx, SAM_ENTRY5, num_entries)))
return NT_STATUS_NO_MEMORY;
- if (!(sam->str=(SAM_STR5 *)talloc(ctx, num_entries*sizeof(SAM_STR5))))
+ if (!(sam->str=TALLOC_ARRAY(ctx, SAM_STR5, num_entries)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(sam->sam);
if (UNMARSHALLING(ps) && num_entries > 0) {
- if ((sam->sam = (SAM_ENTRY5 *)
- prs_alloc_mem(ps, sizeof(SAM_ENTRY5) *
- num_entries)) == NULL) {
+ if ((sam->sam = PRS_ALLOC_MEM(ps, SAM_ENTRY5, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_ENTRY5\n"));
return False;
}
- if ((sam->str = (SAM_STR5 *)
- prs_alloc_mem(ps, sizeof(SAM_STR5) *
- num_entries)) == NULL) {
+ if ((sam->str = PRS_ALLOC_MEM(ps, SAM_STR5, num_entries)) == NULL) {
DEBUG(0, ("out of memory allocating SAM_STR5\n"));
return False;
}
prs_struct *ps, int depth)
{
if (UNMARSHALLING(ps))
- *ctr = (GROUP_INFO_CTR *)prs_alloc_mem(ps,sizeof(GROUP_INFO_CTR));
+ *ctr = PRS_ALLOC_MEM(ps,GROUP_INFO_CTR,1);
if (*ctr == NULL)
return False;
if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
return False;
if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
- r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
+ r_u->rid = PRS_ALLOC_MEM(ps,uint32,r_u->num_rids);
if (r_u->rid == NULL)
return False;
}
return False;
if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
- r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
+ r_u->attr = PRS_ALLOC_MEM(ps,uint32,r_u->num_attrs);
if (r_u->attr == NULL)
return False;
}
if ((*num_gids) != 0) {
if (UNMARSHALLING(ps)) {
- (*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
+ (*gid) = PRS_ALLOC_MEM(ps,DOM_GID,*num_gids);
}
if ((*gid) == NULL) {
return False;
if (UNMARSHALLING(ps)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_dom_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
return False;
if (UNMARSHALLING(ps)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
return False;
if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
- r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
- r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+ r_u->sam = PRS_ALLOC_MEM(ps,SAM_ENTRY,r_u->num_entries2);
+ r_u->uni_grp_name = PRS_ALLOC_MEM(ps,UNISTR2,r_u->num_entries2);
}
if (r_u->num_entries2 != 0 &&
return False;
if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
- q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
+ q_u->ptr_sid = PRS_ALLOC_MEM(ps,uint32,q_u->num_sids2);
if (q_u->ptr_sid == NULL)
return False;
- q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
+ q_u->sid = PRS_ALLOC_MEM(ps, DOM_SID2, q_u->num_sids2);
if (q_u->sid == NULL)
return False;
}
if ((*num_rids) != 0) {
if (UNMARSHALLING(ps)) {
/* reading */
- (*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
+ (*rid) = PRS_ALLOC_MEM(ps,uint32, *num_rids);
}
if ((*rid) == NULL)
return False;
q_u->flags = flags;
q_u->ptr = 0;
q_u->num_rids2 = num_rids;
- q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
+ q_u->rid = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids );
if (q_u->rid == NULL) {
q_u->num_rids1 = 0;
q_u->num_rids2 = 0;
return False;
if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
- q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
+ q_u->rid = PRS_ALLOC_MEM(ps, uint32, q_u->num_rids2);
if (q_u->rid == NULL)
return False;
}
if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
- r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
+ r_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, r_u->num_names2);
if (r_u->hdr_name == NULL)
return False;
- r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
+ r_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, r_u->num_names2);
if (r_u->uni_name == NULL)
return False;
}
return False;
if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
- r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
+ r_u->type = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
if (r_u->type == NULL)
return False;
}
if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
return False;
- ptr_sid = talloc(ps->mem_ctx, sizeof(uint32) * r_u->num_sids1);
+ ptr_sid = TALLOC_ARRAY(ps->mem_ctx, uint32, r_u->num_sids1);
if (!ptr_sid) {
return False;
}
}
if (UNMARSHALLING(ps)) {
- r_u->sid = talloc(ps->mem_ctx, r_u->num_sids1 * sizeof(DOM_SID2));
+ r_u->sid = TALLOC_ARRAY(ps->mem_ctx, DOM_SID2, r_u->num_sids1);
}
for (i = 0; i < r_u->num_sids1; i++) {
q_u->ptr = 0;
q_u->num_names2 = num_names;
- if (!(q_u->hdr_name = (UNIHDR *)talloc_zero(ctx, num_names * sizeof(UNIHDR))))
+ if (!(q_u->hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names)))
return NT_STATUS_NO_MEMORY;
- if (!(q_u->uni_name = (UNISTR2 *)talloc_zero(ctx, num_names * sizeof(UNISTR2))))
+ if (!(q_u->uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_names)))
return NT_STATUS_NO_MEMORY;
for (i = 0; i < num_names; i++) {
return False;
if (UNMARSHALLING(ps) && (q_u->num_names2 != 0)) {
- q_u->hdr_name = (UNIHDR *)prs_alloc_mem(ps, sizeof(UNIHDR) *
- q_u->num_names2);
- q_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, sizeof(UNISTR2) *
- q_u->num_names2);
+ q_u->hdr_name = PRS_ALLOC_MEM(ps, UNIHDR, q_u->num_names2);
+ q_u->uni_name = PRS_ALLOC_MEM(ps, UNISTR2, q_u->num_names2);
if (!q_u->hdr_name || !q_u->uni_name)
return False;
}
r_u->ptr_rids = 1;
r_u->num_rids2 = num_rids;
- if (!(r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+ if (!(r_u->rids = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
return NT_STATUS_NO_MEMORY;
- if (!(r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids)))
+ if (!(r_u->types = TALLOC_ZERO_ARRAY(ctx, uint32, num_rids)))
return NT_STATUS_NO_MEMORY;
if (!r_u->rids || !r_u->types)
}
if (UNMARSHALLING(ps))
- r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
+ r_u->rids = PRS_ALLOC_MEM(ps, uint32, r_u->num_rids2);
if (!r_u->rids) {
DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
}
if (UNMARSHALLING(ps))
- r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
+ r_u->types = PRS_ALLOC_MEM(ps, uint32, r_u->num_types2);
if (!r_u->types) {
DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
switch (switch_value) {
case 0x10:
- ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
+ ctr->info.id10 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_10);
if (ctr->info.id10 == NULL)
return NT_STATUS_NO_MEMORY;
expire.low = 0xffffffff;
expire.high = 0x7fffffff;
- ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
+ ctr->info.id = TALLOC_ZERO_P(ctx,SAM_USER_INFO_11);
init_sam_user_info11(ctr->info.id11, &expire,
"BROOKFIELDS$", /* name */
0x03ef, /* user rid */
}
#endif
case 0x12:
- ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
+ ctr->info.id12 = TALLOC_ZERO_P(ctx,SAM_USER_INFO_12);
if (ctr->info.id12 == NULL)
return NT_STATUS_NO_MEMORY;
case 21:
{
SAM_USER_INFO_21 *cusr;
- cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
+ cusr = TALLOC_ZERO_P(ctx,SAM_USER_INFO_21);
ctr->info.id21 = cusr;
if (ctr->info.id21 == NULL)
return NT_STATUS_NO_MEMORY;
depth++;
if (UNMARSHALLING(ps)) {
- ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
+ ctr = PRS_ALLOC_MEM(ps,SAM_USERINFO_CTR,1);
if (ctr == NULL)
return False;
*ppctr = ctr;
switch (ctr->switch_value) {
case 0x10:
if (UNMARSHALLING(ps))
- ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
+ ctr->info.id10 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_10,1);
if (ctr->info.id10 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
return False;
break;
case 0x11:
if (UNMARSHALLING(ps))
- ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
+ ctr->info.id11 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_11,1);
if (ctr->info.id11 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 0x12:
if (UNMARSHALLING(ps))
- ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
+ ctr->info.id12 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_12,1);
if (ctr->info.id12 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 20:
if (UNMARSHALLING(ps))
- ctr->info.id20 = (SAM_USER_INFO_20 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_20));
+ ctr->info.id20 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_20,1);
if (ctr->info.id20 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 21:
if (UNMARSHALLING(ps))
- ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
+ ctr->info.id21 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_21,1);
if (ctr->info.id21 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 23:
if (UNMARSHALLING(ps))
- ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
+ ctr->info.id23 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_23,1);
if (ctr->info.id23 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 24:
if (UNMARSHALLING(ps))
- ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
+ ctr->info.id24 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_24,1);
if (ctr->info.id24 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
break;
case 25:
if (UNMARSHALLING(ps))
- ctr->info.id25 = (SAM_USER_INFO_25 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_25));
+ ctr->info.id25 = PRS_ALLOC_MEM(ps,SAM_USER_INFO_25,1);
if (ctr->info.id25 == NULL) {
DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
if(!prs_align(ps))
return False;
- if ((q_u->ctr = (SAM_UNK_CTR *)prs_alloc_mem(ps, sizeof(SAM_UNK_CTR))) == NULL)
+ if ((q_u->ctr = PRS_ALLOC_MEM(ps, SAM_UNK_CTR, 1)) == NULL)
return False;
switch (q_u->switch_value) {
/*
* This is a read and we must allocate the stuct to read into.
*/
- if((psa = (SEC_ACL *)prs_alloc_mem(ps, sizeof(SEC_ACL))) == NULL)
+ if((psa = PRS_ALLOC_MEM(ps, SEC_ACL, 1)) == NULL)
return False;
*ppsa = psa;
}
* between a non-present DACL (allow all access) and a DACL with no ACE's
* (allow no access).
*/
- if((psa->ace = (SEC_ACE *)prs_alloc_mem(ps,sizeof(psa->ace[0]) * (psa->num_aces+1))) == NULL)
+ if((psa->ace = PRS_ALLOC_MEM(ps, SEC_ACE, psa->num_aces+1)) == NULL)
return False;
}
if (psd == NULL) {
if(UNMARSHALLING(ps)) {
- if((psd = (SEC_DESC *)prs_alloc_mem(ps,sizeof(SEC_DESC))) == NULL)
+ if((psd = PRS_ALLOC_MEM(ps,SEC_DESC,1)) == NULL)
return False;
*ppsd = psd;
} else {
if (UNMARSHALLING(ps)) {
/* reading */
- if((psd->owner_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->owner_sid))) == NULL)
+ if((psd->owner_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
return False;
}
if (UNMARSHALLING(ps)) {
/* reading */
- if((psd->grp_sid = (DOM_SID *)prs_alloc_mem(ps,sizeof(*psd->grp_sid))) == NULL)
+ if((psd->grp_sid = PRS_ALLOC_MEM(ps,DOM_SID,1)) == NULL)
return False;
}
psdb = *ppsdb;
if (UNMARSHALLING(ps) && psdb == NULL) {
- if((psdb = (SEC_DESC_BUF *)prs_alloc_mem(ps,sizeof(SEC_DESC_BUF))) == NULL)
+ if((psdb = PRS_ALLOC_MEM(ps,SEC_DESC_BUF,1)) == NULL)
return False;
*ppsdb = psdb;
}
/* reading */
if (UNMARSHALLING(ps))
- if((ctr->type=(SPOOL_NOTIFY_OPTION_TYPE *)prs_alloc_mem(ps,ctr->count*sizeof(SPOOL_NOTIFY_OPTION_TYPE))) == NULL)
+ if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL)
return False;
/* the option type struct */
case NOTIFY_STRING:
- if (UNMARSHALLING(ps)) {
- data->notify_data.data.string =
- (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
-
- if (!data->notify_data.data.string)
- return False;
- }
-
if (MARSHALLING(ps))
data->notify_data.data.length /= 2;
if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length))
return False;
+ if (UNMARSHALLING(ps)) {
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+ data->notify_data.data.length);
+
+ if (!data->notify_data.data.string)
+ return False;
+ }
+
if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string,
data->notify_data.data.length))
return False;
case NOTIFY_POINTER:
if (UNMARSHALLING(ps)) {
- data->notify_data.data.string =
- (uint16 *)prs_alloc_mem(ps, data->notify_data.data.length);
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16,
+ data->notify_data.data.length);
if (!data->notify_data.data.string)
return False;
/* Tallocate memory for string */
- data->notify_data.data.string = (uint16 *)prs_alloc_mem(ps, x * 2);
+ data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, x * 2);
if (!data->notify_data.data.string)
return False;
depth++;
if (UNMARSHALLING(ps)) {
- devmode->devicename.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+ devmode->devicename.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
if (devmode->devicename.buffer == NULL)
return False;
}
return False;
if (UNMARSHALLING(ps)) {
- devmode->formname.buffer = (uint16 *)prs_alloc_mem(ps, 32 * sizeof(uint16) );
+ devmode->formname.buffer = PRS_ALLOC_MEM(ps, uint16, 32);
if (devmode->formname.buffer == NULL)
return False;
}
if (devmode->driverextra!=0) {
if (UNMARSHALLING(ps)) {
- devmode->private=(uint8 *)prs_alloc_mem(ps, devmode->driverextra*sizeof(uint8));
+ devmode->private=PRS_ALLOC_MEM(ps, uint8, devmode->driverextra);
if(devmode->private == NULL)
return False;
DEBUG(7,("spoolss_io_devmode: allocated memory [%d] for private\n",devmode->driverextra));
/* so we have a DEVICEMODE to follow */
if (UNMARSHALLING(ps)) {
DEBUG(9,("Allocating memory for spoolss_io_devmode\n"));
- dm_c->devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE));
+ dm_c->devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1);
if(dm_c->devmode == NULL)
return False;
}
SPOOL_PRINTER_INFO_LEVEL_2 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_2*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_2)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_2))) {
DEBUG(0,("make_spoolss_printer_info_2: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_2 sruct!\n"));
return False;
}
SPOOL_PRINTER_INFO_LEVEL_3 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_3*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_3)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_3))) {
DEBUG(0,("make_spoolss_printer_info_3: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_3 sruct!\n"));
return False;
}
SPOOL_PRINTER_INFO_LEVEL_7 *inf;
/* allocate the necessary memory */
- if (!(inf=(SPOOL_PRINTER_INFO_LEVEL_7*)talloc(mem_ctx, sizeof(SPOOL_PRINTER_INFO_LEVEL_7)))) {
+ if (!(inf=TALLOC_P(mem_ctx, SPOOL_PRINTER_INFO_LEVEL_7))) {
DEBUG(0,("make_spoolss_printer_info_7: Unable to allocate SPOOL_PRINTER_INFO_LEVEL_7 struct!\n"));
return False;
}
return False;
if (UNMARSHALLING(ps) && r_u->size) {
- r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+ r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
if(!r_u->data)
return False;
}
if (q_u->buffer_size!=0)
{
if (UNMARSHALLING(ps))
- q_u->buffer=(uint8 *)prs_alloc_mem(ps,q_u->buffer_size*sizeof(uint8));
+ q_u->buffer=PRS_ALLOC_MEM(ps, uint8, q_u->buffer_size);
if(q_u->buffer == NULL)
return False;
if(!prs_uint8s(True, "buffer", ps, depth, q_u->buffer, q_u->buffer_size))
if (q_u->option_ptr!=0) {
if (UNMARSHALLING(ps))
- if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+ if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
return False;
if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
if (q_u->option_ptr!=0) {
if (UNMARSHALLING(ps))
- if((q_u->option=(SPOOL_NOTIFY_OPTION *)prs_alloc_mem(ps,sizeof(SPOOL_NOTIFY_OPTION))) == NULL)
+ if((q_u->option=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION,1)) == NULL)
return False;
if(!smb_io_notify_option("notify option", q_u->option, ps, depth))
/* Yes this should be malloc not talloc. Don't change. */
- chaine.buffer = malloc((q-p+1)*sizeof(uint16));
+ chaine.buffer = SMB_MALLOC((q-p+1)*sizeof(uint16));
if (chaine.buffer == NULL)
return False;
/* Yes this should be realloc - it's freed below. JRA */
- if((tc2=(uint16 *)Realloc(chaine2, realloc_size)) == NULL) {
+ if((tc2=(uint16 *)SMB_REALLOC(chaine2, realloc_size)) == NULL) {
SAFE_FREE(chaine2);
return False;
}
if (chaine2)
{
chaine2[l_chaine2] = '\0';
- *string=(uint16 *)talloc_memdup(prs_get_mem_context(ps),chaine2,realloc_size);
+ *string=(uint16 *)TALLOC_MEMDUP(prs_get_mem_context(ps),chaine2,realloc_size);
SAFE_FREE(chaine2);
}
return False;
/* read the string */
- if((*devmode=(DEVICEMODE *)prs_alloc_mem(ps,sizeof(DEVICEMODE))) == NULL)
+ if((*devmode=PRS_ALLOC_MEM(ps,DEVICEMODE,1)) == NULL)
return False;
if (!spoolss_io_devmode(desc, ps, depth, *devmode))
return False;
depth++;
if (UNMARSHALLING(ps))
- buffer = *pp_buffer = (NEW_BUFFER *)prs_alloc_mem(ps, sizeof(NEW_BUFFER));
+ buffer = *pp_buffer = PRS_ALLOC_MEM(ps, NEW_BUFFER, 1);
if (buffer == NULL)
return False;
make_spoolss_printer_info_2 (mem_ctx, &q_u->info.info_2, info->printers_2);
#if 1 /* JERRY TEST */
- q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+ q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
if (!q_u->secdesc_ctr)
return False;
q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
make_spoolss_printer_info_3 (mem_ctx, &q_u->info.info_3, info->printers_3);
- q_u->secdesc_ctr = (SEC_DESC_BUF*)malloc(sizeof(SEC_DESC_BUF));
+ q_u->secdesc_ctr = SMB_MALLOC_P(SEC_DESC_BUF);
if (!q_u->secdesc_ctr)
return False;
q_u->secdesc_ctr->ptr = (secdesc != NULL) ? 1: 0;
case 1:
{
if (UNMARSHALLING(ps)) {
- if ((il->info_1=(SPOOL_PRINTER_INFO_LEVEL_1 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_1))) == NULL)
+ if ((il->info_1=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_1,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_1("", il->info_1, ps, depth))
*/
case 2:
if (UNMARSHALLING(ps)) {
- if ((il->info_2=(SPOOL_PRINTER_INFO_LEVEL_2 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_2))) == NULL)
+ if ((il->info_2=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_2,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_2("", il->info_2, ps, depth))
case 3:
{
if (UNMARSHALLING(ps)) {
- if ((il->info_3=(SPOOL_PRINTER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_3))) == NULL)
+ if ((il->info_3=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_3,1)) == NULL)
return False;
}
if (!spool_io_printer_info_level_3("", il->info_3, ps, depth))
}
case 7:
if (UNMARSHALLING(ps))
- if ((il->info_7=(SPOOL_PRINTER_INFO_LEVEL_7 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_INFO_LEVEL_7))) == NULL)
+ if ((il->info_7=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_INFO_LEVEL_7,1)) == NULL)
return False;
if (!spool_io_printer_info_level_7("", il->info_7, ps, depth))
return False;
/* reading */
if (UNMARSHALLING(ps)) {
- il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3));
+ il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_3,1);
if(il == NULL)
return False;
*q_u=il;
/* reading */
if (UNMARSHALLING(ps)) {
- il=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6 *)prs_alloc_mem(ps,sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_6));
+ il=PRS_ALLOC_MEM(ps,SPOOL_PRINTER_DRIVER_INFO_LEVEL_6,1);
if(il == NULL)
return False;
*q_u=il;
while (src < ((char *)buf5->buffer) + buf5->buf_len*2) {
rpcstr_pull(f, src, sizeof(f)-1, -1, STR_TERMINATE);
src = skip_unibuf(src, 2*buf5->buf_len - PTR_DIFF(src,buf5->buffer));
- tar = (fstring *)Realloc(*ar, sizeof(fstring)*(n+2));
+ tar = SMB_REALLOC_ARRAY(*ar, fstring, n+2);
if (!tar)
return False;
else
BOOL null_char = False;
SPOOL_PRINTER_DRIVER_INFO_LEVEL_3 *inf;
- if (!(inf=(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3*)talloc_zero(mem_ctx, sizeof(SPOOL_PRINTER_DRIVER_INFO_LEVEL_3))))
+ if (!(inf=TALLOC_ZERO_P(mem_ctx, SPOOL_PRINTER_DRIVER_INFO_LEVEL_3)))
return False;
inf->cversion = info3->version;
{
buf5->buf_len = len;
- if((buf5->buffer=(uint16*)talloc_memdup(mem_ctx, src, sizeof(uint16)*len)) == NULL)
- {
+ if((buf5->buffer=(uint16*)TALLOC_MEMDUP(mem_ctx, src, sizeof(uint16)*len)) == NULL) {
DEBUG(0,("make_spoolss_buffer5: Unable to malloc memory for buffer!\n"));
return False;
}
if (*asc==NULL)
{
- *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_3 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_3));
+ *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_3);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
if (*asc==NULL)
{
- *asc=(NT_PRINTER_DRIVER_INFO_LEVEL_6 *)malloc(sizeof(NT_PRINTER_DRIVER_INFO_LEVEL_6));
+ *asc=SMB_MALLOC_P(NT_PRINTER_DRIVER_INFO_LEVEL_6);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
if (*asc==NULL) {
DEBUGADD(8,("allocating memory\n"));
- *asc=(NT_PRINTER_INFO_LEVEL_2 *)malloc(sizeof(NT_PRINTER_INFO_LEVEL_2));
+ *asc=SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL_2);
if(*asc == NULL)
return False;
ZERO_STRUCTP(*asc);
return False;
if (UNMARSHALLING(ps) && r_u->valuesize) {
- r_u->value = (uint16 *)prs_alloc_mem(ps, r_u->valuesize * 2);
+ r_u->value = PRS_ALLOC_MEM(ps, uint16, r_u->valuesize);
if (!r_u->value) {
DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata value\n"));
return False;
return False;
if (UNMARSHALLING(ps) && r_u->datasize) {
- r_u->data = (uint8 *)prs_alloc_mem(ps, r_u->datasize);
+ r_u->data = PRS_ALLOC_MEM(ps, uint8, r_u->datasize);
if (!r_u->data) {
DEBUG(0, ("spoolss_io_r_enumprinterdata: out of memory for printerdata data\n"));
return False;
case REG_MULTI_SZ:
if (q_u->max_len) {
if (UNMARSHALLING(ps))
- q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+ q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
if(q_u->data == NULL)
return False;
if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
if (src->size != POINTER)
continue;
len = src->notify_data.data.length;
- s = malloc(sizeof(uint16)*len);
+ s = SMB_MALLOC_ARRAY(uint16, len);
if (s == NULL) {
DEBUG(0,("copy_spool_notify_info_data: malloc() failed!\n"));
return False;
if (dst->count)
{
- dst->data = malloc(dst->count * sizeof(SPOOL_NOTIFY_INFO_DATA));
+ dst->data = SMB_MALLOC_ARRAY(SPOOL_NOTIFY_INFO_DATA, dst->count);
DEBUG(10,("copy_spool_notify_info: allocating space for [%d] PRINTER_NOTIFY_INFO_DATA entries\n",
dst->count));
return False;
if (UNMARSHALLING(ps) && r_u->size) {
- r_u->data = (unsigned char *)prs_alloc_mem(ps, r_u->size);
+ r_u->data = PRS_ALLOC_MEM(ps, unsigned char, r_u->size);
if(!r_u->data)
return False;
}
case 0x7:
if (q_u->max_len) {
if (UNMARSHALLING(ps))
- q_u->data=(uint8 *)prs_alloc_mem(ps, q_u->max_len * sizeof(uint8));
+ q_u->data=PRS_ALLOC_MEM(ps, uint8, q_u->max_len);
if(q_u->data == NULL)
return False;
if(!prs_uint8s(False,"data", ps, depth, q_u->data, q_u->max_len))
/* first loop to write basic enum_value information */
if (UNMARSHALLING(ps)) {
- ctr->values = (PRINTER_ENUM_VALUES *)prs_alloc_mem(
- ps, ctr->size_of_array * sizeof(PRINTER_ENUM_VALUES));
+ ctr->values = PRS_ALLOC_MEM(ps, PRINTER_ENUM_VALUES, ctr->size_of_array);
if (!ctr->values)
return False;
}
if ( ctr->values[i].data_len ) {
if ( UNMARSHALLING(ps) ) {
- ctr->values[i].data = (uint8 *)prs_alloc_mem(
- ps, ctr->values[i].data_len);
+ ctr->values[i].data = PRS_ALLOC_MEM(ps, uint8, ctr->values[i].data_len);
if (!ctr->values[i].data)
return False;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info0 = (SRV_SHARE_INFO_0 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_0))))
+ if (!(info0 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_0, num_entries)))
return False;
ctr->share.info0 = info0;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1 = (SRV_SHARE_INFO_1 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_SHARE_INFO_1))))
+ if (!(info1 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_1, num_entries)))
return False;
ctr->share.info1 = info1;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info2 = (SRV_SHARE_INFO_2 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_2))))
+ if (!(info2 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_2,num_entries)))
return False;
ctr->share.info2 = info2;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info501 = (SRV_SHARE_INFO_501 *) prs_alloc_mem(ps, num_entries *
- sizeof (SRV_SHARE_INFO_501))))
+ if (!(info501 = PRS_ALLOC_MEM(ps, SRV_SHARE_INFO_501, num_entries)))
return False;
ctr->share.info501 = info501;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info502 = (SRV_SHARE_INFO_502 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_502))))
+ if (!(info502 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_502,num_entries)))
return False;
ctr->share.info502 = info502;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1004 = (SRV_SHARE_INFO_1004 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1004))))
+ if (!(info1004 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1004,num_entries)))
return False;
ctr->share.info1004 = info1004;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1005 = (SRV_SHARE_INFO_1005 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1005))))
+ if (!(info1005 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1005,num_entries)))
return False;
ctr->share.info1005 = info1005;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1006 = (SRV_SHARE_INFO_1006 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1006))))
+ if (!(info1006 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1006,num_entries)))
return False;
ctr->share.info1006 = info1006;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1007 = (SRV_SHARE_INFO_1007 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1007))))
+ if (!(info1007 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1007,num_entries)))
return False;
ctr->share.info1007 = info1007;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info1501 = (SRV_SHARE_INFO_1501 *)prs_alloc_mem(ps,num_entries * sizeof(SRV_SHARE_INFO_1501))))
+ if (!(info1501 = PRS_ALLOC_MEM(ps,SRV_SHARE_INFO_1501,num_entries)))
return False;
ctr->share.info1501 = info1501;
}
depth++;
if(UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (SRV_SESS_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_SESS_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_SESS_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
depth++;
if (UNMARSHALLING(ps)) {
- ctr = *pp_ctr = (SRV_CONN_INFO_CTR *)prs_alloc_mem(ps, sizeof(SRV_CONN_INFO_CTR));
+ ctr = *pp_ctr = PRS_ALLOC_MEM(ps, SRV_CONN_INFO_CTR, 1);
if (ctr == NULL)
return False;
}
int i;
if (UNMARSHALLING(ps)) {
- if (!(info3 = (SRV_FILE_INFO_3 *)prs_alloc_mem(ps, num_entries * sizeof(SRV_FILE_INFO_3))))
+ if (!(info3 = PRS_ALLOC_MEM(ps, SRV_FILE_INFO_3, num_entries)))
return False;
ctr->file.info3 = info3;
}
return False;
if (UNMARSHALLING(ps)) {
- q_n->ctr = (SRV_INFO_CTR *)
- prs_alloc_mem(ps, sizeof(SRV_INFO_CTR));
+ q_n->ctr = PRS_ALLOC_MEM(ps, SRV_INFO_CTR, 1);
if (!q_n->ctr)
return False;
DISK_INFO *dinfo;
- if(!(dinfo = (DISK_INFO *)prs_alloc_mem(ps, sizeof(*dinfo) * entries_read3)))
- return False;
+ if(!(dinfo = PRS_ALLOC_MEM(ps, DISK_INFO, entries_read3)))
+ return False;
r_n->disk_enum_ctr.disk_info = dinfo;
}
vfs_ChDir(p->conn,p->conn->connectpath);
- jn.referral_list = (struct referral*) talloc(p->mem_ctx, jn.referral_count
- * sizeof(struct referral));
-
+ jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
if(jn.referral_list == NULL) {
DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
return WERR_DFS_INTERNAL_ERROR;
dfs3[i].ptr_storages = 1;
/* also enumerate the storages */
- dfs3[i].storages = (DFS_STORAGE_INFO*) talloc(ctx, j[i].referral_count *
- sizeof(DFS_STORAGE_INFO));
+ dfs3[i].storages = TALLOC_ARRAY(ctx, DFS_STORAGE_INFO, j[i].referral_count);
if (!dfs3[i].storages)
return False;
case 1:
{
DFS_INFO_1* dfs1;
- dfs1 = (DFS_INFO_1*) talloc(ctx, num_jn * sizeof(DFS_INFO_1));
+ dfs1 = TALLOC_ARRAY(ctx, DFS_INFO_1, num_jn);
if (!dfs1)
return WERR_NOMEM;
init_reply_dfs_info_1(jn, dfs1, num_jn);
case 2:
{
DFS_INFO_2* dfs2;
- dfs2 = (DFS_INFO_2*) talloc(ctx, num_jn * sizeof(DFS_INFO_2));
+ dfs2 = TALLOC_ARRAY(ctx, DFS_INFO_2, num_jn);
if (!dfs2)
return WERR_NOMEM;
init_reply_dfs_info_2(jn, dfs2, num_jn);
case 3:
{
DFS_INFO_3* dfs3;
- dfs3 = (DFS_INFO_3*) talloc(ctx, num_jn * sizeof(DFS_INFO_3));
+ dfs3 = TALLOC_ARRAY(ctx, DFS_INFO_3, num_jn);
if (!dfs3)
return WERR_NOMEM;
init_reply_dfs_info_3(ctx, jn, dfs3, num_jn);
r_u->reshnd.ptr_hnd = 1;
r_u->reshnd.handle = num_jn;
- r_u->ctr = (DFS_INFO_CTR*)talloc(p->mem_ctx, sizeof(DFS_INFO_CTR));
+ r_u->ctr = TALLOC_P(p->mem_ctx, DFS_INFO_CTR);
if (!r_u->ctr)
return WERR_NOMEM;
ZERO_STRUCTP(r_u->ctr);
{
DEBUG(10, ("_echo_data\n"));
- r_u->data = talloc(p->mem_ctx, q_u->size);
+ r_u->data = TALLOC(p->mem_ctx, q_u->size);
r_u->size = q_u->size;
memcpy(r_u->data, q_u->data, q_u->size);
}
DEBUG(10, ("_source_data\n"));
- r_u->data = talloc(p->mem_ctx, q_u->size);
+ r_u->data = TALLOC(p->mem_ctx, q_u->size);
r_u->size = q_u->size;
for (i = 0; i < r_u->size; i++)
DEBUG(10,("fill_dsrole_dominfo_basic: enter\n"));
- if ( !(basic = talloc_zero(ctx, sizeof(DSROLE_PRIMARY_DOMAIN_INFO_BASIC))) ) {
+ if ( !(basic = TALLOC_ZERO_P(ctx, DSROLE_PRIMARY_DOMAIN_INFO_BASIC)) ) {
DEBUG(0,("fill_dsrole_dominfo_basic: FATAL error! talloc_xero() failed\n"));
return NT_STATUS_NO_MEMORY;
}
* Create list.
*/
- if ((hl = (struct handle_list *)malloc(sizeof(struct handle_list))) == NULL)
+ if ((hl = SMB_MALLOC_P(struct handle_list)) == NULL)
return False;
ZERO_STRUCTP(hl);
return False;
}
- pol = (struct policy *)malloc(sizeof(*p));
+ pol = SMB_MALLOC_P(struct policy);
if (!pol) {
DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
return False;
/* Allocate memory for list of names */
if (num_entries > 0) {
- if (!(trn->name = (LSA_TRANS_NAME *)talloc(ctx, sizeof(LSA_TRANS_NAME) *
- num_entries))) {
+ if (!(trn->name = TALLOC_ARRAY(ctx, LSA_TRANS_NAME, num_entries))) {
DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
return;
}
- if (!(trn->uni_name = (UNISTR2 *)talloc(ctx, sizeof(UNISTR2) *
- num_entries))) {
+ if (!(trn->uni_name = TALLOC_ARRAY(ctx, UNISTR2, num_entries))) {
DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
return;
}
/* associate the domain SID with the (unique) handle. */
- if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+ if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(info);
}
/* associate the domain SID with the (unique) handle. */
- if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+ if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(info);
info->id2.auditing_enabled = 1;
info->id2.count1 = 7;
info->id2.count2 = 7;
- if ((info->id2.auditsettings = (uint32 *)talloc(p->mem_ctx,7*sizeof(uint32))) == NULL)
+ if ((info->id2.auditsettings = TALLOC_ARRAY(p->mem_ctx,uint32, 7)) == NULL)
return NT_STATUS_NO_MEMORY;
for (i = 0; i < 7; i++)
info->id2.auditsettings[i] = 3;
DEBUG(5,("_lsa_lookup_sids: truncating SID lookup list to %d\n", num_entries));
}
- ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
- names = (LSA_TRANS_NAME_ENUM *)talloc_zero(p->mem_ctx, sizeof(LSA_TRANS_NAME_ENUM));
+ ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
+ names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM);
if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
r_u->status = NT_STATUS_INVALID_HANDLE;
DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries));
}
- ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
- rids = (DOM_RID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_RID2)*num_entries);
+ ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
+ rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
r_u->status = NT_STATUS_INVALID_HANDLE;
if (enum_context >= PRIV_ALL_INDEX)
return NT_STATUS_NO_MORE_ENTRIES;
- entries = (LSA_PRIV_ENTRY *)talloc_zero(p->mem_ctx, sizeof(LSA_PRIV_ENTRY) * (PRIV_ALL_INDEX));
+ entries = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_PRIV_ENTRY, PRIV_ALL_INDEX);
if (entries==NULL)
return NT_STATUS_NO_MEMORY;
if (q_u->enum_context >= num_entries)
return NT_STATUS_NO_MORE_ENTRIES;
- sids->ptr_sid = (uint32 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(uint32));
- sids->sid = (DOM_SID2 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(DOM_SID2));
+ sids->ptr_sid = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_entries-q_u->enum_context);
+ sids->sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_entries-q_u->enum_context);
if (sids->ptr_sid==NULL || sids->sid==NULL) {
SAFE_FREE(map);
return NT_STATUS_ACCESS_DENIED;
/* associate the user/group SID with the (unique) handle. */
- if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
+ if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(info);
SAM_ACCOUNT *sampw;
struct auth_context *auth_context = NULL;
- usr_info = (NET_USER_INFO_3 *)talloc(p->mem_ctx, sizeof(NET_USER_INFO_3));
+ usr_info = TALLOC_P(p->mem_ctx, NET_USER_INFO_3);
if (!usr_info)
return NT_STATUS_NO_MEMORY;
int n_fns = 0;
PIPE_RPC_FNS *context_fns;
- if ( !(context_fns = malloc(sizeof(PIPE_RPC_FNS))) ) {
+ if ( !(context_fns = SMB_MALLOC_P(PIPE_RPC_FNS)) ) {
DEBUG(0,("check_bind_req: malloc() failed!\n"));
return False;
}
/* We use a temporary variable because this call can fail and
rpc_lookup will still be valid afterwards. It could then succeed if
called again later */
- rpc_entry = realloc(rpc_lookup,
- ++rpc_lookup_size*sizeof(struct rpc_table));
+ rpc_lookup_size++;
+ rpc_entry = SMB_REALLOC_ARRAY(rpc_lookup, struct rpc_table, rpc_lookup_size);
if (NULL == rpc_entry) {
rpc_lookup_size--;
DEBUG(0, ("rpc_pipe_register_commands: memory allocation failed\n"));
rpc_entry = rpc_lookup + (rpc_lookup_size - 1);
ZERO_STRUCTP(rpc_entry);
- rpc_entry->pipe.clnt = strdup(clnt);
- rpc_entry->pipe.srv = strdup(srv);
- rpc_entry->cmds = realloc(rpc_entry->cmds,
- (rpc_entry->n_cmds + size) *
- sizeof(struct api_struct));
- memcpy(rpc_entry->cmds + rpc_entry->n_cmds, cmds,
- size * sizeof(struct api_struct));
+ rpc_entry->pipe.clnt = SMB_STRDUP(clnt);
+ rpc_entry->pipe.srv = SMB_STRDUP(srv);
+ rpc_entry->cmds = SMB_REALLOC_ARRAY(rpc_entry->cmds, struct api_struct, rpc_entry->n_cmds + size);
+ memcpy(rpc_entry->cmds + rpc_entry->n_cmds, cmds, size * sizeof(struct api_struct));
rpc_entry->n_cmds += size;
return NT_STATUS_OK;
if ((DEBUGLEVEL >= 10) &&
(prs_offset(&p->in_data.data) != prs_data_size(&p->in_data.data))) {
size_t data_len = prs_data_size(&p->in_data.data) - prs_offset(&p->in_data.data);
- char *data;
-
- data = malloc(data_len);
+ char *data = SMB_MALLOC(data_len);
DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
if (data) {
for (p = Pipes; p; p = p->next)
DEBUG(5,("open_rpc_pipe_p: name %s pnum=%x\n", p->name, p->pnum));
- p = (smb_np_struct *)malloc(sizeof(*p));
-
+ p = SMB_MALLOC_P(smb_np_struct);
if (!p) {
DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
return NULL;
return NULL;
}
- p = (pipes_struct *)malloc(sizeof(*p));
+ p = SMB_MALLOC_P(pipes_struct);
- if (!p)
- {
+ if (!p) {
DEBUG(0,("ERROR! no memory for pipes_struct!\n"));
return NULL;
}
if ( subkey_len && subkeyname2[subkey_len-1] == '\\' )
subkeyname2[subkey_len-1] = '\0';
- if ((regkey=(REGISTRY_KEY*)malloc(sizeof(REGISTRY_KEY))) == NULL)
+ if ((regkey=SMB_MALLOC_P(REGISTRY_KEY)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP( regkey );
/* couple of hard coded registry values */
if ( strequal(name, "RefusePasswordChange") ) {
- if ( (val = (REGISTRY_VALUE*)malloc(sizeof(REGISTRY_VALUE))) == NULL ) {
+ if ( (val = SMB_MALLOC_P(REGISTRY_VALUE)) == NULL ) {
DEBUG(0,("_reg_info: malloc() failed!\n"));
return NT_STATUS_NO_MEMORY;
}
mem_ctx = talloc_init("samr_info for domain sid %s", sid_str);
- if ((info = (struct samr_info *)talloc(mem_ctx, sizeof(struct samr_info))) == NULL)
+ if ((info = TALLOC_P(mem_ctx, struct samr_info)) == NULL)
return NULL;
ZERO_STRUCTP(info);
if (info->disp_info.num_user_account % MAX_SAM_ENTRIES == 0) {
DEBUG(10,("load_sampwd_entries: allocating more memory\n"));
- pwd_array=(SAM_ACCOUNT *)talloc_realloc(mem_ctx, info->disp_info.disp_user_info,
- (info->disp_info.num_user_account+MAX_SAM_ENTRIES)*sizeof(SAM_ACCOUNT));
+ pwd_array=TALLOC_REALLOC_ARRAY(mem_ctx, info->disp_info.disp_user_info, SAM_ACCOUNT,
+ info->disp_info.num_user_account+MAX_SAM_ENTRIES);
if (pwd_array==NULL)
return NT_STATUS_NO_MEMORY;
info->disp_info.num_group_account=group_entries;
- grp_array=(DOMAIN_GRP *)talloc(mem_ctx, info->disp_info.num_group_account*sizeof(DOMAIN_GRP));
+ grp_array=TALLOC_ARRAY(mem_ctx, DOMAIN_GRP, info->disp_info.num_group_account);
if (group_entries!=0 && grp_array==NULL) {
DEBUG(1, ("load_group_domain_entries: talloc() failed for grp_array!\n"));
SAFE_FREE(map);
if (num_entries == 0)
return NT_STATUS_OK;
- sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_entries);
+ sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_entries);
- uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_entries);
+ uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_entries);
if (sam == NULL || uni_name == NULL) {
DEBUG(0, ("make_user_sam_entry_list: talloc_zero failed!\n"));
if (num_sam_entries == 0)
return;
- sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
-
- uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
+ sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
+ uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
if (sam == NULL || uni_name == NULL) {
DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
num_entries=max_entries;
}
- *d_grp=(DOMAIN_GRP *)talloc_zero(ctx, num_entries*sizeof(DOMAIN_GRP));
+ *d_grp=TALLOC_ZERO_ARRAY(ctx, DOMAIN_GRP, num_entries);
if (num_entries!=0 && *d_grp==NULL){
SAFE_FREE(map);
return NT_STATUS_NO_MEMORY;
if (*p_num_entries == 0)
return NT_STATUS_OK;
- *d_grp = talloc(ctx, sizeof(DOMAIN_GRP) * (*p_num_entries));
+ *d_grp = TALLOC_ARRAY(ctx, DOMAIN_GRP, *p_num_entries);
if (*d_grp == NULL) {
SAFE_FREE(info);
DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to only %d entries\n", max_entries));
}
- if (!(ctr = (SAM_DISPINFO_CTR *)talloc_zero(p->mem_ctx,sizeof(SAM_DISPINFO_CTR))))
+ if (!(ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_DISPINFO_CTR)))
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(ctr);
switch (q_u->switch_level) {
case 0x1:
if (max_entries) {
- if (!(ctr->sam.info1 = (SAM_DISPINFO_1 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_1))))
+ if (!(ctr->sam.info1 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_1,max_entries)))
return NT_STATUS_NO_MEMORY;
}
disp_ret = init_sam_dispinfo_1(p->mem_ctx, ctr->sam.info1, max_entries, enum_context,
break;
case 0x2:
if (max_entries) {
- if (!(ctr->sam.info2 = (SAM_DISPINFO_2 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_2))))
+ if (!(ctr->sam.info2 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_2,max_entries)))
return NT_STATUS_NO_MEMORY;
}
disp_ret = init_sam_dispinfo_2(p->mem_ctx, ctr->sam.info2, max_entries, enum_context,
break;
case 0x3:
if (max_entries) {
- if (!(ctr->sam.info3 = (SAM_DISPINFO_3 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_3))))
+ if (!(ctr->sam.info3 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_3,max_entries)))
return NT_STATUS_NO_MEMORY;
}
disp_ret = init_sam_dispinfo_3(p->mem_ctx, ctr->sam.info3, max_entries, enum_context, info->disp_info.disp_group_info);
break;
case 0x4:
if (max_entries) {
- if (!(ctr->sam.info4 = (SAM_DISPINFO_4 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_4))))
+ if (!(ctr->sam.info4 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_4,max_entries)))
return NT_STATUS_NO_MEMORY;
}
disp_ret = init_sam_dispinfo_4(p->mem_ctx, ctr->sam.info4, max_entries, enum_context, info->disp_info.disp_user_info);
break;
case 0x5:
if (max_entries) {
- if (!(ctr->sam.info5 = (SAM_DISPINFO_5 *)talloc_zero(p->mem_ctx,max_entries*sizeof(SAM_DISPINFO_5))))
+ if (!(ctr->sam.info5 = TALLOC_ZERO_ARRAY(p->mem_ctx,SAM_DISPINFO_5,max_entries)))
return NT_STATUS_NO_MEMORY;
}
disp_ret = init_sam_dispinfo_5(p->mem_ctx, ctr->sam.info5, max_entries, enum_context, info->disp_info.disp_group_info);
*pp_hdr_name = NULL;
if (num_names != 0) {
- hdr_name = (UNIHDR *)talloc_zero(ctx, sizeof(UNIHDR)*num_names);
+ hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names);
if (hdr_name == NULL)
return False;
- uni_name = (UNISTR2 *)talloc_zero(ctx,sizeof(UNISTR2)*num_names);
+ uni_name = TALLOC_ZERO_ARRAY(ctx,UNISTR2, num_names);
if (uni_name == NULL)
return False;
}
}
if (num_rids) {
- if ((group_attrs = (uint32 *)talloc_zero(p->mem_ctx, num_rids * sizeof(uint32))) == NULL)
+ if ((group_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids )) == NULL)
return NT_STATUS_NO_MEMORY;
}
DEBUG(5,("_samr_query_userinfo: sid:%s\n", sid_string_static(&info->sid)));
- ctr = (SAM_USERINFO_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_USERINFO_CTR));
+ ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_USERINFO_CTR);
if (!ctr)
return NT_STATUS_NO_MEMORY;
switch (q_u->switch_value) {
case 0x10:
- ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_10));
+ ctr->info.id10 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_10);
if (ctr->info.id10 == NULL)
return NT_STATUS_NO_MEMORY;
expire.low = 0xffffffff;
expire.high = 0x7fffffff;
- ctr->info.id = (SAM_USER_INFO_11 *)talloc_zero(p->mem_ctx,
- sizeof
- (*ctr->
- info.
- id11));
+ ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_11));
ZERO_STRUCTP(ctr->info.id11);
init_sam_user_info11(ctr->info.id11, &expire,
"BROOKFIELDS$", /* name */
#endif
case 0x12:
- ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(p->mem_ctx, sizeof(SAM_USER_INFO_12));
+ ctr->info.id12 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_12);
if (ctr->info.id12 == NULL)
return NT_STATUS_NO_MEMORY;
break;
case 20:
- ctr->info.id20 = (SAM_USER_INFO_20 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_20));
+ ctr->info.id20 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_20);
if (ctr->info.id20 == NULL)
return NT_STATUS_NO_MEMORY;
if (!NT_STATUS_IS_OK(r_u->status = get_user_info_20(p->mem_ctx, ctr->info.id20, &info->sid)))
break;
case 21:
- ctr->info.id21 = (SAM_USER_INFO_21 *)talloc_zero(p->mem_ctx,sizeof(SAM_USER_INFO_21));
+ ctr->info.id21 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_21);
if (ctr->info.id21 == NULL)
return NT_STATUS_NO_MEMORY;
if (!NT_STATUS_IS_OK(r_u->status = get_user_info_21(p->mem_ctx, ctr->info.id21,
&(sids[i]), &rid))
continue;
- gids = talloc_realloc(p->mem_ctx, gids,
- sizeof(*gids) * (num_gids+1));
+ gids = TALLOC_REALLOC_ARRAY(p->mem_ctx, gids, DOM_GID, num_gids+1);
gids[num_gids].attr=7;
gids[num_gids].g_rid = rid;
num_gids += 1;
uint32 num_users=0, num_groups=0, num_aliases=0;
- if ((ctr = (SAM_UNK_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
+ if ((ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_CTR)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(ctr);
if (num_sam_entries == 0)
return True;
- sam = (SAM_ENTRY *)talloc_zero(ctx, sizeof(SAM_ENTRY)*num_sam_entries);
- uni_name = (UNISTR2 *)talloc_zero(ctx, sizeof(UNISTR2)*num_sam_entries);
+ sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
+ uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
if (sam == NULL || uni_name == NULL)
return False;
!sid_check_is_builtin(&info->sid))
return NT_STATUS_OBJECT_TYPE_MISMATCH;
- members = talloc(p->mem_ctx, sizeof(DOM_SID) * q_u->num_sids1);
+ members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, q_u->num_sids1);
if (members == NULL)
return NT_STATUS_NO_MEMORY;
if (!sid_peek_check_rid(&info->sid, &aliases[i], &rid))
continue;
- rids = talloc_realloc(p->mem_ctx, rids,
- sizeof(*rids) * (num_groups+1));
+ rids = TALLOC_REALLOC_ARRAY(p->mem_ctx, rids, uint32, num_groups+1);
if (rids == NULL)
return NT_STATUS_NO_MEMORY;
if (!pdb_enum_aliasmem(&alias_sid, &sids, &num_sids))
return NT_STATUS_NO_SUCH_ALIAS;
- sid = (DOM_SID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_SID2) * num_sids);
+ sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_sids);
if (num_sids!=0 && sid == NULL) {
SAFE_FREE(sids);
return NT_STATUS_NO_MEMORY;
return;
}
- *uids = Realloc(*uids, (*num+1) * sizeof(uid_t));
+ *uids = SMB_REALLOC_ARRAY(*uids, uid_t, *num+1);
if (*uids == NULL)
return;
if(!get_memberuids(gid, &uids, &num))
return NT_STATUS_NO_SUCH_GROUP;
- rid=talloc_zero(p->mem_ctx, sizeof(uint32)*num);
- attr=talloc_zero(p->mem_ctx, sizeof(uint32)*num);
+ rid=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num);
+ attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num);
if (num!=0 && (rid==NULL || attr==NULL))
return NT_STATUS_NO_MEMORY;
if (!ret)
return NT_STATUS_INVALID_HANDLE;
- ctr=(GROUP_INFO_CTR *)talloc_zero(p->mem_ctx, sizeof(GROUP_INFO_CTR));
+ ctr=TALLOC_ZERO_P(p->mem_ctx, GROUP_INFO_CTR);
if (ctr==NULL)
return NT_STATUS_NO_MEMORY;
uint32 account_policy_temp;
- if ((ctr = (SAM_UNK_CTR *)talloc_zero(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
+ if ((ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_CTR)) == NULL)
return NT_STATUS_NO_MEMORY;
ZERO_STRUCTP(ctr);
if (!sp)
return NULL;
- new_sp = (SPOOL_NOTIFY_OPTION *)malloc(sizeof(SPOOL_NOTIFY_OPTION));
+ new_sp = SMB_MALLOC_P(SPOOL_NOTIFY_OPTION);
if (!new_sp)
return NULL;
DEBUG(10,("open_printer_hnd: name [%s]\n", name));
- if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
+ if((new_printer=SMB_MALLOC_P(Printer_entry)) == NULL)
return False;
ZERO_STRUCTP(new_printer);
init_unistr2(&unistr, msg->notify.data, UNI_STR_TERMINATE);
data->notify_data.data.length = msg->len * 2;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, msg->len * 2);
+ data->notify_data.data.string = TALLOC_ARRAY(mem_ctx, uint16, msg->len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
return;
data->notify_data.data.length = prs_offset(&ps);
- data->notify_data.data.string = talloc(mem_ctx, prs_offset(&ps));
+ data->notify_data.data.string = TALLOC(mem_ctx, prs_offset(&ps));
prs_copy_all_data_out((char *)data->notify_data.data.string, &ps);
if ( i == ctr->num_groups ) {
ctr->num_groups++;
- if ( !(groups = talloc_realloc( ctr->ctx, ctr->msg_groups, sizeof(SPOOLSS_NOTIFY_MSG_GROUP)*ctr->num_groups)) ) {
+ if ( !(groups = TALLOC_REALLOC_ARRAY( ctr->ctx, ctr->msg_groups, SPOOLSS_NOTIFY_MSG_GROUP, ctr->num_groups)) ) {
DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed!\n"));
return 0;
}
msg_grp->num_msgs++;
- if ( !(msg_list = talloc_realloc( ctr->ctx, msg_grp->msgs, sizeof(SPOOLSS_NOTIFY_MSG)*msg_grp->num_msgs )) ) {
+ if ( !(msg_list = TALLOC_REALLOC_ARRAY( ctr->ctx, msg_grp->msgs, SPOOLSS_NOTIFY_MSG, msg_grp->num_msgs )) ) {
DEBUG(0,("notify_msg_ctr_addmsg: talloc_realloc() failed for new message [%d]!\n", msg_grp->num_msgs));
return 0;
}
/* need to allocate own copy of data */
if ( msg->len != 0 )
- msg_grp->msgs[new_slot].notify.data = talloc_memdup( ctr->ctx, msg->notify.data, msg->len );
+ msg_grp->msgs[new_slot].notify.data = TALLOC_MEMDUP( ctr->ctx, msg->notify.data, msg->len );
return ctr->num_groups;
}
/* allocate the max entries possible */
- data = talloc( mem_ctx, msg_group->num_msgs*sizeof(SPOOL_NOTIFY_INFO_DATA) );
+ data = TALLOC_ARRAY( mem_ctx, SPOOL_NOTIFY_INFO_DATA, msg_group->num_msgs);
ZERO_STRUCTP(data);
/* build the array of change notifications */
/* bulk copy first */
- d = talloc_memdup(ctx, devmode, sizeof(DEVICEMODE));
+ d = TALLOC_MEMDUP(ctx, devmode, sizeof(DEVICEMODE));
if (!d)
return NULL;
len = unistrlen(devmode->devicename.buffer);
if (len != -1) {
- d->devicename.buffer = talloc(ctx, len*2);
+ d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
if (unistrcpy(d->devicename.buffer, devmode->devicename.buffer) != len)
return NULL;
}
len = unistrlen(devmode->formname.buffer);
if (len != -1) {
- d->devicename.buffer = talloc(ctx, len*2);
+ d->devicename.buffer = TALLOC_ARRAY(ctx, uint16, len);
if (unistrcpy(d->formname.buffer, devmode->formname.buffer) != len)
return NULL;
}
- d->private = talloc_memdup(ctx, devmode->private, devmode->driverextra);
+ d->private = TALLOC_MEMDUP(ctx, devmode->private, devmode->driverextra);
return d;
}
if ((devmode->driverextra != 0) && (devmode->private != NULL)) {
SAFE_FREE(nt_devmode->private);
nt_devmode->driverextra=devmode->driverextra;
- if((nt_devmode->private=(uint8 *)malloc(nt_devmode->driverextra * sizeof(uint8))) == NULL)
+ if((nt_devmode->private=SMB_MALLOC_ARRAY(uint8, nt_devmode->driverextra)) == NULL)
return False;
memcpy(nt_devmode->private, devmode->private, nt_devmode->driverextra);
}
/* special case for 0 length values */
if ( data_len ) {
- if ( (*data = (uint8 *)talloc_memdup(ctx, regval_data_p(val), data_len)) == NULL )
+ if ( (*data = (uint8 *)TALLOC_MEMDUP(ctx, regval_data_p(val), data_len)) == NULL )
return WERR_NOMEM;
}
else {
- if ( (*data = (uint8 *)talloc_zero(ctx, in_size)) == NULL )
+ if ( (*data = (uint8 *)TALLOC_ZERO(ctx, in_size)) == NULL )
return WERR_NOMEM;
}
}
if (!StrCaseCmp(value, "W3SvcInstalled")) {
*type = 0x4;
- if((*data = (uint8 *)talloc_zero(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC_ZERO(ctx, 4*sizeof(uint8) )) == NULL)
return WERR_NOMEM;
*needed = 0x4;
return WERR_OK;
if (!StrCaseCmp(value, "BeepEnabled")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4*sizeof(uint8) )) == NULL)
return WERR_NOMEM;
SIVAL(*data, 0, 0x00);
*needed = 0x4;
if (!StrCaseCmp(value, "EventLog")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
return WERR_NOMEM;
/* formally was 0x1b */
SIVAL(*data, 0, 0x0);
if (!StrCaseCmp(value, "NetPopup")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
return WERR_NOMEM;
SIVAL(*data, 0, 0x00);
*needed = 0x4;
if (!StrCaseCmp(value, "MajorVersion")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
return WERR_NOMEM;
/* Windows NT 4.0 seems to not allow uploading of drivers
if (!StrCaseCmp(value, "MinorVersion")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
return WERR_NOMEM;
SIVAL(*data, 0, 0);
*needed = 0x4;
*type = 0x3;
*needed = 0x114;
- if((*data = (uint8 *)talloc(ctx, (*needed)*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, *needed)) == NULL)
return WERR_NOMEM;
ZERO_STRUCTP( *data );
const char *string="C:\\PRINTERS";
*type = 0x1;
*needed = 2*(strlen(string)+1);
- if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
return WERR_NOMEM;
memset(*data, 0, (*needed > in_size) ? *needed:in_size);
const char *string="Windows NT x86";
*type = 0x1;
*needed = 2*(strlen(string)+1);
- if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
return WERR_NOMEM;
memset(*data, 0, (*needed > in_size) ? *needed:in_size);
for (i=0; i<strlen(string); i++) {
if (!StrCaseCmp(value, "DsPresent")) {
*type = 0x4;
- if((*data = (uint8 *)talloc(ctx, 4*sizeof(uint8) )) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, 4 )) == NULL)
return WERR_NOMEM;
SIVAL(*data, 0, 0x01);
*needed = 0x4;
return WERR_BADFILE;
*type = 0x1;
*needed = 2*(strlen(hostname)+1);
- if((*data = (uint8 *)talloc(ctx, ((*needed > in_size) ? *needed:in_size) *sizeof(uint8))) == NULL)
+ if((*data = (uint8 *)TALLOC(ctx, (*needed > in_size) ? *needed:in_size )) == NULL)
return WERR_NOMEM;
memset(*data, 0, (*needed > in_size) ? *needed:in_size);
for (i=0; i<strlen(hostname); i++) {
if ( strequal(value, "ChangeId") ) {
*type = REG_DWORD;
*needed = sizeof(uint32);
- if ( (*data = (uint8*)talloc(p->mem_ctx, sizeof(uint32))) == NULL) {
+ if ( (*data = (uint8*)TALLOC(p->mem_ctx, sizeof(uint32))) == NULL) {
status = WERR_NOMEM;
goto done;
}
/* reply this param doesn't exist */
if ( *out_size ) {
- if((*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL) {
+ if((*data=(uint8 *)TALLOC_ZERO_ARRAY(p->mem_ctx, uint8, *out_size)) == NULL) {
if ( printer )
free_a_printer( &printer, 2 );
return WERR_NOMEM;
len = rpcstr_push(temp, printer->info_2->servername, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, p, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, lp_servicename(snum), sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->portname, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->drivername, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->comment, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->location,sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->sepfile, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->printprocessor, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->parameters, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, printer->info_2->datatype, sizeof(pstring)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, queue->fs_user, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, queue->fs_file, sizeof(temp)-2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = rpcstr_push(temp, p, sizeof(temp) - 2, STR_TERMINATE);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
len = sizeof(SYSTEMTIME);
data->notify_data.data.length = len;
- data->notify_data.data.string = (uint16 *)talloc(mem_ctx, len);
+ data->notify_data.data.string = (uint16 *)TALLOC(mem_ctx, len);
if (!data->notify_data.data.string) {
data->notify_data.data.length = 0;
if (!search_notify(type, field, &j) )
continue;
- if((tid=(SPOOL_NOTIFY_INFO_DATA *)Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
+ if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
DEBUG(2,("construct_notify_printer_info: failed to enlarge buffer info->data!\n"));
return False;
} else
if (!search_notify(type, field, &j) )
continue;
- if((tid=Realloc(info->data, (info->count+1)*sizeof(SPOOL_NOTIFY_INFO_DATA))) == NULL) {
+ if((tid=SMB_REALLOC_ARRAY(info->data, SPOOL_NOTIFY_INFO_DATA, info->count+1)) == NULL) {
DEBUG(2,("construct_notify_jobs_info: failed to enlarg buffer info->data!\n"));
return False;
}
/* it's the first time, add it to the list */
if (session_counter==NULL) {
- if((session_counter=(counter_printer_0 *)malloc(sizeof(counter_printer_0))) == NULL) {
+ if((session_counter=SMB_MALLOC_P(counter_printer_0)) == NULL) {
free_a_printer(&ntprinter, 2);
return False;
}
goto done;
}
- if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) == NULL) {
+ if ((devmode = SMB_MALLOC_P(DEVICEMODE)) == NULL) {
DEBUG(2,("construct_dev_mode: malloc fail.\n"));
goto done;
}
return False;
*pp_printer = NULL;
- if ((printer = (PRINTER_INFO_3 *)malloc(sizeof(PRINTER_INFO_3))) == NULL) {
+ if ((printer = SMB_MALLOC_P(PRINTER_INFO_3)) == NULL) {
DEBUG(2,("construct_printer_info_3: malloc fail.\n"));
return False;
}
DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
if (construct_printer_info_1(NULL, flags, ¤t_prt, snum)) {
- if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_1))) == NULL) {
+ if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_1, *returned +1)) == NULL) {
DEBUG(2,("enum_all_printers_info_1: failed to enlarge printers buffer!\n"));
SAFE_FREE(printers);
*returned=0;
* undocumented RPC call.
*/
- if((printer=(PRINTER_INFO_1 *)malloc(sizeof(PRINTER_INFO_1))) == NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
return WERR_NOMEM;
*returned=1;
DEBUG(4,("Found a printer in smb.conf: %s[%x]\n", lp_servicename(snum), snum));
if (construct_printer_info_2(NULL, ¤t_prt, snum)) {
- if((tp=Realloc(printers, (*returned +1)*sizeof(PRINTER_INFO_2))) == NULL) {
+ if((tp=SMB_REALLOC_ARRAY(printers, PRINTER_INFO_2, *returned +1)) == NULL) {
DEBUG(2,("enum_all_printers_info_2: failed to enlarge printers buffer!\n"));
SAFE_FREE(printers);
*returned = 0;
{
PRINTER_INFO_0 *printer=NULL;
- if((printer=(PRINTER_INFO_0*)malloc(sizeof(PRINTER_INFO_0))) == NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_0)) == NULL)
return WERR_NOMEM;
construct_printer_info_0(print_hnd, printer, snum);
{
PRINTER_INFO_1 *printer=NULL;
- if((printer=(PRINTER_INFO_1*)malloc(sizeof(PRINTER_INFO_1))) == NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_1)) == NULL)
return WERR_NOMEM;
construct_printer_info_1(print_hnd, PRINTER_ENUM_ICON8, printer, snum);
{
PRINTER_INFO_2 *printer=NULL;
- if((printer=(PRINTER_INFO_2*)malloc(sizeof(PRINTER_INFO_2)))==NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_2))==NULL)
return WERR_NOMEM;
construct_printer_info_2(print_hnd, printer, snum);
{
PRINTER_INFO_4 *printer=NULL;
- if((printer=(PRINTER_INFO_4*)malloc(sizeof(PRINTER_INFO_4)))==NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_4))==NULL)
return WERR_NOMEM;
if (!construct_printer_info_4(print_hnd, printer, snum))
{
PRINTER_INFO_5 *printer=NULL;
- if((printer=(PRINTER_INFO_5*)malloc(sizeof(PRINTER_INFO_5)))==NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_5))==NULL)
return WERR_NOMEM;
if (!construct_printer_info_5(print_hnd, printer, snum))
{
PRINTER_INFO_7 *printer=NULL;
- if((printer=(PRINTER_INFO_7*)malloc(sizeof(PRINTER_INFO_7)))==NULL)
+ if((printer=SMB_MALLOC_P(PRINTER_INFO_7))==NULL)
return WERR_NOMEM;
if (!construct_printer_info_7(print_hnd, printer, snum))
/* add one extra unit16 for the second terminating NULL */
- if ( (tuary=Realloc(*uni_array, (j+1+strlen(line)+2)*sizeof(uint16))) == NULL ) {
+ if ( (tuary=SMB_REALLOC_ARRAY(*uni_array, uint16, j+1+strlen(line)+2)) == NULL ) {
DEBUG(2,("init_unistr_array: Realloc error\n" ));
return 0;
} else
DRIVER_INFO_1 *info=NULL;
WERROR status;
- if((info=(DRIVER_INFO_1 *)malloc(sizeof(DRIVER_INFO_1))) == NULL)
+ if((info=SMB_MALLOC_P(DRIVER_INFO_1)) == NULL)
return WERR_NOMEM;
status=construct_printer_driver_info_1(info, snum, servername, architecture, version);
DRIVER_INFO_2 *info=NULL;
WERROR status;
- if((info=(DRIVER_INFO_2 *)malloc(sizeof(DRIVER_INFO_2))) == NULL)
+ if((info=SMB_MALLOC_P(DRIVER_INFO_2)) == NULL)
return WERR_NOMEM;
status=construct_printer_driver_info_2(info, snum, servername, architecture, version);
JOB_INFO_1 *info;
int i;
- info=(JOB_INFO_1 *)malloc(*returned*sizeof(JOB_INFO_1));
+ info=SMB_MALLOC_ARRAY(JOB_INFO_1,*returned);
if (info==NULL) {
SAFE_FREE(queue);
*returned=0;
WERROR result;
DEVICEMODE *devmode = NULL;
- info=(JOB_INFO_2 *)malloc(*returned*sizeof(JOB_INFO_2));
+ info=SMB_MALLOC_ARRAY(JOB_INFO_2,*returned);
if (info==NULL) {
*returned=0;
result = WERR_NOMEM;
return WERR_NOMEM;
if(ndrivers != 0) {
- if((tdi1=(DRIVER_INFO_1 *)Realloc(driver_info_1, (*returned+ndrivers) * sizeof(DRIVER_INFO_1))) == NULL) {
+ if((tdi1=SMB_REALLOC_ARRAY(driver_info_1, DRIVER_INFO_1, *returned+ndrivers )) == NULL) {
DEBUG(0,("enumprinterdrivers_level1: failed to enlarge driver info buffer!\n"));
SAFE_FREE(driver_info_1);
SAFE_FREE(list);
return WERR_NOMEM;
if(ndrivers != 0) {
- if((tdi2=(DRIVER_INFO_2 *)Realloc(driver_info_2, (*returned+ndrivers) * sizeof(DRIVER_INFO_2))) == NULL) {
+ if((tdi2=SMB_REALLOC_ARRAY(driver_info_2, DRIVER_INFO_2, *returned+ndrivers )) == NULL) {
DEBUG(0,("enumprinterdrivers_level2: failed to enlarge driver info buffer!\n"));
SAFE_FREE(driver_info_2);
SAFE_FREE(list);
return WERR_NOMEM;
if(ndrivers != 0) {
- if((tdi3=(DRIVER_INFO_3 *)Realloc(driver_info_3, (*returned+ndrivers) * sizeof(DRIVER_INFO_3))) == NULL) {
+ if((tdi3=SMB_REALLOC_ARRAY(driver_info_3, DRIVER_INFO_3, *returned+ndrivers )) == NULL) {
DEBUG(0,("enumprinterdrivers_level3: failed to enlarge driver info buffer!\n"));
SAFE_FREE(driver_info_3);
SAFE_FREE(list);
switch (level) {
case 1:
- if ((forms_1=(FORM_1 *)malloc(*numofforms * sizeof(FORM_1))) == NULL) {
+ if ((forms_1=SMB_MALLOC_ARRAY(FORM_1, *numofforms)) == NULL) {
*numofforms=0;
return WERR_NOMEM;
}
close(fd);
if(numlines) {
- if((ports=(PORT_INFO_1 *)malloc( numlines * sizeof(PORT_INFO_1) )) == NULL) {
+ if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
DEBUG(10,("Returning WERR_NOMEM [%s]\n",
dos_errstr(WERR_NOMEM)));
file_lines_free(qlines);
} else {
*returned = 1; /* Sole Samba port returned. */
- if((ports=(PORT_INFO_1 *)malloc( sizeof(PORT_INFO_1) )) == NULL)
+ if((ports=SMB_MALLOC_P(PORT_INFO_1)) == NULL)
return WERR_NOMEM;
DEBUG(10,("enumports_level_1: port name %s\n", SAMBA_PRINTER_PORT_NAME));
close(fd);
if(numlines) {
- if((ports=(PORT_INFO_2 *)malloc( numlines * sizeof(PORT_INFO_2) )) == NULL) {
+ if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
file_lines_free(qlines);
return WERR_NOMEM;
}
*returned = 1;
- if((ports=(PORT_INFO_2 *)malloc( sizeof(PORT_INFO_2) )) == NULL)
+ if((ports=SMB_MALLOC_P(PORT_INFO_2)) == NULL)
return WERR_NOMEM;
DEBUG(10,("enumports_level_2: port name %s\n", SAMBA_PRINTER_PORT_NAME));
int snum;
WERROR err = WERR_OK;
- if ((printer = (NT_PRINTER_INFO_LEVEL *)malloc(sizeof(NT_PRINTER_INFO_LEVEL))) == NULL) {
+ if ((printer = SMB_MALLOC_P(NT_PRINTER_INFO_LEVEL)) == NULL) {
DEBUG(0,("spoolss_addprinterex_level_2: malloc fail.\n"));
return WERR_NOMEM;
}
if (!(short_archi = get_short_archi(long_archi)))
return WERR_INVALID_ENVIRONMENT;
- if((info=(DRIVER_DIRECTORY_1 *)malloc(sizeof(DRIVER_DIRECTORY_1))) == NULL)
+ if((info=SMB_MALLOC_P(DRIVER_DIRECTORY_1)) == NULL)
return WERR_NOMEM;
slprintf(path, sizeof(path)-1, "\\\\%s\\print$\\%s", pservername, short_archi);
*out_max_value_len=(in_value_len/sizeof(uint16));
- if((*out_value=(uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
+ if((*out_value=(uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL)
{
result = WERR_NOMEM;
goto done;
/* only allocate when given a non-zero data_len */
- if ( in_data_len && ((*data_out=(uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
+ if ( in_data_len && ((*data_out=(uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL) )
{
result = WERR_NOMEM;
goto done;
/* name */
*out_max_value_len=(in_value_len/sizeof(uint16));
- if ( (*out_value = (uint16 *)talloc_zero(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL )
+ if ( (*out_value = (uint16 *)TALLOC_ZERO(p->mem_ctx, in_value_len*sizeof(uint8))) == NULL )
{
result = WERR_NOMEM;
goto done;
/* data - counted in bytes */
*out_max_data_len = in_data_len;
- if ( (*data_out = (uint8 *)talloc_zero(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
+ if ( (*data_out = (uint8 *)TALLOC_ZERO(p->mem_ctx, in_data_len*sizeof(uint8))) == NULL)
{
result = WERR_NOMEM;
goto done;
{
PRINTPROCESSOR_1 *info_1=NULL;
- if((info_1 = (PRINTPROCESSOR_1 *)malloc(sizeof(PRINTPROCESSOR_1))) == NULL)
+ if((info_1 = SMB_MALLOC_P(PRINTPROCESSOR_1)) == NULL)
return WERR_NOMEM;
(*returned) = 0x1;
{
PRINTPROCDATATYPE_1 *info_1=NULL;
- if((info_1 = (PRINTPROCDATATYPE_1 *)malloc(sizeof(PRINTPROCDATATYPE_1))) == NULL)
+ if((info_1 = SMB_MALLOC_P(PRINTPROCDATATYPE_1)) == NULL)
return WERR_NOMEM;
(*returned) = 0x1;
{
PRINTMONITOR_1 *info_1=NULL;
- if((info_1 = (PRINTMONITOR_1 *)malloc(sizeof(PRINTMONITOR_1))) == NULL)
+ if((info_1 = SMB_MALLOC_P(PRINTMONITOR_1)) == NULL)
return WERR_NOMEM;
(*returned) = 0x1;
{
PRINTMONITOR_2 *info_2=NULL;
- if((info_2 = (PRINTMONITOR_2 *)malloc(sizeof(PRINTMONITOR_2))) == NULL)
+ if((info_2 = SMB_MALLOC_P(PRINTMONITOR_2)) == NULL)
return WERR_NOMEM;
(*returned) = 0x1;
BOOL found=False;
JOB_INFO_1 *info_1=NULL;
- info_1=(JOB_INFO_1 *)malloc(sizeof(JOB_INFO_1));
+ info_1=SMB_MALLOC_P(JOB_INFO_1);
if (info_1 == NULL) {
return WERR_NOMEM;
DEVICEMODE *devmode = NULL;
NT_DEVICEMODE *nt_devmode = NULL;
- info_2=(JOB_INFO_2 *)malloc(sizeof(JOB_INFO_2));
+ info_2=SMB_MALLOC_P(JOB_INFO_2);
ZERO_STRUCTP(info_2);
if ( !(nt_devmode=print_job_devmode( lp_const_servicename(snum), jobid )) )
devmode = construct_dev_mode(snum);
else {
- if ((devmode = (DEVICEMODE *)malloc(sizeof(DEVICEMODE))) != NULL) {
+ if ((devmode = SMB_MALLOC_P(DEVICEMODE)) != NULL) {
ZERO_STRUCTP( devmode );
convert_nt_devicemode( devmode, nt_devmode );
}
if ( *out_size )
{
- if( (*data=(uint8 *)talloc_zero(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) {
+ if( (*data=(uint8 *)TALLOC_ZERO(p->mem_ctx, *out_size*sizeof(uint8))) == NULL ) {
status = WERR_NOMEM;
goto done;
}
num_entries = regval_ctr_numvals( &p_data->keys[key_index].values );
if ( num_entries )
{
- if ( (enum_values=talloc(p->mem_ctx, num_entries*sizeof(PRINTER_ENUM_VALUES))) == NULL )
+ if ( (enum_values=TALLOC_ARRAY(p->mem_ctx, PRINTER_ENUM_VALUES, num_entries)) == NULL )
{
DEBUG(0,("_spoolss_enumprinterdataex: talloc() failed to allocate memory for [%lu] bytes!\n",
(unsigned long)num_entries*sizeof(PRINTER_ENUM_VALUES)));
data_len = regval_size( val );
if ( data_len ) {
- if ( !(enum_values[i].data = talloc_memdup(p->mem_ctx, regval_data_p(val), data_len)) )
+ if ( !(enum_values[i].data = TALLOC_MEMDUP(p->mem_ctx, regval_data_p(val), data_len)) )
{
DEBUG(0,("talloc_memdup failed to allocate memory [data_len=%d] for data!\n",
data_len ));
if (!get_short_archi(long_archi))
return WERR_INVALID_ENVIRONMENT;
- if((info=(PRINTPROCESSOR_DIRECTORY_1 *)malloc(sizeof(PRINTPROCESSOR_DIRECTORY_1))) == NULL)
+ if((info=SMB_MALLOC_P(PRINTPROCESSOR_DIRECTORY_1)) == NULL)
return WERR_NOMEM;
pstrcpy(path, "C:\\WINNT\\System32\\spool\\PRTPROCS\\W32X86");
switch (info_level) {
case 0:
{
- SRV_SHARE_INFO_0 *info0;
+ SRV_SHARE_INFO_0 *info0 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_0, num_entries);
int i = 0;
- info0 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_0));
+ if (!info0) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1:
{
- SRV_SHARE_INFO_1 *info1;
+ SRV_SHARE_INFO_1 *info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
int i = 0;
- info1 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1));
+ if (!info1) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 2:
{
- SRV_SHARE_INFO_2 *info2;
+ SRV_SHARE_INFO_2 *info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
int i = 0;
- info2 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_2));
+ if (!info2) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 501:
{
- SRV_SHARE_INFO_501 *info501;
+ SRV_SHARE_INFO_501 *info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
int i = 0;
- info501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_501));
+ if (!info501) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 502:
{
- SRV_SHARE_INFO_502 *info502;
+ SRV_SHARE_INFO_502 *info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
int i = 0;
- info502 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_502));
+ if (!info502) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1004:
{
- SRV_SHARE_INFO_1004 *info1004;
+ SRV_SHARE_INFO_1004 *info1004 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1004, num_entries);
int i = 0;
- info1004 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1004));
+ if (!info1004) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1005:
{
- SRV_SHARE_INFO_1005 *info1005;
+ SRV_SHARE_INFO_1005 *info1005 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1005, num_entries);
int i = 0;
- info1005 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1005));
+ if (!info1005) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1006:
{
- SRV_SHARE_INFO_1006 *info1006;
+ SRV_SHARE_INFO_1006 *info1006 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1006, num_entries);
int i = 0;
- info1006 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1006));
+ if (!info1006) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1007:
{
- SRV_SHARE_INFO_1007 *info1007;
+ SRV_SHARE_INFO_1007 *info1007 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1007, num_entries);
int i = 0;
- info1007 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1007));
+ if (!info1007) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
case 1501:
{
- SRV_SHARE_INFO_1501 *info1501;
+ SRV_SHARE_INFO_1501 *info1501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1501, num_entries);
int i = 0;
- info1501 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1501));
+ if (!info1501) {
+ return False;
+ }
for (snum = *resume_hnd; snum < num_services; snum++) {
if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
int i;
if (*total_entries > 0) {
ctr->ptr_entries = 1;
- ctr->file.info3 = talloc(ctx, ctr->num_entries *
- sizeof(SRV_FILE_INFO_3));
+ ctr->file.info3 = TALLOC_ARRAY(ctx, SRV_FILE_INFO_3, ctr->num_entries);
}
for (i=0 ;i<ctr->num_entries;i++) {
init_srv_file_info3(&ctr->file.info3[i].info_3, i+*resume_hnd, 0x35, 0, "\\PIPE\\samr", "dummy user");
WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
{
WERROR status = WERR_OK;
- SRV_INFO_CTR *ctr = (SRV_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_INFO_CTR));
+ SRV_INFO_CTR *ctr = TALLOC_P(p->mem_ctx, SRV_INFO_CTR);
if (!ctr)
return WERR_NOMEM;
{
DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
- r_u->ctr = (SRV_CONN_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_CONN_INFO_CTR));
+ r_u->ctr = TALLOC_P(p->mem_ctx, SRV_CONN_INFO_CTR);
if (!r_u->ctr)
return WERR_NOMEM;
{
DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
- r_u->ctr = (SRV_SESS_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_SESS_INFO_CTR));
+ r_u->ctr = TALLOC_P(p->mem_ctx, SRV_SESS_INFO_CTR);
if (!r_u->ctr)
return WERR_NOMEM;
struct tm *t;
time_t unixdate = time(NULL);
- tod = (TIME_OF_DAY_INFO *)talloc(p->mem_ctx, sizeof(TIME_OF_DAY_INFO));
+ tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO);
if (!tod)
return WERR_NOMEM;
r_u->disk_enum_ctr.unknown = 0;
- {
- DISK_INFO *dinfo;
-
- int dinfo_size = MAX_SERVER_DISK_ENTRIES * sizeof(*dinfo);
-
- if(!(dinfo = talloc(ctx, dinfo_size))) {
- return WERR_NOMEM;
- }
-
- r_u->disk_enum_ctr.disk_info = dinfo;
+ if(!(r_u->disk_enum_ctr.disk_info = TALLOC_ARRAY(ctx, DISK_INFO, MAX_SERVER_DISK_ENTRIES))) {
+ return WERR_NOMEM;
}
r_u->disk_enum_ctr.disk_info_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
DOM_GID *gids;
int i;
- gids = (DOM_GID *)talloc(mem_ctx, sizeof(*gids) * nt_token->num_sids);
+ gids = TALLOC_ARRAY(mem_ctx, DOM_GID, nt_token->num_sids);
if (!gids) {
return NT_STATUS_NO_MEMORY;
DEBUG(5,("_wks_query_info: %d\n", __LINE__));
- wks100 = (WKS_INFO_100 *)talloc_zero(p->mem_ctx, sizeof(WKS_INFO_100));
+ wks100 = TALLOC_ZERO_P(p->mem_ctx, WKS_INFO_100);
if (!wks100)
return NT_STATUS_NO_MEMORY;
}
size = atoi(argv[1]);
- in_data = malloc(size);
+ in_data = SMB_MALLOC(size);
for (i = 0; i < size; i++)
in_data[i] = i & 0xff;
}
size = atoi(argv[1]);
- in_data = malloc(size);
+ in_data = SMB_MALLOC(size);
for (i = 0; i < size; i++)
in_data[i] = i & 0xff;
/* Convert arguments to sids */
- sids = (DOM_SID *)talloc(mem_ctx, sizeof(DOM_SID) * (argc - 1));
+ sids = TALLOC_ARRAY(mem_ctx, DOM_SID, argc - 1);
if (!sids) {
printf("could not allocate memory for %d sids\n", argc - 1);
/* Look up names */
num_names = argc - 2;
- names = (const char **)talloc(mem_ctx, sizeof(char *) * num_names);
+ names = TALLOC_ARRAY(mem_ctx, const char *, num_names);
for (i = 0; i < argc - 2; i++)
names[i] = argv[i + 2];
/* Look up rids */
num_rids = argc - 1;
- rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
+ rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
for (i = 0; i < argc - 1; i++)
sscanf(argv[i + 1], "%i", &rids[i]);
/* allocate the space; add one extra slot for a terminating NULL.
Each filename is NULL terminated and the end contains a double
NULL */
- if ((info->dependentfiles=(uint16*)talloc(mem_ctx, (len+1)*sizeof(uint16))) == NULL)
+ if ((info->dependentfiles=TALLOC_ARRAY(mem_ctx, uint16, len+1)) == NULL)
{
DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
return False;
fstrcpy(value.valuename, argv[2]);
value.type = REG_SZ;
value.size = data.uni_str_len * 2;
- value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size);
+ value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
result = cli_spoolss_setprinterdata(cli, mem_ctx, &pol, &value);
option.option_type_ptr = 1;
option.count = option.ctr.count = 2;
- option.ctr.type = (SPOOL_NOTIFY_OPTION_TYPE *)talloc(
- mem_ctx, sizeof(SPOOL_NOTIFY_OPTION_TYPE) * 2);
+ option.ctr.type = TALLOC_ARRAY(mem_ctx, SPOOL_NOTIFY_OPTION_TYPE, 2);
ZERO_STRUCT(option.ctr.type[0]);
option.ctr.type[0].type = PRINTER_NOTIFY_TYPE;
if (!commands)
return NULL;
- matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS);
+ matches = SMB_MALLOC_ARRAY(char *, MAX_COMPLETIONS);
if (!matches) return NULL;
- matches[count++] = strdup(text);
+ matches[count++] = SMB_STRDUP(text);
if (!matches[0]) return NULL;
while (commands && count < MAX_COMPLETIONS-1)
( commands->cmd_set[i].returntype == RPC_RTYPE_WERROR &&
commands->cmd_set[i].wfn)))
{
- matches[count] = strdup(commands->cmd_set[i].name);
+ matches[count] = SMB_STRDUP(commands->cmd_set[i].name);
if (!matches[count])
return NULL;
count++;
if (count == 2) {
SAFE_FREE(matches[0]);
- matches[0] = strdup(matches[1]);
+ matches[0] = SMB_STRDUP(matches[1]);
}
matches[count] = NULL;
return matches;
{
struct cmd_list *entry;
- if (!(entry = (struct cmd_list *)malloc(sizeof(struct cmd_list)))) {
+ if (!(entry = SMB_MALLOC_P(struct cmd_list))) {
DEBUG(0, ("out of memory\n"));
return;
}
return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = smb_xmalloc(sizeof(struct idmap_function_entry));
+ entry = SMB_XMALLOC_P(struct idmap_function_entry);
entry->name = smb_xstrdup(name);
entry->methods = methods;
BOOL tdb_is_new = False;
/* use the old database if present */
- tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
+ tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb"));
if (!tdbfile) {
DEBUG(0, ("idmap_init: out of memory!\n"));
return NT_STATUS_NO_MEMORY;
* the expiration time here.
*/
- if((blr = (blocking_lock_record *)malloc(sizeof(blocking_lock_record))) == NULL) {
+ if((blr = SMB_MALLOC_P(blocking_lock_record)) == NULL) {
DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
return False;
}
- if((blr->inbuf = (char *)malloc(length)) == NULL) {
+ if((blr->inbuf = (char *)SMB_MALLOC(length)) == NULL) {
DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
SAFE_FREE(blr);
return False;
return NULL;
}
- if ((conn=(connection_struct *)talloc_zero(mem_ctx, sizeof(*conn)))==NULL) {
+ if ((conn=TALLOC_ZERO_P(mem_ctx, connection_struct))==NULL) {
DEBUG(0,("talloc_zero() failed!\n"));
return NULL;
}
if (dptrs_open >= MAX_OPEN_DIRECTORIES)
dptr_idleoldest();
- dptr = (dptr_struct *)malloc(sizeof(dptr_struct));
+ dptr = SMB_MALLOC_P(dptr_struct);
if(!dptr) {
DEBUG(0,("malloc fail in dptr_create.\n"));
return -1;
if (!p)
return(NULL);
- dirp = (Dir *)malloc(sizeof(Dir));
+ dirp = SMB_MALLOC_P(Dir);
if (!dirp) {
DEBUG(0,("Out of memory in OpenDir\n"));
SMB_VFS_CLOSEDIR(conn,p);
if (used + l > dirp->mallocsize) {
int s = MAX(used+l,used+2000);
char *r;
- r = (char *)Realloc(dirp->data,s);
+ r = (char *)SMB_REALLOC(dirp->data,s);
if (!r) {
DEBUG(0,("Out of memory in OpenDir\n"));
break;
return NULL;
}
- if ((fh =(FAKE_FILE_HANDLE *)talloc_zero(mem_ctx, sizeof(FAKE_FILE_HANDLE)))==NULL) {
+ if ((fh =TALLOC_ZERO_P(mem_ctx, FAKE_FILE_HANDLE))==NULL) {
DEBUG(0,("talloc_zero() failed.\n"));
talloc_destroy(mem_ctx);
return NULL;
if(alloc_size == 0 || fsp->wcp)
return False;
- if((wcp = (write_cache *)malloc(sizeof(write_cache))) == NULL) {
+ if((wcp = SMB_MALLOC_P(write_cache)) == NULL) {
DEBUG(0,("setup_write_cache: malloc fail.\n"));
return False;
}
wcp->offset = 0;
wcp->alloc_size = alloc_size;
wcp->data_size = 0;
- if((wcp->data = malloc(wcp->alloc_size)) == NULL) {
+ if((wcp->data = SMB_MALLOC(wcp->alloc_size)) == NULL) {
DEBUG(0,("setup_write_cache: malloc fail for buffer size %u.\n",
(unsigned int)wcp->alloc_size ));
SAFE_FREE(wcp);
return NULL;
}
- fsp = (files_struct *)malloc(sizeof(*fsp));
+ fsp = SMB_MALLOC_P(files_struct);
if (!fsp) {
unix_ERR_class = ERRSRV;
unix_ERR_code = ERRnofids;
static BOOL api_rpc_trans_reply(char *outbuf, smb_np_struct *p)
{
BOOL is_data_outstanding;
- char *rdata = malloc(p->max_trans_reply);
+ char *rdata = SMB_MALLOC(p->max_trans_reply);
int data_len;
if(rdata == NULL) {
goto bad_param;
if (tdscnt) {
- if((data = (char *)malloc(tdscnt)) == NULL) {
+ if((data = (char *)SMB_MALLOC(tdscnt)) == NULL) {
DEBUG(0,("reply_trans: data malloc fail for %u bytes !\n", tdscnt));
END_PROFILE(SMBtrans);
return(ERROR_DOS(ERRDOS,ERRnomem));
}
if (tpscnt) {
- if((params = (char *)malloc(tpscnt)) == NULL) {
+ if((params = (char *)SMB_MALLOC(tpscnt)) == NULL) {
DEBUG(0,("reply_trans: param malloc fail for %u bytes !\n", tpscnt));
SAFE_FREE(data);
END_PROFILE(SMBtrans);
if (suwcnt) {
unsigned int i;
- if((setup = (uint16 *)malloc(suwcnt*sizeof(uint16))) == NULL) {
+ if((setup = SMB_MALLOC_ARRAY(uint16,suwcnt)) == NULL) {
DEBUG(0,("reply_trans: setup malloc fail for %u bytes !\n", (unsigned int)(suwcnt * sizeof(uint16))));
SAFE_FREE(data);
SAFE_FREE(params);
*/
*rdata_len = 0;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,ERRunknownlevel);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,0);
}
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
* init_package will return wrong size if buflen=0
*/
desc.buflen = getlen(desc.format);
- desc.base = tmpdata = (char *) malloc (desc.buflen);
+ desc.base = tmpdata = (char *) SMB_MALLOC (desc.buflen);
}
if (init_package(&desc,1,count)) {
*rdata_len = desc.usedlen;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,desc.neededlen);
*/
*rdata_len = 0;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,ERRunknownlevel);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,0);
if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
queuecnt++;
if (uLevel > 0) {
- if((queue = (print_queue_struct**)malloc(queuecnt*sizeof(print_queue_struct*))) == NULL) {
+ if((queue = SMB_MALLOC_ARRAY(print_queue_struct*, queuecnt)) == NULL) {
DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
return False;
}
memset(queue,0,queuecnt*sizeof(print_queue_struct*));
- if((status = (print_status_struct*)malloc(queuecnt*sizeof(print_status_struct))) == NULL) {
+ if((status = SMB_MALLOC_ARRAY(print_status_struct,queuecnt)) == NULL) {
DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
return False;
}
memset(status,0,queuecnt*sizeof(print_status_struct));
- if((subcntarr = (int*)malloc(queuecnt*sizeof(int))) == NULL) {
+ if((subcntarr = SMB_MALLOC_ARRAY(int,queuecnt)) == NULL) {
DEBUG(0,("api_DosPrintQEnum: malloc fail !\n"));
return False;
}
n++;
}
}
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
struct srv_info_struct *ts;
alloced += 10;
- ts = (struct srv_info_struct *)
- Realloc(*servers,sizeof(**servers)*alloced);
+ ts = SMB_REALLOC_ARRAY(*servers,struct srv_info_struct, alloced);
if (!ts) {
DEBUG(0,("get_server_info: failed to enlarge servers info struct!\n"));
return(0);
}
*rdata_len = fixed_len + string_len;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
memset(*rdata,'\0',*rdata_len);
p2 = (*rdata) + fixed_len; /* auxilliary data (strings) will go here */
}
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,(missed == 0 ? NERR_Success : ERRmoredata));
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,counted);
*rdata_len = 0;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,0x08AC); /* informational warning message */
SSVAL(*rparam,2,0);
if (!prefix_ok(str1,"zWrLh")) return False;
if (!check_share_info(uLevel,str2)) return False;
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
p = *rdata;
*rdata_len = fill_share_info(conn,snum,uLevel,&p,&mdrcnt,0,0,0);
if (*rdata_len < 0) return False;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
SSVAL(*rparam,4,*rdata_len);
}
}
*rdata_len = fixed_len + string_len;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
memset(*rdata,0,*rdata_len);
p2 = (*rdata) + fixed_len; /* auxiliary data (strings) will go here */
}
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,missed ? ERRmoredata : NERR_Success);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,counted);
} else return False;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
SSVAL(*rparam,4,*rdata_len);
error_exit:
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
SSVAL(*rparam,0,res);
SSVAL(*rparam,2,0);
DEBUG(10,("api_RNetGroupEnum:resume context: %d, client buffer size: %d\n", resume_context, cli_buf_size));
*rdata_len = cli_buf_size;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
p = *rdata;
*rdata_len = PTR_DIFF(p,*rdata);
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam, 0, errflags);
SSVAL(*rparam, 2, 0); /* converter word */
NTSTATUS result;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
/* check it's a supported varient */
return False;
*rdata_len = mdrcnt + 1024;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
DEBUG(10,("api_RNetUserEnum:resume context: %d, client buffer size: %d\n", resume_context, cli_buf_size));
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
/* check it's a supported varient */
if (strcmp("B21",str2) != 0)
return False;
*rdata_len = cli_buf_size;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
p = *rdata;
{
char *p;
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 21;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
memcpy(pass2,p+16,16);
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
fstring user;
char *p = param + 2;
*rparam_len = 2;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
return(False);
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
if (!print_job_exists(sharename, jobid)) {
return(False);
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
snum = print_queue_snum(QueueName);
if(!rap_to_pjobid(SVAL(p,0), sharename, &jobid))
return False;
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
if ( (snum = lp_servicenumber(sharename)) == -1 ) {
DEBUG(0,("api_PrintJobInfo: unable to get service number from sharename [%s]\n",
}
*rdata_len = mdrcnt;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
p = *rdata;
p2 = p + struct_len;
*rdata_len = PTR_DIFF(p2,*rdata);
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
SSVAL(*rparam,4,*rdata_len);
DEBUG(4,("NetWkstaGetInfo level %d\n",level));
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
/* check it's a supported varient */
if (!(level==10 && strcsequal(str1,"WrLh") && strcsequal(str2,"zzzBBzz")))
return(False);
*rdata_len = mdrcnt + 1024;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
vuser->user.unix_name));
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
DEBUG(4,("RNetUserGetInfo level=%d\n", uLevel));
if (strcmp(level_string,str2) != 0) return False;
*rdata_len = mdrcnt + 1024;
- *rdata = REALLOC(*rdata,*rdata_len);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,*rdata_len);
SSVAL(*rparam,0,NERR_Success);
SSVAL(*rparam,2,0); /* converter word */
/* check it's a supported varient */
if (strcmp(str1,"OOWb54WrLh") != 0) return False;
if (uLevel != 1 || strcmp(str2,"WB21BWDWWDDDDDDDzzzD") != 0) return False;
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
desc.subformat = NULL;
*rdata_len = desc.usedlen;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,desc.neededlen);
if (strcmp(str2,"") != 0) return False;
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,0); /* errorcode */
SSVAL(*rparam,2,0); /* converter word */
SSVAL(*rparam,4,0x7f); /* permission flags */
}
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
* init_package will return wrong size if buflen=0
*/
desc.buflen = getlen(desc.format);
- desc.base = tmpdata = (char *)malloc ( desc.buflen );
+ desc.base = tmpdata = (char *)SMB_MALLOC( desc.buflen );
}
if (init_package(&desc,1,0)) {
}
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,desc.neededlen);
return False;
count = print_queue_status(snum,&queue,&status);
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
}
else {
if (mdrcnt > 0) {
- *rdata = REALLOC(*rdata,mdrcnt);
+ *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
} else {
* init_package will return wrong size if buflen=0
*/
desc.buflen = getlen(desc.format);
- desc.base = tmpdata = (char *)malloc ( desc.buflen );
+ desc.base = tmpdata = (char *)SMB_MALLOC( desc.buflen );
}
if (init_package(&desc,1,0)) {
fill_printdest_info(conn,snum,uLevel,&desc);
}
*rparam_len = 6;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,desc.neededlen);
if (lp_snum_ok(i) && lp_print_ok(i) && lp_browseable(i))
queuecnt++;
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
if (init_package(&desc,queuecnt,0)) {
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
if (strcmp(str1,"WrLeh") != 0) return False;
if (uLevel != 0 || strcmp(str2,"B41") != 0) return False;
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
if (init_package(&desc,1,0)) {
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
if (strcmp(str1,"WrLeh") != 0) return False;
if (uLevel != 0 || strcmp(str2,"B13") != 0) return False;
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
desc.base = *rdata;
desc.buflen = mdrcnt;
desc.format = str2;
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
if (strcmp(str1,"WrLeh") != 0) return False;
if (uLevel != 0 || strcmp(str2,"B9") != 0) return False;
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
memset((char *)&desc,'\0',sizeof(desc));
desc.base = *rdata;
desc.buflen = mdrcnt;
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0);
SSVAL(*rparam,4,succnt);
num_sessions = list_sessions(&session_list);
- if (mdrcnt > 0) *rdata = REALLOC(*rdata,mdrcnt);
+ if (mdrcnt > 0) *rdata = SMB_REALLOC_LIMIT(*rdata,mdrcnt);
memset((char *)&desc,'\0',sizeof(desc));
desc.base = *rdata;
desc.buflen = mdrcnt;
*rdata_len = desc.usedlen;
*rparam_len = 8;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
SSVALS(*rparam,0,desc.errcode);
SSVAL(*rparam,2,0); /* converter */
SSVAL(*rparam,4,num_sessions); /* count */
int *rdata_len,int *rparam_len)
{
*rparam_len = MIN(*rparam_len,mprcnt);
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
int *rdata_len,int *rparam_len)
{
*rparam_len = 4;
- *rparam = REALLOC(*rparam,*rparam_len);
+ *rparam = SMB_REALLOC_LIMIT(*rparam,*rparam_len);
*rdata_len = 0;
return ERROR_NT(NT_STATUS_ACCESS_DENIED);
}
- rdata = (char *)malloc(1024);
+ rdata = (char *)SMB_MALLOC(1024);
if (rdata)
memset(rdata,'\0',1024);
- rparam = (char *)malloc(1024);
+ rparam = (char *)SMB_MALLOC(1024);
if (rparam)
memset(rparam,'\0',1024);
if(data_val.dptr == NULL || data_val.dsize == 0) {
ext_start = strrchr( s, '.' );
if( ext_start ) {
- if((saved_ext = strdup(ext_start)) == NULL)
+ if((saved_ext = SMB_STRDUP(ext_start)) == NULL)
return False;
*ext_start = '\0';
/* mangle it into 8.3 */
if (cache83)
- tmp = strdup(OutName);
+ tmp = SMB_STRDUP(OutName);
to_8_3(OutName, default_case);
*/
static BOOL cache_init(void)
{
- if (prefix_cache) return True;
+ if (prefix_cache) {
+ return True;
+ }
- prefix_cache = calloc(MANGLE_CACHE_SIZE, sizeof(char *));
- if (!prefix_cache) return False;
+ prefix_cache = SMB_CALLOC_ARRAY(char *,MANGLE_CACHE_SIZE);
+ if (!prefix_cache) {
+ return False;
+ }
- prefix_cache_hashes = calloc(MANGLE_CACHE_SIZE, sizeof(u32));
- if (!prefix_cache_hashes) return False;
+ prefix_cache_hashes = SMB_CALLOC_ARRAY(u32, MANGLE_CACHE_SIZE);
+ if (!prefix_cache_hashes) {
+ return False;
+ }
return True;
}
free(prefix_cache[i]);
}
- prefix_cache[i] = strndup(prefix, length);
+ prefix_cache[i] = SMB_STRNDUP(prefix, length);
prefix_cache_hashes[i] = hash;
}
DEBUG(10,("parse_symlink: count=%d\n", count));
- reflist = *preflist = (struct referral*) malloc(count * sizeof(struct referral));
+ reflist = *preflist = SMB_MALLOC_ARRAY(struct referral, count);
if(reflist == NULL) {
DEBUG(0,("parse_symlink: Malloc failed!\n"));
return False;
*self_referralp = True;
jucn->referral_count = 1;
- if((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
+ if((ref = SMB_MALLOC_P(struct referral)) == NULL) {
DEBUG(0,("self_ref: malloc failed for referral\n"));
return False;
}
self_referralp);
jucn->referral_count = 1;
- if ((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) {
+ if ((ref = SMB_MALLOC_P(struct referral)) == NULL) {
DEBUG(0, ("malloc failed for referral\n"));
goto out;
}
/* add the unexplained 0x16 bytes */
reply_size += 0x16;
- pdata = Realloc(pdata,reply_size);
+ pdata = SMB_REALLOC(pdata,reply_size);
if(pdata == NULL) {
DEBUG(0,("malloc failed for Realloc!\n"));
return -1;
reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
}
- pdata = Realloc(pdata,reply_size);
+ pdata = SMB_REALLOC(pdata,reply_size);
if(pdata == NULL) {
DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
return -1;
jucn[cnt].volume_name[0] = '\0';
jucn[cnt].referral_count = 1;
- ref = jucn[cnt].referral_list
- = (struct referral*) malloc(sizeof(struct referral));
+ ref = jucn[cnt].referral_list = SMB_MALLOC_P(struct referral);
if (jucn[cnt].referral_list == NULL) {
DEBUG(0, ("Malloc failed!\n"));
goto out;
{
struct change_notify *cnbp;
- if((cnbp = (struct change_notify *)malloc(sizeof(*cnbp))) == NULL) {
+ if((cnbp = SMB_MALLOC_P(struct change_notify)) == NULL) {
DEBUG(0,("change_notify_set: malloc fail !\n" ));
return -1;
}
DEBUG(15,("quota entry for id[%s] path[%s]\n",
sid_string_static(&sid),fsp->conn->connectpath));
- if ((tmp_list_ent=(SMB_NTQUOTA_LIST *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_LIST)))==NULL) {
+ if ((tmp_list_ent=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_LIST))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
*qt_list = NULL;
talloc_destroy(mem_ctx);
return (-1);
}
- if ((tmp_list_ent->quotas=(SMB_NTQUOTA_STRUCT *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_STRUCT)))==NULL) {
+ if ((tmp_list_ent->quotas=TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_STRUCT))==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
*qt_list = NULL;
talloc_destroy(mem_ctx);
if (!mem_ctx)
return False;
- qt_handle = (SMB_NTQUOTA_HANDLE *)talloc_zero(mem_ctx,sizeof(SMB_NTQUOTA_HANDLE));
+ qt_handle = TALLOC_ZERO_P(mem_ctx,SMB_NTQUOTA_HANDLE);
if (qt_handle==NULL) {
DEBUG(0,("talloc_zero() failed\n"));
return NULL;
if (ptr==NULL)
smb_panic("nttrans_realloc() called with NULL ptr\n");
- tptr = Realloc_zero(*ptr, size);
+ tptr = SMB_REALLOC(*ptr, size);
if(tptr == NULL) {
*ptr = NULL;
return NULL;
}
+ memset(tptr,'\0',size);
*ptr = tptr;
return ERROR_NT(NT_STATUS_NO_MEMORY);
}
- shadow_data = (SHADOW_COPY_DATA *)talloc_zero(shadow_mem_ctx,sizeof(SHADOW_COPY_DATA));
+ shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
if (shadow_data == NULL) {
DEBUG(0,("talloc_zero() failed!\n"));
return ERROR_NT(NT_STATUS_NO_MEMORY);
}
sid_len = IVAL(pdata,4);
+ /* Ensure this is less than 1mb. */
+ if (sid_len > (1024*1024)) {
+ return ERROR_DOS(ERRDOS,ERRnomem);
+ }
if (data_count < 8+sid_len) {
DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
goto bad_param;
}
-
+
+ /* Don't allow more than 128mb for each value. */
+ if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
+ END_PROFILE(SMBnttrans);
+ return ERROR_DOS(ERRDOS,ERRnomem);
+ }
+
/* Allocate the space for the setup, the maximum needed parameters and data */
if(setup_count > 0)
- setup = (char *)malloc(setup_count);
+ setup = (char *)SMB_MALLOC(setup_count);
if (total_parameter_count > 0)
- params = (char *)malloc(total_parameter_count);
+ params = (char *)SMB_MALLOC(total_parameter_count);
if (total_data_count > 0)
- data = (char *)malloc(total_data_count);
+ data = (char *)SMB_MALLOC(total_data_count);
if ((total_parameter_count && !params) || (total_data_count && !data) ||
(setup_count && !setup)) {
return -1;
}
- broken_entry = malloc(sizeof(struct share_mode_entry_list));
+ broken_entry = SMB_MALLOC_P(struct share_mode_entry_list);
if (!broken_entry) {
smb_panic("open_mode_check: malloc fail.\n");
}
* messages crossing on the wire.
*/
- if((inbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+ if((inbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
DEBUG(0,("oplock_break: malloc fail for input buffer.\n"));
return False;
}
- if((outbuf = (char *)malloc(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
+ if((outbuf = (char *)SMB_MALLOC(BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN))==NULL) {
DEBUG(0,("oplock_break: malloc fail for output buffer.\n"));
SAFE_FREE(inbuf);
return False;
return UID_FIELD_INVALID;
}
- if((vuser = (user_struct *)malloc( sizeof(user_struct) )) == NULL) {
+ if((vuser = SMB_MALLOC_P(user_struct)) == NULL) {
DEBUG(0,("Failed to malloc users struct!\n"));
data_blob_free(&session_key);
return UID_FIELD_INVALID;
DEBUG(3,("add_session_user: session userlist already too large.\n"));
return;
}
- newlist = Realloc( session_userlist, len_session_userlist + PSTRING_LEN );
+ newlist = SMB_REALLOC( session_userlist, len_session_userlist + PSTRING_LEN );
if( newlist == NULL ) {
DEBUG(1,("Unable to resize session_userlist\n"));
return;
char *user_list = NULL;
if ( session_userlist )
- user_list = strdup(session_userlist);
+ user_list = SMB_STRDUP(session_userlist);
else
- user_list = strdup("");
+ user_list = SMB_STRDUP("");
if (!user_list)
return(False);
*store_size = PAI_ENTRIES_BASE + ((num_entries + num_def_entries)*PAI_ENTRY_LENGTH);
- pai_buf = malloc(*store_size);
+ pai_buf = SMB_MALLOC(*store_size);
if (!pai_buf) {
return NULL;
}
if (!check_pai_ok(buf, size))
return NULL;
- paiv = malloc(sizeof(struct pai_val));
+ paiv = SMB_MALLOC_P(struct pai_val);
if (!paiv)
return NULL;
for (i = 0; i < paiv->num_entries; i++) {
struct pai_entry *paie;
- paie = malloc(sizeof(struct pai_entry));
+ paie = SMB_MALLOC_P(struct pai_entry);
if (!paie) {
free_inherited_info(paiv);
return NULL;
for (i = 0; i < paiv->num_def_entries; i++) {
struct pai_entry *paie;
- paie = malloc(sizeof(struct pai_entry));
+ paie = SMB_MALLOC_P(struct pai_entry);
if (!paie) {
free_inherited_info(paiv);
return NULL;
if (!lp_map_acl_inherit(SNUM(fsp->conn)))
return NULL;
- if ((pai_buf = malloc(pai_buf_size)) == NULL)
+ if ((pai_buf = SMB_MALLOC(pai_buf_size)) == NULL)
return NULL;
do {
/* Buffer too small - enlarge it. */
pai_buf_size *= 2;
SAFE_FREE(pai_buf);
- if ((pai_buf = malloc(pai_buf_size)) == NULL)
+ if (pai_buf_size > 1024*1024) {
+ return NULL; /* Limit malloc to 1mb. */
+ }
+ if ((pai_buf = SMB_MALLOC(pai_buf_size)) == NULL)
return NULL;
}
} while (ret == -1);
static canon_ace *dup_canon_ace( canon_ace *src_ace)
{
- canon_ace *dst_ace = (canon_ace *)malloc(sizeof(canon_ace));
+ canon_ace *dst_ace = SMB_MALLOC_P(canon_ace);
if (dst_ace == NULL)
return NULL;
}
if (!got_user) {
- if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+ if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
return False;
}
}
if (!got_grp) {
- if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+ if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
return False;
}
}
if (!got_other) {
- if ((pace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+ if ((pace = SMB_MALLOC_P(canon_ace)) == NULL) {
DEBUG(0,("ensure_canon_entry_valid: malloc fail.\n"));
return False;
}
* Create a cannon_ace entry representing this NT DACL ACE.
*/
- if ((current_ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL) {
+ if ((current_ace = SMB_MALLOC_P(canon_ace)) == NULL) {
free_canon_ace_list(file_ace);
free_canon_ace_list(dir_ace);
DEBUG(0,("create_canon_ace_lists: malloc fail.\n"));
* Add this entry to the list.
*/
- if ((ace = (canon_ace *)malloc(sizeof(canon_ace))) == NULL)
+ if ((ace = SMB_MALLOC_P(canon_ace)) == NULL)
goto fail;
ZERO_STRUCTP(ace);
num_def_acls = count_canon_ace_list(dir_ace);
/* Allocate the ace list. */
- if ((nt_ace_list = (SEC_ACE *)malloc((num_acls + num_profile_acls + num_def_acls)* sizeof(SEC_ACE))) == NULL) {
+ if ((nt_ace_list = SMB_MALLOC_ARRAY(SEC_ACE,num_acls + num_profile_acls + num_def_acls)) == NULL) {
DEBUG(0,("get_nt_acl: Unable to malloc space for nt_ace_list.\n"));
goto done;
}
static BOOL push_queued_message(enum q_type qt, char *buf, int msg_len, struct timeval *ptv, char *private, size_t private_len)
{
struct pending_message_list *tmp_msg;
- struct pending_message_list *msg = (struct pending_message_list *)
- malloc(sizeof(struct pending_message_list));
+ struct pending_message_list *msg = SMB_MALLOC_P(struct pending_message_list);
if(msg == NULL) {
DEBUG(0,("push_message: malloc fail (1)\n"));
unsigned int num_smbs = 0;
const size_t total_buffer_size = BUFFER_SIZE + LARGE_WRITEX_HDR_SIZE + SAFETY_MARGIN;
- InBuffer = (char *)malloc(total_buffer_size);
- OutBuffer = (char *)malloc(total_buffer_size);
+ InBuffer = (char *)SMB_MALLOC(total_buffer_size);
+ OutBuffer = (char *)SMB_MALLOC(total_buffer_size);
if ((InBuffer == NULL) || (OutBuffer == NULL))
return;
END_PROFILE(SMBsearch);
return ERROR_DOS(ERRDOS,ERRnofids);
}
- dptr_set_wcard(dptr_num, strdup(mask));
+ dptr_set_wcard(dptr_num, SMB_STRDUP(mask));
dptr_set_attr(dptr_num, dirtype);
} else {
dirtype = dptr_attr(dptr_num);
if(fsp->wbmpx_ptr != NULL)
wbms = fsp->wbmpx_ptr; /* Use an existing struct */
else
- wbms = (write_bmpx_struct *)malloc(sizeof(write_bmpx_struct));
+ wbms = SMB_MALLOC_P(write_bmpx_struct);
if(!wbms) {
DEBUG(0,("Out of memory in reply_readmpx\n"));
END_PROFILE(SMBwriteBmpx);
goto fail;
}
- if((groups = (gid_t *)malloc(sizeof(gid_t)*(ngroups+1))) == NULL) {
+ if((groups = SMB_MALLOC_ARRAY(gid_t, ngroups+1)) == NULL) {
DEBUG(0,("setup_groups malloc fail !\n"));
goto fail;
}
ctx_p->ngroups = sys_getgroups(0, NULL);
if (ctx_p->ngroups != 0) {
- if (!(ctx_p->groups = malloc(ctx_p->ngroups * sizeof(gid_t)))) {
+ if (!(ctx_p->groups = SMB_MALLOC_ARRAY(gid_t, ctx_p->ngroups))) {
DEBUG(0, ("Out of memory in push_sec_ctx()\n"));
delete_nt_token(&ctx_p->token);
return False;
sessionid.id_str, sessionid.id_num);
}
- vuser->session_keystr = strdup(keystr);
+ vuser->session_keystr = SMB_STRDUP(keystr);
if (!vuser->session_keystr) {
DEBUG(0, ("session_claim: strdup() failed for session_keystr\n"));
return False;
const struct sessionid *current = (const struct sessionid *) dbuf.dptr;
sesslist->count += 1;
- sesslist->sessions = REALLOC(sesslist->sessions, sesslist->count *
- sizeof(struct sessionid));
+ sesslist->sessions = SMB_REALLOC_ARRAY(sesslist->sessions, struct sessionid,
+ sesslist->count);
memcpy(&sesslist->sessions[sesslist->count - 1], current,
sizeof(struct sessionid));
* translated path.
*/
- translated_path = strdup(orig_translated_path);
+ translated_path = SMB_STRDUP(orig_translated_path);
if (!translated_path)
return;
}
if(case_sensitive) {
- original_path = strdup(full_orig_name);
+ original_path = SMB_STRDUP(full_orig_name);
} else {
original_path = strdup_upper(full_orig_name);
}
return False;
if (conn->case_sensitive) {
- chk_name = strdup(name);
+ chk_name = SMB_STRDUP(name);
if (!chk_name) {
DEBUG(0, ("stat_cache_lookup: strdup failed!\n"));
return False;
again:
- val = talloc_realloc(mem_ctx, val, attr_size);
+ val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size);
if (!val) {
return False;
}
return NULL;
}
- for (i = 0, ea_namelist = talloc(mem_ctx, ea_namelist_size); i < 6;
- ea_namelist = talloc_realloc(mem_ctx, ea_namelist, ea_namelist_size), i++) {
+ for (i = 0, ea_namelist = TALLOC(mem_ctx, ea_namelist_size); i < 6;
+ ea_namelist = TALLOC_REALLOC_ARRAY(mem_ctx, ea_namelist, char, ea_namelist_size), i++) {
if (fsp && fsp->fd != -1) {
sizeret = SMB_VFS_FLISTXATTR(fsp, fsp->fd, ea_namelist, ea_namelist_size);
} else {
if (strnequal(p, "system.", 7) || samba_private_attr_name(p))
continue;
- listp = talloc(mem_ctx, sizeof(struct ea_list));
+ listp = TALLOC_P(mem_ctx, struct ea_list);
if (!listp)
return NULL;
}
/* Realloc the size of parameters and data we will return */
- params = Realloc(*pparams, 28);
+ params = SMB_REALLOC(*pparams, 28);
if( params == NULL )
return(ERROR_DOS(ERRDOS,ERRnomem));
*pparams = params;
DEBUG(5,("dir=%s, mask = %s\n",directory, mask));
- pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+ pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
if( pdata == NULL )
return(ERROR_DOS(ERRDOS,ERRnomem));
memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
- params = Realloc(*pparams, 10);
+ params = SMB_REALLOC(*pparams, 10);
if (params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
/* Save the wildcard match and attribs we are using on this directory -
needed as lanman2 assumes these are being saved between calls */
- if(!(wcard = strdup(mask))) {
+ if(!(wcard = SMB_STRDUP(mask))) {
dptr_close(&dptr_num);
return ERROR_DOS(ERRDOS,ERRnomem);
}
return ERROR_DOS(ERRDOS,ERRunknownlevel);
}
- pdata = Realloc( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+ pdata = SMB_REALLOC( *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
if(pdata == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
/* Realloc the params space */
- params = Realloc(*pparams, 6*SIZEOFWORD);
+ params = SMB_REALLOC(*pparams, 6*SIZEOFWORD);
if( params == NULL )
return ERROR_DOS(ERRDOS,ERRnomem);
return ERROR_DOS(ERRSRV,ERRinvdevice);
}
- pdata = Realloc(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
+ pdata = SMB_REALLOC(*ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
if ( pdata == NULL )
return ERROR_DOS(ERRDOS,ERRnomem);
file_size = 0;
}
- params = Realloc(*pparams,2);
+ params = SMB_REALLOC(*pparams,2);
if (params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
memset((char *)params,'\0',2);
data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
- pdata = Realloc(*ppdata, data_size);
+ pdata = SMB_REALLOC(*ppdata, data_size);
if ( pdata == NULL )
return ERROR_DOS(ERRDOS,ERRnomem);
*ppdata = pdata;
tran_call,fname, fsp ? fsp->fnum : -1, info_level,total_data));
/* Realloc the parameter and data sizes */
- params = Realloc(*pparams,2);
+ params = SMB_REALLOC(*pparams,2);
if(params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
}
/* Realloc the parameter and data sizes */
- params = Realloc(*pparams,2);
+ params = SMB_REALLOC(*pparams,2);
if(params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
}
/* Realloc the parameter and data sizes */
- params = Realloc(*pparams,6);
+ params = SMB_REALLOC(*pparams,6);
if(params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
DEBUG(3,("call_trans2findnotifynext\n"));
/* Realloc the parameter and data sizes */
- params = Realloc(*pparams,4);
+ params = SMB_REALLOC(*pparams,4);
if(params == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*pparams = params;
if ((SVAL(inbuf,(smb_setup+4)) == LMCAT_SPL) &&
(SVAL(inbuf,(smb_setup+6)) == LMFUNC_GETJOBID)) {
- pdata = Realloc(*ppdata, 32);
+ pdata = SMB_REALLOC(*ppdata, 32);
if(pdata == NULL)
return ERROR_DOS(ERRDOS,ERRnomem);
*ppdata = pdata;
/* Allocate the space for the maximum needed parameters and data */
if (total_params > 0)
- params = (char *)malloc(total_params);
+ params = (char *)SMB_MALLOC(total_params);
if (total_data > 0)
- data = (char *)malloc(total_data);
+ data = (char *)SMB_MALLOC(total_data);
if ((total_params && !params) || (total_data && !data)) {
DEBUG(2,("Out of memory in reply_trans2\n"));
return NT_STATUS_OBJECT_NAME_COLLISION;
}
- entry = smb_xmalloc(sizeof(struct vfs_init_function_entry));
+ entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
entry->name = smb_xstrdup(name);
entry->vfs_op_tuples = vfs_op_tuples;
return False;
}
- handle = (vfs_handle_struct *)talloc_zero(conn->mem_ctx,sizeof(vfs_handle_struct));
+ handle = TALLOC_ZERO_P(conn->mem_ctx,vfs_handle_struct);
if (!handle) {
DEBUG(0,("talloc_zero() failed!\n"));
SAFE_FREE(module_name);
if (element == 0)
return;
- p = (char *)malloc(elsize);
+ p = (char *)SMB_MALLOC(elsize);
if (!p) {
DEBUG(5,("array_promote: malloc fail\n"));
pstrcat(tmp_fname, last_component);
#ifdef REALPATH_TAKES_NULL
SAFE_FREE(resolved_name);
- resolved_name = strdup(tmp_fname);
+ resolved_name = SMB_STRDUP(tmp_fname);
if (!resolved_name) {
DEBUG(0,("reduce_name: malloc fail for %s\n", tmp_fname));
errno = saved_errno;
#include "spinlock.h"
#else
#include "includes.h"
+
+#if defined(PARANOID_MALLOC_CHECKER)
+#ifdef malloc
+#undef malloc
+#endif
+
+#ifdef realloc
+#undef realloc
+#endif
+
+#ifdef calloc
+#undef calloc
+#endif
+
+#ifdef strdup
+#undef strdup
+#endif
+
+#ifdef strndup
+#undef strndup
+#endif
+
+#endif
+
#endif
#define TDB_MAGIC_FOOD "TDB file\n"
#else
#include "includes.h"
+
+#ifdef malloc
+#undef malloc
+#endif
+
+#ifdef realloc
+#undef realloc
+#endif
+
+#ifdef calloc
+#undef calloc
+#endif
+
#endif
#include "tdb.h"
len += *i;
if (bufsize < len)
goto no_space;
- *b = (char *)malloc(*i);
+ *b = (char *)SMB_MALLOC(*i);
if (! *b)
goto no_space;
memcpy(*b, buf+4, *i);
for (key = tdb_firstkey(tdb); key.dptr; key = next) {
/* duplicate key string to ensure null-termination */
- char *key_str = (char*) strndup(key.dptr, key.dsize);
+ char *key_str = (char*) SMB_STRNDUP(key.dptr, key.dsize);
if (!key_str) {
DEBUG(0, ("tdb_search_keys: strndup() failed!\n"));
smb_panic("strndup failed!\n");
/* do the pattern checking */
if (fnmatch(pattern, key_str, 0) == 0) {
- rec = (TDB_LIST_NODE*) malloc(sizeof(*rec));
+ rec = SMB_MALLOC_P(TDB_LIST_NODE);
ZERO_STRUCTP(rec);
rec->node_key = key;
if (!opt_password && !opt_machine_pass) {
char *pass = getpass("Password:");
if (pass) {
- opt_password = strdup(pass);
+ opt_password = SMB_STRDUP(pass);
}
}
NTSTATUS connect_pipe(struct cli_state **cli_dst, int pipe_num, BOOL *got_pipe)
{
NTSTATUS nt_status;
- char *server_name = strdup("127.0.0.1");
+ char *server_name = SMB_STRDUP("127.0.0.1");
struct cli_state *cli_tmp = NULL;
if (opt_destination)
- server_name = strdup(opt_destination);
+ server_name = SMB_STRDUP(opt_destination);
/* make a connection to a named pipe */
nt_status = connect_to_ipc(&cli_tmp, NULL, server_name);
{
if (opt_host) {
- *server_name = strdup(opt_host);
+ *server_name = SMB_STRDUP(opt_host);
}
if (opt_have_ip) {
*server_ip = opt_dest_ip;
if (!*server_name) {
- *server_name = strdup(inet_ntoa(opt_dest_ip));
+ *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
}
} else if (*server_name) {
/* resolve the IP address */
if ( !name_status_find(opt_target_workgroup, 0x1b, 0x20, pdc_ip, dc_name) )
return False;
- *server_name = strdup(dc_name);
+ *server_name = SMB_STRDUP(dc_name);
*server_ip = pdc_ip;
}
} else {
*server_ip = msbrow_ip;
}
- *server_name = strdup(inet_ntoa(opt_dest_ip));
+ *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
} else if (flags & NET_FLAGS_MASTER) {
struct in_addr brow_ips;
if (!resolve_name(opt_target_workgroup, &brow_ips, 0x1D)) {
} else {
*server_ip = brow_ips;
}
- *server_name = strdup(inet_ntoa(opt_dest_ip));
+ *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
} else if (!(flags & NET_FLAGS_LOCALHOST_DEFAULT_INSANE)) {
extern struct in_addr loopback_ip;
*server_ip = loopback_ip;
- *server_name = strdup("127.0.0.1");
+ *server_name = SMB_STRDUP("127.0.0.1");
}
if (!server_name || !*server_name) {
break;
case 'U':
opt_user_specified = True;
- opt_user_name = strdup(opt_user_name);
+ opt_user_name = SMB_STRDUP(opt_user_name);
p = strchr(opt_user_name,'%');
if (p) {
*p = 0;
if (!values) /* must be new field, indicate string field */
return True;
if (StrCaseCmp(field, "sAMAccountName") == 0) {
- disp_fields[0] = strdup((char *) values[0]);
+ disp_fields[0] = SMB_STRDUP((char *) values[0]);
}
if (StrCaseCmp(field, "description") == 0)
- disp_fields[1] = strdup((char *) values[0]);
+ disp_fields[1] = SMB_STRDUP((char *) values[0]);
return True;
}
}
tmp_password = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
- password = strdup(tmp_password);
+ password = SMB_STRDUP(tmp_password);
if (!(ads = ads_startup())) {
return -1;
/* number detection */
len = (sign) ? strlen(&timeout_str[number_begin]) : len;
number_end = (unit) ? len - 1 : len;
- number = strndup(&timeout_str[number_begin], number_end);
+ number = SMB_STRNDUP(&timeout_str[number_begin], number_end);
/* calculate actual timeout value */
timeout = (time_t)atoi(number);
return NT_STATUS_UNSUCCESSFUL;
}
- tdbfile = strdup(lock_path("winbindd_idmap.tdb"));
+ tdbfile = SMB_STRDUP(lock_path("winbindd_idmap.tdb"));
if (!tdbfile) {
DEBUG(0, ("idmap_init: out of memory!\n"));
return NT_STATUS_NO_MEMORY;
if (!(cli = net_make_ipc_connection(0)))
return -1;
- sharename = strdup(argv[0]);
+ sharename = SMB_STRDUP(argv[0]);
p = strchr(sharename, '=');
*p = 0;
strlcpy(sinfo.share_name, sharename, sizeof(sinfo.share_name));
/* Look up rids */
- rids = (uint32 *)talloc(mem_ctx, sizeof(uint32) * num_rids);
+ rids = TALLOC_ARRAY(mem_ctx, uint32, num_rids);
for (i = 0; i < num_rids; i++)
rids[i] = user_gids[i].g_rid;
pstring mask;
char *dst = NULL;
- dst = strdup(opt_destination?opt_destination:"127.0.0.1");
+ dst = SMB_STRDUP(opt_destination?opt_destination:"127.0.0.1");
init_enum_hnd(&hnd, 0);
static void push_alias(TALLOC_CTX *mem_ctx, struct full_alias *alias)
{
if (server_aliases == NULL)
- server_aliases = malloc(100 * sizeof(struct full_alias));
+ server_aliases = SMB_MALLOC_ARRAY(struct full_alias, 100);
server_aliases[num_server_aliases] = *alias;
num_server_aliases += 1;
alias.members = NULL;
if (alias.num_members > 0) {
- alias.members = malloc(alias.num_members *
- sizeof(DOM_SID));
+ alias.members = SMB_MALLOC_ARRAY(DOM_SID, alias.num_members);
for (j = 0; j < alias.num_members; j++)
sid_copy(&alias.members[j],
token->num_sids = 4;
- token->user_sids = malloc(4 * sizeof(DOM_SID));
+ token->user_sids = SMB_MALLOC_ARRAY(DOM_SID, 4);
token->user_sids[0] = *user_sid;
sid_copy(&token->user_sids[1], &global_sid_World);
if (is_sid_in_token(token, sid))
return;
- token->user_sids = Realloc(token->user_sids,
- (token->num_sids+1) * sizeof(DOM_SID));
+ token->user_sids = SMB_REALLOC_ARRAY(token->user_sids, DOM_SID, token->num_sids+1);
sid_copy(&token->user_sids[token->num_sids], sid);
*num_tokens += 1;
}
- result = malloc(*num_tokens * sizeof(struct user_token));
+ result = SMB_MALLOC_ARRAY(struct user_token, *num_tokens);
if (result == NULL) {
DEBUG(1, ("Could not malloc sid array\n"));
/* And a new user... */
*num_tokens += 1;
- *tokens = Realloc(*tokens,
- *num_tokens *
- sizeof(struct user_token));
+ *tokens = SMB_REALLOC_ARRAY(*tokens, struct user_token, *num_tokens);
if (*tokens == NULL) {
DEBUG(0, ("Could not realloc tokens\n"));
return False;
return;
share_list->num_shares += 1;
- share_list->shares = Realloc(share_list->shares,
- share_list->num_shares * sizeof(char *));
- share_list->shares[share_list->num_shares-1] = strdup(name);
+ share_list->shares = SMB_REALLOC_ARRAY(share_list->shares, char *, share_list->num_shares);
+ share_list->shares[share_list->num_shares-1] = SMB_STRDUP(name);
}
static void rpc_share_userlist_usage(void)
{
char *str;
str = generate_random_str(DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH);
- clear_trust_password = strdup(str);
+ clear_trust_password = SMB_STRDUP(str);
E_md4hash(clear_trust_password, md4_trust_password);
}
}
/* allocate memory */
- if (!(data = (char *)malloc(read_size))) {
+ if (!(data = (char *)SMB_MALLOC(read_size))) {
d_printf("malloc fail for size %d\n", read_size);
nt_status = NT_STATUS_NO_MEMORY;
goto out;
/* argument given, get a single printer by name */
- sharename = strdup(argv[0]);
+ sharename = SMB_STRDUP(argv[0]);
if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename,
MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd))
}
/* copy devmode (info level 2) */
- ctr_dst.printers_2->devmode = talloc_memdup(mem_ctx,
+ ctr_dst.printers_2->devmode = TALLOC_MEMDUP(mem_ctx,
ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE));
/* do not copy security descriptor (we have another command for that) */
value.type = REG_SZ;
value.size = data.uni_str_len * 2;
- value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size);
+ value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
if (opt_verbose)
display_reg_value(subkey, value);
return NT_STATUS_NO_MEMORY;
}
- nt_members = talloc_zero(t, sizeof(char *) * delta->num_members);
+ nt_members = TALLOC_ZERO_ARRAY(t, char *, delta->num_members);
for (i=0; i<delta->num_members; i++) {
NTSTATUS nt_status;
return 0;
ids->num_entries += 1;
- ids->entries = Realloc(ids->entries,
- sizeof(struct sessionid) * ids->num_entries);
+ ids->entries = SMB_REALLOC_ARRAY(ids->entries, struct sessionid, ids->num_entries);
ids->entries[ids->num_entries-1] = sessionid;
return 0;
return False;
}
- require_membership_of_sid = strdup(response.data.sid.sid);
+ require_membership_of_sid = SMB_STRDUP(response.data.sid.sid);
if (require_membership_of_sid)
return True;
}
if (flags & WBFLAG_PAM_UNIX_NAME) {
- *unix_name = strdup((char *)response.extra_data);
+ *unix_name = SMB_STRDUP((char *)response.extra_data);
if (!*unix_name) {
free_response(&response);
return NT_STATUS_NO_MEMORY;
if ((strncmp(buf, "PW ", 3) == 0)) {
/* The calling application wants us to use a local password (rather than winbindd) */
- opt_password = strndup((const char *)request.data, request.length);
+ opt_password = SMB_STRNDUP((const char *)request.data, request.length);
if (opt_password == NULL) {
DEBUG(1, ("Out of memory\n"));
if (strncmp(buf, "PW ", 3) == 0) {
/* We asked for a password and obviously got it :-) */
- opt_password = strndup((const char *)request.data, request.length);
+ opt_password = SMB_STRNDUP((const char *)request.data, request.length);
if (opt_password == NULL) {
DEBUG(1, ("Out of memory\n"));
/* Server negTokenInit (mech offerings) */
spnego.type = SPNEGO_NEG_TOKEN_INIT;
- spnego.negTokenInit.mechTypes = smb_xmalloc(sizeof(char *) * 3);
+ spnego.negTokenInit.mechTypes = SMB_XMALLOC_ARRAY(char *, 3);
#ifdef HAVE_KRB5
spnego.negTokenInit.mechTypes[0] = smb_xstrdup(OID_KERBEROS5_OLD);
spnego.negTokenInit.mechTypes[1] = smb_xstrdup(OID_NTLMSSP);
request.negTokenInit.mechToken.length);
response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+ response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
status = ntlmssp_update(ntlmssp_state,
}
response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = strdup(OID_KERBEROS5_OLD);
+ response.negTokenTarg.supportedMech = SMB_STRDUP(OID_KERBEROS5_OLD);
response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
response.negTokenTarg.responseToken = data_blob(NULL, 0);
}
*domain++ = '\0';
- domain = strdup(domain);
- user = strdup(principal);
+ domain = SMB_STRDUP(domain);
+ user = SMB_STRDUP(principal);
data_blob_free(&ap_rep);
data_blob_free(&auth_data);
&response.negTokenTarg.responseToken);
response.type = SPNEGO_NEG_TOKEN_TARG;
- response.negTokenTarg.supportedMech = strdup(OID_NTLMSSP);
+ response.negTokenTarg.supportedMech = SMB_STRDUP(OID_NTLMSSP);
response.negTokenTarg.mechListMIC = data_blob(NULL, 0);
if (NT_STATUS_IS_OK(status)) {
- user = strdup(ntlmssp_state->user);
- domain = strdup(ntlmssp_state->domain);
+ user = SMB_STRDUP(ntlmssp_state->user);
+ domain = SMB_STRDUP(ntlmssp_state->domain);
ntlmssp_end(&ntlmssp_state);
}
}
return False;
}
- principal = malloc(spnego.negTokenInit.mechListMIC.length+1);
+ principal = SMB_MALLOC(spnego.negTokenInit.mechListMIC.length+1);
if (principal == NULL) {
DEBUG(1, ("Could not malloc principal\n"));
/* We asked for a password and obviously got it :-) */
- opt_password = strndup((const char *)request.data, request.length);
+ opt_password = SMB_STRNDUP((const char *)request.data, request.length);
if (opt_password == NULL) {
DEBUG(1, ("Out of memory\n"));
}
staticpass = getpass("new password:");
- password1 = strdup(staticpass);
+ password1 = SMB_STRDUP(staticpass);
memset(staticpass, 0, strlen(staticpass));
staticpass = getpass("retype new password:");
- password2 = strdup(staticpass);
+ password2 = SMB_STRDUP(staticpass);
memset(staticpass, 0, strlen(staticpass));
if (strcmp (password1, password2)) {
fprintf (stderr, "Passwords does not match!\n");
return True;
}
- aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE));
+ aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
}
if (strncmp(tok,"OWNER:", 6) == 0) {
- owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!owner_sid ||
!StringToSid(owner_sid, tok+6)) {
printf("Failed to parse owner sid\n");
}
if (strncmp(tok,"GROUP:", 6) == 0) {
- grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+ grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
if (!grp_sid ||
!StringToSid(grp_sid, tok+6)) {
printf("Failed to parse group sid\n");
struct name_list **name_list = (struct name_list **)state;
struct name_list *new_name;
- new_name = (struct name_list *)malloc(sizeof(struct name_list));
+ new_name = SMB_MALLOC_P(struct name_list);
if (!new_name)
return;
char *ret2;
if (len == 0) len = 1024;
else len *= 2;
- ret2 = (char *)Realloc(ret, len);
+ ret2 = (char *)SMB_REALLOC(ret, len);
if (!ret2) return ret;
ret = ret2;
}
*p = 0;
- variables[num_variables].name = strdup(line);
- variables[num_variables].value = strdup(p+1);
+ variables[num_variables].name = SMB_STRDUP(line);
+ variables[num_variables].value = SMB_STRDUP(p+1);
SAFE_FREE(line);
*p = 0;
- variables[num_variables].name = strdup(tok);
- variables[num_variables].value = strdup(p+1);
+ variables[num_variables].name = SMB_STRDUP(tok);
+ variables[num_variables].value = SMB_STRDUP(p+1);
if (!variables[num_variables].name ||
!variables[num_variables].value)
variables[i].name, -1,
dest, sizeof(dest), True);
free(variables[i].name);
- variables[i].name = strdup(dest);
+ variables[i].name = SMB_STRDUP(dest);
convert_string(CH_UTF8, CH_UNIX,
variables[i].value, -1,
dest, sizeof(dest), True);
free(variables[i].value);
- variables[i].value = strdup(dest);
+ variables[i].value = SMB_STRDUP(dest);
}
}
become_user_permanently(pass->pw_uid, pass->pw_gid);
/* Save the users name */
- C_user = strdup(user);
+ C_user = SMB_STRDUP(user);
passwd_free(&pass);
return True;
}
if (line[0] == '\r' || line[0] == '\n') break;
if (strnequal(line,"GET ", 4)) {
got_request = True;
- url = strdup(&line[4]);
+ url = SMB_STRDUP(&line[4]);
} else if (strnequal(line,"POST ", 5)) {
got_request = True;
request_post = 1;
- url = strdup(&line[5]);
+ url = SMB_STRDUP(&line[5]);
} else if (strnequal(line,"PUT ", 4)) {
got_request = True;
cgi_setup_error("400 Bad Request", "",
count++;
lang_num++;
}
- pl = (struct pri_list *)malloc(sizeof(struct pri_list) * lang_num);
+ pl = SMB_MALLOC_ARRAY(struct pri_list, lang_num);
for (i = 0; i < lang_num; i++) {
char *pri_code;
if ((pri_code=strstr(lang_list[i], ";q="))) {
} else {
pl[i].pri = 1;
}
- pl[i].string = strdup(lang_list[i]);
+ pl[i].string = SMB_STRDUP(lang_list[i]);
}
str_list_free(&lang_list);
if (PID_or_Machine) {
PIDMAP *newmap;
- if ((newmap = (PIDMAP *) malloc (sizeof (PIDMAP))) == NULL) {
+ if ((newmap = SMB_MALLOC_P(PIDMAP)) == NULL) {
/* XXX need error message for this?
if malloc fails, PID is always shown */
return;
}
newmap->pid = pid;
- newmap->machine = strdup (machine);
+ newmap->machine = SMB_STRDUP(machine);
DLIST_ADD(pidmap, newmap);
}