automatically generate ndr_print_*() functions for every IDL
authorAndrew Tridgell <tridge@samba.org>
Tue, 11 Nov 2003 04:04:36 +0000 (04:04 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 11 Nov 2003 04:04:36 +0000 (04:04 +0000)
structure. This allows easy debug and test tool writing without having
to write functions that print every element of complex structures.

source/build/pidl/parser.pm
source/librpc/ndr/libndr.h
source/librpc/ndr/ndr.c
source/librpc/ndr/ndr_basic.c
source/librpc/ndr/ndr_lsa.c
source/librpc/ndr/ndr_sec.c
source/librpc/rpc/dcerpc.c
source/torture/rpc/lsa.c

index 1b0934705245039ace5fc158c895d2461b2267c9..19e6dc26f4e74dbc99e00d88f15e3c247384191f 100644 (file)
@@ -70,6 +70,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($$)
@@ -109,6 +124,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
@@ -271,6 +337,25 @@ sub ParseStructPush($)
        $res .= "done:\n";
 }
 
+#####################################################################
+# 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($)
@@ -340,6 +425,14 @@ sub ParseUnionPush($)
        print "WARNING! union push  not done\n";        
 }
 
+#####################################################################
+# print a union
+sub ParseUnionPrint($)
+{
+       my $e = shift;
+       print "WARNING! union print not done\n";        
+}
+
 #####################################################################
 # parse a union - pull side
 sub ParseUnionPull($)
@@ -384,6 +477,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);
 }
 
 #####################################################################
index 870500d169c0e9163f230abdc37f02574d58a95d..24ae09f5380fd4196fd86b71da88e836ec6976b0 100644 (file)
@@ -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"
index 2ab78d3d091796c5bcf2bbca297695dabbb03392..f7aead014c7370f7272e05531c05ccf6df403e91 100644 (file)
@@ -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);
+}
index b6c5a0cd53b00efb2fdce8d9d91cbc96b9075661..11f3bb5e23509e07a3aae18acc21fe19161b1711 100644 (file)
@@ -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));
+}
index 2a2d5a5c035b1791242e7ffbe7a0c4e6a3818c1b..89c59f7c00512057440897aa4ebff1e3fbe96ff7 100644 (file)
@@ -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));
index b83bf87771c472d4661039d3596b8344473f161b..98f40e0ea39432e5dd212ed9d438089a030b4523 100644 (file)
@@ -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);
+}
+
+
+
index 97aa466e3a61216130f3eb5e7ff218505c410b4e..3018b8621baf012631d76aab90ff061a65bfb5de 100644 (file)
@@ -808,3 +808,5 @@ failed:
        ndr_push_free(push);
        return status;
 }
+
+
index ca8c25bdd6c1a9425ee1ccb5eb440642f4ae5c01..ece5212ee6ac30544462dfa596bcfcd32498e258 100644 (file)
@@ -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;
 }