-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmsg_file_write.go
107 lines (93 loc) · 2.68 KB
/
msg_file_write.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package smb
func init() {
commandRequestMap[CommandWrite] = func() DataI {
return &WriteRequest{}
}
}
//CommandWrite
type WriteRequest struct {
Header
StructureSize uint16
DataOffset uint16 `smb:"offset:Data"`
DataLength uint32 `smb:"len:Data"`
FileOffset uint64
FileId GUID
Channel uint32
RemainingBytes uint32
WriteChannelInfoOffset uint16 `smb:"offset:WriteChannelInfo"`
WriteChannelInfoLength uint16 `smb:"len:WriteChannelInfo"`
Flags uint32
Data []byte
// WriteChannelInfo []byte
}
type WriteResponse struct {
Header
StructureSize uint16
Reserved uint16
Count uint32
Remaining uint32
WriteChannelInfoOffset uint16 `smb:"offset:WriteChannelInfo"`
WriteChannelInfoLength uint16 `smb:"len:WriteChannelInfo"`
WriteChannelInfo []byte
}
func (data *WriteRequest) ServerAction(ctx *DataCtx) (interface{}, error) {
data.Header.Flags = SMB2_FLAGS_RESPONSE
if data.Header.Flags&SMB2_FLAGS_PRIORITY_MASK == SMB2_FLAGS_PRIORITY_MASK {
return ERR(data.Header, STATUS_NOT_SUPPORTED)
}
if data.DataLength > kMaxTransactSize ||
data.DataLength == 0 ||
// data.Channel != 0 ||
len(data.Data) == 0 ||
len(data.Data) != int(data.DataLength) {
return ERR(data.Header, StatusInvalidParameter)
}
fileid := ctx.FileID(data.FileId)
webfile, ok := ctx.session.openedFiles[fileid]
if !ok {
return ERR(data.Header, STATUS_FILE_CLOSED)
}
if fileid.IsSvrSvc(ctx.session) {
return DcerpcWrite(ctx, data)
}
_, err := webfile.Seek(int64(data.FileOffset), 0)
if err != nil {
return ERR(data.Header, STATUS_UNSUCCESSFUL)
}
doneSize, err := webfile.Write(data.Data)
if err != nil {
return ERR(data.Header, STATUS_UNSUCCESSFUL)
}
resp := WriteResponse{
Count: uint32(doneSize),
Header: data.Header,
StructureSize: 17,
}
return &resp, nil
}
// //////////////////////////////////////////////////////////////////////
func NewWriteResponse() WriteResponse {
return WriteResponse{}
}
// Channel属性
const (
SMB2_CHANNEL_NONE = 0x00000000
SMB2_CHANNEL_RDMA_V1 = 0x00000001
SMB2_CHANNEL_RDMA_V1_INVALIDATE = 0x00000002
SMB2_CHANNEL_RDMA_TRANSFORM = 0x00000003
)
// 写入请求
func (c *SessionC) NewWriteRequest(treeId uint32, fileId, buf []byte) WriteRequest {
smb2Header := c.newHeader(CommandWrite)
smb2Header.Credits = 127
smb2Header.TreeID = treeId
return WriteRequest{
Header: smb2Header,
StructureSize: 49,
// FileId: fileId,
Channel: SMB2_CHANNEL_NONE,
RemainingBytes: 0,
Flags: 0,
Data: buf,
}
}