4.4-lite, plus our local changes

This commit is contained in:
deraadt 1994-06-29 01:49:37 +00:00
parent 50b13742e4
commit d6743f02e5
8 changed files with 1029 additions and 684 deletions

View File

@ -1,9 +1,9 @@
# from: @(#)Makefile 5.15 (Berkeley) 7/1/90
# $Id: Makefile,v 1.8 1994/05/24 06:53:33 deraadt Exp $
# from : @(#)Makefile 8.2 (Berkeley) 4/4/94
# $Id: Makefile,v 1.9 1994/06/29 01:49:37 deraadt Exp $
PROG= ftpd
CFLAGS+=-I${.CURDIR}/../../usr.bin/ftp -DHASSETPROCTITLE -DSKEY
SRCS= ftpd.c ftpcmd.c glob.c logwtmp.c popen.c vers.c klogin.c
CFLAGS+=-DHASSETPROCTITLE -DSKEY
SRCS= ftpd.c ftpcmd.c logwtmp.c popen.c
MAN8= ftpd.0
CLEANFILES+=ftpcmd.c y.tab.h
.PATH: ${.CURDIR}/../../usr.bin/ftp ${.CURDIR}/../../usr.bin/login
@ -13,7 +13,7 @@ DPADD+= ${LIBCRYPT} ${LIBSKEY}
.if defined(KERBEROS)
CFLAGS+= -DKERBEROS
LDADD+= -lkrb -ldes
LDADD+= -lkrb -ldes
DPADD+= ${LIBKRB} ${LIBDES}
.endif

66
libexec/ftpd/extern.h Normal file
View File

@ -0,0 +1,66 @@
/*-
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* 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.
*
* from: @(#)extern.h 8.2 (Berkeley) 4/4/94
* $Id: extern.h,v 1.1 1994/06/29 01:49:39 deraadt Exp $
*/
void blkfree __P((char **));
char **copyblk __P((char **));
void cwd __P((char *));
void delete __P((char *));
void dologout __P((int));
void fatal __P((char *));
int ftpd_pclose __P((FILE *));
FILE *ftpd_popen __P((char *, char *));
char *getline __P((char *, int, FILE *));
void logwtmp __P((char *, char *, char *));
void lreply __P((int, const char *, ...));
void makedir __P((char *));
void nack __P((char *));
void pass __P((char *));
void passive __P((void));
void perror_reply __P((int, char *));
void pwd __P((void));
void removedir __P((char *));
void renamecmd __P((char *, char *));
char *renamefrom __P((char *));
void reply __P((int, const char *, ...));
void retrieve __P((char *, char *));
void send_file_list __P((char *));
void setproctitle __P((const char *, ...));
void statcmd __P((void));
void statfilecmd __P((char *));
void store __P((char *, char *, int));
void upper __P((char *));
void user __P((char *));
void yyerror __P((char *));

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
.\" Copyright (c) 1985, 1988, 1991 The Regents of the University of California.
.\" All rights reserved.
.\" Copyright (c) 1985, 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -29,27 +29,24 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" from: @(#)ftpd.8 6.9 (Berkeley) 3/16/91
.\" $Id: ftpd.8,v 1.4 1994/05/24 06:53:36 deraadt Exp $
.\" from: @(#)ftpd.8 8.2 (Berkeley) 4/19/94
.\" $Id: ftpd.8,v 1.5 1994/06/29 01:49:43 deraadt Exp $
.\"
.Dd March 16, 1991
.Dd April 19, 1994
.Dt FTPD 8
.Os BSD 4.2
.Sh NAME
.Nm ftpd
.Nd
.Tn DARPA
Internet File Transfer Protocol server
.Sh SYNOPSIS
.Nm ftpd
.Op Fl d
.Op Fl l
.Op Fl t Ar timeout
.Op Fl dl
.Op Fl T Ar maxtimeout
.Op Fl t Ar timeout
.Sh DESCRIPTION
.Nm Ftpd
is the
.Tn DARPA
Internet File Transfer Protocol
server process. The server uses the
.Tn TCP
@ -62,15 +59,14 @@ service specification; see
Available options:
.Bl -tag -width Ds
.It Fl d
Debugging information is written to the syslog.
Debugging information is written to the syslog using LOG_FTP.
.It Fl l
Each
Each successful and failed
.Xr ftp 1
session is logged in the syslog.
.It Fl t
The inactivity timeout period is set to
.Ar timeout
seconds (the default is 15 minutes).
session is logged using syslog with a facility of LOG_FTP.
If this option is specified twice, the retrieve (get), store (put), append,
delete, make directory, remove directory and rename operations and
their filename arguments are also logged.
.It Fl T
A client may also request a different timeout period;
the maximum period allowed may be set to
@ -79,10 +75,33 @@ seconds with the
.Fl T
option.
The default limit is 2 hours.
.It Fl t
The inactivity timeout period is set to
.Ar timeout
seconds (the default is 15 minutes).
.El
.Pp
The ftp server currently supports the following ftp
requests; case is not distinguished.
The file
.Pa /etc/nologin
can be used to disable ftp access.
If the file exists,
.Nm
displays it and exits.
If the file
.Pa /etc/ftpwelcome
exists,
.Nm
prints it before issuing the
.Dq ready
message.
If the file
.Pa /etc/motd
exists,
.Nm
prints it after a successful login.
.Pp
The ftp server currently supports the following ftp requests.
The case of the requests is ignored.
.Bl -column "Request" -offset indent
.It Request Ta "Description"
.It ABOR Ta "abort previous command"
@ -133,27 +152,23 @@ SITE request.
.Pp
.Bl -column Request -offset indent
.It Sy Request Ta Sy Description
.It UMASK Ta change umask. Em E.g. SITE UMASK 002
.It IDLE Ta set idle-timer. Em E.g. SITE IDLE 60
.It CHMOD Ta change mode of a file. Em E.g.
SITE CHMOD 755 filename
.It HELP Ta give help information. Em E.g. SITE HELP
.It UMASK Ta change umask, e.g. ``SITE UMASK 002''
.It IDLE Ta set idle-timer, e.g. ``SITE IDLE 60''
.It CHMOD Ta change mode of a file, e.g. ``SITE CHMOD 755 filename''
.It HELP Ta give help information.
.El
.Pp
The remaining ftp requests specified in Internet
.%T "RFC 959"
The remaining ftp requests specified in Internet RFC 959
are
recognized, but not implemented.
MDTM and SIZE are not specified in
.%T "RFC 959" ,
but will appear in the next updated FTP RFC.
MDTM and SIZE are not specified in RFC 959, but will appear in the
next updated FTP RFC.
.Pp
The ftp server will abort an active file transfer only when the
ABOR
command is preceded by a Telnet "Interrupt Process" (IP)
signal and a Telnet "Synch" signal in the command Telnet stream,
as described in Internet
.%T "RFC 959" .
as described in Internet RFC 959.
If a
STAT
command is received during a data transfer, preceded by a Telnet IP
@ -172,21 +187,21 @@ authenticates users according to five rules.
.Pp
.Bl -enum -offset indent
.It
The user name must be in the password data base,
The login name must be in the password data base,
.Pa /etc/passwd ,
and not have a null password. In this case a password
must be provided by the client before any file operations
may be performed.
and not have a null password.
In this case a password must be provided by the client before any
file operations may be performed.
If the user has an S/Key key, the response from a successful USER
command will include an S/Key challenge. The client may choose to respond
with a PASS command giving either a standard password or an S/Key
one-time password. The server will automaticly determine which type of
one-time password. The server will automatically determine which type of
password it has been given and attempt to authenticate accordingly. See
.Xr skey 1
for more information on S/Key authentication. S/Key is a Trademark of
Bellcore.
.It
The user name must not appear in the file
The login name must not appear in the file
.Pa /etc/ftpusers .
.It
The user must have a standard shell returned by
@ -214,8 +229,8 @@ anonymous ftp account must be present in the password
file (user
.Dq ftp ) .
In this case the user is allowed
to log in by specifying any password (by convention this
is given as the client host's name).
to log in by specifying any password (by convention an email address for
the user should be used as the password).
.El
.Pp
In the last case,
@ -223,28 +238,31 @@ In the last case,
takes special measures to restrict the client's access privileges.
The server performs a
.Xr chroot 2
command to the home directory of the
to the home directory of the
.Dq ftp
user.
In order that system security is not breached, it is recommended
that the
.Dq ftp
subtree be constructed with care; the following
rules are recommended.
subtree be constructed with care, following these rules:
.Bl -tag -width "~ftp/pub" -offset indent
.It Pa ~ftp
Make the home directory owned by
.Dq ftp
.Dq root
and unwritable by anyone.
.It Pa ~ftp/bin
Make this directory owned by the super-user and unwritable by
anyone. The program
Make this directory owned by
.Dq root
and unwritable by anyone (mode 555).
The program
.Xr ls 1
must be present to support the list command. This
program should have mode 111.
must be present to support the list command.
This program should be mode 111.
.It Pa ~ftp/etc
Make this directory owned by the super-user and unwritable by
anyone. The files
Make this directory owned by
.Dq root
and unwritable by anyone (mode 555).
The files
.Xr passwd 5
and
.Xr group 5
@ -253,14 +271,30 @@ must be present for the
command to be able to produce owner names rather than numbers.
The password field in
.Xr passwd
is not used, and should not contain real encrypted passwords.
is not used, and should not contain real passwords.
The file
.Pa motd ,
if present, will be printed after a successful login.
These files should be mode 444.
.It Pa ~ftp/pub
Make this directory mode 777 and owned by
.Dq ftp .
Users
should then place files which are to be accessible via the
anonymous account in this directory.
Guests
can then place files which are to be accessible via the anonymous
account in this directory.
.El
.Sh FILES
.Bl -tag -width /etc/ftpwelcome -compact
.It Pa /etc/ftpusers
List of unwelcome/restricted users.
.It Pa /etc/ftpchroot
List of normal users who should be chroot'd.
.It Pa /etc/ftpwelcome
Welcome notice.
.It Pa /etc/motd
Welcome notice after login.
.It Pa /etc/nologin
Displayed and access refused.
.El
.Sh SEE ALSO
.Xr ftp 1 ,
@ -268,9 +302,6 @@ anonymous account in this directory.
.Xr getusershell 3 ,
.Xr syslogd 8
.Sh BUGS
The anonymous account is inherently dangerous and should
avoided when possible.
.Pp
The server must run as the super-user
to create sockets with privileged port numbers. It maintains
an effective user id of the logged in user, reverting to

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -33,17 +33,20 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)logwtmp.c 5.7 (Berkeley) 2/25/91";*/
static char rcsid[] = "$Id: logwtmp.c,v 1.2 1993/08/01 18:30:45 mycroft Exp $";
static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: logwtmp.c,v 1.3 1994/06/29 01:49:47 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <utmp.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "extern.h"
static int fd = -1;
@ -52,13 +55,12 @@ static int fd = -1;
* after first call, for use with ftp (which may chroot
* after login, but before logout).
*/
void
logwtmp(line, name, host)
char *line, *name, *host;
{
struct utmp ut;
struct stat buf;
time_t time();
char *strncpy();
if (fd < 0 && (fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) < 0)
return;

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,11 +30,13 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* from: @(#)pathnames.h 5.2 (Berkeley) 6/1/90
* $Id: pathnames.h,v 1.3 1994/04/06 20:50:15 cgd Exp $
* from: @(#)pathnames.h 5.2 (Berkeley) 6/1/90
* $Id: pathnames.h,v 1.4 1994/06/29 01:49:49 deraadt Exp $
*/
#include <paths.h>
#define _PATH_FTPUSERS "/etc/ftpusers"
#define _PATH_FTPCHROOT "/etc/ftpchroot"
#define _PATH_FTPUSERS "/etc/ftpusers"
#define _PATH_FTPCHROOT "/etc/ftpchroot"
#define _PATH_FTPWELCOME "/etc/ftpwelcome"
#define _PATH_FTPLOGINMESG "/etc/motd"

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1988 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 1988, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software written by Ken Arnold and
* published in UNIX Review, Vol. 6, No. 8.
@ -36,20 +36,25 @@
*/
#ifndef lint
/*static char sccsid[] = "from: @(#)popen.c 5.9 (Berkeley) 2/25/91";*/
static char rcsid[] = "$Id: popen.c,v 1.2 1993/08/01 18:30:43 mycroft Exp $";
static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94";
static char rcsid[] = "$Id: popen.c,v 1.3 1994/06/29 01:49:50 deraadt Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <glob.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
/*
* Special version of popen which avoids call to shell. This insures noone
* Special version of popen which avoids call to shell. This ensures noone
* may create a pipe to a hidden program as a side effect of a list or dir
* command.
*/
@ -60,24 +65,23 @@ FILE *
ftpd_popen(program, type)
char *program, *type;
{
register char *cp;
char *cp;
FILE *iop;
int argc, gargc, pdes[2], pid;
char **pop, *argv[100], *gargv[1000], *vv[2];
extern char **ftpglob(), **copyblk();
char **pop, *argv[100], *gargv[1000];
if (*type != 'r' && *type != 'w' || type[1])
return(NULL);
return (NULL);
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return(NULL);
return (NULL);
if ((pids = (int *)malloc((u_int)(fds * sizeof(int)))) == NULL)
return(NULL);
bzero((char *)pids, fds * sizeof(int));
return (NULL);
memset(pids, 0, fds * sizeof(int));
}
if (pipe(pdes) < 0)
return(NULL);
return (NULL);
/* break up string into pieces */
for (argc = 0, cp = program;; cp = NULL)
@ -87,14 +91,16 @@ ftpd_popen(program, type)
/* glob each piece */
gargv[0] = argv[0];
for (gargc = argc = 1; argv[argc]; argc++) {
if (!(pop = ftpglob(argv[argc]))) { /* globbing failed */
vv[0] = argv[argc];
vv[1] = NULL;
pop = copyblk(vv);
}
argv[argc] = (char *)pop; /* save to free later */
while (*pop && gargc < 1000)
gargv[gargc++] = *pop++;
glob_t gl;
int flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE;
memset(&gl, 0, sizeof(gl));
if (glob(argv[argc], flags, NULL, &gl))
gargv[gargc++] = strdup(argv[argc]);
else
for (pop = gl.gl_pathv; *pop; pop++)
gargv[gargc++] = strdup(*pop);
globfree(&gl);
}
gargv[gargc] = NULL;
@ -107,15 +113,15 @@ ftpd_popen(program, type)
/* NOTREACHED */
case 0: /* child */
if (*type == 'r') {
if (pdes[1] != 1) {
dup2(pdes[1], 1);
dup2(pdes[1], 2); /* stderr, too! */
if (pdes[1] != STDOUT_FILENO) {
dup2(pdes[1], STDOUT_FILENO);
(void)close(pdes[1]);
}
dup2(STDOUT_FILENO, STDERR_FILENO); /* stderr too! */
(void)close(pdes[0]);
} else {
if (pdes[0] != 0) {
dup2(pdes[0], 0);
if (pdes[0] != STDIN_FILENO) {
dup2(pdes[0], STDIN_FILENO);
(void)close(pdes[0]);
}
(void)close(pdes[1]);
@ -133,31 +139,34 @@ ftpd_popen(program, type)
}
pids[fileno(iop)] = pid;
pfree: for (argc = 1; argv[argc] != NULL; argc++) {
blkfree((char **)argv[argc]);
free((char *)argv[argc]);
}
return(iop);
pfree: for (argc = 1; gargv[argc] != NULL; argc++)
free(gargv[argc]);
return (iop);
}
int
ftpd_pclose(iop)
FILE *iop;
{
register int fdes;
int omask;
union wait stat_loc;
int pid;
int fdes, omask, status;
pid_t pid;
/*
* pclose returns -1 if stream is not associated with a
* `popened' command, or, if already `pclosed'.
*/
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
return(-1);
return (-1);
(void)fclose(iop);
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
while ((pid = wait((int *)&stat_loc)) != pids[fdes] && pid != -1);
while ((pid = waitpid(pids[fdes], &status, 0)) < 0 && errno == EINTR)
continue;
(void)sigsetmask(omask);
pids[fdes] = 0;
return(pid == -1 ? -1 : stat_loc.w_status);
if (pid < 0)
return (pid);
if (WIFEXITED(status))
return (WEXITSTATUS(status));
return (1);
}