Print this page
1575 untangle libmlrpc ... (libmlrpc)

*** 19,28 **** --- 19,30 ---- * CDDL HEADER END */ /* * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. + * + * Copyright 2013 Nexenta Systems, Inc. All rights reserved. */ /* * NDR heap management. The heap is used for temporary storage by * both the client and server side library routines. In order to
*** 44,56 **** #include <stdlib.h> #include <string.h> #include <strings.h> #include <sys/uio.h> ! #include <smbsrv/libsmb.h> ! #include <smbsrv/libmlrpc.h> ! #include <smbsrv/smb_sid.h> /* * Allocate a heap structure and the first heap block. For many RPC * operations this will be the only time we need to malloc memory * in this instance of the heap. The only point of note here is that --- 46,57 ---- #include <stdlib.h> #include <string.h> #include <strings.h> #include <sys/uio.h> ! #include <libmlrpc.h> ! #include <ndr_wchar.h> /* * Allocate a heap structure and the first heap block. For many RPC * operations this will be the only time we need to malloc memory * in this instance of the heap. The only point of note here is that
*** 152,161 **** --- 153,179 ---- heap->iov->iov_len += size; return ((void *)p); } /* + * Convenience function to copy some memory into the heap. + */ + void * + ndr_heap_dupmem(ndr_heap_t *heap, const void *mem, size_t len) + { + void *p; + + if (mem == NULL) + return (NULL); + + if ((p = ndr_heap_malloc(heap, len)) != NULL) + (void) memcpy(p, mem, len); + + return (p); + } + + /* * Convenience function to do heap strdup. */ void * ndr_heap_strdup(ndr_heap_t *heap, const char *s) {
*** 169,180 **** * 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); } /* --- 187,197 ---- * We don't need to clutter the heap with empty strings. */ if ((len = strlen(s)) == 0) return (""); ! p = ndr_heap_dupmem(heap, s, len+1); return (p); } /*
*** 181,196 **** * Make an ndr_mstring_t from a regular string. */ int ndr_heap_mstring(ndr_heap_t *heap, const char *s, ndr_mstring_t *out) { if (s == NULL || out == NULL) return (-1); ! out->length = smb_wcequiv_strlen(s); ! out->allosize = out->length + sizeof (smb_wchar_t); if ((out->str = ndr_heap_strdup(heap, s)) == NULL) return (-1); return (0); } --- 198,223 ---- * Make an ndr_mstring_t from a regular string. */ int ndr_heap_mstring(ndr_heap_t *heap, const char *s, ndr_mstring_t *out) { + size_t slen; + if (s == NULL || out == NULL) return (-1); ! /* ! * Determine the WC strlen of s ! * Was ndr__wcequiv_strlen(s) ! */ ! slen = ndr__mbstowcs(NULL, s, NDR_STRING_MAX); ! if (slen == (size_t)-1) ! return (-1); + out->length = slen * sizeof (ndr_wchar_t); + out->allosize = out->length + sizeof (ndr_wchar_t); + if ((out->str = ndr_heap_strdup(heap, s)) == NULL) return (-1); return (0); }
*** 205,228 **** * 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); } } void ndr_heap_mkvcb(ndr_heap_t *heap, uint8_t *data, uint32_t datalen, --- 232,266 ---- * aware that this is really a string. */ void ndr_heap_mkvcs(ndr_heap_t *heap, char *s, ndr_vcstr_t *vc) { + size_t slen; int mlen; ! /* ! * Determine the WC strlen of s ! * Was ndr__wcequiv_strlen(s) ! */ ! slen = ndr__mbstowcs(NULL, s, NDR_STRING_MAX); ! if (slen == (size_t)-1) ! slen = 0; ! ! vc->wclen = slen * sizeof (ndr_wchar_t); vc->wcsize = vc->wclen; ! /* ! * alloc one extra wchar for a null ! * See slen + 1 arg for mbstowcs ! */ ! mlen = sizeof (ndr_vcs_t) + vc->wcsize + sizeof (ndr_wchar_t); vc->vcs = ndr_heap_malloc(heap, mlen); if (vc->vcs) { vc->vcs->vc_first_is = 0; ! vc->vcs->vc_length_is = slen; ! (void) ndr__mbstowcs(vc->vcs->buffer, s, slen + 1); } } void ndr_heap_mkvcb(ndr_heap_t *heap, uint8_t *data, uint32_t datalen,
*** 248,277 **** bcopy(data, vcbuf->vcb->buffer, datalen); } } /* ! * 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); - } - int ndr_heap_used(ndr_heap_t *heap) { int used = 0; int i; --- 286,298 ---- bcopy(data, vcbuf->vcb->buffer, datalen); } } /* ! * Removed ndr_heap_siddup(), now using ndr_heap_dupmem(). */ int ndr_heap_used(ndr_heap_t *heap) { int used = 0; int i;