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/drop", false, _modinit, _moddeinit,
15 	PACKAGE_STRING,
16 	VENDOR_STRING
17 );
18 
19 static void gs_cmd_drop(sourceinfo_t *si, int parc, char *parv[]);
20 
21 command_t gs_drop = { "DROP", N_("Drops a group registration."), AC_AUTHENTICATED, 2, gs_cmd_drop, { .path = "groupserv/drop" } };
22 
gs_cmd_drop(sourceinfo_t * si,int parc,char * parv[])23 static void gs_cmd_drop(sourceinfo_t *si, int parc, char *parv[])
24 {
25 	mygroup_t *mg;
26 	char *name = parv[0];
27 	char *key = parv[1];
28 	char fullcmd[512];
29 	char key0[80], key1[80];
30 
31 	if (!name)
32 	{
33 		command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "DROP");
34 		command_fail(si, fault_needmoreparams, _("Syntax: DROP <!group>"));
35 		return;
36 	}
37 
38 	if (*name != '!')
39 	{
40 		command_fail(si, fault_badparams, STR_INVALID_PARAMS, "DROP");
41 		command_fail(si, fault_badparams, _("Syntax: DROP <!group>"));
42 		return;
43 	}
44 
45 	if (!(mg = mygroup_find(name)))
46 	{
47 		command_fail(si, fault_nosuch_target, _("Group \2%s\2 does not exist."), name);
48 		return;
49 	}
50 
51 	if (!groupacs_sourceinfo_has_flag(mg, si, GA_FOUNDER))
52 	{
53 		command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
54 		return;
55 	}
56 
57 	if (si->su != NULL)
58 	{
59 		if (!key)
60 		{
61 			create_challenge(si, entity(mg)->name, 0, key0);
62 			snprintf(fullcmd, sizeof fullcmd, "/%s%s DROP %s %s",
63 					(ircd->uses_rcommand == false) ? "msg " : "",
64 					si->service->disp, entity(mg)->name, key0);
65 			command_success_nodata(si, _("To avoid accidental use of this command, this operation has to be confirmed. Please confirm by replying with \2%s\2"),
66 					fullcmd);
67 			return;
68 		}
69 		/* accept current and previous key */
70 		create_challenge(si, entity(mg)->name, 0, key0);
71 		create_challenge(si, entity(mg)->name, 1, key1);
72 		if (strcmp(key, key0) && strcmp(key, key1))
73 		{
74 			command_fail(si, fault_badparams, _("Invalid key for \2%s\2."), "DROP");
75 			return;
76 		}
77 	}
78 
79 	logcommand(si, CMDLOG_REGISTER, "DROP: \2%s\2", entity(mg)->name);
80 	remove_group_chanacs(mg);
81 	hook_call_group_drop(mg);
82 	object_unref(mg);
83 	command_success_nodata(si, _("The group \2%s\2 has been dropped."), name);
84 	return;
85 }
86 
87 
_modinit(module_t * m)88 void _modinit(module_t *m)
89 {
90 	use_groupserv_main_symbols(m);
91 
92 	service_named_bind_command("groupserv", &gs_drop);
93 }
94 
_moddeinit(module_unload_intent_t intent)95 void _moddeinit(module_unload_intent_t intent)
96 {
97 	service_named_unbind_command("groupserv", &gs_drop);
98 }
99 
100