remove ftpd200
This commit is contained in:
parent
ee8602a486
commit
f379b3eecb
15 changed files with 1 additions and 2655 deletions
|
@ -12,7 +12,7 @@ SUBDIR= aal add_route arp ash at autil awk \
|
|||
dhrystone diff dirname dis386 dis88 diskctl du dumpcore \
|
||||
ed eject elle elvis env expand factor file \
|
||||
find finger fingerd fix fold format fortune fsck.mfs \
|
||||
ftp101 ftpd200 gcov-pull getty grep head hexdump host \
|
||||
ftp101 gcov-pull getty grep head hexdump host \
|
||||
hostaddr id ifconfig ifdef install \
|
||||
intr ipcrm ipcs irdpd isoread join kill last leave \
|
||||
less lex loadkeys loadramdisk logger login look lp \
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
# Makefile for ftpd
|
||||
#
|
||||
# 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
# 2005-02-25 version 2.00
|
||||
|
||||
PROG= in.ftpd
|
||||
SRCS= ftpd.c access.c file.c net.c
|
||||
MAN= ftpd.8
|
||||
SCRIPTS= ftpdsh
|
||||
FILES= setup.anonftp
|
||||
NEED_NBSDLIBC=y
|
||||
LDADD+= -lcrypt
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -1,35 +0,0 @@
|
|||
ftpd200 --- FTP server program for Minix 2.0
|
||||
written by Michael Temari <Michael@TemWare.Com> release 2.00 2005-02-25
|
||||
|
||||
Full download: <a href="/pub/contrib/ftpd200.tar.Z">ftpd200.tar.Z</a>
|
||||
|
||||
Ftpd is the File Transfer Protocol (FTP) server.
|
||||
|
||||
Important: Release 2.00 incorporates an improved mechanism to restrict
|
||||
execution of commands on the server. This is done through use of a
|
||||
shell script, ftpdsh. Any earlier ftpd version in use on a system
|
||||
accessible from the Internet should be upgraded at least to version 1.01,
|
||||
version 2.00 is preferable.
|
||||
|
||||
Installation: unpack the tarball in /usr/local/src or another directory
|
||||
of your choice:
|
||||
zcat < ftpd200.tar.Z | tar xvfp -
|
||||
|
||||
The ftpd200 directory will be created. Read the Makefile to see how
|
||||
the program is compiled and installed:
|
||||
|
||||
make (or make ftpd) -- compiles the binary
|
||||
make install -- installs /usr/bin/in.ftpd, and ftpdsh. Also installs
|
||||
setup.anonftp script.
|
||||
make installman -- installs new ftpd.8 man page in /usr/local/man/man8
|
||||
|
||||
The shell script setup.anonftp sets up and verifies configuration for
|
||||
anonymous ftp. If you provide anonymous ftp you are letting anyone in
|
||||
the whole wide world execute a program on your computer. You want to
|
||||
make sure it's set up correctly so outsiders can't mess with things
|
||||
they shouldn't.
|
||||
|
||||
This file is included as README in the source directory. For more
|
||||
notes on compiling and installing, also please see the file README2.
|
||||
|
||||
notes updated by asw 2005-02-25
|
|
@ -1,34 +0,0 @@
|
|||
README2: additional notes on compiling and installing ftpd.
|
||||
|
||||
Note that the Makefile install options will replace files in /usr/bin
|
||||
and /usr/man that were installed with the Minix distribution. If you
|
||||
are not sure you want to do this you can either rename the original
|
||||
in.ftpd binary, the anonftp.* scripts, and the ftpd.8 man page to
|
||||
prevent them from being replaced, or you can edit the Makefile to
|
||||
change the directory values:
|
||||
BINDIR= /usr/local/bin
|
||||
MANDIR= /usr/local/man/man8
|
||||
ASW's practice is to rename binaries with a suffix that indicates the
|
||||
original distribution from which they were obtained, i.e., in.ftpd.203
|
||||
for the version distributed with Minix 2.0.3, or with a date code or a
|
||||
version number.
|
||||
|
||||
If you are sure you want to replace the original ftpd provided with your
|
||||
distribution you may want to copy the contents of the unpacked tarball
|
||||
to the main directory tree, in this case /usr/src/commands/ftpd, so that
|
||||
a new version will be compiled if you do a general recompilation of all
|
||||
commands using "make all" or "make compile" in /usr/src. ASW's practice
|
||||
is generally to make a directory in /usr/local/src for new versions of
|
||||
major programs.
|
||||
Also note that if you create a new man page where one did not exist
|
||||
previously you will need to run makewhatis to rebuild the whatis
|
||||
database, i.e.:
|
||||
makewhatis /usr/man
|
||||
or
|
||||
makewhatis /usr/local/man
|
||||
|
||||
Important: the scripts for setting up and maintaining an anonymous ftp
|
||||
installation haven't been checked for a long time, I would appreciate
|
||||
comments.
|
||||
|
||||
ASW 2005-02-06
|
|
@ -1,134 +0,0 @@
|
|||
/* access.c Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
* This file handles:
|
||||
*
|
||||
* USER PASS QUIT
|
||||
*
|
||||
*
|
||||
* 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <net/gen/in.h>
|
||||
#include <net/gen/tcp.h>
|
||||
|
||||
#include "ftpd.h"
|
||||
#include "access.h"
|
||||
|
||||
_PROTOTYPE(static int AreWeIn, (char *name, struct passwd *pwd));
|
||||
|
||||
static char *msg530 = "530 Not logged in.\r\n";
|
||||
|
||||
/* Returns -1 = not logged in, 0 = loggedin */
|
||||
int ChkLoggedIn()
|
||||
{
|
||||
if(!loggedin) {
|
||||
printf(msg530);
|
||||
return(-1);
|
||||
} else
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* what a USER! */
|
||||
int doUSER(buff)
|
||||
char *buff;
|
||||
{
|
||||
loggedin = 0;
|
||||
gotuser = 0;
|
||||
strncpy(username, buff, sizeof(username));
|
||||
username[sizeof(username)-1] = '\0';
|
||||
|
||||
if(*username == '\0') {
|
||||
printf("501 Bad user name.\r\n");
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
gotuser = 1;
|
||||
|
||||
printf("331 Password required for %s.\r\n", username);
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* secret, secret, secret */
|
||||
int doPASS(buff)
|
||||
char *buff;
|
||||
{
|
||||
char *name;
|
||||
struct passwd *pwd;
|
||||
int bad=0;
|
||||
|
||||
name = username;
|
||||
|
||||
if(!strcmp(name, "anonymous"))
|
||||
name = "ftp";
|
||||
|
||||
if(!gotuser || ((pwd = getpwnam(name)) == (struct passwd *)0))
|
||||
bad = 1;
|
||||
else
|
||||
if(strcmp(name, "ftp")) {
|
||||
if(!strcmp(pwd->pw_passwd, crypt("", pwd->pw_passwd)))
|
||||
bad = 1;
|
||||
if(strcmp(pwd->pw_passwd, crypt(buff, pwd->pw_passwd)))
|
||||
bad = 1;
|
||||
} else {
|
||||
strncpy(anonpass, buff, sizeof(anonpass));
|
||||
anonpass[sizeof(anonpass)-1] = '\0';
|
||||
}
|
||||
|
||||
if(bad) {
|
||||
logit("LOGIN", "FAIL");
|
||||
printf(msg530);
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
return(AreWeIn(name, pwd));
|
||||
}
|
||||
|
||||
/* bye, bye don't let the door hit you in the butt on the way out */
|
||||
int doQUIT(buff)
|
||||
char *buff;
|
||||
{
|
||||
printf("221 Service closing, don't be a stranger.\r\n");
|
||||
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
/* see if this user is okay */
|
||||
static int AreWeIn(name, pwd)
|
||||
char *name;
|
||||
struct passwd *pwd;
|
||||
{
|
||||
if(!strcmp(name, "ftp")) {
|
||||
if(chroot(pwd->pw_dir)) {
|
||||
logit("LOGIN", "FAIL");
|
||||
printf("530 Not logged in, could not chroot.\r\n");
|
||||
return(GOOD);
|
||||
}
|
||||
strncpy(newroot, pwd->pw_dir, sizeof(newroot));
|
||||
newroot[sizeof(newroot)-1] = '\0';
|
||||
anonymous = 1;
|
||||
strcpy(pwd->pw_dir, "/");
|
||||
}
|
||||
|
||||
if(setgid(pwd->pw_gid) || setuid(pwd->pw_uid) || chdir(pwd->pw_dir)) {
|
||||
logit("LOGIN", "FAIL");
|
||||
printf(msg530);
|
||||
anonymous = 0;
|
||||
} else {
|
||||
logit("LOGIN", "PASS");
|
||||
showmsg("230", (char *)NULL);
|
||||
printf("230 User %s logged in, directory %s.\r\n",
|
||||
username, pwd->pw_dir);
|
||||
loggedin = 1;
|
||||
}
|
||||
|
||||
return(GOOD);
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
/* ftpd.h
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
*
|
||||
* 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
_PROTOTYPE(int ChkLoggedIn, (void));
|
||||
_PROTOTYPE(int doUSER, (char *buff));
|
||||
_PROTOTYPE(int doPASS, (char *buff));
|
||||
_PROTOTYPE(int doQUIT, (char *buff));
|
File diff suppressed because it is too large
Load diff
|
@ -1,32 +0,0 @@
|
|||
/* file.h Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
*
|
||||
* 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
_PROTOTYPE(int doALLO, (char *buff));
|
||||
_PROTOTYPE(int doAPPE, (char *buff));
|
||||
_PROTOTYPE(int doCDUP, (char *buff));
|
||||
_PROTOTYPE(int doCWD, (char *buff));
|
||||
_PROTOTYPE(int doDELE, (char *buff));
|
||||
_PROTOTYPE(int doLIST, (char *buff));
|
||||
_PROTOTYPE(int doMDTM, (char *buff));
|
||||
_PROTOTYPE(int doMODE, (char *buff));
|
||||
_PROTOTYPE(int doMKD, (char *buff));
|
||||
_PROTOTYPE(int doNLST, (char *buff));
|
||||
_PROTOTYPE(int doPWD, (char *buff));
|
||||
_PROTOTYPE(int doREST, (char *buff));
|
||||
_PROTOTYPE(int doRETR, (char *buff));
|
||||
_PROTOTYPE(int doRMD, (char *buff));
|
||||
_PROTOTYPE(int doRNFR, (char *buff));
|
||||
_PROTOTYPE(int doRNTO, (char *buff));
|
||||
_PROTOTYPE(int doSITE, (char *buff));
|
||||
_PROTOTYPE(int doSIZE, (char *buff));
|
||||
_PROTOTYPE(int doSTAT, (char *buff));
|
||||
_PROTOTYPE(int doSTOR, (char *buff));
|
||||
_PROTOTYPE(int doSTOU, (char *buff));
|
||||
_PROTOTYPE(int doSTRU, (char *buff));
|
||||
_PROTOTYPE(int doSYST, (char *buff));
|
||||
_PROTOTYPE(int doTYPE, (char *buff));
|
|
@ -1,161 +0,0 @@
|
|||
.\" Copyright (c) 1985 Regents of the University of California.
|
||||
.\" All rights reserved. The Berkeley software License Agreement
|
||||
.\" specifies the terms and conditions for redistribution.
|
||||
.\"
|
||||
.\" @(#)ftpd.8c 6.4 (Berkeley) 5/28/86
|
||||
.\"
|
||||
.TH FTPD 8
|
||||
.SH NAME
|
||||
ftpd, in.ftpd, ftpdsh, setup.anonftp \- DARPA Internet File Transfer Protocol server
|
||||
.SH SYNOPSIS
|
||||
.B "ftp stream tcp nowait root /usr/bin/in.ftpd in.ftpd"
|
||||
.br
|
||||
.B "tcpd ftp /usr/bin/in.ftpd"
|
||||
.SH DESCRIPTION
|
||||
.B Ftpd
|
||||
is the DARPA Internet File Transfer Prototocol
|
||||
server process. The server uses the TCP protocol
|
||||
and listens at the port specified in the ``ftp''
|
||||
service specification; see
|
||||
.BR services (5).
|
||||
.PP
|
||||
The ftp server currently supports the following ftp
|
||||
requests; case is not distinguished.
|
||||
.PP
|
||||
.nf
|
||||
.ta \w'Request 'u
|
||||
\fBRequest Description\fP
|
||||
ABOR abort previous command
|
||||
ACCT specify account (ignored)
|
||||
ALLO allocate storage (vacuously)
|
||||
APPE append to a file
|
||||
CDUP change to parent of current working directory
|
||||
CWD change working directory
|
||||
DELE delete a file
|
||||
HELP give help information
|
||||
LIST give list files in a directory (``ls -lA'')
|
||||
MKD make a directory
|
||||
MODE specify data transfer \fImode\fP
|
||||
NLST give name list of files in directory (``ls'')
|
||||
NOOP do nothing
|
||||
PASS specify password
|
||||
PASV prepare for server-to-server transfer
|
||||
PORT specify data connection port
|
||||
PWD print the current working directory
|
||||
QUIT terminate session
|
||||
RETR retrieve a file
|
||||
RMD remove a directory
|
||||
RNFR specify rename-from file name
|
||||
RNTO specify rename-to file name
|
||||
STOR store a file
|
||||
STOU store a file with a unique name
|
||||
STRU specify data transfer \fIstructure\fP
|
||||
TYPE specify data transfer \fItype\fP
|
||||
USER specify user name
|
||||
XCUP change to parent of current working directory
|
||||
XCWD change working directory
|
||||
XMKD make a directory
|
||||
XPWD print the current working directory
|
||||
XRMD remove a directory
|
||||
.fi
|
||||
.PP
|
||||
The remaining ftp requests specified in Internet RFC 959 are
|
||||
recognized, but not implemented.
|
||||
.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 RFC 959.
|
||||
.PP
|
||||
.B Ftpd
|
||||
interprets file names according to the ``globbing''
|
||||
conventions used by
|
||||
.BR csh (1).
|
||||
This allows users to utilize the metacharacters ``*?[]{}~''.
|
||||
.PP
|
||||
.B Ftpd
|
||||
authenticates users according to two rules.
|
||||
.IP 1)
|
||||
The user name must be in the password data base,
|
||||
.BR /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.
|
||||
.IP 2)
|
||||
If the user name is ``anonymous'' or ``ftp'', an
|
||||
anonymous ftp account must be present in the password
|
||||
file (user ``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).
|
||||
.PP
|
||||
In the last case,
|
||||
.B ftpd
|
||||
takes special measures to restrict the client's access privileges.
|
||||
The server performs a
|
||||
.BR chroot (2)
|
||||
command to the home directory of the ``ftp'' user.
|
||||
In order that system security is not breached, it is recommended
|
||||
that the ``ftp'' subtree be constructed with care; the following
|
||||
rules are recommended.
|
||||
.IP ~ftp)
|
||||
Make the home directory owned by ``ftp'' and unwritable by anyone.
|
||||
.IP ~ftp/bin)
|
||||
Make this directory owned by the super-user and unwritable by
|
||||
anyone. The program
|
||||
.BR ls (1)
|
||||
must be present to support the list commands.
|
||||
Also,
|
||||
.BR crc (1)
|
||||
must be present to support generating crcs using the site command,
|
||||
.BR tar (1)
|
||||
and
|
||||
.BR compress (1)
|
||||
must be present to support on-the-fly generation of .tar and .tar.Z archives,
|
||||
.BR gzip (1)
|
||||
must be present to support gzip compression, and
|
||||
.BR sh (1)
|
||||
must be present to support
|
||||
.BR ftpdsh (8)
|
||||
which also must be present.
|
||||
.BR ftpdsh controls which binaries can be used.
|
||||
These programs should all have mode 111.
|
||||
.IP ~ftp/etc)
|
||||
Make this directory owned by the super-user and unwritable by
|
||||
anyone. The files
|
||||
.BR passwd (5)
|
||||
and
|
||||
.BR group (5)
|
||||
must be present for the
|
||||
.B ls
|
||||
command to work properly. These files should be mode 444. They can (and
|
||||
should) be stripped down versions so as not to reveal names of users who
|
||||
are not owners of files in the ~ftp/pub directory tree.
|
||||
.IP ~ftp/pub)
|
||||
Make this directory mode 755 and owned by the super-user. Create
|
||||
directories in it owned by users if those users want to manage an
|
||||
anonymous ftp directory.
|
||||
.IP ~ftp/pub/incoming)
|
||||
Optionally create this directory for anonymous uploads. Make it mode
|
||||
777. The FTP daemon will create files with mode 266, so remote users
|
||||
can write a file, but only local users can do something with it.
|
||||
.PP
|
||||
The script
|
||||
.B setup.anonftp
|
||||
can be used to create or check an anonymous FTP tree.
|
||||
.SH "SEE ALSO"
|
||||
.BR ftp (1).
|
||||
.SH BUGS
|
||||
The anonymous account is inherently dangerous and should
|
||||
avoided when possible.
|
||||
.ig \" Minix doesn't have privileged port numbers (yet?)
|
||||
.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
|
||||
the super-user only when binding addresses to sockets. The
|
||||
possible security holes have been extensively
|
||||
scrutinized, but are possibly incomplete.
|
||||
..
|
||||
.\" man page updated by Al Woodhull 2005-02-25
|
||||
|
||||
|
|
@ -1,410 +0,0 @@
|
|||
/* ftpd.c Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* ftpd An FTP server program for use with Minix.
|
||||
*
|
||||
* Usage: Minix usage: tcpd ftp ftpd
|
||||
*
|
||||
* 06/14/92 Tnet Release Michael Temari
|
||||
* 01/15/96 0.30 Michael Temari
|
||||
* 01/25/96 0.90 Michael Temari
|
||||
* 03/17/96 0.91 Michael Temari
|
||||
* 06/27/96 0.92 Michael Temari
|
||||
* 07/02/96 0.93 Michael Temari
|
||||
* 07/15/96 0.94 Michael Temari
|
||||
* 08/27/96 0.95 Michael Temari
|
||||
* 02/09/97 0.96 Michael Temari
|
||||
* 02/10/97 0.97 Michael Temari
|
||||
* 09/25/97 0.98 Michael Temari
|
||||
* 03/10/00 0.99 Michael Temari, <Michael@TemWare.Com>
|
||||
* 12/12/03 1.00 Michael Temari, <Michael@TemWare.Com>
|
||||
* 02/06/05 1.01 Michael Temari, <Michael@TemWare.Com>
|
||||
* 02/12/05 2.00 Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
char *FtpdVersion = "2.00";
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <net/gen/in.h>
|
||||
#include <net/gen/tcp.h>
|
||||
|
||||
#include "ftpd.h"
|
||||
#include "access.h"
|
||||
#include "file.h"
|
||||
#include "net.h"
|
||||
|
||||
#ifdef __NBSD_LIBC
|
||||
/* Already declared in stdio.h */
|
||||
#define getline ftpd_getline
|
||||
#endif
|
||||
|
||||
_PROTOTYPE(static void init, (void));
|
||||
_PROTOTYPE(static int doHELP, (char *buff));
|
||||
_PROTOTYPE(static int doNOOP, (char *buff));
|
||||
_PROTOTYPE(static int doUNIMP, (char *buff));
|
||||
_PROTOTYPE(static int getline, (char *line, int len));
|
||||
|
||||
FILE *msgfile = (FILE *)NULL;
|
||||
|
||||
/* The following defines the inactivity timeout in seconds */
|
||||
#define INACTIVITY_TIMEOUT 60*5
|
||||
|
||||
char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
char line[512];
|
||||
|
||||
int type, format, mode, structure;
|
||||
int ftpdata_fd = -1;
|
||||
int loggedin, gotuser, anonymous;
|
||||
char username[80];
|
||||
char anonpass[128];
|
||||
char newroot[128];
|
||||
|
||||
ipaddr_t myipaddr, rmtipaddr, dataaddr;
|
||||
tcpport_t myport, rmtport, dataport;
|
||||
|
||||
char myhostname[256], rmthostname[256];
|
||||
|
||||
#define FTPD_LOG "/usr/adm/ftpd.log"
|
||||
#define FTPD_MSG "/etc/ftpd_msg"
|
||||
|
||||
FILE *logfile;
|
||||
|
||||
int timeout = 0;
|
||||
|
||||
_PROTOTYPE(static int doHELP, (char *buff));
|
||||
_PROTOTYPE(int readline, (char **args));
|
||||
_PROTOTYPE(void Timeout, (int sig));
|
||||
_PROTOTYPE(int main, (int argc, char *argv[]));
|
||||
|
||||
struct commands {
|
||||
char *name;
|
||||
_PROTOTYPE(int (*func), (char *buff));
|
||||
};
|
||||
|
||||
struct commands commands[] = {
|
||||
"ABOR", doUNIMP,
|
||||
"ACCT", doUNIMP,
|
||||
"ALLO", doALLO,
|
||||
"APPE", doAPPE,
|
||||
"CDUP", doCDUP,
|
||||
"CWD", doCWD,
|
||||
"DELE", doDELE,
|
||||
"HELP", doHELP,
|
||||
"LIST", doLIST,
|
||||
"MDTM", doMDTM,
|
||||
"MKD", doMKD,
|
||||
"MODE", doMODE,
|
||||
"NLST", doNLST,
|
||||
"NOOP", doNOOP,
|
||||
"PASS", doPASS,
|
||||
"PASV", doPASV,
|
||||
"PORT", doPORT,
|
||||
"PWD", doPWD,
|
||||
"QUIT", doQUIT,
|
||||
"REIN", doUNIMP,
|
||||
"REST", doREST,
|
||||
"RETR", doRETR,
|
||||
"RMD", doRMD,
|
||||
"RNFR", doRNFR,
|
||||
"RNTO", doRNTO,
|
||||
"SITE", doSITE,
|
||||
"SIZE", doSIZE,
|
||||
"SMNT", doUNIMP,
|
||||
"STAT", doSTAT,
|
||||
"STOR", doSTOR,
|
||||
"STOU", doSTOU,
|
||||
"STRU", doSTRU,
|
||||
"SYST", doSYST,
|
||||
"TYPE", doTYPE,
|
||||
"USER", doUSER,
|
||||
"XCUP", doCDUP,
|
||||
"XCWD", doCWD,
|
||||
"XMKD", doMKD,
|
||||
"XPWD", doPWD,
|
||||
"XRMD", doRMD,
|
||||
"", (int (*)())0
|
||||
};
|
||||
|
||||
static void init()
|
||||
{
|
||||
loggedin = 0;
|
||||
gotuser = 0;
|
||||
anonymous = 0;
|
||||
newroot[0] = '\0';
|
||||
type = TYPE_A;
|
||||
format = 0;
|
||||
mode = MODE_S;
|
||||
structure = 0;
|
||||
ftpdata_fd = -1;
|
||||
username[0] = '\0';
|
||||
anonpass[0] = '\0';
|
||||
}
|
||||
|
||||
/* nothing, nada, zilch... */
|
||||
static int doNOOP(buff)
|
||||
char *buff;
|
||||
{
|
||||
printf("200 NOOP to you too!\r\n");
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* giv'em help, what a USER! */
|
||||
static int doHELP(buff)
|
||||
char *buff;
|
||||
{
|
||||
struct commands *cmd;
|
||||
char star;
|
||||
int i;
|
||||
char *space = " ";
|
||||
|
||||
printf("214-Here is a list of available ftp commands\r\n");
|
||||
printf(" Those with '*' are not yet implemented.\r\n");
|
||||
|
||||
i = 0;
|
||||
for(cmd = commands; *cmd->name != '\0'; cmd++) {
|
||||
if(cmd->func == doUNIMP)
|
||||
star = '*';
|
||||
else
|
||||
star = ' ';
|
||||
printf(" %s%c%s", cmd->name, star, space + strlen(cmd->name));
|
||||
if(++i == 6) {
|
||||
printf("\r\n");
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(i)
|
||||
printf("\r\n");
|
||||
|
||||
printf("214 That's all the help you get.\r\n");
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* not implemented */
|
||||
static int doUNIMP(buff)
|
||||
char *buff;
|
||||
{
|
||||
printf("502 Command \"%s\" not implemented!\r\n", line);
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* convert line for use */
|
||||
void cvtline(args)
|
||||
char **args;
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = line + strlen(line);
|
||||
while(--p >= line)
|
||||
if(*p == '\r' || *p == '\n' || isspace(*p))
|
||||
*p = '\0';
|
||||
else
|
||||
break;
|
||||
|
||||
p = line;
|
||||
|
||||
#ifdef DEBUG
|
||||
logit("COMMAND", line);
|
||||
#endif
|
||||
|
||||
while(*p && !isspace(*p)) {
|
||||
*p = toupper(*p);
|
||||
p++;
|
||||
}
|
||||
|
||||
if(*p) {
|
||||
*p = '\0';
|
||||
p++;
|
||||
while(*p && isspace(*p))
|
||||
p++;
|
||||
}
|
||||
|
||||
*args = p;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static int getline(line, len)
|
||||
char *line;
|
||||
int len;
|
||||
{
|
||||
int s;
|
||||
int gotcr;
|
||||
|
||||
/* leave room for at end for null */
|
||||
len--;
|
||||
|
||||
/* got to be able to put in at least 1 character */
|
||||
if(len < 1)
|
||||
return(-1);
|
||||
|
||||
gotcr = 0;
|
||||
while(len-- > 0) {
|
||||
s = read(0, line, 1);
|
||||
if(s != 1)
|
||||
return(-1);
|
||||
if(*line == '\n')
|
||||
break;
|
||||
gotcr = (*line == '\r');
|
||||
line++;
|
||||
}
|
||||
if(gotcr)
|
||||
--line;
|
||||
|
||||
*line = '\0';
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
int readline(args)
|
||||
char **args;
|
||||
{
|
||||
if(getline(line, sizeof(line)))
|
||||
return(BAD);
|
||||
|
||||
cvtline(args);
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* signal handler for inactivity timeout */
|
||||
void Timeout(sig)
|
||||
int sig;
|
||||
{
|
||||
timeout = 1;
|
||||
|
||||
printf("421 Inactivity timer expired.\r\n");
|
||||
}
|
||||
|
||||
/* logit */
|
||||
void logit(type, parm)
|
||||
char *type;
|
||||
char *parm;
|
||||
{
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
|
||||
if(logfile == (FILE *)NULL)
|
||||
return;
|
||||
|
||||
time(&now);
|
||||
tm = localtime(&now);
|
||||
fprintf(logfile, "%4d%02d%02d%02d%02d%02d ",
|
||||
1900+tm->tm_year,
|
||||
tm->tm_mon + 1,
|
||||
tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
fprintf(logfile, "%s %s %s %s %s\n",
|
||||
rmthostname, username, anonymous ? anonpass : username, type, parm);
|
||||
fflush(logfile);
|
||||
}
|
||||
|
||||
void showmsg(reply, filename)
|
||||
char *reply;
|
||||
char *filename;
|
||||
{
|
||||
FILE *mfp;
|
||||
char *pe;
|
||||
static char mline[256];
|
||||
|
||||
if(filename == (char *)NULL)
|
||||
mfp = msgfile;
|
||||
else
|
||||
mfp = fopen(filename, "r");
|
||||
|
||||
if(mfp == (FILE *)NULL)
|
||||
return;
|
||||
|
||||
while(fgets(mline, sizeof(mline), mfp) != (char *)NULL) {
|
||||
pe = mline + strlen(mline);
|
||||
while(--pe >= mline)
|
||||
if(*pe == '\r' || *pe == '\n')
|
||||
*pe = '\0';
|
||||
else
|
||||
break;
|
||||
printf("%s- %s\r\n", reply, mline);
|
||||
}
|
||||
|
||||
if(filename != (char *)NULL)
|
||||
fclose(mfp);
|
||||
}
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
struct commands *cmd;
|
||||
char *args;
|
||||
int status;
|
||||
time_t now;
|
||||
struct tm *tm;
|
||||
int s;
|
||||
|
||||
GetNetInfo();
|
||||
|
||||
/* open transfer log file if it exists */
|
||||
if((logfile = fopen(FTPD_LOG, "r")) != (FILE *)NULL) {
|
||||
fclose(logfile);
|
||||
logfile = fopen(FTPD_LOG, "a");
|
||||
}
|
||||
|
||||
/* open login msg file */
|
||||
msgfile = fopen(FTPD_MSG, "r");
|
||||
|
||||
/* Let's initialize some stuff */
|
||||
init();
|
||||
|
||||
/* Log the connection */
|
||||
logit("CONNECT", "");
|
||||
|
||||
/* Tell 'em we are ready */
|
||||
time(&now);
|
||||
tm = localtime(&now);
|
||||
printf("220 FTP service (Ftpd %s) ready on %s at ",
|
||||
FtpdVersion, myhostname);
|
||||
printf("%s, %02d %s %d %02d:%02d:%02d %s\r\n", days[tm->tm_wday],
|
||||
tm->tm_mday, months[tm->tm_mon], 1900+tm->tm_year,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec,
|
||||
tzname[tm->tm_isdst]);
|
||||
fflush(stdout);
|
||||
|
||||
/* Loop here getting commands */
|
||||
while(1) {
|
||||
signal(SIGALRM, Timeout);
|
||||
alarm(INACTIVITY_TIMEOUT);
|
||||
if(readline(&args) != GOOD) {
|
||||
if(!timeout)
|
||||
printf("221 Control connection closing (EOF).\r\n");
|
||||
break;
|
||||
}
|
||||
alarm(0);
|
||||
for(cmd = commands; *cmd->name != '\0'; cmd++)
|
||||
if(!strcmp(line, cmd->name))
|
||||
break;
|
||||
if(*cmd->name != '\0')
|
||||
status = (*cmd->func)(args);
|
||||
else {
|
||||
printf("500 Command \"%s\" not recognized.\r\n", line);
|
||||
status = GOOD;
|
||||
}
|
||||
fflush(stdout);
|
||||
if(status != GOOD)
|
||||
break;
|
||||
}
|
||||
|
||||
CleanUpPasv();
|
||||
|
||||
return(-1);
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
/* ftpd.h Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
*
|
||||
* 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
#define GOOD 0
|
||||
#define BAD 1
|
||||
|
||||
#define TYPE_A 0
|
||||
#define TYPE_I 1
|
||||
|
||||
#define MODE_S 0
|
||||
#define MODE_B 1
|
||||
|
||||
#define MODE_B_EOF 64
|
||||
|
||||
extern char *FtpdVersion;
|
||||
extern int type, format, mode, structure;
|
||||
extern ipaddr_t myipaddr, rmtipaddr, dataaddr;
|
||||
extern tcpport_t myport, rmtport, dataport;
|
||||
extern int ftpdata_fd;
|
||||
extern int loggedin, gotuser, anonymous;
|
||||
extern char newroot[128];
|
||||
extern char *days[], *months[];
|
||||
extern char username[80];
|
||||
extern char anonpass[128];
|
||||
extern char myhostname[256], rmthostname[256];
|
||||
extern char line[512];
|
||||
|
||||
extern FILE *logfile;
|
||||
|
||||
_PROTOTYPE(void cvtline, (char **args));
|
||||
_PROTOTYPE(void logit, (char *type, char *parm));
|
||||
_PROTOTYPE(void showmsg, (char *reply, char *filename));
|
|
@ -1,14 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
case $1 in
|
||||
1) ls -A $2 ;;
|
||||
2) ls -la $2 ;;
|
||||
3) crc $2 ;;
|
||||
12) tar cf - $2 ;;
|
||||
13) tar cf - $2 | compress -q ;;
|
||||
14) compress -cq $2 ;;
|
||||
15) tar cf - $2 | gzip ;;
|
||||
16) tar -c $2 ;;
|
||||
17) compress -dcq $2 ;;
|
||||
esac
|
||||
exit
|
|
@ -1,431 +0,0 @@
|
|||
/* net.c Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
* This file handles:
|
||||
*
|
||||
* PASV PORT
|
||||
*
|
||||
*
|
||||
* 01/25/1995 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
* 02/09/2005 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <net/netlib.h>
|
||||
#include <net/hton.h>
|
||||
#include <net/gen/in.h>
|
||||
#include <net/gen/inet.h>
|
||||
#include <net/gen/tcp.h>
|
||||
#include <net/gen/tcp_io.h>
|
||||
#include <net/gen/socket.h>
|
||||
#include <net/gen/netdb.h>
|
||||
|
||||
#include "ftpd.h"
|
||||
#include "access.h"
|
||||
#include "net.h"
|
||||
|
||||
_PROTOTYPE(static void timeout, (int sig));
|
||||
|
||||
static char *msg425 = "425-Could not open data connection.\r\n";
|
||||
static char *msg501 = "501 Syntax error in parameters.\r\n";
|
||||
|
||||
static int gottimeout = 0;
|
||||
static int lpid = -1;
|
||||
static int didpassive = 0;
|
||||
|
||||
/* they must be behind a firewall or using a web browser */
|
||||
int doPASV(buff)
|
||||
char *buff;
|
||||
{
|
||||
nwio_tcpconf_t tcpconf;
|
||||
nwio_tcpcl_t tcplopt;
|
||||
char *tcp_device;
|
||||
ipaddr_t ipaddr;
|
||||
tcpport_t lport;
|
||||
int s;
|
||||
time_t starttime;
|
||||
int retry;
|
||||
|
||||
if(ChkLoggedIn())
|
||||
return(GOOD);
|
||||
|
||||
CleanUpPasv();
|
||||
|
||||
/* here we set up a connection to listen on */
|
||||
if((tcp_device = getenv("TCP_DEVICE")) == NULL)
|
||||
tcp_device = TCP_DEVICE;
|
||||
|
||||
if(ftpdata_fd >= 0) {
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
}
|
||||
|
||||
if((ftpdata_fd = open(tcp_device, O_RDWR)) < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not open tcp_device. Error %s\r\n", strerror(errno));
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
tcpconf.nwtc_flags = NWTC_LP_SEL | NWTC_SET_RA | NWTC_UNSET_RP;
|
||||
|
||||
tcpconf.nwtc_remaddr = rmtipaddr;
|
||||
tcpconf.nwtc_remport = htons(0);
|
||||
tcpconf.nwtc_locport = htons(0);
|
||||
|
||||
s = ioctl(ftpdata_fd, NWIOSTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not ioctl NWIOSTCPCONF. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not NWIOGTCPCONF. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(GOOD);
|
||||
}
|
||||
ipaddr = tcpconf.nwtc_locaddr;
|
||||
lport = tcpconf.nwtc_locport;
|
||||
|
||||
/* Now lets fork a child to do the listening :-( */
|
||||
|
||||
tcplopt.nwtcl_flags = 0;
|
||||
|
||||
lpid = fork();
|
||||
if(lpid < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not fork listener. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(GOOD);
|
||||
} else if(lpid == 0) {
|
||||
retry = 0;
|
||||
while(1) {
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: child %d parent %d listen try %d\n", getpid(), getppid(), retry);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
s = ioctl(ftpdata_fd, NWIOTCPLISTEN, &tcplopt);
|
||||
if(!(s == -1 && errno == EAGAIN)) break;
|
||||
if(retry++ > 10) break;
|
||||
sleep(1);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: child %d s %d errno %d\n", getpid(), s, errno);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
if(s < 0)
|
||||
exit(errno); /* tells parent listen failed */
|
||||
else
|
||||
exit(0); /* tells parent listen okay */
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d wait for %d\n", getpid(), lpid);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
|
||||
/* wait for child to be listening, no more than serveral seconds */
|
||||
(void) time(&starttime);
|
||||
while(1) {
|
||||
if(time((time_t *)NULL) > (starttime + 15)) break;
|
||||
signal(SIGALRM, timeout);
|
||||
alarm(1);
|
||||
s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d s %d errno %d start %ld now %ld\n",
|
||||
getpid(), lpid, s, errno, starttime, time((time_t *)NULL));
|
||||
fflush(logfile);
|
||||
#endif
|
||||
alarm(0);
|
||||
if(s == -1) break;
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
#define hiword(x) ((u16_t)((x) >> 16))
|
||||
#define loword(x) ((u16_t)(x & 0xffff))
|
||||
#define hibyte(x) (((x) >> 8) & 0xff)
|
||||
#define lobyte(x) ((x) & 0xff)
|
||||
|
||||
printf("227 Entering Passive Mode (%u,%u,%u,%u,%u,%u).\r\n",
|
||||
hibyte(hiword(htonl(ipaddr))), lobyte(hiword(htonl(ipaddr))),
|
||||
hibyte(loword(htonl(ipaddr))), lobyte(loword(htonl(ipaddr))),
|
||||
hibyte(htons(lport)), lobyte(htons(lport)));
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d send 227\n", getpid(), lpid);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
|
||||
didpassive = -1;
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* they want us to connect here */
|
||||
int doPORT(buff)
|
||||
char *buff;
|
||||
{
|
||||
u32_t ipaddr;
|
||||
u16_t port;
|
||||
int i;
|
||||
|
||||
if(ftpdata_fd >= 0) {
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
}
|
||||
|
||||
ipaddr = (u32_t)0;
|
||||
for(i = 0; i < 4; i++) {
|
||||
ipaddr = (ipaddr << 8) + (u32_t)atoi(buff);
|
||||
if((buff = strchr(buff, ',')) == (char *)0) {
|
||||
printf(msg501);
|
||||
return(GOOD);
|
||||
}
|
||||
buff++;
|
||||
}
|
||||
port = (u16_t)atoi(buff);
|
||||
if((buff = strchr(buff, ',')) == (char *)0) {
|
||||
printf(msg501);
|
||||
return(0);
|
||||
}
|
||||
buff++;
|
||||
port = (port << 8) + (u16_t)atoi(buff);
|
||||
|
||||
dataaddr = htonl(ipaddr);
|
||||
dataport = htons(port);
|
||||
if(dataaddr != rmtipaddr) {
|
||||
printf(msg501);
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
printf("200 Port command okay.\r\n");
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* connect, huh? */
|
||||
int DataConnect()
|
||||
{
|
||||
nwio_tcpconf_t tcpconf;
|
||||
nwio_tcpcl_t tcpcopt;
|
||||
nwio_tcpcl_t tcplopt;
|
||||
char *tcp_device;
|
||||
int s, cs;
|
||||
int retry;
|
||||
|
||||
if(didpassive && ftpdata_fd >= 0) {
|
||||
didpassive = 0;
|
||||
gottimeout = 0;
|
||||
signal(SIGALRM, timeout);
|
||||
alarm(10);
|
||||
while(!gottimeout) {
|
||||
s = waitpid(lpid, &cs, 0);
|
||||
if((s == lpid) || (s < 0 && errno == ECHILD)) break;
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d waitpid s %d cs %04x errno %d\n", getpid(), lpid, s, cs, errno);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
}
|
||||
alarm(0);
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d waitpid s %d cs %04x errno %d\n", getpid(), lpid, s, cs, errno);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
if(gottimeout) {
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d got timeout\n", getpid(), lpid);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
kill(lpid, SIGKILL);
|
||||
s = waitpid(lpid, &cs, 0);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d continuing\n", getpid(), lpid);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
lpid = -1;
|
||||
if(gottimeout) {
|
||||
printf(msg425);
|
||||
printf("425 Child listener timeout.\r\n");
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Child listener vanished.\r\n");
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
if((cs & 0x00ff)) {
|
||||
printf(msg425);
|
||||
printf("425 Child listener failed %04x\r\n", cs);
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
cs = (cs >> 8) & 0x00ff;
|
||||
if(cs) {
|
||||
printf(msg425);
|
||||
printf("425 Child listener error %s\r\n", strerror(cs));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "ftpd: parent %d child %d pasv done\n", getpid(), lpid);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
if(ftpdata_fd >= 0)
|
||||
return(GOOD);
|
||||
|
||||
if((tcp_device = getenv("TCP_DEVICE")) == NULL)
|
||||
tcp_device = TCP_DEVICE;
|
||||
|
||||
if((ftpdata_fd = open(tcp_device, O_RDWR)) < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not open tcp_device. Error %s\r\n", strerror(errno));
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
tcpconf.nwtc_flags = NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP;
|
||||
tcpconf.nwtc_remaddr = dataaddr;
|
||||
tcpconf.nwtc_remport = dataport;
|
||||
tcpconf.nwtc_locport = htons(20);
|
||||
|
||||
s = ioctl(ftpdata_fd, NWIOSTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not ioctl NWIOSTCPCONF. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not ioctl NWIOGTCPCONF. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
tcpcopt.nwtcl_flags = 0;
|
||||
|
||||
retry = 0;
|
||||
do {
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "try connect\n"); fflush(logfile);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
sleep(2);
|
||||
s = ioctl(ftpdata_fd, NWIOTCPCONN, &tcpcopt);
|
||||
#ifdef DEBUG
|
||||
fprintf(logfile, "after connect %d %d\n", s, errno);
|
||||
fflush(logfile);
|
||||
#endif
|
||||
if(!(s == -1 && errno == EAGAIN)) break;
|
||||
if(retry++ > 10) break;
|
||||
sleep(1);
|
||||
} while(1);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not ioctl NWIOTCPCONN. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
s = ioctl(ftpdata_fd, NWIOGTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf(msg425);
|
||||
printf("425 Could not ioctl NWIOGTCPCONF. Error %s\r\n", strerror(errno));
|
||||
close(ftpdata_fd);
|
||||
ftpdata_fd = -1;
|
||||
return(BAD);
|
||||
}
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
/* Clean up stuff we did to get a Pasv connection going */
|
||||
int CleanUpPasv()
|
||||
{
|
||||
int s, cs;
|
||||
|
||||
if(lpid >= 0) {
|
||||
kill(lpid, SIGKILL);
|
||||
while(1) {
|
||||
s = waitpid(lpid, &cs, 0);
|
||||
if(s == lpid || (s == -1 && errno == ECHILD))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lpid = -1;
|
||||
|
||||
didpassive = 0;
|
||||
|
||||
return(GOOD);
|
||||
}
|
||||
|
||||
void GetNetInfo()
|
||||
{
|
||||
nwio_tcpconf_t tcpconf;
|
||||
int s;
|
||||
struct hostent *hostent;
|
||||
|
||||
/* Ask the system what our hostname is. */
|
||||
if(gethostname(myhostname, sizeof(myhostname)) < 0)
|
||||
strcpy(myhostname, "unknown");
|
||||
|
||||
/* lets get our ip address and the clients ip address */
|
||||
s = ioctl(0, NWIOGTCPCONF, &tcpconf);
|
||||
if(s < 0) {
|
||||
printf("421 FTP service unable to get remote ip address. Closing.\r\n");
|
||||
fflush(stdout);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
myipaddr = tcpconf.nwtc_locaddr;
|
||||
myport = tcpconf.nwtc_locport;
|
||||
rmtipaddr = tcpconf.nwtc_remaddr;
|
||||
rmtport = tcpconf.nwtc_remport;
|
||||
|
||||
/* Look up the host name of the remote host. */
|
||||
hostent = gethostbyaddr((char *) &rmtipaddr, sizeof(rmtipaddr), AF_INET);
|
||||
if(!hostent)
|
||||
strcpy(rmthostname, inet_ntoa(rmtipaddr));
|
||||
else {
|
||||
strncpy(rmthostname, hostent->h_name, sizeof(rmthostname)-1);
|
||||
rmthostname[sizeof(rmthostname)-1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static void timeout(sig)
|
||||
int sig;
|
||||
{
|
||||
gottimeout = 1;
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
/* net.h Copyright 1992-2000 by Michael Temari All Rights Reserved
|
||||
*
|
||||
* This file is part of ftpd.
|
||||
*
|
||||
*
|
||||
* 01/25/96 Initial Release Michael Temari, <Michael@TemWare.Com>
|
||||
*/
|
||||
|
||||
_PROTOTYPE(int doPASV, (char *buff));
|
||||
_PROTOTYPE(int doPORT, (char *buff));
|
||||
_PROTOTYPE(int DataConnect, (void));
|
||||
_PROTOTYPE(int CleanUpPasv, (void));
|
||||
_PROTOTYPE(void GetNetInfo, (void));
|
|
@ -1,75 +0,0 @@
|
|||
#!/bin/sh
|
||||
# setup.anonftp - Anonymous FTP setup and maintenance.
|
||||
#
|
||||
# 01/22/96 Initial Release Al Woodhul, <asw@hampshire.edu>
|
||||
# 01/25/96 Michael Temari, <temari@ix.netcom.com>
|
||||
#
|
||||
|
||||
# What is needed for anon ftp
|
||||
|
||||
# ref: Hunt TCP/IP Net Admin pp. 338++
|
||||
# ref: Nemeth et al UNIX System Admin Handbook p. 295
|
||||
# ref: mail from M. Temari 18.01.96
|
||||
|
||||
# programs possibly used by ftpd
|
||||
PROGS="sh ls crc tar compress gzip"
|
||||
|
||||
echo Checking /etc/passwd
|
||||
if grep '^ftp:[^:]*:[1-9][0-9]*:[1-9][0-9]*:[^:]*:/[^:]*:[^:]*$' \
|
||||
/etc/passwd >/dev/null
|
||||
then
|
||||
echo -n "OK, ftp entry found: "
|
||||
grep '^ftp:' /etc/passwd
|
||||
else
|
||||
echo "Found no entry for ftp in /etc/passwd, please add one with the"
|
||||
echo "home directory pointing to the anonymous FTP directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ftp directory
|
||||
FTPDIR="`sed '/^ftp:/!d; s/^.*:\\([^:]*\\):[^:]*/\\1/' /etc/passwd`"
|
||||
|
||||
if [ `whoami` != root ]
|
||||
then
|
||||
echo You must be root to do this
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Setting up for anonymous ftp
|
||||
|
||||
echo Making $FTPDIR and subdirectories
|
||||
install -d -m 755 -o root -g operator $FTPDIR
|
||||
install -d -m 751 -o root -g operator $FTPDIR/bin
|
||||
install -d -m 751 -o root -g operator $FTPDIR/dev
|
||||
install -d -m 751 -o root -g operator $FTPDIR/etc
|
||||
install -d -m 755 -o root -g operator $FTPDIR/pub
|
||||
incoming=
|
||||
if [ -d $FTPDIR/pub/incoming ]
|
||||
then
|
||||
incoming=t
|
||||
elif [ -t 0 ]
|
||||
then
|
||||
echo -n "Create \"incoming\" directory? [n] "; read yn
|
||||
case "$yn" in
|
||||
[yY]*|ok|sure) incoming=t
|
||||
esac
|
||||
fi
|
||||
test "$incoming" && install -d -m 777 -o root -g operator $FTPDIR/pub/incoming
|
||||
|
||||
echo Copying files
|
||||
for PROG in $PROGS
|
||||
do
|
||||
test -f /usr/bin/$PROG && install -lcs /usr/bin/$PROG $FTPDIR/bin
|
||||
done
|
||||
cp -rp /dev/tcp $FTPDIR/dev/tcp
|
||||
install -lcs ftpdsh $FTPDIR/bin
|
||||
|
||||
echo Copying a minimum of the password and group files
|
||||
sed 's/^\([^:]*\):[^:]*:\([^:]*:[^:]*\):.*$/\1:*:\2:::/' \
|
||||
/etc/passwd >$FTPDIR/etc/passwd
|
||||
sed 's/^\([^:]*\):[^:]*:\([^:]*\):.*$/\1:*:\2:/' \
|
||||
/etc/group >$FTPDIR/etc/group
|
||||
chown root:operator $FTPDIR/etc/*
|
||||
chmod 444 $FTPDIR/etc/*
|
||||
|
||||
echo "Anonymous ftp setup complete"
|
Loading…
Reference in a new issue