1994-05-27 12:39:25 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1985, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Rick Adams.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 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
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-12-04 07:20:45 +00:00
|
|
|
static const char copyright[] =
|
1994-05-27 12:39:25 +00:00
|
|
|
"@(#) Copyright (c) 1985, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-12-04 07:20:45 +00:00
|
|
|
#if 0
|
1994-05-27 12:39:25 +00:00
|
|
|
static char sccsid[] = "@(#)uucpd.c 8.1 (Berkeley) 6/4/93";
|
1997-12-04 07:20:45 +00:00
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-27 12:39:25 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 4.2BSD TCP/IP server for uucico
|
|
|
|
* uucico's TCP channel causes this server to be run at the remote end.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
1997-04-01 20:39:59 +00:00
|
|
|
#include <sys/param.h>
|
1994-05-27 12:39:25 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
1997-12-04 07:20:45 +00:00
|
|
|
#include <errno.h>
|
1994-05-27 12:39:25 +00:00
|
|
|
#include <fcntl.h>
|
1997-12-04 07:20:45 +00:00
|
|
|
#include <netdb.h>
|
1994-05-27 12:39:25 +00:00
|
|
|
#include <pwd.h>
|
1997-12-04 07:20:45 +00:00
|
|
|
#include <signal.h>
|
1994-05-27 12:39:25 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-11-23 19:33:17 +00:00
|
|
|
#include <syslog.h>
|
1997-12-04 07:20:45 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <utmp.h>
|
1997-03-25 09:52:38 +00:00
|
|
|
#include <sys/param.h>
|
1994-05-27 12:39:25 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1997-03-25 09:52:38 +00:00
|
|
|
#if (MAXLOGNAME-1) > UT_NAMESIZE
|
|
|
|
#define LOGNAMESIZE UT_NAMESIZE
|
|
|
|
#else
|
|
|
|
#define LOGNAMESIZE (MAXLOGNAME-1)
|
|
|
|
#endif
|
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
#define SCPYN(a, b) strncpy(a, b, sizeof (a))
|
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
struct sockaddr_storage hisctladdr;
|
1994-05-27 12:39:25 +00:00
|
|
|
int hisaddrlen = sizeof hisctladdr;
|
2000-05-14 18:01:05 +00:00
|
|
|
struct sockaddr_storage myctladdr;
|
1994-05-27 12:39:25 +00:00
|
|
|
int mypid;
|
|
|
|
|
1994-11-25 02:27:08 +00:00
|
|
|
char Username[64], Logname[64];
|
1994-05-27 12:39:25 +00:00
|
|
|
char *nenv[] = {
|
|
|
|
Username,
|
1994-11-25 02:27:08 +00:00
|
|
|
Logname,
|
1994-05-27 12:39:25 +00:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
extern char **environ;
|
1994-11-23 19:33:17 +00:00
|
|
|
extern void logwtmp(char *line, char *name, char *host);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
void doit(struct sockaddr *sinp);
|
1994-11-23 19:33:17 +00:00
|
|
|
void dologout(void);
|
|
|
|
int readline(char start[], int num, int passw);
|
2000-05-14 18:01:05 +00:00
|
|
|
void dologin(struct passwd *pw, struct sockaddr *sin);
|
1994-05-27 12:39:25 +00:00
|
|
|
|
1999-04-25 22:23:38 +00:00
|
|
|
int main(int argc, char **argv)
|
1994-11-23 19:33:17 +00:00
|
|
|
{
|
1994-05-27 12:39:25 +00:00
|
|
|
environ = nenv;
|
|
|
|
close(1); close(2);
|
|
|
|
dup(0); dup(0);
|
|
|
|
hisaddrlen = sizeof (hisctladdr);
|
1994-11-23 19:33:17 +00:00
|
|
|
openlog("uucpd", LOG_PID, LOG_DAEMON);
|
1994-08-23 20:13:32 +00:00
|
|
|
if (getpeername(0, (struct sockaddr *)&hisctladdr, &hisaddrlen) < 0) {
|
1994-11-23 19:33:17 +00:00
|
|
|
syslog(LOG_ERR, "getpeername: %m");
|
1994-05-27 12:39:25 +00:00
|
|
|
_exit(1);
|
|
|
|
}
|
2000-05-14 18:01:05 +00:00
|
|
|
doit((struct sockaddr *)&hisctladdr);
|
1994-05-27 12:39:25 +00:00
|
|
|
dologout();
|
1994-11-23 19:33:17 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
void badlogin(char *name, struct sockaddr *sin)
|
1994-11-23 19:33:17 +00:00
|
|
|
{
|
1997-04-01 20:39:59 +00:00
|
|
|
char remotehost[MAXHOSTNAMELEN];
|
1994-11-23 19:33:17 +00:00
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
realhostname_sa(remotehost, sizeof(remotehost) - 1, sin, sin->sa_len);
|
1999-04-07 08:27:45 +00:00
|
|
|
remotehost[sizeof(remotehost) - 1] = '\0';
|
1997-04-01 20:39:59 +00:00
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
syslog(LOG_NOTICE, "LOGIN FAILURE FROM %s", remotehost);
|
|
|
|
syslog(LOG_AUTHPRIV|LOG_NOTICE,
|
|
|
|
"LOGIN FAILURE FROM %s, %s", remotehost, name);
|
|
|
|
|
|
|
|
fprintf(stderr, "Login incorrect.\n");
|
1994-05-27 12:39:25 +00:00
|
|
|
exit(1);
|
1994-11-23 19:33:17 +00:00
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
void doit(struct sockaddr *sinp)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
1994-11-25 02:27:08 +00:00
|
|
|
char user[64], passwd[64];
|
1994-05-27 12:39:25 +00:00
|
|
|
char *xpasswd, *crypt();
|
1994-11-23 19:33:17 +00:00
|
|
|
struct passwd *pw;
|
|
|
|
pid_t s;
|
1997-03-25 09:52:38 +00:00
|
|
|
int pwdok =0;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
alarm(60);
|
1999-03-30 10:23:35 +00:00
|
|
|
do {
|
|
|
|
printf("login: "); fflush(stdout);
|
|
|
|
errno = 0;
|
|
|
|
if (readline(user, sizeof user, 0) < 0) {
|
|
|
|
syslog(LOG_WARNING, "login read: %m");
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
} while (user[0] == '\0');
|
1997-03-25 09:52:38 +00:00
|
|
|
/* truncate username to LOGNAMESIZE characters */
|
|
|
|
user[LOGNAMESIZE] = '\0';
|
1994-05-27 12:39:25 +00:00
|
|
|
pw = getpwnam(user);
|
1997-03-25 09:52:38 +00:00
|
|
|
/*
|
|
|
|
* Fail after password if:
|
|
|
|
* 1. Invalid user
|
|
|
|
* 2. Shell is not uucico
|
|
|
|
* 3. Account has expired
|
|
|
|
* 4. Password is incorrect
|
|
|
|
*/
|
|
|
|
if (pw != NULL && strcmp(pw->pw_shell, _PATH_UUCICO) == 0 &&
|
1997-04-08 12:32:17 +00:00
|
|
|
(!pw->pw_expire || time(NULL) >= pw->pw_expire))
|
1997-03-25 09:52:38 +00:00
|
|
|
pwdok = 1;
|
|
|
|
/* always ask for passwords to deter account guessing */
|
|
|
|
if (!pwdok || (pw->pw_passwd && *pw->pw_passwd != '\0')) {
|
1994-05-27 12:39:25 +00:00
|
|
|
printf("Password: "); fflush(stdout);
|
1999-03-30 10:23:35 +00:00
|
|
|
errno = 0;
|
1994-11-23 19:33:17 +00:00
|
|
|
if (readline(passwd, sizeof passwd, 1) < 0) {
|
1999-11-06 20:58:44 +00:00
|
|
|
syslog(LOG_WARNING, "passwd for '%s' read: %m", user);
|
1994-11-23 19:33:17 +00:00
|
|
|
_exit(1);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
1997-03-25 09:52:38 +00:00
|
|
|
if (pwdok) {
|
|
|
|
xpasswd = crypt(passwd, pw->pw_passwd);
|
|
|
|
if (strcmp(xpasswd, pw->pw_passwd))
|
|
|
|
pwdok = 0;
|
|
|
|
}
|
|
|
|
if (!pwdok)
|
1994-11-23 19:33:17 +00:00
|
|
|
badlogin(user, sinp);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
alarm(0);
|
1994-11-23 19:33:17 +00:00
|
|
|
sprintf(Username, "USER=%s", pw->pw_name);
|
1994-11-25 02:27:08 +00:00
|
|
|
sprintf(Logname, "LOGNAME=%s", pw->pw_name);
|
1995-03-20 05:58:37 +00:00
|
|
|
if ((s = fork()) < 0) {
|
1994-11-23 19:33:17 +00:00
|
|
|
syslog(LOG_ERR, "fork: %m");
|
1995-03-20 05:58:37 +00:00
|
|
|
_exit(1);
|
|
|
|
} else if (s == 0) {
|
1994-11-23 19:33:17 +00:00
|
|
|
dologin(pw, sinp);
|
|
|
|
setgid(pw->pw_gid);
|
|
|
|
initgroups(pw->pw_name, pw->pw_gid);
|
|
|
|
chdir(pw->pw_dir);
|
|
|
|
setuid(pw->pw_uid);
|
1994-11-25 02:27:08 +00:00
|
|
|
execl(pw->pw_shell, "uucico", NULL);
|
1994-11-23 19:33:17 +00:00
|
|
|
syslog(LOG_ERR, "execl: %m");
|
1995-03-20 05:58:37 +00:00
|
|
|
_exit(1);
|
1994-11-23 19:33:17 +00:00
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
int readline(char start[], int num, int passw)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
char c;
|
1994-11-23 19:33:17 +00:00
|
|
|
register char *p = start;
|
|
|
|
register int n = num;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
while (n-- > 0) {
|
|
|
|
if (read(0, &c, 1) <= 0)
|
|
|
|
return(-1);
|
|
|
|
c &= 0177;
|
1994-11-23 19:33:17 +00:00
|
|
|
if (c == '\n' || c == '\r' || c == '\0') {
|
|
|
|
if (p == start && passw) {
|
|
|
|
n++;
|
|
|
|
continue;
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
*p = '\0';
|
|
|
|
return(0);
|
|
|
|
}
|
1994-11-23 19:33:17 +00:00
|
|
|
if (c == 025) {
|
|
|
|
n = num;
|
|
|
|
p = start;
|
|
|
|
continue;
|
|
|
|
}
|
1994-05-27 12:39:25 +00:00
|
|
|
*p++ = c;
|
|
|
|
}
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
void dologout(void)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
union wait status;
|
1994-11-23 19:33:17 +00:00
|
|
|
pid_t pid;
|
|
|
|
char line[32];
|
1994-05-27 12:39:25 +00:00
|
|
|
|
|
|
|
while ((pid=wait((int *)&status)) > 0) {
|
1998-06-30 15:19:51 +00:00
|
|
|
sprintf(line, "uucp%ld", (long)pid);
|
1994-11-23 19:33:17 +00:00
|
|
|
logwtmp(line, "", "");
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record login in wtmp file.
|
|
|
|
*/
|
2000-05-14 18:01:05 +00:00
|
|
|
void dologin(struct passwd *pw, struct sockaddr *sin)
|
1994-05-27 12:39:25 +00:00
|
|
|
{
|
|
|
|
char line[32];
|
1999-04-06 23:06:00 +00:00
|
|
|
char remotehost[UT_HOSTSIZE + 1];
|
1994-11-23 19:33:17 +00:00
|
|
|
int f;
|
|
|
|
time_t cur_time;
|
1994-05-27 12:39:25 +00:00
|
|
|
|
2000-05-14 18:01:05 +00:00
|
|
|
realhostname_sa(remotehost, sizeof(remotehost) - 1, sin, sin->sa_len);
|
1997-04-08 20:36:36 +00:00
|
|
|
remotehost[sizeof remotehost - 1] = '\0';
|
1999-04-06 23:06:00 +00:00
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
/* hack, but must be unique and no tty line */
|
1998-06-30 15:19:51 +00:00
|
|
|
sprintf(line, "uucp%ld", (long)getpid());
|
1994-11-23 19:33:17 +00:00
|
|
|
time(&cur_time);
|
1994-05-27 12:39:25 +00:00
|
|
|
if ((f = open(_PATH_LASTLOG, O_RDWR)) >= 0) {
|
|
|
|
struct lastlog ll;
|
|
|
|
|
1994-11-23 19:33:17 +00:00
|
|
|
ll.ll_time = cur_time;
|
|
|
|
lseek(f, (off_t)pw->pw_uid * sizeof(struct lastlog), L_SET);
|
1994-05-27 12:39:25 +00:00
|
|
|
SCPYN(ll.ll_line, line);
|
|
|
|
SCPYN(ll.ll_host, remotehost);
|
|
|
|
(void) write(f, (char *) &ll, sizeof ll);
|
|
|
|
(void) close(f);
|
|
|
|
}
|
1995-03-20 05:58:37 +00:00
|
|
|
logwtmp(line, pw->pw_name, remotehost);
|
1994-05-27 12:39:25 +00:00
|
|
|
}
|