#include <config.h>
#ifdef HAVE_GETPRPWNAM
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#ifdef __hpux
# undef MAXINT
# include <hpsecurity.h>
#else
# include <sys/security.h>
#endif
#include <prot.h>
#include <sudoers.h>
#include "sudo_auth.h"
#ifdef __alpha
extern int crypt_type;
#endif
int
sudo_secureware_init(const struct sudoers_context *ctx, struct passwd *pw,
sudo_auth *auth)
{
debug_decl(sudo_secureware_init, SUDOERS_DEBUG_AUTH);
if (auth->data != NULL)
debug_return_int(AUTH_SUCCESS);
#ifdef __alpha
if (crypt_type == INT_MAX)
debug_return_int(AUTH_FAILURE);
#endif
sudo_setspent();
auth->data = sudo_getepw(pw);
sudo_endspent();
debug_return_int(auth->data ? AUTH_SUCCESS : AUTH_ERROR);
}
int
sudo_secureware_verify(const struct sudoers_context *ctx, struct passwd *pw,
const char *pass, sudo_auth *auth, struct sudo_conv_callback *callback)
{
char *pw_epasswd = auth->data;
char *epass = NULL;
debug_decl(sudo_secureware_verify, SUDOERS_DEBUG_AUTH);
if (pass[0] == '\0')
debug_return_int(pw_epasswd[0] ? AUTH_FAILURE : AUTH_SUCCESS);
#if defined(__alpha)
# ifdef HAVE_DISPCRYPT
epass = dispcrypt(pass, pw_epasswd, crypt_type);
# else
if (crypt_type == AUTH_CRYPT_BIGCRYPT)
epass = bigcrypt(pass, pw_epasswd);
else if (crypt_type == AUTH_CRYPT_CRYPT16)
epass = crypt(pass, pw_epasswd);
# endif
#elif defined(HAVE_BIGCRYPT)
epass = bigcrypt(pass, pw_epasswd);
#endif
if (epass != NULL && strcmp(pw_epasswd, epass) == 0)
debug_return_int(AUTH_SUCCESS);
debug_return_int(AUTH_FAILURE);
}
int
sudo_secureware_cleanup(const struct sudoers_context *ctx, struct passwd *pw,
sudo_auth *auth, bool force)
{
char *pw_epasswd = auth->data;
debug_decl(sudo_secureware_cleanup, SUDOERS_DEBUG_AUTH);
if (pw_epasswd != NULL)
freezero(pw_epasswd, strlen(pw_epasswd));
debug_return_int(AUTH_SUCCESS);
}
#endif