| 1 |
/* |
| 2 |
* Copyright (c) 2005 William Pitcock, et al. |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the nickserv DROP function. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
DECLARE_MODULE_V1 |
| 12 |
( |
| 13 |
"nickserv/drop", false, _modinit, _moddeinit, |
| 14 |
PACKAGE_STRING, |
| 15 |
VENDOR_STRING |
| 16 |
); |
| 17 |
|
| 18 |
static void ns_cmd_drop(sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
static void ns_cmd_fdrop(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
| 21 |
command_t ns_drop = { "DROP", N_("Drops an account registration."), AC_NONE, 3, ns_cmd_drop, { .path = "nickserv/drop" } }; |
| 22 |
command_t ns_fdrop = { "FDROP", N_("Forces dropping an account registration."), PRIV_USER_ADMIN, 1, ns_cmd_fdrop, { .path = "nickserv/fdrop" } }; |
| 23 |
|
| 24 |
void _modinit(module_t *m) |
| 25 |
{ |
| 26 |
service_named_bind_command("nickserv", &ns_drop); |
| 27 |
service_named_bind_command("nickserv", &ns_fdrop); |
| 28 |
} |
| 29 |
|
| 30 |
void _moddeinit(module_unload_intent_t intent) |
| 31 |
{ |
| 32 |
service_named_unbind_command("nickserv", &ns_drop); |
| 33 |
service_named_unbind_command("nickserv", &ns_fdrop); |
| 34 |
} |
| 35 |
|
| 36 |
static void ns_cmd_drop(sourceinfo_t *si, int parc, char *parv[]) |
| 37 |
{ |
| 38 |
myuser_t *mu; |
| 39 |
mynick_t *mn; |
| 40 |
char *acc = parv[0]; |
| 41 |
char *pass = parv[1]; |
| 42 |
char *key = parv[2]; |
| 43 |
char fullcmd[512]; |
| 44 |
char key0[80], key1[80]; |
| 45 |
|
| 46 |
if (!acc || !pass) |
| 47 |
{ |
| 48 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "DROP"); |
| 49 |
command_fail(si, fault_needmoreparams, _("Syntax: DROP <account> <password>")); |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
if (!(mu = myuser_find(acc))) |
| 54 |
{ |
| 55 |
if (!nicksvs.no_nick_ownership) |
| 56 |
{ |
| 57 |
mn = mynick_find(acc); |
| 58 |
if (mn != NULL && command_find(si->service->commands, "UNGROUP")) |
| 59 |
{ |
| 60 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is a grouped nick, use %s to remove it."), acc, "UNGROUP"); |
| 61 |
return; |
| 62 |
} |
| 63 |
} |
| 64 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), acc); |
| 65 |
return; |
| 66 |
} |
| 67 |
|
| 68 |
if (metadata_find(mu, "private:freeze:freezer")) |
| 69 |
{ |
| 70 |
command_fail(si, fault_authfail, nicksvs.no_nick_ownership ? "You cannot login as \2%s\2 because the account has been frozen." : "You cannot identify to \2%s\2 because the nickname has been frozen.", entity(mu)->name); |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
if (!verify_password(mu, pass)) |
| 75 |
{ |
| 76 |
command_fail(si, fault_authfail, _("Authentication failed. Invalid password for \2%s\2."), entity(mu)->name); |
| 77 |
bad_password(si, mu); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
if (!nicksvs.no_nick_ownership && |
| 82 |
MOWGLI_LIST_LENGTH(&mu->nicks) > 1 && |
| 83 |
command_find(si->service->commands, "UNGROUP")) |
| 84 |
{ |
| 85 |
command_fail(si, fault_noprivs, _("Account \2%s\2 has %zu other nick(s) grouped to it, remove those first."), |
| 86 |
entity(mu)->name, MOWGLI_LIST_LENGTH(&mu->nicks) - 1); |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
if (is_soper(mu)) |
| 91 |
{ |
| 92 |
command_fail(si, fault_noprivs, _("The nickname \2%s\2 belongs to a services operator; it cannot be dropped."), acc); |
| 93 |
return; |
| 94 |
} |
| 95 |
|
| 96 |
if (mu->flags & MU_HOLD) |
| 97 |
{ |
| 98 |
command_fail(si, fault_noprivs, _("The account \2%s\2 is held; it cannot be dropped."), acc); |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
if (!key) |
| 103 |
{ |
| 104 |
create_challenge(si, entity(mu)->name, 0, key0); |
| 105 |
snprintf(fullcmd, sizeof fullcmd, "/%s%s DROP %s %s %s", |
| 106 |
(ircd->uses_rcommand == false) ? "msg " : "", |
| 107 |
nicksvs.me->disp, entity(mu)->name, pass, key0); |
| 108 |
command_success_nodata(si, _("This is a friendly reminder that you are about to \2destroy\2 the account \2%s\2."), |
| 109 |
entity(mu)->name); |
| 110 |
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"), |
| 111 |
fullcmd); |
| 112 |
return; |
| 113 |
} |
| 114 |
|
| 115 |
create_challenge(si, entity(mu)->name, 0, key0); |
| 116 |
create_challenge(si, entity(mu)->name, 1, key1); |
| 117 |
if (strcmp(key, key0) && strcmp(key, key1)) |
| 118 |
{ |
| 119 |
command_fail(si, fault_badparams, _("Invalid key for %s."), "DROP"); |
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
command_add_flood(si, FLOOD_MODERATE); |
| 124 |
logcommand(si, CMDLOG_REGISTER, "DROP: \2%s\2", entity(mu)->name); |
| 125 |
hook_call_user_drop(mu); |
| 126 |
if (!nicksvs.no_nick_ownership) |
| 127 |
holdnick_sts(si->service->me, 0, entity(mu)->name, NULL); |
| 128 |
command_success_nodata(si, _("The account \2%s\2 has been dropped."), entity(mu)->name); |
| 129 |
object_dispose(mu); |
| 130 |
} |
| 131 |
|
| 132 |
static void ns_cmd_fdrop(sourceinfo_t *si, int parc, char *parv[]) |
| 133 |
{ |
| 134 |
myuser_t *mu; |
| 135 |
mynick_t *mn; |
| 136 |
char *acc = parv[0]; |
| 137 |
mowgli_node_t *n; |
| 138 |
|
| 139 |
if (!acc) |
| 140 |
{ |
| 141 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FDROP"); |
| 142 |
command_fail(si, fault_needmoreparams, _("Syntax: FDROP <account>")); |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
if (!(mu = myuser_find(acc))) |
| 147 |
{ |
| 148 |
if (!nicksvs.no_nick_ownership) |
| 149 |
{ |
| 150 |
mn = mynick_find(acc); |
| 151 |
if (mn != NULL && command_find(si->service->commands, "FUNGROUP")) |
| 152 |
{ |
| 153 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is a grouped nick, use %s to remove it."), acc, "FUNGROUP"); |
| 154 |
return; |
| 155 |
} |
| 156 |
} |
| 157 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), acc); |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
if (is_soper(mu)) |
| 162 |
{ |
| 163 |
command_fail(si, fault_noprivs, _("The nickname \2%s\2 belongs to a services operator; it cannot be dropped."), acc); |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
if (mu->flags & MU_HOLD) |
| 168 |
{ |
| 169 |
command_fail(si, fault_noprivs, _("The account \2%s\2 is held; it cannot be dropped."), acc); |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
wallops("%s dropped the account \2%s\2", get_oper_name(si), entity(mu)->name); |
| 174 |
logcommand(si, CMDLOG_ADMIN | LG_REGISTER, "FDROP: \2%s\2", entity(mu)->name); |
| 175 |
hook_call_user_drop(mu); |
| 176 |
if (!nicksvs.no_nick_ownership) |
| 177 |
{ |
| 178 |
MOWGLI_ITER_FOREACH(n, mu->nicks.head) |
| 179 |
{ |
| 180 |
mn = n->data; |
| 181 |
holdnick_sts(si->service->me, 0, mn->nick, NULL); |
| 182 |
} |
| 183 |
} |
| 184 |
command_success_nodata(si, _("The account \2%s\2 has been dropped."), entity(mu)->name); |
| 185 |
object_dispose(mu); |
| 186 |
} |
| 187 |
|
| 188 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 189 |
* vim:ts=8 |
| 190 |
* vim:sw=8 |
| 191 |
* vim:noexpandtab |
| 192 |
*/ |