Browse Source

adding features

ENGINE-325
Volker Birk 2 years ago
parent
commit
644e307684
8 changed files with 188 additions and 27 deletions
  1. +10
    -2
      Makefile.conf
  2. +9
    -1
      src/Makefile
  3. +14
    -0
      src/pEpEngine.h
  4. +6
    -3
      src/pEp_internal.h
  5. +83
    -18
      src/platform_unix.c
  6. +15
    -0
      src/platform_unix.h
  7. +41
    -3
      src/platform_windows.cpp
  8. +10
    -0
      src/platform_windows.h

+ 10
- 2
Makefile.conf View File

@ -39,8 +39,16 @@ endif
# Installation path prefix for libraries and binaries, except for system.db
PREFIX=$(HOME)
# Installation path for system.db
SYSTEM_DB=/usr/local/share/pEp/system.db
# pEp files and directories
#
# the PER_USER_DIRECTORY will be in $(HOME), respectively
# in debug builds the PER_USER_DIRECTORY will be in $(PEP_HOME) instead if set
#
# PER_MACHINE_DIRECTORY is calculated depending on platform; overwrite if
# necessary
#PER_USER_DIRECTORY=.pEp
#PER_MACHINE_DIRECTORY=/usr/local/share/pEp
# Filename of the pEpEngine library
ifeq ($(BUILD_FOR),Linux)


+ 9
- 1
src/Makefile View File

@ -5,7 +5,15 @@
include ../Makefile.conf
CFLAGS+= $(ETPAN_INC) $(PEP_MIME_INC) -I../asn.1 -DSYSTEM_DB=\"$(SYSTEM_DB)\" $(EXTRA_MACROS)
ifdef PER_USER_DIRECTORY
EXTRA_MACROS+= -DPER_USER_DIRECTORY=$(PER_USER_DIRECTORY)
endif
ifdef PER_MACHINE_DIRECTORY
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=$(PER_MACHINE_DIRECTORY)
endif
CFLAGS+= $(ETPAN_INC) $(PEP_MIME_INC) -I../asn.1 $(EXTRA_MACROS)
LDFLAGS+= $(ETPAN_LIB) $(PEP_MIME_LIB) -L../asn.1 -shared
LDLIBS+= -lc -lasn1
NO_SOURCE=


+ 14
- 0
src/pEpEngine.h View File

@ -1293,6 +1293,20 @@ DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session,
pEp_identity *identity,
bool* is_pEp);
// per_user_directory() - returns the directory for pEp management db
//
// return_value:
// path to actual per user directory or NULL on failure
DYNAMIC_API const char *per_user_directory(void);
// per_machine_directory() - returns the directory for pEp system db
//
// return value:
// path to actual per user directory or NULL on failure
DYNAMIC_API const char *per_machine_directory(void);
DYNAMIC_API PEP_STATUS reset_pEptest_hack(PEP_SESSION session);


+ 6
- 3
src/pEp_internal.h View File

@ -24,7 +24,7 @@
// default keyserver
#ifndef DEFAULT_KEYSERVER
#define DEFAULT_KEYSERVER "hkp://keys.gnupg.net"
#define DEFAULT_KEYSERVER "hkps://keys.openpgp.org"
#endif
// crashdump constants
@ -73,8 +73,10 @@
#else
#define LOCAL_DB unix_local_db(false)
#endif
#ifndef SYSTEM_DB
#define SYSTEM_DB "/usr/share/pEp/system.db"
#ifdef ANDROID
#define SYSTEM_DB android_system_db()
#else
#define SYSTEM_DB unix_system_db()
#endif
#ifndef LIBGPGME
#define LIBGPGME "libgpgme-pthread.so"
@ -563,3 +565,4 @@ static inline int Sqlite3_step(sqlite3_stmt* stmt)
} while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
return rc;
}

+ 83
- 18
src/platform_unix.c View File

@ -9,6 +9,7 @@
#endif
#endif
#include <stdbool.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
@ -22,23 +23,17 @@
#include <regex.h>
#include "platform_unix.h"
#include "dynamic_api.h"
#define MAX_PATH 1024
#ifndef LOCAL_DB_FILENAME
#define OLD_LOCAL_DB_FILENAME ".pEp_management.db"
#define OLD_KEYS_DB_FILENAME ".pEp_keys.db"
#define LOCAL_DB_DIR ".pEp"
#define LOCAL_DB_FILENAME "management.db"
#define KEYS_DB_FILENAME "keys.db"
#endif
#define SYSTEM_DB_FILENAME "system.db"
#ifndef bool
#define bool int
#define true 1
#define false 0
#endif
#ifdef ANDROID
#include <uuid.h>
@ -310,11 +305,7 @@ static void _move(const char *o, const char *ext, const char *n)
free(_new);
}
#ifdef NDEBUG
const char *unix_local_db(void)
#else
const char *unix_local_db(int reset)
#endif
DYNAMIC_API const char *per_user_directory(void)
{
static char *path = NULL;
if (path)
@ -326,24 +317,56 @@ const char *unix_local_db(int reset)
if (!home)
#endif
home = getenv("HOME");
assert(home);
if (!home)
return NULL;
path = strdup(home);
assert(path);
if (!path)
return NULL;
char *path_c = NULL;
char *old_path = NULL;
char *old_path_c = NULL;
char *_path = _stradd(&path, "/");
if (!_path)
goto error;
_path = _stradd(&path, LOCAL_DB_DIR);
_path = _stradd(&path, PER_USER_DIRECTORY);
if (!_path)
goto error;
return path;
error:
_empty(&path);
return NULL;
}
#ifdef NDEBUG
const char *unix_local_db(void)
#else
const char *unix_local_db(int reset)
#endif
{
static char *path = NULL;
#ifdef NDEBUG
if (path)
#else
if (path && !reset)
#endif
return path;
if (!per_user_directory())
return NULL;
path = strdup(per_user_directory());
assert(path);
if (!path)
return NULL;
char *path_c = NULL;
char *old_path = NULL;
char *old_path_c = NULL;
struct stat dir;
int r = stat(path, &dir);
if (r) {
@ -358,7 +381,7 @@ const char *unix_local_db(int reset)
}
}
_path = _stradd(&path, "/");
char *_path = _stradd(&path, "/");
if (!_path)
goto error;
@ -378,6 +401,16 @@ const char *unix_local_db(int reset)
if (errno == ENOENT) {
// we do not have management.db yet, let's test if we need to move
// one with the old name
const char *home = NULL;
#ifndef NDEBUG
home = getenv("PEP_HOME");
if (!home)
#endif
home = getenv("HOME");
// we were already checking for HOME existing, so this is only a
// safeguard
assert(home);
old_path = strdup(home);
assert(old_path);
if (!old_path)
@ -643,3 +676,35 @@ const char *gpg_agent_conf(int reset)
return NULL;
}
#endif
DYNAMIC_API const char *per_machine_directory(void)
{
return PER_MACHINE_DIRECTORY;
}
const char *unix_system_db(void)
{
static char *path = NULL;
if (path)
return path;
path = strdup(per_machine_directory());
assert(path);
if (!path)
return NULL;
char *_path = _stradd(&path, "/");
if (!_path)
goto error;
_path = _stradd(&path, SYSTEM_DB_FILENAME);
if (!_path)
goto error;
return path;
error:
_empty(&path);
return NULL;
}

+ 15
- 0
src/platform_unix.h View File

@ -16,6 +16,20 @@
#include <uuid/uuid.h>
#endif
// pEp files and directories
#ifndef PER_USER_DIRECTORY
#define PER_USER_DIRECTORY ".pEp"
#endif
#ifndef PER_MACHINE_DIRECTORY
#ifdef __APPLE__
#define PER_MACHINE_DIRECTORY "/usr/share/pEp"
#else
#define PER_MACHINE_DIRECTORY "/usr/local/share/pEp"
#endif
#endif
#ifdef __cplusplus
extern "C" {
@ -32,6 +46,7 @@ const char *gpg_conf(int reset);
const char *gpg_agent_conf(int reset);
const char *gpg_home(int reset);
#endif
const char *unix_system_db(void);
#ifdef ANDROID


+ 41
- 3
src/platform_windows.cpp View File

@ -17,10 +17,14 @@
#include <string>
#include <stdexcept>
#include "platform_windows.h"
#include "dynamic_api.h"
#include <fcntl.h>
#include <tchar.h>
#include <sys\stat.h>
#define LOCAL_DB_FILENAME "management.db"
#define SYSTEM_DB_FILENAME "system.db"
#ifndef WC_ERR_INVALID_CHARS
#define WC_ERR_INVALID_CHARS 0x00000080 // error for invalid chars
#endif
@ -114,7 +118,7 @@ static const DWORD PATH_BUF_SIZE = 32768;
static inline string managementPath(const char *file_path, const char *file_name)
{
string path;
static TCHAR tPath[PATH_BUF_SIZE];
TCHAR tPath[PATH_BUF_SIZE];
DWORD length = ExpandEnvironmentStringsW(utf16_string(file_path).c_str(),
tPath, PATH_BUF_SIZE);
@ -134,6 +138,40 @@ static inline string managementPath(const char *file_path, const char *file_name
extern "C" {
DYNAMIC_API const char *per_user_directory(void)
{
static string path;
if (path.length())
return path.c_str();
TCHAR tPath[PATH_BUF_SIZE];
DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_USER_DIRECTORY)).c_str(),
tPath, PATH_BUF_SIZE);
assert(length);
if (length == 0)
throw bad_alloc(); // BUG: there are other errors possible beside out of memory
path = utf8_string(wstring(tPath));
return path.c_str();
}
DYNAMIC_API const char *per_machine_directory(void)
{
static string path;
if (path.length())
return path.c_str();
TCHAR tPath[PATH_BUF_SIZE];
DWORD length = ExpandEnvironmentStringsW(utf16_string(string(PER_MACHINE_DIRECTORY)).c_str(),
tPath, PATH_BUF_SIZE);
assert(length);
if (length == 0)
throw bad_alloc(); // BUG: there are other errors possible beside out of memory
path = utf8_string(wstring(tPath));
return path.c_str();
}
void *dlopen(const char *filename, int flag) {
static TCHAR path[PATH_BUF_SIZE];
@ -196,14 +234,14 @@ void *dlsym(void *handle, const char *symbol) {
const char *windoze_local_db(void) {
static string path;
if (path.length() == 0)
path = managementPath("%LOCALAPPDATA%\\pEp", "management.db");
path = managementPath(PER_USER_DIRECTORY, LOCAL_DB_FILENAME);
return path.c_str();
}
const char *windoze_system_db(void) {
static string path;
if (path.length() == 0)
path = managementPath("%ALLUSERSPROFILE%\\pEp", "system.db");
path = managementPath(PER_MACHINE_DIRECTORY, SYSTEM_DB_FILENAME);
return path.c_str();
}


+ 10
- 0
src/platform_windows.h View File

@ -22,6 +22,16 @@
#include <basetsd.h>
#include <time.h>
// pEp files and directories
#ifndef PER_USER_DIRECTORY
#define PER_USER_DIRECTORY "%LOCALAPPDATA%\\pEp"
#endif
#ifndef PER_MACHINE_DIRECTORY
#define PER_MACHINE_DIRECTORY "%ALLUSERSPROFILE%\\pEp"
#endif
#ifdef __cplusplus
extern "C" {
#endif


Loading…
Cancel
Save