From: saitoh@icsts1.osaka-u.ac.jp (SAITOH Akinori)
Newsgroups: fj.comp.comm
Subject: Re: UUCP/TCP problem between SunOS4.0.3 and SunOS4.1.1
Date: 10 Apr 92 16:19:04 GMT
Distribution: fj
Organization: tokura-lab., Osaka Univ., Japan

$B$_$s$JIOK3$,0-$$$s$d!"snF#!w:eBg$G$9!#(J

In article <TOMO.92Apr10.021826@season.axis.co.jp>, tomo@axis.co.jp (Tomoyuki Sakakibara) writes:
> $B%"%/%7%9$N:g86$G$9!#(J
> $BIaDL!"$D$J$,$k$HCe8FB&$+$i(J"^PShere=" $B$FMh$^$9$h$M!#$3$l$b$J$$!#(J
> telnet xxx 540 $B$H$d$C$F$b(J login:, Password: $B$ODL$k$N$@$1$l$I$bF1$8>u67(J
> $B$G$9!#(J

> $B%W%m%H%3%k%M%4%7%(!<%7%g%s0JA0$N>uBV$N$h$&$J5$$,$7$^$9!#(J

$B$=$&$$$&$H$-$O$M!"(J/usr/spool/uucp/ERRLOG $B$r$_$k$s$G$9$M!#(J
	STTY FAILED
$B$@$H8@$C$F$^$9$M$'!#$^$:!"(Juucico $B$N(Jexec $B$,$&$^$/$$$C$F$k$3$H(J
$B$,$o$+$j$^$9!#$=$l$+$i%(%i!<$r5/$3$7$F%"%\!<%H$7$F$k$3$H$b!#(J

$B$o$9$l$F$?!#(JSUN OS 4.0.x $B$N(J uucp $B$O(J SVR2 $B$N$G$b(J BSD $B$N$G$b$J(J
$B$$JQ$J$d$D$@$C$?$s$@!#(J

$B$I$&$d$i!"(Jsocket $B>e$G$OF0$+$J$$$h$&$G$9!#(J
$B855$$J?M$J$i!"(Jioctl $B$N%(%i!<%3!<%I$rL5;k$9$k$h$&$K%P%$%J%j(J
$B%Q%C%A$r$"$C$F$/$@$5$$!#(J

$B$=$&$;$:$KL5M}LpM}F0$+$9$K$O!"8zN($r5>@7$K$9$kI,MW$,$"$j$^$9!#(J
$B4pK\E*%"%$%G%#%"$r0J2<$K<($7$^$9!#(J

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#		uucpd.diff
#		fakepty.c
#		uucp.h
# This archive created:  Sat Apr 11 00:59:30 JST 1992
export PATH; PATH=/bin:$PATH
:
:	File = uucpd.diff
:
echo shar: extracting "'uucpd.diff'" '( 1233 characters )'
if test -f 'uucpd.diff'
then
	echo shar: will not over-write existing file "'uucpd.diff'"
else
cat > uucpd.diff << '!End-Of-uucpd.diff!'
*** uucpd.c.orig	Fri Apr 10 23:10:29 1992
--- uucpd.c	Sat Apr 11 00:57:43 1992
***************
*** 49,54 ****
--- 49,56 ----
  int hisaddrlen = sizeof hisctladdr;
  struct	sockaddr_in myctladdr;
  int mypid;
+ int ptyfd;
+ int ttypfd;
  
  char Username[64];
  char *nenv[] = {
***************
*** 78,85 ****
  		perror("getpeername");
  		_exit(1);
  	}
! 	if (fork() == 0)
! 		doit(&hisctladdr);
  	dologout();
  	exit(1);
  #else !BSDINETD
--- 80,89 ----
  		perror("getpeername");
  		_exit(1);
  	}
! 	if(doit(&hisctladdr)==0) {
! 		close(ttypfd);
! 		docopy(0,ptyfd);
! 	}
  	dologout();
  	exit(1);
  #else !BSDINETD
***************
*** 172,177 ****
--- 176,187 ----
  	alarm(0);
  	sprintf(Username, "USER=%s", user);
  	dologin(pw, sinp);
+ #ifdef	BSDINETD
+ 	if(initpty())
+ 		return -1;
+ 	if(fork()!=0)
+ 		return 0;
+ #endif	BSDINETD
  	setgid(pw->pw_gid);
  #ifdef BSD4_2
  	initgroups(pw->pw_name, pw->pw_gid);
***************
*** 179,184 ****
--- 189,197 ----
  	chdir(pw->pw_dir);
  	setuid(pw->pw_uid);
  #ifdef BSD4_2
+ 	close(0); close(1);close(2);
+ 	dup(ttypfd); dup(ttypfd); dup(ttypfd);
+ 	close(ttypfd); close(ptyfd);
  	execl(UUCICO, "uucico", (char *)0);
  #endif BSD4_2
  	perror("uucico server: execl");
!End-Of-uucpd.diff!
if test 1233 -ne "`wc -c < 'uucpd.diff'`"
then
	 echo shar: error transmitting "'uucpd.diff'" '(should have been 1233 characters)'
fi
fi
:
:	File = fakepty.c
:
echo shar: extracting "'fakepty.c'" '( 3782 characters )'
if test -f 'fakepty.c'
then
	echo shar: will not over-write existing file "'fakepty.c'"
else
cat > fakepty.c << '!End-Of-fakepty.c!'

#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/file.h>
#ifndef O_RDWR
#include <sys/fcntl.h>
#endif
#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif
#include <setjmp.h>
#include <sys/errno.h>
extern int      errno;
extern int ptyfd;
extern int ttypfd;

int childdeath=0;

onchld()
{
	childdeath=1;
}


docopy(rmtfd,ttyfd)
{
	int nfds , nfound;
	int remain_in,remain_out;
	char outbuf[0x400],inbuf[0x400];
	char *outbp,*inbp;
	fd_set rdfdset,wrfdset,expfdset;
	struct timeval timeoutval;
	int	fl,n;

	signal(SIGCHLD, onchld);
	if((fl=fcntl(rmtfd,F_GETFL,0))<0)
		perror("fcntl(rmtfd,F_GETFL,0)");
	if(fcntl(rmtfd,F_SETFL,fl|FNDELAY)<0)
		perror("fcntl(rmtfd,F_SETFL,fl|FNDELAY)");
	if((fl=fcntl(ttyfd,F_GETFL,0))<0)
		perror("fcntl(ttyfd,F_GETFL,0)");
	if(fcntl(ttyfd,F_SETFL,fl|FNDELAY)<0)
		perror("fcntl(ttyfd,F_SETFL,fl|FNDELAY)");

	nfds= (rmtfd>ttyfd?rmtfd:ttyfd) +1;
	remain_in=remain_out=0;
	inbp=inbuf;
	outbp=outbuf;
	FD_ZERO(&rdfdset); FD_ZERO(&wrfdset); FD_ZERO(&expfdset);

	FD_SET(rmtfd,&rdfdset); FD_SET(ttyfd,&rdfdset);
	FD_SET(rmtfd,&wrfdset); FD_SET(ttyfd,&wrfdset);
	timeoutval.tv_sec=30; timeoutval.tv_usec=0;
	while((nfound=select(nfds,&rdfdset,&wrfdset,
			&expfdset,&timeoutval))<0 && errno==EINTR)
				;
	if(nfound <=0)
		return;
	for (;childdeath==0;) {
		if(remain_out == 0){
			if( FD_ISSET(ttyfd, & rdfdset)) {
				if ((n = read(ttyfd, outbuf, sizeof(outbuf))) >0){
					remain_out=n;
					outbp= outbuf;
					continue;
				}else if(n==0 || errno==EWOULDBLOCK) {
					FD_CLR(ttyfd, & rdfdset);
				} else if (errno!=EINTR) {
					return;
				}
			}
		}else if( FD_ISSET(rmtfd, & wrfdset)) {
			if ((n = write(rmtfd,outbp ,remain_out))>0){
				remain_out -=n;
				outbp +=n;
				continue;
			}else if(n==0 ) {
				fprintf(stderr,"write(rmtfd)==0\n");
				return;
			}else if(errno!=EWOULDBLOCK){
				FD_CLR(rmtfd, & wrfdset);
			}else if(errno!=EINTR) {
				perror("write(rmtfd)");
				return;
			}
		}

		if(remain_in == 0){
			if( FD_ISSET(rmtfd, & rdfdset)) {
				if ((n = read(rmtfd, inbuf, sizeof(inbuf))) >0){
					remain_in=n;
					inbp=inbuf;
					continue;
				}else if(n==0 || errno==EWOULDBLOCK) {
					FD_CLR(rmtfd, & rdfdset);
				} else if (errno!=EINTR) {
					return;
				}
			}
		}else if( FD_ISSET(ttyfd, & wrfdset)) {
			if ((n = write(ttyfd,inbp,remain_in))>0){
				remain_in -=n;
				inbp +=n;
				continue;
			}else if(n==0 ) {
				fprintf(stderr,"write(ttyfd)==0\n");
				return;
			}else if(errno ==EWOULDBLOCK){
				FD_CLR(ttyfd, & wrfdset);
			}else if(errno!=EINTR) {
				perror("write(ttyfd)");
				return;
			}
		}

		/*
		FD_SET(rmtfd,&expfdset);
		FD_SET(ttyfd,&expfdset);
		*/
		FD_ZERO(&rdfdset);
		FD_ZERO(&wrfdset);
		if(remain_in==0)
			FD_SET(rmtfd,&rdfdset);
		else
			FD_SET(ttyfd,&wrfdset);
		if(remain_out==0)
			FD_SET(ttyfd,&rdfdset);
		else
			FD_SET(rmtfd,&wrfdset);
		timeoutval.tv_sec=30;
		timeoutval.tv_usec=0;
		while((nfound=select(nfds,&rdfdset,&wrfdset,
			0/*&expfdset*/,&timeoutval))<0 && errno==EINTR)
				;
		if(nfound <=0) {
			fprintf(stderr,"select timeout\n");
			return;
		}
/*		if(FD_ISSET(ttyfd,&expfdset)||FD_ISSET(rmtfd,&expfdset))
			return;*/
	}
}

char ptyname[128];
char ttypname[128];


initpty()
{
	int             i, j;


	for (i = 0;i<16*3; i++ ){
		sprintf(ptyname, "/dev/pty%c%c",
			"pqr"[i / 16],
			"0123456789abcdef"[i % 16]);
		if ((ptyfd = open(ptyname, O_RDWR)) < 0) {
			if(errno==ENOENT)
				return -1;
			continue;
		}
		sprintf(ttypname, "/dev/tty%c%c",
			"pqr"[i / 16], "0123456789abcdef"[i % 16]);
		if ((ttypfd = open(ttypname, O_RDWR)) < 0) {
			close(ptyfd);
			continue;
		}
		return 0;
	}
	return -1;
}

!End-Of-fakepty.c!
if test 3782 -ne "`wc -c < 'fakepty.c'`"
then
	 echo shar: error transmitting "'fakepty.c'" '(should have been 3782 characters)'
fi
fi
:
:	File = uucp.h
:
echo shar: extracting "'uucp.h'" '( 112 characters )'
if test -f 'uucp.h'
then
	echo shar: will not over-write existing file "'uucp.h'"
else
cat > uucp.h << '!End-Of-uucp.h!'
#include <stdio.h>
#include <sys/types.h>
#define BSDINETD
#define BSD4_2
#define UUCICO "/usr/lib/uucp/uucico"
!End-Of-uucp.h!
if test 112 -ne "`wc -c < 'uucp.h'`"
then
	 echo shar: error transmitting "'uucp.h'" '(should have been 112 characters)'
fi
fi
#	End of shell archive

$B$3$$$D$H(J
UUCP/ISDN $B$H$I$C$A$,B.$$$+$J$!!#(J SUN 3 $B$@$H(J 64Kbps $B=P$J$$$+$b$M!#(J

Good luck.

	$B@FF#!!L@5*(J	$BsnF#!wETAR8&!%>pJs!%4pAC9)!%:eBg(J
	saitoh@icsts1.osaka-u.ac.jp
	-- $B$3$N@$$+$i(J ICMP_UNREACH$B$H(J ICMP_TIMXCEED $B$H$,L5$/$J$l$P$$$$$N$K(J
Newsgroups: fj.comp.comm