/* charon.c -- This source is for the program "charon", a client of the
 * charon initialization.  This is a stream buffer that assumes that
 * given no arguments it will get charon input from the server on stdin
 * and output charon protocol on stdout.  The User's password is obtained
 * from /dev/tty.
 *
 * Created by:	Derek Atkins <warlord@MIT.EDU>
 *
 * $Source: /afs/net.mit.edu/user/warlord/Thesis/src/charon/RCS/charon.c,v $
 * $Author: warlord $
 *
 */

#include <warlord-copyright.h>

#if !defined(lint) && !defined(SABER)
static char charon_c[] = "$Id: charon.c,v 1.2 93/12/11 15:09:45 warlord Exp Locker: warlord $";
#endif

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <krb.h>
#include <charon.h>

static void *tty_state = NULL;

/* If we get a signal, we should do this, so that we can exit
 * cleanly.
 */
int
error_exit()
{
  crn_revert_echo(tty_state);
  exit(1);
}

main(int argc, char *argv[])
{
    int retval;

    /* Turn off echoing */
    tty_state = crn_kill_echo(0);

    /* trap a lot of signals */
    signal(SIGHUP, error_exit);
    signal(SIGINT, error_exit);
    signal(SIGQUIT, error_exit);
    signal(SIGKILL, error_exit);
    signal(SIGTERM, error_exit);

    /* Initiate the protocol */
    if ((retval = crn_cli_get_tickets(0, NULL, 0, 0)) != CRN_OK)
	fprintf(stderr, "%s\n", crn_err_msg(retval));

    /* Turn on echoing */
    crn_revert_echo(tty_state);

    return(0);
}
