Browse Source

ENGINE-579: save management.db and keys.db to different folder if env variable PEP_APPDATA is set

pEpMIME_windows
Thomas 3 years ago
parent
commit
fc0173604d
4 changed files with 40 additions and 9 deletions
  1. +1
    -0
      src/pEp_internal.h
  2. +12
    -7
      src/pgp_sequoia.c
  3. +26
    -2
      src/platform_windows.cpp
  4. +1
    -0
      src/platform_windows.h

+ 1
- 0
src/pEp_internal.h View File

@ -55,6 +55,7 @@
#include "platform.h"
#ifdef WIN32
#define KEYS_DB windoze_keys_db()
#define LOCAL_DB windoze_local_db()
#define SYSTEM_DB windoze_system_db()
#define LIBGPGME "libgpgme-11.dll"


+ 12
- 7
src/pgp_sequoia.c View File

@ -182,23 +182,26 @@ PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
{
PEP_STATUS status = PEP_STATUS_OK;
#ifdef _WIN32
int sqlite_result;
sqlite_result = sqlite3_open_v2(KEYS_DB,
&session->key_db,
SQLITE_OPEN_READWRITE
| SQLITE_OPEN_CREATE
| SQLITE_OPEN_FULLMUTEX
| SQLITE_OPEN_PRIVATECACHE,
NULL);
#else
// Create the home directory.
char *home_env = NULL;
#ifndef NDEBUG
home_env = getenv("PEP_HOME");
#endif
#ifdef _WIN32
#define PEP_KEYS_PATH "\\pEp\\keys.db"
if (!home_env)
home_env = getenv("LOCALAPPDATA");
#else
#define PEP_KEYS_PATH "/.pEp_keys.db"
if (!home_env)
home_env = getenv("HOME");
#endif
if (!home_env)
ERROR_OUT(NULL, PEP_INIT_GPGME_INIT_FAILED, "HOME unset");
@ -224,6 +227,8 @@ PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
| SQLITE_OPEN_PRIVATECACHE,
NULL);
free(path);
#endif
if (sqlite_result != SQLITE_OK)
ERROR_OUT(NULL, PEP_INIT_CANNOT_OPEN_DB,
"opening keys DB: %s", sqlite3_errmsg(session->key_db));


+ 26
- 2
src/platform_windows.cpp View File

@ -25,6 +25,9 @@
#define WC_ERR_INVALID_CHARS 0x00000080 // error for invalid chars
#endif
#define ENV_PEP_APPDATA "PEP_APPDATA"
#define ENV_PEP_APPDATA_VAL "1"
using namespace std;
static string utf8_string(wstring wstr) {
@ -193,10 +196,31 @@ void *dlsym(void *handle, const char *symbol) {
return (void *) (intptr_t) GetProcAddress((HMODULE) handle, symbol);
}
const char *windoze_keys_db(void) {
static string path;
if (path.length() == 0) {
const char * env = getenv(ENV_PEP_APPDATA);
if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
path = managementPath("%APPDATA%\\pEp", "keys.db");
else
path = managementPath("%LOCALAPPDATA%\\pEp", "keys.db");
}
return path.c_str();
}
const char *windoze_local_db(void) {
static string path;
if (path.length() == 0)
path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
if (path.length() == 0) {
const char * env = getenv(ENV_PEP_APPDATA);
if (env && (strcmp(env, ENV_PEP_APPDATA_VAL) == 0))
path = managementPath("%APPDATA%\\pEp", "management.db");
else
path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
}
return path.c_str();
}


+ 1
- 0
src/platform_windows.h View File

@ -75,6 +75,7 @@ char *stpcpy(char *dst, const char *src);
size_t strlcpy(char* dst, const char* src, size_t size);
size_t strlcat(char* dst, const char* src, size_t size);
const char *windoze_keys_db(void);
const char *windoze_local_db(void);
const char *windoze_system_db(void);
const char *gpg_conf(void);


Loading…
Cancel
Save