diff --git a/.gitignore b/.gitignore index bf004a6..1a3c4bb 100644 --- a/.gitignore +++ b/.gitignore @@ -37,10 +37,14 @@ dev/* .use_size conf debug* +src/benchmark* src/nostdlib src/x src/y src/z +x +y +z randdata test.conf postfix.sh diff --git a/configure b/configure index 016ae99..dce5984 100755 --- a/configure +++ b/configure @@ -103,7 +103,6 @@ do dyncmd ) ft_dyncmd=$yesno ;; greet ) ft_greet=$yesno ;; hostinfo ) ft_hostinfo=$yesno ;; - idwrap ) ft_idwrap=$yesno ;; ircd_ext ) ft_ircd_ext=$yesno ;; libmusl ) try_libmusl=$yesno ;; md5 ) ft_md5=$yesno ;; @@ -154,7 +153,7 @@ do esac case "$feature" in - alias | botnet | bounce | chanban | ctcp | dccfile | debug | dynamode | dyncmd | greet | hostinfo | idwrap | ircd_ext | libmusl | md5 \ + alias | botnet | bounce | chanban | ctcp | dccfile | debug | dynamode | dyncmd | greet | hostinfo | 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 ) case _"$optarg"_ in @@ -206,8 +205,6 @@ do greet_no ) ft_greet=no ;; hostinfo_yes | hostinfo_ ) ft_hostinfo=yes ;; hostinfo_no ) ft_hostinfo=no ;; - idwrap_yes | idwrap_ ) ft_idwrap=yes ;; - idwrap_no ) ft_idwrap=no ;; ircd_ext_yes | ircd_ext_ ) ft_ircd_ext=yes ;; ircd_ext_no ) ft_ircd_ext=no ;; libmusl_yes | libmusl_ ) try_libmusl=/usr/local/musl/bin/musl-gcc ;; @@ -273,7 +270,6 @@ do dyncmd ) ft_dyncmd=no ;; greet ) ft_greet=no ;; hostinfo ) ft_hostinfo=no ;; - idwrap ) ft_idwrap=no ;; ircd_ext ) ft_ircd_ext=no ;; libmusl ) try_libmusl=no ;; md5 ) ft_md5=no ;; @@ -1074,26 +1070,6 @@ fi echo $ac_t "$has_ldscript" rm -f $TESTP -# -# idwrap -# -has_idwrap=no -def_idwrap='#undef IDWRAP' -IDWRAP_PATH='/* nothing */' - -if [ -r .use_idwrap -o "$ft_idwrap" = yes ]; then - echo $ac_n "checking for idwrap path ... "$ac_c - if test -z "$idwrappath"; then - idwrappath="/tmp/.ident/" - fi - if test -d $idwrappath; then - IDWRAP_PATH='"'"$idwrappath"'"' - has_idwrap="$IDWRAP_PATH" - def_idwrap='#define IDWRAP' - fi - echo $ac_t "$has_idwrap" -fi - # # # @@ -1425,12 +1401,12 @@ test "$ft_uptime" && $out "$ft_uptime" && ans=$ft_uptime test -z "$ft_uptime" && read ans test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes && def_uptime='#define UPTIME' -def_urlcapture='#undef URLCAPTURE' +def_urlcap='#undef URLCAPTURE' unset ans $out $ac_n "[ BETA ] URL capture support? ....................... [Y/n] "$ac_c test "$ft_urlcapture" && $out "$ft_urlcapture" && ans=$ft_urlcapture test -z "$ft_urlcapture" && read ans -test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes && def_urlcapture='#define URLCAPTURE' +test -z "$ans" -o "$ans" = y -o "$ans" = Y -o "$ans" = yes -o "$ans" = YES -o "$ans" = Yes && def_urlcap='#define URLCAPTURE' def_wingate='#undef WINGATE' unset ans @@ -1502,7 +1478,6 @@ sed " s|@DEF_DYNAMODE@|$def_dynamode|; s|@DEF_GREET@|$def_greet|; s|@DEF_HOSTINFO@|$def_hostinfo|; - s|@DEF_IDWRAP@|$def_idwrap|; s|@DEF_IRCD_EXT@|$def_ircd_ext|; s|@DEF_MD5@|$def_md5|; s|@DEF_SHA@|$def_sha|; @@ -1523,7 +1498,7 @@ s|@DEF_SUPPRESS@|$def_suppress|; s|@DEF_TOYBOX@|$def_toybox|; s|@DEF_TRIVIA@|$def_trivia|; s|@DEF_UPTIME@|$def_uptime|; -s|@DEF_URLCAPTURE@|$def_urlcapture|; + s|@DEF_URLCAP@|$def_urlcap|; s|@DEF_WEB@|$def_web|; s|@DEF_WINGATE@|$def_wingate|; @@ -1534,14 +1509,13 @@ s|@DEF_CRYPT_FUNCTION@|$CRYPT_FUNCTION|; s|@CRYPT_HAS_SHA@|$CRYPT_HAS_SHA|; s|@CRYPT_HAS_MD5@|$CRYPT_HAS_MD5|; s|@CRYPT_HAS_DES@|$CRYPT_HAS_DES|; -s|@IDWRAP_PATH@|$IDWRAP_PATH|; s|@PTSIZE_DEFINE32@|$PTSIZE_DEFINE32|; s|@PTSIZE_DEFINE64@|$PTSIZE_DEFINE64|; s|@UNALIGNED_MEM@|$UNALIGNED_MEM|; " < src/config.h.in >> src/config.h save_myconfig() { - names="alias botnet bounce chanban ctcp dccfile debug dynamode dyncmd greet hostinfo idwrap ircd_ext libmusl md5 + names="alias botnet bounce chanban ctcp dccfile debug dynamode dyncmd greet hostinfo 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 diff --git a/src/bounce.c b/src/bounce.c index de2f651..ce9cfba 100644 --- a/src/bounce.c +++ b/src/bounce.c @@ -45,16 +45,8 @@ #define BNC_ACTIVE 5 #define BNC_DEAD 6 -#ifdef IDWRAP - -#define USE_VHOST 2 - -#else /* not IDWRAP */ - #define USE_VHOST TRUE -#endif /* IDWRAP */ - void bounce_parse(ircLink *irc, char *message) { Mech fakebot; @@ -175,10 +167,6 @@ void bounce_parse(ircLink *irc, char *message) #ifdef WINGATE current->setting[STR_WINGATE].str_var = NULL; #endif /* WINGATE */ -#ifdef IDWRAP - current->identfile = NULL; - current->setting[STR_IDENT].str_var = irc->handle; -#endif /* IDWRAP */ if (virtual) { @@ -189,28 +177,10 @@ void bounce_parse(ircLink *irc, char *message) { irc->status = BNC_CONNECTING; irc->active = now + 60; /* 120 second timeout */ -#ifdef IDWRAP - irc->idfile = current->identfile; -#endif /* IDWRAP */ } } } -#ifdef IDWRAP - -void bounce_cleanup(void) -{ - ircLink *irc; - - for(irc=bnclist;irc;irc=irc->next) - { - if (irc->idfile) - unlink(irc->idfile); - } -} - -#endif /* IDWRAP */ - void new_port_bounce(const struct Setting *no_op) { if (bounce_sock != -1) @@ -379,13 +349,6 @@ void process_bounce(void) Free((char**)&irc->nickLine); Free((char**)&irc->nick); Free((char**)&irc->handle); -#ifdef IDWRAP - if (irc->idfile) - { - unlink(irc->idfile); - Free((char**)&irc->idfile); - } -#endif /* IDWRAP */ Free((char**)&irc); continue; } diff --git a/src/channel.c b/src/channel.c index 05ce725..df03e67 100644 --- a/src/channel.c +++ b/src/channel.c @@ -427,7 +427,7 @@ void channel_massmode(const Chan *chan, char *pattern, int filtmode, char mode, /* * never deop yourself, stupid bot */ - if (nickcmp(pat,current->nick)) + if (nickcmp(pat,getbotnick(current))) willdo = TRUE; } else @@ -890,9 +890,10 @@ void do_mode(COMMAND_ARGS) } else { + /* todo: is it really necessary to chop? */ target = chop(&rest); - if (!nickcmp(current->nick,target)) + if (!nickcmp(target,getbotnick(current))) { to_server("MODE %s %s\n",target,rest); } diff --git a/src/config.h.in b/src/config.h.in index b0d3438..a661338 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -71,12 +71,6 @@ */ @DEF_HOSTINFO@ -/* - * IDWRAP: support for idwrap ident spoofing - */ -@DEF_IDWRAP@ -#define IDWRAP_PATH @IDWRAP_PATH@ - /* * IRCD_EXTENSIONS: support some special features of new ircds */ @@ -195,7 +189,7 @@ /* * URLCAPTURE: capture url's mentioned */ -@DEF_URLCAPTURE@ +@DEF_URLCAP@ /* * WEB: serving documents via HTTP diff --git a/src/core.c b/src/core.c index 7b36799..c796e63 100644 --- a/src/core.c +++ b/src/core.c @@ -33,22 +33,6 @@ #include #endif /* HOSTINFO */ -#ifdef IDWRAP - -void unlink_identfile(void) -{ - if (current->identfile) - { -#ifdef DEBUG - debug("(unlink_identfile) unlink(%s)\n",current->identfile); -#endif /* DEBUG */ - unlink(current->identfile); - Free((char**)¤t->identfile); - } -} - -#endif /* IDWRAP */ - int conf_callback(char *line) { @@ -57,7 +41,7 @@ int conf_callback(char *line) fix_config_line(line); - on_msg((char*)CoreUser.name,current->nick,line); + on_msg((char*)CoreUser.name,getbotnick(current),line); return(FALSE); } @@ -108,7 +92,7 @@ void readcfgfile(void) } if ((current) && (current->chanlist == NULL)) - to_file(1,"%s %s will not join any channels\n",ERR_INIT,current->nick); + to_file(1,"init: Warning: %s will not join any channels\n",getbotnick(current)); oc = 0; #ifdef DEBUG @@ -123,8 +107,8 @@ void readcfgfile(void) to_file(1,", ..."); break; } - to_file(1,"%s%s",(oc > 0) ? ", " : "",bot->nick); - oc += strlen(bot->nick); + to_file(1,"%s%s",(oc > 0) ? ", " : "",getbotnick(bot)); + oc += getbotnicklen(bot); } to_file(1," ]\n"); #ifdef DEBUG @@ -243,7 +227,7 @@ int write_session(void) for(bot=botlist;bot;bot=bot->next) { - to_file(sf,"nick %i %s\n",bot->guid,bot->wantnick); + to_file(sf,"nick %i %s\n",bot->guid,getbotwantnick(bot)); /* * current->setting contains channel defaults and global vars */ @@ -327,22 +311,6 @@ int write_session(void) * Bot nicking, adding and killing */ -void setbotnick(Mech *bot, char *nick) -{ - /* - * if its exactly the same we dont need to change it - */ - if (!stringcmp(bot->nick,nick)) - return; - - Free((char**)&bot->nick); - set_mallocdoer(setbotnick); - bot->nick = stringdup(nick); -#ifdef BOTNET - botnet_refreshbotinfo(); -#endif /* BOTNET */ -} - Mech *add_bot(int guid, char *nick) { Mech *bot; @@ -352,10 +320,8 @@ Mech *add_bot(int guid, char *nick) bot->connect = CN_NOSOCK; bot->sock = -1; bot->guid = guid; - set_mallocdoer(add_bot); - bot->nick = stringdup(nick); - set_mallocdoer(add_bot); - bot->wantnick = stringdup(nick); + setbotnick(bot,nick); + setbotwantnick(bot,nick); set_binarydefault(bot->setting); bot->next = botlist; botlist = bot; @@ -375,7 +341,7 @@ void signoff(char *from, char *reason) if (from) { - to_user(from,"Killing mech: %s",current->nick); + to_user(from,"Killing mech: %s",getbotnick(current)); to_user(from,"Saving the lists..."); } fname = current->setting[STR_USERFILE].str_var; @@ -419,9 +385,6 @@ void signoff(char *from, char *reason) if (current->sock != -1) { -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ if (!reason) reason = randstring(SIGNOFFSFILE); to_server("QUIT :%s\n",(reason) ? reason : ""); @@ -451,9 +414,6 @@ void signoff(char *from, char *reason) /* * little of this n that */ - Free((char**)¤t->nick); - Free((char**)¤t->wantnick); - Free((char**)¤t->userhost); /* * These 2 are used by do_die() to pass reason and doer. @@ -481,10 +441,6 @@ void signoff(char *from, char *reason) */ if ((current = botlist) == NULL) { -#if defined(BOUNCE) && defined(IDWRAP) - bounce_cleanup(); -#endif /* BOUNCE && IDWRAP */ - #ifdef TRIVIA write_triviascore(); #endif /* TRIVIA */ @@ -759,7 +715,7 @@ void register_with_server(void) to_server((sendpass) ? "PASS :%s\nNICK %s\nUSER %s " MECHUSERLOGIN " 0 :%s\n" : "%sNICK %s\nUSER %s " MECHUSERLOGIN " 0 :%s\n", (sendpass) ? sp->pass : "", - current->wantnick, + getbotwantnick(current), (ident) ? ident : BOTLOGIN, (ircname) ? ircname : VERSION); current->connect = CN_CONNECTED; @@ -1034,8 +990,8 @@ void update(SequenceTime *this) if ((now - current->lastreset) > RESETINTERVAL) { current->lastreset = now; - if (stringcmp(current->nick,current->wantnick)) - to_server("NICK %s\n",current->wantnick); + if (stringcmp(getbotnick(current),getbotwantnick(current))) + to_server("NICK %s\n",getbotwantnick(current)); check_idlekick(); if ((x = current->setting[INT_AAWAY].int_var) && current->away == FALSE) { @@ -1134,10 +1090,10 @@ void process_server_input(void) if (FD_ISSET(current->sock,&write_fds)) { - setbotnick(current,current->wantnick); + setbotnick(current,getbotwantnick(current)); #ifdef DEBUG debug("[PSI] {%i} connection established (%s) [ASYNC]\n", - current->sock,current->wantnick); + current->sock,getbotwantnick(current)); #endif /* DEBUG */ #ifdef WINGATE if ((current->vhost_type & VH_WINGATE_BOTH) == VH_WINGATE) @@ -1170,10 +1126,6 @@ void process_server_input(void) * send NICK, USER and maybe PASS */ register_with_server(); -#ifdef IDWRAP - if (current->sock == -1) - unlink_identfile(); -#endif /* IDWRAP */ return; } if (FD_ISSET(current->sock,&read_fds)) @@ -1244,9 +1196,6 @@ breaksock: #endif /* DEBUG */ breaksock2: *current->sockdata = 0; -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ close(current->sock); current->sock = -1; current->connect = CN_NOSOCK; @@ -1287,11 +1236,11 @@ void do_core(COMMAND_ARGS) bu++; } - i = stringcmp(current->nick,current->wantnick); + i = stringcmp(getbotnick(current),getbotwantnick(current)); if (i) - table_buffer(TEXT_CURRNICKWANT,current->nick,current->wantnick,current->guid); + table_buffer(TEXT_CURRNICKWANT,getbotnick(current),getbotwantnick(current),current->guid); else - table_buffer(TEXT_CURRNICKHAS,current->nick,current->guid); + table_buffer(TEXT_CURRNICKHAS,getbotnick(current),current->guid); table_buffer(TEXT_USERLISTSTATS,u,su,EXTRA_CHAR(su),bu,EXTRA_CHAR(bu)); pt = tmp; @@ -1716,15 +1665,15 @@ void do_nick(COMMAND_ARGS) char *nick; int guid; - nick = chop(&rest); - if (!nick || !*nick) + if (!rest || !*rest) { usage(from); /* usage for CurrentCmd->name */ return; } + nick = chop(&rest); guid = asc2int(nick); backup = current; - if (!errno) + if (errno == 0) /* we got a number */ { nick = chop(&rest); for(current=botlist;current;current=current->next) @@ -1735,7 +1684,7 @@ void do_nick(COMMAND_ARGS) break; } } - if (!is_nick(nick)) + if (is_nick(nick) == FALSE) { current = backup; to_user(from,ERR_NICK,nick); @@ -1756,15 +1705,11 @@ void do_nick(COMMAND_ARGS) { if (current->guid == 0) { - Free((char**)¤t->nick); - set_mallocdoer(do_nick); - current->nick = stringdup(nick); - current->guid = guid; + setbotnick(current,nick); + current->guid = guid; /* guid might be undefined? */ } - Free((char**)¤t->wantnick); - set_mallocdoer(do_nick); - current->wantnick = stringdup(nick); - to_server("NICK %s\n",current->wantnick); + setbotwantnick(current,nick); + to_server("NICK %s\n",getbotwantnick(current)); } current = backup; } diff --git a/src/ctcp.c b/src/ctcp.c index c01bb96..a9beb26 100644 --- a/src/ctcp.c +++ b/src/ctcp.c @@ -82,7 +82,7 @@ void delete_client(Client *client) pspy = &(*pspy)->next; } send_global(SPYSTR_STATUS,"[%s] %s[%i] has disconnected", - current->nick,client->user->name,client->user->x.x.access); + getbotnick(current),client->user->name,client->user->x.x.access); } #ifdef DCC_FILE if (client->fileno >= 0) @@ -347,11 +347,11 @@ void parse_dcc(Client *client) bp = ptr; chop(&bp); ptr = get_token(&bp,"\001"); - on_action(CurrentUser->name,current->nick,ptr); + on_action(CurrentUser->name,getbotnick(current),ptr); } else { - on_msg(CurrentUser->name,current->nick,ptr); + on_msg(CurrentUser->name,getbotnick(current),ptr); } CurrentDCC = NULL; /* diff --git a/src/debug.c b/src/debug.c index 6e4c440..22af7ac 100644 --- a/src/debug.c +++ b/src/debug.c @@ -168,7 +168,7 @@ LS struct { send_kick, "send_kick" }, { send_mode, "send_mode" }, { set_str_varc, "set_str_varc" CFG1_SE }, -{ setbotnick, "setbotnick" }, +{ set_mix16, "set_mix16" CORE_SE }, { sig_hup, "sig_hup" RARE_SE }, { table_buffer, "table_buffer" }, #ifdef ALIAS @@ -661,7 +661,6 @@ void debug_memory(void) { memtouch(bot->lastcmds[i]); } - memtouch(bot->userhost); } debug("> Memory allocations\n"); for(mea=mrrec;(mea);mea=mea->next) @@ -851,7 +850,7 @@ void debug_core(void) } debug(" ; ---\n"); if (current) - debug("; current\t\t"mx_pfmt" \"%s\"\n",(mx_ptr)current,nullstr(current->nick)); + debug("; current\t\t"mx_pfmt" \"%s\"\n",(mx_ptr)current,nullstr(getbotnick(current))); else debug("; current\t\t"mx_pfmt"\n",(mx_ptr)current); debug("; executable\t\t\"%s\"\n",executable); @@ -887,8 +886,6 @@ void debug_core(void) for(bot=botlist;bot;bot=bot->next) { memtouch(bot); - memtouch(bot->nick); - memtouch(bot->wantnick); debug(" ; Mech*\t\t"mx_pfmt"\n",(mx_ptr)bot); debug(" ; next\t\t"mx_pfmt"\n",(mx_ptr)bot->next); debug(" ; connect\t\t%s (%i)\n",strdef(CNdefs,bot->connect),bot->connect); @@ -906,8 +903,8 @@ void debug_core(void) { debug_server(sp," "); } - debug(" ; nick\t\t\"%s\"\n",nullstr(bot->nick)); - debug(" ; wantnick\t\t\"%s\"\n",nullstr(bot->wantnick)); + debug(" ; nick\t\t\"%s\"\n",nullstr(getbotnick(bot))); + debug(" ; wantnick\t\t\"%s\"\n",nullstr(getbotwantnick(bot))); debug_settings(bot->setting,DSET_GLOBAL); diff --git a/src/function.c b/src/function.c index 27f1394..aee4fb2 100644 --- a/src/function.c +++ b/src/function.c @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Parts Copyright (c) 1997-2020 proton + Parts Copyright (c) 1997-2025 proton 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 @@ -167,6 +167,50 @@ void Free(char **mem) #endif /* DEBUG */ +void set_mix16(Mix16 *mix, const char *str) +{ + int sz; + + if (mix->opt >= 16) + { + Free(&mix->x.ptr); + } + + sz = strlen(str); + if (sz < 16) + { + stringcpy(mix->x.string,str); + } + else + { + set_mallocdoer(set_mix16); + mix->x.ptr = stringdup(str); + } + mix->opt = sz; +} + +void set_mix64(Mix64 *mix, const char *str) +{ + int sz; + + if (mix->opt >= 64) + { + Free(&mix->x.ptr); + } + + sz = strlen(str); + if (sz < 64) + { + stringcpy(mix->x.string,str); + } + else + { + set_mallocdoer(set_mix64); + mix->x.ptr = stringdup(str); + } + mix->opt = sz; +} + Strp *make_strp(Strp **pp, const char *string) { set_mallocdoer(make_strp); diff --git a/src/global.h b/src/global.h index 5bf1f30..6ab0c1a 100644 --- a/src/global.h +++ b/src/global.h @@ -55,7 +55,6 @@ BEG const char NULLSTR[] MDEF(""); BEG const char ERR_CHAN[] MDEF("I'm not on %s"); BEG const char ERR_FILEOPEN[] MDEF("Couldn't open the file %s"); -BEG const char ERR_INIT[] MDEF("init: Warning:"); BEG const char ERR_NICK[] MDEF("Invalid nickname: %s"); BEG const char ERR_NOCHANNELS[] MDEF("I'm not active on any channels"); BEG const char ERR_NOTOPPED[] MDEF("I'm not opped on %s"); diff --git a/src/h.h b/src/h.h index c90ca7f..b250362 100644 --- a/src/h.h +++ b/src/h.h @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Copyright (c) 1997-2024 proton + Copyright (c) 1997-2025 proton 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 @@ -183,11 +183,21 @@ LS void do_idle(COMMAND_ARGS) __page(CMD1_SEG); /* core.c */ -void unlink_identfile(void); +#define getbotnicklen(z) (z->nick.opt) +#define getbotnick(z) ((z->nick.opt < 16) ? z->nick.x.string : z->nick.x.ptr) +#define getbotwantnick(z) ((z->wantnick.opt < 16) ? z->wantnick.x.string : z->wantnick.x.ptr) +#define getbotuserhost(z) ((z->userhost.opt == 0) ? UNKNOWNATUNKNOWN : ((z->userhost.opt < 64) ? z->userhost.x.string : z->userhost.x.ptr)) + +#define setbotnick(z,y) set_mix16(&z->nick,y) +#define setbotwantnick(z,y) set_mix16(&z->wantnick,y) +#define setbotuserhost(z,y) set_mix64(&z->userhost,y) + +void set_mix16(Mix16 *, const char *) __page(CORE_SEG); +void set_mix64(Mix64 *, const char *) __page(CORE_SEG); + int conf_callback(char *line) __page(CFG1_SEG); void readcfgfile(void) __page(CFG1_SEG); int write_session(void) __page(CORE_SEG); -void setbotnick(Mech *bot, char *nick) __page(CFG1_SEG); Mech *add_bot(int guid, char *nick) __page(CFG1_SEG); void signoff(char *from, char *reason) __page(RARE_SEG); void kill_all_bots(char *reason) __attr(RARE_SEG, __noreturn__);; diff --git a/src/io.c b/src/io.c index c4b686a..65a0d21 100644 --- a/src/io.c +++ b/src/io.c @@ -115,10 +115,6 @@ int SockConnect(char *host, int port, int use_vhost) { struct sockaddr_in sai; int s; -#ifdef IDWRAP - char *id,identfile[64]; - int t = FALSE; -#endif /* IDWRAP */ #ifdef DEBUG debug("(SockConnect) %s %i%s\n",nullstr(host),port,(use_vhost) ? " [VHOST]" : ""); @@ -130,16 +126,7 @@ int SockConnect(char *host, int port, int use_vhost) memset((char*)&sai,0,sizeof(sai)); sai.sin_family = AF_INET; - /* - * special case, BOUNCE feature may call SockConnect() - * to create the IDWRAP symlink, using special use_vhost value == 2 - */ -#if defined(BOUNCE) && defined(IDWRAP) - if ((use_vhost == TRUE) -#else /* not ... */ - if (use_vhost -#endif /* ... */ - && ((current->vhost_type & VH_IPALIAS_FAIL) == 0) + if (use_vhost && ((current->vhost_type & VH_IPALIAS_FAIL) == 0) && current->setting[STR_VIRTUAL].str_var) { current->vhost_type |= VH_IPALIAS_BOTH; @@ -151,25 +138,12 @@ int SockConnect(char *host, int port, int use_vhost) #ifdef WINGATE use_vhost++; #endif /* WINGATE */ -#ifdef IDWRAP - t = TRUE; -#endif /* IDWRAP */ #ifdef DEBUG debug("(SockConnect) IP Alias virtual host bound OK\n"); #endif /* DEBUG */ } } } -#ifdef IDWRAP - /* - * do a blank bind to get a port number - */ - if (!t) - { - sai.sin_addr.s_addr = INADDR_ANY; - bind(s,(struct sockaddr *)&sai,sizeof(sai)); - } -#endif /* IDWRAP */ memset((char*)&sai,0,sizeof(sai)); sai.sin_family = AF_INET; @@ -204,29 +178,6 @@ int SockConnect(char *host, int port, int use_vhost) /* * Normal connect, no bounces... */ -#ifdef IDWRAP - if (use_vhost) - { - t = sizeof(sai); - if (getsockname(s,(struct sockaddr*)&sai,&t) == 0) - { - if (current->identfile) - Free((char**)¤t->identfile); - sprintf(identfile,IDWRAP_PATH "%i.%i",ntohs(sai.sin_port),port); - id = current->setting[STR_IDENT].str_var; - if (symlink((id) ? id : BOTLOGIN,identfile) == 0) - { - set_mallocdoer(SockConnect); - current->identfile = Strdup(identfile); -#ifdef DEBUG - debug("(SockConnect) symlink: %s -> %s\n",identfile,(id) ? id : BOTLOGIN); -#endif /* DEBUG */ - } - } - memset((char*)&sai,0,sizeof(sai)); - sai.sin_family = AF_INET; - } -#endif /* IDWRAP */ sai.sin_port = htons(port); if ((sai.sin_addr.s_addr = get_ip(host)) == -1) { diff --git a/src/main.c b/src/main.c index 1bc9573..198dfb8 100755 --- a/src/main.c +++ b/src/main.c @@ -209,7 +209,7 @@ LS struct int sig_hup_callback(char *line) { - on_msg((char*)CoreUser.name,current->nick,line); + on_msg((char*)CoreUser.name,getbotnick(current),line); return(FALSE); } @@ -295,9 +295,6 @@ void do_sigusr1(void) { if (current->sock != -1) { -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ close(current->sock); } current->sock = -1; @@ -686,9 +683,6 @@ doit_jumptonext: #ifdef DEBUG debug("(doit) {%i} Connection timed out\n",current->sock); #endif /* DEBUG */ -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ close(current->sock); current->sock = -1; goto restart_dcc; diff --git a/src/net.c b/src/net.c index 95133c1..05fe957 100644 --- a/src/net.c +++ b/src/net.c @@ -206,8 +206,8 @@ void botnet_refreshbotinfo(void) Server *sv; sv = find_server(current->server); - botnet_relay(NULL,"BL%i 0 %s!%s %s:%i %s %s\n", current->guid,current->nick, - (current->userhost) ? current->userhost : UNKNOWNATUNKNOWN, + botnet_relay(NULL,"BL%i 0 %s!%s %s:%i %s %s\n", current->guid,getbotnick(current), + getbotuserhost(current), (sv) ? ((*sv->realname) ? sv->realname : sv->name) : UNKNOWN, (sv) ? sv->port : 0,BOTCLASS,VERSION); #ifdef DEBUG @@ -248,8 +248,8 @@ void botnet_dumplinklist(BotNet *bn) */ sv = find_server(bot->server); to_file(bn->sock,"BL%i %c %s!%s %s:%i %s %s\n",bot->guid, - (bot == bn->controller) ? '0' : '1',bot->nick, - (bot->userhost) ? bot->userhost : UNKNOWNATUNKNOWN, + (bot == bn->controller) ? '0' : '1',getbotnick(bot), + getbotuserhost(bot), (sv) ? ((*sv->realname) ? sv->realname : sv->name) : UNKNOWN, (sv) ? sv->port : 0,BOTCLASS,VERSION); } @@ -987,7 +987,7 @@ int commandlocal(int dg, int sg, char *from, char *command) *p2 = current->setting[CHR_CMDCHAR].char_var; stringcpy((*p2 == *command) ? p2 : p2+1,command); - on_msg(p1,current->nick,p2); + on_msg(p1,getbotnick(current),p2); CurrentDCC = NULL; } if (dg == -1) diff --git a/src/ons.c b/src/ons.c index 5168bf9..24df1c1 100644 --- a/src/ons.c +++ b/src/ons.c @@ -82,7 +82,7 @@ void on_kick(char *from, char *rest) if (current->spy & SPYF_CHANNEL) send_spy(chan->name,"*** %s was kicked by %s (%s)",nick,CurrentNick,rest); - if (!nickcmp(current->nick,nick)) + if (!nickcmp(getbotnick(current),nick)) { #ifdef DEBUG debug("(on_kick) I was kicked from %s\n",chan->name); @@ -290,8 +290,8 @@ void on_nick(char *from, char *newnick) * grab the nick *RIGHT NOW* * this is a setting because this is risky, you might get collided as a result */ - if (!nickcmp(CurrentNick,current->wantnick)) - to_server("NICK %s\n",current->wantnick); + if (!nickcmp(CurrentNick,getbotwantnick(current))) + to_server("NICK %s\n",getbotwantnick(current)); #endif /* FASTNICK */ /* @@ -311,9 +311,12 @@ void on_nick(char *from, char *newnick) change_authnick(from,newnuh); - if ((isbot = !nickcmp(current->nick,CurrentNick))) + if ((isbot = !nickcmp(getbotnick(current),CurrentNick))) { setbotnick(current,newnick); +#ifdef BOTNET + botnet_refreshbotinfo(); +#endif /* BOTNET */ } for(chan=current->chanlist;chan;chan=chan->next) @@ -450,7 +453,7 @@ void on_msg(char *from, char *to, char *rest) if ((p2 = (uchar*)(command = chop(&rest))) == NULL) return; - p1 = (uchar*)current->nick; + p1 = (uchar*)getbotnick(current); while(!(i = tolowertab[*(p1++)] - tolowertab[*p2]) && *(p2++)) ; @@ -726,7 +729,7 @@ public_msg: { partyline_broadcast(CurrentDCC,"<%s> %s\n",origstart); #ifdef BOTNET - botnet_relay(NULL,"PM* * %s@%s %s\n",CurrentNick,current->nick,origstart); + botnet_relay(NULL,"PM* * %s@%s %s\n",CurrentNick,getbotnick(current),origstart); #endif /* BOTNET */ } else @@ -800,7 +803,7 @@ modeloop: } } else - if (!nickcmp(current->nick,nick)) + if (!nickcmp(getbotnick(current),nick)) { /* * wooohoooo! they gave me ops!!! @@ -824,7 +827,7 @@ modeloop: victim->flags &= ~(CU_CHANOP|CU_DEOPPED); if (i == BOTLEVEL) { - if (!nickcmp(current->nick,nick)) + if (!nickcmp(getbotnick(current),nick)) { /* * they dont love me!!! :~( @@ -1105,7 +1108,7 @@ void on_action(char *from, char *to, char *rest) { partyline_broadcast(CurrentDCC,"* %s %s\n",rest); #ifdef BOTNET - botnet_relay(NULL,"PM* * %s@%s \001%s\n",CurrentNick,current->nick,rest); + botnet_relay(NULL,"PM* * %s@%s \001%s\n",CurrentNick,getbotnick(current),rest); #endif /* BOTNET */ return; } diff --git a/src/parse.c b/src/parse.c index a4d658c..29c2672 100644 --- a/src/parse.c +++ b/src/parse.c @@ -84,7 +84,7 @@ void parse_join(char *from, char *rest) if ((CurrentChan = chan = find_channel_ny(rest)) == NULL) return; - if (!nickcmp(current->nick,from)) + if (!nickcmp(getbotnick(current),from)) { #ifdef DEBUG debug("(parse_join) Im joining %s\n",chan->name); @@ -202,7 +202,7 @@ void parse_mode(char *from, char *rest) on_mode(from,to,rest); } else - if (!stringcasecmp(current->nick,to)) + if (!stringcasecmp(getbotnick(current),to)) /* todo: nickcmp? */ { char *dst; char sign; @@ -311,7 +311,7 @@ void parse_part(char *from, char *rest) if (current->spy & SPYF_CHANNEL) send_spy(channel,"*** Parts: %s (%s)",nick,from); - if (!nickcmp(current->nick,nick)) + if (!nickcmp(getbotnick(current),nick)) { #ifdef DEBUG debug("(parse_part) Im parting %s\n",chan->name); @@ -547,6 +547,9 @@ void parse_251(char *from, char *rest) { nick = chop(&rest); setbotnick(current,nick); +#ifdef BOTNET + botnet_refreshbotinfo(); +#endif /* BOTNET */ for(sp=serverlist;sp;sp=sp->next) { if (!stringcasecmp(sp->name,from) || !stringcasecmp(sp->realname,from)) @@ -702,11 +705,9 @@ void parse_311(char *from, char *rest) if (host) host[-1] = '@'; - if (!nickcmp(nick,current->nick)) + if (!nickcmp(getbotnick(current),nick)) { - Free((char**)¤t->userhost); - set_mallocdoer(parse_311); - current->userhost = stringdup(user); + setbotuserhost(current,user); #ifdef BOTNET botnet_refreshbotinfo(); #endif /* BOTNET */ @@ -855,7 +856,7 @@ void parse_319(char *from, char *rest) send_pa(PA_WHOIS,nick,"Channels: %s",rest); /* if nick is myself (the bot), check for reset recovery */ - if (!nickcmp(nick,current->nick)) + if (!nickcmp(getbotnick(current),nick)) { if (current->reset) { @@ -871,7 +872,7 @@ loop: */ while(*channel && *channel != '#') /* this is a recipe for disaster with other valid channels than '#' */ channel++; - sprintf(nuh,"%s!%s",current->nick,current->userhost); + sprintf(nuh,"%s!%s",getbotnick(current),getbotuserhost(current)); #ifdef DEBUG debug("(parse_319) :%s JOIN :%s\n",nuh,channel); #endif /* DEBUG */ @@ -996,7 +997,7 @@ void parse_352(char *from, char *rest) if (*rest == '@') { chan->users->flags = CU_CHANOP; - if (!nickcmp(current->nick,nick)) + if (!nickcmp(getbotnick(current),nick)) { #ifdef DEBUG debug("(parse_352) According to wholist I have ops\n"); @@ -1066,13 +1067,10 @@ void parse_376(char *from, char *rest) { current->connect = CN_ONLINE; current->ontime = now; - to_server("WHOIS %s\n",current->nick); + to_server("WHOIS %s\n",getbotnick(current)); if ((mode = current->setting[STR_UMODES].str_var)) - to_server("MODE %s %s\n",current->nick,mode); + to_server("MODE %s %s\n",getbotnick(current),mode); } -#ifdef IDWRAP - unlink_identfile(); -#endif /* IDWRAP */ } /* @@ -1113,7 +1111,7 @@ void parse_433(char *from, char *rest) do { s2 = chop(&s); - if (current->connect == CN_ONLINE && !stringcasecmp(current->nick,s2)) + if (current->connect == CN_ONLINE && !stringcasecmp(getbotnick(current),s2)) /* todo: nickcmp? */ { /* nicks listed first are more worth, dont try nicks after */ break; @@ -1134,14 +1132,12 @@ void parse_433(char *from, char *rest) if (nick) { #ifdef DEBUG - debug("(parse_433) Nick: %s, Altnick: %s\n",current->nick,nick); + debug("(parse_433) Nick: %s, Altnick: %s\n",getbotnick(current),nick); #endif /* DEBUG */ to_server("NICK %s\n",nick); if (current->connect != CN_ONLINE) { - Free((char**)¤t->nick); - set_mallocdoer(parse_433); - current->nick = stringdup(nick); + setbotnick(current,nick); } return; } diff --git a/src/partyline.c b/src/partyline.c index 319276d..2494735 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -122,7 +122,7 @@ void partyline_banner(Client *client) client->lasttime = now; sprintf(tmp,"[%s] %s[%i] has connected", - current->nick,client->user->name,(int)client->user->x.x.access); + getbotnick(current),client->user->name,(int)client->user->x.x.access); if ((to_file(client->sock,"[%s] %s\n",time2medium(now),tmp)) < 0) { @@ -134,7 +134,7 @@ void partyline_banner(Client *client) { CurrentDCC = client; stringcpy(tmp,SPYSTR_STATUS); - do_spy(client->user->name,current->nick,tmp,0); + do_spy(client->user->name,getbotnick(current),tmp,0); CurrentDCC = NULL; } } @@ -240,7 +240,7 @@ void do_whom(COMMAND_ARGS) { stringcpy(stt,TEXT_NOTCONNECTED); } - table_buffer(TEXT_WHOMSELFLINE,bot->nick,(bot == current) ? "(me)" : "b200",stt); + table_buffer(TEXT_WHOMSELFLINE,getbotnick(bot),(bot == current) ? "(me)" : "b200",stt); for(client=bot->clientlist;client;client=client->next) { m = (now - client->lasttime) / 60; diff --git a/src/reset.c b/src/reset.c index f3ed471..14de5be 100644 --- a/src/reset.c +++ b/src/reset.c @@ -97,7 +97,7 @@ char *recover_client(char *env) found_user: if (to_file(fd,"[%s] [%s] %s[%i] has connected (reset recover)\n", - time2medium(now),current->wantnick,handle,user->x.x.access) < 0) + time2medium(now),getbotwantnick(current),handle,user->x.x.access) < 0) { close(fd); return(p); @@ -121,7 +121,7 @@ found_user: { CurrentDCC = client; stringcpy(client->sockdata,"status"); - do_spy(user->name,current->wantnick,client->sockdata,0); + do_spy(user->name,getbotwantnick(current),client->sockdata,0); *client->sockdata = 0; CurrentDCC = NULL; } diff --git a/src/shit.c b/src/shit.c index 7b5ae14..dd5b198 100644 --- a/src/shit.c +++ b/src/shit.c @@ -201,7 +201,7 @@ Shit *get_shituser(char *userhost, char *channel) */ if (!current->shitlist) return(NULL); - if (!nickcmp(current->nick,userhost)) + if (!nickcmp(getbotnick(current),userhost)) return(NULL); for(chan=current->chanlist;chan;chan=chan->next) { diff --git a/src/spy.c b/src/spy.c index f20a5d7..67cffad 100644 --- a/src/spy.c +++ b/src/spy.c @@ -104,7 +104,7 @@ void send_spy(const char *src, const char *format, ...) #ifdef DEBUG if (src != SPYSTR_RAWIRC) /* too much debug spam */ debug("(send_spy) src <%s> format = '%s', current = '%s' (%i)\n",src,format, - (current == NULL) ? "" : nullstr(current->nick),(current == NULL) ? -1 : current->guid); + (current == NULL) ? "" : getbotnick(current),(current == NULL) ? -1 : current->guid); #endif /* DEBUG */ for(spy=current->spylist;spy;spy=spy->next) @@ -428,7 +428,7 @@ void send_redirect(char *message) Mech *backup; /* PM */ - sprintf(tempdata,"%i %s %s %s",redirect.guid,redirect.to,current->nick,message); + sprintf(tempdata,"%i %s %s %s",redirect.guid,redirect.to,getbotnick(current),message); backup = current; partyMessage(NULL,tempdata); current = backup; @@ -770,7 +770,7 @@ spy_dest_ok: debug("(do_spy) src = `%s'; t_src = %i (%s); dest = `%s'; t_dest = %i (%s), CurrentDCC "mx_pfmt"\n", src,t_src,SPY_DEFS[t_src-1],nullstr(dest),t_dest,SPY_DEFS[t_dest-1],CurrentDCC); if (guid >= 0) - debug("(do_spy) spying from remote bot guid %i (%s), channel %s\n",guid,(destbot) ? destbot->nick : "unknown",src); + debug("(do_spy) spying from remote bot guid %i (%s), channel %s\n",guid,(destbot) ? getbotnick(destbot) : "unknown",src); #endif /* DEBUG */ if (t_dest == SPY_DCC) diff --git a/src/structs.h b/src/structs.h index 1ba6e6f..c8579cb 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,7 +1,7 @@ /* EnergyMech, IRC bot software - Parts Copyright (c) 1997-2020 proton + Parts Copyright (c) 1997-2025 proton 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 @@ -21,6 +21,35 @@ #ifndef STRUCTS_H #define STRUCTS_H 1 +typedef struct Strp +{ + struct Strp *next; + char p[1]; + +} Strp; + +typedef struct Mix16 +{ + union + { + char string[16]; + char *ptr; + } x; + int8_t opt; + +} Mix16; + +typedef struct Mix64 +{ + union + { + char string[64]; + char *ptr; + } x; + int8_t opt; + +} Mix64; + typedef union usercombo { struct @@ -88,10 +117,6 @@ typedef struct ircLink char *nick; /* which nick to speak to */ char *handle; -#ifdef IDWRAP - char *idfile; -#endif /* IDWRAP */ - char servmem[MSGLEN]; char usermem[MSGLEN]; @@ -212,13 +237,6 @@ typedef struct Setting } Setting; -typedef struct Strp -{ - struct Strp *next; - char p[1]; - -} Strp; - typedef struct KickSay { struct KickSay *next; @@ -553,9 +571,10 @@ typedef struct Mech /* * Basic bot information */ - char *nick; /* current nickname */ - char *wantnick; /* wanted nickname */ - char *userhost; + Mix16 nick; + Mix16 wantnick; + Mix64 userhost; + int vhost_type; uint32_t reset:1, @@ -605,10 +624,6 @@ typedef struct Mech char *signoff; char *from; -#ifdef IDWRAP - char *identfile; -#endif /* IDWRAP */ - /* big buffers at the end */ UniVar setting[SIZE_VARS]; /* global vars + channel defaults */ char modes[32]; diff --git a/src/uptime.c b/src/uptime.c index 41e332c..495574e 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -168,7 +168,7 @@ void send_uptime(int type) */ if (botlist) { - nick = botlist->nick; + nick = getbotnick(botlist); upPack.ontime = htonl(botlist->ontime); if ((sp = find_server(botlist->server))) { diff --git a/src/user.c b/src/user.c index 18ee00b..fd40f11 100644 --- a/src/user.c +++ b/src/user.c @@ -593,7 +593,7 @@ void mirror_user(User *user) } #ifdef DEBUG debug("(mirror_user) mirroring user %s[%i] to local bot %s(%i)\n", - user->name,user->x.x.access,nullstr(anybot->nick),anybot->guid); + user->name,user->x.x.access,getbotnick(anybot),anybot->guid); #endif /* DEBUG */ current = anybot; @@ -646,7 +646,7 @@ void mirror_userlist(void) User *user; #ifdef DEBUG - debug("(mirror_userlist) mirroring userlist of %s(%i)\n",nullstr(current->nick),current->guid); + debug("(mirror_userlist) mirroring userlist of %s(%i)\n",getbotnick(current),current->guid); #endif /* DEBUG */ for(user=current->userlist;user;user=user->next) @@ -903,7 +903,7 @@ int is_bot(const char *userhost) for(bot=botlist;bot;bot=bot->next) { - if (!nickcmp(userhost,bot->nick)) + if (!nickcmp(userhost,getbotnick(bot))) return(TRUE); } return(FALSE);