merge default into my branch roker-linux
authorRoker <roker@pep-project.org>
Mon, 27 Jun 2016 09:13:48 +0200
branchroker-linux
changeset 7683db578658a38
parent 761 04fc0f0a3dc3
parent 765 681cfd246db6
child 769 8660da4da019
merge default into my branch
src/Makefile
test/Makefile
     1.1 --- a/README.txt	Thu Jun 23 16:17:32 2016 +0200
     1.2 +++ b/README.txt	Mon Jun 27 09:13:48 2016 +0200
     1.3 @@ -118,5 +118,5 @@
     1.4  You have to import all the test keys into your local gpg instance:
     1.5  
     1.6  	cd test
     1.7 -	cat *.asc | gpg --import
     1.8 +	cat 0x*.asc *_sec.asc| gpg --import
     1.9  
     2.1 --- a/src/Makefile	Thu Jun 23 16:17:32 2016 +0200
     2.2 +++ b/src/Makefile	Mon Jun 27 09:13:48 2016 +0200
     2.3 @@ -30,7 +30,7 @@
     2.4  CFLAGS?=-I$(GPGME_IN)/include $(OPTIMIZE) -fPIC -pedantic \
     2.5  	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -DLIBGPGME=\"$(LIBGPGME)\" \
     2.6  	-DSQLITE_THREADSAFE=1 -D_GNU_SOURCE -I../asn.1
     2.7 -LDFLAGS?=-L$(GPGME_IN)/lib -shared -lc -ldl -letpan -lsqlite3 -lpthread -L../asn.1 -lasn1
     2.8 +LDFLAGS?=-L$(GPGME_IN)/lib -shared -lc -ldl -letpan -lpthread -L../asn.1 -lasn1
     2.9  
    2.10  else
    2.11  $(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
     3.1 --- a/src/pgp_gpg.c	Thu Jun 23 16:17:32 2016 +0200
     3.2 +++ b/src/pgp_gpg.c	Mon Jun 27 09:13:48 2016 +0200
     3.3 @@ -11,7 +11,7 @@
     3.4  static void *gpgme;
     3.5  static struct gpg_s gpg;
     3.6  
     3.7 -static bool ensure_config_values(stringlist_t *keys, stringlist_t *values)
     3.8 +static bool ensure_config_values(stringlist_t *keys, stringlist_t *values, const char* config_file_path)
     3.9  {
    3.10      static char buf[MAX_LINELENGTH];
    3.11      int r;
    3.12 @@ -21,7 +21,7 @@
    3.13      unsigned int i;
    3.14      unsigned int found = 0;
    3.15  
    3.16 -    f = Fopen(gpg_conf(), "r");
    3.17 +    f = Fopen(config_file_path, "r");
    3.18      if (f == NULL && errno == ENOMEM)
    3.19          return false;
    3.20  
    3.21 @@ -57,10 +57,10 @@
    3.22                  }
    3.23              }
    3.24          } while (!feof(f));
    3.25 -        f = Freopen(gpg_conf(), "a", f);
    3.26 +        f = Freopen(config_file_path, "a", f);
    3.27      }
    3.28      else {
    3.29 -        f = Fopen(gpg_conf(), "w");
    3.30 +        f = Fopen(config_file_path, "w");
    3.31      }
    3.32  
    3.33      assert(f);
    3.34 @@ -81,6 +81,7 @@
    3.35      return true;
    3.36  }
    3.37  
    3.38 +
    3.39  PEP_STATUS pgp_init(PEP_SESSION session, bool in_first)
    3.40  {
    3.41      PEP_STATUS status = PEP_STATUS_OK;
    3.42 @@ -106,8 +107,8 @@
    3.43  
    3.44          stringlist_add(conf_keys, "personal-digest-preferences");
    3.45          stringlist_add(conf_values, "SHA256 SHA512 SHA384 SHA224");
    3.46 -        
    3.47 -        bResult = ensure_config_values(conf_keys, conf_values);
    3.48 +
    3.49 +        bResult = ensure_config_values(conf_keys, conf_values, gpg_conf());
    3.50  
    3.51          free_stringlist(conf_keys);
    3.52          free_stringlist(conf_values);
    3.53 @@ -118,6 +119,22 @@
    3.54              goto pep_error;
    3.55          }
    3.56  
    3.57 +        conf_keys = new_stringlist("default-cache-ttl");
    3.58 +        conf_values = new_stringlist("300");
    3.59 +
    3.60 +        stringlist_add(conf_keys, "max-cache-ttl");
    3.61 +        stringlist_add(conf_values, "1200");
    3.62 +
    3.63 +        bResult = ensure_config_values(conf_keys, conf_values, gpg_agent_conf());
    3.64 +
    3.65 +        free_stringlist(conf_keys);
    3.66 +        free_stringlist(conf_values);
    3.67 +
    3.68 +        assert(bResult);
    3.69 +        if(!bResult){
    3.70 +            status = PEP_INIT_NO_GPG_HOME; /* FIXME: Wrong error here? */
    3.71 +            goto pep_error;
    3.72 +        }
    3.73  
    3.74          gpgme = dlopen(LIBGPGME, RTLD_LAZY);
    3.75          if (gpgme == NULL) {
     4.1 --- a/src/platform_unix.c	Thu Jun 23 16:17:32 2016 +0200
     4.2 +++ b/src/platform_unix.c	Mon Jun 27 09:13:48 2016 +0200
     4.3 @@ -113,6 +113,7 @@
     4.4  
     4.5  static const char *gpg_conf_path = ".gnupg";
     4.6  static const char *gpg_conf_name = "gpg.conf";
     4.7 +static const char *gpg_agent_conf_name = "gpg-agent.conf";
     4.8  static const char *gpg_conf_empty = "# Created by pEpEngine\n";
     4.9  
    4.10  static bool ensure_gpg_home(const char **conf, const char **home){
    4.11 @@ -186,6 +187,51 @@
    4.12      return true;
    4.13  }
    4.14  
    4.15 +static bool ensure_gpg_agent_conf(const char **agent_conf){
    4.16 +    static char agent_path[MAX_PATH];
    4.17 +    static bool done = false;
    4.18 +
    4.19 +    if (!done) {
    4.20 +        const char *dirname;
    4.21 +
    4.22 +        if (!ensure_gpg_home(NULL, &dirname)) /* Then dirname won't be set. */
    4.23 +            return false;
    4.24 +
    4.25 +        char *p;
    4.26 +        p = stpncpy(agent_path, dirname, MAX_PATH);
    4.27 +        
    4.28 +        size_t len = MAX_PATH - (p - agent_path) - 2;
    4.29 +
    4.30 +        if (len < strlen(gpg_agent_conf_name))
    4.31 +        {
    4.32 +            assert(0);
    4.33 +            return false;
    4.34 +        }
    4.35 +
    4.36 +        *p++ = '/';
    4.37 +     
    4.38 +        strncpy(p, gpg_agent_conf_name, len);
    4.39 +
    4.40 +        if(access(agent_path, F_OK)){ 
    4.41 +            int fd;
    4.42 +            if(access(dirname, F_OK )) { 
    4.43 +                mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR);
    4.44 +            }
    4.45 +
    4.46 +            fd = open(agent_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
    4.47 +
    4.48 +            if(fd>0) {
    4.49 +                write(fd, gpg_conf_empty, strlen(gpg_conf_empty));
    4.50 +                close(fd);
    4.51 +            }
    4.52 +        }
    4.53 +        done = true;
    4.54 +    }
    4.55 +    if(agent_conf) *agent_conf=agent_path;
    4.56 +
    4.57 +    return true;
    4.58 +}
    4.59 +
    4.60  const char *gpg_conf(void)
    4.61  {
    4.62      const char *conf;
    4.63 @@ -201,3 +247,11 @@
    4.64          return home;
    4.65      return NULL;
    4.66  }
    4.67 +
    4.68 +const char *gpg_agent_conf(void)
    4.69 +{
    4.70 +    const char *agent_conf;
    4.71 +    if(ensure_gpg_agent_conf(&agent_conf))
    4.72 +        return agent_conf;
    4.73 +    return NULL;
    4.74 +}
     5.1 --- a/src/platform_unix.h	Thu Jun 23 16:17:32 2016 +0200
     5.2 +++ b/src/platform_unix.h	Mon Jun 27 09:13:48 2016 +0200
     5.3 @@ -11,6 +11,7 @@
     5.4  const char *unix_local_db(void);
     5.5  
     5.6  const char *gpg_conf(void);
     5.7 +const char *gpg_agent_conf(void);
     5.8  const char *gpg_home(void);
     5.9  
    5.10  #ifdef ANDROID
     6.1 --- a/src/platform_windows.cpp	Thu Jun 23 16:17:32 2016 +0200
     6.2 +++ b/src/platform_windows.cpp	Mon Jun 27 09:13:48 2016 +0200
     6.3 @@ -190,6 +190,15 @@
     6.4      return path.c_str();
     6.5  }
     6.6  
     6.7 +const char *gpg_agent_conf(void)
     6.8 +{
     6.9 +    static string agent_path;
    6.10 +    if (agent_path.length() == 0)
    6.11 +        agent_path = managementPath("%APPDATA%\\gnupg", "gpg-agent.conf");
    6.12 +    return agent_path.c_str();
    6.13 +}
    6.14 +
    6.15 +
    6.16  long random(void)
    6.17  {
    6.18      unsigned int r;