From d1223d3799ad192bc47f4631c16027b41cd47a23 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 09:02:29 +0200 Subject: [PATCH 1/8] Fixed windows known path locations. --- winpr/libwinpr/path/shell.c | 60 +++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 2cfa4466e..d1398b906 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -33,6 +33,12 @@ #include +#if defined(WIN32) +#include +#endif + +static char* GetPath_XDG_CONFIG_HOME(); + /** * SHGetKnownFolderPath function: * http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188/ @@ -43,7 +49,7 @@ * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html */ -char* GetEnvAlloc(LPCSTR lpName) +static char* GetEnvAlloc(LPCSTR lpName) { DWORD length; char* env = NULL; @@ -62,7 +68,7 @@ char* GetEnvAlloc(LPCSTR lpName) return env; } -char* GetPath_HOME() +static char* GetPath_HOME() { char* path = NULL; @@ -80,7 +86,7 @@ char* GetPath_HOME() return path; } -char* GetPath_TEMP() +static char* GetPath_TEMP() { char* path = NULL; @@ -96,11 +102,14 @@ char* GetPath_TEMP() return path; } -char* GetPath_XDG_DATA_HOME() +static char* GetPath_XDG_DATA_HOME() { char* path = NULL; - char* home = NULL; +#if defined(WIN32) + path = GetPath_XDG_CONFIG_HOME(); +#else + char* home = NULL; /** * There is a single base directory relative to which user-specific data files should be written. * This directory is defined by the environment variable $XDG_DATA_HOME. @@ -127,15 +136,28 @@ char* GetPath_XDG_DATA_HOME() sprintf(path, "%s%s", home, "/.local/share"); free(home); +#endif return path; } -char* GetPath_XDG_CONFIG_HOME() +static char* GetPath_XDG_CONFIG_HOME() { char* path = NULL; - char* home = NULL; +#if defined(WIN32) + path = calloc(MAX_PATH, sizeof(char)); + if (!path) + return NULL; + + if (SHGetFolderPathA(0, CSIDL_APPDATA, NULL, + SHGFP_TYPE_CURRENT, path) != S_OK) + { + free(path); + return NULL; + } +#else + char* home = NULL; /** * There is a single base directory relative to which user-specific configuration files should be written. * This directory is defined by the environment variable $XDG_CONFIG_HOME. @@ -166,15 +188,22 @@ char* GetPath_XDG_CONFIG_HOME() sprintf(path, "%s%s", home, "/.config"); free(home); +#endif return path; } -char* GetPath_XDG_CACHE_HOME() +static char* GetPath_XDG_CACHE_HOME() { char* path = NULL; char* home = NULL; +#if defined(WIN32) + home = GetPath_XDG_RUNTIME_DIR(); + + path = GetCombinedPath(home, "cache"); + free(home); +#else /** * There is a single base directory relative to which user-specific non-essential (cached) data should be written. * This directory is defined by the environment variable $XDG_CACHE_HOME. @@ -201,14 +230,26 @@ char* GetPath_XDG_CACHE_HOME() sprintf(path, "%s%s", home, "/.cache"); free(home); +#endif return path; } -char* GetPath_XDG_RUNTIME_DIR() +static char* GetPath_XDG_RUNTIME_DIR() { char* path = NULL; +#if defined(WIN32) + path = calloc(MAX_PATH, sizeof(char)); + if (!path) + return NULL; + if (SHGetFolderPathA(0, CSIDL_LOCAL_APPDATA, NULL, + SHGFP_TYPE_CURRENT, path) != S_OK) + { + free(path); + return NULL; + } +#else /** * There is a single base directory relative to which user-specific runtime files and other file objects should be placed. * This directory is defined by the environment variable $XDG_RUNTIME_DIR. @@ -237,6 +278,7 @@ char* GetPath_XDG_RUNTIME_DIR() */ path = GetEnvAlloc("XDG_RUNTIME_DIR"); +#endif if (path) return path; From 8f68b9c2618ca326506eb878c79f59587043bc92 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 09:07:17 +0200 Subject: [PATCH 2/8] Using vendor/product scheme for settings now. --- CMakeLists.txt | 8 ++++++-- config.h.in | 3 +++ libfreerdp/core/settings.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a2e8e5baf..02aefd4e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,10 @@ if(NOT DEFINED VENDOR) set(VENDOR "FreeRDP" CACHE STRING "FreeRDP package vendor") endif() +if(NOT DEFINED PRODUCT) + set(PRODUCT "FreeRDP" CACHE STRING "FreeRDP package name") +endif() + if(NOT DEFINED FREERDP_VENDOR) set(FREERDP_VENDOR 1) endif() @@ -284,8 +288,8 @@ if(WIN32) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") # Set product and vendor for dll and exe version information. - set(RC_VERSION_VENDOR "FreeRDP") - set(RC_VERSION_PRODUCT "FreeRDP") + set(RC_VERSION_VENDOR ${VENDOR}) + set(RC_VERSION_PRODUCT ${PRODUCT}) set(RC_VERSION_PATCH ${BUILD_NUMBER}) set(RC_VERSION_DESCRIPTION ${GIT_REVISION}) diff --git a/config.h.in b/config.h.in index 528804066..ce212dd59 100644 --- a/config.h.in +++ b/config.h.in @@ -14,6 +14,9 @@ #define CMAKE_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" #define CMAKE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" +#define FREERDP_VENDOR_STRING "${VENDOR}" +#define FREERDP_PRODUCT_STRING "${PRODUCT}" + /* Include files */ #cmakedefine HAVE_FCNTL_H #cmakedefine HAVE_UNISTD_H diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 8015a4118..614e6b05e 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -195,13 +195,14 @@ void settings_get_computer_name(rdpSettings* settings) GetComputerNameExA(ComputerNameNetBIOS, NULL, &nSize); settings->ComputerName = (char*) malloc(nSize); - if (!settings->ComputerName) - return; + if (!settings->ComputerName) + return; GetComputerNameExA(ComputerNameNetBIOS, settings->ComputerName, &nSize); } rdpSettings* freerdp_settings_new(DWORD flags) { + char* base; rdpSettings* settings; settings = (rdpSettings*) calloc(1, sizeof(rdpSettings)); @@ -471,7 +472,12 @@ rdpSettings* freerdp_settings_new(DWORD flags) settings->HomePath = GetKnownPath(KNOWN_PATH_HOME); if (!settings->HomePath) goto out_fail; - settings->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp"); + base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, + FREERDP_VENDOR_STRING); + if (base) + settings->ConfigPath = GetCombinedPath(base, FREERDP_PRODUCT_STRING); + free (base); + if (!settings->ConfigPath) goto out_fail; @@ -778,7 +784,7 @@ out_fail: void freerdp_settings_free(rdpSettings* settings) { if (!settings) - return; + return; free(settings->ServerHostname); free(settings->Username); free(settings->Password); From 70df8d8ba992b9118795c8ba481ce41bb0e6ee30 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 09:45:46 +0200 Subject: [PATCH 3/8] Fixed static function arguments. --- winpr/libwinpr/path/shell.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index d1398b906..87b31cc9d 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -37,7 +37,8 @@ #include #endif -static char* GetPath_XDG_CONFIG_HOME(); +static char* GetPath_XDG_CONFIG_HOME(void); +static char* GetPath_XDG_RUNTIME_DIR(void); /** * SHGetKnownFolderPath function: @@ -68,7 +69,7 @@ static char* GetEnvAlloc(LPCSTR lpName) return env; } -static char* GetPath_HOME() +static char* GetPath_HOME(void) { char* path = NULL; @@ -86,7 +87,7 @@ static char* GetPath_HOME() return path; } -static char* GetPath_TEMP() +static char* GetPath_TEMP(void) { char* path = NULL; @@ -102,7 +103,7 @@ static char* GetPath_TEMP() return path; } -static char* GetPath_XDG_DATA_HOME() +static char* GetPath_XDG_DATA_HOME(void) { char* path = NULL; @@ -141,7 +142,7 @@ static char* GetPath_XDG_DATA_HOME() return path; } -static char* GetPath_XDG_CONFIG_HOME() +static char* GetPath_XDG_CONFIG_HOME(void) { char* path = NULL; @@ -193,7 +194,7 @@ static char* GetPath_XDG_CONFIG_HOME() return path; } -static char* GetPath_XDG_CACHE_HOME() +static char* GetPath_XDG_CACHE_HOME(void) { char* path = NULL; char* home = NULL; @@ -235,7 +236,7 @@ static char* GetPath_XDG_CACHE_HOME() return path; } -static char* GetPath_XDG_RUNTIME_DIR() +char* GetPath_XDG_RUNTIME_DIR(void) { char* path = NULL; #if defined(WIN32) From dd1a03191deb3334f06430eddd4be893dba8fc6f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 09:48:32 +0200 Subject: [PATCH 4/8] Fixed settings path creation. --- libfreerdp/core/settings.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 614e6b05e..d5d0e0891 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -473,9 +473,11 @@ rdpSettings* freerdp_settings_new(DWORD flags) if (!settings->HomePath) goto out_fail; base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, - FREERDP_VENDOR_STRING); - if (base) + FREERDP_VENDOR_STRING); + if (base && CreateDirectoryA(base, NULL)) + { settings->ConfigPath = GetCombinedPath(base, FREERDP_PRODUCT_STRING); + } free (base); if (!settings->ConfigPath) From d3a88014da19111d4c71efda89e7a6b9127d8207 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 10:00:43 +0200 Subject: [PATCH 5/8] Fixed directory creation checks. --- libfreerdp/core/settings.c | 5 ++++- winpr/libwinpr/path/shell.c | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index d5d0e0891..e4bcf47e8 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -474,9 +474,12 @@ rdpSettings* freerdp_settings_new(DWORD flags) goto out_fail; base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, FREERDP_VENDOR_STRING); - if (base && CreateDirectoryA(base, NULL)) + if (base) { settings->ConfigPath = GetCombinedPath(base, FREERDP_PRODUCT_STRING); + if (!PathFileExistsA(base)) + if (!CreateDirectoryA(base, NULL)) + settings->ConfigPath = NULL; } free (base); diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 87b31cc9d..85a9a73ac 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -203,6 +203,9 @@ static char* GetPath_XDG_CACHE_HOME(void) home = GetPath_XDG_RUNTIME_DIR(); path = GetCombinedPath(home, "cache"); + if (!PathFileExistsA(path)) + if (!CreateDirectoryA(path, NULL)) + path = NULL; free(home); #else /** From e6283db1b99d15b4bb46d3d53c2974f1f870f940 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 10:10:13 +0200 Subject: [PATCH 6/8] Added missing NULL check. --- winpr/libwinpr/path/shell.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 85a9a73ac..fe913db7e 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -201,11 +201,13 @@ static char* GetPath_XDG_CACHE_HOME(void) #if defined(WIN32) home = GetPath_XDG_RUNTIME_DIR(); - - path = GetCombinedPath(home, "cache"); - if (!PathFileExistsA(path)) - if (!CreateDirectoryA(path, NULL)) - path = NULL; + if (home) + { + path = GetCombinedPath(home, "cache"); + if (!PathFileExistsA(path)) + if (!CreateDirectoryA(path, NULL)) + path = NULL; + } free(home); #else /** From ea1dae219d6db5a9e3eaaf21b6c4de43437fbc7c Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 11:53:25 +0200 Subject: [PATCH 7/8] Added config compatibility for default builds. --- libfreerdp/core/settings.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index e4bcf47e8..bb4fbc186 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -472,16 +472,36 @@ rdpSettings* freerdp_settings_new(DWORD flags) settings->HomePath = GetKnownPath(KNOWN_PATH_HOME); if (!settings->HomePath) goto out_fail; - base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, - FREERDP_VENDOR_STRING); - if (base) + + /* For default FreeRDP continue using same config directory + * as in old releases. + * Custom builds use / as config folder. */ + if (_stricmp(FREERDP_VENDOR_STRING, FREERDP_PRODUCT_STRING)) { - settings->ConfigPath = GetCombinedPath(base, FREERDP_PRODUCT_STRING); - if (!PathFileExistsA(base)) - if (!CreateDirectoryA(base, NULL)) - settings->ConfigPath = NULL; + base = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, + FREERDP_VENDOR_STRING); + if (base) + { + settings->ConfigPath = GetCombinedPath( + base, + FREERDP_PRODUCT_STRING); + if (!PathFileExistsA(base)) + if (!CreateDirectoryA(base, NULL)) + settings->ConfigPath = NULL; + } + free (base); + } else { + int i; + char product[MAX_PATH]; + + memset(product, 0, sizeof(product)); + for (i=0; iConfigPath = GetKnownSubPath( + KNOWN_PATH_XDG_CONFIG_HOME, + product); } - free (base); if (!settings->ConfigPath) goto out_fail; From 6b4cc2ff256ac9b51c9393dce30bb0ddeb1ab1ab Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 2 Jun 2015 12:45:14 +0200 Subject: [PATCH 8/8] Fixed size of string buffer. --- libfreerdp/core/settings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index bb4fbc186..806d9bf03 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -492,10 +492,10 @@ rdpSettings* freerdp_settings_new(DWORD flags) free (base); } else { int i; - char product[MAX_PATH]; + char product[sizeof(FREERDP_PRODUCT_STRING)]; memset(product, 0, sizeof(product)); - for (i=0; iConfigPath = GetKnownSubPath(