Skip to content

Commit 1881846

Browse files
committed
feat: dnsp: add rr-from-string methods
1 parent 0dbd349 commit 1881846

File tree

4 files changed

+392
-15
lines changed

4 files changed

+392
-15
lines changed

idl/dnsp/record.idl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ typedef struct _DnssrvRecordNaptr
289289
{
290290
WORD wOrder;
291291
WORD wPreference;
292-
PDNS_NODE_TEXT nameFlags;
293-
PDNS_NODE_TEXT nameService;
294-
PDNS_NODE_TEXT nameSubstitution;
292+
PDNS_NODE_NAME nameFlags;
293+
PDNS_NODE_NAME nameService;
294+
PDNS_NODE_NAME nameSubstitution;
295295
PDNS_NODE_NAME nameReplacement;
296296
} DNS_RPC_RECORD_NAPTR, *PDNS_RPC_RECORD_NAPTR;
297297

msrpc/dnsp/record.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package dnsp
2+
3+
import (
4+
"github.com/miekg/dns"
5+
6+
"github.com/oiweiwei/go-msrpc/msrpc/dnsp/record"
7+
)
8+
9+
// NewRecordFromString creates a new Record from a string data.
10+
func NewRecordFromString(typ uint16, ttl uint32, data string) (*Record, error) {
11+
12+
record, err := record.NewRecordFromString(typ, ttl, data)
13+
if err != nil {
14+
return nil, err
15+
}
16+
17+
return &Record{
18+
DataLength: record.DataLength,
19+
Type: uint16(record.Type),
20+
Flags: record.Flags,
21+
Serial: record.Serial,
22+
TTLSeconds: record.TTLSeconds,
23+
Timestamp: record.Timestamp,
24+
Buffer: record.Buffer,
25+
}, nil
26+
}
27+
28+
// NewRecordFromRR creates a new Record from a dns.RR.
29+
func NewRecordFromRR(rr dns.RR) (*Record, error) {
30+
31+
record, err := record.NewRecordFromRR(rr)
32+
if err != nil {
33+
return nil, err
34+
}
35+
36+
return &Record{
37+
DataLength: record.DataLength,
38+
Type: uint16(record.Type),
39+
Flags: record.Flags,
40+
Serial: record.Serial,
41+
TTLSeconds: record.TTLSeconds,
42+
Timestamp: record.Timestamp,
43+
Buffer: record.Buffer,
44+
}, nil
45+
}

msrpc/dnsp/record/record.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,15 +6822,15 @@ type RecordNAPTR struct {
68226822
Preference uint16 `idl:"name:wPreference" json:"preference"`
68236823
// nameFlags (variable): Pointer to a structure of type DNS_RPC_NAME (section 2.2.2.2.1)
68246824
// containing the string flags value as specified in section 4.1 in [RFC3403].
6825-
Flags *NodeText `idl:"name:nameFlags" json:"flags"`
6825+
Flags *NodeName `idl:"name:nameFlags" json:"flags"`
68266826
// nameService (variable): Pointer to a structure of type DNS_RPC_NAME (section 2.2.2.2.1)
68276827
// containing service parameters value for NAPTR to control the rewriting and interpretation
68286828
// of the field in the record, as specified in section 4.1 in [RFC3403].
6829-
Service *NodeText `idl:"name:nameService" json:"service"`
6829+
Service *NodeName `idl:"name:nameService" json:"service"`
68306830
// nameSubstitution (variable): Pointer to a structure of type DNS_RPC_NAME (section
68316831
// 2.2.2.2.1) containing a substitution expression value for the NAPTR record, as specified
68326832
// in section 4.1 in [RFC3403].
6833-
Substitution *NodeText `idl:"name:nameSubstitution" json:"substitution"`
6833+
Substitution *NodeName `idl:"name:nameSubstitution" json:"substitution"`
68346834
// nameReplacement (variable): Pointer to a structure of type DNS_RPC_NAME (section
68356835
// 2.2.2.2.1) containing a replacement expression value for the NAPTR record, as specified
68366836
// in section 4.1 in [RFC3403].
@@ -6865,7 +6865,7 @@ func (o *RecordNAPTR) MarshalNDR(ctx context.Context, w ndr.Writer) error {
68656865
return err
68666866
}
68676867
} else {
6868-
if err := (&NodeText{}).MarshalNDR(ctx, w); err != nil {
6868+
if err := (&NodeName{}).MarshalNDR(ctx, w); err != nil {
68696869
return err
68706870
}
68716871
}
@@ -6886,7 +6886,7 @@ func (o *RecordNAPTR) MarshalNDR(ctx context.Context, w ndr.Writer) error {
68866886
return err
68876887
}
68886888
} else {
6889-
if err := (&NodeText{}).MarshalNDR(ctx, w); err != nil {
6889+
if err := (&NodeName{}).MarshalNDR(ctx, w); err != nil {
68906890
return err
68916891
}
68926892
}
@@ -6907,7 +6907,7 @@ func (o *RecordNAPTR) MarshalNDR(ctx context.Context, w ndr.Writer) error {
69076907
return err
69086908
}
69096909
} else {
6910-
if err := (&NodeText{}).MarshalNDR(ctx, w); err != nil {
6910+
if err := (&NodeName{}).MarshalNDR(ctx, w); err != nil {
69116911
return err
69126912
}
69136913
}
@@ -6956,40 +6956,40 @@ func (o *RecordNAPTR) UnmarshalNDR(ctx context.Context, w ndr.Reader) error {
69566956
}
69576957
_ptr_nameFlags := ndr.UnmarshalNDRFunc(func(ctx context.Context, w ndr.Reader) error {
69586958
if o.Flags == nil {
6959-
o.Flags = &NodeText{}
6959+
o.Flags = &NodeName{}
69606960
}
69616961
if err := o.Flags.UnmarshalNDR(ctx, w); err != nil {
69626962
return err
69636963
}
69646964
return nil
69656965
})
6966-
_s_nameFlags := func(ptr interface{}) { o.Flags = *ptr.(**NodeText) }
6966+
_s_nameFlags := func(ptr interface{}) { o.Flags = *ptr.(**NodeName) }
69676967
if err := w.ReadPointer(&o.Flags, _s_nameFlags, _ptr_nameFlags); err != nil {
69686968
return err
69696969
}
69706970
_ptr_nameService := ndr.UnmarshalNDRFunc(func(ctx context.Context, w ndr.Reader) error {
69716971
if o.Service == nil {
6972-
o.Service = &NodeText{}
6972+
o.Service = &NodeName{}
69736973
}
69746974
if err := o.Service.UnmarshalNDR(ctx, w); err != nil {
69756975
return err
69766976
}
69776977
return nil
69786978
})
6979-
_s_nameService := func(ptr interface{}) { o.Service = *ptr.(**NodeText) }
6979+
_s_nameService := func(ptr interface{}) { o.Service = *ptr.(**NodeName) }
69806980
if err := w.ReadPointer(&o.Service, _s_nameService, _ptr_nameService); err != nil {
69816981
return err
69826982
}
69836983
_ptr_nameSubstitution := ndr.UnmarshalNDRFunc(func(ctx context.Context, w ndr.Reader) error {
69846984
if o.Substitution == nil {
6985-
o.Substitution = &NodeText{}
6985+
o.Substitution = &NodeName{}
69866986
}
69876987
if err := o.Substitution.UnmarshalNDR(ctx, w); err != nil {
69886988
return err
69896989
}
69906990
return nil
69916991
})
6992-
_s_nameSubstitution := func(ptr interface{}) { o.Substitution = *ptr.(**NodeText) }
6992+
_s_nameSubstitution := func(ptr interface{}) { o.Substitution = *ptr.(**NodeName) }
69936993
if err := w.ReadPointer(&o.Substitution, _s_nameSubstitution, _ptr_nameSubstitution); err != nil {
69946994
return err
69956995
}

0 commit comments

Comments
 (0)