#ifdef USE_GPG | USE_NETPGP + make [OPENPGP=GPG|NETPGP]

doc_update_sequoia
Edouard Tisserant 8 years ago
parent 04a3177f82
commit 33cc75806c

@ -1,5 +1,7 @@
include ../Makefile.conf
OPENPGP?=GPG
ifeq ($(BUILD_ON),Darwin)
ifeq ($(BUILD_FOR),Darwin)
@ -38,7 +40,18 @@ else
$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
endif
ALL_SOURCE=$(wildcard *.c)
ifeq ("$(OPENPGP)","GPG")
NO_SOURCE=pgp_netpgp.c
CFLAGS+= -DUSE_GPG
else ifeq ("$(OPENPGP)","NETPGP")
NO_SOURCE=pgp_gpg.c
CFLAGS+= -DUSE_NETPGP
LDFLAGS+= -lnetpgp
else
$(error Unknown OpenPGP library : $(OPENPGP))
endif
ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
DEPENDS=$(subst .c,.d,$(ALL_SOURCE))
ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))

@ -1,9 +1,9 @@
#include "pEp_internal.h"
#ifdef NO_GPG
#include "pgp_netpgp.h"
#else
#ifdef USE_GPG
#include "pgp_gpg.h"
#elif USE_NETPGP
#include "pgp_netpgp.h"
#endif
#include <stdlib.h>

@ -47,8 +47,18 @@
#define _EXPORT_PEP_ENGINE_DLL
#include "pEpEngine.h"
#ifndef NO_GPG
// If not specified, build for GPG
#ifndef USE_NETPGP
#ifndef USE_GPG
#define USE_GPG
#endif
#endif
#ifdef USE_GPG
#include "pgp_gpg_internal.h"
#elif USE_NETPGP
#include "pgp_netpgp_internal.h"
#endif
#include "cryptotech.h"
@ -58,8 +68,10 @@
typedef struct _pEpSession {
const char *version;
#ifndef NO_GPG
#ifdef USE_GPG
gpgme_ctx_t ctx;
#elif USE_NETPGP
netpgp_t ctx;
#endif
PEP_cryptotech_t *cryptotech;

@ -43,55 +43,55 @@ static const char *gpg_conf_path = ".gnupg";
static const char *gpg_conf_name = "gpg.conf";
static const char *gpg_conf_empty = "# Created by pEpEngine\n";
const char *gpg_conf(void)
{
static char buffer[MAX_PATH];
static bool ensure_gpg_home(const char **conf, const char **home){
static char path[MAX_PATH];
static char dirname[MAX_PATH];
static bool done = false;
if (!done) {
char *gpg_home = getenv("GNUPGHOME");
if(gpg_home){
char *p;
size_t len;
char *gpg_home_env = getenv("GNUPGHOME");
if(gpg_home_env){
p = stpncpy(path, gpg_home_env, MAX_PATH);
len = MAX_PATH - (p - path) - 2;
char *p = stpncpy(buffer, gpg_home, MAX_PATH);
size_t len = MAX_PATH - (p - buffer) - 2;
if (len < strlen(gpg_conf_name))
{
assert(0);
return NULL;
return false;
}
strncpy(dirname, buffer, MAX_PATH);
*p++ = '/';
strncpy(p, gpg_conf_name, len);
}else{
char *p = stpncpy(buffer, getenv("HOME"), MAX_PATH);
size_t len = MAX_PATH - (p - buffer) - 3;
p = stpncpy(path, getenv("HOME"), MAX_PATH);
len = MAX_PATH - (p - path) - 3;
if (len < strlen(gpg_conf_path) + strlen(gpg_conf_name))
{
assert(0);
return NULL;
return false;
}
*p++ = '/';
strncpy(p, gpg_conf_path, len);
strncpy(dirname, buffer, MAX_PATH);
p += strlen(gpg_conf_path);
len -= strlen(gpg_conf_path) - 1;
*p++ = '/';
strncpy(p, gpg_conf_name, len);
}
if(access(buffer, F_OK)){
strncpy(dirname, path, MAX_PATH);
*p++ = '/';
strncpy(p, gpg_conf_name, len);
if(access(path, F_OK)){
int fd;
if(access(dirname, F_OK )) {
mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR);
}
fd = open(buffer, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
if(fd>0) {
write(fd, gpg_conf_empty, strlen(gpg_conf_empty));
@ -101,5 +101,25 @@ const char *gpg_conf(void)
done = true;
}
return buffer;
if(conf) *conf=path;
if(home) *home=dirname;
return true;
}
const char *gpg_conf(void)
{
const char *conf;
if(ensure_gpg_home(&conf, NULL))
return conf;
return NULL;
}
const char *gpg_home(void)
{
const char *home;
if(ensure_gpg_home(NULL, &home))
return home;
return NULL;
}

Loading…
Cancel
Save