| 1 |
/** |
| 2 |
* modunload.C: Removes a module from memory. |
| 3 |
* |
| 4 |
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
* Rights to this code are as documented in COPYING. |
| 6 |
* |
| 7 |
* |
| 8 |
* Portions of this file were derived from sources bearing the following license: |
| 9 |
* Copyright © 2005-2006 William Pitcock, et al. |
| 10 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
* |
| 12 |
* $Id: modunload.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $ |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "atheme.h" |
| 16 |
#include <ermyth/module.h> |
| 17 |
|
| 18 |
static char const rcsid[] = "$Id: modunload.C,v 1.7 2007-09-16 18:54:44 pippijn Exp $"; |
| 19 |
|
| 20 |
REGISTER_MODULE ("operserv/modunload", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
| 21 |
|
| 22 |
static void os_cmd_modunload (sourceinfo_t *si, int parc, char *parv[]); |
| 23 |
|
| 24 |
command_t const os_modunload = { "MODUNLOAD", N_("Unloads a module."), PRIV_ADMIN, 20, os_cmd_modunload }; |
| 25 |
|
| 26 |
E cmdvec os_cmdtree; |
| 27 |
E helpvec os_helptree; |
| 28 |
|
| 29 |
bool |
| 30 |
_modinit (module *m) |
| 31 |
{ |
| 32 |
os_cmdtree << os_modunload; |
| 33 |
help_addentry (os_helptree, "MODUNLOAD", "help/operserv/modunload", NULL); |
| 34 |
|
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
void |
| 39 |
_moddeinit () |
| 40 |
{ |
| 41 |
os_cmdtree >> os_modunload; |
| 42 |
help_delentry (os_helptree, "MODUNLOAD"); |
| 43 |
} |
| 44 |
|
| 45 |
static void |
| 46 |
os_cmd_modunload (sourceinfo_t *si, int parc, char *parv[]) |
| 47 |
{ |
| 48 |
char *modname; |
| 49 |
int i; |
| 50 |
|
| 51 |
if (parc < 1) |
| 52 |
{ |
| 53 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "MODUNLOAD"); |
| 54 |
command_fail (si, fault::needmoreparams, _("Syntax: MODUNLOAD <module...>")); |
| 55 |
return; |
| 56 |
} |
| 57 |
i = 0; |
| 58 |
while (i < parc) |
| 59 |
{ |
| 60 |
modname = parv[i++]; |
| 61 |
|
| 62 |
if (!strcmp (modname, "operserv/main") |
| 63 |
|| !strcmp (modname, "operserv/modload") |
| 64 |
|| !strcmp (modname, "operserv/modunload")) |
| 65 |
{ |
| 66 |
command_fail (si, fault::noprivs, _("Refusing to unload \2%s\2."), modname); |
| 67 |
continue; |
| 68 |
} |
| 69 |
|
| 70 |
fault::code success = modules::disable (modname); |
| 71 |
|
| 72 |
switch (success) |
| 73 |
{ |
| 74 |
case fault::nosuch_target: |
| 75 |
command_fail (si, fault::nosuch_target, _("\2%s\2 does not exist."), modname); |
| 76 |
continue; |
| 77 |
case fault::nochange: |
| 78 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not loaded; it cannot be unloaded."), modname); |
| 79 |
continue; |
| 80 |
case fault::noprivs: |
| 81 |
slog (LG_INFO, "%s tried to unload a permanent module", get_oper_name (si)); |
| 82 |
command_fail (si, fault::noprivs, _("\2%s\2 is an permanent module; it cannot be unloaded."), modname); |
| 83 |
continue; |
| 84 |
default: |
| 85 |
logcommand (si, CMDLOG_ADMIN, "MODUNLOAD %s", modname); |
| 86 |
command_success_nodata (si, _("Module \2%s\2 unloaded."), modname); |
| 87 |
continue; |
| 88 |
} |
| 89 |
} |
| 90 |
} |