]> jfr.im git - solanum.git/blobdiff - ircd/modules.c
ircd: modules: findmodule_byname(): also check LT_MODULE_EXT here
[solanum.git] / ircd / modules.c
index 72fe3f08a26015f9f7803895c83952bae66d40b3..2e0e0869740f8b8264a7b5c66108c8158059e5d8 100644 (file)
 
 #include <ltdl.h>
 
+#ifndef LT_MODULE_EXT
+#      error "Charybdis requires loadable module support."
+#endif
+
 struct module **modlist = NULL;
 
 static const char *core_module_table[] = {
@@ -66,23 +70,23 @@ int max_mods = MODS_INCREMENT;
 
 static rb_dlink_list mod_paths;
 
-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 void mo_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void mo_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void 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 void me_modload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_modlist(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_modreload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void me_modunload(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static void 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 *);
+static void do_modload(struct Client *, const char *);
+static void do_modunload(struct Client *, const char *);
+static void do_modreload(struct Client *, const char *);
+static void do_modlist(struct Client *, const char *);
+static void do_modrestart(struct Client *);
 
 struct Message modload_msgtab = {
        "MODLOAD", 0, 0, 0, 0,
@@ -202,12 +206,20 @@ int
 findmodule_byname(const char *name)
 {
        int i;
+       char name_ext[PATH_MAX + 1];
+
+       rb_strlcpy(name_ext, name, sizeof basename_ext);
+       rb_strlcat(name_ext, LT_MODULE_EXT, sizeof basename_ext);
 
        for (i = 0; i < num_mods; i++)
        {
                if(!irccmp(modlist[i]->name, name))
                        return i;
+
+               if(!irccmp(modlist[i]->name, name_ext))
+                       return i;
        }
+
        return -1;
 }
 
@@ -223,7 +235,7 @@ load_all_modules(int warn)
        DIR *system_module_dir = NULL;
        struct dirent *ldirent = NULL;
        char module_fq_name[PATH_MAX + 1];
-       int len;
+       size_t module_ext_len = strlen(LT_MODULE_EXT);
 
        modules_init();
 
@@ -241,8 +253,11 @@ load_all_modules(int warn)
 
        while ((ldirent = readdir(system_module_dir)) != NULL)
        {
+               struct stat s;
+               size_t len;
+
                len = strlen(ldirent->d_name);
-               if((len > 3) && !strcmp(ldirent->d_name+len-3, ".la"))
+               if(len > module_ext_len && !strcasecmp(ldirent->d_name + (len - module_ext_len), LT_MODULE_EXT))
                {
                        (void) snprintf(module_fq_name, sizeof(module_fq_name), "%s/%s", AUTOMODPATH, ldirent->d_name);
                        (void) load_a_module(module_fq_name, warn, MAPI_ORIGIN_CORE, 0);
@@ -268,13 +283,13 @@ load_core_modules(int warn)
        for (i = 0; core_module_table[i]; i++)
        {
                snprintf(module_name, sizeof(module_name), "%s/%s%s", MODPATH,
-                           core_module_table[i], ".la");
+                           core_module_table[i], LT_MODULE_EXT);
 
                if(load_a_module(module_name, warn, MAPI_ORIGIN_CORE, 1) == -1)
                {
                        ilog(L_MAIN,
-                            "Error loading core module %s%s: terminating ircd",
-                            core_module_table[i], ".la");
+                            "Error loading core module %s: terminating ircd",
+                            core_module_table[i]);
                        exit(0);
                }
        }
@@ -292,10 +307,9 @@ load_one_module(const char *path, int origin, int coremodule)
        char modpath[PATH_MAX];
        rb_dlink_node *pathst;
        const char *mpath;
-
        struct stat statbuf;
 
-       if (server_state_foreground == 1)
+       if (server_state_foreground)
                inotice("loading module %s ...", path);
 
        if(coremodule != 0)
@@ -308,7 +322,7 @@ load_one_module(const char *path, int origin, int coremodule)
        {
                mpath = pathst->data;
 
-               snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
+               snprintf(modpath, sizeof(modpath), "%s/%s%s", mpath, path, LT_MODULE_EXT);
                if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
                {
                        if(stat(modpath, &statbuf) == 0)
@@ -329,14 +343,14 @@ load_one_module(const char *path, int origin, int coremodule)
 
 
 /* load a module .. */
-static int
+static void
 mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
                           me.name, source_p->name, "admin");
-               return 0;
+               return;
        }
 
        if(parc > 2)
@@ -344,147 +358,214 @@ mo_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sour
                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;
        }
 
-       return do_modload(source_p, parv[1]);
+       do_modload(source_p, parv[1]);
 }
 
-static int
+static void
 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;
        }
 
-       return do_modload(source_p, parv[1]);
+       do_modload(source_p, parv[1]);
 }
 
-static int
-do_modload(struct Client *source_p, const char *module)
+
+/* unload a module .. */
+static void
+mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       char *m_bn = rb_basename(module);
-       int origin;
+       if(!IsOperAdmin(source_p))
+       {
+               sendto_one(source_p, form_str(ERR_NOPRIVS),
+                          me.name, source_p->name, "admin");
+               return;
+       }
 
-       if(findmodule_byname(m_bn) != -1)
+       if(parc > 2)
        {
-               sendto_one_notice(source_p, ":Module %s is already loaded", m_bn);
-               rb_free(m_bn);
-               return 0;
+               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;
        }
 
-       origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION;
-       load_one_module(module, origin, 0);
+       do_modunload(source_p, parv[1]);
+}
 
-       rb_free(m_bn);
+static void
+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;
+       }
 
-       return 0;
+       do_modunload(source_p, parv[1]);
 }
 
-
-/* unload a module .. */
-static int
-mo_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+/* unload and load in one! */
+static void
+mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
                           me.name, source_p->name, "admin");
-               return 0;
+               return;
        }
 
        if(parc > 2)
        {
                sendto_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS,
-                               "ENCAP %s MODUNLOAD %s", parv[2], parv[1]);
+                               "ENCAP %s MODRELOAD %s", parv[2], parv[1]);
                if (match(parv[2], me.name) == 0)
-                       return 0;
+                       return;
        }
 
-       return do_modunload(source_p, parv[1]);
+       do_modreload(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)
+static void
+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;
        }
 
-       return do_modunload(source_p, parv[1]);
+       do_modreload(source_p, parv[1]);
 }
 
-static int
-do_modunload(struct Client *source_p, const char *module)
+/* list modules .. */
+static void
+mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
-       int modindex;
-       char *m_bn = rb_basename(module);
-
-       if((modindex = findmodule_byname(m_bn)) == -1)
+       if(!IsOperAdmin(source_p))
        {
-               sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
-               rb_free(m_bn);
-               return 0;
+               sendto_one(source_p, form_str(ERR_NOPRIVS),
+                          me.name, source_p->name, "admin");
+               return;
        }
 
-       if(modlist[modindex]->core == 1)
+       if(parc > 2)
        {
-               sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn);
-               rb_free(m_bn);
-               return 0;
+               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;
        }
 
-       if(unload_one_module(m_bn, 1) == -1)
+       do_modlist(source_p, parc > 1 ? parv[1] : 0);
+}
+
+static void
+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, ":Module %s is not loaded", m_bn);
+               sendto_one_notice(source_p, ":*** You do not have an appropriate shared block "
+                               "to load modules on this server.");
+               return;
        }
 
-       rb_free(m_bn);
-       return 0;
+       do_modlist(source_p, parv[1]);
 }
 
-/* unload and load in one! */
-static int
-mo_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+/* unload and reload all modules */
+static void
+mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
 {
        if(!IsOperAdmin(source_p))
        {
                sendto_one(source_p, form_str(ERR_NOPRIVS),
                           me.name, source_p->name, "admin");
-               return 0;
+               return;
        }
 
-       if(parc > 2)
+       if(parc > 1)
        {
-               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;
+               sendto_match_servs(source_p, parv[1], CAP_ENCAP, NOCAPS,
+                               "ENCAP %s MODRESTART", parv[1]);
+               if (match(parv[1], me.name) == 0)
+                       return;
        }
 
-       return do_modreload(source_p, parv[1]);
+       do_modrestart(source_p);
 }
 
-static int
-me_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+static void
+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 void
+do_modload(struct Client *source_p, const char *module)
+{
+       char *m_bn = rb_basename(module);
+       int origin;
+
+       if(findmodule_byname(m_bn) != -1)
+       {
+               sendto_one_notice(source_p, ":Module %s is already loaded", m_bn);
+               rb_free(m_bn);
+               return;
        }
 
-       return do_modreload(source_p, parv[1]);
+       origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION;
+       load_one_module(module, origin, 0);
+
+       rb_free(m_bn);
+}
+
+static void
+do_modunload(struct Client *source_p, const char *module)
+{
+       int modindex;
+       char *m_bn = rb_basename(module);
+
+       if((modindex = findmodule_byname(m_bn)) == -1)
+       {
+               sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
+               rb_free(m_bn);
+               return;
+       }
+
+       if(modlist[modindex]->core == 1)
+       {
+               sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn);
+               rb_free(m_bn);
+               return;
+       }
+
+       if(unload_one_module(m_bn, 1) == -1)
+       {
+               sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
+       }
+
+       rb_free(m_bn);
 }
 
-static int
+static void
 do_modreload(struct Client *source_p, const char *module)
 {
        int modindex;
@@ -495,7 +576,7 @@ do_modreload(struct Client *source_p, const char *module)
        {
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
                rb_free(m_bn);
-               return 0;
+               return;
        }
 
        check_core = modlist[modindex]->core;
@@ -504,7 +585,7 @@ do_modreload(struct Client *source_p, const char *module)
        {
                sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
                rb_free(m_bn);
-               return 0;
+               return;
        }
 
        if((load_one_module(m_bn, modlist[modindex]->origin, check_core) == -1) && check_core)
@@ -516,45 +597,30 @@ do_modreload(struct Client *source_p, const char *module)
        }
 
        rb_free(m_bn);
-       return 0;
 }
 
-/* list modules .. */
-static int
-mo_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
+static void
+do_modrestart(struct Client *source_p)
 {
-       if(!IsOperAdmin(source_p))
-       {
-               sendto_one(source_p, form_str(ERR_NOPRIVS),
-                          me.name, source_p->name, "admin");
-               return 0;
-       }
+       int modnum;
 
-       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;
-       }
+       sendto_one_notice(source_p, ":Reloading all modules");
 
-       return do_modlist(source_p, parc > 1 ? parv[1] : 0);
-}
+       modnum = num_mods;
+       while (num_mods)
+               unload_one_module(modlist[0]->name, 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;
-       }
+       load_all_modules(0);
+       load_core_modules(0);
+       rehash(0);
 
-       return do_modlist(source_p, parv[1]);
+       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);
 }
 
-static int
+static void
 do_modlist(struct Client *source_p, const char *pattern)
 {
        int i;
@@ -596,67 +662,8 @@ do_modlist(struct Client *source_p, const char *pattern)
        }
 
        sendto_one(source_p, form_str(RPL_ENDOFMODLIST), me.name, source_p->name);
-       return 0;
-}
-
-/* unload and reload all modules */
-static int
-mo_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv)
-{
-       if(!IsOperAdmin(source_p))
-       {
-               sendto_one(source_p, form_str(ERR_NOPRIVS),
-                          me.name, source_p->name, "admin");
-               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;
-       while (num_mods)
-               unload_one_module(modlist[0]->name, 0);
-
-       load_all_modules(0);
-       load_core_modules(0);
-       rehash(0);
-
-       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);
-       return 0;
-}
-
-
 static void increase_modlist(void);
 
 #define MODS_INCREMENT 10
@@ -816,7 +823,7 @@ load_a_module(const char *path, int warn, int origin, int core)
 
        mod_basename = rb_basename(path);
 
-       tmpptr = lt_dlopen(path);
+       tmpptr = lt_dlopenext(path);
 
        if(tmpptr == NULL)
        {
@@ -829,7 +836,6 @@ load_a_module(const char *path, int warn, int origin, int core)
                return -1;
        }
 
-
        /*
         * _mheader is actually a struct mapi_mheader_*, but mapi_version
         * is always the first member of this structure, so we treate it
@@ -919,8 +925,7 @@ load_a_module(const char *path, int warn, int origin, int core)
                                if (delta > MOD_WARN_DELTA)
                                {
                                        delta /= 86400;
-                                       iwarn(L_MAIN,
-                                               "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
+                                       iwarn("Module %s build date is out of sync with ircd build date by %ld days, expect problems",
                                                mod_basename, delta);
                                        sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                                "Module %s build date is out of sync with ircd build date by %ld days, expect problems",
@@ -1035,11 +1040,11 @@ load_a_module(const char *path, int warn, int origin, int core)
                }
 
                sendto_realops_snomask(SNO_GENERAL, L_ALL,
-                                    "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
+                                    "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
                                     mod_basename, ver, MAPI_VERSION(*mapi_version), o, description,
-                                    (unsigned long) tmpptr);
-               ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at 0x%lx",
-                    mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (unsigned long) tmpptr);
+                                    (void *) tmpptr);
+               ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d; origin: %s; description: \"%s\"] loaded at %p",
+                    mod_basename, ver, MAPI_VERSION(*mapi_version), o, description, (void *) tmpptr);
        }
        rb_free(mod_basename);
        return 0;