* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char copyright
[] =
"@(#) Copyright (c) 1985, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)uucpd.c 8.1 (Berkeley) 6/4/93";
* 4.2BSD TCP/IP server for uucico
* uucico's TCP channel causes this server to be run at the remote end.
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(_PATH_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
, _PATH_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((int *)&status
)) > 0) {
while ((pid
=wait3((int *)&status
,WNOHANG
,0)) > 0) {
wtmp
= open(_PATH_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((char *)&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(_PATH_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(_PATH_LASTLOG
, O_RDWR
)) >= 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
);