# # # patch "ssh_agent.cc" # from [42f17e038cf53ac983878f685da04c3a096cf1d8] # to [6e2e784bd8ad59cc47defc7d1c6255ffc1e28134] # # patch "ssh_agent.hh" # from [72cb4b38cd4e955640abe9ead4d9f51644fbe2f7] # to [208ee27931a03f399210f5b4184fe7ec06bc242d] # ============================================================ --- ssh_agent.cc 42f17e038cf53ac983878f685da04c3a096cf1d8 +++ ssh_agent.cc 6e2e784bd8ad59cc47defc7d1c6255ffc1e28134 @@ -8,12 +8,20 @@ #include "sanity.hh" #include "netio.hh" +using Botan::RSA_PublicKey; +using Botan::BigInt; +using Netxx::Stream; +using boost::shared_ptr; +using std::string; +using std::vector; using std::min; /* * The ssh-agent network format is essentially based on a u32 which * is the length of the packet followed by that number of bytes. * + * u32 encoding is big-endian + * * The packet to ask for the keys that ssh-agent has is in this format: * u32 = 1 * command = 11 @@ -78,55 +86,46 @@ ssh_agent::ssh_agent() ssh_agent::ssh_agent() { - connect(); -} - -ssh_agent::~ssh_agent() -{ - disconnect(); -} - -bool -ssh_agent::connect() -{ const char *authsocket; int sock; struct sockaddr_un sunaddr; - if (connected()) - return true; - authsocket = getenv("SSH_AUTH_SOCK"); if (!authsocket) { L(FL("ssh_agent: connect: ssh-agent socket not found")); - return false; + return; } sunaddr.sun_family = AF_UNIX; strncpy(sunaddr.sun_path, authsocket, sizeof(sunaddr.sun_path)); sock = socket(AF_UNIX, SOCK_STREAM, 0); - E(sock >= 0, F("ssh_agent: connect: could not open socket to ssh-agent")); + if (sock < 0) + { + W(F("ssh_agent: connect: could not open socket to ssh-agent")); + return; + } int ret = fcntl(sock, F_SETFD, 1); if (ret == -1) { close(sock); - E(ret != -1, F("ssh_agent: connect: could not set up socket for ssh-agent")); + W(F("ssh_agent: connect: could not set up socket for ssh-agent")); + return; } ret = ::connect(sock, (struct sockaddr *)&sunaddr, sizeof sunaddr); if (ret < 0) { close(sock); - E(ret >= 0, F("ssh_agent: connect: could not connect to socket for ssh-agent")); + W(F("ssh_agent: connect: could not connect to socket for ssh-agent")); + return; } stream = shared_ptr(new Stream(sock)); } -void -ssh_agent::disconnect() +ssh_agent::~ssh_agent() { if (connected()) { stream->close(); ============================================================ --- ssh_agent.hh 72cb4b38cd4e955640abe9ead4d9f51644fbe2f7 +++ ssh_agent.hh 208ee27931a03f399210f5b4184fe7ec06bc242d @@ -8,41 +8,32 @@ #include #include -using Botan::RSA_PublicKey; -using Botan::BigInt; -using Netxx::Stream; -using boost::shared_ptr; -using std::string; -using std::vector; - class ssh_agent { public: ssh_agent(); ~ssh_agent(); - bool connect(); - void disconnect(); bool connected(); - vector const get_keys(); - void sign_data(RSA_PublicKey const & key, string const & data, string & out); + std::vector const get_keys(); + void sign_data(Botan::RSA_PublicKey const & key, std::string const & data, std::string & out); private: - shared_ptr stream; - vector keys; + boost::shared_ptr stream; + std::vector keys; //helper functions for reading and unpacking data from ssh-agent - void fetch_packet(string & packet); - void read_num_bytes(u32 const len, string & out); + void fetch_packet(std::string & packet); + void read_num_bytes(u32 const len, std::string & out); u32 get_long(char const * buf); - u32 get_long_from_buf(string const & buf, u32 & loc); - void get_string_from_buf(string const & buf, u32 & loc, u32 & len, string & out); + u32 get_long_from_buf(std::string const & buf, u32 & loc); + void get_string_from_buf(std::string const & buf, u32 & loc, u32 & len, std::string & out); //helper functions for packing data to send to ssh-agent void put_long(u32 l, char * buf); - void put_long_into_buf(u32 l, string & buf); - void put_string_into_buf(string const & str, string & buf); - void put_bigint_into_buf(BigInt const & bi, string & buf); - void put_key_into_buf(RSA_PublicKey const & key, string & buf); + void put_long_into_buf(u32 l, std::string & buf); + void put_string_into_buf(std::string const & str, std::string & buf); + void put_bigint_into_buf(Botan::BigInt const & bi, std::string & buf); + void put_key_into_buf(Botan::RSA_PublicKey const & key, std::string & buf); }; // Local Variables: