1
/* $Id: xprobe_module_hdlr.cc,v 1.7 2005/02/09 18:36:45 mederchik Exp $ */
3
** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
4
** Ofir Arkin <ofir@sys-security.com>
6
** This program is free software; you can redistribute it and/or modify
7
** it under the terms of the GNU General Public License as published by
8
** the Free Software Foundation; either version 2 of the License, or
9
** (at your option) any later version.
12
** This program is distributed in the hope that it will be useful,
13
** but WITHOUT ANY WARRANTY; without even the implied warranty of
14
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
** GNU General Public License for more details.
17
** You should have received a copy of the GNU General Public License
18
** along with this program; if not, write to the Free Software
19
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "xprobe_module_hdlr.h"
24
#include "interface.h"
26
#include "xpmodules/static_modules.h"
30
extern Cmd_Opts *copts;
33
int Xprobe_Module_Hdlr::load(void) {
35
xprobe_module_func_t *ptr;
37
ui->msg("[+] Loading modules.\n");
40
while (ptr !=NULL && ptr->name !=NULL && ptr->func !=NULL) {
41
if (!copts->mod_is_disabled(cnt++))
42
add(ptr->func, ptr->name);
49
int Xprobe_Module_Hdlr::init(void) {
50
map<int, Xprobe_Module *>::iterator m_i;
52
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++)
53
(*m_i).second->init();
57
int Xprobe_Module_Hdlr::print(void) {
58
map<int, Xprobe_Module *>::iterator m_i;
60
ui->msg("[+] Following modules are loaded:\n");
61
xml->log(XPROBELOG_MOD_SESS_START, "Loaded modules");
62
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) {
63
ui->msg("[x] [%d] %s - %s\n", (*m_i).first,
64
(*m_i).second->get_name(), (*m_i).second->get_desc());
65
xml->log(XPROBELOG_MSG_MODULE, "%t%n%d%s", m_i->second->get_type(),
66
m_i->second->get_name(), m_i->first, m_i->second->get_desc());
68
ui->msg("[+] %i modules registered\n", mod_counter);
69
xml->log(XPROBELOG_MOD_SESS_END, "End modules");
73
int Xprobe_Module_Hdlr::exec(int mod_type, Target *tg, OS_Matrix *os) {
74
map<int, Xprobe_Module *>::iterator m_i;
76
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) {
77
if ((*m_i).second->get_type() == mod_type) {
78
xprobe_debug(XPROBE_DEBUG_MODULES,
79
"[+] Executing module: %s\n", (*m_i).second->get_name());
80
(*m_i).second->exec(tg, os);
86
int Xprobe_Module_Hdlr::fini(void) {
87
map<int, Xprobe_Module *>::iterator m_i;
89
//xprobe_debug(XPROBE_DEBUG_MODULES, "[+] Deinitializing modules\n");
90
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++) {
91
xprobe_debug(XPROBE_DEBUG_MODULES, "[+] Deinitializing module: [%i] %s\n", (*m_i).first,
92
(*m_i).second->get_name());
93
(*m_i).second->fini();
96
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++)
99
ui->msg("[+] Modules deinitialized\n");
104
int Xprobe_Module_Hdlr::add(int (*init_func)(Xprobe_Module_Hdlr *, char *), char *nm) {
106
xprobe_debug(XPROBE_DEBUG_MODULES, "[+] adding %s via function: %p\n", nm, init_func);
107
return(init_func(this, nm));
110
int Xprobe_Module_Hdlr::register_module(Xprobe_Module *mod) {
113
mod->set_id(mod_counter);
114
modlist.insert(pair<int, Xprobe_Module *>(mod_counter, mod));
119
void Xprobe_Module_Hdlr::add_keyword(int id, char *str) {
122
kwdlist.insert(pair<string, int>(kwd, id));
126
/* XXX: temp plug. Supposed to return module ptr which is registered for
129
Xprobe_Module *Xprobe_Module_Hdlr::find_mod(string &kwd) {
130
map <string, int>::iterator kw_i;
131
map<int, Xprobe_Module *>::iterator mod_i;
133
kw_i = kwdlist.find(kwd);
135
if (kw_i == kwdlist.end()) {
136
xprobe_debug(XPROBE_DEBUG_CONFIG, "[x] failed to lookup module on %s keyword\n", kwd.c_str());
139
mod_i = modlist.find((* kw_i).second);
140
if (mod_i == modlist.end()) {
141
ui->error("[x] failed to associate moule id!\n");
144
xprobe_debug(XPROBE_DEBUG_CONFIG,"[x] keyword: %s handled by module: %s\n", kwd.c_str(),
145
(*mod_i).second->get_name());
146
return (*mod_i).second;
149
int Xprobe_Module_Hdlr::loaded_mods_num(int mod_type) {
150
map<int, Xprobe_Module *>::iterator m_i;
153
for (m_i = modlist.begin(); m_i != modlist.end(); m_i++)
154
if ((*m_i).second->get_type() == mod_type) num++;
156
/* sometimes os_test module handles multiple keywords */
157
if (mod_type == XPROBE_MODULE_OSTEST && num < keywords)
163
int Xprobe_Module_Hdlr::modbyname(char *nm) {
165
xprobe_module_func_t *ptr;
168
ptr = mod_init_funcs;
169
while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {
171
if (!strcasecmp(ptr->name, nm)) return cnt;
178
void Xprobe_Module_Hdlr::display_mod_names(void) {
180
xprobe_module_func_t *ptr;
183
ptr = mod_init_funcs;
184
while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {
186
ui->msg("%s%c", ptr->name, cnt%4?'\t':'\n');
190
ui->msg("[%d] %s\n", cnt++, ptr->name);
199
Xprobe_Module_Hdlr::Xprobe_Module_Hdlr(void) {
204
Xprobe_Module_Hdlr::~Xprobe_Module_Hdlr(void) {
208
int Xprobe_Module_Hdlr::get_module_count() {
210
xprobe_module_func_t *ptr;
212
ptr = mod_init_funcs;
213
while (ptr !=NULL && ptr->name !=NULL && ptr->func != NULL) {