Debian Codegraph @

modules/groupserv/fflags.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/fflags", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void gs_cmd_fflags(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t gs_fflags = { "FFLAGS", N_("Forces a flag change on a user in a group."), PRIV_GROUP_ADMIN, 3, gs_cmd_fflags, { .path = "groupserv/fflags" } };
22
23 static void gs_cmd_fflags(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;
30
31 if (!parv[0] || !parv[1] || !parv[2])
32 {
33 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FFLAGS");
34 command_fail(si, fault_needmoreparams, _("Syntax: FFLAGS <!group> [user] [changes]"));
35 return;
36 }
37
38 if ((mg = mygroup_find(parv[0])) == NULL)
39 {
40 command_fail(si, fault_nosuch_target, _("The group \2%s\2 does not exist."), parv[0]);
41 return;
42 }
43
44 if (si->smu == NULL)
45 {
46 command_fail(si, fault_noprivs, _("You are not logged in."));
47 return;
48 }
49
50 if ((mt = myentity_find_ext(parv[1])) == NULL)
51 {
52 command_fail(si, fault_nosuch_target, _("\2%s\2 is not a registered account."), parv[1]);
53 return;
54 }
55
56 ga = groupacs_find(mg, mt, 0, false);
57 if (ga != NULL)
58 flags = ga->flags;
59
60 flags = gs_flags_parser(parv[2], 1, flags);
61
62 if (!(flags & GA_FOUNDER) && groupacs_find(mg, mt, GA_FOUNDER, false))
63 {
64 if (mygroup_count_flag(mg, GA_FOUNDER) == 1)
65 {
66 command_fail(si, fault_noprivs, _("You may not remove the last founder."));
67 return;
68 }
69
70 if (!groupacs_sourceinfo_has_flag(mg, si, GA_FOUNDER))
71 {
72 command_fail(si, fault_noprivs, _("You may not remove a founder's +F access."));
73 return;
74 }
75 }
76
77 if (ga != NULL && flags != 0)
78 ga->flags = flags;
79 else if (ga != NULL)
80 {
81 groupacs_delete(mg, mt);
82 command_success_nodata(si, _("\2%s\2 has been removed from \2%s\2."), mt->name, entity(mg)->name);
83 wallops("\2%s\2 is removing flags for \2%s\2 on \2%s\2", get_oper_name(si), mt->name, entity(mg)->name);
84 logcommand(si, CMDLOG_ADMIN, "FFLAGS:REMOVE: \2%s\2 on \2%s\2", mt->name, entity(mg)->name);
85 return;
86 }
87 else
88 {
89 if (MOWGLI_LIST_LENGTH(&mg->acs) > gs_config->maxgroupacs && (!(mg->flags & MG_ACSNOLIMIT)))
90 {
91 command_fail(si, fault_toomany, _("Group %s access list is full."), entity(mg)->name);
92 return;
93 }
94 ga = groupacs_add(mg, mt, flags);
95 }
96
97 MOWGLI_ITER_FOREACH(n, entity(mg)->chanacs.head)
98 {
99 chanacs_t *ca = n->data;
100
101 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.",
102 mt->name, gflags_tostr(ga_flags, ga->flags), entity(mg)->name,
103 bitmask_to_flags(ca->level), ca->mychan->name);
104
105 hook_call_channel_acl_change(&(hook_channel_acl_req_t){ .ca = ca });
106 }
107
108 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);
109
110 /* XXX */
111 wallops("\2%s\2 is modifying flags(\2%s\2) for \2%s\2 on \2%s\2", get_oper_name(si), gflags_tostr(ga_flags, ga->flags), mt->name, entity(mg)->name);
112 logcommand(si, CMDLOG_ADMIN, "FFLAGS: \2%s\2 now has flags \2%s\2 on \2%s\2", mt->name, gflags_tostr(ga_flags, ga->flags), entity(mg)->name);
113 }
114
115 void _modinit(module_t *m)
116 {
117 use_groupserv_main_symbols(m);
118
119 service_named_bind_command("groupserv", &gs_fflags);
120 }
121
122 void _moddeinit(module_unload_intent_t intent)
123 {
124 service_named_unbind_command("groupserv", &gs_fflags);
125 }
126