Browse Source

fix ENGINE-956

It is now possible to use shell environment variables in PER_USER_DIRECTORY and
PER_MACHINE_DIRECTORY, expanded at *run* time.  This is meant to allow more
freedom to the deployment engineer, without affecting development.  Notice that,
when PER_USER_DIRECTORY and PER_MACHINE_DIRECTORY are defined in the Makefile,
dollar signs must be escaped (a dollar becomes a double dollar) because of
*make* syntax: this has nothing to do with pEp engine code.
Expansion follows the Unix shell $VARIABLE syntax: ${VARIABLE} is not supported.
See _expand_variables.

src/platform_unix.c contained some duplicated logic about caching path results
into static variables; this change set would have added to the complexity by
calling the new path expansion function, in many different places.  Seize the
occasion for factoring.

Do not change the meaning of PER_USER_DIRECTORY yet; I would like to do it,
since it is confusing and inconsistent with per_user_directory
(PER_USER_DIRECTORY is a relative path on Unix, while per_user_directory is
absolute), but the actual semantics with respect to $HOME and $PEP_HOME is
complicated and I do not want to break it.
New API function per_user_relative_directory.

Remove the ugly "reset" argument from unix_local_db (which was conditionally
defined according to NDEBUG!), used to force path re-computation in the test
suite after changing an environment variable so as to work in a new "home"
directory.  In the place of this reset argument add clear API functions to the
engine for handling the cache.
My quick grapping and IRC interaction confirm that nobody was using the
functionality out of the engine test suite.  Adapt the test suite to use the new
API.

Tentatively add caching and expansion functionality to android_system_db as well.
master
Luca Saiu 3 months ago
parent
commit
3095f39fec
10 changed files with 519 additions and 117 deletions
  1. +5
    -2
      db/Makefile
  2. +5
    -2
      src/Makefile
  3. +10
    -0
      src/pEpEngine.c
  4. +43
    -1
      src/pEpEngine.h
  5. +0
    -5
      src/pEp_internal.h
  6. +10
    -14
      src/pgp_sequoia.c
  7. +404
    -79
      src/platform_unix.c
  8. +2
    -8
      src/platform_unix.h
  9. +14
    -0
      src/platform_windows.cpp
  10. +26
    -6
      test/src/Engine.cc

+ 5
- 2
db/Makefile View File

@ -18,8 +18,11 @@ system.db: create_system_db.sql $(DICOS)
.PHONY: install
install: system.db
mkdir -p $(DESTDIR)$(PER_MACHINE_DIRECTORY)
cp system.db $(DESTDIR)$(PER_MACHINE_DIRECTORY)
# Notice that the expansion of these make variables may still contain
# shell variable occurrences, to be expanded in their turn. This
# serves to leave more freedom to the deployment engineer.
mkdir -p "$(DESTDIR)$(PER_MACHINE_DIRECTORY)"
cp system.db "$(DESTDIR)$(PER_MACHINE_DIRECTORY)"
.PHONY: clean
clean:


+ 5
- 2
src/Makefile View File

@ -5,12 +5,15 @@
include ../Makefile.conf
# Notice the single quotes below: since user definitions can contain dollar
# signs it is important to prevent their expansion: shell variable references
# here must be expanded at run time, and not at compile time.
ifdef PER_USER_DIRECTORY
EXTRA_MACROS+= -DPER_USER_DIRECTORY=$(PER_USER_DIRECTORY)
EXTRA_MACROS+= -DPER_USER_DIRECTORY='"$(PER_USER_DIRECTORY)"'
endif
ifdef PER_MACHINE_DIRECTORY
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY=\"$(PER_MACHINE_DIRECTORY)\"
EXTRA_MACROS+= -DPER_MACHINE_DIRECTORY='"$(PER_MACHINE_DIRECTORY)"'
endif
NO_SOURCE=


+ 10
- 0
src/pEpEngine.c View File

@ -28,6 +28,13 @@ DYNAMIC_API PEP_STATUS init(
{
PEP_STATUS status = PEP_STATUS_OK;
// Initialise the path cache. It is the state of the environment at this
// time that determines path names, unless the path cache is explicitly
// reset later.
status = reset_path_cache ();
if (status != PEP_STATUS_OK)
return status;
bool in_first = false;
assert(sqlite3_threadsafe());
@ -143,6 +150,9 @@ DYNAMIC_API void release(PEP_SESSION session)
if (session) {
free_Sync_state(session);
// Clear the path cache, releasing a little memory.
clear_path_cache ();
if (session->db) {
pEp_finalize_sql_stmts(session);
if (session->db) {


+ 43
- 1
src/pEpEngine.h View File

@ -182,6 +182,8 @@ typedef enum {
PEP_MESSAGE_IGNORE = 0xff03,
PEP_CANNOT_CONFIG = 0xff04,
PEP_UNBOUND_ENVIRONMENT_VARIABLE = -8,
PEP_PATH_SYNTAX_ERROR = -7,
PEP_RECORD_NOT_FOUND = -6,
PEP_CANNOT_CREATE_TEMP_FILE = -5,
PEP_ILLEGAL_VALUE = -4,
@ -189,7 +191,7 @@ typedef enum {
PEP_OUT_OF_MEMORY = -2,
PEP_UNKNOWN_ERROR = -1,
PEP_VERSION_MISMATCH = -7,
PEP_VERSION_MISMATCH = -9,
} PEP_STATUS;
/**
@ -1757,7 +1759,21 @@ DYNAMIC_API PEP_STATUS is_pEp_user(PEP_SESSION session,
pEp_identity *identity,
bool* is_pEp);
/**
* <!-- per_user_relative_directory() -->
*
* @brief Returns the directory for pEp management db as a relative
* path from the home directory (or the pEp home directory)
*
* @retval char* relative pathname
* @retval NULL on failure
*
*/
DYNAMIC_API const char *per_user_relative_directory(void);
/**
* <!-- per_user_directory() -->
*
* @brief Returns the directory for pEp management db
@ -1949,6 +1965,32 @@ DYNAMIC_API PEP_STATUS get_replacement_fpr(
*/
DYNAMIC_API PEP_STATUS set_as_pEp_user(PEP_SESSION session, pEp_identity* user);
/**
* <!-- reset_path_cache() -->
*
* @brief Recompute pathnames according to the current value of the
* environment. This is automatically called by init on
* platforms where a pathname cache exists, but it is possible
* to call it again explicitly in case the paths need to be
* recomputed from updated environment variables; the intended
* use case is test suites, working with temporary
* directories.
*
* @retval PEP_STATUS_OK success
* @retval PEP_UNBOUND_ENVIRONMENT_VARIABLE unknown variable referenced
* @retval PEP_PATH_SYNTAX_ERROR invalid syntax in argument
* @retval PEP_OUT_OF_MEMORY out of memory
*
*/
DYNAMIC_API PEP_STATUS reset_path_cache(void);
/**
* <!-- reset_path_cache() -->
*
* @brief Empty the path cache, releasing resources.
*
*/
DYNAMIC_API void clear_path_cache(void);
#ifdef __cplusplus
}


+ 0
- 5
src/pEp_internal.h View File

@ -77,12 +77,7 @@
#else // UNIX
#define _POSIX_C_SOURCE 200809L
#include <dlfcn.h>
#ifdef NDEBUG
#define LOCAL_DB unix_local_db()
#else
#define LOCAL_DB unix_local_db(false)
#define LOCAL_DB_RESET unix_local_db(true)
#endif
#ifdef ANDROID
#define SYSTEM_DB android_system_db()
#else


+ 10
- 14
src/pgp_sequoia.c View File

@ -451,28 +451,24 @@ PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
| SQLITE_OPEN_PRIVATECACHE,
NULL);
#else
// Create the home directory.
char *home_env = NULL;
#ifndef NDEBUG
home_env = getenv("PEP_HOME");
#endif
#define PEP_KEYS_PATH "/.pEp/keys.db"
if (!home_env)
home_env = getenv("HOME");
if (!home_env)
ERROR_OUT(NULL, PEP_INIT_CRYPTO_LIB_INIT_FAILED, "HOME unset");
// Compute a string containing the DB absolute path name.
#define PEP_KEYS_RELATIVE_FILENAME "keys.db"
const char *directory = per_user_directory();
// Create the DB and initialize it.
size_t path_size = strlen(home_env) + sizeof(PEP_KEYS_PATH);
size_t path_size
= (strlen(directory)
+ 1 /* '/' */
+ strlen(PEP_KEYS_RELATIVE_FILENAME)
+ 1 /* '\0' */);
char *path = (char *) calloc(path_size, 1);
assert(path);
if (!path)
ERROR_OUT(NULL, PEP_OUT_OF_MEMORY, "out of memory");
int r = snprintf(path, path_size, "%s" PEP_KEYS_PATH, home_env);
int r = snprintf(path, path_size, "%s/%s",
directory, PEP_KEYS_RELATIVE_FILENAME);
assert(r >= 0 && r < path_size);
if (r < 0) {
free(path);


+ 404
- 79
src/platform_unix.c View File

@ -25,6 +25,7 @@
#include <fcntl.h>
#include <regex.h>
#include "pEpEngine.h" /* For PEP_STATUS */
#include "platform_unix.h"
#include "dynamic_api.h"
@ -99,29 +100,28 @@ long int random(void)
return nrand48(xsubi);
} */
const char *android_system_db(void)
/* This is a non-caching function: see the comments in "Internal path caching
functionality" below. */
static char *_android_system_db(void)
{
static char buffer[MAX_PATH];
static bool done = false;
if (!done) {
char *tw_env;
if(tw_env = getenv("TRUSTWORDS")){
char *p = stpncpy(buffer, tw_env, MAX_PATH);
ssize_t len = MAX_PATH - (p - buffer) - 2;
if (len < strlen(SYSTEM_DB_FILENAME)) {
assert(0);
return NULL;
}
char *buffer = malloc (MAX_PATH);
if (buffer == NULL)
return NULL;
char *tw_env;
if(tw_env = getenv("TRUSTWORDS")){
char *p = stpncpy(buffer, tw_env, MAX_PATH);
ssize_t len = MAX_PATH - (p - buffer) - 2;
*p++ = '/';
strncpy(p, SYSTEM_DB_FILENAME, len);
done = true;
}else{
if (len < strlen(SYSTEM_DB_FILENAME)) {
assert(0);
return NULL;
}
*p++ = '/';
strncpy(p, SYSTEM_DB_FILENAME, len);
}else{
return NULL;
}
return buffer;
}
@ -341,7 +341,383 @@ static void _move(const char *o, const char *ext, const char *n)
free(_new);
}
#ifndef NDEBUG
/**
* @internal
*
* <!-- _strdup_or_NULL() -->
*
* @brief Return a malloc-allocated copy of the given string, or (this
* is the added functionality with respect to the standard
* strdup) a malloc-allocated copy of "" if the argument is
* NULL.
*
* @param[in] *original constchar
* @retval NULL out of memory
* @retval non-NULL malloc-allocated buffer
*/
static char *_strdup_or_NULL(const char *original)
{
if (original == NULL)
original = "";
return strdup (original);
}
/*
* Environment variable expansion
* **********************************************************************
*/
/* The state of a DFA implementing variable recognition in _expand_variables ,
below. */
enum _expand_variable_state {
_expand_variable_state_non_variable,
_expand_variable_state_after_dollar,
_expand_variable_state_after_backslash,
_expand_variable_state_in_variable
};
/**
* @internal
*
* <!-- _expand_variables() -->
*
* @brief Set a malloc-allocated '\0'-terminated string which is
* a copy of the argument with shell variables expanded, where
* variable references use Unix shell-style syntax $VARIABLE.
* Notice that the alternative syntax ${VARIABLE} is not
* supported.
* See [FIXME: deployment-engineer documentation].
*
* @param[in] string_with_variables char *
* @param[out] copy_with_variables_expanded char **
* @retval PEP_STATUS_OK success
* @retval PEP_UNBOUND_ENVIRONMENT_VARIABLE unknown variable referenced
* @retval PEP_PATH_SYNTAX_ERROR invalid syntax in argument
* @retval PEP_OUT_OF_MEMORY out of memory
*
*/
static PEP_STATUS _expand_variables(char **out,
const char *string_with_variables)
{
PEP_STATUS res = PEP_STATUS_OK;
size_t in_length = strlen(string_with_variables);
const char *variable_name_beginning; /* This points within the input. */
char *variable_name_copy = NULL /* we free on error. */;
size_t allocated_size
#ifdef NDEBUG
= 1024;
#else
= 1 /* Notice that 0 is incorrect: this grows by doubling. */;
#endif // #ifdef NDEBUG
int out_index = 0; /* The out index is also the used out size */
const char *in = string_with_variables;
/* In the pEp engine we adopt the convention of "" behaving the same as
NULL. Notice that we never free this, so it is not a problem if this
string is not malloc-allocated. */
if (in == NULL)
in = "";
/* We free on error. */
* out = NULL ;
/* Recognise a variable according to POSIX syntax which, luckily for us,
only allows for letters, digits and underscores -- The first character
may not be a digit... */
#define VALID_FIRST_CHARACTER_FOR_VARIABLE(c) \
( ((c) >= 'a' && (c) <= 'z') \
|| ((c) >= 'A' && (c) <= 'Z') \
|| ((c) == '_'))
/* ...But characters after the first may be. */
#define VALID_NON_FIRST_CHARACTER_FOR_VARIABLE(c) \
( VALID_FIRST_CHARACTER_FOR_VARIABLE(c) \
|| ((c) >= '0' && (c) <= '9'))
/* Append the char argument to the result string, automatically resizing it
if needed. */
#define EMIT_CHAR(c) \
do \
{ \
if (out_index == allocated_size) { \
allocated_size *= 2; \
/*fprintf (stderr, "ALLOCATED SIZE: %i -> %i\n", (int) allocated_size / 2, (int) allocated_size);*/\
* out = realloc (* out, allocated_size); \
if (* out == NULL) \
FATAL (PEP_OUT_OF_MEMORY, \
"cannot grow buffer"); \
} \
(* out) [out_index] = (c); \
out_index ++; \
} \
while (false)
/* Append the string argument to the output string, automatically resizing
it as needed. */
#define EMIT_STRING(s) \
do { \
const char *p; \
for (p = (s); (* p) != '\0'; p ++) \
EMIT_CHAR (* p); \
} while (false)
/* Emit the expansion of the environment variable whose name is delimited on
the left by variable_name_beginning and on the right by the character
coming right *before* in. Fail fatally if the variable is unbound.
The expansion is emitted by appending to the result string, automatically
resizing it as needed. */
#define EMIT_CURRENT_VARIABLE \
do { \
const char *variable_past_end = in; \
size_t variable_name_length \
= variable_past_end - variable_name_beginning; \
strcpy (variable_name_copy, variable_name_beginning); \
variable_name_copy [variable_name_length] = '\0'; \
const char *variable_value = getenv (variable_name_copy); \
if (variable_value == NULL) \
FATAL_NAME (PEP_UNBOUND_ENVIRONMENT_VARIABLE, \
"unbound variable", variable_name_copy); \
EMIT_STRING (variable_value); \
} while (false)
#define FATAL(code, message) \
do { res = (code); goto failure; } while (false)
#define FATAL_NAME(code, message, name) \
FATAL((code), (message))
/* We can allocate buffers, now that we have FATAL. */
if ((variable_name_copy
= malloc (in_length + 1 /* a safe upper bound for a sub-string. */))
== NULL)
FATAL (PEP_OUT_OF_MEMORY, "out of mmeory");
if (((* out) = malloc (allocated_size)) == NULL)
FATAL (PEP_OUT_OF_MEMORY, "out of memory");
/* This logic implements a DFA. */
enum _expand_variable_state s = _expand_variable_state_non_variable;
char c;
while (true) {
c = * in;
switch (s) {
case _expand_variable_state_non_variable:
if (c == '$') {
variable_name_beginning = in + 1;
s = _expand_variable_state_after_dollar;
}
else if (c == '\\')
s = _expand_variable_state_after_backslash;
else /* This includes c == '\0'. */
EMIT_CHAR (c);
if (c == '\0')
goto success;
break;
case _expand_variable_state_after_backslash:
if (c == '$' || c == '\\') {
EMIT_CHAR (c);
s = _expand_variable_state_non_variable;
}
else if (c == '\0') /* Just to give a nicer error message */
FATAL (PEP_PATH_SYNTAX_ERROR, "trailing unescaped '\\'");
else /* this would be correct even with '\0' */
FATAL (PEP_PATH_SYNTAX_ERROR, "invalid escape");
break;
case _expand_variable_state_after_dollar:
if (VALID_FIRST_CHARACTER_FOR_VARIABLE (c))
s = _expand_variable_state_in_variable;
else if (c == '\0') /* Just to give a nicer error message */
FATAL (PEP_PATH_SYNTAX_ERROR,"trailing '$' character");
else if (c == '\\') /* Just to give a nicer error message */
FATAL (PEP_PATH_SYNTAX_ERROR,
"empty variable name followed by escape");
else if (c == '$') /* Just to give a nicer error message */
FATAL (PEP_PATH_SYNTAX_ERROR, "two consecutive '$' characters");
else
FATAL (PEP_PATH_SYNTAX_ERROR,
"invalid variable first character after '$'");
break;
case _expand_variable_state_in_variable:
if (VALID_NON_FIRST_CHARACTER_FOR_VARIABLE (c))
/* Do nothing */;
else if (c == '\\') {
EMIT_CURRENT_VARIABLE;
s = _expand_variable_state_after_backslash;
}
else {
/* This includes c == '\0'. */
EMIT_CURRENT_VARIABLE;
EMIT_CHAR (c);
if (c == '\0')
goto success;
else
s = _expand_variable_state_non_variable;
}
break;
default:
FATAL (PEP_STATEMACHINE_INVALID_STATE /* Slightly questionable: this
should be an assertion. */,
"impossible DFA state");
} /* switch */
in ++;
} /* while */
success:
free(variable_name_copy);
return res;
failure:
free(* out);
* out = NULL;
goto success;
#undef VALID_FIRST_CHARACTER_FOR_VARIABLE
#undef VALID_NON_FIRST_CHARACTER_FOR_VARIABLE
#undef EMIT_CHAR
#undef EMIT_STRING
#undef EMIT_CURRENT_VARIABLE
#undef FATAL
#undef FATAL_NAME
}
/*
* Internal path caching functionality
* **********************************************************************
*/
/* Several functions in this compilation unit return paths to files or
* directories, always returning pointers to the same internally managed memory
* at every call.
*
* The cache is filled at engine initialisation, using the value of environment
* variables at initialisation time: after that point no out-of-memory errors
* are possible, until reset.
*
* In debugging mode the cache can be "reset", with every path recomputed on
* demand according to the current environment.
*/
/* For each path we define:
- a static char * variable pointing to the cached value;
- a prototype for a static function returning a malloc-allocated copy of
the value, unexapanded, not using the cache (to be defined below by hand);
- a public API function returning a pointer to cached memory. */
#define DEFINE_CACHED_PATH(name) \
/* A static variable holding the cached path, or NULL. */ \
static char *_ ## name ## _cache = NULL; \
\
/* A prototype for the hand-written function returning the \
computed value for the path, without using the cache and \
without expanding variables. */ \
static char *_ ## name(void); \
\
/* The public version of the function, using the cache. */ \
DYNAMIC_API const char *name(void) \
{ \
if (_ ## name ## _cache == NULL) { \
/* It is unusual and slightly bizarre than a path is \
accessed before initialisation; however it can happen \
in the engine test suite. */ \
fprintf (stderr, \
"WARNING: accessing %s before its cache is set:" \
" this should not happen in production.\n", \
#name); \
reset_path_cache(); \
} \
return _ ## name ## _cache; \
}
/* Define cached paths using the functionality above: */
DEFINE_CACHED_PATH (per_user_relative_directory)
DEFINE_CACHED_PATH (per_user_directory)
DEFINE_CACHED_PATH (per_machine_directory)
#ifdef ANDROID
DEFINE_CACHED_PATH (android_system_db)
#endif
DEFINE_CACHED_PATH (unix_system_db)
DEFINE_CACHED_PATH (unix_local_db)
/* Free every cache variable and re-initialise it to NULL: this
re-initialisation is important when this function is used here,
internally, as part of cleanup on errors. */
DYNAMIC_API void clear_path_cache (void)
{
#define UNSET(name) \
do { \
free((void *) _ ## name ## _cache); \
(_ ## name ## _cache) = NULL; \
} while (false)
UNSET (per_user_relative_directory);
UNSET (per_user_directory);
UNSET (per_machine_directory);
#ifdef ANDROID
UNSET (android_system_db);
#endif
UNSET (unix_system_db);
UNSET (unix_local_db);
#undef UNSET
}
DYNAMIC_API PEP_STATUS reset_path_cache(void)
{
PEP_STATUS res = PEP_STATUS_OK;
#define SET_OR_FAIL(name) \
do { \
unexpanded_path = (_ ## name)(); \
if (unexpanded_path == NULL) { \
res = PEP_OUT_OF_MEMORY; \
goto free_everything_and_fail; \
} \
res = _expand_variables(& _ ## name ## _cache, unexpanded_path); \
if (res != PEP_STATUS_OK) \
goto free_everything_and_fail; \
/* Clear unxpanded_path for the next call of SET_OR_FAIL. */ \
free((void *) unexpanded_path); \
unexpanded_path = NULL; \
} while (false)
/* In case this is not the first invocation, start by releasing memory. */
clear_path_cache ();
const char *unexpanded_path = NULL;
SET_OR_FAIL (per_user_relative_directory);
SET_OR_FAIL (per_user_directory);
SET_OR_FAIL (per_machine_directory);
#ifdef ANDROID
SET_OR_FAIL (android_system_db);
#endif
SET_OR_FAIL (unix_system_db);
SET_OR_FAIL (unix_local_db);
return res;
free_everything_and_fail:
free((void *) unexpanded_path);
clear_path_cache ();
return res;
#undef SET_OR_FAIL
}
/**
* @internal
*
* <!-- _per_user_directory() -->
*
* @brief TODO
*
*/
static char *_per_user_relative_directory(void)
{
return _strdup_or_NULL(PER_USER_DIRECTORY);
}
/**
* @internal
*
@ -349,27 +725,10 @@ static void _move(const char *o, const char *ext, const char *n)
*
* @brief TODO
*
* @param[in] reset int
*
*/
static const char *_per_user_directory(int reset)
#else
static const char *_per_user_directory(void)
#endif
static char *_per_user_directory(void)
{
static char *path = NULL;
#ifdef NDEBUG
if (path)
return path;
#else
if (path && !reset)
return path;
else if (path) {
free(path);
path = NULL;
}
#endif
char *path = NULL;
const char *home = NULL;
#ifndef NDEBUG
@ -401,32 +760,9 @@ error:
return NULL;
}
#ifdef NDEBUG
const char *unix_local_db(void)
#else
const char *unix_local_db(int reset)
#endif
char *_unix_local_db(void)
{
static char *path = NULL;
#ifdef NDEBUG
if (path)
#else
if (path && !reset)
#endif
return path;
const char* pathret = NULL;
#ifndef NDEBUG
pathret = _per_user_directory(reset);
#else
pathret = _per_user_directory();
#endif
if (!pathret)
return NULL;
path = strdup(pathret);
assert(path);
char* path = (char *) _per_user_directory() /* This memory is not shared. */;
if (!path)
return NULL;
@ -538,26 +874,15 @@ the_end:
return path;
}
DYNAMIC_API const char *per_user_directory(void) {
#ifdef NDEBUG
return _per_user_directory();
#else
return _per_user_directory(false);
#endif
}
DYNAMIC_API const char *per_machine_directory(void)
{
return PER_MACHINE_DIRECTORY;
static char *_per_machine_directory(void) {
return _strdup_or_NULL(PER_MACHINE_DIRECTORY);
}
const char *unix_system_db(void)
char *_unix_system_db(void)
{
static char *path = NULL;
if (path)
return path;
char *path = NULL;
path = strdup(per_machine_directory());
path = _per_machine_directory() /* Use this fresh copy. */;
assert(path);
if (!path)
return NULL;


+ 2
- 8
src/platform_unix.h View File

@ -41,25 +41,19 @@
extern "C" {
#endif
#ifdef NDEBUG
const char *unix_local_db(void);
#else
/**
* <!-- unix_local_db() -->
*
* @brief TODO
*
* @param[in] reset int
*
*/
const char *unix_local_db(int reset);
#endif
const char *unix_local_db(void);
/**
* <!-- unix_system_db() -->
*
* @brief TODO
*
*
*/
const char *unix_system_db(void);


+ 14
- 0
src/platform_windows.cpp View File

@ -22,6 +22,8 @@
#include <tchar.h>
#include <sys\stat.h>
#include "pEpEngine.h" // just for PEP_STATUS
#define LOCAL_DB_FILENAME "management.db"
#define SYSTEM_DB_FILENAME "system.db"
#define KEYS_DB "keys.db"
@ -458,4 +460,16 @@ void log_output_debug(const char *title,
OutputDebugStringA(str);
}
DYNAMIC_API PEP_STATUS reset_path_cache(void)
{
/* Do nothing and return success. This only exists for API compatibility
with the Unix version. */
return PEP_STATUS_OK;
}
DYNAMIC_API void clear_path_cache (void)
{
/* Like reset_path_cache, do nothing. */
}
} // "C"

+ 26
- 6
test/src/Engine.cc View File

@ -19,6 +19,7 @@
#include "TestUtilities.h"
#include "Engine.h"
#include "pEpTestStatic.h"
#include "pEpEngine_internal.h"
#include <algorithm>
#include "TestConstants.h"
@ -91,16 +92,34 @@ void Engine::start() {
if (success != 0)
throw std::runtime_error("SETUP: Cannot set engine_home for init.");
unix_local_db(true);
PEP_STATUS status = init(&session, cached_messageToSend, cached_inject_sync_event, cached_ensure_passphrase);
PEP_STATUS status;
status = reset_path_cache();
assert(status == PEP_STATUS_OK);
FILE *f = fopen ("/home/luca/pep-src/pep-engine/PER_USER_DIRECTORY", "w");
fprintf (f, "* per_user_directory (): %s\n", per_user_directory ());
fclose (f);
f = fopen ("/home/luca/pep-src/pep-engine/PER_MACHINE_DIRECTORY", "w");
fprintf (f, "* per_machine_directory (): %s\n", per_machine_directory ());
fclose (f);
fprintf (stderr, "* per_user_directory (): %s\n", per_user_directory ());
fprintf (stderr, "* per_user_directory (): %s\n", per_user_directory ());
status = init(&session, cached_messageToSend, cached_inject_sync_event, cached_ensure_passphrase);
assert(status == PEP_STATUS_OK);
assert(session);
}
void Engine::copy_conf_file_to_test_dir(const char* dest_path, const char* conf_orig_path, const char* conf_dest_name) {
string conf_dest_path = string(dest_path) + "/.pEp/";
string conf_dest_path
= (string(dest_path)
+ string("/")
+ string(per_user_relative_directory ())
+ string("/"));
fprintf (stderr, "COPYING %s from %s to %s\n",
dest_path,
conf_orig_path,
conf_dest_path.c_str ());
struct stat pathinfo;
if(stat(conf_dest_path.c_str(), &pathinfo) != 0) {
@ -149,5 +168,6 @@ void Engine::shut_down() {
if (success != 0)
throw std::runtime_error("RESTORE: Cannot reset home directory! Either set environment variable manually back to your home, or quit this session!");
unix_local_db(true);
PEP_STATUS status = reset_path_cache();
assert(status == PEP_STATUS_OK);
}

Loading…
Cancel
Save