dcc.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  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 (have_cmd(C_bot[i].type))
  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(dcc[idx].user, randstr, dcc[idx].hash, sizeof(dcc[idx].hash));
  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(dcc[idx].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. // killsock(dcc[idx].sock);
  1101. return;
  1102. }
  1103. /* Buffer data received on this socket. */
  1104. sockoptions(sock, EGG_OPTION_SET, SOCK_BUFFER);
  1105. #if SIZEOF_SHORT == 2
  1106. if (port < 1024) {
  1107. #else
  1108. if (port < 1024 || port > 65535) {
  1109. #endif
  1110. putlog(LOG_BOTS, "*", DCC_BADSRC, s, port);
  1111. killsock(sock);
  1112. return;
  1113. }
  1114. char x[1024] = "";
  1115. int i;
  1116. putlog(LOG_DEBUG, "*", "Telnet connection: %s/%d", s, port);
  1117. sprintf(x, "-telnet!telnet@%s", iptostr(htonl(ip)));
  1118. if (match_ignore(x) || detect_telnet_flood(x)) {
  1119. killsock(sock);
  1120. return;
  1121. }
  1122. /* If a matching bot ip is found, it might still be on the ignore list as a host,
  1123. * so we'll just reverse the ip anyway and check the ignores before
  1124. * proceeding with user matching
  1125. */
  1126. i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
  1127. dcc[i].addr = ip;
  1128. dcc[i].sock = sock;
  1129. dcc[i].user = get_user_by_host(x); /* check for matching -telnet!telnet@ip */
  1130. strcpy(dcc[i].host, s);
  1131. #ifdef USE_IPV6
  1132. if (sockprotocol(sock) == AF_INET6)
  1133. strcpy(dcc[i].host6, s);
  1134. #endif /* USE_IPV6 */
  1135. dcc[i].port = port;
  1136. dcc[i].timeval = now;
  1137. strcpy(dcc[i].nick, "*");
  1138. dcc[i].u.dns->ibuf = idx;
  1139. int dns_id = egg_dns_reverse(s, 20, dcc_telnet_dns_callback, (void *) i);
  1140. if (dns_id >= 0)
  1141. dcc[i].dns_id = dns_id;
  1142. }
  1143. static void dcc_telnet_dns_callback(int id, void *client_data, const char *ip, char **hosts)
  1144. {
  1145. int i = (int) client_data;
  1146. if (!valid_dns_id(i, id))
  1147. return;
  1148. int j = -1, sock, idx = -1;
  1149. char s2[UHOSTLEN + 20] = "";
  1150. if (valid_idx(i))
  1151. idx = dcc[i].u.dns->ibuf;
  1152. strlcpy(dcc[i].host, hosts ? hosts[0] : ip, UHOSTLEN);
  1153. sprintf(s2, "-telnet!telnet@%s", dcc[i].host);
  1154. if (match_ignore(s2)) {
  1155. killsock(dcc[i].sock);
  1156. lostdcc(i);
  1157. return;
  1158. }
  1159. if (!valid_idx(idx)) {
  1160. putlog(LOG_BOTS, "*", "Lost listening socket while resolving %s", dcc[i].host);
  1161. killsock(dcc[i].sock);
  1162. lostdcc(i);
  1163. return;
  1164. }
  1165. if (dcc[idx].host[0] == '@') {
  1166. /* Restrict by hostname */
  1167. if (!wild_match(dcc[idx].host + 1, dcc[i].host)) {
  1168. putlog(LOG_BOTS, "*", DCC_BADHOST, dcc[i].host);
  1169. killsock(dcc[i].sock);
  1170. lostdcc(i);
  1171. return;
  1172. }
  1173. }
  1174. /* . ssl_link(dcc[i].sock, ACCEPT_SSL); */
  1175. changeover_dcc(i, &DCC_IDENTWAIT, 0);
  1176. dcc[i].timeval = now;
  1177. dcc[i].u.ident_sock = dcc[idx].sock;
  1178. if (!dcc[i].user)
  1179. dcc[i].user = get_user_by_host(s2); /* check for matching -telnet!telnet@host */
  1180. if (hosts)
  1181. putlog(LOG_MISC, "*", "Telnet connection: %s[%s]/%d", dcc[i].host, ip, dcc[i].port);
  1182. else
  1183. putlog(LOG_MISC, "*", "Telnet connection: %s/%d", dcc[i].host, dcc[i].port);
  1184. sock = open_telnet((char *) ip, 113);
  1185. char s[UHOSTLEN] = "";
  1186. if (sock < 0) {
  1187. if (sock == -2)
  1188. strcpy(s, "DNS lookup failed for ident");
  1189. else
  1190. strcpy(s, strerror(errno));
  1191. } else {
  1192. j = new_dcc(&DCC_IDENT, 0);
  1193. if (j < 0) {
  1194. killsock(sock);
  1195. strcpy(s, "No Free DCC's");
  1196. }
  1197. }
  1198. if (s[0]) {
  1199. putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, s);
  1200. sprintf(s, "telnet@%s", dcc[i].host);
  1201. dcc_telnet_got_ident(i, s);
  1202. return;
  1203. }
  1204. dcc[j].sock = sock;
  1205. dcc[j].port = 113;
  1206. dcc[j].addr = dcc[i].addr;
  1207. strcpy(dcc[j].host, dcc[i].host);
  1208. strcpy(dcc[j].nick, "*");
  1209. dcc[j].u.ident_sock = dcc[i].sock;
  1210. dcc[j].user = dcc[i].user;
  1211. dcc[j].timeval = now;
  1212. dprintf(j, "%d, %d\n", dcc[i].port, dcc[idx].port);
  1213. }
  1214. static void
  1215. eof_dcc_telnet(int idx)
  1216. {
  1217. putlog(LOG_MISC, "*", DCC_PORTDIE, dcc[idx].port);
  1218. killsock(dcc[idx].sock);
  1219. lostdcc(idx);
  1220. }
  1221. static void
  1222. display_telnet(int idx, char *buf)
  1223. {
  1224. sprintf(buf, "lstn %d%s", dcc[idx].port, (dcc[idx].status & LSTN_PUBLIC) ? " pub" : "");
  1225. }
  1226. struct dcc_table DCC_TELNET = {
  1227. "TELNET",
  1228. DCT_LISTEN,
  1229. eof_dcc_telnet,
  1230. dcc_telnet,
  1231. NULL,
  1232. NULL,
  1233. display_telnet,
  1234. NULL,
  1235. NULL,
  1236. NULL
  1237. };
  1238. static void
  1239. eof_dcc_dupwait(int idx)
  1240. {
  1241. putlog(LOG_BOTS, "*", DCC_LOSTDUP, dcc[idx].host);
  1242. killsock(dcc[idx].sock);
  1243. lostdcc(idx);
  1244. }
  1245. static void
  1246. dcc_dupwait(int idx, char *buf, int i)
  1247. {
  1248. /* We just ignore any data at this point. */
  1249. return;
  1250. }
  1251. /* We now check again. If the bot is still marked as duplicate, there is no
  1252. * botnet lag we could push it on, so we just drop the connection.
  1253. */
  1254. static void
  1255. timeout_dupwait(int idx)
  1256. {
  1257. /* Still duplicate? */
  1258. if (in_chain(dcc[idx].nick)) {
  1259. char x[UHOSTLEN] = "";
  1260. egg_snprintf(x, sizeof x, "%s!%s", dcc[idx].nick, dcc[idx].host);
  1261. putlog(LOG_BOTS, "*", DCC_DUPLICATE, x);
  1262. killsock(dcc[idx].sock);
  1263. lostdcc(idx);
  1264. } else {
  1265. /* Ha! Now it's gone and we can grant this bot access. */
  1266. dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
  1267. }
  1268. }
  1269. static void
  1270. display_dupwait(int idx, char *buf)
  1271. {
  1272. sprintf(buf, "wait duplicate?");
  1273. }
  1274. static void
  1275. kill_dupwait(int idx, void *x)
  1276. {
  1277. register struct dupwait_info *p = (struct dupwait_info *) x;
  1278. if (p) {
  1279. if (p->chat && DCC_CHAT.kill)
  1280. DCC_CHAT.kill(idx, p->chat);
  1281. free(p);
  1282. }
  1283. }
  1284. struct dcc_table DCC_DUPWAIT = {
  1285. "DUPWAIT",
  1286. DCT_VALIDIDX,
  1287. eof_dcc_dupwait,
  1288. dcc_dupwait,
  1289. &dupwait_timeout,
  1290. timeout_dupwait,
  1291. display_dupwait,
  1292. kill_dupwait,
  1293. NULL,
  1294. NULL
  1295. };
  1296. /* This function is called if a bot gets removed from the list. It checks
  1297. * wether we have a pending duplicate connection for that bot and continues
  1298. * with the login in that case.
  1299. */
  1300. void
  1301. dupwait_notify(const char *who)
  1302. {
  1303. for (register int idx = 0; idx < dcc_total; idx++)
  1304. if (dcc[idx].type && (dcc[idx].type == &DCC_DUPWAIT) && !egg_strcasecmp(dcc[idx].nick, who)) {
  1305. dcc_telnet_pass(idx, dcc[idx].u.dupwait->atr);
  1306. break;
  1307. }
  1308. }
  1309. static void
  1310. dcc_telnet_id(int idx, char *buf, int atr)
  1311. {
  1312. char *nick = buf;
  1313. int bot = 0;
  1314. strip_telnet(dcc[idx].sock, nick, &atr);
  1315. if (nick[0] == '-') {
  1316. nick++;
  1317. bot = 1;
  1318. }
  1319. nick[HANDLEN] = 0;
  1320. dcc[idx].user = get_user_by_handle(userlist, nick);
  1321. if (!bot && dcc[idx].user->bot) {
  1322. putlog(LOG_WARN, "*", "Refused %s (fake bot login for '%s')", dcc[idx].host, nick);
  1323. killsock(dcc[idx].sock);
  1324. lostdcc(idx);
  1325. return;
  1326. }
  1327. bool ok = 0;
  1328. if (dcc[idx].user) {
  1329. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  1330. get_user_flagrec(dcc[idx].user, &fr, NULL);
  1331. ok = 1;
  1332. if (conf.bot->hub && !glob_huba(fr))
  1333. ok = 0;
  1334. if (!conf.bot->hub) {
  1335. /* if I am a chanhub and they dont have +c then drop */
  1336. if (ischanhub() && !glob_chuba(fr))
  1337. ok = 0;
  1338. if (!ischanhub())
  1339. ok = 0;
  1340. }
  1341. if (!ok && glob_bot(fr))
  1342. ok = 1;
  1343. }
  1344. if (!ok) {
  1345. putlog(LOG_BOTS, "*", DCC_INVHANDLE, dcc[idx].host, nick);
  1346. killsock(dcc[idx].sock);
  1347. lostdcc(idx);
  1348. return;
  1349. }
  1350. correct_handle(nick);
  1351. strcpy(dcc[idx].nick, nick);
  1352. if (dcc[idx].user->bot) {
  1353. if (!egg_strcasecmp(conf.bot->nick, dcc[idx].nick)) {
  1354. putlog(LOG_BOTS, "*", DCC_MYBOTNETNICK, dcc[idx].host);
  1355. killsock(dcc[idx].sock);
  1356. lostdcc(idx);
  1357. return;
  1358. } else if (in_chain(dcc[idx].nick)) {
  1359. struct chat_info *ci = dcc[idx].u.chat;
  1360. dcc[idx].type = &DCC_DUPWAIT;
  1361. dcc[idx].u.dupwait = (struct dupwait_info *) my_calloc(1, sizeof(struct dupwait_info));
  1362. dcc[idx].u.dupwait->chat = ci;
  1363. dcc[idx].u.dupwait->atr = atr;
  1364. return;
  1365. }
  1366. }
  1367. dcc_telnet_pass(idx, atr);
  1368. }
  1369. static void
  1370. dcc_telnet_pass(int idx, int atr)
  1371. {
  1372. struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
  1373. get_user_flagrec(dcc[idx].user, &fr, NULL);
  1374. /* No password set? */
  1375. if (!glob_bot(fr) && (u_pass_match(dcc[idx].user, "-"))) {
  1376. dprintf(idx, "Can't telnet until you have a password set.\r\n");
  1377. putlog(LOG_MISC, "*", DCC_NOPASS, dcc[idx].nick, dcc[idx].host);
  1378. killsock(dcc[idx].sock);
  1379. lostdcc(idx);
  1380. return;
  1381. }
  1382. if (dcc[idx].type == &DCC_DUPWAIT) {
  1383. struct chat_info *ci = dcc[idx].u.dupwait->chat;
  1384. free(dcc[idx].u.dupwait);
  1385. dcc[idx].u.chat = ci;
  1386. }
  1387. dcc[idx].type = &DCC_CHAT_PASS;
  1388. dcc[idx].timeval = now;
  1389. if ((conf.bot->hub && !glob_huba(fr)) || (!conf.bot->hub && ischanhub() && !glob_chuba(fr)))
  1390. dcc[idx].status |= STAT_PARTY;
  1391. if (conf.bot->hub) {
  1392. if (glob_bot(fr)) {
  1393. /* negotiate a new linking scheme */
  1394. int i = 0;
  1395. char buf[1024] = "", rand[51] = "";
  1396. make_rand_str(rand, 50);
  1397. link_hash(idx, rand);
  1398. for (i = 0; enclink[i].name; i++)
  1399. sprintf(buf, "%s%d ", buf[0] ? buf : "", enclink[i].type);
  1400. dprintf(idx, "neg? %s %s\n", rand, buf);
  1401. } else
  1402. /* Turn off remote telnet echo (send IAC WILL ECHO). */
  1403. dprintf(idx, "\n%s" TLN_IAC_C TLN_WILL_C TLN_ECHO_C "\n", DCC_ENTERPASS);
  1404. } else
  1405. dprintf(idx, "%s\n" TLN_IAC_C TLN_WILL_C TLN_ECHO_C, response(RES_PASSWORD));
  1406. }
  1407. static void
  1408. eof_dcc_telnet_id(int idx)
  1409. {
  1410. putlog(LOG_MISC, "*", DCC_LOSTCON, dcc[idx].host, dcc[idx].port);
  1411. killsock(dcc[idx].sock);
  1412. lostdcc(idx);
  1413. }
  1414. static void
  1415. timeout_dcc_telnet_id(int idx)
  1416. {
  1417. putlog(LOG_MISC, "*", DCC_TTIMEOUT, dcc[idx].host);
  1418. killsock(dcc[idx].sock);
  1419. lostdcc(idx);
  1420. }
  1421. static void
  1422. display_dcc_telnet_id(int idx, char *buf)
  1423. {
  1424. sprintf(buf, "t-in waited %lis", now - dcc[idx].timeval);
  1425. }
  1426. struct dcc_table DCC_TELNET_ID = {
  1427. "TELNET_ID",
  1428. 0,
  1429. eof_dcc_telnet_id,
  1430. dcc_telnet_id,
  1431. &password_timeout,
  1432. timeout_dcc_telnet_id,
  1433. display_dcc_telnet_id,
  1434. kill_dcc_general,
  1435. out_dcc_general,
  1436. NULL
  1437. };
  1438. static void
  1439. dcc_socket(int idx, char *buf, int len)
  1440. {
  1441. }
  1442. static void
  1443. eof_dcc_socket(int idx)
  1444. {
  1445. killsock(dcc[idx].sock);
  1446. lostdcc(idx);
  1447. }
  1448. static void
  1449. display_dcc_socket(int idx, char *buf)
  1450. {
  1451. strcpy(buf, "sock (stranded)");
  1452. }
  1453. struct dcc_table DCC_SOCKET = {
  1454. "SOCKET",
  1455. DCT_VALIDIDX,
  1456. eof_dcc_socket,
  1457. dcc_socket,
  1458. NULL,
  1459. NULL,
  1460. display_dcc_socket,
  1461. NULL,
  1462. NULL,
  1463. NULL
  1464. };
  1465. void
  1466. dcc_identwait(int idx, char *buf, int len)
  1467. {
  1468. /* Ignore anything now */
  1469. }
  1470. void
  1471. eof_dcc_identwait(int idx)
  1472. {
  1473. putlog(LOG_MISC, "*", DCC_LOSTCONN, dcc[idx].host, dcc[idx].port);
  1474. for (int i = 0; i < dcc_total; i++)
  1475. if (dcc[i].type && (dcc[i].type == &DCC_IDENT) && (dcc[i].u.ident_sock == dcc[idx].sock)) {
  1476. killsock(dcc[i].sock); /* Cleanup ident socket */
  1477. dcc[i].u.other = 0;
  1478. lostdcc(i);
  1479. break;
  1480. }
  1481. killsock(dcc[idx].sock); /* Cleanup waiting socket */
  1482. dcc[idx].u.other = 0;
  1483. lostdcc(idx);
  1484. }
  1485. static void
  1486. display_dcc_identwait(int idx, char *buf)
  1487. {
  1488. sprintf(buf, "idtw waited %lis", now - dcc[idx].timeval);
  1489. }
  1490. struct dcc_table DCC_IDENTWAIT = {
  1491. "IDENTWAIT",
  1492. 0,
  1493. eof_dcc_identwait,
  1494. dcc_identwait,
  1495. NULL,
  1496. NULL,
  1497. display_dcc_identwait,
  1498. NULL,
  1499. NULL,
  1500. NULL
  1501. };
  1502. void
  1503. dcc_ident(int idx, char *buf, int len)
  1504. {
  1505. char ident_response[512] = "", uid[512] = "", buf1[UHOSTLEN] = "";
  1506. sscanf(buf, "%*[^:]:%[^:]:%*[^:]:%[^\n]\n", ident_response, uid);
  1507. rmspace(ident_response);
  1508. if (ident_response[0] != 'U') {
  1509. dcc[idx].timeval = now;
  1510. return;
  1511. }
  1512. rmspace(uid);
  1513. uid[20] = 0; /* 20 character ident max */
  1514. for (int i = 0; i < dcc_total; i++)
  1515. if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
  1516. simple_sprintf(buf1, "%s@%s", uid, dcc[idx].host);
  1517. dcc_telnet_got_ident(i, buf1);
  1518. }
  1519. dcc[idx].u.other = 0;
  1520. killsock(dcc[idx].sock);
  1521. lostdcc(idx);
  1522. }
  1523. void
  1524. eof_dcc_ident(int idx)
  1525. {
  1526. char buf[UHOSTLEN] = "";
  1527. for (int i = 0; i < dcc_total; i++)
  1528. if (dcc[i].type && (dcc[i].type == &DCC_IDENTWAIT) && (dcc[i].sock == dcc[idx].u.ident_sock)) {
  1529. putlog(LOG_MISC, "*", DCC_EOFIDENT);
  1530. simple_sprintf(buf, "telnet@%s", dcc[idx].host);
  1531. dcc_telnet_got_ident(i, buf);
  1532. }
  1533. killsock(dcc[idx].sock);
  1534. dcc[idx].u.other = 0;
  1535. lostdcc(idx);
  1536. }
  1537. static void
  1538. display_dcc_ident(int idx, char *buf)
  1539. {
  1540. sprintf(buf, "idnt (sock %d)", dcc[idx].u.ident_sock);
  1541. }
  1542. struct dcc_table DCC_IDENT = {
  1543. "IDENT",
  1544. 0,
  1545. eof_dcc_ident,
  1546. dcc_ident,
  1547. &identtimeout,
  1548. eof_dcc_ident,
  1549. display_dcc_ident,
  1550. NULL,
  1551. NULL,
  1552. NULL
  1553. };
  1554. static void
  1555. dcc_telnet_got_ident(int i, char *host)
  1556. {
  1557. int idx;
  1558. for (idx = 0; idx < dcc_total; idx++)
  1559. if (dcc[i].type && (dcc[idx].type == &DCC_TELNET) && (dcc[idx].sock == dcc[i].u.ident_sock))
  1560. break;
  1561. dcc[i].u.other = 0;
  1562. if (idx == dcc_total || !dcc[idx].type) {
  1563. putlog(LOG_MISC, "*", DCC_LOSTIDENT);
  1564. killsock(dcc[i].sock);
  1565. lostdcc(i);
  1566. return;
  1567. }
  1568. strlcpy(dcc[i].host, host, UHOSTLEN);
  1569. char shost[UHOSTLEN + 20] = "", sip[UHOSTLEN + 20] = "";
  1570. char *p = strchr(host, '@');
  1571. *p = 0;
  1572. egg_snprintf(shost, sizeof(shost), "-telnet!%s", dcc[i].host);
  1573. egg_snprintf(sip, sizeof(sip), "-telnet!%s@%s", host, iptostr(htonl(dcc[i].addr)));
  1574. if (match_ignore(shost) || match_ignore(sip)) {
  1575. killsock(dcc[i].sock);
  1576. lostdcc(i);
  1577. return;
  1578. }
  1579. if (protect_telnet) {
  1580. struct userrec *u = NULL;
  1581. bool ok = 1;
  1582. u = dcc[i].user;
  1583. if (!u)
  1584. u = get_user_by_host(sip); /* Check for -telnet!ident@ip */
  1585. if (!u)
  1586. u = get_user_by_host(shost); /* Check for -telnet!ident@host */
  1587. if (!u)
  1588. ok = 0;
  1589. if (ok && u && conf.bot->hub && !(u->flags & USER_HUBA))
  1590. ok = 0;
  1591. /* if I am a chanhub and they dont have +c then drop */
  1592. if (ok && (!conf.bot->hub && ischanhub() && u && !(u->flags & USER_CHUBA)))
  1593. ok = 0;
  1594. /* else if (!(u->flags & USER_PARTY))
  1595. ok = 0; */
  1596. if (!ok && u && u->bot)
  1597. ok = 1;
  1598. if (!ok && (dcc[idx].status & LSTN_PUBLIC))
  1599. ok = 1;
  1600. if (!ok) {
  1601. putlog(LOG_MISC, "*", DCC_NOACCESS, dcc[i].host);
  1602. killsock(dcc[i].sock);
  1603. lostdcc(i);
  1604. return;
  1605. }
  1606. }
  1607. /* Do not buffer data anymore. All received and stored data is passed
  1608. * over to the dcc functions from now on. */
  1609. sockoptions(dcc[i].sock, EGG_OPTION_UNSET, SOCK_BUFFER);
  1610. dcc[i].type = &DCC_TELNET_ID;
  1611. dcc[i].u.chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
  1612. egg_bzero(dcc[i].u.chat, sizeof(struct chat_info));
  1613. /* Copy acceptable-nick/host mask */
  1614. dcc[i].status = (STAT_TELNET | STAT_ECHO | STAT_COLOR | STAT_BANNER | STAT_CHANNELS | STAT_BOTS | STAT_WHOM);
  1615. /* Copy acceptable-nick/host mask */
  1616. strlcpy(dcc[i].nick, dcc[idx].host, HANDLEN);
  1617. dcc[i].timeval = now;
  1618. strcpy(dcc[i].u.chat->con_chan, chanset ? chanset->dname : "*");
  1619. /* This is so we dont tell someone doing a portscan anything
  1620. * about ourselves. <cybah>
  1621. */
  1622. /* n ssl_link(dcc[i].sock, ACCEPT_SSL); */
  1623. if (conf.bot->hub)
  1624. dprintf(i, " \n"); /* represents hub that support new linking scheme */
  1625. else
  1626. dprintf(i, "%s\n", response(RES_USERNAME));
  1627. }