Skip to content

Instantly share code, notes, and snippets.

@kjmancuso
Last active August 29, 2015 13:56
Show Gist options
  • Save kjmancuso/9245472 to your computer and use it in GitHub Desktop.
Save kjmancuso/9245472 to your computer and use it in GitHub Desktop.
/*
* Copyright (c) 2014 Kevin Mancuso
* Rights to this code are as documented in doc/LICENSE.
*
*/
#include "atheme.h"
DECLARE_MODULE_V1
(
"totes/ns_fpass", false, _modinit, _moddeinit,
PACKAGE_STRING,
"Atheme Development Group <http://www.atheme.org>"
);
static void ns_cmd_fpass(sourceinfo_t *si, int parc, char *parv[]);
command_t ns_fpass = { "FPASS", "Sets a precypted password on behalf of another user.", PRIV_USER_ADMIN, 3, ns_cmd_fpass, { .path = "totes/fpass" } };
void _modinit(module_t *m)
{
service_named_bind_command("nickserv", &ns_fpass);
}
void _moddeinit(module_unload_intent_t intent)
{
service_named_unbind_command("nickserv", &ns_fpass);
}
static void ns_cmd_fpass(sourceinfo_t *si, int parc, char *parv[])
{
char *target = parv[0];
char *password = parv[1];
char *crypt = parv[2];
int crypt_f = 0;
myuser_t *mu = si->smu;
if (!strcasecmp(parv[2], "CRYPTPASS"))
{
crypt_f = 1;
}
if (!target || !password)
{
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FPASS");
command_fail(si, fault_needmoreparams, "Syntax: FPASS <account> <pass> [CRYPTPASS]");
return;
}
if (auth_module_loaded)
{
command_fail(si, fault_noprivs, _("You must change the password in the external system."));
return;
}
if (!(mu = myuser_find(target)))
{
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), target);
return;
}
if (crypt_f == 1)
{
logcommand(si, CMDLOG_SET, "FPASS:PASSWORD: \2%s\2 CRYPTED", entity(mu)->name);
mowgli_strlcpy(mu->pass, password, PASSLEN);
}
else
{
logcommand(si, CMDLOG_SET, "FPASS:PASSWORD: \2%s\2", entity(mu)->name);
set_password(mu, password);
}
command_success_nodata(si, _("The password for \2%s\2 has been changed to \2%s\2."), entity(mu)->name, password);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment