| 1 |
/* |
| 2 |
* Copyright (c) 2006 Stephen Bennett |
| 3 |
* Copyright (c) 2008 Atheme Development Group |
| 4 |
* Rights to this code are documented in doc/LICENSE. |
| 5 |
* |
| 6 |
* This file contains functionality which implements the OService IDENTIFY command. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "atheme.h" |
| 10 |
|
| 11 |
DECLARE_MODULE_V1 |
| 12 |
( |
| 13 |
"operserv/identify", false, _modinit, _moddeinit, |
| 14 |
PACKAGE_STRING, |
| 15 |
VENDOR_STRING |
| 16 |
); |
| 17 |
|
| 18 |
static void os_cmd_identify(sourceinfo_t *si, int parc, char *parv[]); |
| 19 |
|
| 20 |
command_t os_identify = { "IDENTIFY", N_("Authenticate for services operator privileges."), AC_AUTHENTICATED, 1, os_cmd_identify, { .path = "oservice/identify" } }; |
| 21 |
command_t os_id = { "ID", N_("Alias for IDENTIFY"), AC_AUTHENTICATED, 1, os_cmd_identify, { .path = "oservice/identify" } }; |
| 22 |
|
| 23 |
void _modinit(module_t *m) |
| 24 |
{ |
| 25 |
service_named_bind_command("operserv", &os_identify); |
| 26 |
service_named_bind_command("operserv", &os_id); |
| 27 |
} |
| 28 |
|
| 29 |
void _moddeinit(module_unload_intent_t intent) |
| 30 |
{ |
| 31 |
service_named_unbind_command("operserv", &os_identify); |
| 32 |
service_named_unbind_command("operserv", &os_id); |
| 33 |
} |
| 34 |
|
| 35 |
static bool verify_operserv_password(soper_t *so, char *password) |
| 36 |
{ |
| 37 |
if (so == NULL || password == NULL) |
| 38 |
return false; |
| 39 |
|
| 40 |
return crypt_verify_password(password, so->password) != NULL; |
| 41 |
} |
| 42 |
|
| 43 |
static void os_cmd_identify(sourceinfo_t *si, int parc, char *parv[]) |
| 44 |
{ |
| 45 |
/* XXX use this with authcookie also */ |
| 46 |
if (si->su == NULL) |
| 47 |
{ |
| 48 |
command_fail(si, fault_noprivs, _("\2%s\2 can only be executed via IRC."), "IDENTIFY"); |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
if (parc < 1) |
| 53 |
{ |
| 54 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "IDENTIFY"); |
| 55 |
command_fail(si, fault_needmoreparams, _("Syntax: IDENTIFY <password>")); |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
if (!is_soper(si->smu)) |
| 60 |
{ |
| 61 |
command_fail(si, fault_noprivs, _("You do not have a services operator account.")); |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if (si->smu->soper->password == NULL) |
| 66 |
{ |
| 67 |
command_fail(si, fault_nochange, _("Your services operator account does not have a password set.")); |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
if (si->su->flags & UF_SOPER_PASS) |
| 72 |
{ |
| 73 |
command_fail(si, fault_nochange, _("You are already identified to %s."), si->service->nick); |
| 74 |
return; |
| 75 |
} |
| 76 |
|
| 77 |
if (!verify_operserv_password(si->smu->soper, parv[0])) |
| 78 |
{ |
| 79 |
command_fail(si, fault_authfail, _("Invalid password.")); |
| 80 |
logcommand(si, CMDLOG_ADMIN, "failed IDENTIFY (bad password)"); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
si->su->flags |= UF_SOPER_PASS; |
| 85 |
command_success_nodata(si, _("You are now identified to %s."), |
| 86 |
si->service->nick); |
| 87 |
logcommand(si, CMDLOG_ADMIN, "IDENTIFY"); |
| 88 |
} |
| 89 |
|
| 90 |
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 91 |
* vim:ts=8 |
| 92 |
* vim:sw=8 |
| 93 |
* vim:noexpandtab |
| 94 |
*/ |