Debian Codegraph @

modules/nickserv/ghost.c

raw
1 /*
2 * Copyright (c) 2005-2007 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the NickServ GHOST function.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "nickserv/ghost", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void ns_cmd_ghost(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t ns_ghost = { "GHOST", N_("Reclaims use of a nickname."), AC_NONE, 2, ns_cmd_ghost, { .path = "nickserv/ghost" } };
21
22 void _modinit(module_t *m)
23 {
24 service_named_bind_command("nickserv", &ns_ghost);
25 }
26
27 void _moddeinit(module_unload_intent_t intent)
28 {
29 service_named_unbind_command("nickserv", &ns_ghost);
30 }
31
32 void ns_cmd_ghost(sourceinfo_t *si, int parc, char *parv[])
33 {
34 myuser_t *mu;
35 char *target = parv[0];
36 char *password = parv[1];
37 user_t *target_u;
38 mynick_t *mn;
39
40 if (!target)
41 {
42 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "GHOST");
43 command_fail(si, fault_needmoreparams, _("Syntax: GHOST <target> [password]"));
44 return;
45 }
46
47 if (nicksvs.no_nick_ownership)
48 mn = NULL, mu = myuser_find(target);
49 else
50 {
51 mn = mynick_find(target);
52 mu = mn != NULL ? mn->owner : NULL;
53 }
54
55 target_u = user_find_named(target);
56 if (!target_u)
57 {
58 command_fail(si, fault_nosuch_target, _("\2%s\2 is not online."), target);
59 return;
60 }
61 else if (!mu && !target_u->myuser)
62 {
63 command_fail(si, fault_nosuch_target, _("\2%s\2 is not a registered nickname."), target);
64 return;
65 }
66 else if (target_u == si->su)
67 {
68 command_fail(si, fault_badparams, _("You may not ghost yourself."));
69 return;
70 }
71
72 /* At this point, we're now checking metadata associated with the target's account.
73 * If the target nick is unregistered, mu will be unset thus far. */
74 if (target_u->myuser && !mu)
75 mu = target_u->myuser;
76
77 if (password && metadata_find(mu, "private:freeze:freezer"))
78 {
79 command_fail(si, fault_authfail, "You cannot ghost users as \2%s\2 because the account has been frozen.", entity(mu)->name);
80 logcommand(si, CMDLOG_DO, "failed GHOST \2%s\2 (frozen)", target);
81 return;
82 }
83
84 if (password && (mu->flags & MU_NOPASSWORD))
85 {
86 command_fail(si, fault_authfail, _("Password authentication is disabled for this account."));
87 logcommand(si, CMDLOG_DO, "failed GHOST \2%s\2 (password authentication disabled)", target);
88 return;
89 }
90
91 if ((target_u->myuser && target_u->myuser == si->smu) || /* they're identified under our account */
92 (!nicksvs.no_nick_ownership && mn && mu == si->smu) || /* we're identified under their nick's account */
93 (!nicksvs.no_nick_ownership && password && verify_password(mu, password))) /* we have the correct password */
94 {
95 logcommand(si, CMDLOG_DO, "GHOST: \2%s!%s@%s\2", target_u->nick, target_u->user, target_u->vhost);
96
97 kill_user(si->service->me, target_u, "GHOST command used by %s",
98 si->su != NULL && !strcmp(si->su->user, target_u->user) && !strcmp(si->su->vhost, target_u->vhost) ? si->su->nick : get_source_mask(si));
99
100 command_success_nodata(si, _("\2%s\2 has been ghosted."), target);
101
102 /* Update the account's last seen time.
103 * Perhaps the ghosted nick belonged to someone else, but we were identified to it?
104 * Try this first. */
105 if (target_u->myuser && target_u->myuser == si->smu)
106 target_u->myuser->lastlogin = CURRTIME;
107 else
108 mu->lastlogin = CURRTIME;
109
110 return;
111 }
112
113 if (password)
114 {
115 logcommand(si, CMDLOG_DO, "failed GHOST \2%s\2 (bad password)", target);
116 command_fail(si, fault_authfail, _("Invalid password for \2%s\2."), entity(mu)->name);
117 bad_password(si, mu);
118 }
119 else
120 {
121 logcommand(si, CMDLOG_DO, "failed GHOST \2%s\2 (invalid login)", target);
122 command_fail(si, fault_noprivs, _("You may not ghost \2%s\2."), target);
123 }
124 }
125
126 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
127 * vim:ts=8
128 * vim:sw=8
129 * vim:noexpandtab
130 */