ENGINE-579: save management.db and keys.db to different folder if env variable PEP_APPDATA is set sequoia_windows
authorThomas
Fri, 14 Jun 2019 14:45:26 +0200
branchsequoia_windows
changeset 383565f3c7d59eb1
parent 3833 97d3517be4a3
child 3842 5be8219250cb
ENGINE-579: save management.db and keys.db to different folder if env variable PEP_APPDATA is set
src/pEp_internal.h
src/pgp_sequoia.c
src/platform_windows.cpp
src/platform_windows.h
     1.1 --- a/src/pEp_internal.h	Fri Jun 14 07:54:26 2019 +0200
     1.2 +++ b/src/pEp_internal.h	Fri Jun 14 14:45:26 2019 +0200
     1.3 @@ -55,6 +55,7 @@
     1.4  #include "platform.h"
     1.5  
     1.6  #ifdef WIN32
     1.7 +#define KEYS_DB windoze_keys_db()
     1.8  #define LOCAL_DB windoze_local_db()
     1.9  #define SYSTEM_DB windoze_system_db()
    1.10  #define LIBGPGME "libgpgme-11.dll"
     2.1 --- a/src/pgp_sequoia.c	Fri Jun 14 07:54:26 2019 +0200
     2.2 +++ b/src/pgp_sequoia.c	Fri Jun 14 14:45:26 2019 +0200
     2.3 @@ -182,23 +182,26 @@
     2.4  {
     2.5      PEP_STATUS status = PEP_STATUS_OK;
     2.6  
     2.7 +#ifdef _WIN32
     2.8 +	int sqlite_result;
     2.9 +	sqlite_result = sqlite3_open_v2(KEYS_DB,
    2.10 +		&session->key_db,
    2.11 +		SQLITE_OPEN_READWRITE
    2.12 +		| SQLITE_OPEN_CREATE
    2.13 +		| SQLITE_OPEN_FULLMUTEX
    2.14 +		| SQLITE_OPEN_PRIVATECACHE,
    2.15 +		NULL);
    2.16 +#else
    2.17      // Create the home directory.
    2.18      char *home_env = NULL;
    2.19  #ifndef NDEBUG
    2.20      home_env = getenv("PEP_HOME");
    2.21  #endif
    2.22  
    2.23 -#ifdef _WIN32
    2.24 -    #define PEP_KEYS_PATH "\\pEp\\keys.db"
    2.25 -
    2.26 -    if (!home_env)
    2.27 -        home_env = getenv("LOCALAPPDATA");
    2.28 -#else
    2.29      #define PEP_KEYS_PATH "/.pEp_keys.db"
    2.30  
    2.31      if (!home_env)
    2.32          home_env = getenv("HOME");
    2.33 -#endif
    2.34  
    2.35      if (!home_env)
    2.36          ERROR_OUT(NULL, PEP_INIT_GPGME_INIT_FAILED, "HOME unset");
    2.37 @@ -224,6 +227,8 @@
    2.38                                      | SQLITE_OPEN_PRIVATECACHE,
    2.39                                      NULL);
    2.40      free(path);
    2.41 +#endif
    2.42 +
    2.43      if (sqlite_result != SQLITE_OK)
    2.44          ERROR_OUT(NULL, PEP_INIT_CANNOT_OPEN_DB,
    2.45                    "opening keys DB: %s", sqlite3_errmsg(session->key_db));
     3.1 --- a/src/platform_windows.cpp	Fri Jun 14 07:54:26 2019 +0200
     3.2 +++ b/src/platform_windows.cpp	Fri Jun 14 14:45:26 2019 +0200
     3.3 @@ -25,6 +25,9 @@
     3.4  #define WC_ERR_INVALID_CHARS      0x00000080  // error for invalid chars
     3.5  #endif
     3.6  
     3.7 +#define ENV_PEP_APPDATA "PEP_APPDATA"
     3.8 +#define ENV_PEP_APPDATA_VAL "1" 
     3.9 +
    3.10  using namespace std;
    3.11  
    3.12  static string utf8_string(wstring wstr) {
    3.13 @@ -193,10 +196,31 @@
    3.14  	return (void *) (intptr_t) GetProcAddress((HMODULE) handle, symbol);
    3.15  }
    3.16  
    3.17 +const char *windoze_keys_db(void) {
    3.18 +	static string path;
    3.19 +	if (path.length() == 0) {
    3.20 +
    3.21 +		const char * env = getenv(ENV_PEP_APPDATA);
    3.22 +
    3.23 +		if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
    3.24 +			path = managementPath("%APPDATA%\\pEp", "keys.db");
    3.25 +		else
    3.26 +			path = managementPath("%LOCALAPPDATA%\\pEp", "keys.db");
    3.27 +	}
    3.28 +	return path.c_str();
    3.29 +}
    3.30 +
    3.31  const char *windoze_local_db(void) {
    3.32  	static string path;
    3.33 -	if (path.length() == 0)
    3.34 -        path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
    3.35 +	if (path.length() == 0) {
    3.36 +
    3.37 +		const char * env = getenv(ENV_PEP_APPDATA);
    3.38 +
    3.39 +		if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
    3.40 +			path = managementPath("%APPDATA%\\pEp", "management.db");
    3.41 +		else
    3.42 +			path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
    3.43 +	}
    3.44      return path.c_str();
    3.45  }
    3.46  
     4.1 --- a/src/platform_windows.h	Fri Jun 14 07:54:26 2019 +0200
     4.2 +++ b/src/platform_windows.h	Fri Jun 14 14:45:26 2019 +0200
     4.3 @@ -75,6 +75,7 @@
     4.4  size_t strlcpy(char* dst, const	char* src, size_t size);
     4.5  size_t strlcat(char* dst, const	char* src, size_t size);
     4.6  
     4.7 +const char *windoze_keys_db(void);
     4.8  const char *windoze_local_db(void);
     4.9  const char *windoze_system_db(void);
    4.10  const char *gpg_conf(void);