Debian Codegraph @

modules/groupserv/flags.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains routines to handle the GroupServ HELP command.
6 *
7 */
8
9 #include "atheme.h"
10 #include "groupserv.h"
11
12 DECLARE_MODULE_V1
13 (
14 "groupserv/flags", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void gs_cmd_flags(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t gs_flags = { "FLAGS", N_("Sets flags on a user in a group."), AC_AUTHENTICATED, 3, gs_cmd_flags, { .path = "groupserv/flags" } };
22
23 static void gs_cmd_flags(sourceinfo_t *si, int parc, char *parv[])
24 {
25 mowgli_node_t *n;
26 mygroup_t *mg;
27 myentity_t *mt;
28 groupacs_t *ga;
29 unsigned int flags = 0, oldflags = 0;
30 unsigned int dir = 0;
31 char *c;
32 bool operoverride = false;
33
34 if (!parv[0])
35 {
36 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FLAGS");
37 command_fail(si, fault_needmoreparams, _("Syntax: FLAGS <!group> [user] [changes]"));
38 return;
39 }
40
41 if ((mg = mygroup_find(parv[0])) == NULL)
42 {
43 command_fail(si, fault_nosuch_target, _("The group \2%s\2 does not exist."), parv[0]);
44 return;
45 }
46
47 if (!groupacs_sourceinfo_has_flag(mg, si, (parv[2] != NULL ? GA_FLAGS : GA_ACLVIEW)))
48 {
49 if (has_priv(si, PRIV_GROUP_AUSPEX))
50 operoverride = true;
51 else
52 {
53 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
54 return;
55 }
56 }
57
58 if (!parv[1])
59 {
60 int i = 1;
61
62 command_success_nodata(si, _("Entry Account Flags"));
63 command_success_nodata(si, "----- ---------------------- -----");
64
65 MOWGLI_ITER_FOREACH(n, mg->acs.head)
66 {
67 ga = n->data;
68
69 command_success_nodata(si, "%-5d %-22s %s", i, ga->mt->name,
70 gflags_tostr(ga_flags, ga->flags));
71
72 i++;
73 }
74
75 command_success_nodata(si, "----- ---------------------- -----");
76 command_success_nodata(si, _("End of \2%s\2 FLAGS listing."), parv[0]);
77
78 if (operoverride)
79 logcommand(si, CMDLOG_ADMIN, "FLAGS: \2%s\2 (oper override)", parv[0]);
80 else
81 logcommand(si, CMDLOG_GET, "FLAGS: \2%s\2", parv[0]);
82
83 return;
84 }
85
86 /* simple check since it's already checked above */
87 if (operoverride)
88 {
89 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
90 return;
91 }
92
93 if ((mt = myentity_find_ext(parv[1])) == NULL)
94 {
95 command_fail(si, fault_nosuch_target, _("\2%s\2 is not a registered account."), parv[1]);
96 return;
97 }
98
99 if (!parv[2])
100 {
101 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FLAGS");
102 command_fail(si, fault_needmoreparams, _("Syntax: FLAGS <!group> <user> <changes>"));
103 return;
104 }
105
106 if (isuser(mt) && (MU_NEVERGROUP & user(mt)->flags) && (groupacs_find(mg, mt, 0, true) == NULL))
107 {
108 command_fail(si, fault_noprivs, _("\2%s\2 does not wish to have flags in any groups."), parv[1]);
109 return;
110 }
111
112 ga = groupacs_find(mg, mt, 0, false);
113 if (ga != NULL)
114 flags = ga->flags;
115
116 oldflags = flags;
117 flags = gs_flags_parser(parv[2], 1, flags);
118
119 /* check for MU_NEVEROP and forbid committing the change if it's enabled */
120 if (!(oldflags & GA_CHANACS) && (flags & GA_CHANACS))
121 {
122 if (isuser(mt) && user(mt)->flags & MU_NEVEROP)
123 {
124 command_fail(si, fault_noprivs, _("\2%s\2 does not wish to be added to channel access lists (NEVEROP set)."), mt->name);
125 return;
126 }
127 }
128
129 if ((flags & GA_FOUNDER) && !(oldflags & GA_FOUNDER))
130 {
131 if (!(groupacs_sourceinfo_flags(mg, si) & GA_FOUNDER))
132 {
133 flags &= ~GA_FOUNDER;
134 goto no_founder;
135 }
136
137 flags |= GA_FLAGS;
138 }
139 else if ((oldflags & GA_FOUNDER) && !(flags & GA_FOUNDER) && !(groupacs_sourceinfo_flags(mg, si) & GA_FOUNDER))
140 {
141 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
142 return;
143 }
144
145 if (!(flags & GA_FOUNDER) && groupacs_find(mg, mt, GA_FOUNDER, false))
146 {
147 if (mygroup_count_flag(mg, GA_FOUNDER) == 1)
148 {
149 command_fail(si, fault_noprivs, _("You may not remove the last founder."));
150 return;
151 }
152
153 if (!groupacs_sourceinfo_has_flag(mg, si, GA_FOUNDER))
154 {
155 command_fail(si, fault_noprivs, _("You may not remove a founder's +F access."));
156 return;
157 }
158 }
159
160 no_founder:
161 if (ga != NULL && flags != 0)
162 {
163 if (ga->flags != flags)
164 ga->flags = flags;
165 else
166 {
167 command_fail(si, fault_nochange, _("Group \2%s\2 access for \2%s\2 unchanged."), entity(mg)->name, mt->name);
168 return;
169 }
170 }
171 else if (ga != NULL)
172 {
173 groupacs_delete(mg, mt);
174 command_success_nodata(si, _("\2%s\2 has been removed from \2%s\2."), mt->name, entity(mg)->name);
175 logcommand(si, CMDLOG_SET, "FLAGS:REMOVE: \2%s\2 on \2%s\2", mt->name, entity(mg)->name);
176 return;
177 }
178 else if (flags != 0)
179 {
180 if (MOWGLI_LIST_LENGTH(&mg->acs) > gs_config->maxgroupacs && (!(mg->flags & MG_ACSNOLIMIT)))
181 {
182 command_fail(si, fault_toomany, _("Group \2%s\2 access list is full."), entity(mg)->name);
183 return;
184 }
185 ga = groupacs_add(mg, mt, flags);
186 }
187 else
188 {
189 command_fail(si, fault_nochange, _("Group \2%s\2 access for \2%s\2 unchanged."), entity(mg)->name, mt->name);
190 return;
191 }
192
193 MOWGLI_ITER_FOREACH(n, entity(mg)->chanacs.head)
194 {
195 chanacs_t *ca = n->data;
196
197 verbose(ca->mychan, "\2%s\2 now has flags \2%s\2 in the group \2%s\2 which communally has \2%s\2 on \2%s\2.",
198 mt->name, gflags_tostr(ga_flags, ga->flags), entity(mg)->name,
199 bitmask_to_flags(ca->level), ca->mychan->name);
200
201 hook_call_channel_acl_change(&(hook_channel_acl_req_t){ .ca = ca });
202 }
203
204 command_success_nodata(si, _("\2%s\2 now has flags \2%s\2 on \2%s\2."), mt->name, gflags_tostr(ga_flags, ga->flags), entity(mg)->name);
205
206 /* XXX */
207 logcommand(si, CMDLOG_SET, "FLAGS: \2%s\2 now has flags \2%s\2 on \2%s\2", mt->name, gflags_tostr(ga_flags, ga->flags), entity(mg)->name);
208 }
209
210 void _modinit(module_t *m)
211 {
212 use_groupserv_main_symbols(m);
213
214 service_named_bind_command("groupserv", &gs_flags);
215 }
216
217 void _moddeinit(module_unload_intent_t intent)
218 {
219 service_named_unbind_command("groupserv", &gs_flags);
220 }
221