myconfig, configure option testing and fixing, monitor_fs()

This commit is contained in:
joonicks 2018-04-15 03:57:44 +02:00
parent db4842c42e
commit 5f0fdada3e
26 changed files with 462 additions and 264 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
# autogenerated files # autogenerated files
myconfig
src/Makefile src/Makefile
src/config.h src/config.h
src/mcmd.h src/mcmd.h

View File

@ -58,7 +58,7 @@ TRIVFILES = trivia/mkindex.c
SRCFILES = src/alias.c src/auth.c src/bounce.c src/channel.c src/core.c src/ctcp.c src/debug.c src/dns.c \ SRCFILES = src/alias.c src/auth.c src/bounce.c src/channel.c src/core.c src/ctcp.c src/debug.c src/dns.c \
src/function.c src/gencmd.c src/greet.c src/help.c src/hostinfo.c src/irc.c src/kicksay.c src/main.c src/mega.c \ src/function.c src/gencmd.c src/greet.c src/help.c src/hostinfo.c src/irc.c src/kicksay.c src/main.c src/mega.c \
src/net.c src/note.c src/notify.c src/ons.c src/parse.c src/partyline.c src/perl.c src/prot.c \ src/net.c src/note.c src/notify.c src/ons.c src/parse.c src/partyline.c src/perl.c src/prot.c \
src/python.c src/reset.c src/seen.c src/shit.c src/socket.c src/spy.c src/tcl.c \ src/python.c src/reset.c src/seen.c src/shit.c src/io.c src/spy.c src/tcl.c \
src/toybox.c src/trivia.c src/uptime.c src/user.c src/vars.c src/web.c \ src/toybox.c src/trivia.c src/uptime.c src/user.c src/vars.c src/web.c \
src/lib/md5.c src/lib/md5.h src/lib/string.c src/lib/md5.c src/lib/md5.h src/lib/string.c

View File

@ -1,5 +1,7 @@
3.1 -- WORK IN PROGRESS (~April, 2018) 3.1 -- WORK IN PROGRESS (~April, 2018)
* Added: configure now saves the options selected in ./myconfig for later re-use
* Fixed: Missing ifdef BOTNET in user.c
* Added: Git version hash included in version string if git environment is found. * Added: Git version hash included in version string if git environment is found.
* Added: RAND command (toybox). Usage: RAND [[min[-| ]]max|"nick"|"luser"] * Added: RAND command (toybox). Usage: RAND [[min[-| ]]max|"nick"|"luser"]
* Added: Energymech can now link with libmusl (--with-libmusl[=/PATH/TO/musl-gcc]) * Added: Energymech can now link with libmusl (--with-libmusl[=/PATH/TO/musl-gcc])

62
configure vendored
View File

@ -879,6 +879,8 @@ fi
# #
if [ "$has_md5" = yes ]; then if [ "$has_md5" = yes ]; then
echo "checking for MD5 in crypt() ... (cached) yes" echo "checking for MD5 in crypt() ... (cached) yes"
elif [ "$ft_md5" = no ]; then
has_md5=notest
elif [ ! "$ft_md5" = no ]; then elif [ ! "$ft_md5" = no ]; then
TESTC=config/pw.c TESTC=config/pw.c
echo $ac_n "checking for MD5 in crypt() ... "$ac_c echo $ac_n "checking for MD5 in crypt() ... "$ac_c
@ -922,7 +924,9 @@ fi
has_perl=no has_perl=no
perlinclude= perlinclude=
libperl= libperl=
if [ ! "$ft_perl" = no ]; then if [ "$ft_perl" = no ]; then
has_perl=notest
elif [ ! "$ft_perl" = no ]; then
echo $ac_n "checking for perl ... "$ac_c echo $ac_n "checking for perl ... "$ac_c
pinc1=`perl -MConfig -e 'print $Config{archlib}'` pinc1=`perl -MConfig -e 'print $Config{archlib}'`
if [ -r $pinc1/CORE/perl.h -a -r $pinc1/CORE/EXTERN.h -a -r $pinc1/CORE/XSUB.h ]; then if [ -r $pinc1/CORE/perl.h -a -r $pinc1/CORE/EXTERN.h -a -r $pinc1/CORE/XSUB.h ]; then
@ -943,7 +947,9 @@ fi
# check for tcl # check for tcl
# #
has_tcl=no has_tcl=no
if [ ! "$ft_tcl" = no ]; then if [ "$ft_tcl" = no ]; then
has_tcl=notest
elif [ ! "$ft_tcl" = no ]; then
echo $ac_n "checking for tcl ... "$ac_c echo $ac_n "checking for tcl ... "$ac_c
TESTC=config/tcl.c TESTC=config/tcl.c
tclconfig= tclconfig=
@ -990,7 +996,9 @@ fi
# check for python # check for python
# #
has_python=no has_python=no
if [ ! "$ft_python" = no ]; then if [ "$ft_python" = no ]; then
has_python=notest
elif [ ! "$ft_python" = no ]; then
echo $ac_n "checking for python ... "$ac_c echo $ac_n "checking for python ... "$ac_c
TESTC=config/python.c TESTC=config/python.c
libpython= libpython=
@ -1266,6 +1274,8 @@ unset ans
$out $ac_n "[STABLE] Password hashing with MD5? (less secure) ... [Y/n] "$ac_c $out $ac_n "[STABLE] Password hashing with MD5? (less secure) ... [Y/n] "$ac_c
if [ "$has_md5" = no ]; then if [ "$has_md5" = no ]; then
$out 'no (unsupported)' $out 'no (unsupported)'
elif [ "$has_md5" = notest ]; then
$out 'no'
else else
test "$ft_md5" && $out "$ft_md5" && ans=$ft_md5 test "$ft_md5" && $out "$ft_md5" && ans=$ft_md5
test -z "$ft_md5" && read ans test -z "$ft_md5" && read ans
@ -1283,14 +1293,13 @@ else
test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes -o "$ans" = internal && def_sha='#define SHACRYPT' test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes -o "$ans" = internal && def_sha='#define SHACRYPT'
fi fi
#
# perl support not yet functional (2009-05-11)
#
def_perl='#undef PERL' def_perl='#undef PERL'
unset ans unset ans
$out $ac_n "[ ALPHA] Scripting with Perl? ....................... [y/N] "$ac_c $out $ac_n "[ ALPHA] Scripting with Perl? ....................... [y/N] "$ac_c
if [ "$has_perl" = no ]; then if [ "$has_perl" = no ]; then
$out 'no (unsupported)' $out 'no (unsupported)'
elif [ "$has_perl" = notest ]; then
$out 'no'
else else
test "$ft_perl" && $out "$ft_perl" && ans=$ft_perl test "$ft_perl" && $out "$ft_perl" && ans=$ft_perl
test -z "$ft_perl" && read ans test -z "$ft_perl" && read ans
@ -1302,6 +1311,8 @@ unset ans
$out $ac_n "[ BETA ] Scripting with Python? ..................... [y/N] "$ac_c $out $ac_n "[ BETA ] Scripting with Python? ..................... [y/N] "$ac_c
if [ "$has_python" = no ]; then if [ "$has_python" = no ]; then
$out 'no (unsupported)' $out 'no (unsupported)'
elif [ "$has_python" = notest ]; then
$out 'no'
else else
test "$ft_python" && $out "$ft_python" && ans=$ft_python test "$ft_python" && $out "$ft_python" && ans=$ft_python
test -z "$ft_python" && read ans test -z "$ft_python" && read ans
@ -1317,6 +1328,8 @@ unset ans
$out $ac_n "[ BETA ] Scripting with Tcl? ........................ [y/N] "$ac_c $out $ac_n "[ BETA ] Scripting with Tcl? ........................ [y/N] "$ac_c
if [ "$has_tcl" = no ]; then if [ "$has_tcl" = no ]; then
$out 'no (unsupported)' $out 'no (unsupported)'
elif [ "$has_tcl" = notest ]; then
$out 'no'
else else
test "$ft_tcl" && $out "$ft_tcl" && ans=$ft_tcl test "$ft_tcl" && $out "$ft_tcl" && ans=$ft_tcl
test -z "$ft_tcl" && read ans test -z "$ft_tcl" && read ans
@ -1496,17 +1509,46 @@ if [ "$compile" = yes ]; then
exit exit
fi fi
save_myconfig() {
names="alias botnet bounce chanban ctcp dccfile debug dynamode dyncmd greet hostinfo idwrap ircd_ext libmusl md5
netcfg newbie note notify perl profiling python rawdns redirect seen session sha stats suppress tcl
telnet toybox trivia uptime urlcapture web wingate"
echo "./configure \\" > ./myconfig
chmod 755 ./myconfig
for uu in $names
do
eval v="\$ft_$uu"
case "$v" in
yes) echo "--with-"$uu" \\" >> ./myconfig ;;
no) echo "--without-"$uu" \\" >> ./myconfig ;;
esac
done
test "$compile" = yes && echo "--compile \\" >> ./myconfig
test "$install" = yes && echo "--install \\" >> ./myconfig
test "$silentopt" = yes && echo "--silence=options \\" >> ./myconfig
test "$ft_md5" = internal && echo "--md5=internal \\" >> ./myconfig
test "$ft_sha" = internal && echo "--sha=internal \\" >> ./myconfig
test "$optitype" = speed && echo "--optimize=speed \\" >> ./myconfig
test "$optitype" = size && echo "--optimize=size \\" >> ./myconfig
test "$cc_ofp_opt" = yes && echo "--use-ofp \\" >> ./myconfig
test "$cc_ofp_opt" = yes && echo "--no-ofp \\" >> ./myconfig
test ! "$try_libmusl" = no -a -x "$CC" && echo "--with-libmusl="$CC" \\" >> ./myconfig
}
if [ -w ./myconfig -o ! -e ./myconfig ]; then
save_myconfig
fi
echo '' echo ''
echo 'All done. You can now "make install"' echo 'All done. You can now "make install"'
if [ ! "$cores" = 1 ]; then if [ ! "$cores" = 1 ]; then
echo "For speedy compiling, use \`\`make -j$cores''" echo "For speedy compiling, use \`\`make -j$cores''"
fi fi
echo '' echo ''
echo "Your chosen ./configure options have been saved to ./myconfig"
echo 'if you wish to save ./myconfig in its current state, chmod -w ./myconfig'
echo ''
echo 'Submit your bugreports at https://github.com/MadCamel/energymech/issues' echo 'Submit your bugreports at https://github.com/MadCamel/energymech/issues'
echo '' echo ''
echo 'You have read the README file I hope?' echo 'You have read the README file I hope?'
echo '' echo ''
# make: 7.962u 0.870s 0:08.52 103.6% 0+0k 0+0io 0pf+0w
# make -j4: 8.779u 1.069s 0:03.11 316.0% 0+0k 0+0io 0pf+0w
# make -j8: 8.977u 1.064s 0:02.92 343.4% 0+0k 0+0io 0pf+0w

View File

@ -48,13 +48,13 @@ INCS = $(BASEINCLUDES) mcmd.h text.h usercombo.h
TESTFILES = aliastest safepathtest TESTFILES = aliastest safepathtest
OFILES = alias.o auth.o bounce.o channel.o core.o ctcp.o debug.o dns.o function.o greet.o \ OFILES = alias.o auth.o bounce.o channel.o core.o ctcp.o debug.o dns.o function.o greet.o \
help.o hostinfo.o irc.o kicksay.o main.o net.o note.o notify.o ons.o parse.o partyline.o \ help.o hostinfo.o io.o irc.o kicksay.o main.o net.o note.o notify.o ons.o parse.o partyline.o \
perl.o prot.o python.o reset.o seen.o shit.o socket.o spy.o tcl.o toybox.o \ perl.o prot.o python.o reset.o seen.o shit.o spy.o tcl.o toybox.o \
trivia.o uptime.o user.o vars.o web.o lib/string.o @MD5_O@ @SHA_O@ trivia.o uptime.o user.o vars.o web.o lib/string.o @MD5_O@ @SHA_O@
SRCFILES = alias.c auth.c bounce.c channel.c core.c ctcp.c debug.c dns.c function.c greet.c \ SRCFILES = alias.c auth.c bounce.c channel.c core.c ctcp.c debug.c dns.c function.c greet.c \
help.c hostinfo.c irc.c kicksay.c main.c net.c note.c notify.c ons.c parse.c partyline.c \ help.c hostinfo.c io.c irc.c kicksay.c main.c net.c note.c notify.c ons.c parse.c partyline.c \
perl.c prot.c python.c reset.c seen.c shit.c socket.c spy.c tcl.c toybox.c \ perl.c prot.c python.c reset.c seen.c shit.c spy.c tcl.c toybox.c \
trivia.c uptime.c user.c vars.c web.c lib/string.c @MD5_C@ @SHA_C@ trivia.c uptime.c user.c vars.c web.c lib/string.c @MD5_C@ @SHA_C@
.PHONY: all clean mega-install mega mega-static test commands .PHONY: all clean mega-install mega mega-static test commands
@ -66,7 +66,7 @@ all: $(INSTALLNAME)
# instead of doing extra parsing and handling while the bot is running. # instead of doing extra parsing and handling while the bot is running.
# #
gencmd: gencmd.c socket.c config.h structs.h gencmd: gencmd.c io.c config.h structs.h
$(CC) $(LFLAGS) -o gencmd gencmd.c $(CC) $(LFLAGS) -o gencmd gencmd.c
mcmd.h: gencmd mcmd.h: gencmd
@ -182,6 +182,9 @@ help.o: help.c $(INCS) usage.h
hostinfo.o: hostinfo.c $(INCS) hostinfo.o: hostinfo.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF) $(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
io.o: io.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
irc.o: irc.c $(INCS) irc.o: irc.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF) $(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
@ -227,9 +230,6 @@ seen.o: seen.c $(INCS)
shit.o: shit.c $(INCS) shit.o: shit.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF) $(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
socket.o: socket.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)
spy.o: spy.c $(INCS) spy.o: spy.c $(INCS)
$(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF) $(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< $(CPROF)

View File

@ -478,8 +478,8 @@ listcheck:
checksum = ""; checksum = "";
if (user->pass) if (user->pass)
{ {
sprintf(gsockdata,"%s %s %s",from,user->name,user->pass); sprintf(globaldata,"%s %s %s",from,user->name,user->pass);
checksum = makepass(gsockdata); checksum = makepass(globaldata);
} }
botnet_relay(NULL,"PA%s %s %s\n",user->name,from,checksum); botnet_relay(NULL,"PA%s %s %s\n",user->name,from,checksum);
#endif /* BOTNET */ #endif /* BOTNET */

View File

@ -1059,8 +1059,8 @@ void update(SequenceTime *this)
temp = TEXT_NOTINSERVLIST; temp = TEXT_NOTINSERVLIST;
if ((sp = find_server(current->server))) if ((sp = find_server(current->server)))
{ {
sprintf(gsockdata,"%s:%i",(*sp->realname) ? sp->realname : sp->name,sp->port); sprintf(globaldata,"%s:%i",(*sp->realname) ? sp->realname : sp->name,sp->port);
temp = gsockdata; temp = globaldata;
} }
chantemp = (current->activechan) ? current->activechan->name : TEXT_NONE; chantemp = (current->activechan) ? current->activechan->name : TEXT_NONE;
send_spy(SPYSTR_STATUS,"C:%s AC:%i CS:%s",chantemp,x,temp); send_spy(SPYSTR_STATUS,"C:%s AC:%i CS:%s",chantemp,x,temp);

View File

@ -26,6 +26,9 @@
#include "defines.h" #include "defines.h"
#include "structs.h" #include "structs.h"
#include "global.h" #include "global.h"
#ifdef TCL
#include <tcl.h>
#endif
#include "h.h" #include "h.h"
#include "settings.h" #include "settings.h"
@ -231,11 +234,12 @@ LS struct
#ifdef SCRIPTING #ifdef SCRIPTING
LS const DEFstruct SCRIPTdefs[] = LS const DEFstruct SCRIPTdefs[] =
{ {
{ HOOK_PARSE, "HOOK_PARSE" }, { MEV_PARSE, "MEV_PARSE" },
{ HOOK_TIMER, "HOOK_TIMER" }, { MEV_TIMER, "MEV_TIMER" },
{ HOOK_COMMAND, "HOOK_COMMAND" }, { MEV_COMMAND, "MEV_COMMAND" },
{ HOOK_BOTNET, "HOOK_BOTNET" }, { MEV_BOTNET, "MEV_BOTNET" },
{ HOOK_DCC_COMPLETE, "HOOK_DCC_COMPLETE" }, { MEV_DCC_COMPLETE, "MEV_DCC_COMPLETE" },
{ MEV_DNSRESULT, "MEV_DNSRESULT" },
#ifdef TCL #ifdef TCL
{ .v.func=tcl_timer_jump, "tcl_timer_jump" }, { .v.func=tcl_timer_jump, "tcl_timer_jump" },
{ .v.func=tcl_parse_jump, "tcl_parse_jump" }, { .v.func=tcl_parse_jump, "tcl_parse_jump" },
@ -1293,7 +1297,7 @@ void debug_scripthook(void)
debug(" ; func\t\t"mx_pfmt" %s\n",(mx_ptr)h->func,funcdef(SCRIPTdefs,h->func)); debug(" ; func\t\t"mx_pfmt" %s\n",(mx_ptr)h->func,funcdef(SCRIPTdefs,h->func));
debug(" ; guid\t\t%i\n",h->guid); debug(" ; guid\t\t%i\n",h->guid);
debug(" ; flags\t\t%s (%i)\n",strdef(SCRIPTdefs,h->flags),h->flags); debug(" ; flags\t\t%s (%i)\n",strdef(SCRIPTdefs,h->flags),h->flags);
if (h->flags == HOOK_TIMER) if (h->flags == MEV_TIMER)
{ {
debug(" ; timer\t\t"mx_pfmt"\n",(mx_ptr)h->type.timer); debug(" ; timer\t\t"mx_pfmt"\n",(mx_ptr)h->type.timer);
debug(" ; timer.second1\t%s ( 0..29)\n",uint32tobin(30,h->type.timer->second1)); debug(" ; timer.second1\t%s ( 0..29)\n",uint32tobin(30,h->type.timer->second1));

View File

@ -406,6 +406,9 @@ enum {
#ifdef URLCAPTURE #ifdef URLCAPTURE
#define SPY_URL 8 #define SPY_URL 8
#endif /* URLCAPTURE */ #endif /* URLCAPTURE */
#ifdef HOSTINFO
#define SPY_SYSMON 9
#endif /* HOSTINFO */
#define SPYF_ANY 1 #define SPYF_ANY 1
#define SPYF_CHANNEL (1 << SPY_CHANNEL) #define SPYF_CHANNEL (1 << SPY_CHANNEL)
@ -456,14 +459,14 @@ enum {
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
/* /*
* scripting hooks * scripting events
*/ */
#define HOOK_PARSE 0 #define MEV_PARSE 0
#define HOOK_TIMER 1 #define MEV_TIMER 1
#define HOOK_COMMAND 2 #define MEV_COMMAND 2
#define HOOK_BOTNET 3 #define MEV_BOTNET 3
#define HOOK_DCC_COMPLETE 4 #define MEV_DCC_COMPLETE 4
#define HOOK_DNS 5 #define MEV_DNSRESULT 5
/* /*
* *

View File

@ -200,7 +200,7 @@ struct in_addr *get_stored_ip(const char *ipdata)
*/ */
#ifdef SCRIPTING #ifdef SCRIPTING
void dns_hook(char *host, char * resolved) void dns_hook(char *host, char *resolved)
{ {
Hook *hook; Hook *hook;
Mech *backbot; Mech *backbot;
@ -208,7 +208,7 @@ void dns_hook(char *host, char * resolved)
backbot = current; backbot = current;
for(hook=hooklist;hook;hook=hook->next) for(hook=hooklist;hook;hook=hook->next)
{ {
if (hook->flags == HOOK_DNS && !stringcasecmp(host,hook->type.host)) if (hook->flags == MEV_DNSRESULT && !stringcasecmp(host,hook->type.host))
{ {
for(current=botlist;current;current=current->next) for(current=botlist;current;current=current->next)
{ {
@ -881,7 +881,7 @@ void do_dns(COMMAND_ARGS)
/* flip an IP backwards to resolve hostname */ /* flip an IP backwards to resolve hostname */
// a11.b22.c33.d44 // a11.b22.c33.d44
// d44.c33.b22.a11.in-addr.arpa // d44.c33.b22.a11.in-addr.arpa
dst = gsockdata; dst = globaldata;
flipstep: flipstep:
src = host; src = host;
dot = NULL; dot = NULL;
@ -902,9 +902,9 @@ flipstep:
} }
stringcpy(stringcpy(dst,host),".in-addr.arpa"); stringcpy(stringcpy(dst,host),".in-addr.arpa");
#ifdef DEBUG #ifdef DEBUG
debug("(do_dns) host flipped to %s\n",gsockdata); debug("(do_dns) host flipped to %s\n",globaldata);
#endif /* DEBUG */ #endif /* DEBUG */
host = gsockdata; host = globaldata;
} }
/* check if its in cache now */ /* check if its in cache now */
if ((res = poll_rawdns(host))) if ((res = poll_rawdns(host)))

View File

@ -230,7 +230,7 @@ void table_buffer(const char *format, ...)
int sz; int sz;
va_start(msg,format); va_start(msg,format);
sz = sizeof(Strp) + vsprintf(gsockdata,format,msg); sz = sizeof(Strp) + vsprintf(globaldata,format,msg);
va_end(msg); va_end(msg);
for(sp=&e_table;*sp;sp=&(*sp)->next) for(sp=&e_table;*sp;sp=&(*sp)->next)
@ -239,7 +239,7 @@ void table_buffer(const char *format, ...)
set_mallocdoer(table_buffer); set_mallocdoer(table_buffer);
*sp = (Strp*)Calloc(sz); *sp = (Strp*)Calloc(sz);
/* Calloc sets to zero (*sp)->next = NULL; */ /* Calloc sets to zero (*sp)->next = NULL; */
stringcpy((*sp)->p,gsockdata); stringcpy((*sp)->p,globaldata);
} }
void table_send(const char *from, const int space) void table_send(const char *from, const int space)

View File

@ -22,9 +22,9 @@
#include "config.h" #include "config.h"
#include "structs.h" #include "structs.h"
char gsockdata[MAXLEN]; char globaldata[MAXLEN];
#include "socket.c" #include "io.c"
/* /*

View File

@ -68,6 +68,9 @@ BEG const char SPYSTR_BOTNET[] MDEF("botnet");
#ifdef URLCAPTURE #ifdef URLCAPTURE
BEG const char SPYSTR_URL[] MDEF("url"); BEG const char SPYSTR_URL[] MDEF("url");
#endif /* URLCAPTURE */ #endif /* URLCAPTURE */
#ifdef URLCAPTURE
BEG const char SPYSTR_SYSMON[] MDEF("sysmon");
#endif /* URLCAPTURE */
BEG const char STR_MECHRESET[] MDEF("MECHRESET="); BEG const char STR_MECHRESET[] MDEF("MECHRESET=");
@ -117,7 +120,7 @@ BEG User __internal_users[2];
* generic output buffer, can be used as buffer in any `leaf' function * generic output buffer, can be used as buffer in any `leaf' function
* (functions that do not call any other non-trivial functions) * (functions that do not call any other non-trivial functions)
*/ */
BEG char gsockdata[MAXLEN]; BEG char globaldata[MAXLEN];
BEG char nick_buf[MAXHOSTLEN]; BEG char nick_buf[MAXHOSTLEN];
BEG char nuh_buf[NUHLEN]; BEG char nuh_buf[NUHLEN];
@ -452,6 +455,19 @@ LS coreServerGroup defaultServerGroup =
"default" /* name */ "default" /* name */
}; };
LS struct
{
const char *string;
const int id;
} meventstrings[] = {
{ "parse", MEV_PARSE },
{ "timer", MEV_TIMER },
{ "command", MEV_COMMAND },
{ "botnet", MEV_BOTNET },
{ "dcc_complete", MEV_DCC_COMPLETE },
{ "dnsresult", MEV_DNSRESULT }};
#else /* MAIN_C */ #else /* MAIN_C */
extern const uchar tolowertab[]; extern const uchar tolowertab[];

91
src/h.h
View File

@ -327,12 +327,33 @@ void do_usage(COMMAND_ARGS) __page(CMD1_SEG);
/* hostinfo.c */ /* hostinfo.c */
void monitor_fs(const char *);
void select_monitor();
void process_monitor();
int parse_proc_status(char *line) __page(CMD1_SEG); int parse_proc_status(char *line) __page(CMD1_SEG);
int parse_proc_cpuinfo(char *line) __page(CMD1_SEG); int parse_proc_cpuinfo(char *line) __page(CMD1_SEG);
void do_hostinfo(COMMAND_ARGS) __page(CMD1_SEG); void do_hostinfo(COMMAND_ARGS) __page(CMD1_SEG);
void do_meminfo(COMMAND_ARGS) __page(CMD1_SEG); void do_meminfo(COMMAND_ARGS) __page(CMD1_SEG);
void do_cpuinfo(COMMAND_ARGS) __page(CMD1_SEG); void do_cpuinfo(COMMAND_ARGS) __page(CMD1_SEG);
/* io.c */
LS uint32_t get_ip(const char *) __page(CORE_SEG);
LS void SockFlags(int) __page(CORE_SEG);
LS int SockOpts(void) __page(CORE_SEG);
LS int SockListener(int) __page(CORE_SEG);
LS int SockConnect(char *, int, int) __page(CORE_SEG);
LS int SockAccept(int) __page(CORE_SEG);
int to_file(int sock, const char *format, ...);
void to_server(char *format, ...);
void to_user_q(const char *, const char *, ...);
void to_user(const char *, const char *, ...);
char *sockread(int, char *, char *);
void readline(int, int (*)(char *));
void remove_ks(KillSock *);
int killsock(int);
LS void do_clearqueue(COMMAND_ARGS) __page(CMD1_SEG);
/* irc.c */ /* irc.c */
LS void make_ireq(int, const char *, const char *) __page(CMD1_SEG); LS void make_ireq(int, const char *, const char *) __page(CMD1_SEG);
@ -426,9 +447,6 @@ void select_botnet(void);
void process_botnet(void); void process_botnet(void);
void do_link(COMMAND_ARGS) __page(CMD1_SEG); void do_link(COMMAND_ARGS) __page(CMD1_SEG);
void do_cmd(COMMAND_ARGS) __page(CMD1_SEG); void do_cmd(COMMAND_ARGS) __page(CMD1_SEG);
/* net_chan.c */
/* note.c */ /* note.c */
@ -555,20 +573,24 @@ LS void do_unban(COMMAND_ARGS) __page(CMD1_SEG);
LS void do_banlist(COMMAND_ARGS) __page(CMD1_SEG); LS void do_banlist(COMMAND_ARGS) __page(CMD1_SEG);
/* python.c */ /* python.c */
#ifdef PYTHON #ifdef PYTHON
char *python_unicode2char(PyUnicodeObject *obj); #ifdef DEBUG_C
PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds); PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds);
PyObject *python_unhook(PyObject *self, PyObject *args, PyObject *keywds); PyObject *python_unhook(PyObject *self, PyObject *args, PyObject *keywds);
#endif
//char *python_unicode2char(PyUnicodeObject *obj);
//PyObject *python_userlevel(PyObject *self, PyObject *args, PyObject *keywds);
//PyObject *python_to_server(PyObject *self, PyObject *args, PyObject *keywds);
//PyObject *python_to_file(PyObject *self, PyObject *args, PyObject *keywds);
//static PyObject *python_dcc_sendfile(PyObject *self, PyObject *args, PyObject *keywds);
//PyObject *python_debug(PyObject *self, PyObject *args);
//PyMODINIT_FUNC pythonInit(void);
int python_parse_jump(char *, char *, Hook *);
int python_timer_jump(Hook *hook); int python_timer_jump(Hook *hook);
void python_dcc_complete(Client *client, int cps); void python_dcc_complete(Client *client, int cps);
PyObject *python_userlevel(PyObject *self, PyObject *args, PyObject *keywds);
PyObject *python_to_server(PyObject *self, PyObject *args, PyObject *keywds);
PyObject *python_to_file(PyObject *self, PyObject *args, PyObject *keywds);
static PyObject *python_dcc_sendfile(PyObject *self, PyObject *args, PyObject *keywds);
PyObject *python_debug(PyObject *self, PyObject *args);
int python_dns_jump(char *host, char *resolved, Hook *hook); int python_dns_jump(char *host, char *resolved, Hook *hook);
PyMODINIT_FUNC pythonInit(void);
void init_python(void); void init_python(void);
void free_python(void); void free_python(void);
void do_python(COMMAND_ARGS) __page(CMD1_SEG); void do_python(COMMAND_ARGS) __page(CMD1_SEG);
@ -576,12 +598,6 @@ void do_pythonscript(COMMAND_ARGS) __page(CMD1_SEG);
#endif /* PYTHON */ #endif /* PYTHON */
/* redirect.c */
int begin_redirect(char *, char *);
void send_redirect(char *);
void end_redirect(void);
/* reset.c */ /* reset.c */
char *recover_client(char *env); char *recover_client(char *env);
@ -613,24 +629,6 @@ void do_rshit(COMMAND_ARGS) __page(CMD1_SEG);
void do_shitlist(COMMAND_ARGS) __page(CMD1_SEG); void do_shitlist(COMMAND_ARGS) __page(CMD1_SEG);
void do_clearshit(COMMAND_ARGS) __page(CMD1_SEG); void do_clearshit(COMMAND_ARGS) __page(CMD1_SEG);
/* socket.c */
LS uint32_t get_ip(const char *) __page(CORE_SEG);
LS void SockFlags(int) __page(CORE_SEG);
LS int SockOpts(void) __page(CORE_SEG);
LS int SockListener(int) __page(CORE_SEG);
LS int SockConnect(char *, int, int) __page(CORE_SEG);
LS int SockAccept(int) __page(CORE_SEG);
int to_file(int sock, const char *format, ...);
void to_server(char *format, ...);
void to_user_q(const char *, const char *, ...);
void to_user(const char *, const char *, ...);
char *sockread(int, char *, char *);
void readline(int, int (*)(char *));
void remove_ks(KillSock *);
int killsock(int);
LS void do_clearqueue(COMMAND_ARGS) __page(CMD1_SEG);
/* spy.c */ /* spy.c */
void send_spy(const char *src, const char *format, ...); void send_spy(const char *src, const char *format, ...);
@ -639,6 +637,9 @@ void spy_typecount(Mech *bot);
int spy_source(char *from, int *t_src, const char **src); int spy_source(char *from, int *t_src, const char **src);
char *urlhost(const char *); char *urlhost(const char *);
LS void urlcapture(const char *) __page(CORE_SEG); LS void urlcapture(const char *) __page(CORE_SEG);
int begin_redirect(char *, char *);
void send_redirect(char *);
void end_redirect(void);
void stats_loghour(Chan *chan, char *filename, int hour); void stats_loghour(Chan *chan, char *filename, int hour);
void stats_plusminususer(Chan *chan, int plusminus); void stats_plusminususer(Chan *chan, int plusminus);
void do_spy(COMMAND_ARGS) __page(CMD1_SEG); void do_spy(COMMAND_ARGS) __page(CMD1_SEG);
@ -649,20 +650,22 @@ LS void do_urlhist(COMMAND_ARGS) __page(CMD1_SEG);
/* tcl.c */ /* tcl.c */
#ifdef TCL #ifdef TCL
LS char *tcl_var_read(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags); //LS char *tcl_var_read(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
LS char *tcl_var_write(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags); //LS char *tcl_var_write(Tcl_TVInfo *vinfo, Tcl_Interp *I, char *n1, char *n2, int flags);
LS int tcl_timer_jump(Hook *hook); LS int tcl_timer_jump(Hook *hook);
LS int tcl_parse_jump(char *from, char *rest, Hook *hook); LS int tcl_parse_jump(char *from, char *rest, Hook *hook);
LS void tcl_dcc_complete(Client *client, int cps); LS void tcl_dcc_complete(Client *client, int cps);
#ifdef DEBUG_C
LS int tcl_hook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); LS int tcl_hook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_unhook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); #endif
LS int tcl_userlevel(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_unhook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_debug(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_userlevel(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_to_server(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_debug(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_to_file(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_to_server(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_dcc_sendfile(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_to_file(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_dns_jump(char *host, char *resolved, Hook *hook); //LS int tcl_dcc_sendfile(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]); //LS int tcl_dns_jump(char *host, char *resolved, Hook *hook);
//LS int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[]);
LS void init_tcl(void); LS void init_tcl(void);
LS void do_tcl(COMMAND_ARGS) __page(CMD1_SEG); LS void do_tcl(COMMAND_ARGS) __page(CMD1_SEG);

View File

@ -20,14 +20,13 @@
*/ */
#define HOSTINFO_C #define HOSTINFO_C
#include "config.h" #include "config.h"
#ifdef HOSTINFO #ifdef HOSTINFO
#include "defines.h" #include "defines.h"
#include "structs.h" #include "structs.h"
#include "global.h" #include "global.h"
#include "h.h" #include "h.h"
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/inotify.h>
/* /*
Emulate this, but use the same memory space: Emulate this, but use the same memory space:
@ -279,11 +278,11 @@ void do_cpuinfo(COMMAND_ARGS)
#else #else
return; return;
#endif #endif
n = read(fd,gsockdata,MSGLEN-2); n = read(fd,globaldata,MSGLEN-2);
gsockdata[n] = 0; globaldata[n] = 0;
close(fd); close(fd);
rest = gsockdata; rest = globaldata;
a1 = chop(&rest); a1 = chop(&rest);
a2 = chop(&rest); a2 = chop(&rest);
a3 = chop(&rest); a3 = chop(&rest);
@ -316,4 +315,99 @@ void do_cpuinfo(COMMAND_ARGS)
omni+1,bogostr,cpustr,a1,a2,a3); omni+1,bogostr,cpustr,a1,a2,a3);
} }
//---------------------------------------------------------------------------------------------------------------------------------------------------
#ifdef DEBUG
struct
{
int value;
char *str;
} in2str[] =
{
{ IN_ACCESS, "IN_ACCESS" }, // File was accessed (read)
{ IN_ATTRIB, "IN_ATTRIB" }, // Metadata changed, e.g., permissions, timestamps, extended attributes, link count, UID, GID, etc.
{ IN_CLOSE_WRITE, "IN_CLOSE_WRITE" }, // File opened for writing was closed
{ IN_CLOSE_NOWRITE, "IN_CLOSE_NOWRITE" }, // File not opened for writing was closed
{ IN_CREATE, "IN_CREATE" }, // File/directory created in watched directory
{ IN_DELETE, "IN_DELETE" }, // File/directory deleted from watched directory
{ IN_DELETE_SELF, "IN_DELETE_SELF" }, // Watched file/directory was itself deleted
{ IN_MODIFY, "IN_MODIFY" }, // File was modified
{ IN_MOVE_SELF, "IN_MOVE_SELF" }, // Watched file/directory was itself moved
{ IN_MOVED_FROM, "IN_MOVED_FROM" }, // Generated for the directory containing the old filename when a file is renamed
{ IN_MOVED_TO, "IN_MOVED_TO" }, // Generated for the directory containing the new filename when a file is renamed
{ IN_OPEN, "IN_OPEN" }, // File was opened
{ 0, NULL }
};
char *inomask2str(uint32_t mask, char *dst)
{
const char *src;
int i,n = 0;
for(i=0;in2str[i].str;i++)
{
if ((mask & in2str[i].value) == in2str[i].value)
{
if (n)
dst[n++] = '|';
src = in2str[i].str;
for(;src[n];n++)
dst[n] = src[n];
}
}
dst[n] = 0;
return(dst);
}
#endif /* DEBUG */
int ino;
void monitor_fs(const char *file)
{
struct inotify_event *ivent;
ino = inotify_init();
inotify_add_watch(ino,file,IN_ALL_EVENTS);
#ifdef DEBUG
debug("(monitor_fs) added notifier on %s [fd %i]\n",file,ino);
#endif
}
void select_monitor()
{
FD_SET(ino,&read_fds);
}
void process_monitor()
{
struct inotify_event *ivent;
char tmp[256];
int n;
if (FD_ISSET(ino,&read_fds))
{
ivent = (struct inotify_event *)&globaldata;
n = read(ino,globaldata,sizeof(struct inotify_event));
if (ivent->len > 0)
read(ino,ivent->name,ivent->len);
else
*ivent->name = 0;
#ifdef DEBUG
debug("ino %i, n %i, sz %i\n",ino,n,sizeof(in2str));
debug("wd %i, mask %lu, cookie %lu, len %lu, name %s\n",
ivent->wd,ivent->mask,ivent->cookie,ivent->len,ivent->name);
debug("%s\n",inomask2str(ivent->mask,tmp));
debug("(process_monitor) ino %i bytes read, int wd = %i, uint32_t mask = %s (%lu), uint32_t cookie = %lu, uint32_t len = %lu, char name = %s\n",
n,ivent->wd,inomask2str(ivent->mask,tmp),ivent->mask,ivent->cookie,ivent->len,ivent->name);
#endif
if ((ivent->mask & IN_CLOSE_WRITE) == IN_CLOSE_WRITE)
return;
send_global(SPYSTR_SYSMON,"Alert: Executable was touched");
}
}
#endif /* HOSTINFO */ #endif /* HOSTINFO */

View File

@ -281,19 +281,19 @@ int to_file(int sock, const char *format, ...)
return(-1); return(-1);
va_start(msg,format); va_start(msg,format);
vsprintf(gsockdata,format,msg); vsprintf(globaldata,format,msg);
va_end(msg); va_end(msg);
#if defined(DEBUG) && !defined(GENCMD_C) #if defined(DEBUG) && !defined(GENCMD_C)
i = write(sock,gsockdata,strlen(gsockdata)); i = write(sock,globaldata,strlen(globaldata));
rest = gsockdata; rest = globaldata;
while((line = get_token(&rest,"\n"))) /* rest cannot be NULL */ while((line = get_token(&rest,"\n"))) /* rest cannot be NULL */
debug("(out) {%i} %s\n",sock,nullstr(line)); debug("(out) {%i} %s\n",sock,nullstr(line));
if (i < 0) if (i < 0)
debug("(out) {%i} errno = %i\n",sock,errno); debug("(out) {%i} errno = %i\n",sock,errno);
return(i); return(i);
#else /* DEBUG */ #else /* DEBUG */
return(write(sock,gsockdata,strlen(gsockdata))); return(write(sock,globaldata,strlen(globaldata)));
#endif /* DEBUG */ #endif /* DEBUG */
} }
@ -314,7 +314,7 @@ void to_server(char *format, ...)
return; return;
va_start(msg,format); va_start(msg,format);
vsprintf(gsockdata,format,msg); vsprintf(globaldata,format,msg);
va_end(msg); va_end(msg);
/* /*
@ -323,7 +323,7 @@ void to_server(char *format, ...)
*/ */
current->sendq_time += 2; current->sendq_time += 2;
if (write(current->sock,gsockdata,strlen(gsockdata)) < 0) if (write(current->sock,globaldata,strlen(globaldata)) < 0)
{ {
#ifdef DEBUG #ifdef DEBUG
debug("[StS] {%i} errno = %i\n",current->sock,errno); debug("[StS] {%i} errno = %i\n",current->sock,errno);
@ -334,7 +334,7 @@ void to_server(char *format, ...)
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
rest = gsockdata; rest = globaldata;
while((line = get_token(&rest,"\n"))) /* rest cannot be NULL */ while((line = get_token(&rest,"\n"))) /* rest cannot be NULL */
debug("[StS] {%i} %s\n",current->sock,line); debug("[StS] {%i} %s\n",current->sock,line);
#endif /* DEBUG */ #endif /* DEBUG */
@ -531,7 +531,7 @@ char *sockread(int s, char *rest, char *line)
} }
rdst = src; rdst = src;
n = read(s,gsockdata,MSGLEN-2); n = read(s,globaldata,MSGLEN-2);
switch(n) switch(n)
{ {
case 0: case 0:
@ -540,8 +540,8 @@ char *sockread(int s, char *rest, char *line)
return(NULL); return(NULL);
} }
gsockdata[n] = 0; globaldata[n] = 0;
src = gsockdata; src = globaldata;
while(*src) while(*src)
{ {

View File

@ -517,6 +517,10 @@ mainloop:
select_bounce(); select_bounce();
#endif /* BOUNCE */ #endif /* BOUNCE */
#ifdef HOSTINFO
select_monitor();
#endif
/* /*
* unset here, reset if needed in bot loop * unset here, reset if needed in bot loop
*/ */
@ -790,6 +794,10 @@ restart_die:
process_web(); process_web();
#endif /* WEB */ #endif /* WEB */
#ifdef HOSTINFO
process_monitor();
#endif
#ifdef TRIVIA #ifdef TRIVIA
trivia_tick(); trivia_tick();
#endif /* TRIVIA */ #endif /* TRIVIA */
@ -1134,6 +1142,10 @@ int main(int argc, char **argv, char **envp)
#endif /* DEBUG */ #endif /* DEBUG */
} }
#ifdef HOSTINFO
monitor_fs(executable);
#endif
if (startup == 666) if (startup == 666)
exit(0); exit(0);
startup = FALSE; startup = FALSE;

View File

@ -23,6 +23,7 @@
#include "greet.c" #include "greet.c"
#include "help.c" #include "help.c"
#include "hostinfo.c" #include "hostinfo.c"
#include "io.c"
#include "irc.c" #include "irc.c"
#include "kicksay.c" #include "kicksay.c"
#include "lib/string.c" #include "lib/string.c"
@ -39,7 +40,6 @@
#include "reset.c" #include "reset.c"
#include "seen.c" #include "seen.c"
#include "shit.c" #include "shit.c"
#include "socket.c"
#include "spy.c" #include "spy.c"
#include "tcl.c" #include "tcl.c"
#include "toybox.c" #include "toybox.c"

View File

@ -185,15 +185,15 @@ void botnet_relay(BotNet *source, char *format, ...)
if (!sz) if (!sz)
{ {
va_start(msg,format); va_start(msg,format);
vsprintf(gsockdata,format,msg); vsprintf(globaldata,format,msg);
va_end(msg); va_end(msg);
sz = strlen(gsockdata); sz = strlen(globaldata);
} }
if (write(bn->sock,gsockdata,sz) < 0) if (write(bn->sock,globaldata,sz) < 0)
botnet_deaduplink(bn); botnet_deaduplink(bn);
#ifdef DEBUG #ifdef DEBUG
debug("[bnr] {%i} %s",bn->sock,gsockdata); debug("[bnr] {%i} %s",bn->sock,globaldata);
#endif /* DEBUG */ #endif /* DEBUG */
} }
} }
@ -927,8 +927,8 @@ void partyAuth(BotNet *bn, char *rest)
m = 0; m = 0;
if (user->pass) if (user->pass)
{ {
sprintf(gsockdata,"%s %s %s",userhost,user->name,user->pass); sprintf(globaldata,"%s %s %s",userhost,user->name,user->pass);
m = passmatch(gsockdata,checksum); m = passmatch(globaldata,checksum);
} }
if (m) if (m)
{ {

View File

@ -511,7 +511,7 @@ recheck_alias:
/* /*
* does the hook match? * does the hook match?
*/ */
if (hook->flags == HOOK_COMMAND && !stringcasecmp(command,hook->type.command)) if (hook->flags == MEV_COMMAND && !stringcasecmp(command,hook->type.command))
{ {
if (hook->func(from,rest,hook)) if (hook->func(from,rest,hook))
/* if the hook returns non-zero, the input should not be parsed internally */ /* if the hook returns non-zero, the input should not be parsed internally */

View File

@ -1513,7 +1513,7 @@ void parseline(char *rest)
/* /*
* does the hook match? * does the hook match?
*/ */
if (hook->flags == HOOK_PARSE && !stringcasecmp(command,hook->type.command)) if (hook->flags == MEV_PARSE && !stringcasecmp(command,hook->type.command))
{ {
if (hook->func(from,rest,hook)) if (hook->func(from,rest,hook))
/* if the hook returns non-zero, the input should not be parsed internally */ /* if the hook returns non-zero, the input should not be parsed internally */

View File

@ -40,10 +40,10 @@ void send_kick(Chan *chan, const char *nick, const char *format, ...)
va_list vargs; va_list vargs;
/* /*
* gsockdata safe to use since we're a `tail' function * globaldata safe to use since we're a `tail' function
*/ */
va_start(vargs,format); va_start(vargs,format);
vsprintf(gsockdata,format,vargs); vsprintf(globaldata,format,vargs);
va_end(vargs); va_end(vargs);
pp = &chan->kicklist; pp = &chan->kicklist;
@ -51,11 +51,11 @@ void send_kick(Chan *chan, const char *nick, const char *format, ...)
pp = &(*pp)->next; pp = &(*pp)->next;
set_mallocdoer(send_kick); set_mallocdoer(send_kick);
*pp = new = (qKick*)Calloc(sizeof(qKick) + Strlen2(nick,gsockdata)); // gsockdata is never NULL *pp = new = (qKick*)Calloc(sizeof(qKick) + Strlen2(nick,globaldata)); // globaldata is never NULL
/* Calloc sets to zero new->next = NULL; */ /* Calloc sets to zero new->next = NULL; */
new->reason = stringcpy(new->nick,nick) + 1; new->reason = stringcpy(new->nick,nick) + 1;
stringcpy(new->reason,gsockdata); stringcpy(new->reason,globaldata);
} }
void push_kicks(Chan *chan) void push_kicks(Chan *chan)
@ -589,7 +589,7 @@ void chanban_action(char *nick, char *channel, Shit *shit)
cu->flags |= CU_CHANBAN; cu->flags |= CU_CHANBAN;
format_uh(nuh,1); // returns mask in 'nuh' buffer (nuh_buf) format_uh(nuh,1); // returns mask in 'nuh' buffer (nuh_buf)
send_mode(CurrentChan,90,QM_RAWMODE,'+','b',(void*)nuh); send_mode(CurrentChan,90,QM_RAWMODE,'+','b',(void*)nuh);
send_kick(CurrentChan,nick,"%s (%s)",shit->reason,channel); // clobbers gsockdata send_kick(CurrentChan,nick,"%s (%s)",shit->reason,channel); // clobbers globaldata
} }
} }
} }

View File

@ -49,16 +49,17 @@ by Nemesis128 <stnsls@gmail.com>
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
char *python_unicode2char(PyUnicodeObject *obj) char *python_unicode2char(PyUnicodeObject *obj)
{ /* try to get a valid char* from PyUnicode object. { /* try to get a valid char* from PyUnicode object.
returned str must be free'd afterwards. */ returned str must be free'd afterwards. */
int sz = PyUnicode_GET_SIZE(obj); int sz = PyUnicode_GET_SIZE(obj);
wchar_t *wcs = (wchar_t*) malloc(sizeof(wchar_t) * sz);
PyUnicode_AsWideChar(obj, wcs, sz); wchar_t *wcs = (wchar_t*) malloc(sizeof(wchar_t) * sz);
char *cs = (char*) malloc(sizeof(char) * (sz + 1)); PyUnicode_AsWideChar(obj, wcs, sz);
wcstombs(cs, wcs, sz); char *cs = (char*) malloc(sizeof(char) * (sz + 1));
cs[sz] = '\0'; wcstombs(cs, wcs, sz);
free(wcs); cs[sz] = '\0';
return cs; free(wcs);
return cs;
} }
#endif /* Py3k */ #endif /* Py3k */
@ -66,39 +67,42 @@ char *python_unicode2char(PyUnicodeObject *obj)
static PyObject *python_error; /* emech exception object */ static PyObject *python_error; /* emech exception object */
static PyObject *python_getvar(PyObject *self, PyObject *args) static PyObject *python_getvar(PyObject *self, PyObject *args)
{ /* get some global var */ { /* get some global var */
int vartype;
#ifdef DEBUG #ifdef DEBUG
if (!current) if (!current)
{ {
PyErr_SetString(python_error, "(python_getvar) No current bot?!"); PyErr_SetString(python_error, "(python_getvar) No current bot?!");
return NULL; return NULL;
} }
#endif /* DEBUG */ #endif /* DEBUG */
int vartype;
if (!PyArg_ParseTuple(args, "i", &vartype)) if (!PyArg_ParseTuple(args, "i", &vartype))
return NULL; return NULL;
switch (vartype)
{ switch(vartype)
case PYVAR_guid: {
return Py_BuildValue("i", current ? current->guid : -1); case PYVAR_guid:
case PYVAR_currentnick: return Py_BuildValue("i", current ? current->guid : -1);
return Py_BuildValue("s", CurrentNick); case PYVAR_currentnick:
case PYVAR_botnick: return Py_BuildValue("s", CurrentNick);
return Py_BuildValue("s", current && current->nick ? current->nick : ""); case PYVAR_botnick:
case PYVAR_wantnick: return Py_BuildValue("s", current && current->nick ? current->nick : "");
return Py_BuildValue("s", current && current->wantnick ? current->wantnick : ""); case PYVAR_wantnick:
case PYVAR_userhost: return Py_BuildValue("s", current && current->wantnick ? current->wantnick : "");
return Py_BuildValue("s", current && current->userhost ? current->userhost : ""); case PYVAR_userhost:
case PYVAR_server: return Py_BuildValue("s", current && current->userhost ? current->userhost : "");
return Py_BuildValue("i", current && current->server ? current->server : -1); case PYVAR_server:
case PYVAR_nextserver: return Py_BuildValue("i", current && current->server ? current->server : -1);
return Py_BuildValue("i", current && current->nextserver ? current->nextserver : -1); case PYVAR_nextserver:
case PYVAR_currentchan: return Py_BuildValue("i", current && current->nextserver ? current->nextserver : -1);
return Py_BuildValue("s", current && current->activechan ? current->activechan->name : ""); case PYVAR_currentchan:
default: return Py_BuildValue("s", current && current->activechan ? current->activechan->name : "");
PyErr_SetString(python_error, "(python_getvar) invalid var"); default:
return NULL; PyErr_SetString(python_error, "(python_getvar) invalid var");
} return NULL;
}
} }
/* From channel.c */ /* From channel.c */
@ -106,15 +110,21 @@ static PyObject *python_getvar(PyObject *self, PyObject *args)
static PyObject *python_is_chanuser(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_is_chanuser(PyObject *self, PyObject *args, PyObject *keywds)
/* Return True if $nick is on $chan, else False */ /* Return True if $nick is on $chan, else False */
{ {
char *chan, *nick; char *chan, *nick;
static char *kwlist[] = {"chan", "nick", NULL}; static char *kwlist[] = {"chan", "nick", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &chan, &nick))
return NULL; if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &chan, &nick))
Chan *ch = (Chan*) find_channel(chan, CHAN_ANY); return NULL;
if (!ch) Py_RETURN_FALSE;
ChanUser *cu = find_chanuser(ch, nick); Chan *ch = (Chan*) find_channel(chan, CHAN_ANY);
if (!cu) Py_RETURN_FALSE;
Py_RETURN_TRUE; if (!ch)
Py_RETURN_FALSE;
ChanUser *cu = find_chanuser(ch, nick);
if (!cu)
Py_RETURN_FALSE;
Py_RETURN_TRUE;
} }
#if 0 #if 0
@ -122,38 +132,41 @@ static PyObject *python_is_chanuser(PyObject *self, PyObject *args, PyObject *ke
static PyObject *python_do_join(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_do_join(PyObject *self, PyObject *args, PyObject *keywds)
/* Join a channel */ /* Join a channel */
{ {
char *from, *to="", *rest; char *from, *to="", *rest;
int cmdaccess = 100; int cmdaccess = 100;
static char *kwlist[] = {"from", "rest", "cmdaccess", NULL}; static char *kwlist[] = {"from", "rest", "cmdaccess", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|i", kwlist,
&from, &rest, &cmdaccess)) if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|i", kwlist, &from, &rest, &cmdaccess))
return NULL; return NULL;
do_join(from, to, rest, cmdaccess);
Py_RETURN_NONE; do_join(from, to, rest, cmdaccess);
Py_RETURN_NONE;
} }
static PyObject *python_do_part(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_do_part(PyObject *self, PyObject *args, PyObject *keywds)
/* Part a channel */ /* Part a channel */
{ {
char *from, *to, *rest=""; char *from, *to, *rest="";
int cmdaccess = 100; int cmdaccess = 100;
static char *kwlist[] = {"from", "to", NULL}; static char *kwlist[] = {"from", "to", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &from, &to)) if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &from, &to))
return NULL; return NULL;
do_part(from, to, rest, cmdaccess); do_part(from, to, rest, cmdaccess);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject *python_do_cycle(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_do_cycle(PyObject *self, PyObject *args, PyObject *keywds)
/* Cycle a channel */ /* Cycle a channel */
{ {
char *from, *to, *rest=""; char *from, *to, *rest="";
int cmdaccess = 100; int cmdaccess = 100;
static char *kwlist[] = {"from", "to", NULL}; static char *kwlist[] = {"from", "to", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &from, &to))
return NULL; if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &from, &to))
do_cycle(from, to, rest, cmdaccess); return NULL;
Py_RETURN_NONE;
do_cycle(from, to, rest, cmdaccess);
Py_RETURN_NONE;
} }
static PyObject *python_do_wall(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_do_wall(PyObject *self, PyObject *args, PyObject *keywds)
@ -239,13 +252,16 @@ static PyObject *python_do_idle(PyObject *self, PyObject *args, PyObject *keywds
static PyObject *python_find_nuh(PyObject *self, PyObject *args, PyObject *keywds) static PyObject *python_find_nuh(PyObject *self, PyObject *args, PyObject *keywds)
/* Find nuh */ /* Find nuh */
{ {
char *nick, *nuh; char *nick, *nuh;
static char *kwlist[] = {"nick", NULL}; static char *kwlist[] = {"nick", NULL};
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &nick))
return NULL; if (!PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &nick))
nuh = find_nuh(nick); return NULL;
if (nuh == NULL) Py_RETURN_NONE;
else return Py_BuildValue("s", nuh); if ((nuh = find_nuh(nick)) == NULL)
Py_RETURN_NONE;
else
return Py_BuildValue("s", nuh);
} }
/* From core.c */ /* From core.c */
@ -291,34 +307,33 @@ static PyObject *python_do_server(PyObject *self, PyObject *args, PyObject *keyw
PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds) PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds)
{ {
Hook *hook; Hook *hook;
HookTimer hooktimer; HookTimer hooktimer;
PyObject *cb, *funcname; PyObject *cb, *funcname;
char *type, *command, *cbname; char *type, *command, *cbname;
int guid = 0, mode, sz1, sz2; int guid = 0, mode, sz1, sz2;
static char *kwlist[] = {"type", "command", "callback", "guid", NULL};
static char *kwlist[] = {"type", "command", "callback", "guid", NULL}; if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO|i", kwlist, &type, &command, &cb, &guid))
if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO|i", kwlist, return NULL;
&type, &command, &cb, &guid))
return NULL;
/* check callback function */ /* check callback function */
if (!PyFunction_Check(cb)) if (!PyFunction_Check(cb))
{ {
PyErr_SetString(python_error, "(python_hook) callback is not a function"); PyErr_SetString(python_error, "(python_hook) callback is not a function");
return NULL; return NULL;
} }
funcname = PyObject_GetAttrString(cb, "__name__"); /* new ref */ funcname = PyObject_GetAttrString(cb, "__name__"); /* new ref */
if (!funcname) if (!funcname)
{ {
PyErr_SetString(python_error, "(python_hook) cant get function name"); PyErr_SetString(python_error, "(python_hook) cant get function name");
return NULL; return NULL;
} }
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
cbname = python_unicode2char((PyUnicodeObject*) funcname); cbname = python_unicode2char((PyUnicodeObject*) funcname);
#else #else
cbname = PyString_AsString(funcname); /* not a copy! */ cbname = PyString_AsString(funcname); /* not a copy! */
#endif /* Py3k */ #endif /* Py3k */
mode = strlen(type); mode = strlen(type);
@ -334,34 +349,34 @@ PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds)
return NULL; return NULL;
} }
if (!stringcasecmp(type, "command")) if (!stringcasecmp(type, "command"))
mode = HOOK_COMMAND; mode = MEV_COMMAND;
else else
if (!stringcasecmp(type, "dcc_complete")) if (!stringcasecmp(type, "dcc_complete"))
mode = HOOK_DCC_COMPLETE; mode = MEV_DCC_COMPLETE;
else else
if (!stringcasecmp(type, "parse")) if (!stringcasecmp(type, "parse"))
mode = HOOK_PARSE; mode = MEV_PARSE;
else else
if (!stringcasecmp(type, "timer")) if (!stringcasecmp(type, "timer"))
{ {
if (compile_timer(&hooktimer, command) < 0) if (compile_timer(&hooktimer, command) < 0)
{ {
Py_DECREF(funcname); Py_DECREF(funcname);
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
free(cbname); free(cbname);
#endif /* Py3k */ #endif /* Py3k */
PyErr_SetString(python_error, "(python_hook) cant compile timer"); PyErr_SetString(python_error, "(python_hook) cant compile timer");
return NULL; return NULL;
} }
mode = HOOK_TIMER; mode = MEV_TIMER;
sz1 = sizeof(HookTimer); sz1 = sizeof(HookTimer);
} }
else else
{ {
Py_DECREF(funcname); Py_DECREF(funcname);
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
free(cbname); free(cbname);
#endif /* Py3k */ #endif /* Py3k */
PyErr_SetString(python_error, "(python_hook) invalid hook type"); PyErr_SetString(python_error, "(python_hook) invalid hook type");
return NULL; return NULL;
@ -378,13 +393,13 @@ PyObject *python_hook(PyObject *self, PyObject *args, PyObject *keywds)
switch(mode) switch(mode)
{ {
case HOOK_COMMAND: case MEV_COMMAND:
case HOOK_PARSE: case MEV_PARSE:
stringcpy(hook->type.command, command); stringcpy(hook->type.command, command);
hook->func = python_parse_jump; hook->func = python_parse_jump;
break; break;
default: default:
/* case HOOK_TIMER: */ /* case MEV_TIMER: */
memcpy(hook->type.timer, &hooktimer, sizeof(HookTimer)); memcpy(hook->type.timer, &hooktimer, sizeof(HookTimer));
hook->func = python_timer_jump; hook->func = python_timer_jump;
break; break;
@ -469,7 +484,7 @@ void python_dcc_complete(Client *client, int cps)
for (hook = hooklist; hook; hook = hook->next) for (hook = hooklist; hook; hook = hook->next)
{ {
if (hook->flags == HOOK_DCC_COMPLETE && if (hook->flags == MEV_DCC_COMPLETE &&
hook->guid && current && hook->guid == current->guid) hook->guid && current && hook->guid == current->guid)
{ {
/* get callback object */ /* get callback object */
@ -715,7 +730,7 @@ static PyObject *python_dns(PyObject *self, PyObject *args, PyObject *keywds)
set_mallocdoer(python_dns); set_mallocdoer(python_dns);
hook = (Hook*)Calloc(sizeof(Hook) + strlen(host)); hook = (Hook*)Calloc(sizeof(Hook) + strlen(host));
hook->guid = (current) ? current->guid : 0; hook->guid = (current) ? current->guid : 0;
hook->flags = HOOK_DNS; hook->flags = MEV_DNSRESULT;
hook->next = hooklist; hook->next = hooklist;
hooklist = hook; hooklist = hook;
hook->type.host = stringcpy(hook->self, cbname) + 1; hook->type.host = stringcpy(hook->self, cbname) + 1;
@ -889,9 +904,9 @@ PyMODINIT_FUNC pythonInit(void)
PyModule_AddIntConstant(m, "define_debug", 0); PyModule_AddIntConstant(m, "define_debug", 0);
#endif /* DEBUG */ #endif /* DEBUG */
PyModule_AddStringConstant(m, "HOOK_COMMAND", "command"); PyModule_AddStringConstant(m, "MEV_COMMAND", "command");
PyModule_AddStringConstant(m, "HOOK_PARSE", "parse"); PyModule_AddStringConstant(m, "MEV_PARSE", "parse");
PyModule_AddStringConstant(m, "HOOK_TIMER", "timer"); PyModule_AddStringConstant(m, "MEV_TIMER", "timer");
PyModule_AddStringConstant(m, "DCC_COMPLETE", "dcc_complete"); PyModule_AddStringConstant(m, "DCC_COMPLETE", "dcc_complete");
PyModule_AddIntConstant(m, "OK", 0); PyModule_AddIntConstant(m, "OK", 0);

View File

@ -44,6 +44,7 @@ LS const char SPY_DEFS[][12] =
"SPY_RAWIRC", "SPY_RAWIRC",
"SPY_BOTNET", "SPY_BOTNET",
"SPY_URL", "SPY_URL",
"SPY_SYSMON",
}; };
#endif /* DEBUG */ #endif /* DEBUG */
@ -178,6 +179,9 @@ struct
#ifdef URLCAPTURE #ifdef URLCAPTURE
{ SPYSTR_URL, SPY_URL }, { SPYSTR_URL, SPY_URL },
#endif /* URLCAPTURE */ #endif /* URLCAPTURE */
#ifdef HOSTINFO
{ SPYSTR_SYSMON, SPY_SYSMON },
#endif
{ NULL, 0 }, { NULL, 0 },
}; };

View File

@ -189,7 +189,7 @@ void tcl_dcc_complete(Client *client, int cps)
vname = Tcl_NewStringObj("_cps",3); vname = Tcl_NewStringObj("_cps",3);
for(hook=hooklist;hook;hook=hook->next) for(hook=hooklist;hook;hook=hook->next)
{ {
if (hook->flags == HOOK_DCC_COMPLETE && if (hook->flags == MEV_DCC_COMPLETE &&
hook->guid && current && hook->guid == current->guid) hook->guid && current && hook->guid == current->guid)
{ {
Tcl_SetVar(energymech_tcl,"_filetarget",client->whom,0); Tcl_SetVar(energymech_tcl,"_filetarget",client->whom,0);
@ -234,19 +234,19 @@ int tcl_hook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[])
return(TCL_ERROR); return(TCL_ERROR);
if (!stringcasecmp(type,"command")) if (!stringcasecmp(type,"command"))
mode = HOOK_COMMAND; mode = MEV_COMMAND;
else else
if (!stringcasecmp(type,"dcc_complete")) if (!stringcasecmp(type,"dcc_complete"))
mode = HOOK_DCC_COMPLETE; mode = MEV_DCC_COMPLETE;
else else
if (!stringcasecmp(type,"parse")) if (!stringcasecmp(type,"parse"))
mode = HOOK_PARSE; mode = MEV_PARSE;
else else
if (!stringcasecmp(type,"timer")) if (!stringcasecmp(type,"timer"))
{ {
if (compile_timer(&hooktimer,command) < 0) if (compile_timer(&hooktimer,command) < 0)
return(TCL_ERROR); return(TCL_ERROR);
mode = HOOK_TIMER; mode = MEV_TIMER;
sz1 = sizeof(HookTimer); sz1 = sizeof(HookTimer);
} }
else else
@ -265,13 +265,13 @@ int tcl_hook(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[])
switch(mode) switch(mode)
{ {
case HOOK_COMMAND: case MEV_COMMAND:
case HOOK_PARSE: case MEV_PARSE:
stringcpy(hook->type.command,command); stringcpy(hook->type.command,command);
hook->func = tcl_parse_jump; hook->func = tcl_parse_jump;
break; break;
default: default:
/* case HOOK_TIMER: */ /* case MEV_TIMER: */
memcpy(hook->type.timer,&hooktimer,sizeof(HookTimer)); memcpy(hook->type.timer,&hooktimer,sizeof(HookTimer));
hook->func = tcl_timer_jump; hook->func = tcl_timer_jump;
break; break;
@ -499,7 +499,7 @@ int tcl_dns(void *foo, Tcl_Interp *I, int objc, Tcl_Obj *CONST objv[])
set_mallocdoer(tcl_dns); set_mallocdoer(tcl_dns);
hook = (Hook*)Calloc(sizeof(Hook) + strlen(host)); hook = (Hook*)Calloc(sizeof(Hook) + strlen(host));
hook->guid = (current) ? current->guid : 0; hook->guid = (current) ? current->guid : 0;
hook->flags = HOOK_DNS; hook->flags = MEV_DNSRESULT;
hook->next = hooklist; hook->next = hooklist;
hooklist = hook; hooklist = hook;
hook->type.host = stringcpy(hook->self,callback) + 1; hook->type.host = stringcpy(hook->self,callback) + 1;

View File

@ -637,7 +637,7 @@ void mirror_user(User *user)
} }
current = backup; // assume my old identity current = backup; // assume my old identity
#ifdef DEBUG #ifdef DEBUG
debug("(x)\n"); debug("(mirror_user) %s[%i] finished\n",user->name,user->x.x.access);
#endif /* DEBUG */ #endif /* DEBUG */
} }
@ -1585,7 +1585,9 @@ void change_pass(User *user, char *pass)
if (strlen(user->pass) <= strlen(enc)) if (strlen(user->pass) <= strlen(enc))
{ {
stringcpy(user->pass,enc); stringcpy(user->pass,enc);
#ifdef BOTNET
user->modcount++; user->modcount++;
#endif /* BOTNET */
} }
/* /*
* password is stuck in a solid malloc in a linked list * password is stuck in a solid malloc in a linked list