diff options
author | George Hazan <ghazan@miranda.im> | 2019-05-27 16:21:17 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-05-27 16:21:17 +0300 |
commit | 189f6be24f11066a3c711b783cf98f79f703e3a5 (patch) | |
tree | 3acf7a0cf990f574d9edb0f8045b605d8e3ec024 /plugins/CryptoPP/src/GPGw | |
parent | e3179c1ef509482ff9b4c7d4fb89d0b208e84000 (diff) |
as well as calls of GetVersionEx should be removed
Diffstat (limited to 'plugins/CryptoPP/src/GPGw')
-rw-r--r-- | plugins/CryptoPP/src/GPGw/pipeexec.cpp | 215 |
1 files changed, 91 insertions, 124 deletions
diff --git a/plugins/CryptoPP/src/GPGw/pipeexec.cpp b/plugins/CryptoPP/src/GPGw/pipeexec.cpp index 3a04fd1697..f892c207a4 100644 --- a/plugins/CryptoPP/src/GPGw/pipeexec.cpp +++ b/plugins/CryptoPP/src/GPGw/pipeexec.cpp @@ -1,134 +1,101 @@ #include "../commonheaders.h"
#include "gpgw.h"
-BOOL isWindowsNT(void)
-{
- BOOL result;
- OSVERSIONINFO ovi;
-
- memset(&ovi, 0, sizeof(ovi));
- ovi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
- GetVersionEx(&ovi);
-
- if(ovi.dwPlatformId==VER_PLATFORM_WIN32_NT) result=TRUE;
- else result=FALSE;
-
- return result;
-}
-
-
void storeOutput(HANDLE ahandle, char **aoutput)
{
- DWORD success;
- char readbuffer[10];
- DWORD transfered;
- DWORD available;
-
- do
- {
- PeekNamedPipe(ahandle, NULL, 0, NULL, &available, NULL);
-
- if(available==0) continue;
-
- success=ReadFile(ahandle, readbuffer, sizeof(readbuffer), &transfered, NULL);
-
- if ((success)&&(transfered!=0))
- appendText(aoutput, readbuffer, transfered);
- }
- while(available>0);
+ DWORD available;
+ do {
+ PeekNamedPipe(ahandle, NULL, 0, NULL, &available, NULL);
+
+ if (available == 0) continue;
+
+ DWORD transfered;
+ char readbuffer[10];
+ DWORD success = ReadFile(ahandle, readbuffer, sizeof(readbuffer), &transfered, NULL);
+ if ((success) && (transfered != 0))
+ appendText(aoutput, readbuffer, transfered);
+ } while (available > 0);
}
-
pxResult pxExecute(char *acommandline, char *ainput, char **aoutput, LPDWORD aexitcode)
{
- BOOL success;
- STARTUPINFO startupinfo;
- SECURITY_ATTRIBUTES securityattributes;
- SECURITY_DESCRIPTOR securitydescriptor;
- PROCESS_INFORMATION processinformation;
- HANDLE newstdin, newstdout, readstdout, writestdin;
- char *inputpos;
- DWORD transfered;
- int size;
-
- LogMessage("commandline:\n", acommandline, "\n");
-
- memset(&securityattributes, 0, sizeof(securityattributes));
- securityattributes.nLength=sizeof(SECURITY_ATTRIBUTES);
- securityattributes.bInheritHandle=TRUE;
-
- if(isWindowsNT())
- {
- InitializeSecurityDescriptor(&securitydescriptor, SECURITY_DESCRIPTOR_REVISION);
- SetSecurityDescriptorDacl(&securitydescriptor, TRUE, NULL, FALSE);
- securityattributes.lpSecurityDescriptor=&securitydescriptor;
- }
- else securityattributes.lpSecurityDescriptor=NULL;
-
- success=CreatePipe(&newstdin, &writestdin ,&securityattributes ,0);
- if (! success)
- {
- LogMessage("--- ", "create pipe failed", "\n");
- return pxCreatePipeFailed;
- }
-
- success=CreatePipe(&readstdout, &newstdout, &securityattributes, 0);
- if (! success)
- {
- LogMessage("--- ", "create pipe failed", "\n");
- CloseHandle(newstdin);
- CloseHandle(writestdin);
- return pxCreatePipeFailed;
- }
-
- GetStartupInfo(&startupinfo);
- startupinfo.dwFlags=STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
- startupinfo.wShowWindow=SW_HIDE;
- startupinfo.hStdOutput=newstdout;
- startupinfo.hStdError=newstdout;
- startupinfo.hStdInput=newstdin;
-
- success=CreateProcess(NULL, acommandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &startupinfo, &processinformation);
-
- if (! success)
- {
- LogMessage("--- ", "create process failed", "\n");
- CloseHandle(newstdin);
- CloseHandle(writestdin);
- CloseHandle(newstdout);
- CloseHandle(readstdout);
- return pxCreateProcessFailed;
- }
-
- inputpos=ainput;
-
- while(TRUE)
- {
- success=GetExitCodeProcess(processinformation.hProcess, aexitcode);
- if ((success)&&(*aexitcode!=STILL_ACTIVE)) break;
-
- storeOutput(readstdout, aoutput);
-
- if (*inputpos!='\0') size=1;
- else size=0;
-
- success=WriteFile(writestdin, inputpos, size, &transfered, NULL);
-
- inputpos+=transfered;
- }
-
- storeOutput(readstdout, aoutput);
- WaitForSingleObject(processinformation.hProcess, INFINITE);
-
- LogMessage("output:\n", *aoutput, "");
-
- CloseHandle(processinformation.hThread);
- CloseHandle(processinformation.hProcess);
- CloseHandle(newstdin);
- CloseHandle(newstdout);
- CloseHandle(readstdout);
- CloseHandle(writestdin);
-
- return pxSuccess;
+ LogMessage("commandline:\n", acommandline, "\n");
+
+ SECURITY_ATTRIBUTES securityattributes;
+ memset(&securityattributes, 0, sizeof(securityattributes));
+ securityattributes.nLength = sizeof(SECURITY_ATTRIBUTES);
+ securityattributes.bInheritHandle = TRUE;
+
+ SECURITY_DESCRIPTOR securitydescriptor;
+ InitializeSecurityDescriptor(&securitydescriptor, SECURITY_DESCRIPTOR_REVISION);
+ SetSecurityDescriptorDacl(&securitydescriptor, TRUE, NULL, FALSE);
+ securityattributes.lpSecurityDescriptor = &securitydescriptor;
+
+ HANDLE newstdin, newstdout, readstdout, writestdin;
+ BOOL success = CreatePipe(&newstdin, &writestdin, &securityattributes, 0);
+ if (!success) {
+ LogMessage("--- ", "create pipe failed", "\n");
+ return pxCreatePipeFailed;
+ }
+
+ success = CreatePipe(&readstdout, &newstdout, &securityattributes, 0);
+ if (!success) {
+ LogMessage("--- ", "create pipe failed", "\n");
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ return pxCreatePipeFailed;
+ }
+
+ STARTUPINFO startupinfo;
+ GetStartupInfo(&startupinfo);
+ startupinfo.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
+ startupinfo.wShowWindow = SW_HIDE;
+ startupinfo.hStdOutput = newstdout;
+ startupinfo.hStdError = newstdout;
+ startupinfo.hStdInput = newstdin;
+
+ PROCESS_INFORMATION processinformation;
+ success = CreateProcess(NULL, acommandline, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &startupinfo, &processinformation);
+ if (!success) {
+ LogMessage("--- ", "create process failed", "\n");
+ CloseHandle(newstdin);
+ CloseHandle(writestdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ return pxCreateProcessFailed;
+ }
+
+ char *inputpos = ainput;
+
+ while (TRUE) {
+ success = GetExitCodeProcess(processinformation.hProcess, aexitcode);
+ if ((success) && (*aexitcode != STILL_ACTIVE))
+ break;
+
+ storeOutput(readstdout, aoutput);
+
+ int size;
+ if (*inputpos != '\0')
+ size = 1;
+ else
+ size = 0;
+
+ DWORD transfered;
+ success = WriteFile(writestdin, inputpos, size, &transfered, NULL);
+ inputpos += transfered;
+ }
+
+ storeOutput(readstdout, aoutput);
+ WaitForSingleObject(processinformation.hProcess, INFINITE);
+
+ LogMessage("output:\n", *aoutput, "");
+
+ CloseHandle(processinformation.hThread);
+ CloseHandle(processinformation.hProcess);
+ CloseHandle(newstdin);
+ CloseHandle(newstdout);
+ CloseHandle(readstdout);
+ CloseHandle(writestdin);
+
+ return pxSuccess;
}
-
|