| 1 |
/* |
| 2 |
* Copyright (c) 2012 William Pitcock <[email protected]>. |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 5 |
* purpose with or without fee is hereby granted, provided that the above |
| 6 |
* copyright notice and this permission notice appear in all copies. |
| 7 |
* |
| 8 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 9 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 10 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 11 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 12 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 13 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 14 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 15 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 16 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 17 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 18 |
* POSSIBILITY OF SUCH DAMAGE. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "atheme.h" |
| 22 |
|
| 23 |
DECLARE_MODULE_V1("security/cmdperm", false, _modinit, _moddeinit, PACKAGE_VERSION, VENDOR_STRING); |
| 24 |
|
| 25 |
static bool (*parent_command_authorize)(service_t *svs, sourceinfo_t *si, command_t *c, const char *userlevel) = NULL; |
| 26 |
|
| 27 |
static bool cmdperm_command_authorize(service_t *svs, sourceinfo_t *si, command_t *c, const char *userlevel) |
| 28 |
{ |
| 29 |
char permbuf[BUFSIZE], *cp; |
| 30 |
|
| 31 |
snprintf(permbuf, sizeof permbuf, "command:%s:%s", svs->internal_name, c->name); |
| 32 |
for (cp = permbuf; *cp != '\0'; cp++) |
| 33 |
*cp = ToLower(*cp); |
| 34 |
|
| 35 |
if (!has_priv(si, permbuf)) |
| 36 |
{ |
| 37 |
logaudit_denycmd(si, c, permbuf); |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
return parent_command_authorize(svs, si, c, userlevel); |
| 42 |
} |
| 43 |
|
| 44 |
void _modinit(module_t *m) |
| 45 |
{ |
| 46 |
parent_command_authorize = command_authorize; |
| 47 |
command_authorize = cmdperm_command_authorize; |
| 48 |
} |
| 49 |
|
| 50 |
void _moddeinit(module_unload_intent_t intent) |
| 51 |
{ |
| 52 |
command_authorize = parent_command_authorize; |
| 53 |
} |