-
Notifications
You must be signed in to change notification settings - Fork 51
/
Smb2CreateResponse.java
338 lines (270 loc) · 8.6 KB
/
Smb2CreateResponse.java
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*
* © 2017 AgNO3 Gmbh & Co. KG
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package jcifs.internal.smb2.create;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jcifs.Configuration;
import jcifs.internal.CommonServerMessageBlockRequest;
import jcifs.internal.SMBProtocolDecodingException;
import jcifs.internal.SmbBasicFileInfo;
import jcifs.internal.smb2.RequestWithFileId;
import jcifs.internal.smb2.ServerMessageBlock2Response;
import jcifs.internal.util.SMBUtil;
import jcifs.util.Hexdump;
/**
* @author mbechler
*
*/
public class Smb2CreateResponse extends ServerMessageBlock2Response implements SmbBasicFileInfo {
private static final Logger log = LoggerFactory.getLogger(Smb2CreateResponse.class);
private byte oplockLevel;
private byte openFlags;
private int createAction;
private long creationTime;
private long lastAccessTime;
private long lastWriteTime;
private long changeTime;
private long allocationSize;
private long endOfFile;
private int fileAttributes;
private byte[] fileId = new byte[16];
private CreateContextResponse[] createContexts;
private final String fileName;
/**
* @param config
* @param name
*/
public Smb2CreateResponse ( Configuration config, String name ) {
super(config);
this.fileName = name;
}
/**
* {@inheritDoc}
*
* @see jcifs.internal.smb2.ServerMessageBlock2Response#prepare(jcifs.internal.CommonServerMessageBlockRequest)
*/
@Override
public void prepare ( CommonServerMessageBlockRequest next ) {
if ( isReceived() && ( next instanceof RequestWithFileId ) ) {
( (RequestWithFileId) next ).setFileId(this.fileId);
}
super.prepare(next);
}
/**
* @return the oplockLevel
*/
public final byte getOplockLevel () {
return this.oplockLevel;
}
/**
* @return the flags
*/
public final byte getOpenFlags () {
return this.openFlags;
}
/**
* @return the createAction
*/
public final int getCreateAction () {
return this.createAction;
}
/**
* @return the creationTime
*/
public final long getCreationTime () {
return this.creationTime;
}
/**
* {@inheritDoc}
*
* @see jcifs.internal.SmbBasicFileInfo#getCreateTime()
*/
@Override
public final long getCreateTime () {
return getCreationTime();
}
/**
* @return the lastAccessTime
*/
@Override
public final long getLastAccessTime () {
return this.lastAccessTime;
}
/**
* @return the lastWriteTime
*/
@Override
public final long getLastWriteTime () {
return this.lastWriteTime;
}
/**
* @return the changeTime
*/
public final long getChangeTime () {
return this.changeTime;
}
/**
* @return the allocationSize
*/
public final long getAllocationSize () {
return this.allocationSize;
}
/**
* @return the endOfFile
*/
public final long getEndOfFile () {
return this.endOfFile;
}
/**
* {@inheritDoc}
*
* @see jcifs.internal.SmbBasicFileInfo#getSize()
*/
@Override
public final long getSize () {
return getEndOfFile();
}
/**
* @return the fileAttributes
*/
public final int getFileAttributes () {
return this.fileAttributes;
}
/**
* {@inheritDoc}
*
* @see jcifs.internal.SmbBasicFileInfo#getAttributes()
*/
@Override
public final int getAttributes () {
return getFileAttributes();
}
/**
* @return the fileId
*/
public final byte[] getFileId () {
return this.fileId;
}
/**
* @return the fileName
*/
public final String getFileName () {
return this.fileName;
}
/**
* @return the createContexts
*/
public CreateContextResponse[] getCreateContexts () {
return this.createContexts;
}
/**
* {@inheritDoc}
*
* @see jcifs.internal.smb2.ServerMessageBlock2#writeBytesWireFormat(byte[], int)
*/
@Override
protected int writeBytesWireFormat ( byte[] dst, int dstIndex ) {
return 0;
}
/**
* {@inheritDoc}
*
* @throws Smb2ProtocolDecodingException
*
* @see jcifs.internal.smb2.ServerMessageBlock2#readBytesWireFormat(byte[], int)
*/
@Override
protected int readBytesWireFormat ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
int start = bufferIndex;
int structureSize = SMBUtil.readInt2(buffer, bufferIndex);
if ( structureSize != 89 ) {
throw new SMBProtocolDecodingException("Structure size is not 89");
}
this.oplockLevel = buffer[ bufferIndex + 2 ];
this.openFlags = buffer[ bufferIndex + 3 ];
bufferIndex += 4;
this.createAction = SMBUtil.readInt4(buffer, bufferIndex);
bufferIndex += 4;
this.creationTime = SMBUtil.readTime(buffer, bufferIndex);
bufferIndex += 8;
this.lastAccessTime = SMBUtil.readTime(buffer, bufferIndex);
bufferIndex += 8;
this.lastWriteTime = SMBUtil.readTime(buffer, bufferIndex);
bufferIndex += 8;
this.changeTime = SMBUtil.readTime(buffer, bufferIndex);
bufferIndex += 8;
this.allocationSize = SMBUtil.readInt8(buffer, bufferIndex);
bufferIndex += 8;
this.endOfFile = SMBUtil.readInt8(buffer, bufferIndex);
bufferIndex += 8;
this.fileAttributes = SMBUtil.readInt4(buffer, bufferIndex);
bufferIndex += 4;
bufferIndex += 4; // Reserved2
System.arraycopy(buffer, bufferIndex, this.fileId, 0, 16);
bufferIndex += 16;
int createContextOffset = SMBUtil.readInt4(buffer, bufferIndex);
bufferIndex += 4;
int createContextLength = SMBUtil.readInt4(buffer, bufferIndex);
bufferIndex += 4;
if ( createContextOffset > 0 && createContextLength > 0 ) {
List<CreateContextResponse> contexts = new LinkedList<>();
int createContextStart = getHeaderStart() + createContextOffset;
int next = 0;
do {
int cci = createContextStart;
next = SMBUtil.readInt4(buffer, cci);
cci += 4;
int nameOffset = SMBUtil.readInt2(buffer, cci);
int nameLength = SMBUtil.readInt2(buffer, cci + 2);
cci += 4;
int dataOffset = SMBUtil.readInt2(buffer, cci + 2);
cci += 4;
int dataLength = SMBUtil.readInt4(buffer, cci);
cci += 4;
byte[] nameBytes = new byte[nameLength];
System.arraycopy(buffer, createContextStart + nameOffset, nameBytes, 0, nameBytes.length);
cci = Math.max(cci, createContextStart + nameOffset + nameLength);
CreateContextResponse cc = createContext(nameBytes);
if ( cc != null ) {
cc.decode(buffer, createContextStart + dataOffset, dataLength);
contexts.add(cc);
}
cci = Math.max(cci, createContextStart + dataOffset + dataLength);
if ( next > 0 ) {
createContextStart += next;
}
bufferIndex = Math.max(bufferIndex, cci);
}
while ( next > 0 );
this.createContexts = contexts.toArray(new CreateContextResponse[0]);
}
if ( log.isDebugEnabled() ) {
log.debug("Opened " + this.fileName + ": " + Hexdump.toHexString(this.fileId));
}
return bufferIndex - start;
}
/**
* @param nameBytes
* @return
*/
private static CreateContextResponse createContext ( byte[] nameBytes ) {
return null;
}
}