]> jfr.im git - solanum.git/blobdiff - ircd/modules.c
ircd: change MessageHandler to include a MsgBuf pointer at the front for tag access
[solanum.git] / ircd / modules.c
index 35cf39340cde6f969a97eda3a5e6aa0da33ce3b2..700d379eac4b5ebfbc84a98e41d70983c1eaace6 100644 (file)
@@ -25,8 +25,6 @@
  */
 
 #include "stdinc.h"
-
-
 #include "modules.h"
 #include "logger.h"
 #include "ircd.h"
@@ -38,9 +36,7 @@
 #include "parse.h"
 #include "ircd_defs.h"
 #include "match.h"
-
-
-#ifndef STATIC_MODULES
+#include "s_serv.h"
 
 #include <ltdl.h>
 
@@ -69,35 +65,47 @@ int max_mods = MODS_INCREMENT;
 
 static rb_dlink_list mod_paths;
 
-static int mo_modload(struct Client *, struct Client *, int, const char **);
-static int mo_modlist(struct Client *, struct Client *, int, const char **);
-static int mo_modreload(struct Client *, struct Client *, int, const char **);
-static int mo_modunload(struct Client *, struct Client *, int, const char **);
-static int mo_modrestart(struct Client *, struct Client *, int, const char **);
+static int mo_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int mo_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+
+static int me_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_modrestart(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+
+static int do_modload(struct Client *, const char *);
+static int do_modunload(struct Client *, const char *);
+static int do_modreload(struct Client *, const char *);
+static int do_modlist(struct Client *, const char *);
+static int do_modrestart(struct Client *);
 
 struct Message modload_msgtab = {
        "MODLOAD", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modload, 2}}
+       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}}
 };
 
 struct Message modunload_msgtab = {
        "MODUNLOAD", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modunload, 2}}
+       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}}
 };
 
 struct Message modreload_msgtab = {
        "MODRELOAD", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modreload, 2}}
+       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}}
 };
 
 struct Message modlist_msgtab = {
        "MODLIST", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modlist, 0}}
+       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}}
 };
 
 struct Message modrestart_msgtab = {
        "MODRESTART", 0, 0, 0, MFLG_SLOW,
-       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_modrestart, 0}}
+       {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}}
 };
 
 void
@@ -232,12 +240,12 @@ load_all_modules(int warn)
 
        while ((ldirent = readdir(system_module_dir)) != NULL)
        {
-               len = strlen(ldirent->d_name);
-               if((len > 3) && !strcmp(ldirent->d_name+len-3, SHARED_SUFFIX))
-                {
-                       (void) rb_snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
-                       (void) load_a_module(module_fq_name, warn, 0);
-                }
+               len = strlen(ldirent->d_name);
+               if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la"))
+               {
+                       (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
+                       (void) load_a_module(module_fq_name, warn, 0);
+               }
 
        }
        (void) closedir(system_module_dir);
@@ -258,14 +266,14 @@ load_core_modules(int warn)
 
        for (i = 0; core_module_table[i]; i++)
        {
-               rb_snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
-                           core_module_table[i], SHARED_SUFFIX);
+               snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
+                           core_module_table[i], ".la");
 
                if(load_a_module(module_name, warn, 1) == -1)
                {
                        ilog(L_MAIN,
                             "Error loading core module %s%s: terminating ircd",
-                            core_module_table[i], SHARED_SUFFIX);
+                            core_module_table[i], ".la");
                        exit(0);
                }
        }
@@ -293,7 +301,7 @@ load_one_module(const char *path, int coremodule)
        {
                mpath = pathst->data;
 
-               rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
+               snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
                if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
                {
                        if(stat(modpath, &statbuf) == 0)
@@ -318,10 +326,8 @@ load_one_module(const char *path, int coremodule)
 
 /* load a module .. */
 static int
-mo_modload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       char *m_bn;
-
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
@@ -329,7 +335,34 @@ mo_modload(struct Client *client_p, struct Client *source_p, int parc, const cha
                return 0;
        }
 
-       m_bn = rb_basename(parv[1]);
+       if(parc > 2)
+       {
+               sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODLOAD %s", parv[2], parv[1]);
+               if (match(parv[2], me.name) == 0)
+                       return 0;
+       }
+
+       return do_modload(source_p, parv[1]);
+}
+
+static int
+me_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
+       {
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return 0;
+       }
+
+       return do_modload(source_p, parv[1]);
+}
+
+static int
+do_modload(struct Client *source_p, const char *module)
+{
+       char *m_bn = rb_basename(module);
 
        if(findmodule_byname(m_bn) != -1)
        {
@@ -338,7 +371,7 @@ mo_modload(struct Client *client_p, struct Client *source_p, int parc, const cha
                return 0;
        }
 
-       load_one_module(parv[1], 0);
+       load_one_module(module, 0);
 
        rb_free(m_bn);
 
@@ -348,11 +381,8 @@ mo_modload(struct Client *client_p, struct Client *source_p, int parc, const cha
 
 /* unload a module .. */
 static int
-mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       char *m_bn;
-       int modindex;
-
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
@@ -360,7 +390,35 @@ mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const c
                return 0;
        }
 
-       m_bn = rb_basename(parv[1]);
+       if(parc > 2)
+       {
+               sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODUNLOAD %s", parv[2], parv[1]);
+               if (match(parv[2], me.name) == 0)
+                       return 0;
+       }
+
+       return do_modunload(source_p, parv[1]);
+}
+
+static int
+me_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
+       {
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return 0;
+       }
+
+       return do_modunload(source_p, parv[1]);
+}
+
+static int
+do_modunload(struct Client *source_p, const char *module)
+{
+       int modindex;
+       char *m_bn = rb_basename(module);
 
        if((modindex = findmodule_byname(m_bn)) == -1)
        {
@@ -387,12 +445,8 @@ mo_modunload(struct Client *client_p, struct Client *source_p, int parc, const c
 
 /* unload and load in one! */
 static int
-mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       char *m_bn;
-       int modindex;
-       int check_core;
-
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
@@ -400,7 +454,36 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
                return 0;
        }
 
-       m_bn = rb_basename(parv[1]);
+       if(parc > 2)
+       {
+               sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODRELOAD %s", parv[2], parv[1]);
+               if (match(parv[2], me.name) == 0)
+                       return 0;
+       }
+
+       return do_modreload(source_p, parv[1]);
+}
+
+static int
+me_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
+       {
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return 0;
+       }
+
+       return do_modreload(source_p, parv[1]);
+}
+
+static int
+do_modreload(struct Client *source_p, const char *module)
+{
+       int modindex;
+       int check_core;
+       char *m_bn = rb_basename(module);
 
        if((modindex = findmodule_byname(m_bn)) == -1)
        {
@@ -420,7 +503,7 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
 
        if((load_one_module(m_bn, check_core) == -1) && check_core)
        {
-               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                     "Error reloading core module: %s: terminating ircd", m_bn);
                ilog(L_MAIN, "Error loading core module %s: terminating ircd", m_bn);
                exit(0);
@@ -432,10 +515,8 @@ mo_modreload(struct Client *client_p, struct Client *source_p, int parc, const c
 
 /* list modules .. */
 static int
-mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       int i;
-
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
@@ -443,11 +524,40 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
                return 0;
        }
 
+       if(parc > 2)
+       {
+               sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODLIST %s", parv[2], parv[1]);
+               if (match(parv[2], me.name) == 0)
+                       return 0;
+       }
+
+       return do_modlist(source_p, parc > 1 ? parv[1] : 0);
+}
+
+static int
+me_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
+       {
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return 0;
+       }
+
+       return do_modlist(source_p, parv[1]);
+}
+
+static int
+do_modlist(struct Client *source_p, const char *pattern)
+{
+       int i;
+
        for (i = 0; i < num_mods; i++)
        {
-               if(parc > 1)
+               if(pattern)
                {
-                       if(match(parv[1], modlist[i]->name))
+                       if(match(pattern, modlist[i]->name))
                        {
                                sendto_one(source_p, form_str(RPL_MODLIST),
                                           me.name, source_p->name,
@@ -460,8 +570,7 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
                {
                        sendto_one(source_p, form_str(RPL_MODLIST),
                                   me.name, source_p->name, modlist[i]->name,
-                                  (unsigned long)(uintptr_t)modlist[i]->address,
-                                  modlist[i]->version,
+                                  (unsigned long)(uintptr_t)modlist[i]->address, modlist[i]->version,
                                   modlist[i]->core ? "(core)" : "");
                }
        }
@@ -472,10 +581,8 @@ mo_modlist(struct Client *client_p, struct Client *source_p, int parc, const cha
 
 /* unload and reload all modules */
 static int
-mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       int modnum;
-
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
@@ -483,6 +590,35 @@ mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const
                return 0;
        }
 
+       if(parc > 1)
+       {
+               sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODRESTART", parv[1]);
+               if (match(parv[1], me.name) == 0)
+                       return 0;
+       }
+
+       return do_modrestart(source_p);
+}
+
+static int
+me_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+{
+       if(!find_shared_conf(source_p->username, source_p->host, source_p->servptr->name, SHARED_MODULE))
+       {
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return 0;
+       }
+
+       return do_modrestart(source_p);
+}
+
+static int
+do_modrestart(struct Client *source_p)
+{
+       int modnum;
+
        sendto_one_notice(source_p, ":Reloading all modules");
 
        modnum = num_mods;
@@ -493,7 +629,7 @@ mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const
        load_core_modules(0);
        rehash(0);
 
-       sendto_realops_snomask(SNO_GENERAL, L_ALL,
+       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                             "Module Restart: %d modules unloaded, %d modules loaded",
                             modnum, num_mods);
        ilog(L_MAIN, "Module Restart: %d modules unloaded, %d modules loaded", modnum, num_mods);
@@ -501,22 +637,6 @@ mo_modrestart(struct Client *client_p, struct Client *source_p, int parc, const
 }
 
 
-
-#ifndef RTLD_NOW
-#define RTLD_NOW RTLD_LAZY     /* openbsd deficiency */
-#endif
-
-#ifndef RTLD_LOCAL
-#define RTLD_LOCAL 0
-#endif
-
-#ifdef CHARYBDIS_PROFILE
-# ifndef RTLD_PROFILE
-#  warning libdl may not support profiling, sucks. :(
-#  define RTLD_PROFILE 0
-# endif
-#endif
-
 static void increase_modlist(void);
 
 #define MODS_INCREMENT 10
@@ -587,6 +707,7 @@ unload_one_module(const char *name, int warn)
        lt_dlclose(modlist[modindex]->address);
 
        rb_free(modlist[modindex]->name);
+       rb_free(modlist[modindex]);
        memmove(&modlist[modindex], &modlist[modindex + 1],
               sizeof(struct module *) * ((num_mods - 1) - modindex));
 
@@ -757,19 +878,3 @@ increase_modlist(void)
        modlist = new_modlist;
        max_mods += MODS_INCREMENT;
 }
-
-#else /* STATIC_MODULES */
-
-/* load_all_modules()
- *
- * input        -
- * output       -
- * side effects - all the msgtabs are added for static modules
- */
-void
-load_all_modules(int warn)
-{
-       load_static_modules();
-}
-
-#endif /* STATIC_MODULES */