| 1 |
/* |
| 2 |
* Copyright (c) 2005 Atheme Development Group |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the GroupServ LISTCHANS function. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
#include "groupserv.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"groupserv/listchans", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
static void gs_cmd_listchans(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
| 21 |
command_t gs_listchans = { "LISTCHANS", N_("Lists channels that a group has access to."), AC_NONE, 1, gs_cmd_listchans, { .path = "groupserv/listchans" } }; |
| 22 |
|
| 23 |
void _modinit(module_t *m) |
| 24 |
{ |
| 25 |
use_groupserv_main_symbols(m); |
| 26 |
service_named_bind_command("groupserv", &gs_listchans); |
| 27 |
} |
| 28 |
|
| 29 |
void _moddeinit(module_unload_intent_t intent) |
| 30 |
{ |
| 31 |
service_named_unbind_command("groupserv", &gs_listchans); |
| 32 |
} |
| 33 |
|
| 34 |
static void gs_cmd_listchans(sourceinfo_t *si, int parc, char *parv[]) |
| 35 |
{ |
| 36 |
mygroup_t *mg; |
| 37 |
mowgli_node_t *n; |
| 38 |
chanacs_t *ca; |
| 39 |
bool operoverride = false; |
| 40 |
unsigned int akicks = 0, i; |
| 41 |
|
| 42 |
/* target */ |
| 43 |
char *target = parv[0]; |
| 44 |
|
| 45 |
if (!target) |
| 46 |
{ |
| 47 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "LISTCHANS"); |
| 48 |
command_fail(si, fault_needmoreparams, _("Syntax: LISTCHANS <!groupname>")); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
if (!(mg = mygroup_find(target))) |
| 53 |
{ |
| 54 |
command_fail(si, fault_nosuch_target, _("Group \2%s\2 does not exist."), target); |
| 55 |
return; |
| 56 |
} |
| 57 |
|
| 58 |
if (!groupacs_sourceinfo_has_flag(mg, si, GA_CHANACS)) |
| 59 |
{ |
| 60 |
if (has_priv(si, PRIV_GROUP_AUSPEX)) |
| 61 |
operoverride = true; |
| 62 |
else |
| 63 |
{ |
| 64 |
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation.")); |
| 65 |
return; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
if (operoverride) |
| 70 |
logcommand(si, CMDLOG_ADMIN, "LISTCHANS: \2%s\2", entity(mg)->name); |
| 71 |
else |
| 72 |
logcommand(si, CMDLOG_GET, "LISTCHANS: \2%s\2", entity(mg)->name); |
| 73 |
|
| 74 |
if (MOWGLI_LIST_LENGTH(&entity(mg)->chanacs) == 0) |
| 75 |
{ |
| 76 |
command_success_nodata(si, _("No channel access was found for the group \2%s\2."), entity(mg)->name); |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
MOWGLI_ITER_FOREACH(n, entity(mg)->chanacs.head) |
| 81 |
{ |
| 82 |
ca = (chanacs_t *)n->data; |
| 83 |
|
| 84 |
/* don't tell users they're akicked (flag +b) */ |
| 85 |
if (ca->level != CA_AKICK) |
| 86 |
command_success_nodata(si, _("Access flag(s) %s in %s"), bitmask_to_flags(ca->level), ca->mychan->name); |
| 87 |
else |
| 88 |
akicks++; |
| 89 |
} |
| 90 |
|
| 91 |
i = MOWGLI_LIST_LENGTH(&entity(mg)->chanacs) - akicks; |
| 92 |
|
| 93 |
if (i == 0) |
| 94 |
command_success_nodata(si, _("No channel access was found for the group \2%s\2."), entity(mg)->name); |
| 95 |
else |
| 96 |
command_success_nodata(si, ngettext(N_("\2%d\2 channel access match for the group \2%s\2"), |
| 97 |
N_("\2%d\2 channel access matches for the group \2%s\2"), i), |
| 98 |
i, entity(mg)->name); |
| 99 |
} |
| 100 |
|
| 101 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 102 |
* vim:ts=8 |
| 103 |
* vim:sw=8 |
| 104 |
* vim:noexpandtab |
| 105 |
*/ |