summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-08-21 13:19:36 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:34:15 -0500
commit9796ba264ca1ad8a7ec178ecfec6331d4cac4349 (patch)
tree35424ddd9e0b22296882b7aa6aa971b4bd124b4d
parent375d11ac788af6e0d9b95cfce9dcbe54024d7505 (diff)
downloadsamba-9796ba264ca1ad8a7ec178ecfec6331d4cac4349.tar.gz
samba-9796ba264ca1ad8a7ec178ecfec6331d4cac4349.tar.bz2
samba-9796ba264ca1ad8a7ec178ecfec6331d4cac4349.zip
r9445: Support flags, add DATA_BLOB support
(This used to be commit cb5b23f0382ea7e242248cdfbbed82bc4eedfe42)
-rw-r--r--source4/build/pidl/Parse/Pidl/Samba/TDR.pm14
-rw-r--r--source4/lib/tdr/tdr.c85
-rw-r--r--source4/lib/tdr/tdr.h7
3 files changed, 100 insertions, 6 deletions
diff --git a/source4/build/pidl/Parse/Pidl/Samba/TDR.pm b/source4/build/pidl/Parse/Pidl/Samba/TDR.pm
index fb9dd0daea..b9bfd83e41 100644
--- a/source4/build/pidl/Parse/Pidl/Samba/TDR.pm
+++ b/source4/build/pidl/Parse/Pidl/Samba/TDR.pm
@@ -50,6 +50,13 @@ sub ParserElement($$$)
$name = ", \"$e->{NAME}\"$array";
}
+ if (has_property($e, "flag")) {
+ pidl "{";
+ indent;
+ pidl "uint32_t saved_flags = tdr->flags;";
+ pidl "tdr->flags |= $e->{PROPERTIES}->{flag};";
+ }
+
if (has_property($e, "charset")) {
fatal($e,"charset() on non-array element") unless (defined($e->{ARRAY_LEN}) and scalar(@{$e->{ARRAY_LEN}}) > 0);
@@ -59,6 +66,7 @@ sub ParserElement($$$)
return;
}
+
if (has_property($e, "switch_is")) {
$switch = ", " . ParseExpr($e->{PROPERTIES}->{switch_is}, $env);
}
@@ -82,6 +90,12 @@ sub ParserElement($$$)
pidl "TDR_CHECK(tdr_$t\_$e->{TYPE}(tdr$name$switch, &v->$e->{NAME}$array));";
if ($array) { deindent; pidl "}"; }
+
+ if (has_property($e, "flag")) {
+ pidl "tdr->flags = saved_flags;";
+ deindent;
+ pidl "}";
+ }
}
sub ParserStruct($$$$)
diff --git a/source4/lib/tdr/tdr.c b/source4/lib/tdr/tdr.c
index 8cfbe3695b..1c84d2229f 100644
--- a/source4/lib/tdr/tdr.c
+++ b/source4/lib/tdr/tdr.c
@@ -34,7 +34,7 @@
} \
} while(0)
-#define TDR_BE(tdr) ((tdr)->flags & TDR_FLAG_BIGENDIAN)
+#define TDR_BE(tdr) ((tdr)->flags & TDR_BIG_ENDIAN)
#define TDR_SVAL(tdr, ofs) (TDR_BE(tdr)?RSVAL(tdr->data,ofs):SVAL(tdr->data,ofs))
#define TDR_IVAL(tdr, ofs) (TDR_BE(tdr)?RIVAL(tdr->data,ofs):IVAL(tdr->data,ofs))
@@ -45,11 +45,9 @@
struct tdr_pull *tdr_pull_init(TALLOC_CTX *mem_ctx, DATA_BLOB *blob)
{
- struct tdr_pull *tdr = talloc(mem_ctx, struct tdr_pull);
+ struct tdr_pull *tdr = talloc_zero(mem_ctx, struct tdr_pull);
tdr->data = blob->data;
tdr->length = blob->length;
- tdr->offset = 0;
- tdr->flags = 0;
return tdr;
}
@@ -167,7 +165,7 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, const char **v, uint32_t length,
TDR_PULL_NEED_BYTES(tdr, el_size*length);
- ret = convert_string_talloc(tdr, chset, CH_UNIX, tdr->data+tdr->offset, el_size*length, (void **)v);
+ ret = convert_string_talloc(tdr, chset, CH_UNIX, tdr->data+tdr->offset, el_size*length, discard_const_p(void *, v));
if (ret == -1) {
return NT_STATUS_INVALID_PARAMETER;
@@ -301,4 +299,81 @@ NTSTATUS tdr_pull_time_t(struct tdr_pull *tdr, time_t *t)
return NT_STATUS_OK;
}
+NTSTATUS tdr_print_time_t(struct tdr_print *tdr, const char *name, time_t *t)
+{
+ if (*t == (time_t)-1 || *t == 0) {
+ tdr->print(tdr, "%-25s: (time_t)%d", name, (int)*t);
+ } else {
+ tdr->print(tdr, "%-25s: %s", name, timestring(tdr, *t));
+ }
+
+ return NT_STATUS_OK;
+}
+
+NTSTATUS tdr_print_NTTIME(struct tdr_print *tdr, const char *name, NTTIME *t)
+{
+ tdr->print(tdr, "%-25s: %s", name, nt_time_string(tdr, *t));
+
+ return NT_STATUS_OK;
+}
+NTSTATUS tdr_print_DATA_BLOB(struct tdr_print *tdr, const char *name, DATA_BLOB *r)
+{
+ tdr->print(tdr, "%-25s: DATA_BLOB length=%u", name, r->length);
+ if (r->length) {
+ dump_data(10, r->data, r->length);
+ }
+
+ return NT_STATUS_OK;
+}
+
+#define TDR_ALIGN(tdr,n) (((tdr)->offset & ((n)-1)) == 0?0:((n)-((tdr)->offset&((n)-1))))
+
+/*
+ push a DATA_BLOB onto the wire.
+*/
+NTSTATUS tdr_push_DATA_BLOB(struct tdr_push *tdr, DATA_BLOB *blob)
+{
+ if (tdr->flags & TDR_ALIGN2) {
+ blob->length = TDR_ALIGN(tdr, 2);
+ } else if (tdr->flags & TDR_ALIGN4) {
+ blob->length = TDR_ALIGN(tdr, 4);
+ } else if (tdr->flags & TDR_ALIGN8) {
+ blob->length = TDR_ALIGN(tdr, 8);
+ }
+
+ TDR_PUSH_NEED_BYTES(tdr, blob->length);
+
+ memcpy(tdr->data+tdr->offset, blob->data, blob->length);
+ return NT_STATUS_OK;
+}
+
+/*
+ pull a DATA_BLOB from the wire.
+*/
+NTSTATUS tdr_pull_DATA_BLOB(struct tdr_pull *tdr, DATA_BLOB *blob)
+{
+ uint32_t length;
+
+ if (tdr->flags & TDR_ALIGN2) {
+ length = TDR_ALIGN(tdr, 2);
+ } else if (tdr->flags & TDR_ALIGN4) {
+ length = TDR_ALIGN(tdr, 4);
+ } else if (tdr->flags & TDR_ALIGN8) {
+ length = TDR_ALIGN(tdr, 8);
+ } else if (tdr->flags & TDR_REMAINING) {
+ length = tdr->length - tdr->offset;
+ } else {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (tdr->length - tdr->offset < length) {
+ length = tdr->length - tdr->offset;
+ }
+
+ TDR_PULL_NEED_BYTES(tdr, length);
+
+ *blob = data_blob_talloc(tdr, tdr->data+tdr->offset, length);
+ tdr->offset += length;
+ return NT_STATUS_OK;
+}
diff --git a/source4/lib/tdr/tdr.h b/source4/lib/tdr/tdr.h
index 604f9d549a..b6a1177c0d 100644
--- a/source4/lib/tdr/tdr.h
+++ b/source4/lib/tdr/tdr.h
@@ -18,7 +18,11 @@
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#define TDR_FLAG_BIGENDIAN 1
+#define TDR_BIG_ENDIAN 0x01
+#define TDR_ALIGN2 0x02
+#define TDR_ALIGN4 0x04
+#define TDR_ALIGN8 0x08
+#define TDR_REMAINING 0x10
struct tdr_pull {
uint8_t *data;
@@ -38,6 +42,7 @@ struct tdr_push {
struct tdr_print {
int level;
void (*print)(struct tdr_print *, const char *, ...);
+ int flags;
};
#define TDR_CHECK(call) do { NTSTATUS _status; \