void * ndr_rpc_malloc(mlsvc_handle_t *handle, size_t size) { ndr_heap_t *heap; if ((heap = ndr_rpc_get_heap(handle)) == NULL) return (NULL); return (ndr_heap_malloc(heap, size)); }
/* * Duplcate a SID in the heap. */ smb_sid_t * ndr_heap_siddup(ndr_heap_t *heap, smb_sid_t *sid) { smb_sid_t *new_sid; unsigned size; if (sid == NULL) return (NULL); size = smb_sid_len(sid); if ((new_sid = ndr_heap_malloc(heap, size)) == NULL) return (NULL); bcopy(sid, new_sid, size); return (new_sid); }
/* * Our regular string marshalling always creates null terminated strings * but some Windows clients and servers are pedantic about the string * formats they will accept and require non-null terminated strings. * This function can be used to build a wide-char, non-null terminated * string in the heap as a varying/conformant array. We need to do the * wide-char conversion here because the marshalling code won't be * aware that this is really a string. */ void ndr_heap_mkvcs(ndr_heap_t *heap, char *s, ndr_vcstr_t *vc) { int mlen; vc->wclen = smb_wcequiv_strlen(s); vc->wcsize = vc->wclen; mlen = sizeof (ndr_vcs_t) + vc->wcsize + sizeof (smb_wchar_t); vc->vcs = ndr_heap_malloc(heap, mlen); if (vc->vcs) { vc->vcs->vc_first_is = 0; vc->vcs->vc_length_is = vc->wclen / sizeof (smb_wchar_t); (void) smb_mbstowcs((smb_wchar_t *)vc->vcs->buffer, s, vc->vcs->vc_length_is); } }
/* * Convenience function to do heap strdup. */ void * ndr_heap_strdup(ndr_heap_t *heap, const char *s) { int len; void *p; if (s == NULL) return (NULL); /* * We don't need to clutter the heap with empty strings. */ if ((len = strlen(s)) == 0) return (""); if ((p = ndr_heap_malloc(heap, len+1)) != NULL) (void) strcpy((char *)p, s); return (p); }
/* * The transaction and the two nds streams use the same heap, which * should already exist at this point. The heap will also be available * to the stub. */ int ndr_generic_call_stub(ndr_xa_t *mxa) { ndr_binding_t *mbind = mxa->binding; ndr_service_t *msvc = mbind->service; ndr_typeinfo_t *intf_ti = msvc->interface_ti; ndr_stub_table_t *ste; int opnum = mxa->opnum; unsigned p_len = intf_ti->c_size_fixed_part; char *param; int rc; if (mxa->heap == NULL) { ndo_printf(0, 0, "%s[0x%02x]: no heap", msvc->name, opnum); return (NDR_DRC_FAULT_OUT_OF_MEMORY); } if ((ste = ndr_svc_find_stub(msvc, opnum)) == NULL) { ndo_printf(0, 0, "%s[0x%02x]: invalid opnum", msvc->name, opnum); return (NDR_DRC_FAULT_REQUEST_OPNUM_INVALID); } if ((param = ndr_heap_malloc(mxa->heap, p_len)) == NULL) return (NDR_DRC_FAULT_OUT_OF_MEMORY); bzero(param, p_len); rc = ndr_decode_call(mxa, param); if (!NDR_DRC_IS_OK(rc)) return (rc); rc = (*ste->func)(param, mxa); if (rc == NDR_DRC_OK) rc = ndr_encode_return(mxa, param); return (rc); }
void ndr_heap_mkvcb(ndr_heap_t *heap, uint8_t *data, uint32_t datalen, ndr_vcbuf_t *vcbuf) { int mlen; if (data == NULL || datalen == 0) { bzero(vcbuf, sizeof (ndr_vcbuf_t)); return; } vcbuf->len = datalen; vcbuf->size = datalen; mlen = sizeof (ndr_vcbuf_t) + datalen; vcbuf->vcb = ndr_heap_malloc(heap, mlen); if (vcbuf->vcb) { vcbuf->vcb->vc_first_is = 0; vcbuf->vcb->vc_length_is = datalen; bcopy(data, vcbuf->vcb->buffer, datalen); } }