References: =========== - [MS-SMB2]: 2.2.13
| 340 | |
| 341 | |
| 342 | class SMB2CreateRequest(Structure): |
| 343 | """ |
| 344 | References: |
| 345 | =========== |
| 346 | - [MS-SMB2]: 2.2.13 |
| 347 | """ |
| 348 | |
| 349 | STRUCTURE_FORMAT = "<HBBIQQIIIIIHHII" |
| 350 | STRUCTURE_SIZE = struct.calcsize(STRUCTURE_FORMAT) |
| 351 | |
| 352 | def __init__(self, filename, file_attributes = 0, |
| 353 | access_mask = 0, share_access = 0, create_disp = 0, create_options = 0, |
| 354 | impersonation = SEC_ANONYMOUS, |
| 355 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
| 356 | create_context_data = b''): |
| 357 | self.filename = filename |
| 358 | self.file_attributes = file_attributes |
| 359 | self.access_mask = access_mask |
| 360 | self.share_access = share_access |
| 361 | self.create_disp = create_disp |
| 362 | self.create_options = create_options |
| 363 | self.oplock = oplock |
| 364 | self.impersonation = impersonation |
| 365 | self.create_context_data = create_context_data or b'' |
| 366 | |
| 367 | def initMessage(self, message): |
| 368 | Structure.initMessage(self, message) |
| 369 | message.command = SMB2_COM_CREATE |
| 370 | |
| 371 | def prepare(self, message): |
| 372 | buf = self.filename.encode('UTF-16LE') |
| 373 | filename_len = len(buf) |
| 374 | if self.create_context_data: |
| 375 | n = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf) |
| 376 | if n % 8 != 0: |
| 377 | buf += b'\0'*(8-n%8) |
| 378 | create_context_offset = SMB2Message.HEADER_SIZE + self.STRUCTURE_SIZE + len(buf) |
| 379 | else: |
| 380 | create_context_offset = n |
| 381 | buf += self.create_context_data |
| 382 | else: |
| 383 | create_context_offset = 0 |
| 384 | if not buf: |
| 385 | buf = b'\0' |
| 386 | |
| 387 | assert create_context_offset % 8 == 0 |
| 388 | message.data = struct.pack(self.STRUCTURE_FORMAT, |
| 389 | 57, # Structure size. Must be 57 as mandated by [MS-SMB2] 2.2.13 |
| 390 | 0, # SecurityFlag. Must be 0 |
| 391 | self.oplock, |
| 392 | self.impersonation, |
| 393 | 0, # SmbCreateFlags. Must be 0 |
| 394 | 0, # Reserved. Must be 0 |
| 395 | self.access_mask, # DesiredAccess. [MS-SMB2] 2.2.13.1 |
| 396 | self.file_attributes, |
| 397 | self.share_access, |
| 398 | self.create_disp, |
| 399 | self.create_options, |
no outgoing calls
no test coverage detected