| 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 CService LOGOUT functions. |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
DECLARE_MODULE_V1 |
| 12 |
( |
| 13 |
"nickserv/logout", false, _modinit, _moddeinit, |
| 14 |
PACKAGE_STRING, |
| 15 |
VENDOR_STRING |
| 16 |
); |
| 17 |
|
| 18 |
static void ns_cmd_logout(sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
|
| 20 |
command_t ns_logout = { "LOGOUT", N_("Logs your services session out."), AC_NONE, 2, ns_cmd_logout, { .path = "nickserv/logout" } }; |
| 21 |
|
| 22 |
void _modinit(module_t *m) |
| 23 |
{ |
| 24 |
service_named_bind_command("nickserv", &ns_logout); |
| 25 |
} |
| 26 |
|
| 27 |
void _moddeinit(module_unload_intent_t intent) |
| 28 |
{ |
| 29 |
service_named_unbind_command("nickserv", &ns_logout); |
| 30 |
} |
| 31 |
|
| 32 |
static void ns_cmd_logout(sourceinfo_t *si, int parc, char *parv[]) |
| 33 |
{ |
| 34 |
user_t *u = si->su; |
| 35 |
mowgli_node_t *n, *tn; |
| 36 |
mynick_t *mn; |
| 37 |
char *user = parv[0]; |
| 38 |
char *pass = parv[1]; |
| 39 |
|
| 40 |
if ((!si->smu) && (!user || !pass)) |
| 41 |
{ |
| 42 |
command_fail(si, fault_nochange, _("You are not logged in.")); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
if (user) |
| 47 |
{ |
| 48 |
u = user_find(user); |
| 49 |
|
| 50 |
if (!u) |
| 51 |
{ |
| 52 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not online."), user); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
if (!u->myuser) |
| 57 |
{ |
| 58 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not logged in."), user); |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
if (u->myuser == si->smu || (pass != NULL && verify_password(u->myuser, pass))) |
| 63 |
notice(nicksvs.nick, u->nick, "You were logged out by \2%s\2.", si->su->nick); |
| 64 |
else if (pass != NULL) |
| 65 |
{ |
| 66 |
logcommand(si, CMDLOG_LOGIN, "failed LOGOUT \2%s\2 (bad password)", u->nick); |
| 67 |
command_fail(si, fault_authfail, _("Authentication failed. Invalid password for \2%s\2."), entity(u->myuser)->name); |
| 68 |
bad_password(si, u->myuser); |
| 69 |
return; |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
command_fail(si, fault_authfail, _("You may not log out \2%s\2."), u->nick); |
| 74 |
return; |
| 75 |
} |
| 76 |
} |
| 77 |
else if (si->su == NULL) |
| 78 |
{ |
| 79 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "LOGOUT"); |
| 80 |
command_fail(si, fault_needmoreparams, _("Syntax: LOGOUT <target> <password>")); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
if (is_soper(u->myuser)) |
| 86 |
logcommand(si, CMDLOG_ADMIN, "DESOPER: \2%s\2 as \2%s\2", u->nick, entity(u->myuser)->name); |
| 87 |
|
| 88 |
if (si->su != u) |
| 89 |
{ |
| 90 |
logcommand(si, CMDLOG_LOGIN, "LOGOUT: \2%s\2", u->nick); |
| 91 |
command_success_nodata(si, _("\2%s\2 has been logged out."), u->nick); |
| 92 |
} |
| 93 |
else |
| 94 |
{ |
| 95 |
logcommand(si, CMDLOG_LOGIN, "LOGOUT"); |
| 96 |
command_success_nodata(si, _("You have been logged out.")); |
| 97 |
} |
| 98 |
|
| 99 |
u->myuser->lastlogin = CURRTIME; |
| 100 |
mn = mynick_find(u->nick); |
| 101 |
if (mn != NULL && mn->owner == u->myuser) |
| 102 |
mn->lastseen = CURRTIME; |
| 103 |
|
| 104 |
if (!ircd_on_logout(u, entity(u->myuser)->name)) |
| 105 |
{ |
| 106 |
MOWGLI_ITER_FOREACH_SAFE(n, tn, u->myuser->logins.head) |
| 107 |
{ |
| 108 |
if (n->data == u) |
| 109 |
{ |
| 110 |
mowgli_node_delete(n, &u->myuser->logins); |
| 111 |
mowgli_node_free(n); |
| 112 |
break; |
| 113 |
} |
| 114 |
} |
| 115 |
u->myuser = NULL; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 120 |
* vim:ts=8 |
| 121 |
* vim:sw=8 |
| 122 |
* vim:noexpandtab |
| 123 |
*/ |