*** ./zotnet/mts/client.c.orig	Fri Jul  8 21:56:54 1994
--- ./zotnet/mts/client.c	Fri Jul  8 22:44:04 1994
***************
*** 26,31 ****
--- 26,46 ----
  #include <hesiod.h>
  #endif
  
+ #if defined(KPOP) && defined(K5POP)
+ #error "You cannot define both KPOP and K5POP"
+ #endif
+ #ifdef K5POP
+ #include "krb5.h"
+ /* #include <krb5/ext-proto.h> */
+ /* #include <krb5/los-proto.h> */
+ #include "com_err.h"
+ #include <ctype.h>
+ 
+ static krb5_error_code retval;
+ static krb5_ccache ccdef;
+ static krb5_principal kclient = NULL, kserver = NULL;
+ #endif
+ 
  #ifdef KPOP
  #include <krb.h>
  #include <ctype.h>
***************
*** 75,80 ****
--- 90,98 ----
  static struct addrent *he, *hz;
  static struct addrent hosts[MAXHOSTS];
  
+ #ifdef K5POP
+ static char *kservice;		/* "pop" if using kpop */
+ #endif
  #ifdef KPOP
  char krb_realm[REALM_SZ];
  char *PrincipalHostname();
***************
*** 109,115 ****
      register struct netent *np;
  #endif
      register struct servent *sp;
! #ifdef	KPOP
      char *cp;
  
      if (cp = index (kservice = service, '/')) {	/* "pop/kpop" */
--- 127,133 ----
      register struct netent *np;
  #endif
      register struct servent *sp;
! #if	defined(KPOP) || defined(K5POP)
      char *cp;
  
      if (cp = index (kservice = service, '/')) {	/* "pop/kpop" */
***************
*** 118,129 ****
      }
      else
  	kservice = NULL;	/* not using KERBEROS */
! #endif	/* KPOP */
      
  
      if ((sp = getservbyname (service, protocol)) == NULL) {
  #ifdef	HESIOD
! 	if ((sp = hes_getservbyname (service, protocol)) == NULL) {
  	    (void) sprintf (response, "%s/%s: unknown service",
  		    protocol, service);
  	    return NOTOK;
--- 136,147 ----
      }
      else
  	kservice = NULL;	/* not using KERBEROS */
! #endif	/* KPOP || K5POP */
      
  
      if ((sp = getservbyname (service, protocol)) == NULL) {
  #ifdef	HESIOD
! 	if ((sp = (struct servent *) hes_getservbyname (service, protocol)) == NULL) {
  	    (void) sprintf (response, "%s/%s: unknown service",
  		    protocol, service);
  	    return NOTOK;
***************
*** 206,214 ****
      register struct addrent *ap;
      struct sockaddr_in  in_socket;
      register struct sockaddr_in *isock = &in_socket;
! #ifdef KPOP
      int rem;
! #endif	/* KPOP */
  
      for (ap = nets; ap < ne; ap++)
  	if (ap -> a_addrtype == hp -> h_addrtype && inet (hp, ap -> a_net))
--- 224,232 ----
      register struct addrent *ap;
      struct sockaddr_in  in_socket;
      register struct sockaddr_in *isock = &in_socket;
! #if	defined(KPOP) || defined(K5POP)
      int rem;
! #endif	/* KPOP || K5POP */
  
      for (ap = nets; ap < ne; ap++)
  	if (ap -> a_addrtype == hp -> h_addrtype && inet (hp, ap -> a_net))
***************
*** 252,257 ****
--- 270,328 ----
  		return NOTOK;
  	}
  
+ #ifdef K5POP
+     if (kservice) {	/* "pop" */
+ 	krb5_error *err_ret = NULL;
+ 
+ 	krb5_init_ets();
+ 
+ 	if (retval = krb5_cc_default(&ccdef)) {
+ 	    sprintf(response, "Post office refused connection: krb5_cc_default: %s",
+ 		    error_message(retval));
+ 	    close(sd);
+ 	    return OOPS2;
+ 	}
+ 	if (retval = krb5_cc_get_principal(ccdef, &kclient)) {
+ 	    sprintf(response, "Post office refused connection: krb5_cc_get_principal: %s",
+ 		    error_message(retval));
+ 	    close(sd);
+ 	    return OOPS2;
+ 	}
+ 
+ 	if (retval = krb5_sname_to_principal(hp->h_name, kservice,
+ 					     KRB5_NT_SRV_HST,
+ 					     &kserver)) {
+ 	    sprintf(response, "Post office refused connection: krb5_sname_to_principal: %s",
+ 		    error_message(retval));
+ 	    close(sd);
+ 	    return OOPS2;
+ 	}
+ 
+ 	retval = krb5_sendauth((krb5_pointer) &sd, "KPOPV1.0", kclient, kserver,
+ 			   AP_OPTS_MUTUAL_REQUIRED,
+ 			   0,		/* no checksum */
+ 			   0,		/* no creds, use ccache instead */
+ 			   ccdef,
+ 			   0,		/* don't need seq # */
+ 			   0,		/* don't need a subsession key */
+ 			   &err_ret,
+ 			   0);		/* don't need reply */
+ 	krb5_free_principal(kserver);
+ 	if (retval) {
+ 	    if (err_ret && err_ret->text.length) {
+ 		sprintf(response, "Post office refused connection: %s [server says '%*s'] ",
+ 		        error_message(retval),
+ 		        err_ret->text.length,
+ 		        err_ret->text.data);
+ 		krb5_free_error(err_ret);
+ 	    } else
+ 		sprintf(response, "Post office refused connection: %s",
+ 		        error_message(retval));
+ 	    close(sd);
+ 	    return OOPS2;
+ 	}
+     }
+ #endif /* K5POP */
  #ifdef KPOP
      if (kservice) {	/* "pop" */
  	ticket = (KTEXT)malloc( sizeof(KTEXT_ST) );
***************
*** 298,307 ****
  		: "unknown error");
  	return NOTOK;
      }
! #ifdef KPOP
      if (kservice)	/* "pop" */
  	return(sd);
! #endif	/* KPOP */
      if (!rproto)
  	return sd;
  
--- 369,378 ----
  		: "unknown error");
  	return NOTOK;
      }
! #if	defined(KPOP) || defined(K5POP)
      if (kservice)	/* "pop" */
  	return(sd);
! #endif	/* KPOP || K5POP */
      if (!rproto)
  	return sd;
  
*** ./uip/popsbr.c.orig	Fri Jul  8 21:59:08 1994
--- ./uip/popsbr.c	Fri Jul  8 22:28:00 1994
***************
*** 144,153 ****
  #endif	/* APOP */
  
  #ifndef NNTP
! #ifndef	KPOP
      if ((fd1 = client (host, "tcp", POPSERVICE, rpop, response)) == NOTOK)
  #else	/* KPOP */
      (void) sprintf (buffer, "%s/%s", POPSERVICE, "kpop");
      if ((fd1 = client (host, "tcp", buffer, rpop, response)) == NOTOK)
  #endif
  #else	/* NNTP */
--- 144,158 ----
  #endif	/* APOP */
  
  #ifndef NNTP
! #if	!defined(KPOP) && !defined(K5POP)
      if ((fd1 = client (host, "tcp", POPSERVICE, rpop, response)) == NOTOK)
  #else	/* KPOP */
+ #ifdef K5POP
+     (void) sprintf (buffer, "%s/%s", POPSERVICE, "k5pop");
+ #endif
+ #ifdef KPOP
      (void) sprintf (buffer, "%s/%s", POPSERVICE, "kpop");
+ #endif
      if ((fd1 = client (host, "tcp", buffer, rpop, response)) == NOTOK)
  #endif
  #else	/* NNTP */
***************
*** 177,183 ****
  		fprintf (stderr, "<--- %s\n", response);
  #ifndef	NNTP
  	    if (*response == '+') {
! #ifndef	KPOP
  #ifdef	APOP
  		if (apop < 0) {
  		    char   *cp = pop_auth (user, pass);
--- 182,188 ----
  		fprintf (stderr, "<--- %s\n", response);
  #ifndef	NNTP
  	    if (*response == '+') {
! #if	!defined(KPOP) && !defined(K5POP)
  #ifdef	APOP
  		if (apop < 0) {
  		    char   *cp = pop_auth (user, pass);
***************
*** 191,197 ****
  		    && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
  					pass) != NOTOK)
  		return OK;
! #else	/* KPOP */
  		if (command ("USER %s", user) != NOTOK
  		    && command ("PASS %s", pass) != NOTOK)
  		return OK;
--- 196,202 ----
  		    && command ("%s %s", rpop ? "RPOP" : (pophack++, "PASS"),
  					pass) != NOTOK)
  		return OK;
! #else	/* KPOP || K5POP */
  		if (command ("USER %s", user) != NOTOK
  		    && command ("PASS %s", pass) != NOTOK)
  		return OK;
*** ./uip/inc.c.orig	Fri Jul  8 22:02:16 1994
--- ./uip/inc.c	Fri Jul  8 22:02:35 1994
***************
*** 19,27 ****
  #ifdef	POP
  #include "../h/dropsbr.h"
  #endif
- #ifdef KPOP
- #include <krb.h>
- #endif
  #ifdef HESIOD
  #include <hesiod.h>
  #endif
--- 19,24 ----
*** ./conf/makefiles/uip.orig	Fri Jul  8 22:17:19 1994
--- ./conf/makefiles/uip	Fri Jul  8 22:35:23 1994
***************
*** 84,89 ****
--- 84,92 ----
  @BEGIN: KPOP
  KRBLIB  =       -lkrb -ldes
  @END: KPOP
+ @BEGIN: K5POP
+ KRBLIB  =       -lkrb5 -lcrypto -lisode -lcom_err
+ @END: K5POP
  @BEGIN: BPOP
  PSHLIB	=	popsbr.o
  PSHLLIBS=	popsbr.c 
*** ./conf/mhconfig.c.orig	Fri Jul  8 22:14:14 1994
--- ./conf/mhconfig.c	Fri Jul  8 22:19:37 1994
***************
*** 138,143 ****
--- 138,144 ----
      "APOP", 0,	/* authenticated pop */
      "BSD43", 0,	/* sgid ttys */
      "KPOP", 0, 	/* KERBEROS pop */
+     "K5POP", 0, /* KERBEROS5 pop */
      "HESIOD", 0,
      "MIME", 0,	/* multi-media extensions */
      "MPOP", 0,	/* mobile pop */
