Example #1
0
/*
 * atheme.login
 *
 * XML Inputs:
 *       account name, password, source ip (optional)
 *
 * XML Outputs:
 *       fault 1 - insufficient parameters
 *       fault 3 - account is not registered
 *       fault 5 - invalid username and password
 *       fault 6 - account is frozen
 *       default - success (authcookie)
 *
 * Side Effects:
 *       an authcookie ticket is created for the myuser_t.
 *       the user's lastlogin is updated
 */
static int xmlrpcmethod_login(void *conn, int parc, char *parv[])
{
	myuser_t *mu;
	authcookie_t *ac;
	const char *sourceip;

	if (parc < 2)
	{
		xmlrpc_generic_error(fault_needmoreparams, "Insufficient parameters.");
		return 0;
	}

	sourceip = parc >= 3 && *parv[2] != '\0' ? parv[2] : NULL;

	if (!(mu = myuser_find(parv[0])))
	{
		xmlrpc_generic_error(fault_nosuch_source, "The account is not registered.");
		return 0;
	}

	if (metadata_find(mu, "private:freeze:freezer") != NULL)
	{
		logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, NULL, CMDLOG_LOGIN, "failed LOGIN to \2%s\2 (frozen)", entity(mu)->name);
		xmlrpc_generic_error(fault_noprivs, "The account has been frozen.");
		return 0;
	}

	if (!verify_password(mu, parv[1]))
	{
		sourceinfo_t *si;

		logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, NULL, CMDLOG_LOGIN, "failed LOGIN to \2%s\2 (bad password)", entity(mu)->name);
		xmlrpc_generic_error(fault_authfail, "The password is not valid for this account.");

		si = sourceinfo_create();
		si->service = NULL;
		si->sourcedesc = parv[2] != NULL && *parv[2] ? parv[2] : NULL;
		si->connection = conn;
		si->v = &xmlrpc_vtable;
		si->force_language = language_find("en");

		bad_password(si, mu);

		object_unref(si);

		return 0;
	}

	mu->lastlogin = CURRTIME;

	ac = authcookie_create(mu);

	logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, mu, CMDLOG_LOGIN, "LOGIN");

	xmlrpc_send_string(ac->ticket);

	return 0;
}
Example #2
0
/*
 * atheme.login
 *
 * XML Inputs:
 *       account name, password, source ip (optional)
 *
 * XML Outputs:
 *       fault 1 - insufficient parameters
 *       fault 3 - account is not registered
 *       fault 5 - invalid username and password
 *       fault 6 - account is frozen
 *       default - success (authcookie)
 *
 * Side Effects:
 *       an authcookie ticket is created for the myuser_t.
 *       the user's lastlogin is updated
 */
static int xmlrpcmethod_login(void *conn, int parc, char *parv[])
{
    myuser_t *mu;
    authcookie_t *ac;
    const char *sourceip;

    if (parc < 2)
    {
        xmlrpc_generic_error(fault_needmoreparams, "Insufficient parameters.");
        return 0;
    }

    sourceip = parc >= 3 && *parv[2] != '\0' ? parv[2] : NULL;

    if (!(mu = myuser_find(parv[0])))
    {
        xmlrpc_generic_error(fault_nosuch_source, "The account is not registered.");
        return 0;
    }

    if (metadata_find(mu, "private:freeze:freezer") != NULL)
    {
        logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, NULL, CMDLOG_LOGIN, "failed LOGIN to %s (frozen)", mu->name);
        xmlrpc_generic_error(fault_noprivs, "The account has been frozen.");
        return 0;
    }

    if (!verify_password(mu, parv[1]))
    {
        logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, NULL, CMDLOG_LOGIN, "failed LOGIN to %s (bad password)", mu->name);
        xmlrpc_generic_error(fault_authfail, "The password is not valid for this account.");
        return 0;
    }

    mu->lastlogin = CURRTIME;

    ac = authcookie_create(mu);

    logcommand_external(nicksvs.me, "xmlrpc", conn, sourceip, mu, CMDLOG_LOGIN, "LOGIN");

    xmlrpc_send_string(ac->ticket);

    return 0;
}