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: Nepenthes.hpp 652 2006-09-26 15:06:11Z common $ */
29 
30 #include "config.h"
31 
32 
33 #ifndef HAVE_NEPENTHES_HPP
34 #define HAVE_NEPENTHES_HPP
35 
36 
37 #ifdef WIN32
38 #include <windows.h>
39 #endif
40 
41 #include <stdint.h>
42 #include <string>
43 #include <sys/types.h>
44 
45 typedef unsigned char byte;
46 
47 /* nepenthes specific log tags */
48 #define l_crit		0x00000001
49 #define l_warn		0x00000002
50 #define l_debug		0x00000004
51 #define l_info		0x00000008
52 #define l_spam		0x00000010
53 #define l_net		0x00000020
54 #define l_script	0x00000040
55 #define l_shell		0x00000080
56 #define l_mem		0x00000100
57 #define l_sc		0x00000200		// shell code
58 #define l_dl		0x00000400		// download
59 #define l_mgr		0x00000800  	// manager
60 #define l_hlr		0x00001000  	// handler
61 #define l_dia		0x00002000  	// dialogue
62 #define l_sub 		0x00004000  	// submit
63 #define l_ev		0x00008000		// event
64 #define l_mod		0x00010000		// module
65 #define l_stdtag 	0x00020000		// standard tag
66 
67 #define l_all		( l_crit  | l_warn | l_debug | l_info | l_spam | l_net | l_script | l_shell | l_mem  | l_sc    | l_dl   | l_mgr  | l_hlr | l_dia | l_sub  | l_ev | l_mod | l_stdtag )
68 #define l_none		0x00000000
69 
70 
71 #define STDTAGS l_debug | l_stdtag
72 
73 /* log shortcuts */
74 //#define DEBUG 1
75 
76 #define logWrite(mask, logformat...) g_Nepenthes->getLogMgr()->logf(mask, logformat)
77 
78 #ifdef HAVE_DEBUG_LOGGING
79 #define logSpam(logformat...) logWrite(l_spam 	| STDTAGS , logformat)
80 #define logDebug(logformat...) logWrite(l_debug	| STDTAGS , logformat)
81 #else	// HAVE_DEBUG_LOGGING
82 #define logSpam(logformat...)
83 #define logDebug(logformat ...)
84 #endif	// HAVE_DEBUG_LOGGING
85 
86 #define logInfo(logformat...) logWrite(l_info	| STDTAGS , logformat)
87 #define logWarn(logformat...) logWrite(l_warn	| STDTAGS , logformat)
88 #define logCrit(logformat...) logWrite(l_crit	| STDTAGS , logformat)
89 
90 #ifdef HAVE_DEBUG_LOGGING
91 #define logPF() logSpam("<in %s>\n", __PRETTY_FUNCTION__)
92 #else	// HAVE_DEBUG_LOGGING
93 #define logPF()
94 #endif // HAVE_DEBUG_LOGGING
95 
96 
97 namespace nepenthes
98 {
99 
100 	class Config;
101 	class DownloadManager;
102     class EventManager;
103     class LuaInterface;
104     class LogManager;
105     class ModuleManager;
106     class ShellcodeManager;
107     class SubmitManager;
108 	class SocketManager;
109 	class Utilities;
110 	class DialogueFactoryManager;
111 	class DNSManager;
112 	class Message;
113 	class SQLManager;
114 	struct Options;
115 
116 
117 /**
118  * the Nepenthes main class (singleton).
119  *
120  * all in all Nepenthes does nothing, he got plenty Managers to do something
121  *
122  */
123 
124     class Nepenthes
125     {
126     public:
127         Nepenthes();
128         virtual ~Nepenthes();
129 
130 		virtual Config				*getConfig();
131         virtual DownloadManager 	*getDownloadMgr();
132         virtual EventManager    	*getEventMgr();
133         virtual LuaInterface    	*getLua();
134         virtual LogManager      	*getLogMgr();
135         virtual ModuleManager   	*getModuleMgr();
136         virtual ShellcodeManager 	*getShellcodeMgr();
137         virtual SubmitManager   	*getSubmitMgr();
138 		virtual SocketManager 		*getSocketMgr();
139 		virtual Utilities			*getUtilities();
140 		virtual DialogueFactoryManager *getFactoryMgr();
141 		virtual DNSManager 			*getDNSMgr();
142 		virtual SQLManager			*getSQLMgr();
143 
144 		virtual bool 				doLoop();
145 		virtual int32_t 			run(int32_t argc, char **argv);
146 		virtual bool				stop();
147 		virtual bool 				reloadConfig();
148 
149     private:
150 		Config              *m_Config;
151 		DialogueFactoryManager *m_DialogueFactoryManager;
152 		DownloadManager     *m_DownloadManager;
153 		DNSManager          *m_DNSManager;
154 		EventManager        *m_EventManager;
155 		LuaInterface        *m_Lua;
156 		LogManager          *m_LogManager;
157 		ModuleManager       *m_ModuleManager;
158 		ShellcodeManager    *m_ShellcodeManager;
159 		SubmitManager       *m_SubmitManager;
160 		SocketManager       *m_SocketManager;
161 		Utilities           *m_Utilities;
162 		SQLManager 			*m_SQLManager;
163 
164 
165 		virtual bool		parseArguments(int32_t argc, char **argv, Options *options);
166 
167 		bool				m_running;
168 
169 		uid_t				m_UID;
170 		gid_t				m_GID;
171 	protected:
172 		bool fileCheckMain(const char *filecheckarg,int32_t argc, int32_t opti, char **argv);
173 		uint8_t fileCheckPrinter(const char *filename, uint8_t options);
174 		int32_t fileCheck(const char *filename, Message **Msg);
175 
176 		bool changeUser(const char *user);
177 		bool changeGroup(const char *group);
178 		bool changeUser();
179 		bool changeGroup();
180 
181 		bool setCapabilties();
182 
183 		bool changeRoot(const char *path);
184 	};
185 
186 
187 	enum ColorSetting
188 	{
189 		colorAuto, colorAlways, colorNever
190 	};
191 	enum RunMode
192 	{
193 		runNormal, runConfigCheck, runFileCheck
194 	};
195 
196 	struct Options
197 	{
198 		Options();
199 
200 		RunMode         m_runMode; // runNormal, runConfigCheck, runFileCheck
201 
202 		bool 			m_daemonize;
203 		bool            m_verbose;
204 		bool            m_setCaps;
205 		bool            m_ringLogger;
206 		ColorSetting    m_color;
207 
208 		const char      *m_fileCheckArguments;
209 		const char      *m_configPath;
210 		const char      *m_workingDir;
211 		const char      *m_changeUser;
212 		const char      *m_changeGroup;
213 		const char      *m_changeRoot;
214 		const char      *m_diskTags;
215 		const char      *m_consoleTags;
216 
217 		std::string     m_logFile;
218 		std::string     m_ringLoggerFile;
219 	};
220 
221 }
222 
223 extern nepenthes::Nepenthes *g_Nepenthes;
224 
225 void show_help(bool defaults);
226 void show_loghelp();
227 void show_version();
228 void show_logo();
229 void show_info();
230 #endif
231 
232