/*
 * $Id: pam_krb4_auth.-c,v 1.1 1997/07/18 16:38:13 warlord Exp $
 * 
 * $Log: pam_krb4_auth.-c,v $
 * Revision 1.1  1997/07/18 16:38:13  warlord
 * Initial revision based on Derrick Brashear's Krb4 PAM Module
 *
 * Revision 1.1  1996/08/29 13:27:51  shadow
 * Initial revision
 *
 *
 * See end of file for Copyright information.
 */

static const char rcsid_auth[] =
"$Id: pam_krb4_auth.-c,v 1.1 1997/07/18 16:38:13 warlord Exp $\n"
" - pam_krb4 authentication functions. <shadow@dementia.org>";

/*
 * _krb4_auth() is a front-end for KRB4 authentication
 *
 *	First, obtain the password from the user. Then use a
 *      routine in 'support.-c' to authenticate the user.
 */

#define _KRB4_AUTHTOK  "-KRB4-PASS"

static int _krb4_auth(pam_handle_t *pamh, unsigned int ctrl)
{
     int retval;
     const char *name, *p;

     /* get the user'name' */

     if ( (retval = _krb4_get_user( pamh, ctrl, NULL, &name) )
	  != PAM_SUCCESS ) {
	  if ( on(KRB4_DEBUG,ctrl) ) {
	       _log_err(LOG_DEBUG, "auth could not identify user");
	  }
	  return retval;
     }

     /* get this user's authentication token */

     if ( (retval = _krb4_read_password(pamh, ctrl
					, NULL, "Password: ", NULL
					, _KRB4_AUTHTOK, &p))
	  != PAM_SUCCESS ) {
	  _log_err(LOG_CRIT, "auth could not identify password for [%s]"
	       , name);
	  name = NULL;
	  return retval;
     }

     /* verify the password of this user */

     retval = _krb4_verify_password(pamh, name, p, ctrl);
     name = p  = NULL;

     return retval;
}

static int _krb4_set_credentials(pam_handle_t *pamh, unsigned int ctrl)
{	
  return (_krb4_set_cred(pamh, ctrl));
}

/********************************************************************
 * Copyright (c) Alexander O. Yuriev, 1996.
 * Copyright (c) Andrew G. Morgan <morgan@physics.ucla.edu> 1996
 * Copyright (c) Cristian Gafton <gafton@sorosis.ro> 1996
 * Copyright (c) Derrick J Brashear <shadow@dementia.org> 1996
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, and the entire permission notice in its entirety,
 *    including the disclaimer of warranties.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.
 * 
 * ALTERNATIVELY, this product may be distributed under the terms of
 * the GNU Public License, in which case the provisions of the GPL are
 * required INSTEAD OF the above restrictions.  (This clause is
 * necessary due to a potential bad interaction between the GPL and
 * the restrictions contained in a BSD-style copyright.)
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
