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.3/src/modules.c (file contents), Revision 1029 by michael, Sun Nov 8 13:10:50 2009 UTC vs.
ircd-hybrid-8/src/modules.c (file contents), Revision 1237 by michael, Thu Sep 29 11:32:21 2011 UTC

# Line 22 | Line 22
22   *  $Id$
23   */
24  
25 + #include "ltdl.h"
26 +
27   #include "stdinc.h"
28   #include "list.h"
29   #include "modules.h"
# Line 40 | Line 42
42  
43   dlink_list mod_list = { NULL, NULL, 0 };
44  
45 +
46 + static const char *unknown_ver = "<unknown>";
47 +
48   static const char *core_module_table[] =
49   {
50    "m_die.la",
# Line 93 | Line 98 | struct Message modrestart_msgtab = {
98   };
99  
100  
101 + int
102 + modules_valid_suffix(const char *name)
103 + {
104 +  return ((name = strrchr(name, '.'))) && !strcmp(name, ".la");
105 + }
106 +
107 + /* unload_one_module()
108 + *
109 + * inputs       - name of module to unload
110 + *              - 1 to say modules unloaded, 0 to not
111 + * output       - 0 if successful, -1 if error
112 + * side effects - module is unloaded
113 + */
114 + int
115 + unload_one_module(const char *name, int warn)
116 + {
117 +  struct module *modp = NULL;
118 +
119 +  if ((modp = findmodule_byname(name)) == NULL)
120 +    return -1;
121 +
122 +  if (modp->modexit)
123 +   modp->modexit();
124 +
125 +  assert(dlink_list_length(&mod_list) > 0);
126 +  dlinkDelete(&modp->node, &mod_list);
127 +  MyFree(modp->name);
128 +
129 +  lt_dlclose(modp->handle);
130 +
131 +  if (warn == 1)
132 +  {
133 +    ilog(L_INFO, "Module %s unloaded", name);
134 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s unloaded", name);
135 +  }
136 +
137 +  return 0;
138 + }
139 +
140 + /* load_a_module()
141 + *
142 + * inputs       - path name of module, int to notice, int of core
143 + * output       - -1 if error 0 if success
144 + * side effects - loads a module if successful
145 + */
146 + int
147 + load_a_module(const char *path, int warn, int core)
148 + {
149 +  lt_dlhandle tmpptr = NULL;
150 +  const char *mod_basename = NULL;
151 +  struct module *modp = NULL;
152 +
153 +  if (findmodule_byname((mod_basename = libio_basename(path))))
154 +    return 1;
155 +
156 +  if (!(tmpptr = lt_dlopen(path))) {
157 +    const char *err = ((err = lt_dlerror())) ? err : "<unknown>";
158 +
159 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Error loading module %s: %s",
160 +                         mod_basename, err);
161 +    ilog(L_WARN, "Error loading module %s: %s", mod_basename, err);
162 +    return -1;
163 +  }
164 +
165 +  if ((modp = lt_dlsym(tmpptr, "module_entry")) == NULL)
166 +  {
167 +    sendto_realops_flags(UMODE_ALL, L_ALL, "Module %s has no module_entry export",
168 +                         mod_basename);
169 +    ilog(L_WARN, "Module %s has no module_entry export", mod_basename);
170 +    lt_dlclose(tmpptr);
171 +    return -1;
172 +  }
173 +
174 +  modp->handle = tmpptr;
175 +
176 +  if (EmptyString(modp->version))
177 +    modp->version = unknown_ver;
178 +
179 +  if (core)
180 +    modp->flags |= MODULE_FLAG_CORE;
181 +
182 +  DupString(modp->name, mod_basename);
183 +  dlinkAdd(modp, &modp->node, &mod_list);
184 +
185 +  if (modp->modinit)
186 +    modp->modinit();
187 +
188 +  if (warn == 1)
189 +  {
190 +    sendto_realops_flags(UMODE_ALL, L_ALL,
191 +                         "Module %s [version: %s handle: %p] loaded.",
192 +                         modp->name, modp->version, tmpptr);
193 +    ilog(L_WARN, "Module %s [version: %s handle: %p] loaded.",
194 +         modp->name, modp->version, tmpptr);
195 +  }
196 +
197 +  return 0;
198 + }
199 +
200   /*
201   * modules_init
202   *
# Line 103 | Line 207 | struct Message modrestart_msgtab = {
207   void
208   modules_init(void)
209   {
210 <  dynlink_init();
210 >  if (lt_dlinit())
211 >  {
212 >    ilog(L_ERROR, "Couldn't initialize the libltdl run time dynamic"
213 >         " link library. Exiting.");
214 >    exit(0);
215 >  }
216  
217    mod_add_cmd(&modload_msgtab);
218    mod_add_cmd(&modunload_msgtab);
# Line 181 | Line 290 | add_conf_module(const char *name)
290   void
291   mod_clear_paths(void)
292   {
293 <  struct module_path *pathst;
294 <  dlink_node *ptr;
186 <  dlink_node *next_ptr;
293 >  struct module_path *pathst = NULL;
294 >  dlink_node *ptr = NULL, *next_ptr = NULL;
295  
296    DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head)
297    {
# Line 208 | Line 316 | mod_clear_paths(void)
316   * output       - NULL if not found or pointer to module
317   * side effects - NONE
318   */
319 < dlink_node *
319 > struct module *
320   findmodule_byname(const char *name)
321   {
322 <  dlink_node *ptr;
215 <  struct module *modp;
322 >  dlink_node *ptr = NULL;
323  
324    DLINK_FOREACH(ptr, mod_list.head)
325    {
326 <    modp = ptr->data;
326 >    struct module *modp = ptr->data;
327  
328      if (strcmp(modp->name, name) == 0)
329 <      return ptr;
329 >      return modp;
330    }
331  
332    return NULL;
# Line 357 | Line 464 | mo_modload(struct Client *client_p, stru
464   {
465    const char *m_bn = 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 382 | Line 489 | mo_modunload(struct Client *client_p, st
489               int parc, char *parv[])
490   {
491    const char *m_bn = NULL;
492 <  dlink_node *ptr;
386 <  struct module *modp;
492 >  struct module *modp = NULL;
493  
494 <  if (!IsAdmin(source_p))
494 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
495    {
496      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
497                 me.name, source_p->name);
# Line 394 | Line 500 | mo_modunload(struct Client *client_p, st
500  
501    m_bn = libio_basename(parv[1]);
502  
503 <  if ((ptr = findmodule_byname(m_bn)) == NULL)
503 >  if ((modp = findmodule_byname(m_bn)) == NULL)
504    {
505      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
506                 me.name, source_p->name, m_bn);
507      return;
508    }
509  
510 <  modp = ptr->data;
405 <
406 <  if (modp->core == 1)
510 >  if (modp->flags & MODULE_FLAG_CORE)
511    {
512      sendto_one(source_p,
513                 ":%s NOTICE %s :Module %s is a core module and may not be unloaded",
# Line 411 | Line 515 | mo_modunload(struct Client *client_p, st
515      return;
516    }
517  
414  /* XXX might want to simply un dlink it here */
415
518    if (unload_one_module(m_bn, 1) == -1)
519    {
520      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
# Line 426 | Line 528 | mo_modreload(struct Client *client_p, st
528               int parc, char *parv[])
529   {
530    const char *m_bn = NULL;
531 <  dlink_node *ptr;
430 <  struct module *modp;
531 >  struct module *modp = NULL;
532    int check_core;
533  
534 <  if (!IsAdmin(source_p))
534 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
535    {
536      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
537                 me.name, source_p->name);
# Line 439 | Line 540 | mo_modreload(struct Client *client_p, st
540  
541    m_bn = libio_basename(parv[1]);
542  
543 <  if ((ptr = findmodule_byname(m_bn)) == NULL)
543 >  if ((modp = findmodule_byname(m_bn)) == NULL)
544    {
545      sendto_one(source_p, ":%s NOTICE %s :Module %s is not loaded",
546                 me.name, source_p->name, m_bn);
547      return;
548    }
549  
550 <  modp = ptr->data;
450 <  check_core = modp->core;
550 >  check_core = (modp->flags & MODULE_FLAG_CORE) != 0;
551  
552    if (unload_one_module(m_bn, 1) == -1)
553    {
# Line 472 | Line 572 | mo_modlist(struct Client *client_p, stru
572   {
573    const dlink_node *ptr = NULL;
574  
575 <  if (!IsAdmin(source_p))
575 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
576    {
577      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
578                 me.name, source_p->name);
# Line 486 | Line 586 | mo_modlist(struct Client *client_p, stru
586      if (parc > 1 && !match(parv[1], modp->name))
587        continue;
588  
589 <    sendto_one(source_p, form_str(RPL_MODLIST), me.name, parv[0],
589 >    sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name,
590                 modp->name, modp->handle,
591 <               modp->version, modp->core?"(core)":"");
591 >               modp->version, (modp->flags & MODULE_FLAG_CORE) ?"(core)":"");
592    }
593  
594    sendto_one(source_p, form_str(RPL_ENDOFMODLIST),
# Line 503 | Line 603 | mo_modrestart(struct Client *client_p, s
603    unsigned int modnum = 0;
604    dlink_node *ptr = NULL, *ptr_next = NULL;
605  
606 <  if (!IsAdmin(source_p))
606 >  if (!HasOFlag(source_p, OPER_FLAG_MODULE))
607    {
608      sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
609                 me.name, source_p->name);

Diff Legend

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