1 /********************************************************************************
2  *                              Nepenthes
3  *                        - finest collection -
4  *
5  *
6  *
7  * Copyright (C) 2005  Paul Baecher & Markus Koetter
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22  *
23  *
24  *             contact nepenthesdev@users.sourceforge.net
25  *
26  *******************************************************************************/
27 
28  /* $Id: SSHSocket.hpp 1979 2005-09-14 12:08:59Z common $ */
29 
30 #include "config.h"
31 #ifdef HAVE_LIBSSH
32 
33 #ifndef HAVE_SSHSOCKET_HPP
34 	#define HAVE_SSHSOCKET_HPP
35 
36 	#undef PACKAGE_BUGREPORT
37 	#undef PACKAGE_NAME
38 	#undef PACKAGE_STRING
39 	#undef PACKAGE_TARNAME
40 	#undef PACKAGE_VERSION
41 
42 
43 extern "C"
44 {
45 
46 #include <libssh/libssh.h>
47 #include <libssh/server.h>
48 }
49 
50 	#undef PACKAGE_BUGREPORT
51 	#undef PACKAGE_NAME
52 	#undef PACKAGE_STRING
53 	#undef PACKAGE_TARNAME
54 	#undef PACKAGE_VERSION
55 
56 
57 #include "DialogueFactory.hpp"
58 #include "Module.hpp"
59 #include "ModuleManager.hpp"
60 #include "SocketManager.hpp"
61 #include "Nepenthes.hpp"
62 #include "Dialogue.hpp"
63 #include "POLLSocket.hpp"
64 
65 using namespace std;
66 
67 namespace nepenthes
68 {
69 
70 	typedef enum
71 	{
72 		SSH_STATE_AUTH,
73 		SSH_STATE_CHANNEL,
74 		SSH_STATE_SHELL_OR_SFTP,
75 		SSH_STATE_DONE,
76 	}ssh_state;
77 
78 	class SSHSocket : public POLLSocket
79 	{
80 	public:
81 		SSHSocket(SSH_OPTIONS *options);
82 		SSHSocket(SSH_SESSION *session);
83 		~SSHSocket();
84 
85 		bool Init();
86 
87 		Socket * acceptConnection();
88 		bool bindPort();
89 		bool wantSend();
90 		int32_t doSend();
91 		int32_t doRecv();
92         bool checkTimeout();
93 		bool handleTimeout();
94 		int32_t getSocket();
95 		int32_t getsockOpt(int32_t level, int32_t optname,void *optval,socklen_t *optlen);
96 
97 	private:
98 		SSH_BIND 	*m_Bind;
99 		SSH_SESSION *m_Session;
100 		CHANNEL *m_Channel;
101 
102 		ssh_state   m_SSHState;
103 
104 		string m_WhatToRead;
105 		string m_User;
106 		string m_Pass;
107 	};
108 }
109 
110 #endif
111 
112 #endif /* HAVE_LIBSSH */
113