summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-01-05 02:01:19 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:08:18 -0500
commit58d9adf409ac11c5d8fd62cbb1bca9974cfbeb7d (patch)
tree635adb720a577497e3d8470e8de9ae7d15820752
parentd9ab65a8b40b540f163b454c6d543f090759cdae (diff)
downloadsamba-58d9adf409ac11c5d8fd62cbb1bca9974cfbeb7d.tar.gz
samba-58d9adf409ac11c5d8fd62cbb1bca9974cfbeb7d.tar.bz2
samba-58d9adf409ac11c5d8fd62cbb1bca9974cfbeb7d.zip
r4526: - much simpler (and more accurate!) ndr_size_*() code generation. It
is less efficient, but I really doubt that matters. - use enum in epmapper.idl for protocol type - added support for "enum8bit" flag, used in epmapper.idl (This used to be commit 1a24a50384b7f588844cd012f1218ca242ca4507)
-rw-r--r--source4/build/pidl/header.pm8
-rw-r--r--source4/build/pidl/needed.pm3
-rw-r--r--source4/build/pidl/parser.pm105
-rw-r--r--source4/gtk/tools/gepdump.c2
-rw-r--r--source4/librpc/idl/drsblobs.idl4
-rw-r--r--source4/librpc/idl/epmapper.idl8
-rw-r--r--source4/librpc/idl/netlogon.idl2
-rw-r--r--source4/librpc/ndr/ndr.c21
-rw-r--r--source4/librpc/rpc/dcerpc.c2
-rw-r--r--source4/librpc/rpc/dcerpc_util.c12
10 files changed, 59 insertions, 108 deletions
diff --git a/source4/build/pidl/header.pm b/source4/build/pidl/header.pm
index d90ee0e679..85ccbcd814 100644
--- a/source4/build/pidl/header.pm
+++ b/source4/build/pidl/header.pm
@@ -188,6 +188,11 @@ sub HeaderTypedef($)
sub HeaderTypedefProto($)
{
my($d) = shift;
+
+ if (needed::is_needed("ndr_size_$d->{NAME}")) {
+ $res .= "size_t ndr_size_$d->{NAME}(const struct $d->{NAME} *r, int flags);\n";
+ }
+
if (!util::has_property($d, "public")) {
return;
}
@@ -199,9 +204,6 @@ sub HeaderTypedefProto($)
$res .= "void ndr_print_$d->{NAME}(struct ndr_print *ndr, const char *name, struct $d->{NAME} *r);\n";
}
- if (needed::is_needed("ndr_size_$d->{NAME}")) {
- $res .= "size_t ndr_size_$d->{NAME}(int ret, const struct $d->{NAME} *r, int flags);\n";
- }
}
if ($d->{DATA}{TYPE} eq "UNION") {
$res .= "NTSTATUS ndr_push_$d->{NAME}(struct ndr_push *ndr, int ndr_flags, int level, union $d->{NAME} *r);\n";
diff --git a/source4/build/pidl/needed.pm b/source4/build/pidl/needed.pm
index f58d897cb3..2f42ce6703 100644
--- a/source4/build/pidl/needed.pm
+++ b/source4/build/pidl/needed.pm
@@ -44,9 +44,6 @@ sub NeededTypedef($)
if ($needed{"push_$t->{NAME}"}) {
$needed{"push_$e->{TYPE}"} = 1;
}
- if ($needed{"ndr_size_$t->{NAME}"}) {
- $needed{"ndr_size_$e->{TYPE}"} = 1;
- }
}
}
if ($t->{DATA}->{TYPE} eq "UNION") {
diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm
index 5a67f3d193..c55b47dc59 100644
--- a/source4/build/pidl/parser.pm
+++ b/source4/build/pidl/parser.pm
@@ -804,6 +804,8 @@ sub ParseEnumPush($)
if (util::has_property($enum->{PARENT}, "v1_enum")) {
pidl "\tNDR_CHECK(ndr_push_uint32(ndr, r));\n";
+ } elsif (util::has_property($enum->{PARENT}, "enum8bit")) {
+ pidl "\tNDR_CHECK(ndr_push_uint8(ndr, r));\n";
} else {
pidl "\tNDR_CHECK(ndr_push_uint16(ndr, r));\n";
}
@@ -822,6 +824,9 @@ sub ParseEnumPull($)
if (util::has_property($enum->{PARENT}, "v1_enum")) {
pidl "\tuint32_t v;\n";
pidl "\tNDR_CHECK(ndr_pull_uint32(ndr, &v));\n";
+ } elsif (util::has_property($enum->{PARENT}, "enum8bit")) {
+ pidl "\tuint8_t v;\n";
+ pidl "\tNDR_CHECK(ndr_pull_uint8(ndr, &v));\n";
} else {
pidl "\tuint16_t v;\n";
pidl "\tNDR_CHECK(ndr_pull_uint16(ndr, &v));\n";
@@ -961,54 +966,12 @@ sub ParseStructNdrSize($)
my $static = fn_prefix($t);
my $sizevar;
- pidl $static . "size_t ndr_size_$t->{NAME}(int ret, const struct $t->{NAME} *r, int flags)\n";
+ pidl "size_t ndr_size_$t->{NAME}(const struct $t->{NAME} *r, int flags)\n";
pidl "{\n";
-
- if (util::has_property($t, "flag")) {
- pidl "\tflags = flags | " . $t->{PROPERTIES}->{flag} . ";\n";
+ if (my $flags = util::has_property($t, "flag")) {
+ pidl "\tflags |= $flags;\n";
}
-
- pidl "\tif(!r) return 0;\n";
-
- pidl "\tret = NDR_SIZE_ALIGN(ret, " . struct_alignment($t->{DATA}) . ", flags);\n";
-
- for my $e (@{$t->{DATA}->{ELEMENTS}}) {
- my $switch = "";
-
- if (util::has_property($e, "subcontext")) {
- pidl "\tret += $e->{PROPERTIES}->{subcontext}; /* Subcontext length */\n";
- }
-
- if (util::has_property($e, "switch_is")) {
- $switch = ", r->$e->{PROPERTIES}->{switch_is}";
- }
-
- if ($e->{POINTERS} > 0) {
- pidl "\tret = ndr_size_ptr(ret, &r->$e->{NAME}, flags); \n";
- } elsif (util::is_inline_array($e)) {
- $sizevar = find_size_var($e, util::array_size($e), "r->");
- check_null_pointer($sizevar);
- pidl "\t{\n";
- pidl "\t\tint i;\n";
- pidl "\t\tfor(i = 0; i < $sizevar; i++) {\n";
- pidl "\t\t\tret = ndr_size_$e->{TYPE}(ret, &r->" . $e->{NAME} . "[i], flags);\n";
- pidl "\t\t}\n";
- pidl "\t}\n";
- } else {
- pidl "\tret = ndr_size_$e->{TYPE}(ret, &r->$e->{NAME}$switch, flags); \n";
- }
- }
-
- # Add lengths of relative members
- for my $e (@{$t->{DATA}->{ELEMENTS}}) {
- next unless (util::has_property($e, "relative"));
-
- pidl "\tif (r->$e->{NAME}) {\n";
- pidl "\t\tret = ndr_size_$e->{TYPE}(ret, r->$e->{NAME}, flags); \n";
- pidl "\t}\n";
- }
-
- pidl "\treturn ret;\n";
+ pidl "\treturn ndr_size_struct(r, flags, (ndr_push_flags_fn_t)ndr_push_$t->{NAME});\n";
pidl "}\n\n";
}
@@ -1162,42 +1125,6 @@ sub ParseUnionPull($)
end_flags($e);
}
-#####################################################################
-# calculate size of ndr union
-
-sub ParseUnionNdrSize($)
-{
- my $t = shift;
- my $static = fn_prefix($t);
-
- pidl $static . "size_t ndr_size_$t->{NAME}(int ret, const union $t->{NAME} *data, uint16 level, int flags)\n";
- pidl "{\n";
- if (util::has_property($t, "flag")) {
- pidl "\tflags = flags | " . $t->{PROPERTIES}->{flag} . ";\n";
- }
- pidl "\tif(!data) return 0;\n\n";
-
- pidl "\tret = NDR_SIZE_ALIGN(ret, " . union_alignment($t->{DATA}) . ", flags);\n";
-
- pidl "\tswitch(level) {\n";
-
- for my $e (@{$t->{DATA}->{DATA}}) {
- if ($e->{TYPE} eq "UNION_ELEMENT") {
-
- if ($e->{CASE} eq "default") {
- pidl "\t\tdefault:";
- } else {
- pidl "\t\tcase $e->{CASE}:";
- }
-
- pidl " return ndr_size_$e->{DATA}->{TYPE}(ret, &data->$e->{DATA}->{NAME}, flags); \n";
-
- }
- }
- pidl "\t}\n";
- pidl "\treturn ret;\n";
- pidl "}\n\n";
-}
#####################################################################
# parse a type
@@ -1376,10 +1303,6 @@ sub ParseTypedefNdrSize($)
($t->{DATA}->{TYPE} eq "STRUCT") &&
ParseStructNdrSize($t);
-
- ($t->{DATA}->{TYPE} eq "UNION") &&
- ParseUnionNdrSize($t);
-
}
#####################################################################
@@ -1707,11 +1630,6 @@ sub ParseInterface($)
}
foreach my $d (@{$data}) {
- ($d->{TYPE} eq "TYPEDEF") &&
- ParseTypedefNdrSize($d);
- }
-
- foreach my $d (@{$data}) {
($d->{TYPE} eq "TYPEDEF") &&
ParseTypedefPush($d);
($d->{TYPE} eq "FUNCTION") &&
@@ -1734,6 +1652,11 @@ sub ParseInterface($)
}
}
+ foreach my $d (@{$data}) {
+ ($d->{TYPE} eq "TYPEDEF") &&
+ ParseTypedefNdrSize($d);
+ }
+
FunctionTable($interface);
}
diff --git a/source4/gtk/tools/gepdump.c b/source4/gtk/tools/gepdump.c
index ce606a6a6e..06e8c309cf 100644
--- a/source4/gtk/tools/gepdump.c
+++ b/source4/gtk/tools/gepdump.c
@@ -55,7 +55,7 @@ static void on_about1_activate (GtkMenuItem *menuitem, gpointer user_data)
gtk_widget_destroy(GTK_WIDGET(aboutwin));
}
-static const char *get_protocol_name(enum epm_protocols protocol)
+static const char *get_protocol_name(enum epm_protocol protocol)
{
switch (protocol) {
case EPM_PROTOCOL_UUID: return "UUID";
diff --git a/source4/librpc/idl/drsblobs.idl b/source4/librpc/idl/drsblobs.idl
index ff8be33478..51c4071a25 100644
--- a/source4/librpc/idl/drsblobs.idl
+++ b/source4/librpc/idl/drsblobs.idl
@@ -94,13 +94,13 @@ interface drsblobs {
typedef [gensize,flag(NDR_PAHEX)] struct {
/* this includes the 8 bytes of the repsFromToBlob header */
- [value(ndr_size_repsFromTo1(8, r, ndr->flags))] uint32 blobsize;
+ [value(ndr_size_repsFromTo1(r, ndr->flags)+8)] uint32 blobsize;
uint32 consecutive_sync_failures;
NTTIME_1sec last_success;
NTTIME_1sec last_attempt;
WERROR result_last_attempt;
[relative,length_is(other_info_length)] repsFromTo1OtherInfo *other_info;
- [value(ndr_size_repsFromTo1OtherInfo(0, r->other_info, ndr->flags))] uint32 other_info_length;
+ [value(ndr_size_repsFromTo1OtherInfo(r->other_info, ndr->flags))] uint32 other_info_length;
uint32 replica_flags;
uint8 schedule[84];
uint32 reserved;
diff --git a/source4/librpc/idl/epmapper.idl b/source4/librpc/idl/epmapper.idl
index e32b01a874..9e59f721bf 100644
--- a/source4/librpc/idl/epmapper.idl
+++ b/source4/librpc/idl/epmapper.idl
@@ -41,7 +41,7 @@ interface epmapper
uint16 version;
} epm_prot_uuid;
- typedef enum {
+ typedef [enum8bit] enum {
/* Level 4 and higher */
EPM_PROTOCOL_DNET_NSP = 0x04,
@@ -71,7 +71,7 @@ interface epmapper
EPM_PROTOCOL_HTTP = 0x1f,
EPM_PROTOCOL_UNIX_DS = 0x20, /* Unix domain socket */
EPM_PROTOCOL_NULL = 0x21
- } epm_protocols;
+ } epm_protocol;
typedef [nodiscriminant] union {
[case(EPM_PROTOCOL_UUID)] epm_prot_uuid uuid;
@@ -206,7 +206,7 @@ interface epmapper
} epm_rhs;
typedef struct {
- uint8 protocol;
+ epm_protocol protocol;
[switch_is(protocol)] epm_protocol_info info;
} epm_lhs;
@@ -226,7 +226,7 @@ interface epmapper
} epm_tower;
typedef struct {
- [value(ndr_size_epm_tower(0, &r->tower,ndr->flags))] uint32 tower_length;
+ [value(ndr_size_epm_tower(&r->tower, ndr->flags))] uint32 tower_length;
[subcontext(4)] epm_tower tower;
} epm_twr_t;
diff --git a/source4/librpc/idl/netlogon.idl b/source4/librpc/idl/netlogon.idl
index 582b21beff..ca867a265c 100644
--- a/source4/librpc/idl/netlogon.idl
+++ b/source4/librpc/idl/netlogon.idl
@@ -638,7 +638,7 @@ interface netlogon
} netr_DELTA_ID_UNION;
typedef struct {
- uint16 delta_type;
+ netr_DeltaEnum delta_type;
[switch_is(delta_type)] netr_DELTA_ID_UNION delta_id_union;
[switch_is(delta_type)] netr_DELTA_UNION delta_union;
} netr_DELTA_ENUM;
diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c
index 0543fbf0d3..44915bac5b 100644
--- a/source4/librpc/ndr/ndr.c
+++ b/source4/librpc/ndr/ndr.c
@@ -862,3 +862,24 @@ NTSTATUS ndr_push_struct_blob(DATA_BLOB *blob, TALLOC_CTX *mem_ctx, void *p,
return NT_STATUS_OK;
}
+
+/*
+ generic ndr_size_*() handler for structures
+*/
+size_t ndr_size_struct(const void *p, int flags, ndr_push_flags_fn_t push)
+{
+ struct ndr_push *ndr;
+ NTSTATUS status;
+ size_t ret;
+
+ ndr = ndr_push_init_ctx(NULL);
+ if (!ndr) return 0;
+ ndr->flags |= flags;
+ status = push(ndr, NDR_SCALARS|NDR_BUFFERS, discard_const(p));
+ if (!NT_STATUS_IS_OK(status)) {
+ return 0;
+ }
+ ret = ndr->offset;
+ talloc_free(ndr);
+ return ret;
+}
diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c
index e329297ab6..3fe2d87475 100644
--- a/source4/librpc/rpc/dcerpc.c
+++ b/source4/librpc/rpc/dcerpc.c
@@ -907,7 +907,7 @@ struct rpc_request *dcerpc_request_send(struct dcerpc_pipe *p,
if (object) {
pkt.u.request.object.object = *object;
pkt.pfc_flags |= DCERPC_PFC_FLAG_ORPC;
- chunk_size -= ndr_size_GUID(0,object,0);
+ chunk_size -= ndr_size_GUID(object,0);
}
DLIST_ADD(p->pending, req);
diff --git a/source4/librpc/rpc/dcerpc_util.c b/source4/librpc/rpc/dcerpc_util.c
index 8c454ab64f..4219b75392 100644
--- a/source4/librpc/rpc/dcerpc_util.c
+++ b/source4/librpc/rpc/dcerpc_util.c
@@ -137,7 +137,7 @@ static const struct {
const char *name;
enum dcerpc_transport_t transport;
int num_protocols;
- enum epm_protocols protseq[MAX_PROTSEQ];
+ enum epm_protocol protseq[MAX_PROTSEQ];
} transports[] = {
{ "ncacn_np", NCACN_NP, 3,
{ EPM_PROTOCOL_NCACN, EPM_PROTOCOL_SMB, EPM_PROTOCOL_NETBIOS }},
@@ -430,6 +430,10 @@ const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *flo
case EPM_PROTOCOL_NULL:
return NULL;
+
+ default:
+ DEBUG(0,("Unsupported lhs protocol %d\n", floor->lhs.protocol));
+ break;
}
return NULL;
@@ -514,6 +518,10 @@ static NTSTATUS dcerpc_floor_set_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor
case EPM_PROTOCOL_NULL:
return NT_STATUS_OK;
+
+ default:
+ DEBUG(0,("Unsupported lhs protocol %d\n", floor->lhs.protocol));
+ break;
}
return NT_STATUS_NOT_SUPPORTED;
@@ -602,7 +610,7 @@ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, struct epm_tower *tower,
NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx, struct dcerpc_binding *binding, struct epm_tower *tower)
{
- const enum epm_protocols *protseq = NULL;
+ const enum epm_protocol *protseq = NULL;
int num_protocols = -1, i;
NTSTATUS status;