summaryrefslogtreecommitdiff
path: root/source3/rpc_parse
diff options
context:
space:
mode:
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r--source3/rpc_parse/parse_net.c28
-rw-r--r--source3/rpc_parse/parse_prs.c66
-rw-r--r--source3/rpc_parse/parse_sec.c8
3 files changed, 72 insertions, 30 deletions
diff --git a/source3/rpc_parse/parse_net.c b/source3/rpc_parse/parse_net.c
index 853bca3b54..1e31836476 100644
--- a/source3/rpc_parse/parse_net.c
+++ b/source3/rpc_parse/parse_net.c
@@ -1804,9 +1804,9 @@ static BOOL net_io_sam_domain_info(const char *desc, SAM_DOMAIN_INFO * info,
if (!smb_io_unihdr("hdr_unknown", &info->hdr_unknown, ps, depth))
return False;
- if (ps->data_offset + 40 > ps->buffer_size)
+ if (prs_offset(ps) + 40 > prs_data_size(ps))
return False;
- ps->data_offset += 40;
+ prs_set_offset(ps, prs_offset(ps) + 40);
if (!smb_io_unistr2("uni_dom_name", &info->uni_dom_name,
info->hdr_dom_name.buffer, ps, depth))
@@ -1843,9 +1843,9 @@ static BOOL net_io_sam_group_info(const char *desc, SAM_GROUP_INFO * info,
if (!smb_io_bufhdr2("hdr_sec_desc", &info->hdr_sec_desc, ps, depth))
return False;
- if (ps->data_offset + 48 > ps->buffer_size)
+ if (prs_offset(ps) + 48 > prs_data_size(ps))
return False;
- ps->data_offset += 48;
+ prs_set_offset(ps, prs_offset(ps) + 48);
if (!smb_io_unistr2("uni_grp_name", &info->uni_grp_name,
info->hdr_grp_name.buffer, ps, depth))
@@ -2124,13 +2124,13 @@ static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
uint32 len = 0x44;
if (!prs_uint32("pwd_len", ps, depth, &len))
return False;
- old_offset = ps->data_offset;
+ old_offset = prs_offset(ps);
if (len == 0x44)
{
if (ps->io)
{
/* reading */
- if (!prs_hash1(ps, ps->data_offset, sess_key))
+ if (!prs_hash1(ps, prs_offset(ps), sess_key))
return False;
}
if (!net_io_sam_passwd_info("pass", &info->pass,
@@ -2144,9 +2144,9 @@ static BOOL net_io_sam_account_info(const char *desc, uint8 sess_key[16],
return False;
}
}
- if (old_offset + len > ps->buffer_size)
+ if (old_offset + len > prs_data_size(ps))
return False;
- ps->data_offset = old_offset + len;
+ prs_set_offset(ps, old_offset + len);
}
if (!smb_io_buffer4("buf_sec_desc", &info->buf_sec_desc,
info->hdr_sec_desc.buffer, ps, depth))
@@ -2181,9 +2181,9 @@ static BOOL net_io_sam_group_mem_info(const char *desc, SAM_GROUP_MEM_INFO * inf
if (!prs_uint32("num_members", ps, depth, &info->num_members))
return False;
- if (ps->data_offset + 16 > ps->buffer_size)
+ if (prs_offset(ps) + 16 > prs_data_size(ps))
return False;
- ps->data_offset += 16;
+ prs_set_offset(ps, prs_offset(ps) + 16);
if (info->ptr_rids != 0)
{
@@ -2263,9 +2263,9 @@ static BOOL net_io_sam_alias_info(const char *desc, SAM_ALIAS_INFO * info,
if (!smb_io_unihdr("hdr_als_desc", &info->hdr_als_desc, ps, depth))
return False;
- if (ps->data_offset + 40 > ps->buffer_size)
+ if (prs_offset(ps) + 40 > prs_data_size(ps))
return False;
- ps->data_offset += 40;
+ prs_set_offset(ps, prs_offset(ps) + 40);
if (!smb_io_unistr2("uni_als_name", &info->uni_als_name,
info->hdr_als_name.buffer, ps, depth))
@@ -2300,9 +2300,9 @@ static BOOL net_io_sam_alias_mem_info(const char *desc, SAM_ALIAS_MEM_INFO * inf
if (info->ptr_members != 0)
{
- if (ps->data_offset + 16 > ps->buffer_size)
+ if (prs_offset(ps) + 16 > prs_data_size(ps))
return False;
- ps->data_offset += 16;
+ prs_set_offset(ps, prs_offset(ps) + 16);
if (!prs_uint32("num_sids", ps, depth, &info->num_sids))
return False;
diff --git a/source3/rpc_parse/parse_prs.c b/source3/rpc_parse/parse_prs.c
index 6f6117a9e2..702375be35 100644
--- a/source3/rpc_parse/parse_prs.c
+++ b/source3/rpc_parse/parse_prs.c
@@ -134,7 +134,8 @@ void prs_mem_free(prs_struct *ps)
void prs_mem_clear(prs_struct *ps)
{
- memset(ps->data_p, '\0', (size_t)ps->buffer_size);
+ if (ps->buffer_size)
+ memset(ps->data_p, '\0', (size_t)ps->buffer_size);
}
/*******************************************************************
@@ -143,11 +144,13 @@ void prs_mem_clear(prs_struct *ps)
char *prs_alloc_mem(prs_struct *ps, size_t size)
{
- char *ret = talloc(ps->mem_ctx, size);
-
- if (ret)
- memset(ret, '\0', size);
+ char *ret = NULL;
+ if (size) {
+ ret = talloc(ps->mem_ctx, size);
+ if (ret)
+ memset(ret, '\0', size);
+ }
return ret;
}
@@ -308,7 +311,7 @@ BOOL prs_force_grow(prs_struct *ps, uint32 extra_space)
/*******************************************************************
Get the data pointer (external interface).
- ********************************************************************/
+********************************************************************/
char *prs_data_p(prs_struct *ps)
{
@@ -357,10 +360,13 @@ BOOL prs_set_offset(prs_struct *ps, uint32 offset)
BOOL prs_append_prs_data(prs_struct *dst, prs_struct *src)
{
+ if (prs_offset(src) == 0)
+ return True;
+
if(!prs_grow(dst, prs_offset(src)))
return False;
- memcpy(&dst->data_p[dst->data_offset], prs_data_p(src), (size_t)prs_offset(src));
+ memcpy(&dst->data_p[dst->data_offset], src->data_p, (size_t)prs_offset(src));
dst->data_offset += prs_offset(src);
return True;
@@ -378,7 +384,7 @@ BOOL prs_append_some_prs_data(prs_struct *dst, prs_struct *src, int32 start, uin
if(!prs_grow(dst, len))
return False;
- memcpy(&dst->data_p[dst->data_offset], prs_data_p(src)+start, (size_t)len);
+ memcpy(&dst->data_p[dst->data_offset], src->data_p + start, (size_t)len);
dst->data_offset += len;
return True;
@@ -388,8 +394,11 @@ BOOL prs_append_some_prs_data(prs_struct *dst, prs_struct *src, int32 start, uin
Append the data from a buffer into a parse_struct.
********************************************************************/
-BOOL prs_append_data(prs_struct *dst, char *src, uint32 len)
+BOOL prs_copy_data_in(prs_struct *dst, char *src, uint32 len)
{
+ if (len == 0)
+ return True;
+
if(!prs_grow(dst, len))
return False;
@@ -400,6 +409,39 @@ BOOL prs_append_data(prs_struct *dst, char *src, uint32 len)
}
/*******************************************************************
+ Copy some data from a parse_struct into a buffer.
+ ********************************************************************/
+
+BOOL prs_copy_data_out(char *dst, prs_struct *src, uint32 len)
+{
+ if (len == 0)
+ return True;
+
+ if(!prs_mem_get(src, len))
+ return False;
+
+ memcpy(dst, &src->data_p[src->data_offset], (size_t)len);
+ src->data_offset += len;
+
+ return True;
+}
+
+/*******************************************************************
+ Copy all the data from a parse_struct into a buffer.
+ ********************************************************************/
+
+BOOL prs_copy_all_data_out(char *dst, prs_struct *src)
+{
+ uint32 len = prs_offset(src);
+
+ if (!len)
+ return True;
+
+ prs_set_offset(src, 0);
+ return prs_copy_data_out(dst, src, len);
+}
+
+/*******************************************************************
Set the data as X-endian (external interface).
********************************************************************/
@@ -1049,7 +1091,7 @@ BOOL prs_unistr(const char *name, prs_struct *ps, int depth, UNISTR *str)
else { /* unmarshalling */
uint32 alloc_len = 0;
- q = prs_data_p(ps) + prs_offset(ps);
+ q = ps->data_p + prs_offset(ps);
/*
* Work out how much space we need and talloc it.
@@ -1242,7 +1284,7 @@ int tdb_prs_store(TDB_CONTEXT *tdb, char *keystr, prs_struct *ps)
TDB_DATA kbuf, dbuf;
kbuf.dptr = keystr;
kbuf.dsize = strlen(keystr)+1;
- dbuf.dptr = prs_data_p(ps);
+ dbuf.dptr = ps->data_p;
dbuf.dsize = prs_offset(ps);
return tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
}
@@ -1272,7 +1314,7 @@ BOOL prs_hash1(prs_struct *ps, uint32 offset, uint8 sess_key[16])
{
char *q;
- q = prs_data_p(ps);
+ q = ps->data_p;
q = &q[offset];
#ifdef DEBUG_PASSWORD
diff --git a/source3/rpc_parse/parse_sec.c b/source3/rpc_parse/parse_sec.c
index a49a34139e..dbd72e5250 100644
--- a/source3/rpc_parse/parse_sec.c
+++ b/source3/rpc_parse/parse_sec.c
@@ -782,7 +782,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if (psd->off_owner_sid != 0) {
- tmp_offset = ps->data_offset;
+ tmp_offset = prs_offset(ps);
if(!prs_set_offset(ps, old_offset + psd->off_owner_sid))
return False;
@@ -803,7 +803,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if (psd->off_grp_sid != 0) {
- tmp_offset = ps->data_offset;
+ tmp_offset = prs_offset(ps);
if(!prs_set_offset(ps, old_offset + psd->off_grp_sid))
return False;
@@ -823,7 +823,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
}
if ((psd->type & SEC_DESC_SACL_PRESENT) && psd->off_sacl) {
- tmp_offset = ps->data_offset;
+ tmp_offset = prs_offset(ps);
if(!prs_set_offset(ps, old_offset + psd->off_sacl))
return False;
if(!sec_io_acl("sacl", &psd->sacl, ps, depth))
@@ -835,7 +835,7 @@ BOOL sec_io_desc(const char *desc, SEC_DESC **ppsd, prs_struct *ps, int depth)
if ((psd->type & SEC_DESC_DACL_PRESENT) && psd->off_dacl != 0) {
- tmp_offset = ps->data_offset;
+ tmp_offset = prs_offset(ps);
if(!prs_set_offset(ps, old_offset + psd->off_dacl))
return False;
if(!sec_io_acl("dacl", &psd->dacl, ps, depth))