/*
 * $Id: pam_krb4.c,v 1.2 1997/07/18 17:20:12 warlord Exp $
 *
 * This is the single file that will be compiled for pam_krb4.
 * it includes each of the modules that have beed defined in the .-c
 * files in this directory.
 *
 * See the end of this file for Copyright information.
 */

/*
 * $Log: pam_krb4.c,v $
 * Revision 1.2  1997/07/18 17:20:12  warlord
 * Fixed Makefile for Athenaisms; look for Kerberos in different places,
 * and fix some missing symbols (probably due to Kerberos v4 differences)
 *
 * Revision 1.1  1997/07/18 16:38:12  warlord
 * Initial revision based on Derrick Brashear's Krb4 PAM Module
 *
 *
 * Revision 1.1  1996/11/05 13:22:19  shadow
 * Initial revision
 *
 */

static const char rcsid[] =
"$Id: pam_krb4.c,v 1.2 1997/07/18 17:20:12 warlord Exp $\n"
" - Kerberos 4 Pluggable Authentication module. <shadow@dementia.org>"
;

#include <sys/types.h>
#include <sys/param.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#define __USE_MISC      /* for get/set/endpwent */
#include <pwd.h>
#include <time.h>	/* for time() */
#include <fcntl.h>

#define _SVID_SOURCE
#define __USE_BSD
#include <sys/time.h>
#include <unistd.h>

/* indicate the following groups are defined */

#define PAM_SM_AUTH
#define PAM_SM_SESSION
#define PAM_SM_PASSWORD

#include <security/pam_modules.h>

#ifndef LINUX 
#include <security/pam_appl.h>
#endif  /* LINUX */

#include <netinet/in.h>
#include <netdb.h>		/* struct hostent */
#include <kadm.h>
#include <kadm_err.h>
#include <krb.h>

#ifdef DEBUG
#define D(x) { \
     _debug_pam("[%s:%s(%d)] ", __FILE__, __FUNCTION__, __LINE__) ; \
     _debug_pam x ; \
}
#else
#define D(x)
#endif

#include "./support.-c"

/*
 * PAM framework looks for these entry-points to pass control to the
 * authentication module.
 */

#include "./pam_krb4_auth.-c"

PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, 
				   int flags,
				   int argc, 
				   const char **argv)
{
     unsigned int ctrl;

     D(("called.\n"));
     ctrl = set_ctrl(flags, argc, argv);
     return _krb4_auth( pamh, ctrl );
}

PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, 
			      int flags,
			      int argc, 
			      const char **argv)
{
     unsigned int ctrl;

     D(("called.\n"));
     ctrl = set_ctrl(flags, argc, argv);
     return _krb4_set_credentials(pamh, ctrl) ;
}

/*
 * PAM framework looks for these entry-points to pass control to the
 * session module.
 */
 
#include "./pam_krb4_sess.-c"

PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh, int flags,
				   int argc, const char **argv)
{
     unsigned int ctrl;

     D(("called.\n"));
     ctrl = set_ctrl(flags, argc, argv);
     return _krb4_open_session(pamh, ctrl);
}

PAM_EXTERN int pam_sm_close_session(pam_handle_t *pamh, int flags,
				    int argc, const char **argv)
{
     unsigned int ctrl;

     D(("called.\n"));
     ctrl = set_ctrl(flags, argc, argv);
     return _krb4_close_session(pamh, ctrl);
}

/*
 * PAM framework looks for these entry-points to pass control to the
 * password changing module.
 */
 
#include "./pam_krb4_passwd.-c"

PAM_EXTERN int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
				int argc, const char **argv)
{
     unsigned int ctrl;

     D(("called.\n"));
     ctrl = set_ctrl(flags, argc, argv);
     return _krb4_chauthtok(pamh, ctrl);
}

/* static module data */

#ifdef PAM_STATIC
struct pam_module _pam_krb4_modstruct = {
     "pam_krb4",
     pam_sm_authenticate,
     pam_sm_setcred,
     NULL,
     pam_sm_open_session,
     pam_sm_close_session,
     pam_sm_chauthtok
};

#endif

/*
 * Copyright (c) Derrick J. Brashear, 1996. All rights reserved
 *
 * 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.
 */
