]>
git.saurik.com Git - apple/network_cmds.git/blob - uucpd.tproj/uucpd.c
4a5445c83191c139b0d81f53f76f34dbc9e10ff9
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1985, 1993
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley by
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 static char copyright
[] =
62 "@(#) Copyright (c) 1985, 1993\n\
63 The Regents of the University of California. All rights reserved.\n";
67 static char sccsid
[] = "@(#)uucpd.c 8.1 (Berkeley) 6/4/93";
71 * 4.2BSD TCP/IP server for uucico
72 * uucico's TCP channel causes this server to be run at the remote end.
75 #include <sys/types.h>
77 #include <sys/ioctl.h>
78 #include <sys/socket.h>
79 #include <netinet/in.h>
80 #include <arpa/inet.h>
91 #include "pathnames.h"
93 struct sockaddr_in hisctladdr
;
94 int hisaddrlen
= sizeof hisctladdr
;
95 struct sockaddr_in myctladdr
;
103 extern char **environ
;
110 register int s
, tcp_socket
;
120 hisaddrlen
= sizeof (hisctladdr
);
121 if (getpeername(0, &hisctladdr
, &hisaddrlen
) < 0) {
122 fprintf(stderr
, "%s: ", argv
[0]);
123 perror("getpeername");
131 sp
= getservbyname("uucp", "tcp");
133 perror("uucpd: getservbyname");
138 if ((s
=open(_PATH_TTY
, 2)) >= 0){
139 ioctl(s
, TIOCNOTTY
, (char *)0);
143 bzero((char *)&myctladdr
, sizeof (myctladdr
));
144 myctladdr
.sin_family
= AF_INET
;
145 myctladdr
.sin_port
= sp
->s_port
;
147 tcp_socket
= socket(AF_INET
, SOCK_STREAM
, 0);
148 if (tcp_socket
< 0) {
149 perror("uucpd: socket");
152 if (bind(tcp_socket
, (char *)&myctladdr
, sizeof (myctladdr
)) < 0) {
153 perror("uucpd: bind");
156 listen(tcp_socket
, 3); /* at most 3 simultaneuos uucp connections */
157 signal(SIGCHLD
, dologout
);
160 s
= accept(tcp_socket
, &hisctladdr
, &hisaddrlen
);
164 perror("uucpd: accept");
168 close(0); close(1); close(2);
169 dup(s
); dup(s
); dup(s
);
170 close(tcp_socket
); close(s
);
182 struct sockaddr_in
*sinp
;
184 char user
[64], passwd
[64];
185 char *xpasswd
, *crypt();
186 struct passwd
*pw
, *getpwnam();
189 printf("login: "); fflush(stdout
);
190 if (readline(user
, sizeof user
) < 0) {
191 fprintf(stderr
, "user read\n");
194 /* truncate username to 8 characters */
198 fprintf(stderr
, "user unknown\n");
201 if (strcmp(pw
->pw_shell
, _PATH_UUCICO
)) {
202 fprintf(stderr
, "Login incorrect.");
205 if (pw
->pw_passwd
&& *pw
->pw_passwd
!= '\0') {
206 printf("Password: "); fflush(stdout
);
207 if (readline(passwd
, sizeof passwd
) < 0) {
208 fprintf(stderr
, "passwd read\n");
211 xpasswd
= crypt(passwd
, pw
->pw_passwd
);
212 if (strcmp(xpasswd
, pw
->pw_passwd
)) {
213 fprintf(stderr
, "Login incorrect.");
218 sprintf(Username
, "USER=%s", user
);
222 initgroups(pw
->pw_name
, pw
->pw_gid
);
227 execl(UUCICO
, "uucico", (char *)0);
229 perror("uucico server: execl");
239 if (read(0, &c
, 1) <= 0)
242 if (c
== '\n' || c
== '\r') {
256 #define SCPYN(a, b) strncpy(a, b, sizeof (a))
266 while ((pid
=wait((int *)&status
)) > 0) {
268 while ((pid
=wait3((int *)&status
,WNOHANG
,0)) > 0) {
270 wtmp
= open(_PATH_WTMP
, O_WRONLY
|O_APPEND
);
272 sprintf(utmp
.ut_line
, "uucp%.4d", pid
);
273 SCPYN(utmp
.ut_name
, "");
274 SCPYN(utmp
.ut_host
, "");
275 (void) time(&utmp
.ut_time
);
276 (void) write(wtmp
, (char *)&utmp
, sizeof (utmp
));
283 * Record login in wtmp file.
287 struct sockaddr_in
*sin
;
292 struct hostent
*hp
= gethostbyaddr((char *)&sin
->sin_addr
,
293 sizeof (struct in_addr
), AF_INET
);
296 strncpy(remotehost
, hp
->h_name
, sizeof (remotehost
));
299 strncpy(remotehost
, inet_ntoa(sin
->sin_addr
),
300 sizeof (remotehost
));
301 wtmp
= open(_PATH_WTMP
, O_WRONLY
|O_APPEND
);
303 /* hack, but must be unique and no tty line */
304 sprintf(line
, "uucp%.4d", getpid());
305 SCPYN(utmp
.ut_line
, line
);
306 SCPYN(utmp
.ut_name
, pw
->pw_name
);
307 SCPYN(utmp
.ut_host
, remotehost
);
309 (void) write(wtmp
, (char *)&utmp
, sizeof (utmp
));
312 if ((f
= open(_PATH_LASTLOG
, O_RDWR
)) >= 0) {
316 lseek(f
, (long)pw
->pw_uid
* sizeof(struct lastlog
), 0);
317 strcpy(line
, remotehost
);
318 SCPYN(ll
.ll_line
, line
);
319 SCPYN(ll
.ll_host
, remotehost
);
320 (void) write(f
, (char *) &ll
, sizeof ll
);