static char sccsid
[] = "@(#)uucpd.c 5.4 (Berkeley) %G%";
* 4.2BSD or 2.9BSD TCP/IP server for uucico
* uucico's TCP channel causes this server to be run at the remote end.
#include <sys/localopts.h>
#if !defined(BSD4_2) && !defined(BSD2_9)
--- You must have either BSD4_2
or BSD2_9 defined
for this to work
#endif !BSD4_2 && !BSD2_9
#if defined(BSD4_2) && defined(BSD2_9)
--- You may
not have both BSD4_2
and BSD2_9 defined
for this to work
#endif /* check for stupidity */
char lastlog
[] = "/usr/adm/lastlog";
struct sockaddr_in hisctladdr
;
int hisaddrlen
= sizeof hisctladdr
;
struct sockaddr_in myctladdr
;
register int s
, tcp_socket
;
hisaddrlen
= sizeof (hisctladdr
);
if (getpeername(0, &hisctladdr
, &hisaddrlen
) < 0) {
fprintf(stderr
, "%s: ", argv
[0]);
sp
= getservbyname("uucp", "tcp");
perror("uucpd: getservbyname");
if ((s
=open("/dev/tty", 2)) >= 0){
ioctl(s
, TIOCNOTTY
, (char *)0);
bzero((char *)&myctladdr
, sizeof (myctladdr
));
myctladdr
.sin_family
= AF_INET
;
myctladdr
.sin_port
= sp
->s_port
;
tcp_socket
= socket(AF_INET
, SOCK_STREAM
, 0);
if (bind(tcp_socket
, (char *)&myctladdr
, sizeof (myctladdr
)) < 0) {
listen(tcp_socket
, 3); /* at most 3 simultaneuos uucp connections */
signal(SIGCHLD
, dologout
);
s
= accept(tcp_socket
, &hisctladdr
, &hisaddrlen
);
close(0); close(1); close(2);
close(tcp_socket
); close(s
);
signal(SIGCHLD
, dologout
);
s
= socket(SOCK_STREAM
, 0, &myctladdr
,
SO_ACCEPTCONN
|SO_KEEPALIVE
);
if (accept(s
, &hisctladdr
) < 0) {
close(0); close(1); close(2);
struct sockaddr_in
*sinp
;
char user
[64], passwd
[64];
struct passwd
*pw
, *getpwnam();
printf("login: "); fflush(stdout
);
if (readline(user
, sizeof user
) < 0) {
fprintf(stderr
, "user read\n");
/* truncate username to 8 characters */
fprintf(stderr
, "user unknown\n");
if (strcmp(pw
->pw_shell
, UUCICO
)) {
fprintf(stderr
, "Login incorrect.");
if (pw
->pw_passwd
&& *pw
->pw_passwd
!= '\0') {
printf("Password: "); fflush(stdout
);
if (readline(passwd
, sizeof passwd
) < 0) {
fprintf(stderr
, "passwd read\n");
xpasswd
= crypt(passwd
, pw
->pw_passwd
);
if (strcmp(xpasswd
, pw
->pw_passwd
)) {
fprintf(stderr
, "Login incorrect.");
sprintf(Username
, "USER=%s", user
);
initgroups(pw
->pw_name
, pw
->pw_gid
);
execl(UUCICO
, "uucico", (char *)0);
sprintf(passwd
, "-h%s", inet_ntoa(sinp
->sin_addr
));
execl(UUCICO
, "uucico", passwd
, (char *)0);
perror("uucico server: execl");
if (c
== '\n' || c
== '\r') {
#define O_APPEND 0 /* kludge */
#define wait3(a,b,c) wait2(a,b)
#define SCPYN(a, b) strncpy(a, b, sizeof (a))
while ((pid
=wait(&status
)) > 0) {
while ((pid
=wait3(&status
,WNOHANG
,0)) > 0) {
wtmp
= open("/usr/adm/wtmp", O_WRONLY
|O_APPEND
);
sprintf(utmp
.ut_line
, "uucp%.4d", pid
);
(void) time(&utmp
.ut_time
);
(void) lseek(wtmp
, 0L, 2);
(void) write(wtmp
, (char *)&utmp
, sizeof (utmp
));
* Record login in wtmp file.
struct hostent
*hp
= gethostbyaddr(&sin
->sin_addr
,
sizeof (struct in_addr
), AF_INET
);
strncpy(remotehost
, hp
->h_name
, sizeof (remotehost
));
strncpy(remotehost
, inet_ntoa(sin
->sin_addr
),
wtmp
= open("/usr/adm/wtmp", O_WRONLY
|O_APPEND
);
/* hack, but must be unique and no tty line */
sprintf(line
, "uucp%.4d", getpid());
SCPYN(utmp
.ut_line
, line
);
SCPYN(utmp
.ut_name
, pw
->pw_name
);
SCPYN(utmp
.ut_host
, remotehost
);
(void) lseek(wtmp
, 0L, 2);
(void) write(wtmp
, (char *)&utmp
, sizeof (utmp
));
if ((f
= open(lastlog
, 2)) >= 0) {
lseek(f
, (long)pw
->pw_uid
* sizeof(struct lastlog
), 0);
strcpy(line
, remotehost
);
SCPYN(ll
.ll_host
, remotehost
);
(void) write(f
, (char *) &ll
, sizeof ll
);