Merge with sync JSON-107
authorVolker Birk <vb@pep.foundation>
Thu, 18 Apr 2019 08:15:57 +0200
branchJSON-107
changeset 68976920db19c36
parent 688 c1907ceae94d
parent 685 7806e2ec3288
Merge with sync
server/gpg_environment.cc
server/gpg_environment.hh
server/hotfixer.cc
server/hotfixer.hh
     1.1 --- a/server/ev_server.cc	Thu Apr 18 08:11:44 2019 +0200
     1.2 +++ b/server/ev_server.cc	Thu Apr 18 08:15:57 2019 +0200
     1.3 @@ -8,7 +8,6 @@
     1.4  #include "pep-types.hh"
     1.5  #include "json_rpc.hh"
     1.6  #include "pep-utils.hh"
     1.7 -#include "gpg_environment.hh"
     1.8  #include "logger.hh"
     1.9  #include "server_version.hh"
    1.10  
    1.11 @@ -16,8 +15,11 @@
    1.12  #include <pEp/blacklist.h>
    1.13  #include <pEp/key_reset.h>
    1.14  #include <pEp/openpgp_compat.h>
    1.15 +#include <pEp/message_api.h> // for get_binary_path()
    1.16  #include <pEp/mime.h>
    1.17  
    1.18 +// libpEpAdapter:
    1.19 +#include <pEp/status_to_string.hh>
    1.20  #include <pEp/slurp.hh>
    1.21  
    1.22  #include <boost/filesystem.hpp>
    1.23 @@ -54,22 +56,18 @@
    1.24  	return ss.str();
    1.25  }
    1.26  
    1.27 -
    1.28 -#ifdef ENIGMAIL_2_0_COMPAT
    1.29 -
    1.30 -// wrapper for Enigmail 2.0 to provide the old Engine's API before JSON-92 / ENGINE-423
    1.31 -PEP_STATUS MIME_decrypt_message_20(PEP_SESSION session, const char* src, size_t src_len, char** plaintext,
    1.32 -	stringlist_t** keylist, PEP_rating* rating, PEP_decrypt_flags_t* flags)
    1.33 +std::string getBinaryPath()
    1.34  {
    1.35 -	*flags = 0;
    1.36 -	char* modified_src = nullptr;
    1.37 -	PEP_STATUS status = MIME_decrypt_message(session, src, src_len, plaintext, keylist, rating, flags, &modified_src);
    1.38 -	pEp_free(modified_src);
    1.39 -	return status;
    1.40 +	const char* gpg_path = nullptr;
    1.41 +	const auto status = get_binary_path( PEP_crypt_OpenPGP, &gpg_path);
    1.42 +	if(status == PEP_STATUS_OK && gpg_path)
    1.43 +	{
    1.44 +		return std::string(gpg_path);
    1.45 +	}
    1.46 +	
    1.47 +	throw std::runtime_error("getBinaryPath returns error: " + ::pEp::status_to_string(status) );
    1.48  }
    1.49  
    1.50 -#endif // ENIGMAIL_2_0_COMPAT
    1.51 -
    1.52  
    1.53  using In_Pep_Session = In<PEP_SESSION, ParamFlag::NoInput>;
    1.54  
    1.55 @@ -161,7 +159,7 @@
    1.56  		FP( "Other", new Separator ),
    1.57  		FP( "serverVersion",       new Func<ServerVersion>( &server_version ) ),
    1.58  		FP( "version",           new Func<std::string>( &version_as_a_string ) ),
    1.59 -		FP( "getGpgEnvironment", new Func<GpgEnvironment>( &getGpgEnvironment ) ),
    1.60 +		FP( "getBinaryPath", new Func<std::string>( &getBinaryPath ) ),
    1.61  
    1.62  		FP( "shutdown",  new Func<void, In<JsonAdapter*,ParamFlag::NoInput>>( &JsonAdapter::shutdown_now ) ),
    1.63  	};
     2.1 --- a/server/gpg_environment.cc	Thu Apr 18 08:11:44 2019 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,52 +0,0 @@
     2.4 -#include "gpg_environment.hh"
     2.5 -#include "function_map.hh"
     2.6 -
     2.7 -#include <cstdlib>
     2.8 -#include <pEp/message_api.h> // for get_binary_path()
     2.9 -
    2.10 -GpgEnvironment getGpgEnvironment()
    2.11 -{
    2.12 -	GpgEnvironment ge{};
    2.13 -
    2.14 -	const char* gpg_path = nullptr;
    2.15 -	const auto status = get_binary_path( PEP_crypt_OpenPGP, &gpg_path);
    2.16 -	if(status == PEP_STATUS_OK && gpg_path)
    2.17 -	{
    2.18 -		ge.gnupg_path = std::string(gpg_path);
    2.19 -	}
    2.20 -	
    2.21 -	const char* home = std::getenv("GNUPGHOME");
    2.22 -	if(home)
    2.23 -	{
    2.24 -		ge.gnupg_home = std::string(home);
    2.25 -	}
    2.26 -
    2.27 -	const char* ai = std::getenv("GPG_AGENT_INFO");
    2.28 -	if(ai)
    2.29 -	{
    2.30 -		ge.gpg_agent_info = std::string(ai);
    2.31 -	}
    2.32 -	
    2.33 -	return ge;
    2.34 -}
    2.35 -
    2.36 -
    2.37 -template<>
    2.38 -Out<GpgEnvironment>::~Out()
    2.39 -{
    2.40 -}
    2.41 -
    2.42 -
    2.43 -template<>
    2.44 -js::Value to_json<GpgEnvironment>(const GpgEnvironment& ge)
    2.45 -{
    2.46 -	js::Object obj;
    2.47 -	obj.emplace_back("gnupg_path", (ge.gnupg_path ? ge.gnupg_path.get() : js::Value{}) );
    2.48 -	obj.emplace_back("gnupg_home", (ge.gnupg_home ? ge.gnupg_home.get() : js::Value{}) );
    2.49 -	obj.emplace_back("gpg_agent_info", (ge.gpg_agent_info ? ge.gpg_agent_info.get() : js::Value{}) );
    2.50 -	return obj;
    2.51 -}
    2.52 -
    2.53 -
    2.54 -template<>
    2.55 -js::Value Type2String<GpgEnvironment>::get()  { return "GpgEnvironment"; }
     3.1 --- a/server/gpg_environment.hh	Thu Apr 18 08:11:44 2019 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,16 +0,0 @@
     3.4 -#ifndef JSON_GPG_ENVIRONMENT_HH
     3.5 -#define JSON_GPG_ENVIRONMENT_HH
     3.6 -
     3.7 -#include <boost/optional.hpp>
     3.8 -#include <string>
     3.9 -
    3.10 -struct GpgEnvironment
    3.11 -{
    3.12 -	boost::optional<std::string> gnupg_path;     // filled by pEpEngine's gnu_gpg_path()
    3.13 -	boost::optional<std::string> gnupg_home;     // filled by getenv("GNUPGHOME")
    3.14 -	boost::optional<std::string> gpg_agent_info; // filled by getenv("GPG_AGENT_INFO")
    3.15 -};
    3.16 -
    3.17 -GpgEnvironment getGpgEnvironment();
    3.18 -
    3.19 -#endif
     4.1 --- a/server/hotfixer.cc	Thu Apr 18 08:11:44 2019 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,187 +0,0 @@
     4.4 -#include "hotfixer.hh"
     4.5 -#include "logger.hh"
     4.6 -
     4.7 -#ifdef __APPLE__
     4.8 -    // disable boost::process because b0rken on MacOS since boost version 1.69
     4.9 -#else
    4.10 -#include <boost/process.hpp>
    4.11 -namespace bp = boost::process;
    4.12 -#endif
    4.13 -
    4.14 -#include <boost/filesystem.hpp>
    4.15 -
    4.16 -#ifdef _WIN32
    4.17 -# ifndef  HOTFIX_SENTINEL_FILE
    4.18 -#  define HOTFIX_SENTINEL_FILE "json-hotfix-1.dat"
    4.19 -# endif
    4.20 -# define HOTFIX_BINARY "pep-hotfix.exe"
    4.21 -#else
    4.22 -# ifndef  HOTFIX_SENTINEL_FILE
    4.23 -#  define HOTFIX_SENTINEL_FILE "json-hotfix-1.dat"
    4.24 -# endif
    4.25 -# define HOTFIX_BINARY "pep-hotfix"
    4.26 -#endif
    4.27 -
    4.28 -#define IS_ERROR_LOGGED(e) ( is_error_logged((e), "hotfixer.cc", __LINE__) )
    4.29 -
    4.30 -namespace fs = boost::filesystem;
    4.31 -namespace sys = boost::system;
    4.32 -
    4.33 -
    4.34 -namespace pEp
    4.35 -{
    4.36 -    namespace utility
    4.37 -    {
    4.38 -
    4.39 -        fs::path get_pep_dir()
    4.40 -        {
    4.41 -            const char *env_pephome = getenv("PEPHOME");
    4.42 -#ifndef _WIN32
    4.43 -            const char *env_usrhome = getenv("HOME");
    4.44 -            const char *env_pepsub = ".pEp";
    4.45 -#else
    4.46 -            const char *env_usrhome = getenv("APPDATA");
    4.47 -            const char *env_pepsub = "pEp";
    4.48 -#endif
    4.49 -            fs::path pephome;
    4.50 -            if (env_pephome)
    4.51 -                pephome = fs::path(env_pephome);
    4.52 -            else
    4.53 -            {
    4.54 -                if (!env_usrhome || !env_pepsub)
    4.55 -                    return fs::path();   // .empty() == true
    4.56 -                fs::path p1 = env_usrhome;
    4.57 -                fs::path p2 = env_pepsub;
    4.58 -                pephome = p1 / p2;
    4.59 -            }
    4.60 -            if(!fs::create_directory(pephome))
    4.61 -                if (!fs::exists(pephome))
    4.62 -                    return fs::path();
    4.63 -            return pephome;
    4.64 -        }
    4.65 -
    4.66 -        int is_error_logged(sys::error_code& sec, const char* const src, const int line)
    4.67 -        {
    4.68 -            int ret = 0;
    4.69 -            if ((ret = sec.value()))
    4.70 -            {
    4.71 -                Logger l("hotfix");
    4.72 -                l.error("%s error (%d): %s (%s:%d)", sec.category().name(), ret, sec.message().c_str(), src, line);
    4.73 -                sec.clear();
    4.74 -                return ret;
    4.75 -            }
    4.76 -            return 0;
    4.77 -        }
    4.78 -
    4.79 -
    4.80 -        int is_error_logged(std::error_code& ec, const char* const src, const int line)
    4.81 -        {
    4.82 -            int ret = 0;
    4.83 -            if ((ret = ec.value()))
    4.84 -            {
    4.85 -                Logger l("hotfix");
    4.86 -                l.error("%s error (%d): %s (%s:%d)", ec.category().name(), ret, ec.message().c_str(), src, line);
    4.87 -                ec.clear();
    4.88 -                return ret;
    4.89 -            }
    4.90 -            return 0;
    4.91 -        }
    4.92 -
    4.93 -
    4.94 -        fs::path get_adapter_share_dir(sys::error_code& sec)
    4.95 -        {
    4.96 -            return fs::path(".");
    4.97 -        }
    4.98 -
    4.99 -
   4.100 -        fs::path get_adapter_bin_dir(sys::error_code& sec)
   4.101 -        {
   4.102 -            fs::path p = "../../bin";
   4.103 -            return p;
   4.104 -        }
   4.105 -
   4.106 -
   4.107 -        bool hotfix_call_required()
   4.108 -        {
   4.109 -            sys::error_code sec;
   4.110 -            int ret;
   4.111 -            Logger L("hotfix");
   4.112 -
   4.113 -            fs::path pepdir = get_adapter_share_dir(sec);
   4.114 -            if ((ret = IS_ERROR_LOGGED(sec)))
   4.115 -                return ret;
   4.116 -
   4.117 -            if (fs::exists(pepdir / HOTFIX_SENTINEL_FILE), sec)
   4.118 -                return false;
   4.119 -
   4.120 -            L.info("hotfix required to run");
   4.121 -            return true;
   4.122 -        }
   4.123 -
   4.124 -
   4.125 -        int hotfix_call_execute()
   4.126 -        {
   4.127 -
   4.128 -// problems on Mac OS and boost::process version 1.69, so we disable this hotfix functionality here. :-P
   4.129 -#ifdef __APPLE__
   4.130 -            return 0;
   4.131 -#else
   4.132 -            std::error_code ec;
   4.133 -            sys::error_code sec;
   4.134 -            int ret;
   4.135 -            Logger L("hotfix");
   4.136 -
   4.137 -            fs::path sent_path = get_adapter_share_dir(sec);
   4.138 -            if ((ret = IS_ERROR_LOGGED(ec)))
   4.139 -                return ret;
   4.140 -            sent_path /= HOTFIX_SENTINEL_FILE;
   4.141 -
   4.142 -            fs::path hotfix_bin = get_adapter_bin_dir(sec);
   4.143 -            if ((ret = IS_ERROR_LOGGED(ec)))
   4.144 -                return ret;
   4.145 -            hotfix_bin /= HOTFIX_BINARY;
   4.146 -
   4.147 -            if (!(fs::exists(hotfix_bin, sec)))
   4.148 -            {
   4.149 -                IS_ERROR_LOGGED(sec);
   4.150 -                L.debug("file: '%s'", hotfix_bin.c_str());
   4.151 -                L.info("error locating hotfix binary, ignoring.");
   4.152 -                return 0;
   4.153 -            }
   4.154 -
   4.155 -            bp::ipstream is;  // reading spipe-stream
   4.156 -            std::string line;
   4.157 -            bp::child c(hotfix_bin, bp::std_out > is, ec);
   4.158 -            if ((ret = IS_ERROR_LOGGED(ec)))
   4.159 -                return ret;
   4.160 -
   4.161 -            while (c.running(ec) && std::getline(is, line) && !line.empty())
   4.162 -                L.info(line);
   4.163 -            if ((ret = IS_ERROR_LOGGED(ec)))
   4.164 -            {
   4.165 -                c.wait(ec);
   4.166 -                return ret;
   4.167 -            }
   4.168 -            c.wait(ec);
   4.169 -            if ((ret = IS_ERROR_LOGGED(ec)))
   4.170 -                return ret;
   4.171 -
   4.172 -            if ((ret = c.exit_code()))
   4.173 -            {
   4.174 -                L.error("hotfix returned exit code %d, exiting...", ret);
   4.175 -                return ret;
   4.176 -            }
   4.177 -
   4.178 -            fs::ofstream sent_file(sent_path);
   4.179 -            sent_file << "# HOTFIX SENTINEL FILE, DO NOT REMOVE" << std::endl;
   4.180 -            sent_file.close();
   4.181 -
   4.182 -            L.debug("sentinel file created: '%s'", sent_path.c_str());
   4.183 -
   4.184 -            return 0;
   4.185 -#endif // ! __APPLE__
   4.186 -
   4.187 -        }
   4.188 -
   4.189 -    }
   4.190 -}
     5.1 --- a/server/hotfixer.hh	Thu Apr 18 08:11:44 2019 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,15 +0,0 @@
     5.4 -#ifndef HOT_FIXER_HH
     5.5 -#define HOT_FIXER_HH
     5.6 -
     5.7 -namespace pEp
     5.8 -{
     5.9 -    namespace utility
    5.10 -    {
    5.11 -
    5.12 -        bool hotfix_call_required();
    5.13 -        int hotfix_call_execute();
    5.14 -
    5.15 -    }
    5.16 -}
    5.17 -
    5.18 -#endif
     6.1 --- a/server/main.cc	Thu Apr 18 08:11:44 2019 +0200
     6.2 +++ b/server/main.cc	Thu Apr 18 08:15:57 2019 +0200
     6.3 @@ -5,7 +5,6 @@
     6.4  #include "daemonize.hh"
     6.5  #include "logger.hh"
     6.6  #include "nulllogger.hh"
     6.7 -#include "hotfixer.hh"
     6.8  
     6.9  #include <thread>
    6.10  #include <fstream>
    6.11 @@ -105,17 +104,6 @@
    6.12  	Logger L("main");
    6.13  	L.info("main logger started");
    6.14  
    6.15 -	int hotfix_ret = 0;
    6.16 -#ifdef _WIN32
    6.17 -	if ((STATUS_HANDLE == 0) && pEp::utility::hotfix_call_required())
    6.18 -#else
    6.19 -	if (pEp::utility::hotfix_call_required())
    6.20 -#endif
    6.21 -	{
    6.22 -		if ((hotfix_ret = pEp::utility::hotfix_call_execute()) != 0)
    6.23 -			return hotfix_ret;
    6.24 -	}
    6.25 -
    6.26  	if(add_sharks)
    6.27  	{
    6.28  		ev_server::addSharks();
     7.1 --- a/server/server_version.cc	Thu Apr 18 08:11:44 2019 +0200
     7.2 +++ b/server/server_version.cc	Thu Apr 18 08:15:57 2019 +0200
     7.3 @@ -68,7 +68,8 @@
     7.4  
     7.5  //  Renumbering due to political decisions - the planned exits 31..39 through the Sauerland will never be build. :-(
     7.6  //  So we got a new exit with the same number:
     7.7 -	"(39) Eisenach"; // JSON-118: fix to_json() for KeySync callbacks to avoid crashes. Add attachment support in interactive.js \o/
     7.8 +//	"(39) Eisenach"; // JSON-118: fix to_json() for KeySync callbacks to avoid crashes. Add attachment support in interactive.js \o/
     7.9 +	"(40) Eisenach-Ost"; // remove all Enigmail leftovers. Bump API version to 0.17.0
    7.10  
    7.11  } // end of anonymous namespace
    7.12  ////////////////////////////////////////////////////////////////////////////
    7.13 @@ -92,7 +93,8 @@
    7.14  //static const ServerVersion sv(0,15,4);  // JSON-117: add trust_own_key()
    7.15  //static const ServerVersion sv(0,15,5);  // JSON-119: add get_key_rating_for_user()
    7.16  //static const ServerVersion sv(0,16,0);  // Kick-out Enigmail 2.0 compat, remove MIME_*() methods, deliverHandshakeResult() changes parameter types
    7.17 -static const ServerVersion sv(0,16,1);  // JSON-120: add support for key_reset_identity(), key_reset_user(), and key_reset_all_own_keys()
    7.18 +//static const ServerVersion sv(0,16,1);  // JSON-120: add support for key_reset_identity(), key_reset_user(), and key_reset_all_own_keys()
    7.19 +static const ServerVersion sv(0,17,0);  // kick out getGpgEnvironment(). It was Enigmail-only (JSON-18) and breaks architecture. Kick-out hotfixer un-feature.
    7.20  
    7.21  	return sv;
    7.22  }