Use wide char file paths for license

This commit is contained in:
Armin Novak 2021-01-27 15:03:29 +01:00 committed by akallabeth
parent 773cfcd6da
commit 54e02e1642
3 changed files with 96 additions and 7 deletions

View File

@ -217,6 +217,32 @@ static FILE* fopen_wrap(const char* path, const char* mode)
#endif
}
static BOOL path_exists(const char* path)
{
BOOL rc = FALSE;
WCHAR* wpath = NULL;
if (!path)
return FALSE;
if (ConvertToUnicode(CP_UTF8, 0, path, -1, &wpath, 0) <= 0)
return FALSE;
rc = PathFileExistsW(wpath);
free(wpath);
return rc;
}
static BOOL path_make(const char* path, LPSECURITY_ATTRIBUTES lpAttributes)
{
BOOL rc = FALSE;
WCHAR* wpath = NULL;
if (!path)
return FALSE;
if (ConvertToUnicode(CP_UTF8, 0, path, -1, &wpath, 0) <= 0)
return FALSE;
rc = PathMakePathW(wpath, lpAttributes);
free(wpath);
return rc;
}
static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, char* hostname)
{
char hash[41];
@ -224,12 +250,14 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, char
char* licenseStorePath = NULL;
char filename[MAX_PATH], filenameNew[MAX_PATH];
char *filepath = NULL, *filepathNew = NULL;
WCHAR* wFilepathNew = NULL;
WCHAR* wFilepath = NULL;
size_t written;
BOOL ret = FALSE;
if (!PathFileExistsA(settings->ConfigPath))
if (!path_exists(settings->ConfigPath))
{
if (!PathMakePathA(settings->ConfigPath, 0))
if (!path_make(settings->ConfigPath, 0))
{
WLog_ERR(TAG, "error creating directory '%s'", settings->ConfigPath);
goto out;
@ -240,9 +268,9 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, char
if (!(licenseStorePath = GetCombinedPath(settings->ConfigPath, licenseStore)))
goto out;
if (!PathFileExistsA(licenseStorePath))
if (!path_exists(licenseStorePath))
{
if (!PathMakePathA(licenseStorePath, 0))
if (!path_make(licenseStorePath, 0))
{
WLog_ERR(TAG, "error creating directory '%s'", licenseStorePath);
goto out;
@ -260,6 +288,10 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, char
if (!(filepathNew = GetCombinedPath(licenseStorePath, filenameNew)))
goto out;
if (ConvertToUnicode(CP_UTF8, 0, filepathNew, -1, &wFilepathNew, 0) <= 0)
goto out;
if (ConvertToUnicode(CP_UTF8, 0, filepath, -1, &wFilepath, 0) <= 0)
goto out;
fp = fopen_wrap(filepathNew, "wb");
if (!fp)
@ -270,14 +302,16 @@ static BOOL saveCal(rdpSettings* settings, const BYTE* data, size_t length, char
if (written != 1)
{
DeleteFileA(filepathNew);
DeleteFileW(wFilepathNew);
goto out;
}
ret = MoveFileExA(filepathNew, filepath, MOVEFILE_REPLACE_EXISTING);
ret = MoveFileExW(wFilepathNew, wFilepath, MOVEFILE_REPLACE_EXISTING);
out:
free(wFilepathNew);
free(filepathNew);
free(wFilepath);
free(filepath);
free(licenseStorePath);
return ret;
@ -1446,7 +1480,7 @@ BOOL license_answer_license_request(rdpLicense* license)
{
wStream* s;
BYTE* license_data = NULL;
size_t license_size = 0;
int license_size = 0;
BOOL status;
char* username;

View File

@ -312,6 +312,7 @@ extern "C"
WINPR_API char* GetCombinedPath(const char* basePath, const char* subPath);
WINPR_API BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes);
WINPR_API BOOL PathMakePathW(LPCWSTR path, LPSECURITY_ATTRIBUTES lpAttributes);
#if !defined(_WIN32) || defined(_UWP)

View File

@ -526,6 +526,60 @@ BOOL PathMakePathA(LPCSTR path, LPSECURITY_ATTRIBUTES lpAttributes)
#endif
}
BOOL PathMakePathW(LPCWSTR path, LPSECURITY_ATTRIBUTES lpAttributes)
{
#if defined(_UWP)
return FALSE;
#elif defined(_WIN32)
return (SHCreateDirectoryExW(NULL, path, lpAttributes) == ERROR_SUCCESS);
#else
const WCHAR delim = PathGetSeparatorW(PATH_STYLE_NATIVE);
char* dup;
char* p;
BOOL result = TRUE;
/* we only operate on a non-null, absolute path */
#if defined(__OS2__)
if (!path)
return FALSE;
#else
if (!path || *path != delim)
return FALSE;
#endif
if (ConvertFromUnicode(CP_UTF8, 0, path, -1, &dup, 0, NULL, NULL))
return FALSE;
#ifdef __OS2__
p = (strlen(dup) > 3) && (dup[1] == L':') && (dup[2] == delim)) ? &dup[3] : dup;
while (p)
#else
for (p = dup; p;)
#endif
{
if ((p = strchr(p + 1, delim)))
*p = '\0';
if (mkdir(dup, 0777) != 0)
if (errno != EEXIST)
{
result = FALSE;
break;
}
if (p)
*p = delim;
}
free(dup);
return (result);
#endif
}
#if !defined(_WIN32) || defined(_UWP)
BOOL PathIsRelativeA(LPCSTR pszPath)