view src/auth/userinfo-shadow.c @ 804:bf38c8f30a4c HEAD

Added safe_memset() which guarantees that compiler optimizations don't optimize it away. Not that we really need to clear the passwords from memory, but won't hurt much either :)
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Dec 2002 12:40:43 +0200
parents ae9e39383a72
children 5ac361acb316
line wrap: on
line source

/*
   Loosely based on auth_shadow.c from popa3d by
   Solar Designer <solar@openwall.com>

   Copyright (C) 2002 Timo Sirainen
*/

#include "config.h"
#undef HAVE_CONFIG_H

#ifdef USERINFO_SHADOW

#include "userinfo-passwd.h"
#include "mycrypt.h"

#include <shadow.h>

static int shadow_verify_plain(const char *user, const char *password,
			       AuthCookieReplyData *reply)
{
	struct passwd *pw;
	struct spwd *spw;
	char *passdup;
	int result;

	spw = getspnam(user);
	if (spw == NULL || !IS_VALID_PASSWD(spw->sp_pwdp))
		return FALSE;

	/* check if the password is valid */
        passdup = t_strdup_noconst(password);
	result = strcmp(mycrypt(passdup, spw->sp_pwdp), spw->sp_pwdp) == 0;

	/* clear the passwords from memory */
	safe_memset(passdup, 0, strlen(passdup));
	safe_memset(spw->sp_pwdp, 0, strlen(spw->sp_pwdp));

	if (!result)
		return FALSE;

	/* password ok, save the user info */
	pw = getpwnam(user);
	if (pw == NULL)
		return FALSE;

        passwd_fill_cookie_reply(pw, reply);
	return TRUE;
}

static void shadow_deinit(void)
{
	endpwent();
        endspent();
}

UserInfoModule userinfo_shadow = {
	NULL,
	shadow_deinit,

	shadow_verify_plain,
	NULL
};

#endif