summaryrefslogtreecommitdiff
path: root/ssh-agent-filter.C
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2013-12-19 15:51:00 +0100
committerTimo Weingärtner <timo@tiwe.de>2013-12-19 15:51:00 +0100
commitc53477965b42efe662bb30c5a6ad9049e1a97ab6 (patch)
tree501463d5f2c9fc40078cd9fe9fbdff0792b53748 /ssh-agent-filter.C
parent127998372577ce6f9640d080bc0e208ddc53f8a9 (diff)
parent477a0a0f1507413be7a5d2882aba28d01f7e6111 (diff)
downloadssh-agent-filter-c53477965b42efe662bb30c5a6ad9049e1a97ab6.tar.gz
Merge tag '0.3.1' into debian
0.3.1
Diffstat (limited to 'ssh-agent-filter.C')
-rw-r--r--ssh-agent-filter.C34
1 files changed, 16 insertions, 18 deletions
diff --git a/ssh-agent-filter.C b/ssh-agent-filter.C
index dd1b508..8ee6aaf 100644
--- a/ssh-agent-filter.C
+++ b/ssh-agent-filter.C
@@ -25,6 +25,10 @@ namespace po = boost::program_options;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
+#include <boost/iostreams/stream_buffer.hpp>
+#include <boost/iostreams/device/file_descriptor.hpp>
+namespace io = boost::iostreams;
+
#include <string>
#include <vector>
#include <set>
@@ -32,7 +36,6 @@ namespace fs = boost::filesystem;
#include <sstream>
#include <stdexcept>
#include <thread>
-#include <ext/stdio_filebuf.h>
#include <csignal>
#include <cstdlib>
@@ -201,7 +204,7 @@ void parse_cmdline (int const argc, char const * const * const argv) {
}
void setup_filters () {
- __gnu_cxx::stdio_filebuf<char> agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out};
+ io::stream_buffer<io::file_descriptor> agent_filebuf{make_upstream_agent_conn(), io::close_handle};
std::iostream agent{&agent_filebuf};
agent.exceptions(std::ios::badbit | std::ios::failbit);
@@ -325,7 +328,7 @@ rfc4251string handle_request (rfc4251string const & r) {
switch (request_code) {
case SSH2_AGENTC_REQUEST_IDENTITIES:
{
- __gnu_cxx::stdio_filebuf<char> agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out};
+ io::stream_buffer<io::file_descriptor> agent_filebuf{make_upstream_agent_conn(), io::close_handle};
std::iostream agent{&agent_filebuf};
agent.exceptions(std::ios::badbit | std::ios::failbit);
rfc4251string agent_answer;
@@ -383,7 +386,7 @@ rfc4251string handle_request (rfc4251string const & r) {
}
if (allow) {
- __gnu_cxx::stdio_filebuf<char> agent_filebuf{make_upstream_agent_conn(), std::ios::in | std::ios::out};
+ io::stream_buffer<io::file_descriptor> agent_filebuf{make_upstream_agent_conn(), io::close_handle};
std::iostream agent{&agent_filebuf};
agent.exceptions(std::ios::badbit | std::ios::failbit);
rfc4251string agent_answer;
@@ -424,22 +427,17 @@ rfc4251string handle_request (rfc4251string const & r) {
return rfc4251string{answer.str()};
}
-void handle_client (int const sock) {
- // we could use only one streambuf and iostream but when
- // switching from read to write an lseek call is made that
- // fails with ESPIPE and causes an exception
- __gnu_cxx::stdio_filebuf<char> client_filebuf_in{sock, std::ios::in};
- __gnu_cxx::stdio_filebuf<char> client_filebuf_out{sock, std::ios::out};
- std::istream client_in{&client_filebuf_in};
- std::ostream client_out{&client_filebuf_out};
- client_out.exceptions(std::ios::badbit | std::ios::failbit);
+void handle_client (int const sock) try {
+ io::stream_buffer<io::file_descriptor> client_filebuf{sock, io::close_handle};
+ std::iostream client{&client_filebuf};
+ client.exceptions(std::ios::badbit | std::ios::failbit);
- rfc4251string request;
- while (client_in >> request) try {
- client_out << handle_request(request) << std::flush;
- } catch (...) {
- break;
+ for (;;) {
+ rfc4251string request;
+ client >> request;
+ client << handle_request(request) << std::flush;
}
+} catch (...) {
}
void sighandler (int sig) {