Locate system.db given by android, using SAFEWORDS env var
authorEdouard Tisserant
Fri, 04 Sep 2015 21:41:11 +0200
changeset 347098632924bd2
parent 346 68a5a5e22905
child 348 878bbf6a42c5
Locate system.db given by android, using SAFEWORDS env var
src/platform_unix.c
src/platform_unix.h
     1.1 --- a/src/platform_unix.c	Wed Sep 02 13:47:52 2015 +0200
     1.2 +++ b/src/platform_unix.c	Fri Sep 04 21:41:11 2015 +0200
     1.3 @@ -11,6 +11,7 @@
     1.4  
     1.5  #define MAX_PATH 1024
     1.6  #define LOCAL_DB_FILENAME ".pEp_management.db"
     1.7 +#define SYSTEM_DB_FILENAME "system.db"
     1.8  
     1.9  #ifndef bool
    1.10  #define bool int
    1.11 @@ -18,8 +19,8 @@
    1.12  #define false 0
    1.13  #endif
    1.14  
    1.15 -char *
    1.16 -local_stpncpy(char *dst, const char *src, size_t n)
    1.17 +#ifdef ANDROID
    1.18 +char *stpncpy(char *dst, const char *src, size_t n)
    1.19  {
    1.20      if (n != 0) {
    1.21          char *d = dst;
    1.22 @@ -39,7 +40,6 @@
    1.23      return (dst);
    1.24  }
    1.25  
    1.26 -#ifdef ANDROID
    1.27  char *stpcpy(char *dst, const char *src)
    1.28  {
    1.29      for (;; ++dst, ++src) {
    1.30 @@ -54,6 +54,33 @@
    1.31    unsigned short xsubi[3] = {'p', 'E', 'p'};
    1.32    return nrand48(xsubi);
    1.33  }
    1.34 +
    1.35 +const char *android_system_db(void)
    1.36 +{
    1.37 +    static char buffer[MAX_PATH];
    1.38 +    static bool done = false;
    1.39 +
    1.40 +    if (!done) {
    1.41 +        char *sw_env;
    1.42 +        if(sw_env = getenv("SAFEWORDS")){
    1.43 +            char *p = stpncpy(buffer, sw_env, MAX_PATH);
    1.44 +            size_t len = MAX_PATH - (p - buffer) - 2;
    1.45 +
    1.46 +            if (len < strlen(SYSTEM_DB_FILENAME)) {
    1.47 +                assert(0);
    1.48 +                return NULL;
    1.49 +            }
    1.50 +
    1.51 +            *p++ = '/';
    1.52 +            strncpy(p, SYSTEM_DB_FILENAME, len);
    1.53 +            done = true;
    1.54 +        }else{
    1.55 +            return NULL;
    1.56 +        }
    1.57 +
    1.58 +    }
    1.59 +    return buffer;
    1.60 +}
    1.61  #endif
    1.62  
    1.63  const char *unix_local_db(void)
    1.64 @@ -64,7 +91,7 @@
    1.65      if (!done) {
    1.66          char *home_env;
    1.67          if(home_env = getenv("HOME")){
    1.68 -            char *p = local_stpncpy(buffer, home_env, MAX_PATH);
    1.69 +            char *p = stpncpy(buffer, home_env, MAX_PATH);
    1.70              size_t len = MAX_PATH - (p - buffer) - 2;
    1.71  
    1.72              if (len < strlen(LOCAL_DB_FILENAME)) {
    1.73 @@ -100,7 +127,7 @@
    1.74  
    1.75          if(gpg_home_env){
    1.76  
    1.77 -            p = local_stpncpy(path, gpg_home_env, MAX_PATH);
    1.78 +            p = stpncpy(path, gpg_home_env, MAX_PATH);
    1.79              len = MAX_PATH - (p - path) - 2;
    1.80  
    1.81              if (len < strlen(gpg_conf_name))
    1.82 @@ -111,7 +138,7 @@
    1.83  
    1.84          }else if(home_env){
    1.85  
    1.86 -            p = local_stpncpy(path, home_env, MAX_PATH);
    1.87 +            p = stpncpy(path, home_env, MAX_PATH);
    1.88              len = MAX_PATH - (p - path) - 3;
    1.89  
    1.90              if (len < strlen(gpg_conf_path) + strlen(gpg_conf_name))
     2.1 --- a/src/platform_unix.h	Wed Sep 02 13:47:52 2015 +0200
     2.2 +++ b/src/platform_unix.h	Fri Sep 04 21:41:11 2015 +0200
     2.3 @@ -9,6 +9,9 @@
     2.4  #endif
     2.5  
     2.6  const char *unix_local_db(void);
     2.7 +const char *android_system_db(void);
     2.8 +#define SYSTEM_DB android_system_db()
     2.9 +
    2.10  const char *gpg_conf(void);
    2.11  const char *gpg_home(void);
    2.12