"Fossies" - the Fresh Open Source Software Archive

Member "src/Core/Unix/CoreServiceRequest.cpp" (10 Oct 2018, 7389 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 "CoreServiceRequest.cpp" 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 #include <errno.h>
   14 #include "CoreServiceRequest.h"
   15 #include "Platform/SerializerFactory.h"
   16 
   17 namespace VeraCrypt
   18 {
   19     void CoreServiceRequest::Deserialize (shared_ptr <Stream> stream)
   20     {
   21         Serializer sr (stream);
   22         sr.Deserialize ("AdminPassword", AdminPassword);
   23         ApplicationExecutablePath = sr.DeserializeWString ("ApplicationExecutablePath");
   24         sr.Deserialize ("ElevateUserPrivileges", ElevateUserPrivileges);
   25         sr.Deserialize ("FastElevation", FastElevation);
   26     }
   27 
   28     void CoreServiceRequest::Serialize (shared_ptr <Stream> stream) const
   29     {
   30         Serializable::Serialize (stream);
   31         Serializer sr (stream);
   32         sr.Serialize ("AdminPassword", AdminPassword);
   33         sr.Serialize ("ApplicationExecutablePath", wstring (ApplicationExecutablePath));
   34         sr.Serialize ("ElevateUserPrivileges", ElevateUserPrivileges);
   35         sr.Serialize ("FastElevation", FastElevation);
   36     }
   37 
   38     // CheckFilesystemRequest
   39     void CheckFilesystemRequest::Deserialize (shared_ptr <Stream> stream)
   40     {
   41         CoreServiceRequest::Deserialize (stream);
   42         Serializer sr (stream);
   43         MountedVolumeInfo = Serializable::DeserializeNew <VolumeInfo> (stream);
   44         sr.Deserialize ("Repair", Repair);
   45     }
   46 
   47     bool CheckFilesystemRequest::RequiresElevation () const
   48     {
   49 #ifdef TC_MACOSX
   50         return false;
   51 #endif
   52         return !Core->HasAdminPrivileges();
   53     }
   54 
   55     void CheckFilesystemRequest::Serialize (shared_ptr <Stream> stream) const
   56     {
   57         CoreServiceRequest::Serialize (stream);
   58         Serializer sr (stream);
   59         MountedVolumeInfo->Serialize (stream);
   60         sr.Serialize ("Repair", Repair);
   61     }
   62 
   63     // DismountFilesystemRequest
   64     void DismountFilesystemRequest::Deserialize (shared_ptr <Stream> stream)
   65     {
   66         CoreServiceRequest::Deserialize (stream);
   67         Serializer sr (stream);
   68         sr.Deserialize ("Force", Force);
   69         MountPoint = sr.DeserializeWString ("MountPoint");
   70     }
   71 
   72     bool DismountFilesystemRequest::RequiresElevation () const
   73     {
   74         return !Core->HasAdminPrivileges();
   75     }
   76 
   77     void DismountFilesystemRequest::Serialize (shared_ptr <Stream> stream) const
   78     {
   79         CoreServiceRequest::Serialize (stream);
   80         Serializer sr (stream);
   81         sr.Serialize ("Force", Force);
   82         sr.Serialize ("MountPoint", wstring (MountPoint));
   83     }
   84 
   85     // DismountVolumeRequest
   86     void DismountVolumeRequest::Deserialize (shared_ptr <Stream> stream)
   87     {
   88         CoreServiceRequest::Deserialize (stream);
   89         Serializer sr (stream);
   90         sr.Deserialize ("IgnoreOpenFiles", IgnoreOpenFiles);
   91         sr.Deserialize ("SyncVolumeInfo", SyncVolumeInfo);
   92         MountedVolumeInfo = Serializable::DeserializeNew <VolumeInfo> (stream);
   93     }
   94 
   95     bool DismountVolumeRequest::RequiresElevation () const
   96     {
   97 #ifdef TC_MACOSX
   98         if (MountedVolumeInfo->Path.IsDevice())
   99         {
  100             try
  101             {
  102                 File file;
  103                 file.Open (MountedVolumeInfo->Path, File::OpenReadWrite);
  104             }
  105             catch (...)
  106             {
  107                 return true;
  108             }
  109         }
  110 
  111         return false;
  112 #endif
  113         return !Core->HasAdminPrivileges();
  114     }
  115 
  116     void DismountVolumeRequest::Serialize (shared_ptr <Stream> stream) const
  117     {
  118         CoreServiceRequest::Serialize (stream);
  119         Serializer sr (stream);
  120         sr.Serialize ("IgnoreOpenFiles", IgnoreOpenFiles);
  121         sr.Serialize ("SyncVolumeInfo", SyncVolumeInfo);
  122         MountedVolumeInfo->Serialize (stream);
  123     }
  124 
  125     // GetDeviceSectorSizeRequest
  126     void GetDeviceSectorSizeRequest::Deserialize (shared_ptr <Stream> stream)
  127     {
  128         CoreServiceRequest::Deserialize (stream);
  129         Serializer sr (stream);
  130         Path = sr.DeserializeWString ("Path");
  131     }
  132 
  133     bool GetDeviceSectorSizeRequest::RequiresElevation () const
  134     {
  135         return !Core->HasAdminPrivileges();
  136     }
  137 
  138     void GetDeviceSectorSizeRequest::Serialize (shared_ptr <Stream> stream) const
  139     {
  140         CoreServiceRequest::Serialize (stream);
  141         Serializer sr (stream);
  142         sr.Serialize ("Path", wstring (Path));
  143     }
  144 
  145     // GetDeviceSizeRequest
  146     void GetDeviceSizeRequest::Deserialize (shared_ptr <Stream> stream)
  147     {
  148         CoreServiceRequest::Deserialize (stream);
  149         Serializer sr (stream);
  150         Path = sr.DeserializeWString ("Path");
  151     }
  152 
  153     bool GetDeviceSizeRequest::RequiresElevation () const
  154     {
  155         return !Core->HasAdminPrivileges();
  156     }
  157 
  158     void GetDeviceSizeRequest::Serialize (shared_ptr <Stream> stream) const
  159     {
  160         CoreServiceRequest::Serialize (stream);
  161         Serializer sr (stream);
  162         sr.Serialize ("Path", wstring (Path));
  163     }
  164 
  165     // GetHostDevicesRequest
  166     void GetHostDevicesRequest::Deserialize (shared_ptr <Stream> stream)
  167     {
  168         CoreServiceRequest::Deserialize (stream);
  169         Serializer sr (stream);
  170         sr.Deserialize ("PathListOnly", PathListOnly);
  171     }
  172 
  173     bool GetHostDevicesRequest::RequiresElevation () const
  174     {
  175         return !Core->HasAdminPrivileges();
  176     }
  177 
  178     void GetHostDevicesRequest::Serialize (shared_ptr <Stream> stream) const
  179     {
  180         CoreServiceRequest::Serialize (stream);
  181         Serializer sr (stream);
  182         sr.Serialize ("PathListOnly", PathListOnly);
  183     }
  184 
  185     // ExitRequest
  186     void ExitRequest::Deserialize (shared_ptr <Stream> stream)
  187     {
  188         CoreServiceRequest::Deserialize (stream);
  189     }
  190 
  191     void ExitRequest::Serialize (shared_ptr <Stream> stream) const
  192     {
  193         CoreServiceRequest::Serialize (stream);
  194     }
  195 
  196     // MountVolumeRequest
  197     void MountVolumeRequest::Deserialize (shared_ptr <Stream> stream)
  198     {
  199         CoreServiceRequest::Deserialize (stream);
  200         Serializer sr (stream);
  201         DeserializedOptions = Serializable::DeserializeNew <MountOptions> (stream);
  202         Options = DeserializedOptions.get();
  203     }
  204 
  205     bool MountVolumeRequest::RequiresElevation () const
  206     {
  207 #ifdef TC_MACOSX
  208         if (Options->Path->IsDevice())
  209         {
  210             try
  211             {
  212                 File file;
  213                 file.Open (*Options->Path, File::OpenReadWrite);
  214             }
  215             catch (...)
  216             {
  217                 return true;
  218             }
  219         }
  220 
  221         return false;
  222 #endif
  223         return !Core->HasAdminPrivileges();
  224     }
  225 
  226     void MountVolumeRequest::Serialize (shared_ptr <Stream> stream) const
  227     {
  228         CoreServiceRequest::Serialize (stream);
  229         Serializer sr (stream);
  230         Options->Serialize (stream);
  231     }
  232 
  233     // SetFileOwnerRequest
  234     void SetFileOwnerRequest::Deserialize (shared_ptr <Stream> stream)
  235     {
  236         CoreServiceRequest::Deserialize (stream);
  237         Serializer sr (stream);
  238 
  239         uint64 owner;
  240         sr.Deserialize ("Owner", owner);
  241         Owner.SystemId = static_cast <uid_t> (owner);
  242 
  243         Path = sr.DeserializeWString ("Path");
  244     }
  245 
  246     bool SetFileOwnerRequest::RequiresElevation () const
  247     {
  248         return !Core->HasAdminPrivileges();
  249     }
  250 
  251     void SetFileOwnerRequest::Serialize (shared_ptr <Stream> stream) const
  252     {
  253         CoreServiceRequest::Serialize (stream);
  254         Serializer sr (stream);
  255 
  256         uint64 owner = Owner.SystemId;
  257         sr.Serialize ("Owner", owner);
  258 
  259         sr.Serialize ("Path", wstring (Path));
  260     }
  261 
  262 
  263     TC_SERIALIZER_FACTORY_ADD_CLASS (CoreServiceRequest);
  264     TC_SERIALIZER_FACTORY_ADD_CLASS (CheckFilesystemRequest);
  265     TC_SERIALIZER_FACTORY_ADD_CLASS (DismountFilesystemRequest);
  266     TC_SERIALIZER_FACTORY_ADD_CLASS (DismountVolumeRequest);
  267     TC_SERIALIZER_FACTORY_ADD_CLASS (ExitRequest);
  268     TC_SERIALIZER_FACTORY_ADD_CLASS (GetDeviceSectorSizeRequest);
  269     TC_SERIALIZER_FACTORY_ADD_CLASS (GetDeviceSizeRequest);
  270     TC_SERIALIZER_FACTORY_ADD_CLASS (GetHostDevicesRequest);
  271     TC_SERIALIZER_FACTORY_ADD_CLASS (MountVolumeRequest);
  272     TC_SERIALIZER_FACTORY_ADD_CLASS (SetFileOwnerRequest);
  273 }