diff options
author | 90 <hi@90.gripe> | 2024-04-26 16:22:03 +0100 |
---|---|---|
committer | 90 <hi@90.gripe> | 2024-04-26 16:22:03 +0100 |
commit | 337c136ce018fc8d9d12b9e188634925238d11cc (patch) | |
tree | 5733614d537fa373cc5376cdc9b8e29a8de4432c /common | |
parent | 119a5ff7d2e2543e51947d35be7c5f84f74b3243 (diff) | |
download | tigervnc-337c136ce018fc8d9d12b9e188634925238d11cc.tar.gz tigervnc-337c136ce018fc8d9d12b9e188634925238d11cc.zip |
Implement XDG Base Directory paths, deprecate ~/.vnc
Diffstat (limited to 'common')
-rw-r--r-- | common/os/os.cxx | 54 | ||||
-rw-r--r-- | common/os/os.h | 24 | ||||
-rw-r--r-- | common/rfb/CSecurityTLS.cxx | 11 |
3 files changed, 45 insertions, 44 deletions
diff --git a/common/os/os.cxx b/common/os/os.cxx index 5c49ce12..35f87b03 100644 --- a/common/os/os.cxx +++ b/common/os/os.cxx @@ -24,6 +24,8 @@ #include <os/os.h> #include <assert.h> +#include <sys/types.h> +#include <sys/stat.h> #ifndef WIN32 #include <pwd.h> @@ -31,18 +33,18 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/types.h> -#include <sys/stat.h> #include <unistd.h> #else #include <windows.h> #include <wininet.h> /* MinGW needs it */ #include <shlobj.h> +#define stat _stat #endif static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_def) { - static char dir[PATH_MAX]; + static char dir[PATH_MAX], legacy[PATH_MAX]; + struct stat st; #ifndef WIN32 char *homedir, *xdgdir; @@ -67,23 +69,17 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ if (userDir) return homedir; - // check if (deprecated) legacy path exists and use that if so - snprintf(dir, sizeof(dir), "%s/.vnc", homedir); - struct stat st; - - if (stat(dir, &st) == 0) - return dir; - - if (xdg_def != NULL) { - xdgdir = getenv(xdg_env); - if (xdgdir != NULL) - snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir); - else - snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def); - } + xdgdir = getenv(xdg_env); + if (xdgdir != NULL && xdgdir[0] == '/') + snprintf(dir, sizeof(dir), "%s/tigervnc", xdgdir); + else + snprintf(dir, sizeof(dir), "%s/%s/tigervnc", homedir, xdg_def); - return dir; + snprintf(legacy, sizeof(legacy), "%s/.vnc", homedir); #else + (void) xdg_def; + (void) xdg_env; + if (userDir) ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_PROFILE, FALSE); else @@ -95,13 +91,20 @@ static const char* getvncdir(bool userDir, const char *xdg_env, const char *xdg_ if (userDir) return dir; - if (strlen(dir) + strlen("\\vnc") >= sizeof(dir)) + ret = SHGetSpecialFolderPath(NULL, legacy, CSIDL_APPDATA, FALSE); + + if (ret == FALSE) return NULL; - strcat(dir, "\\vnc"); + if (strlen(dir) + strlen("\\TigerVNC") >= sizeof(dir)) + return NULL; + if (strlen(legacy) + strlen("\\vnc") >= sizeof(legacy)) + return NULL; - return dir; + strcat(dir, "\\TigerVNC"); + strcat(legacy, "\\vnc"); #endif + return (stat(dir, &st) != 0 && stat(legacy, &st) == 0) ? legacy : dir; } const char* os::getuserhomedir() @@ -114,13 +117,12 @@ const char* os::getvncconfigdir() return getvncdir(false, "XDG_CONFIG_HOME", ".config"); } -const char* os::getvncstatedir() +const char* os::getvncdatadir() { - return getvncdir(false, "XDG_STATE_HOME", ".local/state"); + return getvncdir(false, "XDG_DATA_HOME", ".local/share"); } -/* deprecated */ -const char* os::getvnchomedir() +const char* os::getvncstatedir() { - return getvncdir(false, NULL, NULL); + return getvncdir(false, "XDG_STATE_HOME", ".local/state"); } diff --git a/common/os/os.h b/common/os/os.h index 0561d36c..8e522676 100644 --- a/common/os/os.h +++ b/common/os/os.h @@ -35,32 +35,32 @@ namespace os { * Get VNC config directory. On Unix-like systems, this is either: * - $XDG_CONFIG_HOME/tigervnc * - $HOME/.config/tigervnc - * On Windows, this is simply %APPDATA%/vnc/. + * On Windows, this is simply %APPDATA%/TigerVNC/. * * Returns NULL on failure. */ const char* getvncconfigdir(); /* - * Get VNC state (logs) directory. On Unix-like systems, this is either: - * - $XDG_STATE_HOME/tigervnc - * - $HOME/.local/state/tigervnc - * On Windows, this is simply %APPDATA%/vnc/. + * Get VNC data directory used for X.509 known hosts. + * On Unix-like systems, this is either: + * - $XDG_DATA_HOME/tigervnc + * - $HOME/.local/share/tigervnc + * On Windows, this is simply %APPDATA%/TigerVNC/. * * Returns NULL on failure. */ - const char* getvncstatedir(); + const char* getvncdatadir(); /* - * Get legacy VNC home directory ($HOME/.vnc on Unix-likes). - * If HOME environment variable is set then it is used. - * Otherwise home directory is obtained via getpwuid function. + * Get VNC state (logs) directory. On Unix-like systems, this is either: + * - $XDG_STATE_HOME/tigervnc + * - $HOME/.local/state/tigervnc + * On Windows, this is simply %APPDATA%/TigerVNC/. * * Returns NULL on failure. - * - * Deprecated. */ - const char* getvnchomedir(); + const char* getvncstatedir(); } diff --git a/common/rfb/CSecurityTLS.cxx b/common/rfb/CSecurityTLS.cxx index e2edde89..cc0ca89f 100644 --- a/common/rfb/CSecurityTLS.cxx +++ b/common/rfb/CSecurityTLS.cxx @@ -79,7 +79,6 @@ static const char* configdirfn(const char* fn) return ""; snprintf(full_path, sizeof(full_path), "%s/%s", configdir, fn); - return full_path; } @@ -308,7 +307,7 @@ void CSecurityTLS::checkSession() int err; bool hostname_match; - const char *configDir; + const char *hostsDir; gnutls_datum_t info; size_t len; @@ -385,14 +384,14 @@ void CSecurityTLS::checkSession() /* Certificate has some user overridable problems, so TOFU time */ - configDir = os::getvncconfigdir(); - if (configDir == NULL) { - throw AuthFailureException("Could not obtain VNC config directory " + hostsDir = os::getvncdatadir(); + if (hostsDir == NULL) { + throw AuthFailureException("Could not obtain VNC data directory " "path for known hosts storage"); } std::string dbPath; - dbPath = (std::string)configDir + "/x509_known_hosts"; + dbPath = (std::string)hostsDir + "/x509_known_hosts"; err = gnutls_verify_stored_pubkey(dbPath.c_str(), NULL, client->getServerName(), NULL, |