Skip to content

Commit

Permalink
dcerpc srvsvc: minor tweak
Browse files Browse the repository at this point in the history
Not sure what way to handle when you have things like

int xxx
switch_is(xxx) foo_union

and automatically pass the outer xxx to the array arm in
foo_union.
For now have to specify both in the structures before encoding
it, but it would be nice to have it done automatically
and for decoding it would be nice to automatically
verify that both instances of xxx read from the iov
are actually the same value.
This is so much easier to handle when you have an idl compiler
that can automatically inject the code you need. But I
will have to do with what I have for now.

Signed-off-by: Ronnie Sahlberg <[email protected]>
  • Loading branch information
sahlberg committed Sep 30, 2024
1 parent 1b63d94 commit ba342cb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
6 changes: 3 additions & 3 deletions include/smb2/libsmb2-dcerpc-srvsvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int srvsvc_SHARE_INFO_0_coder(struct dcerpc_context *ctx,
void *ptr);

struct srvsvc_SHARE_INFO_0_carray {
uint32_t max_count; /* filled in by caller before decode */
uint32_t max_count;
struct srvsvc_SHARE_INFO_0 *share_info_0;
};

Expand All @@ -75,7 +75,7 @@ int srvsvc_SHARE_INFO_1_coder(struct dcerpc_context *ctx,
void *ptr);

struct srvsvc_SHARE_INFO_1_carray {
uint32_t max_count; /* filled in by caller before decode */
uint32_t max_count;
struct srvsvc_SHARE_INFO_1 *share_info_1;
};

Expand All @@ -90,7 +90,7 @@ int srvsvc_SHARE_INFO_1_CONTAINER_coder(struct dcerpc_context *dce,
void *ptr);

struct srvsvc_SHARE_ENUM_UNION {
uint32_t level;
uint32_t Level;
union {
struct srvsvc_SHARE_INFO_0_CONTAINER Level0;
struct srvsvc_SHARE_INFO_1_CONTAINER Level1;
Expand Down
12 changes: 8 additions & 4 deletions lib/dcerpc-srvsvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ p_syntax_id_t srvsvc_interface = {
* [MS-SRVS].pdf
*/

/*
* typedef struct _SHARE_INFO_0 {
* [string] wchar_t * shi0_netname;
* } SHARE_INFO_0, *PSHARE_INFO_0, *LPSHARE_INFO_0;
*/
int
srvsvc_SHARE_INFO_0_coder(struct dcerpc_context *ctx,
struct dcerpc_pdu *pdu,
Expand Down Expand Up @@ -238,13 +243,13 @@ srvsvc_SHARE_ENUM_UNION_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu
struct srvsvc_SHARE_ENUM_UNION *ctr = ptr;
uint64_t p;

p = ctr->level;
p = ctr->Level;
if (dcerpc_uint3264_coder(ctx, pdu, iov, offset, &p)) {
return -1;
}
ctr->level = (uint32_t)p;
ctr->Level = (uint32_t)p;

switch (ctr->level) {
switch (ctr->Level) {
case 0:
if (dcerpc_ptr_coder(ctx, pdu, iov, offset, &ctr->Level0,
PTR_UNIQUE,
Expand Down Expand Up @@ -280,7 +285,6 @@ srvsvc_SHARE_ENUM_STRUCT_coder(struct dcerpc_context *ctx, struct dcerpc_pdu *pd
if (dcerpc_uint32_coder(ctx, pdu, iov, offset, &ses->Level)) {
return -1;
}
ses->ShareInfo.level = ses->Level;
if (srvsvc_SHARE_ENUM_UNION_coder(ctx, pdu, iov, offset, &ses->ShareInfo)) {
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion lib/dcerpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,6 @@ dcerpc_encode_utf16(struct dcerpc_context *ctx, struct dcerpc_pdu *pdu,

/* Conformance part */
if (pdu->is_conformance_run) {
// QQQ check for s->utf8==NULL
if (s->utf8 == NULL) {
s->utf8 = "";
}
Expand Down
2 changes: 2 additions & 0 deletions lib/smb2-share-enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,13 @@ smb2_share_enum_async(struct smb2_context *smb2,
switch (level) {
case SHARE_INFO_0:
nse->se_req.ses.Level = level;
nse->se_req.ses.ShareInfo.Level = level;
nse->se_req.ses.ShareInfo.Level0.EntriesRead = 0;
nse->se_req.ses.ShareInfo.Level0.Buffer = NULL;
break;
case SHARE_INFO_1:
nse->se_req.ses.Level = level;
nse->se_req.ses.ShareInfo.Level = level;
nse->se_req.ses.ShareInfo.Level1.EntriesRead = 0;
nse->se_req.ses.ShareInfo.Level1.Buffer = NULL;
break;
Expand Down

0 comments on commit ba342cb

Please sign in to comment.