Example #1
0
static int userauth(const char *user, const char *password, int gid, int rootfd)
{
	int ret;
	char *pw, *pw_enc;

	if (gid != -1 && (ret = check_gid(user, gid)) != 0)
		return ret;
	ret = get_user_hash(user, gid, &pw);
	if (ret != 0)
		return ret;
	ret = escape_chroot(rootfd);
	if (ret == 0) {
		struct crypt_data data = {};
		ret = VZCTL_E_AUTH;
		pw_enc = crypt_r(password, pw, &data);
		if (pw_enc && !strcmp(pw_enc, pw))
			ret = 0;
	}
	free(pw);
	return ret;
}
Example #2
0
int authenticate_user(const char *user, char *passwd)
{
	hash_digest_t passwd_sig, match_against;
	int i;

	calculate_hash(passwd, passwd_sig);

	memset(match_against, 0 , sizeof(match_against));

#if CONFIG_LIBAUTH_DEFAULT_USER
	if (!strncmp(user, CONFIG_LIBAUTH_DEFAULT_USERNAME, strlen(user))) {
		if (string_to_digest(libs_common_libauth_passwd_data_start,
				     libs_common_libauth_passwd_data_size,
				     (u8 *)&match_against,
				     sizeof(match_against)) != VMM_OK)
			return VMM_EFAIL;

		for (i = 0; i < HASH_LEN; i++) {
			if (match_against[i] != passwd_sig[i]) {
				return VMM_EFAIL;
			}
		}

		return VMM_OK;
	}
#endif

	if (get_user_hash(user,
		(u8 *)&match_against, sizeof(match_against)) == VMM_OK) {
		for (i = 0; i < HASH_LEN; i++) {
			if (match_against[i] != passwd_sig[i]) {
				return VMM_EFAIL;
			}
		}

		return VMM_OK;
	}

	return VMM_EFAIL;
}