Skip to content

Commit

Permalink
librpc:ndr: Add ‘int64’ type
Browse files Browse the repository at this point in the history
This type behaves like a signed variant of ‘hyper’. Unlike the existing
‘dlong’ type, which has four byte alignment, ‘int64’ is aligned to eight
bytes.

Bump the NDR version to 3.0.1.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15452

Signed-off-by: Joseph Sutton <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
(cherry picked from commit 402bb17)
  • Loading branch information
jsutton24 authored and Jule Anger committed Aug 17, 2023
1 parent 0bd2b8b commit d5e0f9a
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 3 deletions.
272 changes: 272 additions & 0 deletions librpc/ABI/ndr-3.0.1.sigs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions librpc/ndr/libndr.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ NDR_SCALAR_PROTO(udlong, uint64_t)
NDR_SCALAR_PROTO(udlongr, uint64_t)
NDR_SCALAR_PROTO(dlong, int64_t)
NDR_SCALAR_PROTO(hyper, uint64_t)
NDR_SCALAR_PROTO(int64, int64_t)
NDR_SCALAR_PROTO(pointer, void *)
NDR_SCALAR_PROTO(time_t, time_t)
NDR_SCALAR_PROTO(uid_t, uid_t)
Expand Down
43 changes: 43 additions & 0 deletions librpc/ndr/ndr_basic.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#define NDR_PULL_I32(ndr, ofs) \
(int32_t)(NDR_BE(ndr) ? PULL_BE_U32(ndr->data,ofs) : PULL_LE_U32(ndr->data,ofs))

#define NDR_PULL_I64(ndr, ofs) \
(NDR_BE(ndr) ? PULL_BE_I64((ndr)->data, (ofs)) : PULL_LE_I64((ndr)->data, (ofs)))

#define NDR_PUSH_U16(ndr, ofs, v) \
do { \
if (NDR_BE(ndr)) { \
Expand Down Expand Up @@ -63,6 +66,15 @@
} \
} while (0)

#define NDR_PUSH_I64(ndr, ofs, v) \
do { \
if (NDR_BE(ndr)) { \
PUSH_BE_I64((ndr)->data, (ofs), (v)); \
} else { \
PUSH_LE_I64((ndr)->data, (ofs), (v)); \
} \
} while (0)

static void ndr_dump_data(struct ndr_print *ndr, const uint8_t *buf, int len);

/*
Expand Down Expand Up @@ -306,6 +318,19 @@ _PUBLIC_ enum ndr_err_code ndr_pull_hyper(struct ndr_pull *ndr, int ndr_flags, u
return ndr_pull_udlong(ndr, ndr_flags, v);
}

/*
parse an int64
*/
_PUBLIC_ enum ndr_err_code ndr_pull_int64(struct ndr_pull *ndr, int ndr_flags, int64_t *v)
{
NDR_PULL_CHECK_FLAGS(ndr, ndr_flags);
NDR_PULL_ALIGN(ndr, 8);
NDR_PULL_NEED_BYTES(ndr, 8);
*v = NDR_PULL_I64(ndr, ndr->offset);
ndr->offset += 8;
return NDR_ERR_SUCCESS;
}

/*
parse a pointer
*/
Expand Down Expand Up @@ -643,6 +668,19 @@ _PUBLIC_ enum ndr_err_code ndr_push_hyper(struct ndr_push *ndr, int ndr_flags, u
return ndr_push_udlong(ndr, NDR_SCALARS, v);
}

/*
push an int64
*/
_PUBLIC_ enum ndr_err_code ndr_push_int64(struct ndr_push *ndr, int ndr_flags, int64_t v)
{
NDR_PUSH_CHECK_FLAGS(ndr, ndr_flags);
NDR_PUSH_ALIGN(ndr, 8);
NDR_PUSH_NEED_BYTES(ndr, 8);
NDR_PUSH_I64(ndr, ndr->offset, v);
ndr->offset += 8;
return NDR_ERR_SUCCESS;
}

/*
push a double
*/
Expand Down Expand Up @@ -1210,6 +1248,11 @@ _PUBLIC_ void ndr_print_hyper(struct ndr_print *ndr, const char *name, uint64_t
ndr_print_dlong(ndr, name, v);
}

_PUBLIC_ void ndr_print_int64(struct ndr_print *ndr, const char *name, int64_t v)
{
ndr_print_dlong(ndr, name, v);
}

_PUBLIC_ void ndr_print_pointer(struct ndr_print *ndr, const char *name, void *v)
{
ndr->print(ndr, "%-25s: %p", name, v);
Expand Down
2 changes: 1 addition & 1 deletion librpc/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ bld.SAMBA_LIBRARY('ndr',
public_deps='samba-errors talloc samba-util util_str_hex',
public_headers='gen_ndr/misc.h gen_ndr/ndr_misc.h ndr/libndr.h:ndr.h',
header_path= [('*gen_ndr*', 'gen_ndr')],
vnum='3.0.0',
vnum='3.0.1',
abi_directory='ABI',
abi_match='!ndr_table_* ndr_* GUID_* _ndr_pull_error* _ndr_push_error*',
)
Expand Down
1 change: 1 addition & 0 deletions pidl/lib/Parse/Pidl/NDR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ my $scalar_alignment = {
'int3264' => 5,
'uint3264' => 5,
'hyper' => 8,
'int64' => 8,
'double' => 8,
'pointer' => 8,
'dlong' => 4,
Expand Down
1 change: 1 addition & 0 deletions pidl/lib/Parse/Pidl/Typelist.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ my %scalars = (
"int3264" => "int32_t",
"uint3264" => "uint32_t",
"hyper" => "uint64_t",
"int64" => "int64_t",
"dlong" => "int64_t",
"udlong" => "uint64_t",
"udlongr" => "uint64_t",
Expand Down
1 change: 1 addition & 0 deletions pidl/lib/Parse/Pidl/Wireshark/NDR.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ sub Initialize($$)

$self->register_type("uint3264", "offset = dissect_ndr_uint3264(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT32", "BASE_DEC", 0, "NULL", 8);
$self->register_type("hyper", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 8);
$self->register_type("int64", "offset = dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_INT64", "BASE_DEC", 0, "NULL", 8);
$self->register_type("udlong", "offset = dissect_ndr_duint32(tvb, offset, pinfo, tree, di, drep, \@HF\@, NULL);", "FT_UINT64", "BASE_DEC", 0, "NULL", 4);
$self->register_type("bool8", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
$self->register_type("char", "offset = PIDL_dissect_uint8(tvb, offset, pinfo, tree, di, drep, \@HF\@, \@PARAM\@);","FT_INT8", "BASE_DEC", 0, "NULL", 1);
Expand Down
3 changes: 2 additions & 1 deletion pidl/tests/ndr.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use strict;
use warnings;

use Test::More tests => 47;
use Test::More tests => 48;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
Expand Down Expand Up @@ -480,6 +480,7 @@
is($ne->{REPRESENTATION_TYPE}, "uint8");

is(align_type("hyper"), 8);
is(align_type("int64"), 8);
is(align_type("double"), 8);
is(align_type("uint32"), 4);
is(align_type("uint16"), 2);
Expand Down
3 changes: 2 additions & 1 deletion pidl/tests/typelist.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use strict;
use warnings;

use Test::More tests => 56;
use Test::More tests => 57;
use FindBin qw($RealBin);
use lib "$RealBin";
use Util;
Expand All @@ -21,6 +21,7 @@
is("uint32_t", mapScalarType("uint32"));
is("void", mapScalarType("void"));
is("uint64_t", mapScalarType("hyper"));
is("int64_t", mapScalarType("int64"));
is("double", mapScalarType("double"));

my $x = { TYPE => "ENUM", NAME => "foo", EXTRADATA => 1 };
Expand Down

0 comments on commit d5e0f9a

Please sign in to comment.