r11105: Warn if conformant arrays are not at the end of a struct
authorJelmer Vernooij <jelmer@samba.org>
Sun, 16 Oct 2005 23:47:09 +0000 (23:47 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:44:50 +0000 (13:44 -0500)
Support conformant [string] arrays
Eliminate utf8string

This breaks xattr binary compatibility with previous versions - is that a
problem?

source/librpc/idl/drsuapi.idl
source/librpc/idl/unixinfo.idl
source/librpc/idl/xattr.idl
source/librpc/ndr/ndr_string.c
source/pidl/lib/Parse/Pidl/NDR.pm
source/pidl/lib/Parse/Pidl/Samba/NDR/Parser.pm

index f900af9ce2a3457b885f6125847c6adc11a72f72..971167458151fd9d001765523e973f20f3bd18d9 100644 (file)
@@ -430,7 +430,7 @@ interface drsuapi
        /* UnicodeString values */
        typedef struct {
                [range(0,10485760)] uint32 length;
-               [subcontext(4)] nstring *string;
+               [size_is(length),charset(UTF16)] uint16 *string;
        } drsuapi_DsAttributeValueUnicodeString;
 
        typedef struct {
index e7403688752822132de0d894d6154fb536c1d5ff..ac75430532c847640d9999557a90200ef9620272 100644 (file)
            [out]       dom_sid *sid
            );
 
-        typedef struct {
-                NTSTATUS status;
-                utf8string homedir;
-               utf8string shell;
+    typedef struct {
+       NTSTATUS status;
+        [string,charset(UTF8)] uint8 *homedir;
+               [string,charset(UTF8)] uint8 *shell;
        } unixinfo_GetPWUidInfo;
 
        /******************/
index 48d0c76183025a40cbca03a20ad14ff55330459d..4cb1f75393f051b96b2abfb6e1bdee8bc34b1b02 100644 (file)
@@ -41,7 +41,7 @@ interface xattr
                NTTIME     create_time;
                NTTIME     change_time;
                NTTIME     write_time; /* only used when sticky write time is set */
-               utf8string name;       /* will be used for case-insensitive speedup */
+               [string,charset(UTF8)] uint8 *name;       /* will be used for case-insensitive speedup */
        } xattr_DosInfo2;
 
        typedef [switch_type(uint16)] union {
@@ -59,7 +59,7 @@ interface xattr
        const char *XATTR_DOSEAS_NAME = "user.DosEAs";
 
        typedef struct {
-               utf8string name;
+               [string,charset(UTF8)] uint8 *name;
                DATA_BLOB value;
        } xattr_EA;
 
@@ -85,7 +85,7 @@ interface xattr
                uint32     flags;
                udlong     size;
                udlong     alloc_size;
-               utf8string name;
+               [charset(UTF8),string] uint8 name[];
        } xattr_DosStream;
 
        typedef [public] struct {
index ce035be5dc06b2fbb720f34b2c88f9a7ecd9f266..684bc047c015ffa4257bd17fb942fa02707101e7 100644 (file)
@@ -675,3 +675,10 @@ NTSTATUS ndr_push_charset(struct ndr_push *ndr, int ndr_flags, const char *var,
 
        return NT_STATUS_OK;
 }
+
+/* Return number of elements in a string in the specified charset */
+uint32_t ndr_charset_length(const void *var, int chset)
+{
+       /* FIXME: Treat special chars special here, taking chset into account */
+       return strlen(var);
+}
index 73104758dd07d6754d3c61d49f821a82c4ebb417..d0b6708bf63302b93d01aba01e81054bcbc456ce 100644 (file)
@@ -373,7 +373,12 @@ sub ParseStruct($)
 
        foreach my $x (@{$struct->{ELEMENTS}}) 
        {
-               push @elements, ParseElement($x);
+               my $e = ParseElement($x);
+               if ($x != $struct->{ELEMENTS}[-1] and 
+                       $e->{LEVELS}[0]->{IS_SURROUNDING}) {
+                       print "$x->{FILE}:$x->{LINE}: error: conformant member not at end of struct\n";
+               }
+               push @elements, $e;
        }
 
        my $e = $elements[-1];
index 2ccbc057fce43fe71f1e87d93d3508dbf246db87..d203c4fa439ed298a9d2be90c47193d3cfd0fb64 100644 (file)
@@ -292,7 +292,11 @@ sub ParseArrayPushHeader($$$$$)
        my $length;
 
        if ($l->{IS_ZERO_TERMINATED}) {
-               $size = $length = "ndr_string_length($var_name, sizeof(*$var_name))";
+               if (has_property($e, "charset")) {
+                       $size = $length = "ndr_charset_length($var_name, CH_$e->{PROPERTIES}->{charset})";
+               } else {
+                       $size = $length = "ndr_string_length($var_name, sizeof(*$var_name))";
+               }
        } else {
                $size = ParseExpr($l->{SIZE_IS}, $env);
                $length = ParseExpr($l->{LENGTH_IS}, $env);
@@ -1125,13 +1129,22 @@ sub ParseStructPush($$)
        # we need to push the conformant length early, as it fits on
        # the wire before the structure (and even before the structure
        # alignment)
-       my $e = $struct->{ELEMENTS}[-1];
        if (defined($struct->{SURROUNDING_ELEMENT})) {
                my $e = $struct->{SURROUNDING_ELEMENT};
 
                if (defined($e->{LEVELS}[0]) and 
                        $e->{LEVELS}[0]->{TYPE} eq "ARRAY") {
-                       my $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env);
+                       my $size;
+                       
+                       if ($e->{LEVELS}[0]->{IS_ZERO_TERMINATED}) {
+                               if (has_property($e, "charset")) {
+                                       $size = "ndr_charset_length(r->$e->{NAME}, CH_$e->{PROPERTIES}->{charset})";
+                               } else {
+                                       $size = "ndr_string_length(r->$e->{NAME}, sizeof(*r->$e->{NAME}))";
+                               }
+                       } else {
+                               $size = ParseExpr($e->{LEVELS}[0]->{SIZE_IS}, $env);
+                       }
 
                        pidl "NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, $size));";
                } else {