summaryrefslogtreecommitdiff
path: root/source4/libcli/raw/raweas.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-11-17 22:00:15 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:05:57 -0500
commit5f868bc1acc9bdaed32ae70fb9906334663ccfff (patch)
tree9424d3bf161978f501e41006811c6dad4b83db28 /source4/libcli/raw/raweas.c
parent5efd740d4d4597208f835c6ed787c180056d7264 (diff)
downloadsamba-5f868bc1acc9bdaed32ae70fb9906334663ccfff.tar.gz
samba-5f868bc1acc9bdaed32ae70fb9906334663ccfff.tar.bz2
samba-5f868bc1acc9bdaed32ae70fb9906334663ccfff.zip
r3826: - added testing of ea lists in NTTRANS CREATE
- fixed push/pull of chained ea lists - fixed a bug in the nttrans wire encoding (This used to be commit fcd09224076508f9c10095bf2e2c394232a4d297)
Diffstat (limited to 'source4/libcli/raw/raweas.c')
-rw-r--r--source4/libcli/raw/raweas.c107
1 files changed, 102 insertions, 5 deletions
diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c
index 52c7832a6c..5bd90766aa 100644
--- a/source4/libcli/raw/raweas.c
+++ b/source4/libcli/raw/raweas.c
@@ -37,6 +37,23 @@ uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas)
}
/*
+ work out how many bytes on the wire a chained ea list will consume.
+ This assumes the names are strict ascii, which should be a
+ reasonable assumption
+*/
+uint_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas)
+{
+ uint_t total = 0;
+ int i;
+ for (i=0;i<num_eas;i++) {
+ uint_t len = 8 + strlen(eas[i].name.s)+1 + eas[i].value.length;
+ len = (len + 3) & ~3;
+ total += len;
+ }
+ return total;
+}
+
+/*
put a ea_list into a pre-allocated buffer - buffer must be at least
of size ea_list_size()
*/
@@ -63,6 +80,34 @@ void ea_put_list(char *data, uint_t num_eas, struct ea_struct *eas)
/*
+ put a chained ea_list into a pre-allocated buffer - buffer must be
+ at least of size ea_list_size()
+*/
+void ea_put_list_chained(char *data, uint_t num_eas, struct ea_struct *eas)
+{
+ int i;
+
+ for (i=0;i<num_eas;i++) {
+ uint_t nlen = strlen(eas[i].name.s);
+ uint32_t len = 8+nlen+1+eas[i].value.length;
+ uint_t pad = ((len + 3) & ~3) - len;
+ if (i == num_eas-1) {
+ SIVAL(data, 0, 0);
+ } else {
+ SIVAL(data, 0, len+pad);
+ }
+ SCVAL(data, 4, eas[i].flags);
+ SCVAL(data, 5, nlen);
+ SSVAL(data, 6, eas[i].value.length);
+ memcpy(data+8, eas[i].name.s, nlen+1);
+ memcpy(data+8+nlen+1, eas[i].value.data, eas[i].value.length);
+ memset(data+len, 0, pad);
+ data += len + pad;
+ }
+}
+
+
+/*
pull a ea_struct from a buffer. Return the number of bytes consumed
*/
uint_t ea_pull_struct(const DATA_BLOB *blob,
@@ -102,8 +147,8 @@ uint_t ea_pull_struct(const DATA_BLOB *blob,
pull a ea_list from a buffer
*/
NTSTATUS ea_pull_list(const DATA_BLOB *blob,
- TALLOC_CTX *mem_ctx,
- uint_t *num_eas, struct ea_struct **eas)
+ TALLOC_CTX *mem_ctx,
+ uint_t *num_eas, struct ea_struct **eas)
{
int n;
uint32_t ea_size, ofs;
@@ -116,13 +161,13 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob,
if (ea_size > blob->length) {
return NT_STATUS_INVALID_PARAMETER;
}
-
- ofs = 4;
+
+ ofs = 4;
n = 0;
*num_eas = 0;
*eas = NULL;
- while (ofs+6 < ea_size) {
+ while (ofs < ea_size) {
uint_t len;
DATA_BLOB blob2;
@@ -146,3 +191,55 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob,
return NT_STATUS_OK;
}
+
+/*
+ pull a chained ea_list from a buffer
+*/
+NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob,
+ TALLOC_CTX *mem_ctx,
+ uint_t *num_eas, struct ea_struct **eas)
+{
+ int n;
+ uint32_t ofs;
+
+ if (blob->length < 4) {
+ return NT_STATUS_INFO_LENGTH_MISMATCH;
+ }
+
+ ofs = 0;
+ n = 0;
+ *num_eas = 0;
+ *eas = NULL;
+
+ while (ofs < blob->length) {
+ uint_t len;
+ DATA_BLOB blob2;
+ uint32_t next_ofs = IVAL(blob->data, ofs);
+
+ blob2.data = blob->data + ofs + 4;
+ blob2.length = blob->length - (ofs + 4);
+
+ *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1));
+ if (! *eas) return NT_STATUS_NO_MEMORY;
+
+ len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]);
+ if (len == 0) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ ofs += next_ofs;
+
+ if (ofs+4 > blob->length) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+ n++;
+ if (next_ofs == 0) break;
+ }
+
+ *num_eas = n;
+
+ return NT_STATUS_OK;
+}
+
+
+