* Copyright (c) 1985 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1985 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)uucpd.c 5.6 (Berkeley) 10/24/88";
* 4.2BSD TCP/IP server for uucico
* uucico's TCP channel causes this server to be run at the remote end.
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
);
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);
perror("uucico server: execl");
if (c
== '\n' || c
== '\r') {
#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) 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) 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
);