Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/VibeDevelopers/Comet.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357/* modules/m_modules.c - module for module loading * Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice is present in all copies. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */
#include "stdinc.h"#include "client.h"#include "parse.h"#include "msg.h"#include "modules.h"#include "s_newconf.h"#include "s_conf.h"#include "s_serv.h"#include "hash.h"#include "ircd.h"#include "match.h"#include "numeric.h"#include "send.h"#include "packet.h"#include "logger.h"#include "response.h"
static const char modules_desc[] = "Provides module management commands";
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 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 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 *);
extern void modules_do_reload(void *); /* end of ircd/modules.c */extern void modules_do_restart(void *); /* end of ircd/modules.c */
struct Message modload_msgtab = { "MODLOAD", 0, 0, 0, 0, {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modload, 2}, {mo_modload, 2}}};
struct Message modunload_msgtab = { "MODUNLOAD", 0, 0, 0, 0, {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modunload, 2}, {mo_modunload, 2}}};
struct Message modreload_msgtab = { "MODRELOAD", 0, 0, 0, 0, {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modreload, 2}, {mo_modreload, 2}}};
struct Message modlist_msgtab = { "MODLIST", 0, 0, 0, 0, {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modlist, 0}, {mo_modlist, 0}}};
struct Message modrestart_msgtab = { "MODRESTART", 0, 0, 0, 0, {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_modrestart, 0}, {mo_modrestart, 0}}};
mapi_clist_av1 modules_clist[] = { &modload_msgtab, &modunload_msgtab, &modreload_msgtab, &modlist_msgtab, &modrestart_msgtab, NULL };
DECLARE_MODULE_AV2(modules, NULL, NULL, modules_clist, NULL, NULL, NULL, NULL, modules_desc);
/* load a module .. */static voidmo_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; }
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; }
do_modload(source_p, parv[1]);}
static voidme_modload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv){ do_modload(source_p, parv[1]);}
/* unload a module .. */static voidmo_modunload(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; }
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; }
do_modunload(source_p, parv[1]);}
static voidme_modunload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv){ do_modunload(source_p, parv[1]);}
/* unload and load in one! */static voidmo_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; }
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; }
do_modreload(source_p, parv[1]);}
static voidme_modreload(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv){ do_modreload(source_p, parv[1]);}
/* list modules .. */static voidmo_modlist(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; }
if(parc > 2) { begin_remote_response_batch(count_match_servs(source_p, parv[2], CAP_ENCAP, NOCAPS), parv[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; }
begin_local_response_batch(); do_modlist(source_p, parc > 1 ? parv[1] : 0);}
static voidme_modlist(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv){ do_modlist(source_p, parv[1]);}
/* unload and reload all modules */static voidmo_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; }
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; }
do_modrestart(source_p);}
static voidme_modrestart(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char **parv){ do_modrestart(source_p);}
static voiddo_modload(struct Client *source_p, const char *module){ char *m_bn = rb_basename(module); int origin;
if(findmodule_byname(m_bn) != NULL) { sendto_one_notice(source_p, ":Module %s is already loaded", m_bn); rb_free(m_bn); return; }
mod_remember_clicaps();
origin = strcmp(module, m_bn) == 0 ? MAPI_ORIGIN_CORE : MAPI_ORIGIN_EXTENSION; load_one_module(module, origin, false);
mod_notify_clicaps();
rb_free(m_bn);}
static voiddo_modunload(struct Client *source_p, const char *module){ struct module *mod; char *m_bn = rb_basename(module);
if((mod = findmodule_byname(m_bn)) == NULL) { sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); rb_free(m_bn); return; }
if(mod->core) { sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn); rb_free(m_bn); return; }
mod_remember_clicaps();
if(unload_one_module(m_bn, true) == false) sendto_one_notice(source_p, ":Module %s is not loaded", m_bn);
mod_notify_clicaps();
rb_free(m_bn);}
static voiddo_modreload(struct Client *source_p, const char *module){ struct modreload *info = rb_malloc(sizeof *info); strcpy(info->module, module); strcpy(info->id, source_p->id); rb_defer(&modules_do_reload, info);}
static voiddo_modrestart(struct Client *source_p){ sendto_one_notice(source_p, ":Reloading all modules");
/* * If a remote MODRESTART is received, m_encap.so will be reloaded, * but ms_encap is in the call stack (it indirectly calls this * function). Also, this function is itself in a module. * * This will go horribly wrong if either module is reloaded to a * different address. * * So, defer the restart to the event loop and return now. */ rb_defer(&modules_do_restart, NULL);}
static voiddo_modlist(struct Client *source_p, const char *pattern){ rb_dlink_node *ptr;
RB_DLINK_FOREACH(ptr, module_list.head) { struct module *mod = ptr->data; const char *origin; switch (mod->origin) { case MAPI_ORIGIN_EXTENSION: origin = "extension"; break; case MAPI_ORIGIN_CORE: origin = "builtin"; break; default: origin = "unknown"; break; }
if(pattern) { if(match(pattern, mod->name)) { sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name, mod->name, (unsigned long)(uintptr_t)mod->address, origin, mod->core ? " (core)" : "", mod->version, mod->description); } } else { sendto_one(source_p, form_str(RPL_MODLIST), me.name, source_p->name, mod->name, (unsigned long)(uintptr_t)mod->address, origin, mod->core ? " (core)" : "", mod->version, mod->description); } }
sendto_one(source_p, form_str(RPL_ENDOFMODLIST), me.name, source_p->name);}