| 1 |
pippijn |
1.1 |
/* |
| 2 |
|
|
* Copyright © 2005-2007 William Pitcock, et al. |
| 3 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 4 |
pippijn |
1.1 |
* |
| 5 |
|
|
* This file contains code for the NickServ GHOST function. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.2 |
* $Id: ghost.C,v 1.1 2007-07-19 08:24:54 pippijn Exp $ |
| 8 |
pippijn |
1.1 |
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include "atheme.h" |
| 11 |
|
|
#include <account/mynick.h> |
| 12 |
|
|
#include <account/myuser.h> |
| 13 |
|
|
|
| 14 |
|
|
static char const rcsid[] = "$Id"; |
| 15 |
|
|
|
| 16 |
|
|
struct ns_ghost_listeners : callback::has_listeners |
| 17 |
|
|
{ |
| 18 |
|
|
}; |
| 19 |
|
|
|
| 20 |
|
|
ns_ghost_listeners listeners; |
| 21 |
|
|
|
| 22 |
|
|
DECLARE_MODULE_V1 ("nickserv/ghost", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 23 |
|
|
|
| 24 |
|
|
static void ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[]); |
| 25 |
|
|
|
| 26 |
|
|
command_t ns_ghost = { "GHOST", N_("Reclaims use of a nickname."), AC_NONE, 2, ns_cmd_ghost }; |
| 27 |
|
|
|
| 28 |
|
|
cmdvec *ns_cmdtree; |
| 29 |
|
|
helpvec *ns_helptree; |
| 30 |
|
|
|
| 31 |
|
|
void |
| 32 |
|
|
_modinit (module_t *m) |
| 33 |
|
|
{ |
| 34 |
|
|
MODULE_USE_SYMBOL_T (ns_cmdtree, cmdvec, "nickserv/main", "ns_cmdtree"); |
| 35 |
|
|
MODULE_USE_SYMBOL_T (ns_helptree, helpvec, "nickserv/main", "ns_helptree"); |
| 36 |
|
|
|
| 37 |
|
|
ns_cmdtree << ns_ghost; |
| 38 |
|
|
help_addentry (ns_helptree, "GHOST", "help/nickserv/ghost", NULL); |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
void |
| 42 |
|
|
_moddeinit () |
| 43 |
|
|
{ |
| 44 |
|
|
ns_cmdtree >> ns_ghost; |
| 45 |
|
|
help_delentry (ns_helptree, "GHOST"); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
void |
| 49 |
|
|
ns_cmd_ghost (sourceinfo_t *si, int parc, char *parv[]) |
| 50 |
|
|
{ |
| 51 |
|
|
myuser_t *mu; |
| 52 |
|
|
char *target = parv[0]; |
| 53 |
|
|
char *password = parv[1]; |
| 54 |
|
|
user_t *target_u; |
| 55 |
|
|
mynick_t *mn; |
| 56 |
|
|
|
| 57 |
|
|
if (!target) |
| 58 |
|
|
{ |
| 59 |
|
|
command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "GHOST"); |
| 60 |
|
|
command_fail (si, fault_needmoreparams, _("Syntax: GHOST <target> [password]")); |
| 61 |
|
|
return; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
if (nicksvs.no_nick_ownership) |
| 65 |
|
|
mn = NULL, mu = myuser_find (target); |
| 66 |
|
|
else |
| 67 |
|
|
{ |
| 68 |
|
|
mn = mynick_find (target); |
| 69 |
|
|
mu = mn != NULL ? mn->owner : NULL; |
| 70 |
|
|
} |
| 71 |
|
|
target_u = user_find_named (target); |
| 72 |
|
|
if (!mu && (!target_u || !target_u->myuser)) |
| 73 |
|
|
{ |
| 74 |
|
|
command_fail (si, fault_nosuch_target, _("\2%s\2 is not a registered nickname."), target); |
| 75 |
|
|
return; |
| 76 |
|
|
} |
| 77 |
|
|
|
| 78 |
|
|
if (!target_u) |
| 79 |
|
|
{ |
| 80 |
|
|
command_fail (si, fault_nosuch_target, _("\2%s\2 is not online."), target); |
| 81 |
|
|
return; |
| 82 |
|
|
} |
| 83 |
|
|
else if (target_u == si->su) |
| 84 |
|
|
{ |
| 85 |
|
|
command_fail (si, fault_badparams, _("You may not ghost yourself.")); |
| 86 |
|
|
return; |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
if ((target_u->myuser && target_u->myuser == si->smu) || /* they're identified under our account */ |
| 90 |
|
|
(!nicksvs.no_nick_ownership && mn && mu == si->smu) || /* we're identified under their nick's account */ |
| 91 |
|
|
(!nicksvs.no_nick_ownership && password && mn && verify_password (mu, password))) /* we have their nick's password */ |
| 92 |
|
|
{ |
| 93 |
|
|
/* If we're ghosting an unregistered nick, mu will be unset, |
| 94 |
|
|
* however if it _is_ registered, we still need to set it or |
| 95 |
|
|
* the wrong user will have their last seen time updated... */ |
| 96 |
|
|
if (target_u->myuser && target_u->myuser == si->smu) |
| 97 |
|
|
mu = target_u->myuser; |
| 98 |
|
|
|
| 99 |
|
|
logcommand (si, CMDLOG_DO, "GHOST %s!%s@%s", target_u->nick, target_u->user, target_u->vhost); |
| 100 |
|
|
|
| 101 |
|
|
skill (nicksvs.nick, target, "GHOST command used by %s", si->su != NULL && !strcmp (si->su->user, target_u->user) && !strcmp (si->su->vhost, target_u->vhost) ? si->su->nick : get_source_mask (si)); |
| 102 |
|
|
user_delete (target_u); |
| 103 |
|
|
|
| 104 |
|
|
command_success_nodata (si, _("\2%s\2 has been ghosted."), target); |
| 105 |
|
|
|
| 106 |
|
|
/* don't update the nick's last seen time */ |
| 107 |
|
|
mu->lastlogin = NOW; |
| 108 |
|
|
|
| 109 |
|
|
return; |
| 110 |
|
|
} |
| 111 |
|
|
|
| 112 |
|
|
if (password && mu) |
| 113 |
|
|
{ |
| 114 |
|
|
logcommand (si, CMDLOG_DO, "failed GHOST %s (bad password)", target); |
| 115 |
|
|
command_fail (si, fault_authfail, _("Invalid password for \2%s\2."), mu->name); |
| 116 |
|
|
} |
| 117 |
|
|
else |
| 118 |
|
|
{ |
| 119 |
|
|
logcommand (si, CMDLOG_DO, "failed GHOST %s (invalid login)", target); |
| 120 |
|
|
command_fail (si, fault_noprivs, _("You may not ghost \2%s\2."), target); |
| 121 |
|
|
} |
| 122 |
|
|
} |
| 123 |
|
|
|
| 124 |
|
|
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 125 |
|
|
* vim:ts=8 |
| 126 |
|
|
* vim:sw=8 |
| 127 |
|
|
* vim:noexpandtab |
| 128 |
|
|
*/ |