Debian Codegraph @

modules/groupserv/set_groupname.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Copyright (c) 2007 Jilles Tjoelker
4 * Rights to this code are as documented in doc/LICENSE.
5 *
6 * Changes the account name to another registered nick
7 *
8 */
9
10 #include "atheme.h"
11 #include "uplink.h"
12 #include "groupserv.h"
13
14 DECLARE_MODULE_V1
15 (
16 "groupserv/set_groupname", false, _modinit, _moddeinit,
17 PACKAGE_STRING,
18 VENDOR_STRING
19 );
20
21 static void gs_cmd_set_groupname(sourceinfo_t *si, int parc, char *parv[]);
22
23 command_t gs_set_groupname = { "GROUPNAME", N_("Changes the group's name."), AC_NONE, 1, gs_cmd_set_groupname, { .path = "groupserv/set_groupname" } };
24
25 void _modinit(module_t *m)
26 {
27 use_groupserv_main_symbols(m);
28 use_groupserv_set_symbols(m);
29
30 command_add(&gs_set_groupname, gs_set_cmdtree);
31 }
32
33 void _moddeinit(module_unload_intent_t intent)
34 {
35 command_delete(&gs_set_groupname, gs_set_cmdtree);
36 }
37
38 /* SET GROUPNAME <name> */
39 static void gs_cmd_set_groupname(sourceinfo_t *si, int parc, char *parv[])
40 {
41 char *oldname, *newname;
42 mygroup_t *mg;
43
44 if (parc != 2)
45 {
46 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "GROUPNAME");
47 command_fail(si, fault_needmoreparams, _("Syntax: SET GROUPNAME <oldname> <newname>"));
48 return;
49 }
50
51 oldname = parv[0];
52 newname = parv[1];
53
54 if (*oldname != '!' || *newname != '!')
55 {
56 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "GROUPNAME");
57 command_fail(si, fault_badparams, _("Syntax: SET GROUPNAME <oldname> <newname>"));
58 return;
59 }
60
61 mg = mygroup_find(oldname);
62 if (mg == NULL)
63 {
64 command_fail(si, fault_nosuch_target, _("The group \2%s\2 does not exist."), oldname);
65 return;
66 }
67
68 if (!groupacs_sourceinfo_has_flag(mg, si, GA_FOUNDER))
69 {
70 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
71 return;
72 }
73
74 if (strcmp(entity(mg)->name, newname) == 0)
75 {
76 command_fail(si, fault_nochange, _("The group name is already set to \2%s\2."), newname);
77 return;
78 }
79
80 if (mygroup_find(newname) != NULL)
81 {
82 command_fail(si, fault_nochange, _("The group \2%s\2 already exists."), newname);
83 return;
84 }
85
86 mygroup_rename(mg, newname);
87
88 logcommand(si, CMDLOG_REGISTER, "SET:GROUPNAME: \2%s\2 to \2%s\2", oldname, newname);
89 command_success_nodata(si, _("The group \2%s\2 has been renamed to \2%s\2."), oldname, newname);
90 }
91
92 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
93 * vim:ts=8
94 * vim:sw=8
95 * vim:noexpandtab
96 */