void Serializer::Deserialize (const string &name, const BufferPtr &data) { ValidateName (name); uint64 size = Deserialize <uint64> (); if (data.Size() != size) throw ParameterIncorrect (SRC_POS); DataStream->ReadCompleteBuffer (data); }
void VolumeHeader::Serialize (const BufferPtr &header) const { if (header.Size() != EncryptedHeaderDataSize) throw ParameterIncorrect (SRC_POS); header.Zero(); header[0] = 'V'; header[1] = 'E'; header[2] = 'R'; header[3] = 'A'; size_t offset = 4; header.GetRange (DataAreaKeyOffset, DataAreaKey.Size()).CopyFrom (DataAreaKey); uint16 headerVersion = CurrentHeaderVersion; SerializeEntry (headerVersion, header, offset); SerializeEntry (RequiredMinProgramVersion, header, offset); SerializeEntry (Crc32::ProcessBuffer (header.GetRange (DataAreaKeyOffset, DataKeyAreaMaxSize)), header, offset); uint64 reserved64 = 0; SerializeEntry (reserved64, header, offset); SerializeEntry (reserved64, header, offset); SerializeEntry (HiddenVolumeDataSize, header, offset); SerializeEntry (VolumeDataSize, header, offset); SerializeEntry (EncryptedAreaStart, header, offset); SerializeEntry (EncryptedAreaLength, header, offset); SerializeEntry (Flags, header, offset); if (SectorSize < TC_MIN_VOLUME_SECTOR_SIZE || SectorSize > TC_MAX_VOLUME_SECTOR_SIZE || SectorSize % ENCRYPTION_DATA_UNIT_SIZE != 0) { throw ParameterIncorrect (SRC_POS); } SerializeEntry (SectorSize, header, offset); offset = TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC; SerializeEntry (Crc32::ProcessBuffer (header.GetRange (0, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC)), header, offset); }
uint32 StringConverter::ToUInt32 (const string &str) { uint32 n; stringstream ss (str); ss >> n; if (ss.fail() || n == 0xffffFFFFU) throw ParameterIncorrect (SRC_POS); return n; }
uint64 StringConverter::ToUInt64 (const wstring &str) { uint64 n; wstringstream ss (str); ss >> n; if (ss.fail() || n == 0xffffFFFFffffFFFFULL) throw ParameterIncorrect (SRC_POS); return n; }
int64 StringConverter::ToInt64 (const string &str) { int64 n; stringstream ss (str); ss >> n; if (ss.fail() || n == 0x7fffFFFFffffFFFFLL || n == -0x7fffFFFFffffFFFFLL) throw ParameterIncorrect (SRC_POS); return n; }
int32 StringConverter::ToInt32 (const wstring &str) { int32 n; wstringstream ss (str); ss >> n; if (ss.fail() || n == 0x7fffFFFF || n == -0x7fffFFFF) throw ParameterIncorrect (SRC_POS); return n; }
void *Memory::Allocate (std::size_t size) { if (size < 1) throw ParameterIncorrect (SRC_POS); void *bufPtr = malloc (size); if (!bufPtr) throw bad_alloc(); return bufPtr; }
string StringConverter::GetTrailingNumber (const string &str) { size_t start = str.find_last_not_of ("0123456789"); if (start == string::npos) return str; string s = str.substr (start + 1); if (s.empty ()) throw ParameterIncorrect (SRC_POS); return s; }
void Cipher::SetKey (const ConstBufferPtr &key) { if (key.Size() != GetKeySize ()) throw ParameterIncorrect (SRC_POS); if (!Initialized) ScheduledKey.Allocate (GetScheduledKeySize ()); SetCipherKey (key); Key.CopyFrom (key); Initialized = true; }
T Serializer::Deserialize () { uint64 size; DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &size, sizeof (size))); if (Endian::Big (size) != sizeof (T)) throw ParameterIncorrect (SRC_POS); T data; DataStream->ReadCompleteBuffer (BufferPtr ((byte *) &data, sizeof (data))); return Endian::Big (data); }
bool SystemInfo::IsVersionAtLeast (int versionNumber1, int versionNumber2, int versionNumber3) { vector <int> osVersionNumbers = GetVersion(); if (osVersionNumbers.size() < 2) throw ParameterIncorrect (SRC_POS); if (osVersionNumbers.size() < 3) osVersionNumbers[2] = 0; return (osVersionNumbers[0] * 10000000 + osVersionNumbers[1] * 10000 + osVersionNumbers[2]) >= (versionNumber1 * 10000000 + versionNumber2 * 10000 + versionNumber3); }
auto_ptr <T> CoreService::GetResponse () { auto_ptr <Serializable> deserializedObject (Serializable::DeserializeNew (ServiceOutputStream)); Exception *deserializedException = dynamic_cast <Exception*> (deserializedObject.get()); if (deserializedException) deserializedException->Throw(); if (dynamic_cast <T *> (deserializedObject.get()) == nullptr) throw ParameterIncorrect (SRC_POS); return auto_ptr <T> (dynamic_cast <T *> (deserializedObject.release())); }
void EncryptionAlgorithm::SetKey (const ConstBufferPtr &key) { if (Ciphers.size() < 1) throw NotInitialized (SRC_POS); if (GetKeySize() != key.Size()) throw ParameterIncorrect (SRC_POS); size_t keyOffset = 0; foreach_ref (Cipher &c, Ciphers) { c.SetKey (key.GetRange (keyOffset, c.GetKeySize())); keyOffset += c.GetKeySize(); }
uint64 MemoryStream::Read (const BufferPtr &buffer) { if (Data.size() == 0) throw ParameterIncorrect (SRC_POS); ConstBufferPtr streamBuf (*this); size_t len = buffer.Size(); if (streamBuf.Size() - ReadPosition < len) len = streamBuf.Size() - ReadPosition; BufferPtr(buffer).CopyFrom (streamBuf.GetRange (ReadPosition, len)); ReadPosition += len; return len; }
uint64 EncryptionModeLRW::SectorToBlockIndex (uint64 sectorIndex) const { sectorIndex -= SectorOffset; switch (Ciphers.front()->GetBlockSize()) { case 8: return (sectorIndex << 6) | 1; case 16: return (sectorIndex << 5) | 1; default: throw ParameterIncorrect (SRC_POS); } }
void EncryptionModeLRW::SetKey (const ConstBufferPtr &key) { if (key.Size() != 16) throw ParameterIncorrect (SRC_POS); if (!KeySet) GfContext.Allocate (sizeof (GfCtx)); if (!Gf64TabInit ((unsigned char *) key.Get(), (GfCtx *) (GfContext.Ptr()))) throw bad_alloc(); if (!Gf128Tab64Init ((unsigned char *) key.Get(), (GfCtx *) (GfContext.Ptr()))) throw bad_alloc(); Key.CopyFrom (key); KeySet = true; }
void VolumeFormatOptionsWizardPage::SetFilesystemType (VolumeCreationOptions::FilesystemType::Enum type) { switch (type) { case VolumeCreationOptions::FilesystemType::None: FilesystemTypeChoice->SetStringSelection (LangString["NONE"]); break; case VolumeCreationOptions::FilesystemType::FAT: FilesystemTypeChoice->SetStringSelection (L"FAT"); break; case VolumeCreationOptions::FilesystemType::NTFS: FilesystemTypeChoice->SetStringSelection (L"NTFS"); break; case VolumeCreationOptions::FilesystemType::Ext2: FilesystemTypeChoice->SetStringSelection (L"Linux Ext2"); break; case VolumeCreationOptions::FilesystemType::Ext3: FilesystemTypeChoice->SetStringSelection (L"Linux Ext3"); break; case VolumeCreationOptions::FilesystemType::Ext4: FilesystemTypeChoice->SetStringSelection (L"Linux Ext4"); break; case VolumeCreationOptions::FilesystemType::MacOsExt: FilesystemTypeChoice->SetStringSelection (L"Mac OS Extended"); break; case VolumeCreationOptions::FilesystemType::UFS: FilesystemTypeChoice->SetStringSelection (L"UFS"); break; default: throw ParameterIncorrect (SRC_POS); } }
void VolumePassword::Set (const wchar_t *password, size_t charCount) { if (charCount > MaxSize) throw PasswordTooLong (SRC_POS); union Conv { byte b[sizeof (wchar_t)]; wchar_t c; }; Conv conv; conv.c = L'A'; int lsbPos = -1; for (size_t i = 0; i < sizeof (conv.b); ++i) { if (conv.b[i] == L'A') { lsbPos = i; break; } } if (lsbPos == -1) throw ParameterIncorrect (SRC_POS); bool unportable = false; byte passwordBuf[MaxSize]; for (size_t i = 0; i < charCount; ++i) { conv.c = password[i]; passwordBuf[i] = conv.b[lsbPos]; for (int j = 0; j < (int) sizeof (wchar_t); ++j) { if (j != lsbPos && conv.b[j] != 0) unportable = true; } } Set (passwordBuf, charCount); if (unportable) Unportable = true; }
void Application::Initialize (UserInterfaceType::Enum type) { switch (type) { case UserInterfaceType::Text: { wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) CreateConsoleApp); break; } #ifndef TC_NO_GUI case UserInterfaceType::Graphic: { wxAppInitializer wxTheAppInitializer((wxAppInitializerFunction) CreateGuiApp); break; } #endif default: throw ParameterIncorrect (SRC_POS); } }
void Buffer::Allocate (size_t size) { if (size < 1) throw ParameterIncorrect (SRC_POS); if (DataPtr != nullptr) { if (DataSize == size) return; Free(); } try { DataPtr = static_cast<byte *> (Memory::Allocate (size)); DataSize = size; } catch (...) { DataPtr = nullptr; DataSize = 0; throw; } }
shared_ptr <VolumeInfo> CoreUnix::MountVolume (MountOptions &options) { CoalesceSlotNumberAndMountPoint (options); if (IsVolumeMounted (*options.Path)) throw VolumeAlreadyMounted (SRC_POS); Cipher::EnableHwSupport (!options.NoHardwareCrypto); shared_ptr <Volume> volume; while (true) { try { volume = OpenVolume ( options.Path, options.PreserveTimestamps, options.Password, options.Keyfiles, options.Protection, options.ProtectionPassword, options.ProtectionKeyfiles, options.SharedAccessAllowed, VolumeType::Unknown, options.UseBackupHeaders, options.PartitionInSystemEncryptionScope ); options.Password.reset(); } catch (SystemException &e) { if (options.Protection != VolumeProtection::ReadOnly && (e.GetErrorCode() == EROFS || e.GetErrorCode() == EACCES || e.GetErrorCode() == EPERM)) { // Read-only filesystem options.Protection = VolumeProtection::ReadOnly; continue; } throw; } break; } if (options.Path->IsDevice()) { if (volume->GetFile()->GetDeviceSectorSize() != volume->GetSectorSize()) throw ParameterIncorrect (SRC_POS); #if defined (TC_LINUX) if (volume->GetSectorSize() != TC_SECTOR_SIZE_LEGACY) { if (options.Protection == VolumeProtection::HiddenVolumeReadOnly) throw UnsupportedSectorSizeHiddenVolumeProtection(); if (options.NoKernelCrypto) throw UnsupportedSectorSizeNoKernelCrypto(); } #endif } // Find a free mount point for FUSE service MountedFilesystemList mountedFilesystems = GetMountedFilesystems (); string fuseMountPoint; for (int i = 1; true; i++) { stringstream path; path << GetTempDirectory() << "/" << GetFuseMountDirPrefix() << i; FilesystemPath fsPath (path.str()); bool inUse = false; foreach_ref (const MountedFilesystem &mf, mountedFilesystems) { if (mf.MountPoint == path.str()) { inUse = true; break; } } if (!inUse) { try { if (fsPath.IsDirectory()) fsPath.Delete(); throw_sys_sub_if (mkdir (path.str().c_str(), S_IRUSR | S_IXUSR) == -1, path.str()); fuseMountPoint = fsPath; break; } catch (...) { if (i > 255) throw TemporaryDirectoryFailure (SRC_POS, StringConverter::ToWide (path.str())); } } } try { FuseService::Mount (volume, options.SlotNumber, fuseMountPoint); } catch (...) { try { DirectoryPath (fuseMountPoint).Delete(); } catch (...) { } throw; } try { // Create a mount directory if a default path has been specified bool mountDirCreated = false; string mountPoint; if (!options.NoFilesystem && options.MountPoint) { mountPoint = *options.MountPoint; #ifndef TC_MACOSX if (mountPoint.find (GetDefaultMountPointPrefix()) == 0 && !options.MountPoint->IsDirectory()) { Directory::Create (*options.MountPoint); try { throw_sys_sub_if (chown (mountPoint.c_str(), GetRealUserId(), GetRealGroupId()) == -1, mountPoint); } catch (ParameterIncorrect&) { } mountDirCreated = true; } #endif } try { try { MountVolumeNative (volume, options, fuseMountPoint); } catch (NotApplicable&) { MountAuxVolumeImage (fuseMountPoint, options); } } catch (...) { if (mountDirCreated) remove (mountPoint.c_str()); throw; } } catch (...) { try { VolumeInfoList mountedVolumes = GetMountedVolumes (*options.Path); if (mountedVolumes.size() > 0) { shared_ptr <VolumeInfo> mountedVolume (mountedVolumes.front()); DismountVolume (mountedVolume); } } catch (...) { } throw; } VolumeInfoList mountedVolumes = GetMountedVolumes (*options.Path); if (mountedVolumes.size() != 1) throw ParameterIncorrect (SRC_POS); VolumeEventArgs eventArgs (mountedVolumes.front()); VolumeMountedEvent.Raise (eventArgs); return mountedVolumes.front(); }
void File::Open (const FilePath &path, FileOpenMode mode, FileShareMode shareMode, FileOpenFlags flags) { #ifdef TC_LINUX int sysFlags = O_LARGEFILE; #else int sysFlags = 0; #endif switch (mode) { case CreateReadWrite: sysFlags |= O_CREAT | O_TRUNC | O_RDWR; break; case CreateWrite: sysFlags |= O_CREAT | O_TRUNC | O_WRONLY; break; case OpenRead: sysFlags |= O_RDONLY; break; case OpenWrite: sysFlags |= O_WRONLY; break; case OpenReadWrite: sysFlags |= O_RDWR; break; default: throw ParameterIncorrect (SRC_POS); } if ((flags & File::PreserveTimestamps) && path.IsFile()) { struct stat statData; throw_sys_sub_if (stat (string (path).c_str(), &statData) == -1, wstring (path)); AccTime = statData.st_atime; ModTime = statData.st_mtime; } FileHandle = open (string (path).c_str(), sysFlags, S_IRUSR | S_IWUSR); throw_sys_sub_if (FileHandle == -1, wstring (path)); #if 0 // File locking is disabled to avoid remote filesystem locking issues try { struct flock fl; memset (&fl, 0, sizeof (fl)); fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0; switch (shareMode) { case ShareNone: fl.l_type = F_WRLCK; if (fcntl (FileHandle, F_SETLK, &fl) == -1) throw_sys_sub_if (errno == EAGAIN || errno == EACCES, wstring (path)); break; case ShareRead: fl.l_type = F_RDLCK; if (fcntl (FileHandle, F_SETLK, &fl) == -1) throw_sys_sub_if (errno == EAGAIN || errno == EACCES, wstring (path)); break; case ShareReadWrite: fl.l_type = (mode == OpenRead ? F_RDLCK : F_WRLCK); if (fcntl (FileHandle, F_GETLK, &fl) != -1 && fl.l_type != F_UNLCK) { errno = EAGAIN; throw SystemException (SRC_POS, wstring (path)); } break; case ShareReadWriteIgnoreLock: break; default: throw ParameterIncorrect (SRC_POS); } } catch (...) { close (FileHandle); throw; } #endif // 0 Path = path; mFileOpenFlags = flags; FileIsOpen = true; }
void Hash::ValidateDigestParameters (const BufferPtr &buffer) const { if (buffer.Size() != GetDigestSize ()) throw ParameterIncorrect (SRC_POS); }
bool VolumeHeader::Deserialize (const ConstBufferPtr &header, shared_ptr <EncryptionAlgorithm> &ea, shared_ptr <EncryptionMode> &mode, bool truecryptMode) { if (header.Size() != EncryptedHeaderDataSize) throw ParameterIncorrect (SRC_POS); if (truecryptMode && (header[0] != 'T' || header[1] != 'R' || header[2] != 'U' || header[3] != 'E')) return false; if (!truecryptMode && (header[0] != 'V' || header[1] != 'E' || header[2] != 'R' || header[3] != 'A')) return false; size_t offset = 4; HeaderVersion = DeserializeEntry <uint16> (header, offset); if (HeaderVersion < MinAllowedHeaderVersion) return false; if (HeaderVersion > CurrentHeaderVersion) throw HigherVersionRequired (SRC_POS); if (HeaderVersion >= 4 && Crc32::ProcessBuffer (header.GetRange (0, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC)) != DeserializeEntryAt <uint32> (header, TC_HEADER_OFFSET_HEADER_CRC - TC_HEADER_OFFSET_MAGIC)) { return false; } RequiredMinProgramVersion = DeserializeEntry <uint16> (header, offset); if (!truecryptMode && (RequiredMinProgramVersion > Version::Number())) throw HigherVersionRequired (SRC_POS); if (truecryptMode) { if (RequiredMinProgramVersion < 0x600 || RequiredMinProgramVersion > 0x71a) throw UnsupportedTrueCryptFormat (SRC_POS); RequiredMinProgramVersion = CurrentRequiredMinProgramVersion; } VolumeKeyAreaCrc32 = DeserializeEntry <uint32> (header, offset); VolumeCreationTime = DeserializeEntry <uint64> (header, offset); HeaderCreationTime = DeserializeEntry <uint64> (header, offset); HiddenVolumeDataSize = DeserializeEntry <uint64> (header, offset); mVolumeType = (HiddenVolumeDataSize != 0 ? VolumeType::Hidden : VolumeType::Normal); VolumeDataSize = DeserializeEntry <uint64> (header, offset); EncryptedAreaStart = DeserializeEntry <uint64> (header, offset); EncryptedAreaLength = DeserializeEntry <uint64> (header, offset); Flags = DeserializeEntry <uint32> (header, offset); SectorSize = DeserializeEntry <uint32> (header, offset); if (HeaderVersion < 5) SectorSize = TC_SECTOR_SIZE_LEGACY; if (SectorSize < TC_MIN_VOLUME_SECTOR_SIZE || SectorSize > TC_MAX_VOLUME_SECTOR_SIZE || SectorSize % ENCRYPTION_DATA_UNIT_SIZE != 0) { throw ParameterIncorrect (SRC_POS); } #if !(defined (TC_WINDOWS) || defined (TC_LINUX) || defined (TC_MACOSX)) if (SectorSize != TC_SECTOR_SIZE_LEGACY) throw UnsupportedSectorSize (SRC_POS); #endif offset = DataAreaKeyOffset; if (VolumeKeyAreaCrc32 != Crc32::ProcessBuffer (header.GetRange (offset, DataKeyAreaMaxSize))) return false; DataAreaKey.CopyFrom (header.GetRange (offset, DataKeyAreaMaxSize)); ea = ea->GetNew(); mode = mode->GetNew(); if (typeid (*mode) == typeid (EncryptionModeXTS)) { ea->SetKey (header.GetRange (offset, ea->GetKeySize())); mode->SetKey (header.GetRange (offset + ea->GetKeySize(), ea->GetKeySize())); } else { mode->SetKey (header.GetRange (offset, mode->GetKeySize())); ea->SetKey (header.GetRange (offset + LegacyEncryptionModeKeyAreaSize, ea->GetKeySize())); } ea->SetMode (mode); return true; }
void EncryptionMode::ValidateParameters (byte *data, uint64 length) const { if ((Ciphers.size() > 0 && (length % Ciphers.front()->GetBlockSize()) != 0)) throw ParameterIncorrect (SRC_POS); }
void FatFormatter::Format (WriteSectorCallback &writeSector, uint64 deviceSize, uint32 clusterSize, uint32 sectorSize) { fatparams fatParams; #if TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF #error TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF #endif fatParams.sector_size = (uint16) sectorSize; if (deviceSize / fatParams.sector_size > 0xffffFFFF) throw ParameterIncorrect (SRC_POS); fatParams.num_sectors = (uint32) (deviceSize / fatParams.sector_size); fatParams.cluster_size = clusterSize / fatParams.sector_size; memcpy (fatParams.volume_name, "NO NAME ", 11); GetFatParams (&fatParams); fatparams *ft = &fatParams; SecureBuffer sector (ft->sector_size); uint32 sectorNumber = 0; /* Write the data area */ sector.Zero(); uint32 volumeId; RandomNumberGenerator::GetDataFast (BufferPtr ((byte *) &volumeId, sizeof (volumeId))); PutBoot (ft, (byte *) sector, volumeId); writeSector (sector); ++sectorNumber; /* fat32 boot area */ if (ft->size_fat == 32) { /* fsinfo */ PutFSInfo((byte *) sector, ft); writeSector (sector); ++sectorNumber; /* reserved */ while (sectorNumber < 6) { sector.Zero(); sector[508+3] = 0xaa; /* TrailSig */ sector[508+2] = 0x55; writeSector (sector); ++sectorNumber; } /* bootsector backup */ sector.Zero(); PutBoot (ft, (byte *) sector, volumeId); writeSector (sector); ++sectorNumber; PutFSInfo((byte *) sector, ft); writeSector (sector); ++sectorNumber; } /* reserved */ while (sectorNumber < (uint32)ft->reserved) { sector.Zero(); writeSector (sector); ++sectorNumber; } /* write fat */ for (uint32 x = 1; x <= ft->fats; x++) { for (uint32 n = 0; n < ft->fat_length; n++) { sector.Zero(); if (n == 0) { byte fat_sig[12]; if (ft->size_fat == 32) { fat_sig[0] = (byte) ft->media; fat_sig[1] = fat_sig[2] = 0xff; fat_sig[3] = 0x0f; fat_sig[4] = fat_sig[5] = fat_sig[6] = 0xff; fat_sig[7] = 0x0f; fat_sig[8] = fat_sig[9] = fat_sig[10] = 0xff; fat_sig[11] = 0x0f; memcpy (sector, fat_sig, 12); } else if (ft->size_fat == 16) { fat_sig[0] = (byte) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0xff; memcpy (sector, fat_sig, 4); } else if (ft->size_fat == 12) { fat_sig[0] = (byte) ft->media; fat_sig[1] = 0xff; fat_sig[2] = 0xff; fat_sig[3] = 0x00; memcpy (sector, fat_sig, 4); } } if (!writeSector (sector)) return; } } /* write rootdir */ for (uint32 x = 0; x < ft->size_root_dir / ft->sector_size; x++) { sector.Zero(); if (!writeSector (sector)) return; } }
void CoreService::ProcessRequests (int inputFD, int outputFD) { try { Core = CoreDirect; shared_ptr <Stream> inputStream (new FileStream (inputFD != -1 ? inputFD : InputPipe->GetReadFD())); shared_ptr <Stream> outputStream (new FileStream (outputFD != -1 ? outputFD : OutputPipe->GetWriteFD())); while (true) { shared_ptr <CoreServiceRequest> request = Serializable::DeserializeNew <CoreServiceRequest> (inputStream); try { // ExitRequest if (dynamic_cast <ExitRequest*> (request.get()) != nullptr) { if (ElevatedServiceAvailable) request->Serialize (ServiceInputStream); return; } if (!ElevatedPrivileges && request->ElevateUserPrivileges) { if (!ElevatedServiceAvailable) { finally_do_arg (string *, &request->AdminPassword, { StringConverter::Erase (*finally_arg); }); CoreService::StartElevated (*request); ElevatedServiceAvailable = true; } request->Serialize (ServiceInputStream); GetResponse <Serializable>()->Serialize (outputStream); continue; } // CheckFilesystemRequest CheckFilesystemRequest *checkRequest = dynamic_cast <CheckFilesystemRequest*> (request.get()); if (checkRequest) { Core->CheckFilesystem (checkRequest->MountedVolumeInfo, checkRequest->Repair); CheckFilesystemResponse().Serialize (outputStream); continue; } // DismountFilesystemRequest DismountFilesystemRequest *dismountFsRequest = dynamic_cast <DismountFilesystemRequest*> (request.get()); if (dismountFsRequest) { Core->DismountFilesystem (dismountFsRequest->MountPoint, dismountFsRequest->Force); DismountFilesystemResponse().Serialize (outputStream); continue; } // DismountVolumeRequest DismountVolumeRequest *dismountRequest = dynamic_cast <DismountVolumeRequest*> (request.get()); if (dismountRequest) { DismountVolumeResponse response; response.DismountedVolumeInfo = Core->DismountVolume (dismountRequest->MountedVolumeInfo, dismountRequest->IgnoreOpenFiles, dismountRequest->SyncVolumeInfo); response.Serialize (outputStream); continue; } // GetDeviceSectorSizeRequest GetDeviceSectorSizeRequest *getDeviceSectorSizeRequest = dynamic_cast <GetDeviceSectorSizeRequest*> (request.get()); if (getDeviceSectorSizeRequest) { GetDeviceSectorSizeResponse response; response.Size = Core->GetDeviceSectorSize (getDeviceSectorSizeRequest->Path); response.Serialize (outputStream); continue; } // GetDeviceSizeRequest GetDeviceSizeRequest *getDeviceSizeRequest = dynamic_cast <GetDeviceSizeRequest*> (request.get()); if (getDeviceSizeRequest) { GetDeviceSizeResponse response; response.Size = Core->GetDeviceSize (getDeviceSizeRequest->Path); response.Serialize (outputStream); continue; } // GetHostDevicesRequest GetHostDevicesRequest *getHostDevicesRequest = dynamic_cast <GetHostDevicesRequest*> (request.get()); if (getHostDevicesRequest) { GetHostDevicesResponse response; response.HostDevices = Core->GetHostDevices (getHostDevicesRequest->PathListOnly); response.Serialize (outputStream); continue; } // MountVolumeRequest MountVolumeRequest *mountRequest = dynamic_cast <MountVolumeRequest*> (request.get()); if (mountRequest) { MountVolumeResponse ( Core->MountVolume (*mountRequest->Options) ).Serialize (outputStream); continue; } // SetFileOwnerRequest SetFileOwnerRequest *setFileOwnerRequest = dynamic_cast <SetFileOwnerRequest*> (request.get()); if (setFileOwnerRequest) { CoreUnix *coreUnix = dynamic_cast <CoreUnix *> (Core.get()); if (!coreUnix) throw ParameterIncorrect (SRC_POS); coreUnix->SetFileOwner (setFileOwnerRequest->Path, setFileOwnerRequest->Owner); SetFileOwnerResponse().Serialize (outputStream); continue; } throw ParameterIncorrect (SRC_POS); }
void EncryptionMode::ValidateParameters (byte *data, uint64 sectorCount, size_t sectorSize) const { if (sectorCount == 0 || sectorSize == 0 || (sectorSize % EncryptionDataUnitSize) != 0) throw ParameterIncorrect (SRC_POS); }
void CoreMacOSX::MountAuxVolumeImage (const DirectoryPath &auxMountPoint, const MountOptions &options) const { #if 0 // Check FUSE version char fuseVersionString[MAXHOSTNAMELEN + 1] = { 0 }; size_t fuseVersionStringLength = MAXHOSTNAMELEN; if (sysctlbyname ("macfuse.version.number", fuseVersionString, &fuseVersionStringLength, NULL, 0) != 0) throw HigherFuseVersionRequired (SRC_POS); vector <string> fuseVersion = StringConverter::Split (string (fuseVersionString), "."); if (fuseVersion.size() < 2) throw HigherFuseVersionRequired (SRC_POS); uint32 fuseVersionMajor = StringConverter::ToUInt32 (fuseVersion[0]); uint32 fuseVersionMinor = StringConverter::ToUInt32 (fuseVersion[1]); if (fuseVersionMajor < 1 || (fuseVersionMajor == 1 && fuseVersionMinor < 3)) throw HigherFuseVersionRequired (SRC_POS); #endif // Mount volume image string volImage = string (auxMountPoint) + FuseService::GetVolumeImagePath(); list <string> args; args.push_back ("attach"); args.push_back (volImage); args.push_back ("-plist"); args.push_back ("-noautofsck"); args.push_back ("-imagekey"); args.push_back ("diskimage-class=CRawDiskImage"); if (!options.NoFilesystem && options.MountPoint && !options.MountPoint->IsEmpty()) { args.push_back ("-mount"); args.push_back ("required"); // Let the system specify mount point except when the user specified a non-default one if (string (*options.MountPoint).find (GetDefaultMountPointPrefix()) != 0) { args.push_back ("-mountpoint"); args.push_back (*options.MountPoint); } } else args.push_back ("-nomount"); if (options.Protection == VolumeProtection::ReadOnly) args.push_back ("-readonly"); string xml; while (true) { try { xml = Process::Execute ("hdiutil", args); break; } catch (ExecutedProcessFailed &e) { if (e.GetErrorOutput().find ("noautofsck") != string::npos) { args.remove ("-noautofsck"); continue; } throw; } } size_t p = xml.find ("<key>dev-entry</key>"); if (p == string::npos) throw ParameterIncorrect (SRC_POS); p = xml.find ("<string>", p); if (p == string::npos) throw ParameterIncorrect (SRC_POS); p += 8; size_t e = xml.find ("</string>", p); if (e == string::npos) throw ParameterIncorrect (SRC_POS); DevicePath virtualDev = StringConverter::Trim (xml.substr (p, e - p)); try { FuseService::SendAuxDeviceInfo (auxMountPoint, virtualDev); } catch (...) { try { list <string> args; args.push_back ("detach"); args.push_back (volImage); args.push_back ("-force"); Process::Execute ("hdiutil", args); } catch (ExecutedProcessFailed&) { } throw; } }
void Hash::ValidateDataParameters (const ConstBufferPtr &data) const { if (data.Size() < 1) throw ParameterIncorrect (SRC_POS); }