diff options
Diffstat (limited to 'src/Core/Unix/CoreService.cpp')
-rw-r--r-- | src/Core/Unix/CoreService.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/Core/Unix/CoreService.cpp b/src/Core/Unix/CoreService.cpp index 2a77c90a..6d0f05e5 100644 --- a/src/Core/Unix/CoreService.cpp +++ b/src/Core/Unix/CoreService.cpp @@ -28,9 +28,9 @@ namespace VeraCrypt { template <class T> - auto_ptr <T> CoreService::GetResponse () + unique_ptr <T> CoreService::GetResponse () { - auto_ptr <Serializable> deserializedObject (Serializable::DeserializeNew (ServiceOutputStream)); + unique_ptr <Serializable> deserializedObject (Serializable::DeserializeNew (ServiceOutputStream)); Exception *deserializedException = dynamic_cast <Exception*> (deserializedObject.get()); if (deserializedException) @@ -39,7 +39,7 @@ namespace VeraCrypt if (dynamic_cast <T *> (deserializedObject.get()) == nullptr) throw ParameterIncorrect (SRC_POS); - return auto_ptr <T> (dynamic_cast <T *> (deserializedObject.release())); + return unique_ptr <T> (dynamic_cast <T *> (deserializedObject.release())); } void CoreService::ProcessElevatedRequests () @@ -57,7 +57,7 @@ namespace VeraCrypt // Wait for sync code while (true) { - byte b; + uint8 b; throw_sys_if (read (STDIN_FILENO, &b, 1) != 1); if (b != 0x00) continue; @@ -90,7 +90,7 @@ namespace VeraCrypt { try { - Core = CoreDirect; + Core = move_ptr(CoreDirect); shared_ptr <Stream> inputStream (new FileStream (inputFD != -1 ? inputFD : InputPipe->GetReadFD())); shared_ptr <Stream> outputStream (new FileStream (outputFD != -1 ? outputFD : OutputPipe->GetWriteFD())); @@ -278,7 +278,7 @@ namespace VeraCrypt } template <class T> - auto_ptr <T> CoreService::SendRequest (CoreServiceRequest &request) + unique_ptr <T> CoreService::SendRequest (CoreServiceRequest &request) { static Mutex mutex; ScopeLock lock (mutex); @@ -303,14 +303,13 @@ namespace VeraCrypt // We also use the old way if the user is forcing the use of dummy password for sudo #if defined(TC_LINUX ) || defined (TC_FREEBSD) - + bool authCheckDone = false; if (!Core->GetUseDummySudoPassword ()) { std::vector<char> buffer(128, 0); std::string result; - bool authCheckDone = false; - FILE* pipe = popen("sudo -n uptime 2>&1 | grep 'load average' | wc -l", "r"); // We redirect stderr to stdout (2>&1) to be able to catch the result of the command + FILE* pipe = popen("sudo -n uptime 2>&1 | grep 'load average' | wc -l | tr -d '[:blank:]'", "r"); // We redirect stderr to stdout (2>&1) to be able to catch the result of the command if (pipe) { while (!feof(pipe)) @@ -341,7 +340,7 @@ namespace VeraCrypt try { request.Serialize (ServiceInputStream); - auto_ptr <T> response (GetResponse <T>()); + unique_ptr <T> response (GetResponse <T>()); ElevatedServiceAvailable = true; return response; } @@ -354,7 +353,10 @@ namespace VeraCrypt } request.FastElevation = false; - (*AdminPasswordCallback) (request.AdminPassword); +#if defined(TC_LINUX ) || defined (TC_FREEBSD) + if(!authCheckDone) +#endif + (*AdminPasswordCallback) (request.AdminPassword); } } } @@ -390,8 +392,8 @@ namespace VeraCrypt void CoreService::StartElevated (const CoreServiceRequest &request) { - auto_ptr <Pipe> inPipe (new Pipe()); - auto_ptr <Pipe> outPipe (new Pipe()); + unique_ptr <Pipe> inPipe (new Pipe()); + unique_ptr <Pipe> outPipe (new Pipe()); Pipe errPipe; int forkedPid = fork(); @@ -458,9 +460,12 @@ namespace VeraCrypt adminPassword[request.AdminPassword.size()] = '\n'; } +#if defined(TC_LINUX ) + Thread::Sleep (1000); // wait 1 second for the forked sudo to start +#endif if (write (inPipe->GetWriteFD(), &adminPassword.front(), adminPassword.size())) { } // Errors ignored - Memory::Erase (&adminPassword.front(), adminPassword.size()); + burn (&adminPassword.front(), adminPassword.size()); throw_sys_if (fcntl (outPipe->GetReadFD(), F_SETFL, O_NONBLOCK) == -1); throw_sys_if (fcntl (errPipe.GetReadFD(), F_SETFL, O_NONBLOCK) == -1); @@ -533,12 +538,12 @@ namespace VeraCrypt if (!errOutput.empty()) { - auto_ptr <Serializable> deserializedObject; + unique_ptr <Serializable> deserializedObject; Exception *deserializedException = nullptr; try { - shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((byte *) &errOutput[0], errOutput.size()))); + shared_ptr <Stream> stream (new MemoryStream (ConstBufferPtr ((uint8 *) &errOutput[0], errOutput.size()))); deserializedObject.reset (Serializable::DeserializeNew (stream)); deserializedException = dynamic_cast <Exception*> (deserializedObject.get()); } @@ -570,11 +575,11 @@ namespace VeraCrypt ServiceOutputStream = shared_ptr <Stream> (new FileStream (outPipe->GetReadFD())); // Send sync code - byte sync[] = { 0, 0x11, 0x22 }; + uint8 sync[] = { 0, 0x11, 0x22 }; ServiceInputStream->Write (ConstBufferPtr (sync, array_capacity (sync))); - AdminInputPipe = inPipe; - AdminOutputPipe = outPipe; + AdminInputPipe = move_ptr(inPipe); + AdminOutputPipe = move_ptr(outPipe); } void CoreService::Stop () @@ -585,11 +590,11 @@ namespace VeraCrypt shared_ptr <GetStringFunctor> CoreService::AdminPasswordCallback; - auto_ptr <Pipe> CoreService::AdminInputPipe; - auto_ptr <Pipe> CoreService::AdminOutputPipe; + unique_ptr <Pipe> CoreService::AdminInputPipe; + unique_ptr <Pipe> CoreService::AdminOutputPipe; - auto_ptr <Pipe> CoreService::InputPipe; - auto_ptr <Pipe> CoreService::OutputPipe; + unique_ptr <Pipe> CoreService::InputPipe; + unique_ptr <Pipe> CoreService::OutputPipe; shared_ptr <Stream> CoreService::ServiceInputStream; shared_ptr <Stream> CoreService::ServiceOutputStream; |