mirror of https://github.com/FreeRDP/FreeRDP
commit
3d6e1fb418
|
@ -110,6 +110,8 @@ WINPR_API LPCH MergeEnvironmentStrings(PCSTR original, PCSTR merge);
|
|||
WINPR_API DWORD GetEnvironmentVariableEBA(LPCSTR envBlock, LPCSTR lpName, LPSTR lpBuffer, DWORD nSize);
|
||||
WINPR_API BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue);
|
||||
|
||||
WINPR_API char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -572,3 +572,52 @@ BOOL SetEnvironmentVariableEBA(LPSTR* envBlock, LPCSTR lpName, LPCSTR lpValue)
|
|||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
|
||||
{
|
||||
char* p;
|
||||
int index;
|
||||
int count;
|
||||
int length;
|
||||
char** envp = NULL;
|
||||
|
||||
count = 0;
|
||||
if (!lpszEnvironmentBlock)
|
||||
return NULL;
|
||||
|
||||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
while (p[0] && p[1])
|
||||
{
|
||||
length = strlen(p);
|
||||
p += (length + 1);
|
||||
count++;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
envp = (char**) calloc(count + 1, sizeof(char*));
|
||||
if (!envp)
|
||||
return NULL;
|
||||
envp[count] = NULL;
|
||||
|
||||
while (p[0] && p[1])
|
||||
{
|
||||
length = strlen(p);
|
||||
envp[index] = _strdup(p);
|
||||
if (!envp[index])
|
||||
{
|
||||
for (index -= 1; index >= 0; --index)
|
||||
{
|
||||
free(envp[index]);
|
||||
}
|
||||
free(envp);
|
||||
return NULL;
|
||||
}
|
||||
p += (length + 1);
|
||||
index++;
|
||||
}
|
||||
|
||||
return envp;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "../handle/nonehandle.h"
|
||||
|
||||
#include <winpr/thread.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/**
|
||||
* CreateProcessA
|
||||
|
@ -54,30 +53,16 @@
|
|||
|
||||
#ifndef _WIN32
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/heap.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/environment.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "thread.h"
|
||||
|
||||
#include "../handle/handle.h"
|
||||
#include "../security/security.h"
|
||||
|
||||
#ifndef NSIG
|
||||
|
@ -88,55 +73,6 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
|
||||
{
|
||||
char* p;
|
||||
int index;
|
||||
int count;
|
||||
int length;
|
||||
char** envp = NULL;
|
||||
|
||||
count = 0;
|
||||
if (!lpszEnvironmentBlock)
|
||||
return NULL;
|
||||
|
||||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
while (p[0] && p[1])
|
||||
{
|
||||
length = strlen(p);
|
||||
p += (length + 1);
|
||||
count++;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
p = (char*) lpszEnvironmentBlock;
|
||||
|
||||
envp = (char**) calloc(count + 1, sizeof(char*));
|
||||
if (!envp)
|
||||
return NULL;
|
||||
envp[count] = NULL;
|
||||
|
||||
while (p[0] && p[1])
|
||||
{
|
||||
length = strlen(p);
|
||||
envp[index] = _strdup(p);
|
||||
if (!envp[index])
|
||||
{
|
||||
for (index -= 1; index >= 0; --index)
|
||||
{
|
||||
free(envp[index]);
|
||||
}
|
||||
free(envp);
|
||||
return NULL;
|
||||
}
|
||||
p += (length + 1);
|
||||
index++;
|
||||
}
|
||||
|
||||
return envp;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the file name does not contain a directory path, the system searches for the executable file in the following sequence:
|
||||
*
|
||||
|
@ -151,7 +87,7 @@ char** EnvironmentBlockToEnvpA(LPCH lpszEnvironmentBlock)
|
|||
* this per-application path in the search sequence, use the ShellExecute function.
|
||||
*/
|
||||
|
||||
char* FindApplicationPath(char* application)
|
||||
static char* FindApplicationPath(char* application)
|
||||
{
|
||||
char* path;
|
||||
char* save;
|
||||
|
@ -208,7 +144,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
pid_t pid;
|
||||
int flags;
|
||||
int numArgs;
|
||||
LPSTR* pArgs = NULL;
|
||||
char** envp = NULL;
|
||||
|
@ -230,7 +165,6 @@ BOOL _CreateProcessExA(HANDLE hToken, DWORD dwLogonFlags,
|
|||
if (!pArgs)
|
||||
return FALSE;
|
||||
|
||||
flags = 0;
|
||||
|
||||
token = (WINPR_ACCESS_TOKEN*) hToken;
|
||||
|
||||
|
@ -532,7 +466,7 @@ BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode)
|
|||
}
|
||||
|
||||
|
||||
BOOL ProcessHandleCloseHandle(HANDLE handle)
|
||||
static BOOL ProcessHandleCloseHandle(HANDLE handle)
|
||||
{
|
||||
WINPR_PROCESS* process = (WINPR_PROCESS*) handle;
|
||||
free(process);
|
||||
|
@ -586,6 +520,5 @@ HANDLE CreateProcessHandle(pid_t pid)
|
|||
return (HANDLE)process;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ wStream* Stream_New(BYTE* buffer, size_t size)
|
|||
{
|
||||
wStream* s;
|
||||
|
||||
if (!buffer && !size)
|
||||
return NULL;
|
||||
|
||||
s = malloc(sizeof(wStream));
|
||||
|
||||
if (!s)
|
||||
|
|
|
@ -65,6 +65,16 @@ static BOOL TestStream_Verify(wStream* s, int mincap, int len, int pos)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL TestStream_New()
|
||||
{
|
||||
wStream *s = NULL;
|
||||
/* Test creation of a 0-size stream with no buffer */
|
||||
s = Stream_New(NULL, 0);
|
||||
if (s)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static BOOL TestStream_Create(int count, BOOL selfAlloc)
|
||||
{
|
||||
|
@ -266,6 +276,8 @@ int TestStream(int argc, char* argv[])
|
|||
if (!TestStream_Reading())
|
||||
return 4;
|
||||
|
||||
if (!TestStream_New())
|
||||
return 5;
|
||||
/**
|
||||
* FIXME: Add tests for
|
||||
* Stream_Write_*
|
||||
|
|
Loading…
Reference in New Issue