ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/modules.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/modules.c (file contents), Revision 512 by michael, Sat Mar 4 16:21:54 2006 UTC vs.
ircd-hybrid-8/src/modules.c (file contents), Revision 1234 by michael, Fri Sep 23 08:15:04 2011 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 < #include "tools.h"
26 > #include "list.h"
27   #include "modules.h"
28   #include "s_log.h"
29   #include "ircd.h"
# Line 36 | Line 36
36   #include "ircd_defs.h"
37   #include "irc_string.h"
38   #include "memory.h"
39 #include "list.h"
39  
41 /* -TimeMr14C:
42 * I have moved the dl* function definitions and
43 * the two functions (load_a_module / unload_a_module) to the
44 * file dynlink.c
45 * And also made the necessary changes to those functions
46 * to comply with shl_load and friends.
47 * In this file, to keep consistency with the makefile,
48 * I added the ability to load *.sl files, too.
49 * 27/02/2002
50 */
51
52 #ifndef STATIC_MODULES
40  
41   dlink_list mod_list = { NULL, NULL, 0 };
42  
43   static const char *core_module_table[] =
44   {
45 <  "m_die",
46 <  "m_join",
47 <  "m_kick",
48 <  "m_kill",
49 <  "m_message",
50 <  "m_mode",
51 <  "m_nick",
52 <  "m_part",
53 <  "m_quit",
54 <  "m_server",
55 <  "m_sjoin",
56 <  "m_squit",
45 >  "m_die.la",
46 >  "m_error.la",
47 >  "m_join.la",
48 >  "m_kick.la",
49 >  "m_kill.la",
50 >  "m_message.la",
51 >  "m_mode.la",
52 >  "m_nick.la",
53 >  "m_part.la",
54 >  "m_quit.la",
55 >  "m_server.la",
56 >  "m_sjoin.la",
57 >  "m_squit.la",
58    NULL
59   };
60  
# Line 105 | Line 93 | struct Message modrestart_msgtab = {
93   };
94  
95  
108 extern struct Message error_msgtab;
109
96   /*
97   * modules_init
98   *
# Line 117 | Line 103 | extern struct Message error_msgtab;
103   void
104   modules_init(void)
105   {
106 +  dynlink_init();
107 +
108    mod_add_cmd(&modload_msgtab);
109    mod_add_cmd(&modunload_msgtab);
110    mod_add_cmd(&modreload_msgtab);
111    mod_add_cmd(&modlist_msgtab);
112    mod_add_cmd(&modrestart_msgtab);
125  mod_add_cmd(&error_msgtab);
113   }
114  
115   /* mod_find_path()
# Line 221 | Line 208 | mod_clear_paths(void)
208   * output       - NULL if not found or pointer to module
209   * side effects - NONE
210   */
211 < dlink_node *
211 > struct module *
212   findmodule_byname(const char *name)
213   {
214 <  dlink_node *ptr;
228 <  struct module *modp;
214 >  dlink_node *ptr = NULL;
215  
216    DLINK_FOREACH(ptr, mod_list.head)
217    {
218 <    modp = ptr->data;
218 >    struct module *modp = ptr->data;
219  
220      if (strcmp(modp->name, name) == 0)
221 <      return ptr;
221 >      return modp;
222    }
223  
224    return NULL;
# Line 262 | Line 248 | load_all_modules(int warn)
248  
249    while ((ldirent = readdir(system_module_dir)) != NULL)
250    {
251 <    const char *offset = strrchr(ldirent->d_name, '.');
266 <
267 <    if (offset && !strcmp(offset, SHARED_SUFFIX))
251 >    if (modules_valid_suffix(ldirent->d_name))
252      {
253         snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s",
254                  AUTOMODPATH, ldirent->d_name);
# Line 310 | Line 294 | load_core_modules(int warn)
294  
295    for (; core_module_table[i]; ++i)
296    {
297 <    snprintf(module_name, sizeof(module_name), "%s%s%s", MODPATH,
298 <             core_module_table[i], SHARED_SUFFIX);
297 >    snprintf(module_name, sizeof(module_name), "%s%s",
298 >             MODPATH, core_module_table[i]);
299  
300      if (load_a_module(module_name, warn, 1) == -1)
301      {
302 <      ilog(L_CRIT, "Error loading core module %s%s: terminating ircd",
303 <           core_module_table[i], SHARED_SUFFIX);
302 >      ilog(L_CRIT, "Error loading core module %s: terminating ircd",
303 >           core_module_table[i]);
304        exit(EXIT_FAILURE);
305      }
306    }
# Line 330 | Line 314 | load_core_modules(int warn)
314   * side effects - module is loaded if found.
315   */
316   int
317 < load_one_module(char *path, int coremodule)
317 > load_one_module(const char *path, int coremodule)
318   {
319    dlink_node *ptr = NULL;
320    char modpath[PATH_MAX + 1];
# Line 342 | Line 326 | load_one_module(char *path, int coremodu
326  
327      snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path);
328  
329 +    if (!modules_valid_suffix(path))
330 +      continue;
331 +
332      if (strstr(modpath, "../") == NULL &&
333          strstr(modpath, "/..") == NULL)
334      {
# Line 367 | Line 354 | static void
354   mo_modload(struct Client *client_p, struct Client *source_p,
355             int parc, char *parv[])
356   {
357 <  char *m_bn;
357 >  const char *m_bn = NULL;
358  
359 <  if (!IsAdmin(source_p))
359 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
360    {
361      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
362                 me.name, source_p->name);
363      return;
364    }
365  
366 <  m_bn = basename(parv[1]);
366 >  m_bn = libio_basename(parv[1]);
367  
368    if (findmodule_byname(m_bn) != NULL)
369    {
# Line 393 | Line 380 | static void
380   mo_modunload(struct Client *client_p, struct Client *source_p,
381               int parc, char *parv[])
382   {
383 <  char *m_bn;
384 <  dlink_node *ptr;
398 <  struct module *modp;
383 >  const char *m_bn = NULL;
384 >  struct module *modp = NULL;
385  
386 <  if (!IsAdmin(source_p))
386 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
387    {
388      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
389                 me.name, source_p->name);
390      return;
391    }
392  
393 <  m_bn = basename(parv[1]);
393 >  m_bn = libio_basename(parv[1]);
394  
395 <  if ((ptr = findmodule_byname(m_bn)) == NULL)
395 >  if ((modp = findmodule_byname(m_bn)) == NULL)
396    {
397      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
398                 me.name, source_p->name, m_bn);
399      return;
400    }
401  
402 <  modp = ptr->data;
417 <
418 <  if (modp->core == 1)
402 >  if (modp->flags & MODULE_FLAG_CORE)
403    {
404      sendto_one(source_p,
405                 ":%s NOTICE %s :Module %s is a core module and may not be unloaded",
# Line 423 | Line 407 | mo_modunload(struct Client *client_p, st
407      return;
408    }
409  
426  /* XXX might want to simply un dlink it here */
427
410    if (unload_one_module(m_bn, 1) == -1)
411    {
412      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
# Line 437 | Line 419 | static void
419   mo_modreload(struct Client *client_p, struct Client *source_p,
420               int parc, char *parv[])
421   {
422 <  char *m_bn;
423 <  dlink_node *ptr;
442 <  struct module *modp;
422 >  const char *m_bn = NULL;
423 >  struct module *modp = NULL;
424    int check_core;
425  
426 <  if (!IsAdmin(source_p))
426 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
427    {
428      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
429                 me.name, source_p->name);
430      return;
431    }
432  
433 <  m_bn = basename(parv[1]);
433 >  m_bn = libio_basename(parv[1]);
434  
435 <  if ((ptr = findmodule_byname(m_bn)) == NULL)
435 >  if ((modp = findmodule_byname(m_bn)) == NULL)
436    {
437      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
438                 me.name, source_p->name, m_bn);
439      return;
440    }
441  
442 <  modp = ptr->data;
462 <  check_core = modp->core;
442 >  check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
443  
444    if (unload_one_module(m_bn, 1) == -1)
445    {
# Line 482 | Line 462 | static void
462   mo_modlist(struct Client *client_p, struct Client *source_p,
463             int parc, char *parv[])
464   {
465 <  dlink_node *ptr;
486 <  struct module *modp;
465 >  const dlink_node *ptr = NULL;
466  
467 <  if (!IsAdmin(source_p))
467 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
468    {
469      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
470                 me.name, source_p->name);
# Line 494 | Line 473 | mo_modlist(struct Client *client_p, stru
473  
474    DLINK_FOREACH(ptr, mod_list.head)
475    {
476 <    modp = ptr->data;
476 >    const struct module *modp = ptr->data;
477  
478 <    if (parc > 1)
479 <    {
480 <      if (match(parv[1], modp->name))
481 <      {
482 <        sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0],
483 <                   modp->name, modp->address,
505 <                   modp->version, modp->core?"(core)":"");
506 <      }
507 <    }
508 <    else
509 <    {
510 <      sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0],
511 <                 modp->name, modp->address,
512 <                 modp->version, modp->core?"(core)":"");
513 <    }
478 >    if (parc > 1 && !match(parv[1], modp->name))
479 >      continue;
480 >
481 >    sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
482 >               modp->name, modp->handle,
483 >               modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
484    }
485  
486    sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
# Line 523 | Line 493 | mo_modrestart(struct Client *client_p, s
493                int parc, char *parv[])
494   {
495    unsigned int modnum = 0;
496 <  dlink_node *ptr;
497 <  dlink_node *tptr;
498 <  struct module *modp;
529 <  
530 <  if (!IsAdmin(source_p))
496 >  dlink_node *ptr = NULL, *ptr_next = NULL;
497 >
498 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
499    {
500      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
501                 me.name, source_p->name);
# Line 539 | Line 507 | mo_modrestart(struct Client *client_p, s
507  
508    modnum = dlink_list_length(&mod_list);
509  
510 <  DLINK_FOREACH_SAFE(ptr, tptr, mod_list.head)
510 >  DLINK_FOREACH_SAFE(ptr, ptr_next, mod_list.head)
511    {
512 <    modp = ptr->data;
512 >    struct module *modp = ptr->data;
513      unload_one_module(modp->name, 0);
514    }
515  
# Line 550 | Line 518 | mo_modrestart(struct Client *client_p, s
518    load_core_modules(0);
519  
520    sendto_realops_flags(UMODE_ALL, L_ALL,
521 <              "Module Restart: %u modules unloaded, %lu modules loaded",
521 >              "Module Restart: %u modules unloaded, %u modules loaded",
522                          modnum, dlink_list_length(&mod_list));
523 <  ilog(L_WARN, "Module Restart: %u modules unloaded, %lu modules loaded",
523 >  ilog(L_WARN, "Module Restart: %u modules unloaded, %u modules loaded",
524         modnum, dlink_list_length(&mod_list));
525   }
558
559 #else /* STATIC_MODULES */
560 #include "s_serv.h"
561
562 /* load_all_modules()
563 *
564 * input        - warn flag
565 * output       - NONE
566 * side effects - all the msgtabs are added for static modules
567 */
568 void
569 load_all_modules(int warn)
570 {
571  mod_add_cmd(&error_msgtab);
572  mod_add_cmd(&accept_msgtab);
573  mod_add_cmd(&admin_msgtab);
574  mod_add_cmd(&away_msgtab);
575  mod_add_cmd(&bmask_msgtab);
576  mod_add_cmd(&cap_msgtab);
577  mod_add_cmd(&capab_msgtab);
578  mod_add_cmd(&cburst_msgtab);
579  mod_add_cmd(&close_msgtab);
580  mod_add_cmd(&connect_msgtab);
581 #ifdef HAVE_LIBCRYPTO
582  mod_add_cmd(&challenge_msgtab);
583  mod_add_cmd(&cryptlink_msgtab);
584 #endif
585  mod_add_cmd(&die_msgtab);
586  mod_add_cmd(&drop_msgtab);
587  mod_add_cmd(&eob_msgtab);
588  mod_add_cmd(&etrace_msgtab);
589  mod_add_cmd(&gline_msgtab);
590  add_capability("GLN", CAP_GLN, 1);
591  mod_add_cmd(&hash_msgtab);
592  mod_add_cmd(&ungline_msgtab);
593  mod_add_cmd(&info_msgtab);
594  mod_add_cmd(&invite_msgtab);
595  mod_add_cmd(&ison_msgtab);
596  mod_add_cmd(&join_msgtab);
597  mod_add_cmd(&kick_msgtab);
598  mod_add_cmd(&kill_msgtab);
599  mod_add_cmd(&kline_msgtab);
600  add_capability("KLN", CAP_KLN, 1);
601  mod_add_cmd(&dline_msgtab);
602  mod_add_cmd(&unkline_msgtab);
603  mod_add_cmd(&undline_msgtab);
604  mod_add_cmd(&knock_msgtab);
605  add_capability("KNOCK", CAP_KNOCK, 1);
606  mod_add_cmd(&knockll_msgtab);
607  mod_add_cmd(&links_msgtab);
608  mod_add_cmd(&list_msgtab);
609  mod_add_cmd(&lljoin_msgtab);
610  mod_add_cmd(&llnick_msgtab);
611  mod_add_cmd(&locops_msgtab);
612  mod_add_cmd(&lusers_msgtab);
613  mod_add_cmd(&privmsg_msgtab);
614  mod_add_cmd(&notice_msgtab);
615  mod_add_cmd(&map_msgtab);
616  mod_add_cmd(&mode_msgtab);
617  mod_add_cmd(&motd_msgtab);
618  mod_add_cmd(&names_msgtab);
619  mod_add_cmd(&nburst_msgtab);
620  mod_add_cmd(&nick_msgtab);
621  mod_add_cmd(&omotd_msgtab);
622  mod_add_cmd(&oper_msgtab);
623  mod_add_cmd(&operwall_msgtab);
624  mod_add_cmd(&part_msgtab);
625  mod_add_cmd(&pass_msgtab);
626  mod_add_cmd(&ping_msgtab);
627  mod_add_cmd(&pong_msgtab);
628  mod_add_cmd(&post_msgtab);
629  mod_add_cmd(&get_msgtab);
630  mod_add_cmd(&put_msgtab);
631  mod_add_cmd(&quit_msgtab);
632  mod_add_cmd(&rehash_msgtab);
633  mod_add_cmd(&restart_msgtab);
634  mod_add_cmd(&resv_msgtab);
635  mod_add_cmd(&rkline_msgtab);
636  mod_add_cmd(&rxline_msgtab);
637  mod_add_cmd(&server_msgtab);
638  mod_add_cmd(&set_msgtab);
639  mod_add_cmd(&sid_msgtab);
640  mod_add_cmd(&sjoin_msgtab);
641  mod_add_cmd(&squit_msgtab);
642  mod_add_cmd(&stats_msgtab);
643  mod_add_cmd(&svinfo_msgtab);
644  mod_add_cmd(&tb_msgtab);
645  add_capability("TB", CAP_TB, 1);
646  mod_add_cmd(&tburst_msgtab);
647  add_capability("TBURST", CAP_TBURST, 1);
648  mod_add_cmd(&testline_msgtab);
649  mod_add_cmd(&testgecos_msgtab);
650  mod_add_cmd(&testmask_msgtab);
651  mod_add_cmd(&time_msgtab);
652  mod_add_cmd(&tmode_msgtab);
653  mod_add_cmd(&topic_msgtab);
654  mod_add_cmd(&trace_msgtab);
655  add_capability("UNKLN", CAP_UNKLN, 1);
656  mod_add_cmd(&uid_msgtab);
657  mod_add_cmd(&unresv_msgtab);
658  mod_add_cmd(&unxline_msgtab);
659  mod_add_cmd(&user_msgtab);
660  mod_add_cmd(&userhost_msgtab);
661  mod_add_cmd(&users_msgtab);
662  mod_add_cmd(&version_msgtab);
663  mod_add_cmd(&wallops_msgtab);
664  mod_add_cmd(&who_msgtab);
665  mod_add_cmd(&whois_msgtab);
666  mod_add_cmd(&whowas_msgtab);
667  mod_add_cmd(&xline_msgtab);
668  mod_add_cmd(&help_msgtab);
669  mod_add_cmd(&uhelp_msgtab);
670 #ifdef BUILD_CONTRIB
671  mod_add_cmd(&bs_msgtab);
672  mod_add_cmd(&botserv_msgtab);
673  mod_add_cmd(&capture_msgtab);
674  mod_add_cmd(&chanserv_msgtab);
675  mod_add_cmd(&chghost_msgtab);
676  mod_add_cmd(&chgident_msgtab);
677  mod_add_cmd(&chgname_msgtab);
678  mod_add_cmd(&classlist_msgtab);
679  mod_add_cmd(&clearchan_msgtab);
680  mod_add_cmd(&cs_msgtab);
681  mod_add_cmd(&ctrace_msgtab);
682  mod_add_cmd(&delspoof_msgtab);
683  mod_add_cmd(&flags_msgtab);
684  mod_add_cmd(&forcejoin_msgtab);
685  mod_add_cmd(&forcepart_msgtab);
686  mod_add_cmd(&global_msgtab);
687  mod_add_cmd(&help_msgtab);
688  mod_add_cmd(&uhelp_msgtab);
689  mod_add_cmd(&helpserv_msgtab);
690  mod_add_cmd(&hostserv_msgtab);
691  mod_add_cmd(&identify_msgtab);
692  mod_add_cmd(&jupe_msgtab);
693  mod_add_cmd(&killhost_msgtab);
694  mod_add_cmd(&ltrace_msgtab);
695  mod_add_cmd(&memoserv_msgtab);
696  mod_add_cmd(&mkpasswd_msgtab);
697  mod_add_cmd(&ms_msgtab);
698  mod_add_cmd(&nickserv_msgtab);
699  mod_add_cmd(&ns_msgtab);
700  mod_add_cmd(&ojoin_msgtab);
701  mod_add_cmd(&operserv_msgtab);
702  mod_add_cmd(&operspy_msgtab);
703  mod_add_cmd(&opme_msgtab);
704  mod_add_cmd(&os_msgtab);
705  mod_add_cmd(&seenserv_msgtab);
706  mod_add_cmd(&spoof_msgtab);
707  mod_add_cmd(&statserv_msgtab);
708  mod_add_cmd(&svsnick_msgtab);
709  mod_add_cmd(&uncapture_msgtab);
710  /* FIXME: what about spy*? */
711 #endif
712 }
713 #endif /* STATIC_MODULES */

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)