diff options
author | Andrew Tridgell <tridge@samba.org> | 2003-11-11 04:04:36 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2003-11-11 04:04:36 +0000 |
commit | cecbf0cd8b99f7019a83def88baec889d6a06e6f (patch) | |
tree | 108181e24bac1a4fa10a55de40547d9177b488e8 | |
parent | a934f89549b3d23199d68b7dc3fc3ad16e86b9ad (diff) | |
download | samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.gz samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.tar.bz2 samba-cecbf0cd8b99f7019a83def88baec889d6a06e6f.zip |
automatically generate ndr_print_*() functions for every IDL
structure. This allows easy debug and test tool writing without having
to write functions that print every element of complex structures.
(This used to be commit 81d6181172e36c6fbae0907550a29511ce708574)
-rw-r--r-- | source4/build/pidl/parser.pm | 128 | ||||
-rw-r--r-- | source4/librpc/ndr/libndr.h | 15 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr.c | 61 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_basic.c | 45 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_lsa.c | 293 | ||||
-rw-r--r-- | source4/librpc/ndr/ndr_sec.c | 53 | ||||
-rw-r--r-- | source4/librpc/rpc/dcerpc.c | 2 | ||||
-rw-r--r-- | source4/torture/rpc/lsa.c | 82 |
8 files changed, 615 insertions, 64 deletions
diff --git a/source4/build/pidl/parser.pm b/source4/build/pidl/parser.pm index 1b09347052..19e6dc26f4 100644 --- a/source4/build/pidl/parser.pm +++ b/source4/build/pidl/parser.pm @@ -71,6 +71,21 @@ sub ParseArrayPush($$) } ##################################################################### +# print an array +sub ParseArrayPrint($$) +{ + my $e = shift; + my $var_prefix = shift; + my $size = find_size_var($e, util::array_size($e)); + + if (util::is_scalar_type($e->{TYPE})) { + $res .= "\t\tndr_print_array_$e->{TYPE}(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, $size);\n"; + } else { + $res .= "\t\tndr_print_array(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME}, sizeof($var_prefix$e->{NAME}\[0]), $size, (ndr_print_fn_t)ndr_print_$e->{TYPE});\n"; + } +} + +##################################################################### # parse an array - pull side sub ParseArrayPull($$) { @@ -110,6 +125,30 @@ sub ParseElementPushScalar($$$) } ##################################################################### +# print scalars in a structure element +sub ParseElementPrintScalar($$) +{ + my($e) = shift; + my($var_prefix) = shift; + my $cprefix = util::c_push_prefix($e); + + if (util::has_property($e, "struct_len")) { + return; + } + + if (defined $e->{VALUE}) { + $res .= "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $e->{VALUE});\n"; + } elsif (util::need_wire_pointer($e)) { + $res .= "\tndr_print_ptr(ndr, \"$e->{NAME}\", $var_prefix$e->{NAME});\n"; + $res .= "\tndr->depth++;\n"; + ParseElementPrintBuffer($e, "r->"); + $res .= "\tndr->depth--;\n"; + } else { + $res .= "\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n"; + } +} + +##################################################################### # parse scalars in a structure element - pull size sub ParseElementPullSwitch($$$$) { @@ -186,6 +225,33 @@ sub ParseElementPushBuffer($$) } } +##################################################################### +# print buffers in a structure element +sub ParseElementPrintBuffer($$) +{ + my($e) = shift; + my($var_prefix) = shift; + my $cprefix = util::c_push_prefix($e); + + if (util::is_pure_scalar($e)) { + return; + } + + if (util::need_wire_pointer($e)) { + $res .= "\tif ($var_prefix$e->{NAME}) {\n"; + } + + if (util::array_size($e)) { + ParseArrayPrint($e, "r->"); + } else { + $res .= "\t\tndr_print_$e->{TYPE}(ndr, \"$e->{NAME}\", $cprefix$var_prefix$e->{NAME});\n"; + } + + if (util::need_wire_pointer($e)) { + $res .= "\t}\n"; + } +} + ##################################################################### # parse buffers in a structure element - pull side @@ -272,6 +338,25 @@ sub ParseStructPush($) } ##################################################################### +# generate a struct print function +sub ParseStructPrint($) +{ + my($struct) = shift; + + $res .= "\tndr_print_struct(ndr, name);\n"; + + if (! defined $struct->{ELEMENTS}) { + return; + } + + $res .= "\tndr->depth++;\n"; + foreach my $e (@{$struct->{ELEMENTS}}) { + ParseElementPrintScalar($e, "r->"); + } + $res .= "\tndr->depth--;\n"; +} + +##################################################################### # parse a struct - pull side sub ParseStructPull($) { @@ -341,6 +426,14 @@ sub ParseUnionPush($) } ##################################################################### +# print a union +sub ParseUnionPrint($) +{ + my $e = shift; + print "WARNING! union print not done\n"; +} + +##################################################################### # parse a union - pull side sub ParseUnionPull($) { @@ -385,6 +478,20 @@ sub ParseTypePush($) } ##################################################################### +# generate a print function for a type +sub ParseTypePrint($) +{ + my($data) = shift; + + if (ref($data) eq "HASH") { + ($data->{TYPE} eq "STRUCT") && + ParseStructPrint($data); + ($data->{TYPE} eq "UNION") && + ParseUnionPrint($data); + } +} + +##################################################################### # parse a type sub ParseTypePull($) { @@ -456,6 +563,26 @@ sub ParseTypedefPull($) } +##################################################################### +# parse a typedef - push side +sub ParseTypedefPrint($) +{ + my($e) = shift; + + if ($e->{DATA}->{TYPE} eq "STRUCT") { + $res .= "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, struct $e->{NAME} *r)"; + $res .= "\n{\n"; + ParseTypePrint($e->{DATA}); + $res .= "}\n\n"; + } + + if ($e->{DATA}->{TYPE} eq "UNION") { + $res .= "void ndr_print_$e->{NAME}(struct ndr_print *ndr, const char *name, uint16 level, union $e->{NAME} *r)"; + $res .= "\n{\n"; + ParseTypePrint($e->{DATA}); + $res .= "}\n\n"; + } +} ##################################################################### @@ -537,6 +664,7 @@ sub ParseTypedef($) my($e) = shift; ParseTypedefPush($e); ParseTypedefPull($e); + ParseTypedefPrint($e); } ##################################################################### diff --git a/source4/librpc/ndr/libndr.h b/source4/librpc/ndr/libndr.h index 870500d169..24ae09f538 100644 --- a/source4/librpc/ndr/libndr.h +++ b/source4/librpc/ndr/libndr.h @@ -58,9 +58,23 @@ struct ndr_push_save { uint32 offset; }; + +/* structure passed to functions that print IDL structures */ +struct ndr_print { + uint32 flags; /* LIBNDR_FLAG_* */ + TALLOC_CTX *mem_ctx; + uint32 depth; + void (*print)(struct ndr_print *, const char *, ...); +}; + #define LIBNDR_FLAG_BIGENDIAN 1 +/* useful macro for debugging */ +#define NDR_PRINT_DEBUG(type, p) ndr_print_debug((ndr_print_fn_t)ndr_print_ ##type, #p, p) + + + /* flags passed to control parse flow */ @@ -97,6 +111,7 @@ typedef NTSTATUS (*ndr_pull_fn_t)(struct ndr_pull *, void *); typedef NTSTATUS (*ndr_push_flags_fn_t)(struct ndr_push *, int ndr_flags, void *); typedef NTSTATUS (*ndr_pull_flags_fn_t)(struct ndr_pull *, int ndr_flags, void *); +typedef void (*ndr_print_fn_t)(struct ndr_print *, const char *, void *); /* now pull in the individual parsers */ #include "librpc/ndr/ndr_sec.h" diff --git a/source4/librpc/ndr/ndr.c b/source4/librpc/ndr/ndr.c index 2ab78d3d09..f7aead014c 100644 --- a/source4/librpc/ndr/ndr.c +++ b/source4/librpc/ndr/ndr.c @@ -243,3 +243,64 @@ buffers: done: return NT_STATUS_OK; } + + +/* + print a generic array +*/ +void ndr_print_array(struct ndr_print *ndr, const char *name, void *base, + size_t elsize, uint32 count, + void (*print_fn)(struct ndr_print *, const char *, void *)) +{ + int i; + char *p = base; + ndr->print(ndr, "%s: ARRAY(%d)", name, count); + ndr->depth++; + for (i=0;i<count;i++) { + char *idx=NULL; + asprintf(&idx, "[%d]", i); + if (idx) { + print_fn(ndr, idx, p); + free(idx); + } + p += elsize; + } + ndr->depth--; +} + + + +static void ndr_print_debug_helper(struct ndr_print *ndr, const char *format, ...) +{ + va_list ap; + char *s = NULL; + int i; + + va_start(ap, format); + vasprintf(&s, format, ap); + va_end(ap); + + for (i=0;i<ndr->depth;i++) { + DEBUG(0,(" ")); + } + + DEBUG(0,("%s\n", s)); + free(s); +} + +/* + a useful helper function for printing idl structures via DEBUG() +*/ +void ndr_print_debug(void (*fn)(struct ndr_print *, const char *, void *), + const char *name, + void *ptr) +{ + struct ndr_print ndr; + + ndr.mem_ctx = talloc_init("ndr_print_debug"); + if (!ndr.mem_ctx) return; + ndr.print = ndr_print_debug_helper; + ndr.depth = 0; + fn(&ndr, name, ptr); + talloc_destroy(ndr.mem_ctx); +} diff --git a/source4/librpc/ndr/ndr_basic.c b/source4/librpc/ndr/ndr_basic.c index b6c5a0cd53..11f3bb5e23 100644 --- a/source4/librpc/ndr/ndr_basic.c +++ b/source4/librpc/ndr/ndr_basic.c @@ -373,3 +373,48 @@ NTSTATUS ndr_pull_NTTIME(struct ndr_pull *ndr, NTTIME *t) NDR_CHECK(ndr_pull_uint32(ndr, &t->high)); return NT_STATUS_OK; } + + +void ndr_print_struct(struct ndr_print *ndr, const char *name) +{ + ndr->print(ndr, "%s:", name); +} + +void ndr_print_uint8(struct ndr_print *ndr, const char *name, uint8 v) +{ + ndr->print(ndr, "%-25s: 0x%02x (%u)", name, v, v); +} + +void ndr_print_uint16(struct ndr_print *ndr, const char *name, uint16 v) +{ + ndr->print(ndr, "%-25s: 0x%04x (%u)", name, v, v); +} + +void ndr_print_uint32(struct ndr_print *ndr, const char *name, uint32 v) +{ + ndr->print(ndr, "%-25s: 0x%08x (%u)", name, v, v); +} + +void ndr_print_ptr(struct ndr_print *ndr, const char *name, const void *p) +{ + if (p) { + ndr->print(ndr, "%-25s: *", name); + } else { + ndr->print(ndr, "%-25s: NULL", name); + } +} + +void ndr_print_unistr_noterm(struct ndr_print *ndr, const char *name, const char *s) +{ + ndr->print(ndr, "%-25s: '%s'", name, s); +} + +void ndr_print_unistr(struct ndr_print *ndr, const char *name, const char *s) +{ + ndr->print(ndr, "%-25s: '%s'", name, s); +} + +void ndr_print_NTTIME(struct ndr_print *ndr, const char *name, NTTIME t) +{ + ndr->print(ndr, "%-25s: %s", name, nt_time_string(ndr->mem_ctx, &t)); +} diff --git a/source4/librpc/ndr/ndr_lsa.c b/source4/librpc/ndr/ndr_lsa.c index 2a2d5a5c03..89c59f7c00 100644 --- a/source4/librpc/ndr/ndr_lsa.c +++ b/source4/librpc/ndr/ndr_lsa.c @@ -67,6 +67,21 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_Name(struct ndr_print *ndr, const char *name, struct lsa_Name *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint16(ndr, "name_len", r->name_len); + ndr_print_uint16(ndr, "name_size", r->name_size); + ndr_print_ptr(ndr, "name", r->name); + ndr->depth++; + if (r->name) { + ndr_print_unistr_noterm(ndr, "name", r->name); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_PrivEntry(struct ndr_pull *ndr, int ndr_flags, struct lsa_PrivEntry *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -80,6 +95,16 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_PrivEntry(struct ndr_print *ndr, const char *name, struct lsa_PrivEntry *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_lsa_Name(ndr, "name", &r->name); + ndr_print_uint32(ndr, "luid_low", r->luid_low); + ndr_print_uint32(ndr, "luid_high", r->luid_high); + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_PrivArray(struct ndr_pull *ndr, int ndr_flags, struct lsa_PrivArray *r) { uint32 _ptr_privs; @@ -101,6 +126,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_PrivArray(struct ndr_print *ndr, const char *name, struct lsa_PrivArray *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "privs", r->privs); + ndr->depth++; + if (r->privs) { + ndr_print_array(ndr, "privs", r->privs, sizeof(r->privs[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_PrivEntry); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_EnumPrivs(struct ndr_push *ndr, struct lsa_EnumPrivs *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -179,6 +218,16 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_QosInfo(struct ndr_print *ndr, const char *name, struct lsa_QosInfo *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint16(ndr, "impersonation_level", r->impersonation_level); + ndr_print_uint8(ndr, "context_mode", r->context_mode); + ndr_print_uint8(ndr, "effective_only", r->effective_only); + ndr->depth--; +} + static NTSTATUS ndr_push_lsa_ObjectAttribute(struct ndr_push *ndr, int ndr_flags, struct lsa_ObjectAttribute *r) { struct ndr_push_save _save1, _save2, _save3; @@ -214,6 +263,38 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_ObjectAttribute(struct ndr_print *ndr, const char *name, struct lsa_ObjectAttribute *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_ptr(ndr, "root_dir", r->root_dir); + ndr->depth++; + if (r->root_dir) { + ndr_print_uint8(ndr, "root_dir", *r->root_dir); + } + ndr->depth--; + ndr_print_ptr(ndr, "object_name", r->object_name); + ndr->depth++; + if (r->object_name) { + ndr_print_unistr(ndr, "object_name", r->object_name); + } + ndr->depth--; + ndr_print_uint32(ndr, "attributes", r->attributes); + ndr_print_ptr(ndr, "sec_desc", r->sec_desc); + ndr->depth++; + if (r->sec_desc) { + ndr_print_security_descriptor(ndr, "sec_desc", r->sec_desc); + } + ndr->depth--; + ndr_print_ptr(ndr, "sec_qos", r->sec_qos); + ndr->depth++; + if (r->sec_qos) { + ndr_print_lsa_QosInfo(ndr, "sec_qos", r->sec_qos); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_OpenPolicy(struct ndr_push *ndr, struct lsa_OpenPolicy *r) { NDR_CHECK(ndr_push_ptr(ndr, r->in.system_name)); @@ -250,6 +331,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_AuditLogInfo(struct ndr_print *ndr, const char *name, struct lsa_AuditLogInfo *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "percent_full", r->percent_full); + ndr_print_uint32(ndr, "log_size", r->log_size); + ndr_print_NTTIME(ndr, "retention_time", r->retention_time); + ndr_print_uint8(ndr, "shutdown_in_progress", r->shutdown_in_progress); + ndr_print_NTTIME(ndr, "time_to_shutdown", r->time_to_shutdown); + ndr_print_uint32(ndr, "next_audit_record", r->next_audit_record); + ndr_print_uint32(ndr, "unknown", r->unknown); + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_AuditEventsInfo(struct ndr_pull *ndr, int ndr_flags, struct lsa_AuditEventsInfo *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -260,6 +355,14 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_AuditEventsInfo(struct ndr_print *ndr, const char *name, struct lsa_AuditEventsInfo *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "auditing_mode", r->auditing_mode); + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_PolicyInformation(struct ndr_pull *ndr, int ndr_flags, uint16 *level, union lsa_PolicyInformation *r) { NDR_CHECK(ndr_pull_uint16(ndr, level)); @@ -294,6 +397,10 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_PolicyInformation(struct ndr_print *ndr, const char *name, uint16 level, union lsa_PolicyInformation *r) +{ +} + NTSTATUS ndr_push_lsa_QueryInfoPolicy(struct ndr_push *ndr, struct lsa_QueryInfoPolicy *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -393,6 +500,19 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_SidPtr(struct ndr_print *ndr, const char *name, struct lsa_SidPtr *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_ptr(ndr, "sid", r->sid); + ndr->depth++; + if (r->sid) { + ndr_print_dom_sid2(ndr, "sid", r->sid); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_push_lsa_SidArray(struct ndr_push *ndr, int ndr_flags, struct lsa_SidArray *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -428,6 +548,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_SidArray(struct ndr_print *ndr, const char *name, struct lsa_SidArray *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "num_sids", r->num_sids); + ndr_print_ptr(ndr, "sids", r->sids); + ndr->depth++; + if (r->sids) { + ndr_print_array(ndr, "sids", r->sids, sizeof(r->sids[0]), r->num_sids, (ndr_print_fn_t)ndr_print_lsa_SidPtr); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_EnumAccounts(struct ndr_push *ndr, struct lsa_EnumAccounts *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -480,6 +614,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_DomainInformation(struct ndr_print *ndr, const char *name, struct lsa_DomainInformation *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_lsa_Name(ndr, "name", &r->name); + ndr_print_ptr(ndr, "sid", r->sid); + ndr->depth++; + if (r->sid) { + ndr_print_dom_sid2(ndr, "sid", r->sid); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_DomainList(struct ndr_pull *ndr, int ndr_flags, struct lsa_DomainList *r) { uint32 _ptr_domains; @@ -501,6 +649,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_DomainList(struct ndr_print *ndr, const char *name, struct lsa_DomainList *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "domains", r->domains); + ndr->depth++; + if (r->domains) { + ndr_print_array(ndr, "domains", r->domains, sizeof(r->domains[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_DomainInformation); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_EnumTrustDom(struct ndr_push *ndr, struct lsa_EnumTrustDom *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -543,6 +705,16 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_TranslatedSid(struct ndr_print *ndr, const char *name, struct lsa_TranslatedSid *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint16(ndr, "sid_type", r->sid_type); + ndr_print_uint32(ndr, "rid", r->rid); + ndr_print_uint32(ndr, "sid_index", r->sid_index); + ndr->depth--; +} + static NTSTATUS ndr_push_lsa_TransSidArray(struct ndr_push *ndr, int ndr_flags, struct lsa_TransSidArray *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -578,6 +750,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_TransSidArray(struct ndr_print *ndr, const char *name, struct lsa_TransSidArray *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "sids", r->sids); + ndr->depth++; + if (r->sids) { + ndr_print_array(ndr, "sids", r->sids, sizeof(r->sids[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_TranslatedSid); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_TrustInformation(struct ndr_pull *ndr, int ndr_flags, struct lsa_TrustInformation *r) { uint32 _ptr_sid; @@ -599,6 +785,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_TrustInformation(struct ndr_print *ndr, const char *name, struct lsa_TrustInformation *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_lsa_Name(ndr, "name", &r->name); + ndr_print_ptr(ndr, "sid", r->sid); + ndr->depth++; + if (r->sid) { + ndr_print_dom_sid2(ndr, "sid", r->sid); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_RefDomainList(struct ndr_pull *ndr, int ndr_flags, struct lsa_RefDomainList *r) { uint32 _ptr_domains; @@ -621,6 +821,21 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_RefDomainList(struct ndr_print *ndr, const char *name, struct lsa_RefDomainList *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "domains", r->domains); + ndr->depth++; + if (r->domains) { + ndr_print_array(ndr, "domains", r->domains, sizeof(r->domains[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_TrustInformation); + } + ndr->depth--; + ndr_print_uint32(ndr, "max_count", r->max_count); + ndr->depth--; +} + NTSTATUS ndr_push_lsa_LookupNames(struct ndr_push *ndr, struct lsa_LookupNames *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -681,6 +896,16 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_TranslatedName(struct ndr_print *ndr, const char *name, struct lsa_TranslatedName *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint16(ndr, "sid_type", r->sid_type); + ndr_print_lsa_Name(ndr, "name", &r->name); + ndr_print_uint32(ndr, "sid_index", r->sid_index); + ndr->depth--; +} + static NTSTATUS ndr_push_lsa_TransNameArray(struct ndr_push *ndr, int ndr_flags, struct lsa_TransNameArray *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -716,6 +941,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_TransNameArray(struct ndr_print *ndr, const char *name, struct lsa_TransNameArray *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "names", r->names); + ndr->depth++; + if (r->names) { + ndr_print_array(ndr, "names", r->names, sizeof(r->names[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_TranslatedName); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_LookupSids(struct ndr_push *ndr, struct lsa_LookupSids *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -787,6 +1026,15 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_LUID(struct ndr_print *ndr, const char *name, struct lsa_LUID *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "low", r->low); + ndr_print_uint32(ndr, "high", r->high); + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_LUIDAttribute(struct ndr_pull *ndr, int ndr_flags, struct lsa_LUIDAttribute *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -799,6 +1047,15 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_LUIDAttribute(struct ndr_print *ndr, const char *name, struct lsa_LUIDAttribute *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_lsa_LUID(ndr, "luid", &r->luid); + ndr_print_uint32(ndr, "attribute", r->attribute); + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_PrivilegeSet(struct ndr_pull *ndr, int ndr_flags, struct lsa_PrivilegeSet *r) { if (!(ndr_flags & NDR_SCALARS)) goto buffers; @@ -811,6 +1068,15 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_PrivilegeSet(struct ndr_print *ndr, const char *name, struct lsa_PrivilegeSet *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_lsa_LUIDAttribute(ndr, "set", r->set); + ndr->depth--; +} + NTSTATUS ndr_push_lsa_EnumPrivsAccount(struct ndr_push *ndr, struct lsa_EnumPrivsAccount *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); @@ -1070,6 +1336,19 @@ NTSTATUS ndr_pull_ENUMACCTWITHRIGHT(struct ndr_pull *ndr, struct ENUMACCTWITHRIG return NT_STATUS_OK; } +void ndr_print_lsa_RightAttribute(struct ndr_print *ndr, const char *name, struct lsa_RightAttribute *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_ptr(ndr, "name", r->name); + ndr->depth++; + if (r->name) { + ndr_print_unistr(ndr, "name", r->name); + } + ndr->depth--; + ndr->depth--; +} + static NTSTATUS ndr_pull_lsa_RightSet(struct ndr_pull *ndr, int ndr_flags, struct lsa_RightSet *r) { uint32 _ptr_names; @@ -1091,6 +1370,20 @@ done: return NT_STATUS_OK; } +void ndr_print_lsa_RightSet(struct ndr_print *ndr, const char *name, struct lsa_RightSet *r) +{ + ndr_print_struct(ndr, name); + ndr->depth++; + ndr_print_uint32(ndr, "count", r->count); + ndr_print_ptr(ndr, "names", r->names); + ndr->depth++; + if (r->names) { + ndr_print_array(ndr, "names", r->names, sizeof(r->names[0]), r->count, (ndr_print_fn_t)ndr_print_lsa_Name); + } + ndr->depth--; + ndr->depth--; +} + NTSTATUS ndr_push_lsa_EnumAccountRights(struct ndr_push *ndr, struct lsa_EnumAccountRights *r) { NDR_CHECK(ndr_push_policy_handle(ndr, r->in.handle)); diff --git a/source4/librpc/ndr/ndr_sec.c b/source4/librpc/ndr/ndr_sec.c index b83bf87771..98f40e0ea3 100644 --- a/source4/librpc/ndr/ndr_sec.c +++ b/source4/librpc/ndr/ndr_sec.c @@ -314,3 +314,56 @@ NTSTATUS ndr_push_security_descriptor(struct ndr_push *ndr, return NT_STATUS_OK; } + + +/* + print a dom_sid +*/ +void ndr_print_dom_sid(struct ndr_print *ndr, const char *name, struct dom_sid *sid) +{ + int i, ofs, maxlen; + uint32 ia; + char *ret; + + if (!sid) { + ndr->print(ndr, "%-25s: (NULL SID)", name); + return; + } + + maxlen = sid->num_auths * 11 + 25; + ret = talloc(ndr->mem_ctx, maxlen); + if (!ret) return; + + ia = (sid->id_auth[5]) + + (sid->id_auth[4] << 8 ) + + (sid->id_auth[3] << 16) + + (sid->id_auth[2] << 24); + + ofs = snprintf(ret, maxlen, "S-%u-%lu", + (unsigned int)sid->sid_rev_num, (unsigned long)ia); + + for (i = 0; i < sid->num_auths; i++) { + ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]); + } + + ndr->print(ndr, "%-25s: %s", name, ret); +} + +void ndr_print_dom_sid2(struct ndr_print *ndr, const char *name, struct dom_sid2 *sid) +{ + ndr_print_dom_sid(ndr, name, sid); +} + +/* + print a security descriptor +*/ +void ndr_print_security_descriptor(struct ndr_print *ndr, + const char *name, + struct security_descriptor *sd) +{ + ndr->print(ndr->depth, "%-25s: ndr_print_security_descriptor not implemented", + name); +} + + + diff --git a/source4/librpc/rpc/dcerpc.c b/source4/librpc/rpc/dcerpc.c index 97aa466e3a..3018b8621b 100644 --- a/source4/librpc/rpc/dcerpc.c +++ b/source4/librpc/rpc/dcerpc.c @@ -808,3 +808,5 @@ failed: ndr_push_free(push); return status; } + + diff --git a/source4/torture/rpc/lsa.c b/source4/torture/rpc/lsa.c index ca8c25bdd6..ece5212ee6 100644 --- a/source4/torture/rpc/lsa.c +++ b/source4/torture/rpc/lsa.c @@ -21,6 +21,7 @@ #include "includes.h" + /* these really shouldn't be here .... */ @@ -189,23 +190,12 @@ static BOOL test_LookupNames(struct dcerpc_pipe *p, } if (r.out.domains) { - printf("lookup gave %d domains (max_count=%d)\n", - r.out.domains->count, - r.out.domains->max_count); - for (i=0;i<r.out.domains->count;i++) { - printf("name='%s' sid=%s\n", - r.out.domains->domains[i].name.name, - lsa_sid_string_talloc(mem_ctx, r.out.domains->domains[i].sid)); - } + NDR_PRINT_DEBUG(lsa_RefDomainList, r.out.domains); } printf("lookup gave %d sids (sids.count=%d)\n", count, sids.count); - for (i=0;i<sids.count;i++) { - printf("sid_type=%d rid=%d sid_index=%d\n", - sids.sids[i].sid_type, - sids.sids[i].rid, - sids.sids[i].sid_index); - } + + NDR_PRINT_DEBUG(lsa_TransSidArray, r.out.sids); printf("\n"); @@ -244,23 +234,10 @@ static BOOL test_LookupSids(struct dcerpc_pipe *p, } if (r.out.domains) { - printf("lookup gave %d domains (max_count=%d)\n", - r.out.domains->count, - r.out.domains->max_count); - for (i=0;i<r.out.domains->count;i++) { - printf("name='%s' sid=%s\n", - r.out.domains->domains[i].name.name, - lsa_sid_string_talloc(mem_ctx, r.out.domains->domains[i].sid)); - } + NDR_PRINT_DEBUG(lsa_RefDomainList, r.out.domains); } - printf("lookup gave %d names (names.count=%d)\n", count, names.count); - for (i=0;i<names.count;i++) { - printf("type=%d sid_index=%d name='%s'\n", - names.names[i].sid_type, - names.names[i].sid_index, - names.names[i].name.name); - } + NDR_PRINT_DEBUG(lsa_TransNameArray, r.out.names); printf("\n"); @@ -289,7 +266,7 @@ static BOOL test_LookupPrivName(struct dcerpc_pipe *p, return False; } - printf(" '%s'\n", r.out.name->name); + NDR_PRINT_DEBUG(lsa_Name, r.out.name); return True; } @@ -316,15 +293,11 @@ static BOOL test_EnumPrivsAccount(struct dcerpc_pipe *p, r.out.privs?r.out.privs->count:0, r.out.unknown); if (r.out.privs) { - struct lsa_PrivilegeSet *privs = r.out.privs; int i; - for (i=0;i<privs->count;i++) { - printf("luid=%08x-%08x attribute=0x%08x ", - privs->set[i].luid.low, - privs->set[i].luid.high, - privs->set[i].attribute); + NDR_PRINT_DEBUG(lsa_PrivilegeSet, r.out.privs); + for (i=0;i<r.out.privs->count;i++) { test_LookupPrivName(p, mem_ctx, handle, - &privs->set[i].luid); + &r.out.privs->set[i].luid); } } @@ -353,10 +326,7 @@ static BOOL test_EnumAccountRights(struct dcerpc_pipe *p, return False; } - printf("received %d rights\n", rights.count); - for (i=0;i<rights.count;i++) { - printf("\t'%s'\n", rights.names[i].name); - } + NDR_PRINT_DEBUG(lsa_RightSet, r.out.rights); return True; } @@ -417,9 +387,7 @@ static BOOL test_EnumAccounts(struct dcerpc_pipe *p, printf("Got %d sids resume_handle=%u\n", sids1.num_sids, resume_handle); - for (i=0;i<sids1.num_sids;i++) { - printf("%s\n", lsa_sid_string_talloc(mem_ctx, sids1.sids[i].sid)); - } + NDR_PRINT_DEBUG(lsa_SidArray, r.out.sids); if (!test_LookupSids(p, mem_ctx, handle, &sids1)) { return False; @@ -447,6 +415,8 @@ static BOOL test_EnumAccounts(struct dcerpc_pipe *p, return False; } + NDR_PRINT_DEBUG(lsa_SidArray, r.out.sids); + if (sids2.num_sids != 1) { printf("Returned wrong number of entries (%d)\n", sids2.num_sids); return False; @@ -483,12 +453,7 @@ static BOOL test_EnumPrivs(struct dcerpc_pipe *p, printf("Got %d privs resume_handle=%u\n", privs1.count, resume_handle); - for (i=0;i<privs1.count;i++) { - printf("luid=%08x-%08x '%s'\n", - privs1.privs[i].luid_low, - privs1.privs[i].luid_high, - privs1.privs[i].name.name); - } + NDR_PRINT_DEBUG(lsa_PrivArray, r.out.privs); return True; } @@ -519,11 +484,8 @@ static BOOL test_EnumTrustDom(struct dcerpc_pipe *p, } printf("lookup gave %d domains\n", domains.count); - for (i=0;i<r.out.domains->count;i++) { - printf("name='%s' sid=%s\n", - domains.domains[i].name.name, - lsa_sid_string_talloc(mem_ctx, domains.domains[i].sid)); - } + + NDR_PRINT_DEBUG(lsa_DomainList, r.out.domains); return True; } @@ -546,15 +508,7 @@ static BOOL test_QueryInfoPolicy(struct dcerpc_pipe *p, return False; } - { - struct lsa_AuditLogInfo *u = &r.out.info->audit_log; - printf("percent_full=%d log_size=%d retention_time=%s\n", - u->percent_full, u->log_size, - nt_time_string(mem_ctx, &u->retention_time)); - printf("shutdown_in_progress=%d time_to_shutdown=%s next_audit_record=%d unknown=0x%x\n", - u->shutdown_in_progress, nt_time_string(mem_ctx, &u->time_to_shutdown), - u->next_audit_record, u->unknown); - } + NDR_PRINT_DEBUG(lsa_AuditLogInfo, &r.out.info->audit_log); return True; } |