// Copyright 1997 The Open Group Research Institute.  All rights reserved.

package krb4.lib;

import java.util.Hashtable;

//Constants and other defined values

public class Krb4 {

	/* Kerberos protocol version number */
	public static final int KRB_PROT_VERSION = 4;

	/* KDC port */
	public static final int KRB_PORT = 750;

	/* The maximum sizes for aname, realm, sname, and instance +1 */
	public static final int NAME_SZ = 40;

	/* TGS name */
	public static final String TICKET_GRANTING_TICKET = "krbtgt";

	/* Message types */
	public static final int AUTH_MSG_KDC_REQUEST			= 1;
	public static final int AUTH_MSG_KDC_REPLY				= 2;
	public static final int AUTH_MSG_APPL_REQUEST			= 3;
	public static final int AUTH_MSG_APPL_REQUEST_MUTUAL	= 4;
	public static final int AUTH_MSG_ERR_REPLY				= 5;
	public static final int AUTH_MSG_PRIVATE				= 6;
	public static final int AUTH_MSG_SAFE					= 7;
	public static final int AUTH_MSG_APPL_ERR				= 8;
	public static final int AUTH_MSG_DIE					= 63;


	/* Default ticket lifetime */
	public static final int DEFAULT_TKT_LIFE	= 120;   /* default lifetime 10 hrs */

	/* Definitions for send_to_kdc */
	public static final int CLIENT_KRB_TIMEOUT	= 4;   /* time between retries */
	public static final int CLIENT_KRB_RETRY	= 5;   /* retry this many times */
	public static final int CLIENT_KRB_BUFLEN	= 512; /* max unfragmented packet */

	/* Parameters for rd_ap_req */
	/* Maximum allowable clock skew in seconds */
	public static final int CLOCK_SKEW = 5*60;

	/* Error codes returned from the KDC */
	public static final int KDC_OK			= 0;	/* Request OK */
	public static final int KDC_NAME_EXP	= 1;	/* Principal expired */
	public static final int KDC_SERVICE_EXP	= 2;	/* Service expired */
	public static final int KDC_AUTH_EXP	= 3;	/* Auth expired */
	public static final int KDC_PKT_VER		= 4;	/* Protocol version unknown */
	public static final int KDC_P_MKEY_VER	= 5;	/* Wrong master key version */
	public static final int KDC_S_MKEY_VER 	= 6;	/* Wrong master key version */
	public static final int KDC_BYTE_ORDER	= 7;	/* Byte order unknown */
	public static final int KDC_PR_UNKNOWN	= 8;	/* Principal unknown */
	public static final int KDC_PR_N_UNIQUE = 9;	/* Principal not unique */
	public static final int KDC_NULL_KEY	= 10;	/* Principal has null key */
	public static final int KDC_GEN_ERR		= 20;	/* Generic error from KDC */


	/* Values returned by get_credentials */
	public static final int GC_OK			= 0;	/* Retrieve OK */
	public static final int GC_TKFIL		= 21;	/* Can't read ticket file */
	public static final int GC_NOTKT		= 22;	/* Can't find ticket or TGT */


	/* Values returned by mk_ap_req	 */
	public static final int MK_AP_OK		= 0;	/* Success */
	public static final int MK_AP_TGTEXP	= 26;	/* TGT Expired */

	/* Values returned by rd_ap_req */
	public static final int RD_AP_OK		= 0;	/* Request authentic */
	public static final int RD_AP_UNDEC		= 31;	/* Can't decode authenticator */
	public static final int RD_AP_EXP		= 32;	/* Ticket expired */
	public static final int RD_AP_NYV		= 33;	/* Ticket not yet valid */
	public static final int RD_AP_REPEAT	= 34;	/* Repeated request */
	public static final int RD_AP_NOT_US	= 35;	/* The ticket isn't for us */
	public static final int RD_AP_INCON		= 36;	/* Request is inconsistent */
	public static final int RD_AP_TIME		= 37;	/* clockskew too big */
	public static final int RD_AP_BADD		= 38;	/* Incorrect net address */
	public static final int RD_AP_VERSION	= 39;	/* protocol version mismatch */
	public static final int RD_AP_MSG_TYPE	= 40;	/* invalid msg type */
	public static final int RD_AP_MODIFIED	= 41;	/* message stream modified */
	public static final int RD_AP_ORDER		= 42;	/* message out of order */
	public static final int RD_AP_UNAUTHOR	= 43;	/* unauthorized request */

	/* Values returned by get_pw_tkt */
	public static final int GT_PW_OK		= 0;	/* Got password changing tkt */
	public static final int GT_PW_NULL		= 51;	/* Current PW is null */
	public static final int GT_PW_BADPW		= 52;	/* Incorrect current password */
	public static final int GT_PW_PROT		= 53;	/* Protocol Error */
	public static final int GT_PW_KDCERR	= 54;	/* Error returned by KDC */
	public static final int GT_PW_NULLTKT	= 55;	/* Null tkt returned by KDC */


	/* Values returned by send_to_kdc */
	public static final int SKDC_OK			= 0;	/* Response received */
	public static final int SKDC_RETRY		= 56;	/* Retry count exceeded */
	public static final int SKDC_CANT		= 57;	/* Can't send request */

	/*
	 * Values returned by get_in_tkt
	 * (can also return SKDC_* and KDC errors)
	 */
	public static final int INTK_OK			= 0;	/* Ticket obtained */
	public static final int INTK_PW_NULL	= 51;	/* Current PW is null */
	public static final int INTK_W_NOTALL	= 61;	/* Not ALL tickets returned */
	public static final int INTK_BADPW		= 62;	/* Incorrect password */
	public static final int INTK_PROT		= 63;	/* Protocol Error */
	public static final int INTK_ERR		= 70;	/* Other error */

	/* Values returned by get_adtkt */
	public static final int AD_OK			= 0;	/* Ticket Obtained */
	public static final int AD_NOTGT		= 71;	/* Don't have tgt */

	/* Error codes returned by ticket file utilities */
	public static final int NO_TKT_FIL		= 76;	/* No ticket file found */
	public static final int TKT_FIL_ACC		= 77;	/* Couldn't access tkt file */
	public static final int TKT_FIL_LCK		= 78;	/* Couldn't lock ticket file */
	public static final int TKT_FIL_FMT		= 79;	/* Bad ticket file format */
	public static final int TKT_FIL_INI		= 80;	/* tf_init not called first */

	/* Error code returned by kparse_name */
	public static final int KNAME_FMT		= 81;	/* Bad Kerberos name format */

	/* Error code returned by krb_mk_safe */
	public static final int SAFE_PRIV_ERROR	= -1;	/* syscall error */

	public static final int REP_NO_DATA			= 900;  //No data provided
	public static final int REP_OVERRUN			= 901;  //End of data reached unexpectedly
	public static final int REP_ORDER_UNKNOWN	= 902;  //Byte order unknown (internal error)
	
	static Hashtable errMsgList;

	static {
		errMsgList = new Hashtable();
		errMsgList.put(new Integer(KDC_OK), "Request OK");
		errMsgList.put(new Integer(KDC_NAME_EXP), "Principal expired");
		errMsgList.put(new Integer(KDC_SERVICE_EXP), "Service expired");
		errMsgList.put(new Integer(KDC_AUTH_EXP), "Auth expired");
		errMsgList.put(new Integer(KDC_PKT_VER), "Protocol version unknown");
		errMsgList.put(new Integer(KDC_P_MKEY_VER), "Wrong master key version");
		errMsgList.put(new Integer(KDC_S_MKEY_VER), "Wrong master key version");
		errMsgList.put(new Integer(KDC_BYTE_ORDER), "Byte order unknown");
		errMsgList.put(new Integer(KDC_PR_UNKNOWN), "Principal unknown");
		errMsgList.put(new Integer(KDC_PR_N_UNIQUE), "Principal not unique");
		errMsgList.put(new Integer(KDC_NULL_KEY), "Principal has null key");
		errMsgList.put(new Integer(KDC_GEN_ERR), "Generic error from KDC");


		/* Values returned by get_credentials */
		errMsgList.put(new Integer(GC_TKFIL), "Can't read ticket file");
		errMsgList.put(new Integer(GC_NOTKT), "Can't find ticket or TGT");


		/* Values returned by mk_ap_req	 */
		errMsgList.put(new Integer(MK_AP_TGTEXP), "TGT Expired");

		/* Values returned by rd_ap_req */
		errMsgList.put(new Integer(RD_AP_UNDEC), "Can't decode authenticator");
		errMsgList.put(new Integer(RD_AP_EXP), "Ticket expired");
		errMsgList.put(new Integer(RD_AP_NYV), "Ticket not yet valid");
		errMsgList.put(new Integer(RD_AP_REPEAT), "Repeated request");
		errMsgList.put(new Integer(RD_AP_NOT_US), "The ticket isn't for us");
		errMsgList.put(new Integer(RD_AP_INCON), "Request is inconsistent");
		errMsgList.put(new Integer(RD_AP_TIME), "clockskew too big");
		errMsgList.put(new Integer(RD_AP_BADD), "Incorrect net address");
		errMsgList.put(new Integer(RD_AP_VERSION), "protocol version mismatch");
		errMsgList.put(new Integer(RD_AP_MSG_TYPE), "invalid msg type");
		errMsgList.put(new Integer(RD_AP_MODIFIED), "message stream modified");
		errMsgList.put(new Integer(RD_AP_ORDER), "message out of order");
		errMsgList.put(new Integer(RD_AP_UNAUTHOR), "unauthorized request");

		/* Values returned by get_pw_tkt */
		errMsgList.put(new Integer(GT_PW_NULL), "Current PW is null");
		errMsgList.put(new Integer(GT_PW_BADPW), "Incorrect current password");
		errMsgList.put(new Integer(GT_PW_PROT), "Protocol Error");
		errMsgList.put(new Integer(GT_PW_KDCERR), "Error returned by KDC");
		errMsgList.put(new Integer(GT_PW_NULLTKT), "Null tkt returned by KDC");


		/* Values returned by send_to_kdc */
		errMsgList.put(new Integer(SKDC_RETRY), "Retry count exceeded");
		errMsgList.put(new Integer(SKDC_CANT), "Can't send request");

		/*
		 * Values returned by get_in_tkt
		 * (can also return SKDC_* and KDC errors)
		 */
		errMsgList.put(new Integer(INTK_W_NOTALL), "Not ALL tickets returned");
		errMsgList.put(new Integer(INTK_BADPW), "Incorrect password");
		errMsgList.put(new Integer(INTK_PROT), "Protocol Error");
		errMsgList.put(new Integer(INTK_ERR), "Other error");

		/* Values returned by get_adtkt */
		errMsgList.put(new Integer(AD_NOTGT), "Don't have tgt");

		/* Error codes returned by ticket file utilities */
		errMsgList.put(new Integer(NO_TKT_FIL), "No ticket file found");
		errMsgList.put(new Integer(TKT_FIL_ACC), "Couldn't access tkt file");
		errMsgList.put(new Integer(TKT_FIL_LCK), "Couldn't lock ticket file");
		errMsgList.put(new Integer(TKT_FIL_FMT), "Bad ticket file format");
		errMsgList.put(new Integer(TKT_FIL_INI), "tf_init not called first");

		/* Error code returned by kparse_name */
		errMsgList.put(new Integer(KNAME_FMT), "Bad Kerberos name format");

		/* Error code returned by krb_mk_safe */
		errMsgList.put(new Integer(SAFE_PRIV_ERROR), "syscall error");

		errMsgList.put(new Integer(REP_NO_DATA), "No data provided");
		errMsgList.put(new Integer(REP_OVERRUN), "End of data reached unexpectedly");
		errMsgList.put(new Integer(REP_ORDER_UNKNOWN), "Byte order unknown (internal error)");
	
	}
}