1
0

modules.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  1. /*
  2. * modules.c -- handles:
  3. * support for modules in eggdrop
  4. *
  5. * by Darrin Smith (beldin@light.iinet.net.au)
  6. *
  7. */
  8. #include "main.h"
  9. #include "modules.h"
  10. #include "tandem.h"
  11. #include <ctype.h>
  12. extern struct dcc_t *dcc;
  13. #ifdef S_AUTH
  14. extern struct auth_t *auth;
  15. #endif /* S_AUTH */
  16. #include "users.h"
  17. extern Tcl_Interp *interp;
  18. extern struct userrec *userlist, *lastuser;
  19. extern char tempdir[], botnetnick[], botname[], natip[], cmdprefix[],
  20. hostname[], origbotname[], botuser[], admin[],
  21. userfile[], ver[], notify_new[], kickprefix[], bankickprefix[],
  22. version[], quit_msg[], hostname6[], netpass[], thepass[], dcc_prefix[],
  23. #ifdef S_AUTH
  24. authkey[],
  25. #endif /* S_AUTH */
  26. myip[], myip6[];
  27. extern int noshare, loading, role,
  28. #ifdef S_AUTH
  29. auth_total,
  30. #endif /* S_AUTH */
  31. dcc_total, egg_numver, userfile_perm,
  32. use_console_r, ignore_time, must_be_owner,
  33. debug_output, default_flags, norestruct,
  34. max_dcc, share_greet, password_timeout, localhub,
  35. #ifdef S_IRCNET
  36. use_invites, use_exempts,
  37. #endif
  38. force_expire, do_restart, timesync,
  39. protect_readonly, reserved_port_min, reserved_port_max;
  40. extern time_t now, online_since;
  41. extern struct chanset_t *chanset;
  42. extern tand_t *tandbot;
  43. extern party_t *party;
  44. extern int parties;
  45. extern sock_list *socklist;
  46. int xtra_kill();
  47. int xtra_unpack();
  48. static int module_rename(char *name, char *newname);
  49. struct static_list {
  50. struct static_list *next;
  51. char *name;
  52. char *(*func) ();
  53. } *static_modules = NULL;
  54. void check_static(char *name, char *(*func) ())
  55. {
  56. struct static_list *p = nmalloc(sizeof(struct static_list));
  57. p->name = nmalloc(strlen(name) + 1);
  58. strcpy(p->name, name);
  59. p->func = func;
  60. p->next = static_modules;
  61. static_modules = p;
  62. }
  63. void *mod_killsock(int size, const char *modname, const char *filename, int line)
  64. {
  65. #ifdef DEBUG_MEM
  66. char x[100], *p;
  67. p = strrchr(filename, '/');
  68. egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
  69. x[19] = 0;
  70. real_killsock(size, x, line);
  71. #else
  72. killsock(size);
  73. #endif
  74. return NULL;
  75. }
  76. /* The null functions */
  77. void null_func()
  78. {
  79. }
  80. char *charp_func()
  81. {
  82. return NULL;
  83. }
  84. int minus_func()
  85. {
  86. return -1;
  87. }
  88. int false_func()
  89. {
  90. return 0;
  91. }
  92. /*
  93. * Various hooks & things
  94. */
  95. /* The REAL hooks, when these are called, a return of 0 indicates unhandled
  96. * 1 is handled
  97. */
  98. struct hook_entry *hook_list[REAL_HOOKS];
  99. static void null_share(int idx, char *x)
  100. {
  101. if ((x[0] == 'u') && (x[1] == 'n')) {
  102. putlog(LOG_BOTS, "*", "User file rejected by %s: %s",
  103. dcc[idx].nick, x + 3);
  104. dcc[idx].status &= ~STAT_OFFERED;
  105. if (!(dcc[idx].status & STAT_GETTING)) {
  106. dcc[idx].status &= ~STAT_SHARE;
  107. }
  108. } else if ((x[0] != 'v') && (x[0] != 'e'))
  109. dprintf(idx, "s un Not sharing userfile.\n");
  110. }
  111. void (*encrypt_pass) (char *, char *) = 0;
  112. char *(*encrypt_string) (char *, char *) = 0;
  113. char *(*decrypt_string) (char *, char *) = 0;
  114. void (*shareout) () = null_func;
  115. void (*sharein) (int, char *) = null_share;
  116. void (*shareupdatein) (int, char *) = null_share;
  117. void (*qserver) (int, char *, int) = (void (*)(int, char *, int)) null_func;
  118. void (*add_mode) () = null_func;
  119. int (*match_noterej) (struct userrec *, char *) = (int (*)(struct userrec *, char *)) false_func;
  120. int (*rfc_casecmp) (const char *, const char *) = _rfc_casecmp;
  121. int (*rfc_ncasecmp) (const char *, const char *, int) = _rfc_ncasecmp;
  122. int (*rfc_toupper) (int) = _rfc_toupper;
  123. int (*rfc_tolower) (int) = _rfc_tolower;
  124. void (*dns_hostbyip) (IP) = block_dns_hostbyip;
  125. void (*dns_ipbyhost) (char *) = block_dns_ipbyhost;
  126. module_entry *module_list;
  127. dependancy *dependancy_list = NULL;
  128. /* The horrible global lookup table for functions
  129. * BUT it makes the whole thing *much* more portable than letting each
  130. * OS screw up the symbols their own special way :/
  131. */
  132. Function global_table[] =
  133. {
  134. /* 0 - 3 */
  135. (Function) mod_malloc,
  136. (Function) mod_free,
  137. #ifdef DEBUG_CONTEXT
  138. (Function) eggContext,
  139. #else
  140. (Function) 0,
  141. #endif
  142. (Function) module_rename,
  143. /* 4 - 7 */
  144. (Function) module_register,
  145. (Function) module_find,
  146. (Function) module_depend,
  147. (Function) module_undepend,
  148. /* 8 - 11 */
  149. (Function) add_bind_table,
  150. (Function) del_bind_table,
  151. (Function) find_bind_table,
  152. (Function) check_tcl_bind,
  153. /* 12 - 15 */
  154. (Function) add_builtins,
  155. (Function) rem_builtins,
  156. (Function) add_tcl_commands,
  157. (Function) rem_tcl_commands,
  158. /* 16 - 19 */
  159. (Function) add_tcl_ints,
  160. (Function) rem_tcl_ints,
  161. (Function) add_tcl_strings,
  162. (Function) rem_tcl_strings,
  163. /* 20 - 23 */
  164. (Function) base64_to_int,
  165. (Function) int_to_base64,
  166. (Function) int_to_base10,
  167. (Function) simple_sprintf,
  168. /* 24 - 27 */
  169. (Function) botnet_send_zapf,
  170. (Function) botnet_send_zapf_broad,
  171. (Function) botnet_send_unlinked,
  172. (Function) botnet_send_bye,
  173. /* 28 - 31 */
  174. (Function) botnet_send_chat,
  175. (Function) botnet_send_filereject,
  176. (Function) botnet_send_filesend,
  177. (Function) botnet_send_filereq,
  178. /* 32 - 35 */
  179. (Function) botnet_send_join_idx,
  180. (Function) botnet_send_part_idx,
  181. (Function) updatebot,
  182. (Function) nextbot,
  183. /* 36 - 39 */
  184. (Function) zapfbot,
  185. (Function) n_free,
  186. (Function) u_pass_match,
  187. (Function) _user_malloc,
  188. /* 40 - 43 */
  189. (Function) get_user,
  190. (Function) set_user,
  191. (Function) add_entry_type,
  192. (Function) del_entry_type,
  193. /* 44 - 47 */
  194. (Function) get_user_flagrec,
  195. (Function) set_user_flagrec,
  196. (Function) get_user_by_host,
  197. (Function) get_user_by_handle,
  198. /* 48 - 51 */
  199. (Function) find_entry_type,
  200. (Function) find_user_entry,
  201. (Function) adduser,
  202. (Function) deluser,
  203. /* 52 - 55 */
  204. (Function) addhost_by_handle,
  205. (Function) delhost_by_handle,
  206. (Function) readuserfile,
  207. (Function) write_userfile,
  208. /* 56 - 59 */
  209. (Function) geticon,
  210. (Function) clear_chanlist,
  211. (Function) reaffirm_owners,
  212. (Function) change_handle,
  213. /* 60 - 63 */
  214. (Function) write_user,
  215. (Function) clear_userlist,
  216. (Function) count_users,
  217. (Function) sanity_check,
  218. /* 64 - 67 */
  219. (Function) break_down_flags,
  220. (Function) build_flags,
  221. (Function) flagrec_eq,
  222. (Function) flagrec_ok,
  223. /* 68 - 71 */
  224. (Function) & shareout,
  225. (Function) dprintf,
  226. (Function) chatout,
  227. (Function) chanout_but,
  228. /* 72 - 75 */
  229. (Function) check_validity,
  230. (Function) list_delete,
  231. (Function) list_append,
  232. (Function) list_contains,
  233. /* 76 - 79 */
  234. (Function) answer,
  235. (Function) getmyip,
  236. (Function) neterror,
  237. (Function) tputs,
  238. /* 80 - 83 */
  239. (Function) new_dcc,
  240. (Function) lostdcc,
  241. (Function) getsock,
  242. (Function) mod_killsock,
  243. /* 84 - 87 */
  244. (Function) open_listen_by_af,
  245. (Function) open_telnet_dcc,
  246. (Function) _get_data_ptr,
  247. (Function) open_telnet,
  248. /* 88 - 91 */
  249. (Function) check_tcl_event,
  250. (Function) egg_memcpy,
  251. (Function) my_atoul,
  252. (Function) my_strcpy,
  253. /* 92 - 95 */
  254. (Function) & dcc, /* struct dcc_t * */
  255. (Function) & chanset, /* struct chanset_t * */
  256. (Function) & userlist, /* struct userrec * */
  257. (Function) & lastuser, /* struct userrec * */
  258. /* 96 - 99 */
  259. (Function) & global_bans, /* struct banrec * */
  260. (Function) & global_ign, /* struct igrec * */
  261. (Function) & password_timeout, /* int */
  262. (Function) & share_greet, /* int */
  263. /* 100 - 103 */
  264. (Function) & max_dcc, /* int */
  265. (Function) 0, /* --UNUSED-- */
  266. (Function) & ignore_time, /* int */
  267. (Function) & use_console_r, /* int */
  268. /* 104 - 107 */
  269. (Function) & reserved_port_min,
  270. (Function) & reserved_port_max,
  271. (Function) & debug_output, /* int */
  272. (Function) & noshare, /* int */
  273. /* 108 - 111 */
  274. (Function) 0, /* gban_total -- UNUSED! (Eule) */
  275. (Function) 0, /* int */
  276. (Function) & default_flags, /* int */
  277. (Function) & dcc_total, /* int */
  278. /* 112 - 115 */
  279. (Function) tempdir, /* char * */
  280. (Function) natip, /* char * */
  281. (Function) hostname, /* char * */
  282. (Function) origbotname, /* char * */
  283. /* 116 - 119 */
  284. (Function) botuser, /* char * */
  285. (Function) admin, /* char * */
  286. (Function) userfile, /* char * */
  287. (Function) ver, /* char * */
  288. /* 120 - 123 */
  289. (Function) notify_new, /* char * */
  290. (Function) 0, /* char * */
  291. (Function) version, /* char * */
  292. (Function) botnetnick, /* char * */
  293. /* 124 - 127 */
  294. (Function) & DCC_CHAT_PASS, /* struct dcc_table * */
  295. (Function) & DCC_BOT, /* struct dcc_table * */
  296. (Function) & DCC_LOST, /* struct dcc_table * */
  297. (Function) & DCC_CHAT, /* struct dcc_table * */
  298. /* 128 - 131 */
  299. (Function) & interp, /* Tcl_Interp * */
  300. (Function) & now, /* time_t */
  301. (Function) findanyidx,
  302. (Function) findchan,
  303. /* 132 - 135 */
  304. (Function) 0,
  305. (Function) days,
  306. (Function) daysago,
  307. (Function) daysdur,
  308. /* 136 - 139 */
  309. (Function) ismember,
  310. (Function) newsplit,
  311. (Function) splitnick,
  312. (Function) splitc,
  313. /* 140 - 143 */
  314. (Function) addignore,
  315. (Function) match_ignore,
  316. (Function) delignore,
  317. (Function) fatal,
  318. /* 144 - 147 */
  319. (Function) xtra_kill,
  320. (Function) xtra_unpack,
  321. (Function) movefile,
  322. (Function) copyfile,
  323. /* 148 - 151 */
  324. (Function) do_tcl,
  325. (Function) readtclprog,
  326. (Function) 0,
  327. (Function) def_get,
  328. /* 152 - 155 */
  329. (Function) makepass,
  330. (Function) _wild_match,
  331. (Function) maskhost,
  332. (Function) show_motd,
  333. /* 156 - 159 */
  334. (Function) 0,
  335. (Function) 0,
  336. (Function) 0,
  337. (Function) 0,
  338. /* 160 - 163 */
  339. (Function) touch_laston,
  340. (Function) & add_mode, /* Function * */
  341. (Function) rmspace,
  342. (Function) in_chain,
  343. /* 164 - 167 */
  344. (Function) add_note,
  345. (Function) 0,
  346. (Function) detect_dcc_flood,
  347. (Function) flush_lines,
  348. /* 168 - 171 */
  349. (Function) expected_memory,
  350. (Function) tell_mem_status,
  351. (Function) & do_restart, /* int */
  352. (Function) check_tcl_filt,
  353. /* 172 - 175 */
  354. (Function) add_hook,
  355. (Function) del_hook,
  356. (Function) & H_dcc, /* p_tcl_bind_list * */
  357. (Function) & H_filt, /* p_tcl_bind_list * */
  358. /* 176 - 179 */
  359. (Function) & H_chon, /* p_tcl_bind_list * */
  360. (Function) & H_chof, /* p_tcl_bind_list * */
  361. (Function) & H_load, /* p_tcl_bind_list * */
  362. (Function) & H_unld, /* p_tcl_bind_list * */
  363. /* 180 - 183 */
  364. (Function) & H_chat, /* p_tcl_bind_list * */
  365. (Function) & H_act, /* p_tcl_bind_list * */
  366. (Function) & H_bcst, /* p_tcl_bind_list * */
  367. (Function) & H_bot, /* p_tcl_bind_list * */
  368. /* 184 - 187 */
  369. (Function) & H_link, /* p_tcl_bind_list * */
  370. (Function) & H_disc, /* p_tcl_bind_list * */
  371. (Function) & H_away, /* p_tcl_bind_list * */
  372. (Function) & H_nkch, /* p_tcl_bind_list * */
  373. /* 188 - 191 */
  374. (Function) & USERENTRY_BOTADDR, /* struct user_entry_type * */
  375. (Function) & USERENTRY_BOTFL, /* struct user_entry_type * */
  376. (Function) & USERENTRY_HOSTS, /* struct user_entry_type * */
  377. (Function) & USERENTRY_PASS, /* struct user_entry_type * */
  378. /* 192 - 195 */
  379. (Function) & USERENTRY_XTRA, /* struct user_entry_type * */
  380. (Function) user_del_chan,
  381. (Function) & USERENTRY_INFO, /* struct user_entry_type * */
  382. (Function) & USERENTRY_COMMENT, /* struct user_entry_type * */
  383. /* 196 - 199 */
  384. (Function) & USERENTRY_LASTON, /* struct user_entry_type * */
  385. (Function) putlog,
  386. (Function) botnet_send_chan,
  387. (Function) list_type_kill,
  388. /* 200 - 203 */
  389. (Function) logmodes,
  390. (Function) masktype,
  391. (Function) stripmodes,
  392. (Function) stripmasktype,
  393. /* 204 - 207 */
  394. (Function) 0,
  395. (Function) & online_since, /* time_t * */
  396. (Function) 0,
  397. (Function) check_dcc_attrs,
  398. /* 208 - 211 */
  399. (Function) check_dcc_chanattrs,
  400. (Function) add_tcl_coups,
  401. (Function) rem_tcl_coups,
  402. (Function) botname,
  403. /* 212 - 215 */
  404. (Function) 0, /* remove_gunk() -- UNUSED! (drummer) */
  405. (Function) check_tcl_chjn,
  406. (Function) sanitycheck_dcc,
  407. (Function) isowner,
  408. /* 216 - 219 */
  409. (Function) 0, /* min_dcc_port -- UNUSED! (guppy) */
  410. (Function) 0, /* max_dcc_port -- UNUSED! (guppy) */
  411. (Function) & rfc_casecmp, /* Function * */
  412. (Function) & rfc_ncasecmp, /* Function * */
  413. /* 220 - 223 */
  414. #ifdef S_IRCNET
  415. (Function) & global_exempts, /* struct exemptrec * */
  416. (Function) & global_invites, /* struct inviterec * */
  417. #else
  418. (Function) 0,
  419. (Function) 0,
  420. #endif
  421. (Function) 0, /* ginvite_total -- UNUSED! (Eule) */
  422. (Function) 0, /* gexempt_total -- UNUSED! (Eule) */
  423. /* 224 - 227 */
  424. (Function) & H_event, /* p_tcl_bind_list * */
  425. #ifdef S_IRCNET
  426. (Function) & use_exempts, /* int */
  427. (Function) & use_invites, /* int */
  428. #else
  429. (Function) 0,
  430. (Function) 0,
  431. #endif
  432. (Function) & force_expire, /* int */
  433. /* 228 - 231 */
  434. (Function) 0,
  435. (Function) _user_realloc,
  436. (Function) mod_realloc,
  437. (Function) xtra_set,
  438. /* 232 - 235 */
  439. #ifdef DEBUG_CONTEXT
  440. (Function) eggContextNote,
  441. #else
  442. (Function) 0,
  443. #endif
  444. #ifdef DEBUG_ASSERT
  445. (Function) eggAssert,
  446. #else
  447. (Function) 0,
  448. #endif
  449. (Function) allocsock,
  450. (Function) call_hostbyip,
  451. /* 236 - 239 */
  452. (Function) call_ipbyhost,
  453. (Function) iptostr,
  454. (Function) & DCC_DNSWAIT, /* struct dcc_table * */
  455. (Function) hostsanitycheck_dcc,
  456. /* 240 - 243 */
  457. (Function) dcc_dnsipbyhost,
  458. (Function) dcc_dnshostbyip,
  459. (Function) changeover_dcc,
  460. (Function) make_rand_str,
  461. /* 244 - 247 */
  462. (Function) & protect_readonly, /* int */
  463. (Function) findchan_by_dname,
  464. (Function) removedcc,
  465. (Function) & userfile_perm, /* int */
  466. /* 248 - 251 */
  467. (Function) sock_has_data,
  468. (Function) bots_in_subtree,
  469. (Function) users_in_subtree,
  470. (Function) egg_inet_aton,
  471. /* 252 - 255 */
  472. (Function) egg_snprintf,
  473. (Function) egg_vsnprintf,
  474. (Function) egg_memset,
  475. (Function) egg_strcasecmp,
  476. /* 256 - 259 */
  477. (Function) egg_strncasecmp,
  478. (Function) is_file,
  479. (Function) & must_be_owner, /* int */
  480. (Function) & tandbot, /* tand_t * */
  481. /* 260 - 263 */
  482. (Function) & party, /* party_t * */
  483. (Function) open_address_listen,
  484. (Function) str_escape,
  485. (Function) strchr_unescape,
  486. /* 264 - 267 */
  487. (Function) str_unescape,
  488. (Function) egg_strcatn,
  489. (Function) clear_chanlist_member,
  490. (Function) fixfrom,
  491. /* 268 - 272 */
  492. (Function) sockprotocol,
  493. (Function) & socklist, /* sock_list * */
  494. (Function) sockoptions,
  495. (Function) flush_inbuf,
  496. (Function) kill_bot,
  497. /* 273 - 276 */
  498. (Function) quit_msg, /* char * */
  499. (Function) module_load,
  500. (Function) 0,
  501. (Function) & parties, /* int */
  502. /* 277 - 280 */
  503. (Function) ischanhub,
  504. (Function) rand_dccresp,
  505. (Function) 0,
  506. #ifdef LEAF
  507. (Function) listen_all,
  508. #else
  509. (Function) 0, /* listen_all */
  510. #endif
  511. /* 281 - 284 */
  512. /* gay.
  513. (Function) MD5_Init,
  514. (Function) MD5_Update,
  515. (Function) MD5_Final,
  516. */
  517. (Function) 0,
  518. (Function) 0,
  519. (Function) 0,
  520. (Function) _wild_match_per,
  521. /* 285 - 288 */
  522. (Function) & role, /* int */
  523. (Function) & loading, /* int */
  524. (Function) & localhub, /* int */
  525. (Function) updatebin,
  526. (Function) stats_add,
  527. (Function) lower_bot_linked,
  528. (Function) add_cfg,
  529. (Function) set_cfg_str,
  530. (Function) trigger_cfg_changed,
  531. (Function) higher_bot_linked,
  532. (Function) bot_aggressive_to,
  533. (Function) botunlink,
  534. (Function) hostname6, /* char * */
  535. (Function) & timesync, /* int */
  536. (Function) netpass, /* char * */
  537. (Function) kickreason,
  538. (Function) getting_users,
  539. (Function) add_builtins_dcc,
  540. (Function) rem_builtins_dcc,
  541. (Function) & USERENTRY_ADDED, /* struct user_entry_type * */
  542. (Function) thepass,
  543. (Function) isupdatehub,
  544. (Function) & norestruct,
  545. (Function) botlink,
  546. (Function) makeplaincookie,
  547. (Function) bankickprefix,
  548. (Function) kickprefix,
  549. (Function) deflag_user,
  550. (Function) dcc_prefix,
  551. (Function) goodpass,
  552. #ifdef S_AUTH
  553. (Function) & auth, /* struct auth_t *auth */
  554. (Function) & auth_total,
  555. (Function) new_auth,
  556. (Function) isauthed,
  557. (Function) removeauth,
  558. (Function) makehash,
  559. (Function) & USERENTRY_SECPASS,
  560. (Function) authkey,
  561. #else
  562. (Function) 0,
  563. (Function) 0,
  564. (Function) 0,
  565. (Function) 0,
  566. (Function) 0,
  567. (Function) 0,
  568. (Function) & USERENTRY_SECPASS,
  569. (Function) 0,
  570. #endif /* S_AUTH */
  571. (Function) myip,
  572. (Function) myip6,
  573. (Function) cmdprefix,
  574. (Function) replace,
  575. (Function) degarble,
  576. (Function) egg_inet_ntop,
  577. (Function) open_listen,
  578. (Function) hostprotocol,
  579. (Function) sdprintf,
  580. (Function) putbot,
  581. (Function) putallbots,
  582. (Function) ssl_link,
  583. (Function) dropssl,
  584. (Function) myipstr,
  585. (Function) checkchans
  586. };
  587. void init_modules(void)
  588. {
  589. int i;
  590. module_list = nmalloc(sizeof(module_entry));
  591. module_list->name = nmalloc(8);
  592. strcpy(module_list->name, "eggdrop");
  593. module_list->major = (egg_numver) / 10000;
  594. module_list->minor = ((egg_numver) / 100) % 100;
  595. module_list->next = NULL;
  596. module_list->funcs = NULL;
  597. for (i = 0; i < REAL_HOOKS; i++)
  598. hook_list[i] = NULL;
  599. }
  600. int expmem_modules(int y)
  601. {
  602. int c = 0;
  603. int i;
  604. module_entry *p;
  605. dependancy *d;
  606. struct hook_entry *q;
  607. struct static_list *s;
  608. Function *f;
  609. for (s = static_modules; s; s = s->next)
  610. c += sizeof(struct static_list) + strlen(s->name) + 1;
  611. for (i = 0; i < REAL_HOOKS; i++)
  612. for (q = hook_list[i]; q; q = q->next)
  613. c += sizeof(struct hook_entry);
  614. for (d = dependancy_list; d; d = d->next)
  615. c += sizeof(dependancy);
  616. for (p = module_list; p; p = p->next) {
  617. c += sizeof(module_entry);
  618. c += strlen(p->name) + 1;
  619. f = p->funcs;
  620. if (f && f[MODCALL_EXPMEM] && !y)
  621. c += (int) (f[MODCALL_EXPMEM] ());
  622. }
  623. return c;
  624. }
  625. int module_register(char *name, Function * funcs,
  626. int major, int minor)
  627. {
  628. module_entry *p;
  629. for (p = module_list; p && p->name; p = p->next)
  630. if (!egg_strcasecmp(name, p->name)) {
  631. p->major = major;
  632. p->minor = minor;
  633. p->funcs = funcs;
  634. return 1;
  635. }
  636. return 0;
  637. }
  638. const char *module_load(char *name)
  639. {
  640. module_entry *p;
  641. char *e;
  642. Function f;
  643. struct static_list *sl;
  644. if (module_find(name, 0, 0) != NULL)
  645. return MOD_ALREADYLOAD;
  646. for (sl = static_modules; sl && egg_strcasecmp(sl->name, name); sl = sl->next);
  647. if (!sl)
  648. return "Unknown module.";
  649. f = (Function) sl->func;
  650. p = nmalloc(sizeof(module_entry));
  651. if (p == NULL)
  652. return "Malloc error";
  653. p->name = nmalloc(strlen(name) + 1);
  654. strcpy(p->name, name);
  655. p->major = 0;
  656. p->minor = 0;
  657. p->funcs = 0;
  658. p->next = module_list;
  659. module_list = p;
  660. e = (((char *(*)()) f) (global_table));
  661. if (e) {
  662. module_list = module_list->next;
  663. nfree(p->name);
  664. nfree(p);
  665. return e;
  666. }
  667. check_tcl_load(name);
  668. return NULL;
  669. }
  670. module_entry *module_find(char *name, int major, int minor)
  671. {
  672. module_entry *p;
  673. for (p = module_list; p && p->name; p = p->next)
  674. if ((major == p->major || !major) && minor <= p->minor &&
  675. !egg_strcasecmp(name, p->name))
  676. return p;
  677. return NULL;
  678. }
  679. static int module_rename(char *name, char *newname)
  680. {
  681. module_entry *p;
  682. for (p = module_list; p; p = p->next)
  683. if (!egg_strcasecmp(newname, p->name))
  684. return 0;
  685. for (p = module_list; p && p->name; p = p->next)
  686. if (!egg_strcasecmp(name, p->name)) {
  687. nfree(p->name);
  688. p->name = nmalloc(strlen(newname) + 1);
  689. strcpy(p->name, newname);
  690. return 1;
  691. }
  692. return 0;
  693. }
  694. Function *module_depend(char *name1, char *name2, int major, int minor)
  695. {
  696. module_entry *p = module_find(name2, major, minor);
  697. module_entry *o = module_find(name1, 0, 0);
  698. dependancy *d;
  699. if (!p) {
  700. if (module_load(name2))
  701. return 0;
  702. p = module_find(name2, major, minor);
  703. }
  704. if (!p || !o)
  705. return 0;
  706. d = nmalloc(sizeof(dependancy));
  707. d->needed = p;
  708. d->needing = o;
  709. d->next = dependancy_list;
  710. d->major = major;
  711. d->minor = minor;
  712. dependancy_list = d;
  713. return p->funcs ? p->funcs : (Function *) 1;
  714. }
  715. int module_undepend(char *name1)
  716. {
  717. int ok = 0;
  718. module_entry *p = module_find(name1, 0, 0);
  719. dependancy *d = dependancy_list, *o = NULL;
  720. if (p == NULL)
  721. return 0;
  722. while (d != NULL) {
  723. if (d->needing == p) {
  724. if (o == NULL) {
  725. dependancy_list = d->next;
  726. } else {
  727. o->next = d->next;
  728. }
  729. nfree(d);
  730. if (o == NULL)
  731. d = dependancy_list;
  732. else
  733. d = o->next;
  734. ok++;
  735. } else {
  736. o = d;
  737. d = d->next;
  738. }
  739. }
  740. return ok;
  741. }
  742. void *mod_malloc(int size, const char *modname, const char *filename, int line)
  743. {
  744. #ifdef DEBUG_MEM
  745. char x[100], *p;
  746. p = strrchr(filename, '/');
  747. egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
  748. x[19] = 0;
  749. return n_malloc(size, x, line);
  750. #else
  751. return nmalloc(size);
  752. #endif
  753. }
  754. void *mod_realloc(void *ptr, int size, const char *modname,
  755. const char *filename, int line)
  756. {
  757. #ifdef DEBUG_MEM
  758. char x[100], *p;
  759. p = strrchr(filename, '/');
  760. egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
  761. x[19] = 0;
  762. return n_realloc(ptr, size, x, line);
  763. #else
  764. return nrealloc(ptr, size);
  765. #endif
  766. }
  767. void mod_free(void *ptr, const char *modname, const char *filename, int line)
  768. {
  769. char x[100], *p;
  770. p = strrchr(filename, '/');
  771. egg_snprintf(x, sizeof x, "%s:%s", modname, p ? p + 1 : filename);
  772. x[19] = 0;
  773. n_free(ptr, x, line);
  774. }
  775. /* Hooks, various tables of functions to call on ceratin events
  776. */
  777. void add_hook(int hook_num, Function func)
  778. {
  779. if (hook_num < REAL_HOOKS) {
  780. struct hook_entry *p;
  781. for (p = hook_list[hook_num]; p; p = p->next)
  782. if (p->func == func)
  783. return; /* Don't add it if it's already there */
  784. p = nmalloc(sizeof(struct hook_entry));
  785. p->next = hook_list[hook_num];
  786. hook_list[hook_num] = p;
  787. p->func = func;
  788. } else
  789. switch (hook_num) {
  790. case HOOK_ENCRYPT_PASS:
  791. encrypt_pass = (void (*)(char *, char *)) func;
  792. break;
  793. case HOOK_ENCRYPT_STRING:
  794. encrypt_string = (char *(*)(char *, char *)) func;
  795. break;
  796. case HOOK_DECRYPT_STRING:
  797. decrypt_string = (char *(*)(char *, char *)) func;
  798. break;
  799. case HOOK_SHAREOUT:
  800. shareout = (void (*)()) func;
  801. break;
  802. case HOOK_SHAREIN:
  803. sharein = (void (*)(int, char *)) func;
  804. break;
  805. case HOOK_SHAREUPDATEIN:
  806. shareupdatein = (void (*)(int, char *)) func;
  807. break;
  808. case HOOK_QSERV:
  809. if (qserver == (void (*)(int, char *, int)) null_func)
  810. qserver = (void (*)(int, char *, int)) func;
  811. break;
  812. case HOOK_ADD_MODE:
  813. if (add_mode == (void (*)()) null_func)
  814. add_mode = (void (*)()) func;
  815. break;
  816. /* special hook <drummer> */
  817. case HOOK_RFC_CASECMP:
  818. if (func == NULL) {
  819. rfc_casecmp = egg_strcasecmp;
  820. rfc_ncasecmp = (int (*)(const char *, const char *, int)) egg_strncasecmp;
  821. rfc_tolower = tolower;
  822. rfc_toupper = toupper;
  823. } else {
  824. rfc_casecmp = _rfc_casecmp;
  825. rfc_ncasecmp = _rfc_ncasecmp;
  826. rfc_tolower = _rfc_tolower;
  827. rfc_toupper = _rfc_toupper;
  828. }
  829. break;
  830. case HOOK_MATCH_NOTEREJ:
  831. if (match_noterej == (int (*)(struct userrec *, char *))false_func)
  832. match_noterej = func;
  833. break;
  834. case HOOK_DNS_HOSTBYIP:
  835. if (dns_hostbyip == block_dns_hostbyip)
  836. dns_hostbyip = (void (*)(IP)) func;
  837. break;
  838. case HOOK_DNS_IPBYHOST:
  839. if (dns_ipbyhost == block_dns_ipbyhost)
  840. dns_ipbyhost = (void (*)(char *)) func;
  841. break;
  842. }
  843. }
  844. void del_hook(int hook_num, Function func)
  845. {
  846. if (hook_num < REAL_HOOKS) {
  847. struct hook_entry *p = hook_list[hook_num], *o = NULL;
  848. while (p) {
  849. if (p->func == func) {
  850. if (o == NULL)
  851. hook_list[hook_num] = p->next;
  852. else
  853. o->next = p->next;
  854. nfree(p);
  855. break;
  856. }
  857. o = p;
  858. p = p->next;
  859. }
  860. } else
  861. switch (hook_num) {
  862. case HOOK_ENCRYPT_PASS:
  863. if (encrypt_pass == (void (*)(char *, char *)) func)
  864. encrypt_pass = (void (*)(char *, char *)) null_func;
  865. break;
  866. case HOOK_ENCRYPT_STRING:
  867. if (encrypt_string == (char *(*)(char *, char *)) func)
  868. encrypt_string = (char *(*)(char *, char *)) null_func;
  869. break;
  870. case HOOK_DECRYPT_STRING:
  871. if (decrypt_string == (char *(*)(char *, char *)) func)
  872. decrypt_string = (char *(*)(char *, char *)) null_func;
  873. break;
  874. case HOOK_SHAREOUT:
  875. if (shareout == (void (*)()) func)
  876. shareout = null_func;
  877. break;
  878. case HOOK_SHAREIN:
  879. if (sharein == (void (*)(int, char *)) func)
  880. sharein = null_share;
  881. break;
  882. case HOOK_SHAREUPDATEIN:
  883. if (shareupdatein == (void (*)(int, char *)) func)
  884. shareupdatein = null_share;
  885. break;
  886. case HOOK_QSERV:
  887. if (qserver == (void (*)(int, char *, int)) func)
  888. qserver = null_func;
  889. break;
  890. case HOOK_ADD_MODE:
  891. if (add_mode == (void (*)()) func)
  892. add_mode = null_func;
  893. break;
  894. case HOOK_MATCH_NOTEREJ:
  895. if (match_noterej == (int (*)(struct userrec *, char *))func)
  896. match_noterej = false_func;
  897. break;
  898. case HOOK_DNS_HOSTBYIP:
  899. if (dns_hostbyip == (void (*)(IP)) func)
  900. dns_hostbyip = block_dns_hostbyip;
  901. break;
  902. case HOOK_DNS_IPBYHOST:
  903. if (dns_ipbyhost == (void (*)(char *)) func)
  904. dns_ipbyhost = block_dns_ipbyhost;
  905. break;
  906. }
  907. }
  908. int call_hook_cccc(int hooknum, char *a, char *b, char *c, char *d)
  909. {
  910. struct hook_entry *p, *pn;
  911. int f = 0;
  912. if (hooknum >= REAL_HOOKS)
  913. return 0;
  914. p = hook_list[hooknum];
  915. for (p = hook_list[hooknum]; p && !f; p = pn) {
  916. pn = p->next;
  917. f = p->func(a, b, c, d);
  918. }
  919. return f;
  920. }
  921. void do_module_report(int idx, int details, char *which)
  922. {
  923. module_entry *p = module_list;
  924. if (p && !which && details)
  925. dprintf(idx, "MODULES LOADED:\n");
  926. for (; p; p = p->next) {
  927. if (!which || !egg_strcasecmp(which, p->name)) {
  928. dependancy *d;
  929. if (details)
  930. dprintf(idx, "Module: %s, v %d.%d\n", p->name ? p->name : "CORE",
  931. p->major, p->minor);
  932. if (details > 1) {
  933. for (d = dependancy_list; d; d = d->next)
  934. if (d->needing == p)
  935. dprintf(idx, " requires: %s, v %d.%d\n", d->needed->name,
  936. d->major, d->minor);
  937. }
  938. if (p->funcs) {
  939. Function f = p->funcs[MODCALL_REPORT];
  940. if (f != NULL)
  941. f(idx, details);
  942. }
  943. if (which)
  944. return;
  945. }
  946. }
  947. if (which)
  948. dprintf(idx, "No such module.\n");
  949. }