aboutsummaryrefslogtreecommitdiff
path: root/bpkg/openssl.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-04-14 17:59:24 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-05-04 20:47:45 +0300
commitb13332c991ce2695626eaca367dd8208b174c9ca (patch)
tree809dc321b47d5ef9c72935637f94bf5b84ed640d /bpkg/openssl.cxx
parentc9831f760a83e36a3a2ac84b1bd3f573e47ef195 (diff)
Add support for repository authentication
Diffstat (limited to 'bpkg/openssl.cxx')
-rw-r--r--bpkg/openssl.cxx59
1 files changed, 59 insertions, 0 deletions
diff --git a/bpkg/openssl.cxx b/bpkg/openssl.cxx
new file mode 100644
index 0000000..67500b6
--- /dev/null
+++ b/bpkg/openssl.cxx
@@ -0,0 +1,59 @@
+// file : bpkg/openssl.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <bpkg/openssl>
+
+#include <butl/process>
+#include <butl/fdstream>
+
+#include <bpkg/diagnostics>
+
+using namespace std;
+using namespace butl;
+
+namespace bpkg
+{
+ process
+ start_openssl (const common_options& co,
+ const char* command,
+ const cstrings& options,
+ bool in,
+ bool out,
+ bool err)
+ {
+ cstrings args {co.openssl ().string ().c_str (), command};
+
+ // Add extra options. Normally the order of options is not important
+ // (unless they override each other). However, openssl 1.0.1 seems to have
+ // bugs in that department (that were apparently fixed in 1.0.2). To work
+ // around these bugs we pass user-supplied options first.
+ //
+ for (const string& o: co.openssl_option ())
+ args.push_back (o.c_str ());
+
+ args.insert (args.end (), options.begin (), options.end ());
+ args.push_back (nullptr);
+
+ if (verb >= 2)
+ print_process (args);
+
+ try
+ {
+ // If the caller is interested in reading STDOUT and STDERR, then
+ // redirect STDERR to STDOUT, so both can be read from the same stream.
+ //
+ return process (
+ args.data (), in ? -1 : 0, out ? -1 : 1, err ? (out ? 1 : -1): 2);
+ }
+ catch (const process_error& e)
+ {
+ error << "unable to execute " << args[0] << ": " << e.what ();
+
+ if (e.child ())
+ exit (1);
+
+ throw failed ();
+ }
+ }
+}