Debian Codegraph @

modules/nickserv/listgroups.c

raw
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 nickserv LISTGROUPS function.
6 *
7 */
8
9 #include "atheme.h"
10
11 #include "../groupserv/groupserv.h"
12
13 DECLARE_MODULE_V1
14 (
15 "nickserv/listgroups", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 static void ns_cmd_listgroups(sourceinfo_t *si, int parc, char *parv[]);
21
22 command_t ns_listgroups = { "LISTGROUPS", N_("Lists groups that you have access to."), AC_NONE, 1, ns_cmd_listgroups, { .path = "nickserv/listgroups" } };
23
24 static void ns_cmd_listgroups(sourceinfo_t *si, int parc, char *parv[])
25 {
26 myuser_t *mu;
27 mowgli_node_t *n;
28 mowgli_list_t *l;
29 unsigned int bans = 0, i;
30
31 /* Optional target */
32 char *target = parv[0];
33
34 if (target)
35 {
36 if (!has_priv(si, PRIV_GROUP_AUSPEX))
37 {
38 command_fail(si, fault_noprivs, _("You are not authorized to use the target argument."));
39 return;
40 }
41
42 mu = myuser_find_ext(target);
43
44 if (mu == NULL)
45 {
46 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), target);
47 return;
48 }
49 }
50 else
51 {
52 mu = si->smu;
53 if (mu == NULL)
54 {
55 command_fail(si, fault_noprivs, _("You are not logged in."));
56 return;
57 }
58 }
59
60 if (mu != si->smu)
61 { /* must have been an oper */
62 logcommand(si, CMDLOG_ADMIN, "LISTGROUPS: \2%s\2", entity(mu)->name);
63 }
64 else
65 { /* just a user, or oper is listing himself */
66 logcommand(si, CMDLOG_GET, "LISTGROUPS");
67 }
68
69 l = myentity_get_membership_list(entity(mu));
70
71 if (MOWGLI_LIST_LENGTH(l) == 0)
72 {
73 command_success_nodata(si, _("No group access was found for the nickname \2%s\2."), entity(mu)->name);
74 return;
75 }
76
77 MOWGLI_ITER_FOREACH(n, l->head)
78 {
79 groupacs_t *ga = n->data;
80
81 if (ga->mt != entity(mu))
82 continue;
83
84 if ((ga->flags & GA_BAN))
85 {
86 bans++;
87 continue;
88 }
89
90 command_success_nodata(si, _("Access flag(s) %s in %s"), gflags_tostr(ga_flags, ga->flags), entity(ga->mg)->name);
91 }
92
93 i = MOWGLI_LIST_LENGTH(l) - bans;
94
95 if (i == 0)
96 command_success_nodata(si, _("No group access was found for the nickname \2%s\2."), entity(mu)->name);
97 else
98 command_success_nodata(si, ngettext(N_("\2%d\2 group access match for the nickname \2%s\2"),
99 N_("\2%d\2 group access matches for the nickname \2%s\2"), i),
100 i, entity(mu)->name);
101 }
102
103 void _modinit(module_t *m)
104 {
105 use_groupserv_main_symbols(m);
106
107 service_named_bind_command("nickserv", &ns_listgroups);
108 }
109
110 void _moddeinit(module_unload_intent_t intent)
111 {
112 service_named_unbind_command("nickserv", &ns_listgroups);
113 }
114
115