"Fossies" - the Fresh Open Source Software Archive

Member "src/Core/Unix/CoreServiceProxy.h" (10 Oct 2018, 4661 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "CoreServiceProxy.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Core_Windows_CoreServiceProxy
   14 #define TC_HEADER_Core_Windows_CoreServiceProxy
   15 
   16 #include "CoreService.h"
   17 #include "Volume/VolumePasswordCache.h"
   18 
   19 namespace VeraCrypt
   20 {
   21     template <class T>
   22     class CoreServiceProxy : public T
   23     {
   24     public:
   25         CoreServiceProxy () { }
   26         virtual ~CoreServiceProxy () { }
   27 
   28         virtual void CheckFilesystem (shared_ptr <VolumeInfo> mountedVolume, bool repair) const
   29         {
   30             CoreService::RequestCheckFilesystem (mountedVolume, repair);
   31         }
   32 
   33         virtual void DismountFilesystem (const DirectoryPath &mountPoint, bool force) const
   34         {
   35             CoreService::RequestDismountFilesystem (mountPoint, force);
   36         }
   37 
   38         virtual shared_ptr <VolumeInfo> DismountVolume (shared_ptr <VolumeInfo> mountedVolume, bool ignoreOpenFiles = false, bool syncVolumeInfo = false)
   39         {
   40             shared_ptr <VolumeInfo> dismountedVolumeInfo = CoreService::RequestDismountVolume (mountedVolume, ignoreOpenFiles, syncVolumeInfo);
   41 
   42             VolumeEventArgs eventArgs (dismountedVolumeInfo);
   43             T::VolumeDismountedEvent.Raise (eventArgs);
   44 
   45             return dismountedVolumeInfo;
   46         }
   47 
   48         virtual uint32 GetDeviceSectorSize (const DevicePath &devicePath) const
   49         {
   50             return CoreService::RequestGetDeviceSectorSize (devicePath);
   51         }
   52 
   53         virtual uint64 GetDeviceSize (const DevicePath &devicePath) const
   54         {
   55             return CoreService::RequestGetDeviceSize (devicePath);
   56         }
   57 
   58 #ifndef TC_LINUX
   59         virtual HostDeviceList GetHostDevices (bool pathListOnly = false) const
   60         {
   61             if (pathListOnly)
   62                 return T::GetHostDevices (pathListOnly);
   63             else
   64                 return CoreService::RequestGetHostDevices (pathListOnly);
   65         }
   66 #endif
   67         virtual bool IsPasswordCacheEmpty () const { return VolumePasswordCache::IsEmpty(); }
   68 
   69         virtual shared_ptr <VolumeInfo> MountVolume (MountOptions &options)
   70         {
   71             shared_ptr <VolumeInfo> mountedVolume;
   72 
   73             if (!VolumePasswordCache::IsEmpty()
   74                 && (!options.Password || options.Password->IsEmpty())
   75                 && (!options.Keyfiles || options.Keyfiles->empty()))
   76             {
   77                 finally_do_arg (MountOptions*, &options, { if (finally_arg->Password) finally_arg->Password.reset(); });
   78 
   79                 PasswordIncorrect passwordException;
   80                 foreach (shared_ptr <VolumePassword> password, VolumePasswordCache::GetPasswords())
   81                 {
   82                     try
   83                     {
   84                         options.Password = password;
   85                         mountedVolume = CoreService::RequestMountVolume (options);
   86                         break;
   87                     }
   88                     catch (PasswordIncorrect &e)
   89                     {
   90                         passwordException = e;
   91                     }
   92                 }
   93 
   94                 if (!mountedVolume)
   95                     passwordException.Throw();
   96             }
   97             else
   98             {
   99                 MountOptions newOptions = options;
  100 
  101                 newOptions.Password = Keyfile::ApplyListToPassword (options.Keyfiles, options.Password);
  102                 if (newOptions.Keyfiles)
  103                     newOptions.Keyfiles->clear();
  104 
  105                 newOptions.ProtectionPassword = Keyfile::ApplyListToPassword (options.ProtectionKeyfiles, options.ProtectionPassword);
  106                 if (newOptions.ProtectionKeyfiles)
  107                     newOptions.ProtectionKeyfiles->clear();
  108 
  109                 try
  110                 {
  111                     mountedVolume = CoreService::RequestMountVolume (newOptions);
  112                 }
  113                 catch (ProtectionPasswordIncorrect &e)
  114                 {
  115                     if (options.ProtectionKeyfiles && !options.ProtectionKeyfiles->empty())
  116                         throw ProtectionPasswordKeyfilesIncorrect (e.what());
  117                     throw;
  118                 }
  119                 catch (PasswordIncorrect &e)
  120                 {
  121                     if (options.Keyfiles && !options.Keyfiles->empty())
  122                         throw PasswordKeyfilesIncorrect (e.what());
  123                     throw;
  124                 }
  125 
  126                 if (options.CachePassword
  127                     && ((options.Password && !options.Password->IsEmpty()) || (options.Keyfiles && !options.Keyfiles->empty())))
  128                 {
  129                     VolumePasswordCache::Store (*Keyfile::ApplyListToPassword (options.Keyfiles, options.Password));
  130                 }
  131             }
  132 
  133             VolumeEventArgs eventArgs (mountedVolume);
  134             T::VolumeMountedEvent.Raise (eventArgs);
  135 
  136             return mountedVolume;
  137         }
  138 
  139         virtual void SetAdminPasswordCallback (shared_ptr <GetStringFunctor> functor)
  140         {
  141             CoreService::SetAdminPasswordCallback (functor);
  142         }
  143 
  144         virtual void SetFileOwner (const FilesystemPath &path, const UserId &owner) const
  145         {
  146             CoreService::RequestSetFileOwner (path, owner);
  147         }
  148 
  149         virtual void WipePasswordCache () const
  150         {
  151             VolumePasswordCache::Clear();
  152         }
  153     };
  154 }
  155 
  156 #endif // TC_HEADER_Core_Windows_CoreServiceProxy