Skip to content

Commit

Permalink
dcerpc: more refactoring of dcerpc making it less of akludge
Browse files Browse the repository at this point in the history
goal is to have coder functions that can either marshall or unmarshall
depending on ->direction
and to handle all three types of pointers and alignment
based on conformance data sizes as well as maximum field alignment
of fields inside aggregate types (structs are aligned according to alignment
of the largest alignment of any immediately embedded fields)

Conformance data such as pointer sizes, arm-selector for unions and
max/offset/current sizes for conforming and varying arrays
all affect alignment so we need to refactor properly to make it possible to
have an easy to build ILD compiler for these protocols.
(negotiated transfer syntaxes such as NDR vs NDR64 also affect alignment.
 so, ...   but hey, this will be the third dcerpc/ndr implementation I have
written so better do it right this time so I never need to do it again.)

Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Sep 26, 2024
1 parent 6bc54a0 commit 53f9d1e
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 381 deletions.
14 changes: 1 addition & 13 deletions include/libsmb2-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,7 @@ void smb2_timeout_pdus(struct smb2_context *smb2);

struct dcerpc_context;
int dcerpc_set_uint8(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint8_t value);
int dcerpc_set_uint16(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint16_t value);
int dcerpc_set_uint32(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint32_t value);
int dcerpc_set_uint64(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint64_t value);
int dcerpc_get_uint16(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint16_t *value);
int dcerpc_get_uint32(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint32_t *value);
int dcerpc_get_uint64(struct dcerpc_context *ctx, struct smb2_iovec *iov,
int offset, uint64_t *value);
int *offset, uint8_t value);

struct dcerpc_pdu;
int dcerpc_pdu_direction(struct dcerpc_pdu *pdu);
Expand Down
2 changes: 1 addition & 1 deletion include/smb2/libsmb2-dcerpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef struct dcerpc_uuid {
uint32_t v1;
uint16_t v2;
uint16_t v3;
uint64_t v4;
uint64_t v4; /* TODO: is really a char[8] */
} dcerpc_uuid_t;

typedef struct p_syntax_id {
Expand Down
7 changes: 7 additions & 0 deletions lib/dcerpc-lsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ lsa_RPC_UNICODE_STRING_coder(struct dcerpc_context *dce,
{
uint16_t len, maxlen;

/* TODO conformance split
* during the conformance run we need to do the alignment in all the
coders, even for the coders that do not have any conformance data.
that will eliminate the need to manually set the alignment like
we do here
*/
*offset = dcerpc_align_3264(dce, *offset);

if (dcerpc_pdu_direction(pdu) == DCERPC_ENCODE) {
Expand Down
Loading

0 comments on commit 53f9d1e

Please sign in to comment.