(self, treeId, fileName, desiredAccess, shareMode, creationOptions, creationDisposition, fileAttributes, impersonationLevel = SMB2_IL_IMPERSONATION, securityFlags = 0, oplockLevel = SMB2_OPLOCK_LEVEL_NONE, createContexts = None)
| 1252 | return True |
| 1253 | |
| 1254 | def create(self, treeId, fileName, desiredAccess, shareMode, creationOptions, creationDisposition, fileAttributes, impersonationLevel = SMB2_IL_IMPERSONATION, securityFlags = 0, oplockLevel = SMB2_OPLOCK_LEVEL_NONE, createContexts = None): |
| 1255 | if (treeId in self._Session['TreeConnectTable']) is False: |
| 1256 | raise SessionError(STATUS_INVALID_PARAMETER) |
| 1257 | |
| 1258 | fileName = fileName.replace('/', '\\') |
| 1259 | if len(fileName) > 0: |
| 1260 | fileName = ntpath.normpath(fileName) |
| 1261 | if fileName[0] == '\\': |
| 1262 | fileName = fileName[1:] |
| 1263 | |
| 1264 | if self._Session['TreeConnectTable'][treeId]['IsDfsShare'] is True: |
| 1265 | pathName = fileName |
| 1266 | else: |
| 1267 | pathName = '\\\\' + self._Connection['ServerName'] + '\\' + fileName |
| 1268 | |
| 1269 | fileEntry = copy.deepcopy(FILE) |
| 1270 | fileEntry['LeaseKey'] = uuid.generate() |
| 1271 | fileEntry['LeaseState'] = SMB2_LEASE_NONE |
| 1272 | self.GlobalFileTable[pathName] = fileEntry |
| 1273 | |
| 1274 | if self._Connection['Dialect'] >= SMB2_DIALECT_30 and self._Connection['SupportsDirectoryLeasing'] is True: |
| 1275 | # Is this file NOT on the root directory? |
| 1276 | if len(fileName.split('\\')) > 2: |
| 1277 | parentDir = ntpath.dirname(pathName) |
| 1278 | if parentDir in self.GlobalFileTable: |
| 1279 | raise Exception("Don't know what to do now! :-o") |
| 1280 | else: |
| 1281 | parentEntry = copy.deepcopy(FILE) |
| 1282 | parentEntry['LeaseKey'] = uuid.generate() |
| 1283 | parentEntry['LeaseState'] = SMB2_LEASE_NONE |
| 1284 | self.GlobalFileTable[parentDir] = parentEntry |
| 1285 | |
| 1286 | packet = self.SMB_PACKET() |
| 1287 | packet['Command'] = SMB2_CREATE |
| 1288 | packet['TreeID'] = treeId |
| 1289 | if self._Session['TreeConnectTable'][treeId]['IsDfsShare'] is True: |
| 1290 | packet['Flags'] = SMB2_FLAGS_DFS_OPERATIONS |
| 1291 | |
| 1292 | smb2Create = SMB2Create() |
| 1293 | smb2Create['SecurityFlags'] = 0 |
| 1294 | smb2Create['RequestedOplockLevel'] = oplockLevel |
| 1295 | smb2Create['ImpersonationLevel'] = impersonationLevel |
| 1296 | smb2Create['DesiredAccess'] = desiredAccess |
| 1297 | smb2Create['FileAttributes'] = fileAttributes |
| 1298 | smb2Create['ShareAccess'] = shareMode |
| 1299 | smb2Create['CreateDisposition'] = creationDisposition |
| 1300 | smb2Create['CreateOptions'] = creationOptions |
| 1301 | |
| 1302 | smb2Create['NameLength'] = len(fileName.encode('utf-16le')) |
| 1303 | if fileName != '': |
| 1304 | smb2Create['Buffer'] = fileName.encode('utf-16le') |
| 1305 | else: |
| 1306 | smb2Create['Buffer'] = b'\x00' |
| 1307 | |
| 1308 | if createContexts is not None: |
| 1309 | contextsBuf = b''.join(x.getData() for x in createContexts) |
| 1310 | smb2Create['CreateContextsOffset'] = len(SMB2Packet()) + SMB2Create.SIZE + len(smb2Create['Buffer']) |
| 1311 |
no test coverage detected