vaseboot/VasEBoot-core/commands/password.c

94 lines
2.5 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/auth.h>
#include <VasEBoot/crypto.h>
#include <VasEBoot/list.h>
#include <VasEBoot/mm.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/env.h>
#include <VasEBoot/normal.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/i18n.h>
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
static VasEBoot_dl_t my_mod;
static VasEBoot_err_t
check_password (const char *user, const char *entered,
void *password)
{
if (VasEBoot_crypto_memcmp (entered, password, VAS_EBOOT_AUTH_MAX_PASSLEN) != 0)
return VAS_EBOOT_ACCESS_DENIED;
VasEBoot_auth_authenticate (user);
return VAS_EBOOT_ERR_NONE;
}
VasEBoot_err_t
VasEBoot_normal_set_password (const char *user, const char *password)
{
VasEBoot_err_t err;
char *pass;
int copylen;
pass = VasEBoot_zalloc (VAS_EBOOT_AUTH_MAX_PASSLEN);
if (!pass)
return VasEBoot_errno;
copylen = VasEBoot_strlen (password);
if (copylen >= VAS_EBOOT_AUTH_MAX_PASSLEN)
copylen = VAS_EBOOT_AUTH_MAX_PASSLEN - 1;
VasEBoot_memcpy (pass, password, copylen);
err = VasEBoot_auth_register_authentication (user, check_password, pass);
if (err)
{
VasEBoot_free (pass);
return err;
}
VasEBoot_dl_ref (my_mod);
return VAS_EBOOT_ERR_NONE;
}
static VasEBoot_err_t
VasEBoot_cmd_password (VasEBoot_command_t cmd __attribute__ ((unused)),
int argc, char **args)
{
if (argc != 2)
return VasEBoot_error (VAS_EBOOT_ERR_BAD_ARGUMENT, N_("two arguments expected"));
return VasEBoot_normal_set_password (args[0], args[1]);
}
static VasEBoot_command_t cmd;
VAS_EBOOT_MOD_INIT(password)
{
my_mod = mod;
cmd = VasEBoot_register_command ("password", VasEBoot_cmd_password,
N_("USER PASSWORD"),
N_("Set user password (plaintext). "
"Unrecommended and insecure."));
}
VAS_EBOOT_MOD_FINI(password)
{
VasEBoot_unregister_command (cmd);
}