ec_plugins.c
上传用户:nilegod
上传日期:2007-01-08
资源大小:220k
文件大小:11k
- /*
- ettercap -- PlugIns module
- Copyright (C) 2001 ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- #include "include/ec_main.h"
- #ifdef PERMIT_PLUGINS // don't compile if plug-in not supported
- #include <dlfcn.h>
- #include <unistd.h>
- #include <stdarg.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <signal.h>
- #include <dirent.h>
- #include <sys/time.h>
- #include <errno.h>
- #include "include/ec_plugins.h"
- #include "include/ec_error.h"
- #ifdef HAVE_NCURSES
- #include <ncurses.h>
- #include "include/ec_interface_plugins.h"
- extern WINDOW *plugin_window, *main_window;
- extern short scroll_yp;
- extern int W_MAINX1, W_MAINY1, W_MAINX2, W_MAINY2;
- #endif
- #ifdef DEBUG
- #include "include/ec_debug.h"
- #endif
- #ifdef OPENBSD
- // The below define is a lie since we are really doing RTLD_LAZY since the
- // system doesn't support RTLD_NOW.
- #define RTLD_NOW 1
- #define RTLD_GLOBAL 0
- #endif
- PLUGINS *Plugins_list = NULL;
- // protos....
- int Plugin_Input(char *string, short size, short mode);
- void Plugin_Output(char *message, ...);
- void Plugin_SYS_Output(char *message, ...);
- void Plugin_RunPlugIn(char *name, char **argv);
- int Plugin_MakePlugList(void);
- char *Plugin_Getname(char *plugin);
- int Plugin_Input_GetChar_Block(char *string, short size);
- int Plugin_Input_GetChar_NonBlock(char *string, short size);
- // --------------------------
- void Plugin_RunPlugIn(char *name, char **argv)
- {
- static void *handle;
- char *Ette_Ver;
- void (*Start)(char **);
- #ifdef DEBUG
- Debug_msg("Plugin_RunPlugIn -- starting %s plugin", name);
- #endif
- handle = dlopen(name, RTLD_NOW | RTLD_GLOBAL);
- if (!handle)
- {
- #ifdef DEBUG
- Debug_msg("Plugin_RunPlugIn -- dlopen() | %s", dlerror());
- #endif
- Plugin_SYS_Output("Error Opening %s... (dlopen)", name);
- return;
- }
- Ette_Ver = dlsym(handle, "Ettercap_Version");
- if (Ette_Ver == NULL || strcmp(Ette_Ver, VERSION) )
- {
- Plugin_SYS_Output("This plugin is NOT compatible with ettercap %s", VERSION);
- Plugin_SYS_Output("It was compiled under ettercap %s", Ette_Ver);
- dlclose(handle);
- return;
- }
- Start = dlsym(handle, "PlugIn_Start");
- if (Start == NULL)
- {
- #ifdef DEBUG
- Debug_msg("Plugin_RunPlugIn -- dlsym() | %s", dlerror());
- #endif
- Plugin_SYS_Output("Error Opening %s... (dlsym)", name);
- return;
- }
- Plugin_SYS_Output("Starting %s plugin...", name);
- (*Start)(argv); // lounch the plugin
- if (!Options.normal)
- Plugin_SYS_Output("%s plugin ended. (press 'q' to quit...)", name);
- else
- Plugin_SYS_Output("%s plugin ended.", name);
- dlclose(handle);
- #ifdef DEBUG
- Debug_msg("Plugin_RunPlugIn -- shutting down %s plugin", name);
- #endif
- }
- int Plugin_Input(char *string, short size, short mode)
- {
- int nchars;
- if (mode == P_BLOCK)
- nchars = Plugin_Input_GetChar_Block(string, size);
- else // P_NONBLOCK
- nchars = Plugin_Input_GetChar_NonBlock(string, size);
- return nchars;
- }
- void Plugin_Output(char *message, ...)
- {
- va_list ap;
- char plug_output[250]; // should be enough
- #ifndef HAVE_VPRINTF
- #errors "Must have vsprintf()."
- #endif
- va_start(ap, message);
- vsnprintf(plug_output, 250, message, ap);
- va_end(ap);
- #ifdef HAVE_NCURSES
- if (!Options.normal)
- {
- wprintw(plugin_window, "%s", plug_output);
- pnoutrefresh(plugin_window, scroll_yp, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 2);
- doupdate();
- }
- else
- #endif
- {
- fprintf(stdout, "%s", plug_output);
- fflush(stdout);
- }
- }
- void Plugin_SYS_Output(char *message, ...)
- {
- va_list ap;
- char plug_output[250]; // should be enough
- #ifndef HAVE_VPRINTF
- #errors "Must have vsprintf()."
- #endif
- va_start(ap, message);
- vsnprintf(plug_output, 250, message, ap);
- va_end(ap);
- #ifdef HAVE_NCURSES
- if (!Options.normal)
- {
- #define HELP_COLOR 6
- #define NORM_COLOR 1
- wbkgdset(plugin_window, COLOR_PAIR(HELP_COLOR)); wattron(plugin_window, A_BOLD);
- wprintw(plugin_window, "n%sn", plug_output);
- wbkgdset(plugin_window, COLOR_PAIR(NORM_COLOR)); wattroff(plugin_window, A_BOLD);
- pnoutrefresh(plugin_window, scroll_yp, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 2);
- doupdate();
- }
- else
- #endif
- {
- fprintf(stdout, "n 33[36m %s