[864] in Kerberos-V5-bugs

home help back first fref pref prev next nref lref last post

rlogin posix signals and axp support for encryption

daemon@ATHENA.MIT.EDU (epeisach@MIT.EDU)
Sat Oct 15 08:41:55 1994

From: epeisach@MIT.EDU
Date: Sat, 15 Oct 1994 08:41:50 -0400
To: krb5-bugs@MIT.EDU


rlogin needs posixized signals on the alpha when the oob data comes in
requesting that the window size be sent, the signal handling needs to
know that it should restart the interrupted system call (read in this
case). For non-encrypted rlogin, this is ok, for encrypted, it screws up
the streams. (notice the SA_RESTART in the oob code). I am suprised
that everything worked on the Sun, as the SA_RESTART had to be added to
the zhm code at one time for proper signal handling, but maybe it is a
timing issue.

I also noticed that longjmp was being used from within a signal handler.
(oob). Technically speaking, siglongjmp should be used in this case.
This did not break anything for me, but I coded it in for future
generations. (this required a change to configure.in to check for the
presence of said functions).

The 64 bit code handling on rlogin/rlogind assumed big endian in sending
over length field.... This was a crock, and I replace the longs with
krb5_ui_4 (for an unsigned 4 byte entity) and removed the BITS64 stuff. 
I am not familiar with a cray, so I cannot say what htonl will do with a
64 bit quantity - does it really take a long or a 32 bit int? On the
AXP, htonl takes an unsigned int (i.e. 32 bits). So that is the over
cleanup. 

For rlogin.c, I tried to be semi elegant in how I handled the signal
code, defining Psignal (for posix signal), assuming that PInit was
called somewhere else to initialize the sigaction structure.... In the
oob case, I set the flag bits specially. There was one place where I
I put in the sigactions manually, but that was because the old signal
handler value was important...

(Oh yeah, the rlogind char/unsigned char stuff is still in this patch
awaiting reconcilization).

There are other signals in the bsd applications that can be fixed, but I
didn't feel like it right now.

	Ezra

===================================================================
RCS file: /mit/krb5/.cvsroot/src/appl/bsd/configure.in,v
retrieving revision 5.21
diff -c -r5.21 configure.in
*** 5.21	1994/09/29 21:57:40
--- configure.in	1994/10/15 12:13:17
***************
*** 32,37 ****
--- 32,38 ----
  AC_FUNC_CHECK(setpriority,AC_DEFINE(HAVE_SETPRIORITY))
  AC_FUNC_CHECK(setreuid,AC_DEFINE(HAVE_SETREUID))
  AC_FUNC_CHECK(setresuid,AC_DEFINE(HAVE_SETRESUID))
+ AC_FUNC_CHECK(siglongjmp,AC_DEFINE(HAVE_SIGLONGJMP))
  dnl if srand48 is there, use it (krlogind needs it)
  AC_FUNC_CHECK(srand48,AC_DEFINE(srandom,srand48) AC_DEFINE(random,lrand48))
  AC_FUNC_CHECK(sigprocmask,
===================================================================
RCS file: /mit/krb5/.cvsroot/src/appl/bsd/krlogind.c,v
retrieving revision 5.23
diff -c -r5.23 krlogind.c
*** 5.23	1994/09/30 21:07:13
--- krlogind.c	1994/10/15 12:22:35
***************
*** 241,252 ****
  krb5_authenticator      *kdata;
  krb5_ticket     *ticket = 0;
  
- #ifdef CRAY
- #ifndef BITS64
- #define BITS64
- #endif
- #endif
- 
  #define ARGSTR	"rRkKeExXpPD:?"
  #else /* !KERBEROS */
  #define ARGSTR	"rRpPD:?"
--- 241,246 ----
***************
*** 888,894 ****
  protocol(f, p)
       int f, p;
  {
!     char pibuf[1024], fibuf[1024], *pbp, *fbp;
      register pcc = 0, fcc = 0;
      int cc;
      char cntl;
--- 882,888 ----
  protocol(f, p)
       int f, p;
  {
!     unsigned char pibuf[1024], fibuf[1024], *pbp, *fbp;
      register pcc = 0, fcc = 0;
      int cc;
      char cntl;
***************
*** 944,950 ****
  	    if (fcc < 0 && errno == EWOULDBLOCK)
  	      fcc = 0;
  	    else {
! 		register char *cp;
  		int left, n;
  		
  		if (fcc <= 0)
--- 938,944 ----
  	    if (fcc < 0 && errno == EWOULDBLOCK)
  	      fcc = 0;
  	    else {
! 		register unsigned char *cp;
  		int left, n;
  		
  		if (fcc <= 0)
***************
*** 1218,1224 ****
       int len;
  {
      int nreturned = 0;
!     long net_len,rd_len;
      int cc,retry;
      
      if (!do_encrypt)
--- 1212,1218 ----
       int len;
  {
      int nreturned = 0;
!     krb5_ui_4 net_len,rd_len;
      int cc,retry;
      
      if (!do_encrypt)
***************
*** 1237,1249 ****
  	nstored = 0;
      }
      
- #ifdef BITS64
-     rd_len = 0;
-     if ((cc = krb5_net_read(fd, (char *)&rd_len + 4, 4)) != 4) {
- #else	
      if ((cc = krb5_net_read(fd, (char *)&rd_len, sizeof(rd_len))) !=
  	sizeof(rd_len)) {
- #endif
  	if ((cc < 0)  && (errno == EWOULDBLOCK)) return(cc);
  	/* XXX can't read enough, pipe
  	   must have closed */
--- 1231,1238 ----
***************
*** 1308,1314 ****
       char *buf;
       int len;
  {
!     long net_len;
      
      if (!do_encrypt)
        return(write(fd, buf, len));
--- 1297,1303 ----
       char *buf;
       int len;
  {
!     krb5_ui_4 net_len;
      
      if (!do_encrypt)
        return(write(fd, buf, len));
***************
*** 1329,1339 ****
      }
      
      net_len = htonl(len);	
- #ifdef BITS64
-     (void) write(fd,(char *)&net_len + 4, 4);
- #else
      (void) write(fd, &net_len, sizeof(net_len));
- #endif
      if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
  	syslog(LOG_ERR,"Could not write out all data.");
  	return(-1);
--- 1318,1324 ----
***************
*** 1599,1605 ****
  int len;
  {
  	int nreturned = 0;
! 	long net_len, rd_len;
  	int cc;
  
  	if (!do_encrypt)
--- 1584,1590 ----
  int len;
  {
  	int nreturned = 0;
! 	krb5_ui_4 net_len, rd_len;
  	int cc;
  
  	if (!do_encrypt)
***************
*** 1672,1678 ****
  char *buf;
  int len;
  {
! 	long net_len;
  	static int seeded = 0;
  	static char garbage_buf[8];
  	long garbage;
--- 1657,1663 ----
  char *buf;
  int len;
  {
! 	krb5_ui_4 net_len;
  	static int seeded = 0;
  	static char garbage_buf[8];
  	long garbage;
===================================================================
RCS file: /mit/krb5/.cvsroot/src/appl/bsd/krlogin.c,v
retrieving revision 5.14
diff -c -r5.14 krlogin.c
*** 5.14	1994/09/29 21:57:36
--- krlogin.c	1994/10/15 12:31:03
***************
*** 158,169 ****
  
  #define      UCB_RLOGIN      "/usr/ucb/rlogin"
  
- #ifdef CRAY
- #ifndef BITS64
- #define BITS64
- #endif
- #endif
- 
  #include "rpaths.h"
  #else /* !KERBEROS */
  #define des_read read
--- 158,163 ----
***************
*** 175,180 ****
--- 169,183 ----
  # define TIOCPKT_WINDOW 0x80
  # endif /* TIOCPKT_WINDOW */
  
+ #ifdef POSIX_SIGNALS
+ static struct sigaction sa;
+ #define Psignal(sig, value) { \
+ 	sa.sa_handler = value; \
+ 	(void) sigaction(sig, &sa, (struct sigaction *)0); \
+ 	}
+ #define InitPsignal {sa.sa_flags=0; (void) sigemptyset(&sa.sa_mask); }
+ #endif
+ 
  char	*getenv();
  char	*name;
  int 	rem = -1;		/* Remote socket fd */
***************
*** 318,324 ****
      krb5_error_code status;
      int debug_port = 0;
  #endif /* KERBEROS */
!    
      if (strrchr(argv[0], '/'))
        argv[0] = strrchr(argv[0], '/')+1;
  
--- 321,330 ----
      krb5_error_code status;
      int debug_port = 0;
  #endif /* KERBEROS */
! 
! #ifdef POSIX_SIGNALS
!     InitPsignal;
! #endif
      if (strrchr(argv[0], '/'))
        argv[0] = strrchr(argv[0], '/')+1;
  
***************
*** 777,784 ****
--- 783,795 ----
       * the reader.  Set a trap that simply copies such signals to
       * the child.
       */
+ #ifdef POSIX_SIGNALS
+     Psignal(SIGURG, copytochild);
+     Psignal(SIGUSR1, writeroob);
+ #else
      (void) signal(SIGURG, copytochild);
      (void) signal(SIGUSR1, writeroob);
+ #endif
  
  #ifdef POSIX_SIGNALS
      sigprocmask(SIG_SETMASK, oldmask, (sigset_t*)0);
***************
*** 804,809 ****
--- 815,821 ----
  {
  #ifdef POSIX_SIGNALS
      sigset_t omask, igmask;
+     static struct sigaction osa, nsa;
      sigemptyset(&igmask);
      sigaddset(&igmask, sig);
      sigprocmask(SIG_BLOCK, &igmask, &omask);
***************
*** 815,825 ****
  #endif
  #endif /* POSIX_SIGNALS */
      
-     if (signal(sig, act) == SIG_IGN)
-       (void) signal(sig, SIG_IGN);
  #ifdef POSIX_SIGNALS
      sigprocmask(SIG_SETMASK, &omask, (sigset_t*)0);
  #else    
  #ifndef sgi
      (void) sigsetmask(omask);
  #endif
--- 827,843 ----
  #endif
  #endif /* POSIX_SIGNALS */
      
  #ifdef POSIX_SIGNALS
+     (void) sigemptyset(&nsa.sa_mask);
+     nsa.sa_flags = 0;
+     nsa.sa_handler = act;
+     (void) sigaction(sig, &nsa, &osa);
+     if (osa.sa_handler == SIG_IGN)
+         (void) sigaction(sig, &osa, (struct sigaction *)0);
      sigprocmask(SIG_SETMASK, &omask, (sigset_t*)0);
  #else    
+     if (signal(sig, act) == SIG_IGN)
+       (void) signal(sig, SIG_IGN);
  #ifndef sgi
      (void) sigsetmask(omask);
  #endif
***************
*** 836,842 ****
--- 854,864 ----
      mode(0);
      if (child > 0) {
  	/* make sure catchild does not snap it up */
+ #ifdef POSIX_SIGNALS
+ 	Psignal(SIGCHLD, SIG_DFL);
+ #else
  	(void) signal(SIGCHLD, SIG_DFL);
+ #endif
  	if (kill(child, SIGKILL) >= 0)
  	  while ((w = wait(0)) > 0 && w != child)
  	    /*void*/;
***************
*** 868,874 ****
--- 890,900 ----
      
      if (dosigwinch == 0) {
  	sendwindow();
+ #ifdef POSIX_SIGNALS
+ 	Psignal(SIGWINCH, sigwinch);
+ #else
  	(void) signal(SIGWINCH, sigwinch);
+ #endif
      }
      dosigwinch = 1;
  }
***************
*** 1059,1065 ****
--- 1085,1095 ----
       char cmdc;
  {
      mode(0);
+ #ifdef POSIX_SIGNALS
+     Psignal(SIGCHLD, SIG_IGN);
+ #else     
      (void) signal(SIGCHLD, SIG_IGN);
+ #endif
  #ifdef TIOCGLTC
      (void) kill(cmdc == defltc.t_suspc ? 0 : getpid(), SIGTSTP);
  #else
***************
*** 1067,1073 ****
--- 1097,1107 ----
      (void) kill(cmdc == deftty.c_cc[VSUSP] ? 0 : getpid(), SIGTSTP);
  #endif
  #endif
+ #ifdef POSIX_SIGNALS
+     Psignal(SIGCHLD, catchild);
+ #else
      (void) signal(SIGCHLD, catchild);
+ #endif
      mode(1);
      sigwinch();			/* check for size changes */
  }
***************
*** 1119,1125 ****
--- 1153,1163 ----
  int	rcvcnt;
  int	rcvstate;
  int	ppid;
+ #ifdef HAVE_SIGLONGJMP
+ sigjmp_buf rcvtop;
+ #else
  jmp_buf	rcvtop;
+ #endif
  
  krb5_sigtype
    oob()
***************
*** 1242,1248 ****
--- 1280,1290 ----
  	 * restart anyway.
  	 */
  	rcvcnt = 0;
+ #ifdef HAVE_SIGLONGJMP
+ 	siglongjmp(rcvtop, 1);
+ #else
  	longjmp(rcvtop, 1);
+ #endif
      }
      
      /*
***************
*** 1255,1261 ****
--- 1297,1307 ----
       * a pending write, however, or we won't know how much was written.
       */
      if (rcvd && rcvstate == READING)
+ #ifdef HAVE_SIGLONGJMP
+       siglongjmp(rcvtop, 1);
+ #else
        longjmp(rcvtop, 1);
+ #endif
  }
  
  
***************
*** 1278,1290 ****
--- 1324,1348 ----
      int n, remaining;
      char *bufp = rcvbuf;
      
+ #ifdef POSIX_SIGNALS
+     Psignal(SIGTTOU, SIG_IGN);
+     /* The oob comes during read */
+     sa.sa_flags = SA_RESTART;
+     Psignal(SIGURG, oob);
+     sa.sa_flags = 0;
+ #else
      (void) signal(SIGTTOU, SIG_IGN);
      (void) signal(SIGURG, oob);
+ #endif
      ppid = getppid();
  #ifdef HAVE_SETOWN
      (void) fcntl(rem, F_SETOWN, pid);
  #endif
+ #ifdef HAVE_SIGLONGJMP
+     (void) sigsetjmp(rcvtop);
+ #else
      (void) setjmp(rcvtop);
+ #endif
  #ifdef POSIX_SIGNALS
      sigprocmask(SIG_SETMASK, oldmask, (sigset_t*)0);
  #else
***************
*** 1533,1539 ****
       int len;
  {
      int nreturned = 0;
!     long net_len,rd_len;
      int cc;
      
      if (!encrypt_flag)
--- 1591,1597 ----
       int len;
  {
      int nreturned = 0;
!     krb5_ui_4 net_len,rd_len;
      int cc;
      
      if (!encrypt_flag)
***************
*** 1552,1567 ****
  	nstored = 0;
      }
      
- #ifdef BITS64
-     /*
-      * XXX Ick.  This assumes big endian byte order.
-      */
-     rd_len = 0;
-     if ((cc = krb5_net_read(fd, (char *)&rd_len + 4, 4)) != 4) {
- #else
      if ((cc = krb5_net_read(fd, (char *)&rd_len, sizeof(rd_len))) !=
  	    sizeof(rd_len)) {
- #endif
  		/* XXX can't read enough, pipe
  		   must have closed */
  	return(0);
--- 1610,1617 ----
***************
*** 1612,1618 ****
       char *buf;
       int len;
  {
!     long net_len;
      
      if (!encrypt_flag)
        return(write(fd, buf, len));
--- 1662,1668 ----
       char *buf;
       int len;
  {
!     krb5_ui_4 net_len;
      
      if (!encrypt_flag)
        return(write(fd, buf, len));
***************
*** 1632,1642 ****
      }
      
      net_len = htonl(len);
- #ifdef BITS64
-     (void) write(fd,(char *)&net_len + 4, 4);
- #else
      (void) write(fd, &net_len, sizeof(net_len));
- #endif
      if (write(fd, desoutbuf.data,desoutbuf.length) != desoutbuf.length){
  	fprintf(stderr,"Could not write out all data.\n");
  	return(-1);
--- 1682,1688 ----
***************
*** 1661,1667 ****
       int len;
  {
      int nreturned = 0;
!     long net_len, rd_len;
      int cc;
      
      if (!encrypt_flag)
--- 1707,1713 ----
       int len;
  {
      int nreturned = 0;
!     krb5_ui_4 net_len, rd_len;
      int cc;
      
      if (!encrypt_flag)
***************
*** 1679,1691 ****
  	len -= nstored;
  	nstored = 0;
      }
- #ifdef BITS64
-     net_len = 0;
-     if ((cc = krb5_net_read(fd, (char *)&net_len + 4, 4)) != 4) {
- #else
      if ((cc = krb5_net_read(fd, &net_len, sizeof(net_len))) !=
  	sizeof(net_len)) {
- #endif
  	/* XXX can't read enough, pipe
  	   must have closed */
  	return(0);
--- 1725,1732 ----
***************
*** 1743,1749 ****
       char *buf;
       int len;
  {
!     long net_len;
      static int seeded = 0;
      static char garbage_buf[8];
      long garbage;
--- 1784,1790 ----
       char *buf;
       int len;
  {
!     krb5_ui_4 net_len;
      static int seeded = 0;
      static char garbage_buf[8];
      long garbage;
***************
*** 1776,1786 ****
      /* tell the other end the real amount, but send an 8-byte padded
         packet */
      net_len = htonl(len);
- #ifdef BITS64
-     (void) write(fd,(char *)&net_len + 4, 4);
- #else
      (void) write(fd, &net_len, sizeof(net_len));
- #endif
  #ifdef NOROUNDUP
      (void) write(fd, des_outbuf, ((((len)+((8)-1))/(8))*(8)));
  #else
--- 1817,1823 ----
***************
*** 1796,1803 ****
  
  krb5_sigtype lostpeer()
  {
!     
      (void) signal(SIGPIPE, SIG_IGN);
      prf("\007Connection closed.");
      done(1);
  }
--- 1833,1843 ----
  
  krb5_sigtype lostpeer()
  {
! #ifdef POSIX_SIGNALS
!     Psignal(SIGPIPE, SIG_IGN);
! #else
      (void) signal(SIGPIPE, SIG_IGN);
+ #endif
      prf("\007Connection closed.");
      done(1);
  }


home help back first fref pref prev next nref lref last post