dcc.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. /*
  2. * dcc.c -- handles:
  3. * activity on a dcc socket
  4. * disconnect on a dcc socket
  5. * ...and that's it! (but it's a LOT)
  6. *
  7. */
  8. #include "common.h"
  9. #include "dcc.h"
  10. #include "settings.h"
  11. #include "enclink.h"
  12. #include "tclhash.h"
  13. #include "adns.h"
  14. #include "main.h"
  15. #include "cmds.h"
  16. #include "color.h"
  17. #include "net.h"
  18. #include "response.h"
  19. #include "misc.h"
  20. #include "users.h"
  21. #include "userrec.h"
  22. #include "userent.h"
  23. #include "match.h"
  24. #include "auth.h"
  25. #include "dccutil.h"
  26. #include "crypt.h"
  27. #include "chanprog.h"
  28. #include "botmsg.h"
  29. #include "botcmd.h"
  30. #include "botnet.h"
  31. #include <ctype.h>
  32. #include <errno.h>
  33. #include <sys/types.h>
  34. #include <sys/socket.h>
  35. #include <netinet/in.h>
  36. #include <sys/utsname.h>
  37. #include <sys/stat.h>
  38. #include "tandem.h"
  39. #include "core_binds.h"
  40. struct dcc_t *dcc = NULL; /* DCC list */
  41. time_t timesync = 0;
  42. int dcc_total = 0; /* size of dcc table */
  43. int dccn = 0; /* actual number of dcc entries */
  44. static time_t password_timeout = 40; /* Time to wait for a password from a user */
  45. static time_t auth_timeout = 80;
  46. static time_t bot_timeout = 15; /* Bot timeout value */
  47. static time_t identtimeout = 15; /* Timeout value for ident lookups */
  48. static time_t dupwait_timeout = 5; /* Timeout for rejecting duplicate entries */
  49. bool protect_telnet = 0; /* Even bother with ident lookups :) */
  50. static int flood_telnet_thr = 10; /* Number of telnet connections to be
  51. * considered a flood */
  52. static time_t flood_telnet_time = 5; /* In how many seconds? */
  53. static void dcc_telnet_got_ident(int, char *);
  54. static void dcc_telnet_pass(int, int);
  55. static void
  56. strip_telnet(int sock, char *buf, int *len)
  57. {
  58. unsigned char *p = (unsigned char *) buf, *o = (unsigned char *) buf;
  59. int mark;
  60. while (*p != 0) {
  61. while ((*p != TLN_IAC) && (*p != 0)) {
  62. if (*p == 0xA0) {
  63. *o++ = 32;
  64. p++;
  65. } else
  66. *o++ = *p++;
  67. }
  68. if (*p == TLN_IAC) {
  69. p++;
  70. mark = 2;
  71. if (!*p)
  72. mark = 1; /* bogus */
  73. if ((*p >= TLN_WILL) && (*p <= TLN_DONT)) {
  74. mark = 3;
  75. if (!*(p + 1))
  76. mark = 2; /* bogus */
  77. }
  78. if (*p == TLN_WILL) {
  79. /* WILL X -> response: DONT X */
  80. /* except WILL ECHO which we just smile and ignore */
  81. if (*(p + 1) != TLN_ECHO) {
  82. write(sock, TLN_IAC_C TLN_DONT_C, 2);
  83. write(sock, p + 1, 1);
  84. }
  85. }
  86. if (*p == TLN_DO) {
  87. /* DO X -> response: WONT X */
  88. /* except DO ECHO which we just smile and ignore */
  89. if (*(p + 1) != TLN_ECHO) {
  90. write(sock, TLN_IAC_C TLN_WONT_C, 2);
  91. write(sock, p + 1, 1);
  92. }
  93. }
  94. if (*p == TLN_AYT) {
  95. /* "are you there?" */
  96. /* response is: "hell yes!" */
  97. write(sock, "\r\nHell, yes!\r\n", 14);
  98. }
  99. /* Anything else can probably be ignored */
  100. p += mark - 1;
  101. *len = *len - mark;
  102. }
  103. }
  104. *o = *p;
  105. }
  106. void
  107. send_timesync(int idx)
  108. {
  109. /* Send timesync to idx, or all lower bots if idx<0 */
  110. if (idx >= 0)
  111. dprintf(idx, "ts %li\n", timesync + now);
  112. else {
  113. char s[15] = "";
  114. sprintf(s, "ts %li\n", timesync + now);
  115. for (int i = 0; i < dcc_total; i++) {
  116. if (dcc[i].type && (dcc[i].type == &DCC_BOT) && (bot_aggressive_to(dcc[i].user))) {
  117. dprintf(i, s);
  118. }
  119. }
  120. }
  121. }
  122. static void
  123. greet_new_bot(int idx)
  124. {
  125. char *sysname = NULL;
  126. struct utsname un;
  127. dcc[idx].timeval = now;
  128. dcc[idx].u.bot->version[0] = 0;
  129. dcc[idx].u.bot->sysname[0] = 0;
  130. dcc[idx].u.bot->numver = 0;
  131. if (conf.bot->hub && dcc[idx].user && (!(dcc[idx].user->flags & USER_OP))) {
  132. putlog(LOG_BOTS, "*", "Rejecting link from %s", dcc[idx].nick);
  133. dprintf(idx, "error You are being rejected.\n");
  134. dprintf(idx, "bye\n");
  135. killsock(dcc[idx].sock);
  136. lostdcc(idx);
  137. return;
  138. }
  139. if (bot_hublevel(dcc[idx].user) == 999)
  140. dcc[idx].status |= STAT_LEAF;
  141. dcc[idx].status |= STAT_LINKING;
  142. if (uname(&un) < 0)
  143. sysname = "*";
  144. else
  145. sysname = un.sysname;
  146. dprintf(idx, "v 1001500 %d Wraith %s <%s> %d %li %s\n", HANDLEN, egg_version, "-", conf.bot->localhub, buildts, egg_version);
  147. dprintf(idx, "si %s %s %s", conf.username ? conf.username : "*", un.sysname ? un.sysname : "*",
  148. un.nodename ? un.nodename : "*");
  149. for (int i = 0; i < dcc_total; i++) {
  150. if (dcc[i].type && dcc[i].type == &DCC_FORK_BOT) {
  151. killsock(dcc[i].sock);
  152. lostdcc(i);
  153. }
  154. }
  155. }
  156. static void
  157. bot_version(int idx, char *par)
  158. {
  159. dcc[idx].timeval = now;
  160. if (in_chain(dcc[idx].nick)) {
  161. dprintf(idx, "error Sorry, already connected.\n");
  162. dprintf(idx, "bye\n");
  163. killsock(dcc[idx].sock);
  164. lostdcc(idx);
  165. return;
  166. }
  167. if ((par[0] >= '0') && (par[0] <= '9')) {
  168. char *work = NULL;
  169. work = newsplit(&par);
  170. dcc[idx].u.bot->numver = atoi(work);
  171. /* old numver crap */
  172. } else
  173. dcc[idx].u.bot->numver = 0;
  174. dprintf(idx, "tb %s\n", conf.bot->nick);
  175. size_t l = atol(newsplit(&par));
  176. if (l != HANDLEN) {
  177. putlog(LOG_BOTS, "*", "Non-matching handle lengths with %s, they use %d characters.", dcc[idx].nick, l);
  178. dprintf(idx, "error Non-matching handle length: mine %d, yours %d\n", HANDLEN, l);
  179. dprintf(idx, "bye %s\n", "bad handlen");
  180. killsock(dcc[idx].sock);
  181. lostdcc(idx);
  182. return;
  183. }
  184. char x[1024] = "", *vversion = NULL;
  185. int vlocalhub = 0;
  186. time_t vbuildts = 0;
  187. strlcpy(dcc[idx].u.bot->version, par, 120);
  188. newsplit(&par); /* 'ver' */
  189. newsplit(&par); /* handlen */
  190. newsplit(&par); /* network */
  191. if (par[0])
  192. vlocalhub = atoi(newsplit(&par));
  193. if (par[0])
  194. vbuildts = atol(newsplit(&par));
  195. if (par[0])
  196. vversion = newsplit(&par);
  197. if (conf.bot->hub) {
  198. putlog(LOG_BOTS, "*", DCC_LINKED, dcc[idx].nick);
  199. chatout("*** Linked to %s\n", dcc[idx].nick);
  200. botnet_send_nlinked(idx, dcc[idx].nick, conf.bot->nick, '!', vlocalhub, vbuildts, vversion);
  201. } else {
  202. putlog(LOG_BOTS, "*", "Linked to botnet.");
  203. chatout("*** Linked to botnet.\n");
  204. }
  205. dump_links(idx);
  206. touch_laston(dcc[idx].user, "linked", now);
  207. dcc[idx].type = &DCC_BOT;
  208. addbot(dcc[idx].nick, dcc[idx].nick, conf.bot->nick, '-', vlocalhub, vbuildts, vversion);
  209. egg_snprintf(x, sizeof x, "v 1001500");
  210. bot_shareupdate(idx, x);
  211. bot_share(idx, x);
  212. dprintf(idx, "el\n");
  213. }
  214. void
  215. failed_link(int idx)
  216. {
  217. char s[81] = "", s1[512] = "";
  218. if (dcc[idx].u.bot->linker[0]) {
  219. egg_snprintf(s, sizeof s, "Couldn't link to %s.", dcc[idx].nick);
  220. strcpy(s1, dcc[idx].u.bot->linker);
  221. add_note(s1, conf.bot->nick, s, -2, 0);
  222. }
  223. if (dcc[idx].u.bot->numver >= (-1))
  224. putlog(LOG_BOTS, "*", DCC_LINKFAIL, dcc[idx].nick);
  225. if (dcc[idx].sock != -1) {
  226. for (int i = 0; i < MAXSOCKS; i++)
  227. if (dcc[idx].sock == socklist[i].sock) {
  228. killsock(dcc[idx].sock);
  229. dcc[idx].sock = -1;
  230. }
  231. }
  232. strcpy(s, dcc[idx].nick);
  233. lostdcc(idx);
  234. autolink_cycle(s); /* Check for more auto-connections */
  235. }
  236. static void
  237. cont_link(int idx, char *buf, int ii)
  238. {
  239. /* If we're already connected somewhere, unlink and idle a sec */
  240. for (int i = 0; i < dcc_total; i++) {
  241. if (dcc[i].type && (dcc[i].type == &DCC_BOT) && (!bot_aggressive_to(dcc[i].user))) {
  242. putlog(LOG_BOTS, "*", "Unlinking %s - restructure", dcc[i].nick);
  243. botnet_send_unlinked(i, dcc[i].nick, "Restructure");
  244. killsock(dcc[i].sock);
  245. lostdcc(i);
  246. usleep(1000 * 500);
  247. break;
  248. }
  249. }
  250. /*. ssl_link(dcc[idx].sock, CONNECT_SSL); */
  251. dcc[idx].type = &DCC_BOT_NEW;
  252. dcc[idx].u.bot->numver = 0;
  253. if (ii == 3)
  254. dprintf(idx, "-%s\n", conf.bot->nick);
  255. /* wait for "neg?" now */
  256. /* now we wait to negotiate an encryption */
  257. return;
  258. }
  259. static void
  260. dcc_bot_new(int idx, char *buf, int x)
  261. {
  262. /* struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick); */
  263. char *code = NULL;
  264. strip_telnet(dcc[idx].sock, buf, &x);
  265. code = newsplit(&buf);
  266. if (!egg_strcasecmp(code, "goodbye!")) {
  267. greet_new_bot(idx);
  268. } else if (!egg_strcasecmp(code, "v")) {
  269. bot_version(idx, buf);
  270. } else if (!egg_strcasecmp(code, "neg!")) { /* something to parse in enclink.c */
  271. link_parse(idx, buf);
  272. } else if (!egg_strcasecmp(code, "neg?")) { /* we're connecting to THEM */
  273. int snum = findanysnum(dcc[idx].sock);
  274. if (snum >= 0) {
  275. char *rand = newsplit(&buf), *tmp = strdup(buf), *tmpp = tmp, *p = NULL;
  276. int i = -1;
  277. while ((p = strchr(buf, ' ')) && i == -1) {
  278. *p = 0;
  279. /* pick the first (lowest num) one that we share */
  280. if ((i = link_find_by_type(atoi(tmp))) != -1)
  281. break;
  282. tmp = p++;
  283. }
  284. free(tmpp);
  285. sdprintf("Choosing '%s' for link", enclink[i].name);
  286. link_hash(idx, rand);
  287. dprintf(idx, "neg %s %d\n", dcc[idx].shahash, enclink[i].type);
  288. socklist[snum].enclink = i;
  289. link_link(idx, -1, i, TO);
  290. }
  291. } else if (!egg_strcasecmp(code, "error")) {
  292. putlog(LOG_MISC, "*", "ERROR linking %s: %s", dcc[idx].nick, buf);
  293. killsock(dcc[idx].sock);
  294. lostdcc(idx);
  295. } else if (strcmp(code, "")) {
  296. /* Invalid password/digest on leaf */
  297. putlog(LOG_WARN, "*", "%s failed encrypted link handshake", dcc[idx].nick);
  298. killsock(dcc[idx].sock);
  299. lostdcc(idx);
  300. }
  301. /* Ignore otherwise */
  302. }
  303. static void
  304. eof_dcc_bot_new(int idx)
  305. {
  306. putlog(LOG_BOTS, "*", DCC_LOSTBOT, dcc[idx].nick);
  307. killsock(dcc[idx].sock);
  308. lostdcc(idx);
  309. }
  310. static void
  311. timeout_dcc_bot_new(int idx)
  312. {
  313. if (conf.bot->hub)
  314. putlog(LOG_BOTS, "*", DCC_TIMEOUT, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  315. else
  316. putlog(LOG_BOTS, "*", "Timeout: bot link to %s", dcc[idx].nick);
  317. killsock(dcc[idx].sock);
  318. lostdcc(idx);
  319. }
  320. static void
  321. display_dcc_bot_new(int idx, char *buf)
  322. {
  323. sprintf(buf, "bot* waited %lis", now - dcc[idx].timeval);
  324. }
  325. static void
  326. free_dcc_bot_(int n, void *x)
  327. {
  328. if (dcc[n].type == &DCC_BOT) {
  329. unvia(n, findbot(dcc[n].nick));
  330. rembot(dcc[n].nick);
  331. }
  332. free(x);
  333. }
  334. struct dcc_table DCC_BOT_NEW = {
  335. "BOT_NEW",
  336. 0,
  337. eof_dcc_bot_new,
  338. dcc_bot_new,
  339. &bot_timeout,
  340. timeout_dcc_bot_new,
  341. display_dcc_bot_new,
  342. free_dcc_bot_,
  343. NULL,
  344. NULL
  345. };
  346. /* Hash function for tandem bot commands */
  347. extern botcmd_t C_bot[];
  348. static void
  349. dcc_bot(int idx, char *code, int i)
  350. {
  351. char *msg = NULL;
  352. strip_telnet(dcc[idx].sock, code, &i);
  353. if (debug_output) {
  354. /* if (code[0] != 'z' && code[1] != 'b' && code[2] != ' ') { */
  355. if (code[0] == 's')
  356. putlog(LOG_BOTSHARE, "@", "{%s} %s", dcc[idx].nick, code);
  357. else
  358. putlog(LOG_BOTNET, "@", "<-[%s] %s", dcc[idx].nick, code);
  359. /* } */
  360. }
  361. msg = strchr(code, ' ');
  362. if (msg) {
  363. *msg = 0;
  364. msg++;
  365. } else
  366. msg = "";
  367. for (i = 0; C_bot[i].name; i++) {
  368. int y = egg_strcasecmp(code, C_bot[i].name);
  369. if (!y) {
  370. /* Found a match */
  371. if (!C_bot[i].type || (C_bot[i].type == HUB && conf.bot->hub) || (C_bot[i].type == LEAF && !conf.bot->hub))
  372. (C_bot[i].func) (idx, msg);
  373. break;
  374. } else if (y < 0)
  375. break;
  376. }
  377. }
  378. static void
  379. eof_dcc_bot(int idx)
  380. {
  381. char x[1024] = "";
  382. int bots, users;
  383. bots = bots_in_subtree(findbot(dcc[idx].nick));
  384. users = users_in_subtree(findbot(dcc[idx].nick));
  385. egg_snprintf(x, sizeof x,
  386. "Lost bot: %s (lost %d bot%s and %d user%s)",
  387. dcc[idx].nick, bots, (bots != 1) ? "s" : "", users, (users != 1) ? "s" : "");
  388. putlog(LOG_BOTS, "*", "%s.", x);
  389. chatout("*** %s\n", x);
  390. botnet_send_unlinked(idx, dcc[idx].nick, x);
  391. killsock(dcc[idx].sock);
  392. lostdcc(idx);
  393. }
  394. static void
  395. display_dcc_bot(int idx, char *buf)
  396. {
  397. size_t i = simple_sprintf(buf, "bot flags: ");
  398. buf[i++] = b_status(idx) & STAT_PINGED ? 'P' : 'p';
  399. buf[i++] = b_status(idx) & STAT_SHARE ? 'U' : 'u';
  400. buf[i++] = b_status(idx) & STAT_CALLED ? 'C' : 'c';
  401. buf[i++] = b_status(idx) & STAT_OFFERED ? 'O' : 'o';
  402. buf[i++] = b_status(idx) & STAT_SENDING ? 'S' : 's';
  403. buf[i++] = b_status(idx) & STAT_GETTING ? 'G' : 'g';
  404. buf[i++] = b_status(idx) & STAT_WARNED ? 'W' : 'w';
  405. buf[i++] = b_status(idx) & STAT_LEAF ? 'L' : 'l';
  406. buf[i++] = b_status(idx) & STAT_LINKING ? 'I' : 'i';
  407. buf[i++] = b_status(idx) & STAT_AGGRESSIVE ? 'a' : 'A';
  408. buf[i++] = b_status(idx) & STAT_OFFEREDU ? 'B' : 'b';
  409. buf[i++] = b_status(idx) & STAT_SENDINGU ? 'D' : 'd';
  410. buf[i++] = b_status(idx) & STAT_GETTINGU ? 'E' : 'e';
  411. #ifdef USE_IPV6
  412. if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].host6[0])
  413. buf[i++] = '6';
  414. #endif /* USE_IPV6 */
  415. buf[i++] = 0;
  416. }
  417. static void
  418. display_dcc_fork_bot(int idx, char *buf)
  419. {
  420. sprintf(buf, "conn bot");
  421. }
  422. struct dcc_table DCC_BOT = {
  423. "BOT",
  424. DCT_BOT,
  425. eof_dcc_bot,
  426. dcc_bot,
  427. NULL,
  428. NULL,
  429. display_dcc_bot,
  430. free_dcc_bot_,
  431. NULL,
  432. NULL
  433. };
  434. struct dcc_table DCC_FORK_BOT = {
  435. "FORK_BOT",
  436. 0,
  437. failed_link,
  438. cont_link,
  439. &connect_timeout,
  440. failed_link,
  441. display_dcc_fork_bot,
  442. free_dcc_bot_,
  443. NULL,
  444. NULL
  445. };
  446. static void
  447. dcc_identd(int idx, char *buf, int atr)
  448. {
  449. char outbuf[1024] = "";
  450. egg_snprintf(outbuf, sizeof outbuf, "%s : USERID : UNIX : %s\n", buf, conf.bot->nick);
  451. tputs(dcc[idx].sock, outbuf, strlen(outbuf));
  452. /* just close it, functions neededing it will open it. */
  453. identd_close();
  454. }
  455. static void
  456. eof_dcc_identd(int idx)
  457. {
  458. /* dont bother logging it, who gives a fuck */
  459. killsock(dcc[idx].sock);
  460. lostdcc(idx);
  461. }
  462. static void
  463. display_dcc_identd(int idx, char *buf)
  464. {
  465. sprintf(buf, "idtd %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
  466. }
  467. struct dcc_table DCC_IDENTD = {
  468. "IDENTD",
  469. DCT_LISTEN,
  470. eof_dcc_identd,
  471. dcc_identd,
  472. NULL,
  473. NULL,
  474. display_dcc_identd,
  475. NULL,
  476. NULL,
  477. NULL
  478. };
  479. static void
  480. dcc_identd_connect(int idx, char *buf, int atr)
  481. {
  482. in_addr_t ip;
  483. port_t port;
  484. int j, sock;
  485. char s[UHOSTLEN + 1] = "";
  486. if (dcc_total + 1 > max_dcc) {
  487. j = answer(dcc[idx].sock, s, &ip, &port, 0);
  488. if (j != -1)
  489. killsock(j);
  490. return;
  491. }
  492. sock = answer(dcc[idx].sock, s, &ip, &port, 0);
  493. while ((sock == -1) && (errno == EAGAIN))
  494. sock = answer(sock, s, &ip, &port, 0);
  495. if (sock < 0) {
  496. putlog(LOG_MISC, "*", DCC_FAILED, strerror(errno));
  497. return;
  498. }
  499. /* changeover_dcc(idx, &DCC_IDENTD, 0); */
  500. j = new_dcc(&DCC_IDENTD, 0);
  501. dcc[j].sock = sock;
  502. dcc[j].port = port;
  503. dcc[j].addr = dcc[idx].addr;
  504. strcpy(dcc[j].host, dcc[idx].host);
  505. strcpy(dcc[j].nick, "*");
  506. /* dcc[j].u.ident_sock = dcc[idx].sock; */
  507. dcc[j].timeval = now;
  508. }
  509. struct dcc_table DCC_IDENTD_CONNECT = {
  510. "IDENTD",
  511. DCT_LISTEN,
  512. eof_dcc_identd,
  513. dcc_identd_connect,
  514. NULL,
  515. NULL,
  516. display_dcc_identd,
  517. NULL,
  518. NULL,
  519. NULL
  520. };
  521. static void
  522. dcc_chat_secpass(int idx, char *buf, int atr)
  523. {
  524. int badauth = 0;
  525. if (!atr)
  526. return;
  527. strip_telnet(dcc[idx].sock, buf, &atr);
  528. atr = dcc[idx].user ? dcc[idx].user->flags : 0;
  529. if (dccauth) {
  530. char check[MD5_HASH_LENGTH + 7] = "";
  531. egg_snprintf(check, sizeof check, "+Auth %s", dcc[idx].hash);
  532. badauth = strcmp(check, buf);
  533. /* +secpass */
  534. }
  535. /* Correct pass or secpass! */
  536. if (!dccauth || (dccauth && !badauth)) {
  537. putlog(LOG_MISC, "*", DCC_LOGGEDIN, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  538. if (dcc[idx].u.chat->away) {
  539. free(dcc[idx].u.chat->away);
  540. dcc[idx].u.chat->away = NULL;
  541. }
  542. dcc[idx].type = &DCC_CHAT;
  543. dcc[idx].status &= ~STAT_CHAT;
  544. dcc[idx].u.chat->channel = -2;
  545. /* Turn echo back on for telnet sessions (send IAC WON'T ECHO). */
  546. if (dcc[idx].status & STAT_TELNET)
  547. dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  548. stats_add(dcc[idx].user, 1, 0);
  549. if (!get_user(&USERENTRY_SECPASS, dcc[idx].user)) { /* this should check how many logins instead */
  550. char pass[MAXPASSLEN + 1] = "";
  551. dprintf(idx, "********************************************************************\n \n \n");
  552. dprintf(idx, "%sWARNING: YOU DO NOT HAVE A SECPASS SET, NOW SETTING A RANDOM ONE....%s\n", FLASH(-1), FLASH_END(-1));
  553. make_rand_str(pass, MAXPASSLEN);
  554. set_user(&USERENTRY_SECPASS, dcc[idx].user, pass);
  555. if (conf.bot->hub)
  556. write_userfile(idx);
  557. dprintf(idx, "Your secpass is now: %s%s%s\n", pass, BOLD(-1), BOLD_END(-1));
  558. dprintf(idx, "Make sure you do not lose this, as it is needed to login for now on.\n \n");
  559. dprintf(idx, "********************************************************************\n");
  560. }
  561. dcc_chatter(idx);
  562. } else if (dccauth && badauth) { /* bad auth */
  563. dprintf(idx, "%s\n", response(RES_BADUSERPASS));
  564. putlog(LOG_MISC, "*", DCC_BADAUTH, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  565. if (dcc[idx].u.chat->away) { /* su from a dumb user */
  566. /* Turn echo back on for telnet sessions (send IAC WON'T ECHO). */
  567. if (dcc[idx].status & STAT_TELNET)
  568. dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  569. dcc[idx].user = get_user_by_handle(userlist, dcc[idx].u.chat->away);
  570. strcpy(dcc[idx].nick, dcc[idx].u.chat->away);
  571. free(dcc[idx].u.chat->away);
  572. free(dcc[idx].u.chat->su_nick);
  573. dcc[idx].u.chat->away = NULL;
  574. dcc[idx].u.chat->su_nick = NULL;
  575. dcc[idx].type = &DCC_CHAT;
  576. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  577. botnet_send_join_idx(idx);
  578. chanout_but(-1, dcc[idx].u.chat->channel, DCC_JOIN, dcc[idx].nick);
  579. } else {
  580. killsock(dcc[idx].sock);
  581. lostdcc(idx);
  582. }
  583. }
  584. }
  585. static void
  586. eof_dcc_general(int idx)
  587. {
  588. putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  589. killsock(dcc[idx].sock);
  590. lostdcc(idx);
  591. }
  592. static void
  593. tout_dcc_chat_secpass(int idx)
  594. {
  595. putlog(LOG_MISC, "*", DCC_SPWDTIMEOUT, dcc[idx].nick, dcc[idx].host);
  596. killsock(dcc[idx].sock);
  597. lostdcc(idx);
  598. }
  599. static void
  600. display_dcc_chat_secpass(int idx, char *buf)
  601. {
  602. sprintf(buf, "secpass waited %lis", now - dcc[idx].timeval);
  603. }
  604. static void
  605. tout_dcc_chat_pass(int idx)
  606. {
  607. putlog(LOG_MISC, "*", DCC_PWDTIMEOUT, dcc[idx].nick, dcc[idx].host);
  608. killsock(dcc[idx].sock);
  609. lostdcc(idx);
  610. }
  611. static void
  612. display_dcc_chat_pass(int idx, char *buf)
  613. {
  614. sprintf(buf, "pass waited %lis", now - dcc[idx].timeval);
  615. }
  616. static void
  617. kill_dcc_general(int idx, void *x)
  618. {
  619. register struct chat_info *p = (struct chat_info *) x;
  620. if (p) {
  621. if (p->buffer) {
  622. struct msgq *r = NULL, *q = NULL;
  623. for (r = dcc[idx].u.chat->buffer; r; r = q) {
  624. q = r->next;
  625. free(r->msg);
  626. free(r);
  627. }
  628. }
  629. if (p->away) {
  630. free(p->away);
  631. }
  632. free(p);
  633. }
  634. }
  635. /* Remove the color control codes that mIRC,pIRCh etc use to make
  636. * their client seem so fecking cool! (Sorry, Khaled, you are a nice
  637. * guy, but when you added this feature you forced people to either
  638. * use your *SHAREWARE* client or face screenfulls of crap!)
  639. */
  640. static void
  641. strip_mirc_codes(int flags, char *text)
  642. {
  643. char *dd = text;
  644. while (*text) {
  645. switch (*text) {
  646. case 2: /* Bold text */
  647. if (flags & STRIP_BOLD) {
  648. text++;
  649. continue;
  650. }
  651. break;
  652. case 3: /* mIRC colors? */
  653. if (flags & STRIP_COLOR) {
  654. if (egg_isdigit(text[1])) { /* Is the first char a number? */
  655. text += 2; /* Skip over the ^C and the first digit */
  656. if (egg_isdigit(*text))
  657. text++; /* Is this a double digit number? */
  658. if (*text == ',') { /* Do we have a background color next? */
  659. if (egg_isdigit(text[1]))
  660. text += 2; /* Skip over the first background digit */
  661. if (egg_isdigit(*text))
  662. text++; /* Is it a double digit? */
  663. }
  664. } else
  665. text++;
  666. continue;
  667. }
  668. break;
  669. case 7:
  670. if (flags & STRIP_BELLS) {
  671. text++;
  672. continue;
  673. }
  674. break;
  675. case 0x16: /* Reverse video */
  676. if (flags & STRIP_REV) {
  677. text++;
  678. continue;
  679. }
  680. break;
  681. case 0x1f: /* Underlined text */
  682. if (flags & STRIP_UNDER) {
  683. text++;
  684. continue;
  685. }
  686. break;
  687. case 033:
  688. if (flags & STRIP_ANSI) {
  689. text++;
  690. if (*text == '[') {
  691. text++;
  692. while ((*text == ';') || egg_isdigit(*text))
  693. text++;
  694. if (*text)
  695. text++; /* also kill the following char */
  696. }
  697. continue;
  698. }
  699. break;
  700. }
  701. *dd++ = *text++; /* Move on to the next char */
  702. }
  703. *dd = 0;
  704. }
  705. static void
  706. append_line(int idx, char *line)
  707. {
  708. struct msgq *p = NULL, *q = NULL;
  709. struct chat_info *c = dcc[idx].u.chat;
  710. if (c->current_lines > 1000) {
  711. /* They're probably trying to fill up the bot nuke the sods :) */
  712. for (p = c->buffer; p; p = q) {
  713. q = p->next;
  714. free(p->msg);
  715. free(p);
  716. }
  717. c->buffer = 0;
  718. dcc[idx].status &= ~STAT_PAGE;
  719. do_boot(idx, conf.bot->nick, "too many pages - senq full");
  720. return;
  721. }
  722. size_t l = strlen(line);
  723. if ((c->line_count < c->max_line) && (c->buffer == NULL)) {
  724. c->line_count++;
  725. tputs(dcc[idx].sock, line, l);
  726. } else {
  727. c->current_lines++;
  728. if (c->buffer == NULL)
  729. q = NULL;
  730. else
  731. for (q = c->buffer; q->next; q = q->next) ;
  732. p = (struct msgq *) my_calloc(1, sizeof(struct msgq));
  733. p->len = l;
  734. p->msg = (char *) my_calloc(1, l + 1);
  735. p->next = NULL;
  736. strcpy(p->msg, line);
  737. if (q == NULL)
  738. c->buffer = p;
  739. else
  740. q->next = p;
  741. }
  742. }
  743. static void
  744. out_dcc_general(int idx, char *buf, void *x)
  745. {
  746. register struct chat_info *p = (struct chat_info *) x;
  747. char *y = buf;
  748. strip_mirc_codes(p->strip_flags, buf);
  749. if (dcc[idx].status & STAT_TELNET)
  750. y = add_cr(buf);
  751. if (dcc[idx].status & STAT_PAGE)
  752. append_line(idx, y);
  753. else
  754. tputs(dcc[idx].sock, y, strlen(y));
  755. }
  756. static struct dcc_table DCC_CHAT_SECPASS = {
  757. "CHAT_SECPASS",
  758. 0,
  759. eof_dcc_general,
  760. dcc_chat_secpass,
  761. &auth_timeout,
  762. tout_dcc_chat_secpass,
  763. display_dcc_chat_secpass,
  764. kill_dcc_general,
  765. out_dcc_general,
  766. NULL
  767. };
  768. static void
  769. dcc_chat_pass(int idx, char *buf, int atr)
  770. {
  771. if (!atr)
  772. return;
  773. char *pass = NULL;
  774. strip_telnet(dcc[idx].sock, buf, &atr);
  775. atr = dcc[idx].user ? dcc[idx].user->flags : 0;
  776. pass = newsplit(&buf);
  777. if (dcc[idx].user->bot) {
  778. if (!egg_strcasecmp(pass, "neg!")) { /* we're the hub */
  779. link_parse(idx, buf);
  780. } else if (!egg_strcasecmp(pass, "neg.")) { /* we're done, link up! */
  781. free(dcc[idx].u.chat);
  782. dcc[idx].type = &DCC_BOT_NEW;
  783. dcc[idx].u.bot = (struct bot_info *) my_calloc(1, sizeof(struct bot_info));
  784. dcc[idx].status = STAT_CALLED;
  785. dprintf(idx, "goodbye!\n");
  786. greet_new_bot(idx);
  787. if (conf.bot->hub)
  788. send_timesync(idx);
  789. } else if (!egg_strcasecmp(pass, "neg")) {
  790. int snum = findanysnum(dcc[idx].sock);
  791. if (snum >= 0) {
  792. char *hash = newsplit(&buf);
  793. if (strcmp(dcc[idx].shahash, hash)) {
  794. putlog(LOG_WARN, "*", "%s attempted to negotiate an encryption with an invalid hash.", dcc[idx].nick);
  795. killsock(dcc[idx].sock);
  796. lostdcc(idx);
  797. return;
  798. }
  799. int type = atoi(newsplit(&buf)), i = -1;
  800. /* verify we have that type and then initiate it */
  801. if ((i = link_find_by_type(type)) == -1) {
  802. putlog(LOG_WARN, "*", "%s attempted to link with an invalid encryption.", dcc[idx].nick);
  803. killsock(dcc[idx].sock);
  804. lostdcc(idx);
  805. return;
  806. }
  807. socklist[snum].enclink = i;
  808. link_link(idx, -1, i, FROM);
  809. }
  810. } else {
  811. /* Invalid password/digest on hub */
  812. putlog(LOG_WARN, "*", "%s failed encrypted link handshake.", dcc[idx].nick);
  813. killsock(dcc[idx].sock);
  814. lostdcc(idx);
  815. }
  816. return;
  817. }
  818. if (u_pass_match(dcc[idx].user, pass)) {
  819. if (dccauth) {
  820. char randstr[51] = "";
  821. make_rand_str(randstr, 50);
  822. makehash(idx, -1, randstr);
  823. dcc[idx].type = &DCC_CHAT_SECPASS;
  824. dcc[idx].timeval = now;
  825. dprintf(idx, "-Auth %s %s\n", randstr, conf.bot->nick);
  826. } else {
  827. dcc_chat_secpass(idx, pass, atr);
  828. }
  829. } else {
  830. dprintf(idx, "%s\n", response(RES_BADUSERPASS));
  831. putlog(LOG_MISC, "*", DCC_BADLOGIN, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  832. if (dcc[idx].u.chat->away) { /* su from a dumb user */
  833. /* Turn echo back on for telnet sessions (send IAC WON'T ECHO). */
  834. if (dcc[idx].status & STAT_TELNET)
  835. dprintf(idx, TLN_IAC_C TLN_WONT_C TLN_ECHO_C "\n");
  836. dcc[idx].user = get_user_by_handle(userlist, dcc[idx].u.chat->away);
  837. strcpy(dcc[idx].nick, dcc[idx].u.chat->away);
  838. free(dcc[idx].u.chat->away);
  839. free(dcc[idx].u.chat->su_nick);
  840. dcc[idx].u.chat->away = NULL;
  841. dcc[idx].u.chat->su_nick = NULL;
  842. dcc[idx].type = &DCC_CHAT;
  843. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  844. botnet_send_join_idx(idx);
  845. chanout_but(-1, dcc[idx].u.chat->channel, DCC_JOIN, dcc[idx].nick);
  846. } else {
  847. killsock(dcc[idx].sock);
  848. lostdcc(idx);
  849. }
  850. }
  851. }
  852. struct dcc_table DCC_CHAT_PASS = {
  853. "CHAT_PASS",
  854. 0,
  855. eof_dcc_general,
  856. dcc_chat_pass,
  857. &password_timeout,
  858. tout_dcc_chat_pass,
  859. display_dcc_chat_pass,
  860. kill_dcc_general,
  861. out_dcc_general,
  862. NULL
  863. };
  864. /* Make sure ansi code is just for color-changing
  865. */
  866. static int
  867. check_ansi(char *v)
  868. {
  869. int count = 2;
  870. if (*v++ != '\033')
  871. return 1;
  872. if (*v++ != '[')
  873. return 1;
  874. while (*v) {
  875. if (*v == 'm')
  876. return 0;
  877. if ((*v != ';') && ((*v < '0') || (*v > '9')))
  878. return count;
  879. v++;
  880. count++;
  881. }
  882. return count;
  883. }
  884. static void
  885. eof_dcc_chat(int idx)
  886. {
  887. putlog(LOG_MISC, "*", DCC_LOSTDCC, dcc[idx].nick, dcc[idx].host, dcc[idx].port);
  888. if (dcc[idx].u.chat->channel >= 0) {
  889. chanout_but(idx, dcc[idx].u.chat->channel, "*** %s lost dcc link.\n", dcc[idx].nick);
  890. if (dcc[idx].u.chat->channel < GLOBAL_CHANS)
  891. botnet_send_part_idx(idx, "lost dcc link");
  892. }
  893. check_bind_chof(dcc[idx].nick, idx);
  894. killsock(dcc[idx].sock);
  895. lostdcc(idx);
  896. }
  897. static void
  898. dcc_chat(int idx, char *buf, int len)
  899. {
  900. int i = 0;
  901. strip_telnet(dcc[idx].sock, buf, &len);
  902. if (buf[0] && (buf[0] != settings.dcc_prefix[0]) && !(dcc[idx].user && (dcc[idx].user->flags & USER_NOFLOOD)) &&
  903. detect_dcc_flood(&dcc[idx].timeval, dcc[idx].u.chat, idx))
  904. return;
  905. dcc[idx].timeval = now;
  906. if (buf[0]) {
  907. int nathan = 0, doron = 0, fixed = 0;
  908. char *v = buf, *d = buf;
  909. /* Check for beeps and cancel annoying ones */
  910. while (*v)
  911. switch (*v) {
  912. case 1: /* CTCP ?! */
  913. v++;
  914. break;
  915. case 7: /* Beep - no more than 3 */
  916. nathan++;
  917. if (nathan > 3)
  918. v++;
  919. else
  920. *d++ = *v++;
  921. break;
  922. case 8: /* Backspace - for lame telnet's :) */
  923. if (d > buf) {
  924. d--;
  925. }
  926. v++;
  927. break;
  928. case 27: /* ESC - ansi code? */
  929. doron = check_ansi(v);
  930. /* If it's valid, append a return-to-normal code at the end */
  931. if (!doron) {
  932. *d++ = *v++;
  933. fixed = 1;
  934. } else
  935. v += doron;
  936. break;
  937. case '\r': /* Weird pseudo-linefeed */
  938. v++;
  939. break;
  940. default:
  941. *d++ = *v++;
  942. }
  943. if (fixed)
  944. strcpy(d, "\033[0m");
  945. else
  946. *d = 0;
  947. if (u_pass_match(dcc[idx].user, buf)) { /* user said their password :) */
  948. dprintf(idx, "Sure you want that going to the partyline? ;) (msg to partyline halted.)\n");
  949. } else if (!strncmp(buf, "+Auth ", 6)) { /* ignore extra +Auth lines */
  950. } else if ((!strncmp(buf, settings.dcc_prefix, strlen(settings.dcc_prefix))) || (dcc[idx].u.chat->channel < 0)) {
  951. if (!strncmp(buf, settings.dcc_prefix, strlen(settings.dcc_prefix))) /* strip '.' out */
  952. buf++;
  953. v = newsplit(&buf);
  954. rmspace(buf);
  955. check_bind_dcc(v, idx, buf);
  956. } else if (buf[0] == ',') {
  957. int me = 0;
  958. if ((buf[1] == 'm') && (buf[2] == 'e') && buf[3] == ' ')
  959. me = 1;
  960. for (i = 0; i < dcc_total; i++) {
  961. if (dcc[i].type) {
  962. int ok = 0;
  963. if (dcc[i].type->flags & DCT_MASTER) {
  964. if ((dcc[i].type != &DCC_CHAT) || (dcc[i].u.chat->channel >= 0))
  965. if ((i != idx) || (dcc[idx].status & STAT_ECHO))
  966. ok = 1;
  967. }
  968. if (ok) {
  969. struct userrec *u = get_user_by_handle(userlist, dcc[i].nick);
  970. if (u && (u->flags & USER_MASTER)) {
  971. if (me)
  972. dprintf(i, "-> %s%s\n", dcc[idx].nick, buf + 3);
  973. else
  974. dprintf(i, "-%s-> %s\n", dcc[idx].nick, buf + 1);
  975. }
  976. }
  977. }
  978. }
  979. } else if (buf[0] == '\'') {
  980. int me = 0;
  981. if ((buf[1] == 'm') && (buf[2] == 'e') && ((buf[3] == ' ') || (buf[3] == '\'') || (buf[3] == ',')))
  982. me = 1;
  983. for (i = 0; i < dcc_total; i++) {
  984. if (dcc[i].type && dcc[i].type->flags & DCT_CHAT) {
  985. if (me)
  986. dprintf(i, "=> %s%s\n", dcc[idx].nick, buf + 3);
  987. else
  988. dprintf(i, "=%s=> %s\n", dcc[idx].nick, buf + 1);
  989. }
  990. }
  991. } else {
  992. if (dcc[idx].u.chat->away != NULL)
  993. not_away(idx);
  994. if (!strncmp(buf, "CTCP_MESSAGE ", 13)) /* irssi */
  995. buf += 13;
  996. if (!strncmp(buf, "ACTION ", 7)) {
  997. buf += 7;
  998. check_bind_dcc("me", idx, buf);
  999. } else {
  1000. if (dcc[idx].status & STAT_ECHO)
  1001. chanout_but(-1, dcc[idx].u.chat->channel, "<%s> %s\n", dcc[idx].nick, buf);
  1002. else
  1003. chanout_but(idx, dcc[idx].u.chat->channel, "<%s> %s\n", dcc[idx].nick, buf);
  1004. botnet_send_chan(-1, conf.bot->nick, dcc[idx].nick, dcc[idx].u.chat->channel, buf);
  1005. }
  1006. }
  1007. }
  1008. if (dcc[idx].type == &DCC_CHAT) /* Could have change to files */
  1009. if (dcc[idx].status & STAT_PAGE)
  1010. flush_lines(idx, dcc[idx].u.chat);
  1011. }
  1012. static void
  1013. display_dcc_chat(int idx, char *buf)
  1014. {
  1015. size_t i = simple_sprintf(buf, "chat flags: ");
  1016. int colori = 0;
  1017. buf[i++] = dcc[idx].status & STAT_CHAT ? 'C' : 'c';
  1018. buf[i++] = dcc[idx].status & STAT_PARTY ? 'P' : 'p';
  1019. buf[i++] = dcc[idx].status & STAT_TELNET ? 'T' : 't';
  1020. buf[i++] = dcc[idx].status & STAT_ECHO ? 'E' : 'e';
  1021. buf[i++] = dcc[idx].status & STAT_PAGE ? 'P' : 'p';
  1022. if ((colori = coloridx(idx)))
  1023. buf[i++] = colori == 1 ? 'A' : 'M';
  1024. #ifdef USE_IPV6
  1025. if (sockprotocol(dcc[idx].sock) == AF_INET6 && dcc[idx].host6[0])
  1026. buf[i++] = '6';
  1027. #endif /* USE_IPV6 */
  1028. simple_sprintf(buf + i, "/%d", dcc[idx].u.chat->channel);
  1029. }
  1030. struct dcc_table DCC_CHAT = {
  1031. "CHAT",
  1032. DCT_CHAT | DCT_MASTER | DCT_SHOWWHO | DCT_VALIDIDX | DCT_SIMUL | DCT_CANBOOT | DCT_REMOTEWHO,
  1033. eof_dcc_chat,
  1034. dcc_chat,
  1035. NULL,
  1036. NULL,
  1037. display_dcc_chat,
  1038. kill_dcc_general,
  1039. out_dcc_general,
  1040. NULL
  1041. };
  1042. static int lasttelnets;
  1043. static char lasttelnethost[81];
  1044. static time_t lasttelnettime;
  1045. /* A modified detect_flood for incoming telnet flood protection.
  1046. */
  1047. static bool
  1048. detect_telnet_flood(char *floodhost)
  1049. {
  1050. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  1051. get_user_flagrec(get_user_by_host(floodhost), &fr, NULL);
  1052. if (!flood_telnet_thr || glob_noflood(fr))
  1053. return 0; /* No flood protection */
  1054. if (egg_strcasecmp(lasttelnethost, floodhost)) { /* New... */
  1055. strcpy(lasttelnethost, floodhost);
  1056. lasttelnettime = now;
  1057. lasttelnets = 0;
  1058. return 0;
  1059. }
  1060. if (lasttelnettime < now - flood_telnet_time) {
  1061. /* Flood timer expired, reset it */
  1062. lasttelnettime = now;
  1063. lasttelnets = 0;
  1064. return 0;
  1065. }
  1066. lasttelnets++;
  1067. if (lasttelnets >= flood_telnet_thr) { /* FLOOD! */
  1068. /* Reset counters */
  1069. lasttelnets = 0;
  1070. lasttelnettime = 0;
  1071. lasttelnethost[0] = 0;
  1072. putlog(LOG_MISC, "*", IRC_TELNETFLOOD, floodhost);
  1073. addignore(floodhost, origbotname, "Telnet connection flood", now + (60 * ignore_time));
  1074. return 1;
  1075. }
  1076. return 0;
  1077. }
  1078. static void dcc_telnet_dns_callback(int, void *, const char *, char **);
  1079. static void
  1080. dcc_telnet(int idx, char *buf, int ii)
  1081. {
  1082. in_addr_t ip;
  1083. port_t port;
  1084. char s[UHOSTLEN + 1] = "";
  1085. if (dcc_total + 1 > max_dcc) {
  1086. int j;
  1087. j = answer(dcc[idx].sock, s, &ip, &port, 0);
  1088. if (j != -1) {
  1089. dprintf(-j, "Sorry, too many connections already.\r\n");
  1090. killsock(j);
  1091. }
  1092. return;
  1093. }
  1094. int sock = answer(dcc[idx].sock, s, &ip, &port, 0);
  1095. while ((sock == -1) && (errno == EAGAIN))
  1096. sock = answer(sock, s, &ip, &port, 0);
  1097. /*. ssl_link ACCEPT_SSL should go here!!!! */
  1098. if (sock < 0) {
  1099. putlog(LOG_MISC, "*", DCC_FAILED, strerror(errno));
  1100. return;
  1101. }
  1102. /* Buffer data received on this socket. */
  1103. sockoptions(sock, EGG_OPTION_SET, SOCK_BUFFER);
  1104. #if SIZEOF_SHORT == 2
  1105. if (port < 1024) {
  1106. #else
  1107. if (port < 1024 || port > 65535) {
  1108. #endif
  1109. putlog(LOG_BOTS, "*", DCC_BADSRC, s, port);
  1110. killsock(sock);
  1111. return;
  1112. }
  1113. char x[1024] = "";
  1114. int i;
  1115. putlog(LOG_DEBUG, "*", "Telnet connection: %s/%d", s, port);
  1116. sprintf(x, "-telnet!telnet@%s", iptostr(htonl(ip)));
  1117. if (match_ignore(x) || detect_telnet_flood(x)) {
  1118. killsock(sock);
  1119. return;
  1120. }
  1121. /* If a matching bot ip is found, it might still be on the ignore list as a host,
  1122. * so we'll just reverse the ip anyway and check the ignores before
  1123. * proceeding with user matching
  1124. */
  1125. i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  1126. dcc[i].addr = ip;
  1127. dcc[i].sock = sock;
  1128. dcc[i].user = get_user_by_host(x); /* check for matching -telnet!telnet@ip */
  1129. strcpy(dcc[i].host, s);
  1130. #ifdef USE_IPV6
  1131. if (sockprotocol(sock) == AF_INET6)
  1132. strcpy(dcc[i].host6, s);
  1133. #endif /* USE_IPV6 */
  1134. dcc[i].port = port;
  1135. dcc[i].timeval = now;
  1136. strcpy(dcc[i].nick, "*");
  1137. dcc[i].u.dns->ibuf = idx;
  1138. int dns_id = egg_dns_reverse(s, 20, dcc_telnet_dns_callback, (void *) i);
  1139. if (dns_id >= 0)
  1140. dcc[i].dns_id = dns_id;
  1141. }
  1142. static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, char **hosts)
  1143. {
  1144. int i = (int) client_data;
  1145. if (!valid_dns_id(i, id))
  1146. return;
  1147. int j = -1, sock, idx = -1;
  1148. char s2[UHOSTLEN + 20] = "";
  1149. if (valid_idx(i))
  1150. idx = dcc[i].u.dns->ibuf;
  1151. strlcpy(dcc[i].host, hosts ? hosts[0] : ip, UHOSTLEN);
  1152. sprintf(s2, "-telnet!telnet@%s", dcc[i].host);
  1153. if (match_ignore(s2)) {
  1154. killsock(dcc[i].sock);
  1155. lostdcc(i);
  1156. return;
  1157. }
  1158. if (!valid_idx(idx)) {
  1159. putlog(LOG_BOTS, "*", "Lost listening socket while resolving %s", dcc[i].host);
  1160. killsock(dcc[i].sock);
  1161. lostdcc(i);
  1162. return;
  1163. }
  1164. if (dcc[idx].host[0] == '@') {
  1165. /* Restrict by hostname */
  1166. if (!wild_match(dcc[idx].host + 1, dcc[i].host)) {
  1167. putlog(LOG_BOTS, "*", DCC_BADHOST, dcc[i].host);
  1168. killsock(dcc[i].sock);
  1169. lostdcc(i);
  1170. return;
  1171. }
  1172. }
  1173. /* . ssl_link(dcc[i].sock, ACCEPT_SSL); */
  1174. changeover_dcc(i, &DCC_IDENTWAIT, 0);
  1175. dcc[i].timeval = now;
  1176. dcc[i].u.ident_sock = dcc[idx].sock;
  1177. if (!dcc[i].user)
  1178. dcc[i].user = get_user_by_host(s2); /* check for matching -telnet!telnet@host */
  1179. if (hosts)
  1180. putlog(LOG_MISC, "*", "Telnet connection: %s[%s]/%d", dcc[i].host, ip, dcc[i].port);
  1181. else
  1182. putlog(LOG_MISC, "*", "Telnet connection: %s/%d", dcc[i].host, dcc[i].port);
  1183. sock = open_telnet((char *) ip, 113);
  1184. char s[UHOSTLEN] = "";
  1185. if (sock < 0) {
  1186. if (sock == -2)
  1187. strcpy(s, "DNS lookup failed for ident");
  1188. else
  1189. strcpy(s, strerror(errno));
  1190. } else {
  1191. j = new_dcc(&DCC_IDENT, 0);
  1192. if (j < 0) {
  1193. killsock(sock);
  1194. strcpy(s, "No Free DCC's");
  1195. }
  1196. }
  1197. if (s[0]) {
  1198. putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, s);
  1199. sprintf(s, "telnet@%s", dcc[i].host);
  1200. dcc_telnet_got_ident(i, s);
  1201. return;
  1202. }
  1203. dcc[j].sock = sock;
  1204. dcc[j].port = 113;
  1205. dcc[j].addr = dcc[i].addr;
  1206. strcpy(dcc[j].host, dcc[i].host);
  1207. strcpy(dcc[j].nick, "*");
  1208. dcc[j].u.ident_sock = dcc[i].sock;
  1209. dcc[j].user = dcc[i].user;
  1210. dcc[j].timeval = now;
  1211. dprintf(j, "%d, %d\n", dcc[i].port, dcc[idx].port);
  1212. }
  1213. static void
  1214. eof_dcc_telnet(int idx)
  1215. {
  1216. putlog(LOG_MISC, "*", DCC_PORTDIE, dcc[idx].port);
  1217. killsock(dcc[idx].sock);
  1218. lostdcc(idx);
  1219. }
  1220. static void
  1221. display_telnet(int idx, char *buf)
  1222. {
  1223. sprintf(buf, "lstn %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
  1224. }
  1225. struct dcc_table DCC_TELNET = {
  1226. "TELNET",
  1227. DCT_LISTEN,
  1228. eof_dcc_telnet,
  1229. dcc_telnet,
  1230. NULL,
  1231. NULL,
  1232. display_telnet,
  1233. NULL,
  1234. NULL,
  1235. NULL
  1236. };
  1237. static void
  1238. eof_dcc_dupwait(int idx)
  1239. {
  1240. putlog(LOG_BOTS, "*", DCC_LOSTDUP, dcc[idx].host);
  1241. killsock(dcc[idx].sock);
  1242. lostdcc(idx);
  1243. }
  1244. static void
  1245. dcc_dupwait(int idx, char *buf, int i)
  1246. {
  1247. /* We just ignore any data at this point. */
  1248. return;
  1249. }
  1250. /* We now check again. If the bot is still marked as duplicate, there is no
  1251. * botnet lag we could push it on, so we just drop the connection.
  1252. */
  1253. static void
  1254. timeout_dupwait(int idx)
  1255. {
  1256. /* Still duplicate? */
  1257. if (in_chain(dcc[idx].nick)) {
  1258. char x[UHOSTLEN] = "";
  1259. egg_snprintf(x, sizeof x, "%s!%s", dcc[idx].nick, dcc[idx].host);
  1260. putlog(LOG_BOTS, "*", DCC_DUPLICATE, x);
  1261. killsock(dcc[idx].sock);
  1262. lostdcc(idx);
  1263. } else {
  1264. /* Ha! Now it's gone and we can grant this bot access. */
  1265. dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
  1266. }
  1267. }
  1268. static void
  1269. display_dupwait(int idx, char *buf)
  1270. {
  1271. sprintf(buf, "wait duplicate?");
  1272. }
  1273. static void
  1274. kill_dupwait(int idx, void *x)
  1275. {
  1276. register struct dupwait_info *p = (struct dupwait_info *) x;
  1277. if (p) {
  1278. if (p->chat && DCC_CHAT.kill)
  1279. DCC_CHAT.kill(idx, p->chat);
  1280. free(p);
  1281. }
  1282. }
  1283. struct dcc_table DCC_DUPWAIT = {
  1284. "DUPWAIT",
  1285. DCT_VALIDIDX,
  1286. eof_dcc_dupwait,
  1287. dcc_dupwait,
  1288. &dupwait_timeout,
  1289. timeout_dupwait,
  1290. display_dupwait,
  1291. kill_dupwait,
  1292. NULL,
  1293. NULL
  1294. };
  1295. /* This function is called if a bot gets removed from the list. It checks
  1296. * wether we have a pending duplicate connection for that bot and continues
  1297. * with the login in that case.
  1298. */
  1299. void
  1300. dupwait_notify(const char *who)
  1301. {
  1302. for (register int idx = 0; idx < dcc_total; idx++)
  1303. if (dcc[idx].type && (dcc[idx].type == &DCC_DUPWAIT) && !egg_strcasecmp(dcc[idx].nick, who)) {
  1304. dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
  1305. break;
  1306. }
  1307. }
  1308. static void
  1309. dcc_telnet_id(int idx, char *buf, int atr)
  1310. {
  1311. char *nick = buf;
  1312. int bot = 0;
  1313. strip_telnet(dcc[idx].sock, nick, &atr);
  1314. if (nick[0] == '-') {
  1315. nick++;
  1316. bot = 1;
  1317. }
  1318. nick[HANDLEN] = 0;
  1319. dcc[idx].user = get_user_by_handle(userlist, nick);
  1320. if (!bot && dcc[idx].user->bot) {
  1321. putlog(LOG_WARN, "*", "Refused %s (fake bot login for '%s')", dcc[idx].host, nick);
  1322. killsock(dcc[idx].sock);
  1323. lostdcc(idx);
  1324. return;
  1325. }
  1326. bool ok = 0;
  1327. if (dcc[idx].user) {
  1328. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  1329. get_user_flagrec(dcc[idx].user, &fr, NULL);
  1330. ok = 1;
  1331. if (conf.bot->hub && !glob_huba(fr))
  1332. ok = 0;
  1333. if (!conf.bot->hub) {
  1334. /* if I am a chanhub and they dont have +c then drop */
  1335. if (ischanhub() && !glob_chuba(fr))
  1336. ok = 0;
  1337. if (!ischanhub())
  1338. ok = 0;
  1339. }
  1340. if (!ok && glob_bot(fr))
  1341. ok = 1;
  1342. }
  1343. if (!ok) {
  1344. putlog(LOG_BOTS, "*", DCC_INVHANDLE, dcc[idx].host, nick);
  1345. killsock(dcc[idx].sock);
  1346. lostdcc(idx);
  1347. return;
  1348. }
  1349. correct_handle(nick);
  1350. strcpy(dcc[idx].nick, nick);
  1351. if (dcc[idx].user->bot) {
  1352. if (!egg_strcasecmp(conf.bot->nick, dcc[idx].nick)) {
  1353. putlog(LOG_BOTS, "*", DCC_MYBOTNETNICK, dcc[idx].host);
  1354. killsock(dcc[idx].sock);
  1355. lostdcc(idx);
  1356. return;
  1357. } else if (in_chain(dcc[idx].nick)) {
  1358. struct chat_info *ci = dcc[idx].u.chat;
  1359. dcc[idx].type = &DCC_DUPWAIT;
  1360. dcc[idx].u.dupwait = (struct dupwait_info *) my_calloc(1, sizeof(struct dupwait_info));
  1361. dcc[idx].u.dupwait->chat = ci;
  1362. dcc[idx].u.dupwait->atr = atr;
  1363. return;
  1364. }
  1365. }
  1366. dcc_telnet_pass(idx, atr);
  1367. }
  1368. static void
  1369. dcc_telnet_pass(int idx, int atr)
  1370. {
  1371. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  1372. get_user_flagrec(dcc[idx].user, &fr, NULL);
  1373. /* No password set? */
  1374. if (!glob_bot(fr) && (u_pass_match(dcc[idx].user, "-"))) {
  1375. dprintf(idx, "Can't telnet until you have a password set.\r\n");
  1376. putlog(LOG_MISC, "*", DCC_NOPASS, dcc[idx].nick, dcc[idx].host);
  1377. killsock(dcc[idx].sock);
  1378. lostdcc(idx);
  1379. return;
  1380. }
  1381. if (dcc[idx].type == &DCC_DUPWAIT) {
  1382. struct chat_info *ci = dcc[idx].u.dupwait->chat;
  1383. free(dcc[idx].u.dupwait);
  1384. dcc[idx].u.chat = ci;
  1385. }
  1386. dcc[idx].type = &DCC_CHAT_PASS;
  1387. dcc[idx].timeval = now;
  1388. if ((conf.bot->hub && !glob_huba(fr)) || (!conf.bot->hub && ischanhub() && !glob_chuba(fr)))
  1389. dcc[idx].status |= STAT_PARTY;
  1390. if (conf.bot->hub) {
  1391. if (glob_bot(fr)) {
  1392. /* negotiate a new linking scheme */
  1393. int i = 0;
  1394. char buf[1024] = "", rand[51] = "";
  1395. make_rand_str(rand, 50);
  1396. link_hash(idx, rand);
  1397. for (i = 0; enclink[i].name; i++)
  1398. sprintf(buf, "%s%d ", buf[0] ? buf : "", enclink[i].type);
  1399. dprintf(idx, "neg? %s %s\n", rand, buf);
  1400. } else
  1401. /* Turn off remote telnet echo (send IAC WILL ECHO). */
  1402. dprintf(idx, "\n%s" TLN_IAC_C TLN_WILL_C TLN_ECHO_C "\n", DCC_ENTERPASS);
  1403. } else
  1404. dprintf(idx, "%s\n" TLN_IAC_C TLN_WILL_C TLN_ECHO_C, response(RES_PASSWORD));
  1405. }
  1406. static void
  1407. eof_dcc_telnet_id(int idx)
  1408. {
  1409. putlog(LOG_MISC, "*", DCC_LOSTCON, dcc[idx].host, dcc[idx].port);
  1410. killsock(dcc[idx].sock);
  1411. lostdcc(idx);
  1412. }
  1413. static void
  1414. timeout_dcc_telnet_id(int idx)
  1415. {
  1416. putlog(LOG_MISC, "*", DCC_TTIMEOUT, dcc[idx].host);
  1417. killsock(dcc[idx].sock);
  1418. lostdcc(idx);
  1419. }
  1420. static void
  1421. display_dcc_telnet_id(int idx, char *buf)
  1422. {
  1423. sprintf(buf, "t-in waited %lis", now - dcc[idx].timeval);
  1424. }
  1425. struct dcc_table DCC_TELNET_ID = {
  1426. "TELNET_ID",
  1427. 0,
  1428. eof_dcc_telnet_id,
  1429. dcc_telnet_id,
  1430. &password_timeout,
  1431. timeout_dcc_telnet_id,
  1432. display_dcc_telnet_id,
  1433. kill_dcc_general,
  1434. out_dcc_general,
  1435. NULL
  1436. };
  1437. static void
  1438. dcc_socket(int idx, char *buf, int len)
  1439. {
  1440. }
  1441. static void
  1442. eof_dcc_socket(int idx)
  1443. {
  1444. killsock(dcc[idx].sock);
  1445. lostdcc(idx);
  1446. }
  1447. static void
  1448. display_dcc_socket(int idx, char *buf)
  1449. {
  1450. strcpy(buf, "sock (stranded)");
  1451. }
  1452. struct dcc_table DCC_SOCKET = {
  1453. "SOCKET",
  1454. DCT_VALIDIDX,
  1455. eof_dcc_socket,
  1456. dcc_socket,
  1457. NULL,
  1458. NULL,
  1459. display_dcc_socket,
  1460. NULL,
  1461. NULL,
  1462. NULL
  1463. };
  1464. void
  1465. dcc_identwait(int idx, char *buf, int len)
  1466. {
  1467. /* Ignore anything now */
  1468. }
  1469. void
  1470. eof_dcc_identwait(int idx)
  1471. {
  1472. putlog(LOG_MISC, "*", DCC_LOSTCONN, dcc[idx].host, dcc[idx].port);
  1473. for (int i = 0; i < dcc_total; i++)
  1474. if (dcc[i].type && (dcc[i].type == &DCC_IDENT) && (dcc[i].u.ident_sock == dcc[idx].sock)) {
  1475. killsock(dcc[i].sock); /* Cleanup ident socket */
  1476. dcc[i].u.other = 0;
  1477. lostdcc(i);
  1478. break;
  1479. }
  1480. killsock(dcc[idx].sock); /* Cleanup waiting socket */
  1481. dcc[idx].u.other = 0;
  1482. lostdcc(idx);
  1483. }
  1484. static void
  1485. display_dcc_identwait(int idx, char *buf)
  1486. {
  1487. sprintf(buf, "idtw waited %lis", now - dcc[idx].timeval);
  1488. }
  1489. struct dcc_table DCC_IDENTWAIT = {
  1490. "IDENTWAIT",
  1491. 0,
  1492. eof_dcc_identwait,
  1493. dcc_identwait,
  1494. NULL,
  1495. NULL,
  1496. display_dcc_identwait,
  1497. NULL,
  1498. NULL,
  1499. NULL
  1500. };
  1501. void
  1502. dcc_ident(int idx, char *buf, int len)
  1503. {
  1504. char ident_response[512] = "", uid[512] = "", buf1[UHOSTLEN] = "";
  1505. sscanf(buf, "%*[^:]:%[^:]:%*[^:]:%[^\n]\n", ident_response, uid);
  1506. rmspace(ident_response);
  1507. if (ident_response[0] != 'U') {
  1508. dcc[idx].timeval = now;
  1509. return;
  1510. }
  1511. rmspace(uid);
  1512. uid[20] = 0; /* 20 character ident max */
  1513. for (int i = 0; i < dcc_total; i++)
  1514. if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
  1515. simple_sprintf(buf1, "%s@%s", uid, dcc[idx].host);
  1516. dcc_telnet_got_ident(i, buf1);
  1517. }
  1518. dcc[idx].u.other = 0;
  1519. killsock(dcc[idx].sock);
  1520. lostdcc(idx);
  1521. }
  1522. void
  1523. eof_dcc_ident(int idx)
  1524. {
  1525. char buf[UHOSTLEN] = "";
  1526. for (int i = 0; i < dcc_total; i++)
  1527. if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
  1528. putlog(LOG_MISC, "*", DCC_EOFIDENT);
  1529. simple_sprintf(buf, "telnet@%s", dcc[idx].host);
  1530. dcc_telnet_got_ident(i, buf);
  1531. }
  1532. killsock(dcc[idx].sock);
  1533. dcc[idx].u.other = 0;
  1534. lostdcc(idx);
  1535. }
  1536. static void
  1537. display_dcc_ident(int idx, char *buf)
  1538. {
  1539. sprintf(buf, "idnt (sock %d)", dcc[idx].u.ident_sock);
  1540. }
  1541. struct dcc_table DCC_IDENT = {
  1542. "IDENT",
  1543. 0,
  1544. eof_dcc_ident,
  1545. dcc_ident,
  1546. &identtimeout,
  1547. eof_dcc_ident,
  1548. display_dcc_ident,
  1549. NULL,
  1550. NULL,
  1551. NULL
  1552. };
  1553. static void
  1554. dcc_telnet_got_ident(int i, char *host)
  1555. {
  1556. int idx;
  1557. for (idx = 0; idx < dcc_total; idx++)
  1558. if (dcc[i].type && (dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.ident_sock))
  1559. break;
  1560. dcc[i].u.other = 0;
  1561. if (idx == dcc_total || !dcc[idx].type) {
  1562. putlog(LOG_MISC, "*", DCC_LOSTIDENT);
  1563. killsock(dcc[i].sock);
  1564. lostdcc(i);
  1565. return;
  1566. }
  1567. strlcpy(dcc[i].host, host, UHOSTLEN);
  1568. char shost[UHOSTLEN + 20] = "", sip[UHOSTLEN + 20] = "";
  1569. char *p = strchr(host, '@');
  1570. *p = 0;
  1571. egg_snprintf(shost, sizeof(shost), "-telnet!%s", dcc[i].host);
  1572. egg_snprintf(sip, sizeof(sip), "-telnet!%s@%s", host, iptostr(htonl(dcc[i].addr)));
  1573. if (match_ignore(shost) || match_ignore(sip)) {
  1574. killsock(dcc[i].sock);
  1575. lostdcc(i);
  1576. return;
  1577. }
  1578. if (protect_telnet) {
  1579. struct userrec *u = NULL;
  1580. bool ok = 1;
  1581. u = dcc[i].user;
  1582. if (!u)
  1583. u = get_user_by_host(sip); /* Check for -telnet!ident@ip */
  1584. if (!u)
  1585. u = get_user_by_host(shost); /* Check for -telnet!ident@host */
  1586. if (!u)
  1587. ok = 0;
  1588. if (ok && u && conf.bot->hub && !(u->flags & USER_HUBA))
  1589. ok = 0;
  1590. /* if I am a chanhub and they dont have +c then drop */
  1591. if (ok && (!conf.bot->hub && ischanhub() && u && !(u->flags & USER_CHUBA)))
  1592. ok = 0;
  1593. /* else if (!(u->flags & USER_PARTY))
  1594. ok = 0; */
  1595. if (!ok && u && u->bot)
  1596. ok = 1;
  1597. if (!ok && (dcc[idx].status & LSTN_PUBLIC))
  1598. ok = 1;
  1599. if (!ok) {
  1600. putlog(LOG_MISC, "*", DCC_NOACCESS, dcc[i].host);
  1601. killsock(dcc[i].sock);
  1602. lostdcc(i);
  1603. return;
  1604. }
  1605. }
  1606. /* Do not buffer data anymore. All received and stored data is passed
  1607. * over to the dcc functions from now on. */
  1608. sockoptions(dcc[i].sock, EGG_OPTION_UNSET, SOCK_BUFFER);
  1609. dcc[i].type = &DCC_TELNET_ID;
  1610. dcc[i].u.chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
  1611. egg_bzero(dcc[i].u.chat, sizeof(struct chat_info));
  1612. /* Copy acceptable-nick/host mask */
  1613. dcc[i].status = (STAT_TELNET | STAT_ECHO | STAT_COLOR | STAT_BANNER | STAT_CHANNELS | STAT_BOTS | STAT_WHOM);
  1614. /* Copy acceptable-nick/host mask */
  1615. strlcpy(dcc[i].nick, dcc[idx].host, HANDLEN);
  1616. dcc[i].timeval = now;
  1617. strcpy(dcc[i].u.chat->con_chan, chanset ? chanset->dname : "*");
  1618. /* This is so we dont tell someone doing a portscan anything
  1619. * about ourselves. <cybah>
  1620. */
  1621. /* n ssl_link(dcc[i].sock, ACCEPT_SSL); */
  1622. if (conf.bot->hub)
  1623. dprintf(i, " \n"); /* represents hub that support new linking scheme */
  1624. else
  1625. dprintf(i, "%s\n", response(RES_USERNAME));
  1626. }