_PUBLIC_ NTSTATUS ndr_pull_CIMSTRINGS(struct ndr_pull *ndr, int ndr_flags, struct CIMSTRINGS *r) { uint32_t endofs; uint32_t len; TALLOC_CTX *mem_ctx; uint32_t u; if (!(ndr_flags & NDR_SCALARS)) return NT_STATUS_OK; mem_ctx = ndr->current_mem_ctx; NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &endofs)); endofs += ndr->offset - sizeof(endofs); r->count = 0; len = 5; r->item = talloc_array(mem_ctx, CIMSTRING, len); ndr->current_mem_ctx = r->item; while (ndr->offset < endofs) { if (r->count >= len) { len += 3; r->item = talloc_realloc(mem_ctx, r->item, CIMSTRING, len); } NDR_CHECK(ndr_pull_CIMSTRING(ndr, ndr_flags, &r->item[r->count])); NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &u)); ++r->count; } r->item = talloc_realloc(mem_ctx, r->item, CIMSTRING, r->count); ndr->current_mem_ctx = mem_ctx; return NT_STATUS_OK; }
static NTSTATUS ldif_realloc_maps(TALLOC_CTX *mem_ctx, struct samsync_ldif_context *l, uint32_t num_entries) { /* Re-allocate memory for groupmap and accountmap arrays */ l->groupmap = talloc_realloc(mem_ctx, l->groupmap, GROUPMAP, num_entries + l->num_alloced); l->accountmap = talloc_realloc(mem_ctx, l->accountmap, ACCOUNTMAP, num_entries + l->num_alloced); if (l->groupmap == NULL || l->accountmap == NULL) { DEBUG(1,("GROUPMAP talloc failed\n")); return NT_STATUS_NO_MEMORY; } /* Initialize the new records */ memset(&(l->groupmap[l->num_alloced]), 0, sizeof(GROUPMAP) * num_entries); memset(&(l->accountmap[l->num_alloced]), 0, sizeof(ACCOUNTMAP) * num_entries); /* Remember how many we alloced this time */ l->num_alloced += num_entries; return NT_STATUS_OK; }
int tag_op_list_append (tag_op_list_t *list, const char *tag, notmuch_bool_t remove) { /* Make room if current array is full. This should be a fairly * rare case, considering the initial array size. */ if (list->count == list->size) { list->size *= 2; list->ops = talloc_realloc (list, list->ops, tag_operation_t, list->size); if (list->ops == NULL) { fprintf (stderr, "Out of memory.\n"); return 1; } } /* add the new operation */ list->ops[list->count].tag = tag; list->ops[list->count].remove = remove; list->count++; return 0; }
/* setup a chained reply in req->out with the given word count and initial data buffer size. */ static void req_setup_chain_reply(struct smbsrv_request *req, unsigned int wct, unsigned int buflen) { uint32_t chain_base_size = req->out.size; /* we need room for the wct value, the words, the buffer length and the buffer */ req->out.size += 1 + VWV(wct) + 2 + buflen; /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; req->out.buffer = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated); if (!req->out.buffer) { smbsrv_terminate_connection(req->smb_conn, "allocation failed"); return; } req->out.hdr = req->out.buffer + NBT_HDR_SIZE; req->out.vwv = req->out.buffer + chain_base_size + 1; req->out.wct = wct; req->out.data = req->out.vwv + VWV(wct) + 2; req->out.data_size = buflen; req->out.ptr = req->out.data; SCVAL(req->out.buffer, chain_base_size, wct); SSVAL(req->out.vwv, VWV(wct), buflen); }
WERROR hexedit_resize_buffer(struct hexedit *buf, size_t newsz) { /* reset the cursor if it'll be out of bounds after the resize */ if (buf->cursor_offset > newsz) { buf->cursor_y = 0; buf->cursor_x = HEX_COL1; buf->offset = 0; buf->cursor_offset = 0; buf->cursor_line_offset = 0; buf->nibble = 0; } if (newsz > buf->len) { if (newsz > buf->alloc_size) { uint8_t *d; buf->alloc_size *= 2; if (newsz > buf->alloc_size) { buf->alloc_size = newsz; } d = talloc_realloc(buf, buf->data, uint8_t, buf->alloc_size); if (d == NULL) { return WERR_NOT_ENOUGH_MEMORY; } buf->data = d; } memset(buf->data + buf->len, '\0', newsz - buf->len); buf->len = newsz; } else { buf->len = newsz; } return WERR_OK; }
bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid, uid_t **uids, uint32_t *num_uids) { uint32_t i; if ((*num_uids != 0) && (*uids == NULL)) { /* * A former call to this routine has failed to allocate memory */ return false; } for (i=0; i<*num_uids; i++) { if ((*uids)[i] == uid) { return true; } } *uids = talloc_realloc(mem_ctx, *uids, uid_t, *num_uids+1); if (*uids == NULL) { *num_uids = 0; return false; } (*uids)[*num_uids] = uid; *num_uids += 1; return true; }
static enum MAPISTATUS fetchmail_get_stream(TALLOC_CTX *mem_ctx, mapi_object_t *obj_stream, DATA_BLOB *body) { enum MAPISTATUS retval; uint16_t read_size; uint8_t buf[0x1000]; body->length = 0; body->data = talloc_zero(mem_ctx, uint8_t); do { retval = ReadStream(obj_stream, buf, 0x1000, &read_size); MAPI_RETVAL_IF(retval, GetLastError(), body->data); if (read_size) { body->data = talloc_realloc(mem_ctx, body->data, uint8_t, body->length + read_size); memcpy(&(body->data[body->length]), buf, read_size); body->length += read_size; } } while (read_size); errno = 0; return MAPI_E_SUCCESS; }
/* append a string into a blob */ size_t smbcli_blob_append_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *str, unsigned int flags) { size_t max_len; int len; if (!str) return 0; /* determine string type to use */ if (!(flags & (STR_ASCII|STR_UNICODE))) { flags |= (session->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII; } max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len); if (!blob->data) { return 0; } len = push_string(blob->data + blob->length, str, max_len, flags); blob->length += len; return len; }
static NTSTATUS enum_local_groups(struct winbindd_domain *domain, TALLOC_CTX *mem_ctx, uint32 *num_entries, struct acct_info **info) { uint32 des_access = SEC_RIGHTS_MAXIMUM_ALLOWED; CLI_POLICY_HND *hnd; POLICY_HND dom_pol; NTSTATUS result; int retry; *num_entries = 0; *info = NULL; retry = 0; do { if ( !NT_STATUS_IS_OK(result = cm_get_sam_handle(domain, &hnd)) ) return result; result = cli_samr_open_domain( hnd->cli, mem_ctx, &hnd->pol, des_access, &domain->sid, &dom_pol); } while (!NT_STATUS_IS_OK(result) && (retry++ < 1) && hnd && hnd->cli && hnd->cli->fd == -1); if ( !NT_STATUS_IS_OK(result)) return result; do { struct acct_info *info2 = NULL; uint32 count = 0, start = *num_entries; TALLOC_CTX *mem_ctx2; mem_ctx2 = talloc_init("enum_dom_local_groups[rpc]"); result = cli_samr_enum_als_groups( hnd->cli, mem_ctx2, &dom_pol, &start, 0xFFFF, &info2, &count); if ( !NT_STATUS_IS_OK(result) && !NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES) ) { talloc_destroy(mem_ctx2); break; } (*info) = talloc_realloc(mem_ctx, *info, sizeof(**info) * ((*num_entries) + count)); if (! *info) { talloc_destroy(mem_ctx2); cli_samr_close(hnd->cli, mem_ctx, &dom_pol); return NT_STATUS_NO_MEMORY; } memcpy(&(*info)[*num_entries], info2, count*sizeof(*info2)); (*num_entries) += count; talloc_destroy(mem_ctx2); } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES)); cli_samr_close(hnd->cli, mem_ctx, &dom_pol); return result; }
/* expand the available space in the buffer to ndr->offset + extra_size */ _PUBLIC_ enum ndr_err_code ndr_push_expand(struct ndr_push *ndr, uint32_t extra_size) { uint32_t size = extra_size + ndr->offset; if (size < ndr->offset) { /* extra_size overflowed the offset */ return ndr_push_error(ndr, NDR_ERR_BUFSIZE, "Overflow in push_expand to %u", size); } if (ndr->alloc_size > size) { return NDR_ERR_SUCCESS; } ndr->alloc_size += NDR_BASE_MARSHALL_SIZE; if (size+1 > ndr->alloc_size) { ndr->alloc_size = size+1; } ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size); if (!ndr->data) { return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u", ndr->alloc_size); } return NDR_ERR_SUCCESS; }
/**************************************************************************** add a privilege to a privilege array ****************************************************************************/ NTSTATUS add_privilege(PRIVILEGE_SET *priv_set, LUID_ATTR set) { NTSTATUS ret; LUID_ATTR *new_set; /* check if the privilege is not already in the list */ if (NT_STATUS_IS_OK(check_priv_in_privilege(priv_set, set))) return NT_STATUS_UNSUCCESSFUL; /* 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))); ALLOC_CHECK(new_set, ret, done, "add_privilege"); new_set[priv_set->count].luid.high = set.luid.high; new_set[priv_set->count].luid.low = set.luid.low; new_set[priv_set->count].attr = set.attr; priv_set->count++; priv_set->set = new_set; ret = NT_STATUS_OK; done: return ret; }
ssize_t message_push_string(uint8 **outbuf, const char *str, int flags) { size_t buf_size = smb_len(*outbuf) + 4; size_t grow_size; size_t result = 0; uint8 *tmp; NTSTATUS status; /* * We need to over-allocate, now knowing what srvstr_push will * actually use. This is very generous by incorporating potential * padding, the terminating 0 and at most 4 chars per UTF-16 code * point. */ grow_size = (strlen(str) + 2) * 4; if (!(tmp = talloc_realloc(NULL, *outbuf, uint8, buf_size + grow_size))) { DEBUG(0, ("talloc failed\n")); return -1; } status = srvstr_push((char *)tmp, SVAL(tmp, smb_flg2), tmp + buf_size, str, grow_size, flags, &result); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("srvstr_push failed\n")); return -1; } set_message_bcc((char *)tmp, smb_buflen(tmp) + result); *outbuf = tmp; return result; }
/* Fetch the NFSv4 ACL from the xattr, and convert into Samba's internal NFSv4 format */ static NTSTATUS nfs4_get_nfs4_acl(vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, const char *path, struct SMB4ACL_T **ppacl) { NTSTATUS status; DATA_BLOB blob = data_blob_null; ssize_t length; TALLOC_CTX *frame = talloc_stackframe(); do { blob.length += 1000; blob.data = talloc_realloc(frame, blob.data, uint8_t, blob.length); if (!blob.data) { TALLOC_FREE(frame); errno = ENOMEM; return NT_STATUS_NO_MEMORY; } length = SMB_VFS_NEXT_GETXATTR(handle, path, NFS4ACL_XATTR_NAME, blob.data, blob.length); blob.length = length; } while (length == -1 && errno == ERANGE); if (length == -1) { TALLOC_FREE(frame); return map_nt_error_from_unix(errno); } status = nfs4_get_nfs4_acl_common(mem_ctx, &blob, ppacl); TALLOC_FREE(frame); return status; }
static SMB_ACL_T fake_acls_sys_acl_get_fd(struct vfs_handle_struct *handle, files_struct *fsp, TALLOC_CTX *mem_ctx) { DATA_BLOB blob = data_blob_null; ssize_t length; const char *name = FAKE_ACL_ACCESS_XATTR; struct smb_acl_t *acl = NULL; TALLOC_CTX *frame = talloc_stackframe(); do { blob.length += 1000; blob.data = talloc_realloc(frame, blob.data, uint8_t, blob.length); if (!blob.data) { errno = ENOMEM; TALLOC_FREE(frame); return NULL; } length = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, blob.data, blob.length); blob.length = length; } while (length == -1 && errno == ERANGE); if (length == -1 && errno == ENOATTR) { TALLOC_FREE(frame); return NULL; } if (length != -1) { acl = fake_acls_blob2acl(&blob, mem_ctx); } TALLOC_FREE(frame); return acl; }
/* grow the allocation of the data buffer portion of a reply packet. Note that as this can reallocate the packet buffer this invalidates any local pointers into the packet. To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ static void smbcli_req_grow_allocation(struct smbcli_request *req, unsigned int new_size) { int delta; uint8_t *buf2; delta = new_size - req->out.data_size; if (delta + req->out.size <= req->out.allocated) { /* it fits in the preallocation */ return; } /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } if (buf2 == req->out.buffer) { /* the malloc library gave us the same pointer */ return; } /* update the pointers into the packet */ req->out.data = buf2 + PTR_DIFF(req->out.data, req->out.buffer); req->out.ptr = buf2 + PTR_DIFF(req->out.ptr, req->out.buffer); req->out.vwv = buf2 + PTR_DIFF(req->out.vwv, req->out.buffer); req->out.hdr = buf2 + PTR_DIFF(req->out.hdr, req->out.buffer); req->out.buffer = buf2; }
static float *load_interleaved_samples(const wchar_t *filename, SF_INFO *sf_info){ SNDFILE *sndfile = sf_open(STRING_get_chars(filename),SFM_READ,sf_info); if(sndfile==NULL) return NULL; float *ret = talloc_atomic(sizeof(float) * sf_info->channels * sf_info->frames); int allocated_frames = sf_info->frames; int total_read_frames = sf_readf_float(sndfile, ret, sf_info->frames); if(total_read_frames==0) return NULL; while(true){ float samples[1024*sf_info->channels]; int read_now = sf_readf_float(sndfile, samples, 1024); if(read_now==0) break; if(total_read_frames + read_now > allocated_frames){ allocated_frames = (total_read_frames+read_now) * 2; ret = talloc_realloc(ret, allocated_frames * sizeof(float) * sf_info->channels); } memcpy(ret + (total_read_frames*sf_info->channels), samples, sizeof(float)*1024*sf_info->channels); total_read_frames += read_now; } sf_close(sndfile); sf_info->frames = total_read_frames; return ret; }
/* grow a SMB2 buffer by the specified amount */ NTSTATUS smb2_grow_buffer(struct smb2_request_buffer *buf, size_t increase) { size_t hdr_ofs; size_t dynamic_ofs; uint8_t *buffer_ptr; uint32_t newsize = buf->size + increase; /* a packet size should be limited a bit */ if (newsize >= 0x00FFFFFF) return NT_STATUS_MARSHALL_OVERFLOW; if (newsize <= buf->allocated) return NT_STATUS_OK; hdr_ofs = buf->hdr - buf->buffer; dynamic_ofs = buf->dynamic - buf->buffer; buffer_ptr = talloc_realloc(buf, buf->buffer, uint8_t, newsize); NT_STATUS_HAVE_NO_MEMORY(buffer_ptr); buf->buffer = buffer_ptr; buf->hdr = buf->buffer + hdr_ofs; buf->body = buf->hdr + SMB2_HDR_BODY; buf->dynamic = buf->buffer + dynamic_ofs; buf->allocated = newsize; return NT_STATUS_OK; }
/** \details Expand the available space in the buffer to size \param push Pointer to the mapirops_push structure \param extra_size The extra size to add to current buffer \return MAPIROPS_ERR_SUCCESS on success, MAPIROPS_ERR_BUFSIZE if an overflow is detected, or MAPIROPS_ERR_ALLOC if realloc failed. */ enum mapirops_err_code mapirops_push_expand(struct mapirops_push *push, uint32_t extra_size) { uint32_t size = extra_size + push->offset; if (size < push->offset) { return mapirops_error(MAPIROPS_ERR_BUFSIZE, LOG_ERR, "Overflow in push_expand to %u", size); } if (talloc_get_size(push->data.data) >= size) { return MAPIROPS_ERR_SUCCESS; } push->data.length += MAPIROPS_CHUNK_SIZE; if ((size + 1) > push->data.length) { push->data.length = size + 1; } push->data.data = talloc_realloc(push, push->data.data, uint8_t, push->data.length); if (push->data.data == NULL) { return mapirops_error(MAPIROPS_ERR_ALLOC, LOG_ERR, "Failed to push_expand to %u", push->data.length); } return MAPIROPS_ERR_SUCCESS; }
static bool tldap_add_blob_vals(TALLOC_CTX *mem_ctx, struct tldap_mod *mod, DATA_BLOB *newvals, int num_newvals) { int num_values = talloc_array_length(mod->values); int i; DATA_BLOB *tmp; tmp = talloc_realloc(mem_ctx, mod->values, DATA_BLOB, num_values + num_newvals); if (tmp == NULL) { return false; } mod->values = tmp; for (i=0; i<num_newvals; i++) { mod->values[i+num_values].data = (uint8_t *)talloc_memdup( mod->values, newvals[i].data, newvals[i].length); if (mod->values[i+num_values].data == NULL) { return false; } mod->values[i+num_values].length = newvals[i].length; } mod->num_values = num_values + num_newvals; return true; }
static char * random_utf8_string (void *ctx, size_t char_count) { size_t offset = 0; size_t i; gchar *buf = NULL; size_t buf_size = 0; for (i = 0; i < char_count; i++) { gunichar randomchar; size_t written; /* 6 for one glyph, one for null, one for luck */ while (buf_size <= offset + 8) { buf_size = 2 * buf_size + 8; buf = talloc_realloc (ctx, buf, gchar, buf_size); } do { randomchar = random_unichar (); } while (randomchar == '\n'); written = g_unichar_to_utf8 (randomchar, buf + offset); if (written <= 0) { fprintf (stderr, "error converting to utf8\n"); exit (1); } offset += written; } buf[offset] = 0; return buf; }
/** \details Test the CreateBookmark (0x1b) operation This function: -# Opens the Inbox folder and gets the hierarchy table -# Customize the MAPI table view -# CreateBookmark for each table's row -# Free Bookmark for each created bookmark -# Cleans up \param mt pointer on the top-level mapitest structure \return true on success, otherwise false */ _PUBLIC_ bool mapitest_oxctable_CreateBookmark(struct mapitest *mt) { enum MAPISTATUS retval; mapi_object_t obj_htable; uint32_t *bkPosition; uint32_t count; uint32_t i; struct SPropTagArray *SPropTagArray; struct SRowSet SRowSet; /* Step 1. Logon */ if (! mapitest_common_setup(mt, &obj_htable, &count)) { return false; } /* Step 2. Customize the table view */ SPropTagArray = set_SPropTagArray(mt->mem_ctx, 0x3, PR_DISPLAY_NAME, PR_FID, PR_FOLDER_CHILD_COUNT); retval = SetColumns(&obj_htable, SPropTagArray); MAPIFreeBuffer(SPropTagArray); if (retval != MAPI_E_SUCCESS) { return false; } /* Step 3. Create Bookmarks */ bkPosition = talloc_array(mt->mem_ctx, uint32_t, 1); retval = QueryRows(&obj_htable, 100, TBL_ADVANCE, &SRowSet); for (i = 0; i < SRowSet.cRows; i++) { bkPosition = talloc_realloc(mt->mem_ctx, bkPosition, uint32_t, i + 2); retval = CreateBookmark(&obj_htable, &(bkPosition[i])); mapitest_print_retval_fmt_clean(mt, "CreateBookmark", retval, "(%.2d)", i); if (retval != MAPI_E_SUCCESS) { return false; } } retval = mapi_object_bookmark_get_count(&obj_htable, &count); /* Step 4. Free Bookmarks */ for (i = 0; i < count; i++) { retval = FreeBookmark(&obj_htable, bkPosition[i]); mapitest_print_retval_fmt_clean(mt, "FreeBookmark", retval, "(%.2d)", i); if (retval != MAPI_E_SUCCESS) { return false; } } /* Step 5. Release */ mapi_object_release(&obj_htable); mapitest_common_cleanup(mt); talloc_free(bkPosition); return true; }
static NTSTATUS get_acl_blob(TALLOC_CTX *ctx, vfs_handle_struct *handle, files_struct *fsp, const struct smb_filename *smb_fname, DATA_BLOB *pblob) { size_t size = 1024; uint8_t *val = NULL; uint8_t *tmp; ssize_t sizeret; int saved_errno = 0; ZERO_STRUCTP(pblob); again: tmp = talloc_realloc(ctx, val, uint8_t, size); if (tmp == NULL) { TALLOC_FREE(val); return NT_STATUS_NO_MEMORY; } val = tmp; become_root(); if (fsp && fsp->fh->fd != -1) { sizeret = SMB_VFS_FGETXATTR(fsp, XATTR_NTACL_NAME, val, size); } else { sizeret = SMB_VFS_GETXATTR(handle->conn, smb_fname->base_name, XATTR_NTACL_NAME, val, size); } if (sizeret == -1) { saved_errno = errno; } unbecome_root(); /* Max ACL size is 65536 bytes. */ if (sizeret == -1) { errno = saved_errno; if ((errno == ERANGE) && (size != 65536)) { /* Too small, try again. */ size = 65536; goto again; } /* Real error - exit here. */ TALLOC_FREE(val); return map_nt_error_from_unix(errno); } pblob->data = val; pblob->length = sizeret; return NT_STATUS_OK; }
static void e_mapi_util_bin_append_val (TALLOC_CTX *mem_ctx, struct Binary_r *bin, const uint8_t *val, gsize len) { uint8_t *ptr = NULL; bin->lpb = talloc_realloc (mem_ctx, bin->lpb, uint8_t, bin->cb + len); bin->cb += len; ptr = bin->lpb + bin->cb - len; memcpy (ptr, val, len); }
static void e_mapi_util_bin_append_string (TALLOC_CTX *mem_ctx, struct Binary_r *bin, const gchar *val) { gsize len = strlen (val); gchar *ptr = NULL; bin->lpb = talloc_realloc (mem_ctx, bin->lpb, uint8_t, bin->cb + (len + 1)); bin->cb += (len + 1); ptr = (gchar *) bin->lpb + bin->cb - (len + 1); strcpy (ptr, val); }
/* grow the data size of a trans2 reply */ NTSTATUS smbsrv_blob_grow_data(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, uint32_t new_size) { if (new_size > blob->length) { uint8_t *p; p = talloc_realloc(mem_ctx, blob->data, uint8_t, new_size); NT_STATUS_HAVE_NO_MEMORY(p); blob->data = p; } blob->length = new_size; return NT_STATUS_OK; }
static void e_mapi_util_bin_append_uint16 (TALLOC_CTX *mem_ctx, struct Binary_r *bin, const uint16_t val) { uint8_t *ptr = NULL; bin->lpb = talloc_realloc (mem_ctx, bin->lpb, uint8_t, bin->cb + 2); bin->cb += 2; ptr = bin->lpb + bin->cb - 2; *ptr++ = ( val & 0xFF); *ptr++ = ((val >> 8) & 0xFF); }
char * sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s) { size_t nlen; uint8_t *ret; ret = sss_tc_utf8_tolower(mem_ctx, (const uint8_t *) s, strlen(s), &nlen); if (!ret) return NULL; ret = talloc_realloc(mem_ctx, ret, uint8_t, nlen+1); if (!ret) return NULL; ret[nlen] = '\0'; return (char *) ret; }
static bool add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value, struct ldb_message_element *attrib) { attrib->values = talloc_realloc(mem_ctx, attrib->values, DATA_BLOB, attrib->num_values+1); if (attrib->values == NULL) return false; attrib->values[attrib->num_values].data = talloc_steal(attrib->values, value->data); attrib->values[attrib->num_values].length = value->length; attrib->num_values += 1; return true; }
/** * Realloc @p s to append the formatted result of @p fmt and @p ap, * and return @p s, which may have moved. Good for gradually * accumulating output into a string buffer. **/ char *talloc_vasprintf_append(TALLOC_CTX *t, char *s, const char *fmt, va_list ap) { int len, s_len; va_list ap2; VA_COPY(ap2, ap); s_len = strlen(s); len = vsnprintf(NULL, 0, fmt, ap2); s = talloc_realloc(t, s, s_len + len+1); if (!s) return NULL; VA_COPY(ap2, ap); vsnprintf(s+s_len, len+1, fmt, ap2); return s; }
/* expand the available space in the buffer to 'size' */ _PUBLIC_ NTSTATUS ndr_push_expand(struct ndr_push *ndr, uint32_t size) { if (ndr->alloc_size > size) { return NT_STATUS_OK; } ndr->alloc_size += NDR_BASE_MARSHALL_SIZE; if (size+1 > ndr->alloc_size) { ndr->alloc_size = size+1; } ndr->data = talloc_realloc(ndr, ndr->data, uint8_t, ndr->alloc_size); if (!ndr->data) { return ndr_push_error(ndr, NDR_ERR_ALLOC, "Failed to push_expand to %u", ndr->alloc_size); } return NT_STATUS_OK; }