Nuke this thing.

This commit is contained in:
jkh 1996-06-19 21:13:05 +00:00
parent a5ea59117c
commit 6268e2ef47
28 changed files with 0 additions and 12428 deletions

View File

@ -1,66 +0,0 @@
Subject: NcFTP 1.6.0 - Alternative User Interface for FTP
Archive-name: ncftp/part01
Environment: UNIX, ANSI-C, !SVR4
Supersedes: ncftp: Volume 39, Issue 53-57
NcFTP - Alternative user interface for FTP
Version 1.6.0 by Mike Gleason, NCEMRSoft.
I used to list the features of ncftp in this blurb, but there are just
too many to list. Even if you only ftp occasionally, it is worth your
time to install ncftp (or atleast bug your sysadmin to). If you won't take
my word for it, just ask around, or extract this archive and read the
man page.
1.6.0 is an "evolutionary" upgrade, which consolidates all the previous
patches and adds a little. 1.6 and 1.5 are "interim" versions between
2.0 which has been suspended indefinitely due to time constraints.
Major changes since 1.5.6:
* Built-in support for the "term" package, used by Linux, etc.
* SCO Xenix, Besta, AIX 2, AIX 3, Dynix/PTX support
* Better ISC Unix support.
* Several bug fixes.
Major changes since 1.0.2:
* Supports the Getline (input-edit) and GNU Readline command-line
editing and history libraries.
* Supports the Socks firewall library, and another firewall gateway
implementation.
* Terrific new "recent-sites" file that automatically saves the
sites you call; when you open a site in the recent-sites file
(of course you can abbreviate the names), you start in the
same directory you were in last time.
* Improved on-line help, and tips on how to use the program better
are printed each time you run the program.
* Rewritten man page.
* Faster ascii transfers.
* Typing 'open' by itself lists all the sites the program knows
about (the ones in your .netrc and the recent-sites list) so
you can just pick one.
* Enhanced colon-mode, that can dump a file to stdout (ftpcat mode)
or to a pager. (i.e. ncftp -c wu:/README >/dev/null).
* You can choose whether an open is anonymous by default (like it
had always been) or a user login by default by setting a new
program variable.
* Bugs fixed.
Read the enclosed file, v2_Notes, which explains why I won't be
able to work on the nearly finished, and much improved v2.0.

View File

@ -1,18 +0,0 @@
PROG= ncftp
SRCS= cmds.c cmdtab.c ftp.c ftprc.c getpass.c glob.c main.c open.c set.c \
tips.c util.c
DPADD= $(LIBREADLINE) $(LIBTERMCAP)
LDADD= -lreadline -ltermcap
CFLAGS+= -DGZCAT=\"/usr/bin/gzcat\" -DREADLINE -DCURSES -DNO_CURSES_H \
-DSYSLOG -DTRY_ABOR -DGATEWAY \
-DFTP_DATA_BOTTOM=40000 -DFTP_DATA_TOP=44999
MK= $(CC) $(CFLAGS) $(LDADD)
cmds.o:
$(CC) $(CFLAGS) -DMK='"$(MK)"' -c ${.CURDIR}/cmds.c
.include <bsd.prog.mk>

View File

@ -1,296 +0,0 @@
Note: This version is no longer being enhanced. As of this writing, version
2.x is the officially supported version. Only bug fixes and portability
tweaks will be applied to the 1.9 series.
If you are a novice user, and don't know how to compile things, try
contacting your local guru first (get them to do it for you :-). Please
understand that I don't have time to walk newbies through the whole
installation procedure.
1. READ this entire file. Part A, below, tells what to do if you want to
use NcFTP with a command-line editor. Part B tells you how to configure
the Makefile to compile the program for your system. Part C tells you
how to configure NcFTP's optional features. Part D tells you how to
contact me if you want to report a bug or submit new code to the
program.
2. EDIT the Makefile, making any necessary changes described in parts
A, B, or C. Don't forget to read the directions in the Makefile,
so you don't forget any needed libraries, etcetera.
3. You can also change the program's default behavior by editing defaults.h.
99% of the time you don't need to do this, so you can skip this step.
If you have problems, you can mail me, but please try your best to install
it without my help. I'm quite tired of responding to lazy SunOS users
because they didn't bother reading the directions so that they would have
known that they needed to use GCC.
I _do_ want to hear from you if you have comments or bug reports/fixes. I
would also like to hear from you if you had a system that wasn't covered
in sys.h, so I can add an entry for other users of your system.
The latest version of ncftp is available in the directory:
ftp.cs.unl.edu:/pub/ncftp
Part A. Installing with a command line editor:
----------------------------------------------
As of this release, GNU Readline and Chris Thewalt's Getline command-line
editing and history facilities are supported. Neither are included with the
ncftp sources. You can find Getline at:
ce.berkeley.edu:/pub/thewalt/getline.tar.Z (note: use 'ls', not 'dir!')
and Readline is in the directory:
prep.ai.mit.edu:/pub/gnu
To install Readline, you will need to know where libreadline.a and the
header <readline/readline.h> are. You will need to link libreadline.a and
libcurses.a (or libtermcap.a) with ncftp (see the Makefile). Good luck on
trying to compile it. It is not an easy thing to do! In the Makefile, you
will need to add -DREADLINE to PDEFS, add -lreadline -lcurses to LIBS, and
edit the HDRDIRS and LIBDIRS lines. This stuff is already in the Makefile,
so you can just uncomment it.
To install Getline, you need to know where libgetline.a and it's header
(getline.h) are. In the Makefile, you'll need to add -lgetline to LIBS and
edit the HDRDIRS and LIBDIRS lines. This stuff is already in the Makefile,
so you can just uncomment it.
DO NOT bug me if you can't figure out how to compile Getline or Readline.
Contact their respective authors instead. It is not essential that you use
them.
Part B. System Dependencies:
----------------------------
NcFTP may need work-arounds for some things due to the differences
in implementations of unix. The following systems are taken care
of automatically. For these systems, you should just be able to type
'make' (but proceed to part C):
Silicon Graphics IRIX
IBM's AIX
SINIX
DEC's Ultrix (well, might need to use -lcursesX instead of -lcurses)
NeXT
Pyramid OSx
Berkley Software Design, Inc.'s BSDi
Otherwise you will have to configure ncftp manually.
Important for "Yellow Pages" users: Don't forget to link the library
that includes the YP/NIS version of getpwuid(), etc. Otherwise the program
won't be able to expand ~username/path/name type pathnames, and maybe even
~/path/name types of pathnames. If you're wondering why the program isn't
opening your rc file, this could be the cause.
You will need to add these things to the SDEFS line in the Makefile
as applicable. As an example, if I say 'add -DFoobar to SDEFS,' find
the line in the Makefile that reads 'SDEFS=' (or 'SDEFS=-DFoo2') and
change it to 'SDEFS=-DFoobar' (or 'SDEFS=-DFoo2 -DFoobar). If your
system is listed below, follow the directions and then you ready to
go to part C, below.
Sun Microsystems' SunOS/Solaris: Use an ANSI compiler such as
gcc (set CC=gcc in the Makefile), or acc (set CC=acc).
The regular 'cc' is not an ANSI compiler. You could also run
something like 'ansi2knr' on the sources and hope it works.
You will probably need to link both the curses and termcap
libraries if you use -DCURSES (see below). If you're running
Solaris (SunOS 5.x or greater) add -DSolaris to SDEFS.
I also needed to add -lnsl -lsocket to LIBS.
Hewlett-Packard HP-UX: If you have 7.0, you'll need to find
a copy of <ftp.h> from somewhere (8.0 has it though). Then
set CFLAGS= -Aa. You may also need to use gcc if your
compiler is non-ANSI. Note that for HP-UX, the default
terminal escape codes are for HP terminals, so you should
probably link termcap/curses in so it will get the ANSI
sequences if you're on a vt100, etc., terminal connected
to your HP-UX machine.
Linux: For 'term' support, from what I can tell just add
the path of 'client.a' to LIBS, and add -DTERM_FTP to SDEFS,
to turn on the term specific ftp code. May need to link
-lcurses and -ltermcap.
SCO Unix: Add -DSCO324 or -DSCO322 (as appropriate) to SDEFS,
and -lsocket to LIBS.
SCO Xenix 2.3.4: Add -DSCOXNX to SDEFS;
Try adding -DLINGER if puts don't work.
Add "-lsocket -ldir" to LIBS.
Bull DPX/2: Add -DBULL to SDEFS, add -linet to LIBS, and
use gcc.
Sequent's DYNIX: Use gcc and add -DDYNIX (if necessary) to SDEFS.
You may also be short several string functions which you will
have to get elsewhere, and perhaps mktime and strftime.
You can get all that stuff from the BSD sources (like ftp.uu.net).
Please bug Sequent to update their libc library!
Sequent's Dynix/PTX: Add -DDYNIXPTX to SDEFS.
Add -lsocket -linet -lnsl -lseq to LIBS.
DEC OSF1/1.3: Use gcc, Add -DGETCWDSIZET to SDEFS. cc might work,
though. Try cc if gcc chokes.
If your system doesn't fit any of those, things will be trickier. Answer
all these questions and add to the SDEFS line. You may want to try
each option one at a time until everything works.
* Is your system closer to System V or BSD? Your SDEFS line should have
either -DBSD or -DSYSV. If you don't know, try leaving it blank first;
some compilers automatically define it for you.
* Add -DNO_CONST if your compiler chokes on the const directive. You
will know if you need to add this if the compiler spits out errors saying
it doesn't know what 'const' is.
* As I said above, you will need to link special libraries if your system
is running Yellow Pages.
* Add -DSYSSELECTH if you need <sys/select.h> included for definitions
of fd_set, etc.
* Add -DNO_UNISTDH if you don't have <unistd.h>. If the compiler complains
about not being able to open <unistd.h> add this.
* Add -DNO_STDLIBH if you don't have <stdlib.h>. If the compiler complains
about not being able to open <stdlib.h> add this.
* Add -DNO_UTIMEH if you don't have <utime.h>. If the compiler complains
about not being able to open <utime.h> add this.
* Add -DNO_MKTIME if you don't have the mktime() system call, and don't
feel like getting the source for it and compiling it in with the program.
If you define this, the program will not set the file modification times
to match the ones on the remote host (no big deal).
* Add -DGETPASS if you would rather use the standard getpass() system
call, instead of our version, Getpass(), which takes more than 8
characters. You may want to define this if you are having problems
compiling getpass.c.
If you haven't given up on our Getpass(), you can try adding -DSGTTYB
if you want to use a struct sgttyb instead of a struct termio. By default,
BSD systems define SGTTYB automatically. You can also try adding -DTERMIOS
to use a POSIX compliant struct termios instead. Don't pull your hair out
trying to get the Getpass code to compile; if it gives you problems just
define -DGETPASS and hope your system's getpass can handle passwords
longer than 8 characters.
* Add -DBAD_INETADDR if your inet_addr() function returns a struct in_addr
instead of a u_long, as it should (in DG/UX 5.4.1).
* Add -DBROKEN_MEMCPY if ncftp mysteriously dumps core when trying to open
a remote host. I'm told that this happens because of some problem in System
V's sockets don't like fprintf (and memcpy).
* Add -DPTRTYPE=char if your pre-ANSI compiler complains about the
way malloc() or free() are used, and in general does not like (void *)
as a generic pointer type.
* Add -DNO_STRFTIME if your system does not have strftime(). If you do,
we won't try to use it. This means, however, you cannot use ``%'' values
in your prompt.
* Add -DNO_RENAME if your system does not have rename() (or the one it
has is broken). If you do, we will use our own.
* Add -DNO_STRSTR if your system does not have strstr(). If you do, we
will use our own.
* Add -DLINGER if puts to the remote system are incomplete.
* Add -DNET_ERRNO_H if you need to include <net/errno.h> for definitions
of ECONNREFUSED, etcetera.
* (Optional) Add -DGETCWDSIZET if your system's getcwd() takes a size_t
as the second parameter instead of an int.
* (Optional) Add -DHERROR if you know you have the herror() system
call.
* (Optional) Add -DU_WAIT if you know your wait system call takes
a pointer to a 'union wait.' Defined automatically if you define
BSD.
* (Optional) Add -DHOSTNAME=\"machine.domain.nam\" if your system
doesn't generate it's own hostname. To check this, compile ncftp
then run it and type 'set.' Look at the variable anon-password.
If the hostname is wrong, or if it is in the form of 'yourlogin' or
'yourlogin@machine' instead of 'yourlogin@machine.xxx.yyy,'
re-compile it with HOSTNAME set to your machine's address, in the
form of 'machine.xxx.yyy.'
* (Optional) Add -DHAS_DOMAINNAME if you have the getdomainname()
function.
* (Optional) If you're having problems with your hostname not being
full (i.e you have 'yourlogin@machine') all is not lost. First of all,
define HAS_DOMAINNAME if you can. But sometimes getdomainname() doesn't
work -- instead of giving you the domain name, it returns an empty
string. So you can hardcode the domain name by defining DOMAIN_NAME to
be the domain (i.e. add -DDOMAIN_NAME=\"domain.nam\"). That way, if
getdomainname doesn't work, the program will have something to fall back
on. This problem is common on SunOS/Solaris.
* (Optional) Add -DSTRICT_PROTOS if your compiler wants function prototypes
for all functions, not just non-int-returning ones. This is really just
handy for debugging during development, so this is not recommended.
Part C. Program Options:
------------------------
Add these as applicable to the PDEFS line in the Makefile.
* -DGZCAT=\"path\": If you have the GNU gzip package installed on your system,
the program can try paging remote files compressed with gzip _and_
compress (instead of just compress). Add -DGZCAT=\"/full/path/to/zcat\"
with GZCAT set to the path name of GNU's zcat/gzcat.
* -DCURSES: Uses curses library to display boldface, underline, etc.
By default ncftp uses hard-coded ANSI escapes (^[[1m etc.) to
save the 100k or so the curses library adds. You will also need
to edit the LIBS line in the Makefile to add -lcurses. You may
need to add -ltermcap instead, or both -lcurses and -ltermcap.
If you choose to use the termcap library, you may want to also add
-DNO_CURSES_H so it does not try to include <curses.h>.
* -DSYSLOG: Define this to have ncftp log connections and transfers
to the syslog.
* -DNO_TIPS: Define if you want to cut a little fat at the expense of
novice users.
* -DGETLINE: If you want to use Chris Thewalt's getline input line editor
and history facility, add this (and see below).
* -DREADLINE: If you want to use GNU's readline input line editor and
history facility, add this (and see the Makefile). If you do this, you
also need to add -DCURSES (see above).
* -DSOCKS: NcFTP is now compatible with the Socks library by David Koblas,
at koblas@sgi.com. This lets you use NcFTP with a "firewall" gateway
for enhanced site security. You can get the latest version from...
ftp://ftp.netcom.com/pub/ko/koblas/
After you have compiled it, compile NcFTP
with -DSOCKS added to PDEFS, and the pathname of the Rconnect.o file
added to LIBS.
* -DTRY_ABOR: Define if you want to try the 'ABOR' command from ncftp;
The aborting code has had some problems, so by default the program
'aborts' by continuing to read input but not echoing output.
* -DDB_ERRS: Define this if you want my Perror() function to be more
verbose. You may want to do this if you are a programmer examining this
code, and want to know where in the source the Perror's are coming
from.
--mg (mgleason@cse.unl.edu)

File diff suppressed because it is too large Load Diff

View File

@ -1,133 +0,0 @@
/* cmds.h */
#ifndef _cmd_h_
#define _cmd_h_
/* $RCSfile: cmds.h,v $
* $Revision: 14020.11 $
* $Date: 93/07/09 10:58:19 $
*/
/* Verbosity levels. */
#define V_QUIET -1
#define V_ERRS 0
#define V_TERSE 1
#define V_VERBOSE 2
#define V_IMPLICITCD 4
#define IS_VQUIET (verbose <= V_QUIET)
#define IS_VERRS (verbose == V_ERRS)
#define IS_VTERSE (verbose == V_TERSE)
#define IS_VVERBOSE (verbose == V_VERBOSE)
#define NOT_VQUIET (verbose > V_QUIET)
/* Open modes. */
#define OPEN_A 1
#define OPEN_U 0
#define LS_FLAGS_AND_FILE '\1'
/* Possible values returned by GetDateAndTime. */
#define SIZE_UNKNOWN (-1L)
#define MDTM_UNKNOWN (0L)
/* Command result codes. */
#define USAGE (88)
#define NOERR (0)
#define CMDERR (-1)
/*
* Format of command table.
*/
struct cmd {
char *c_name; /* name of command */
char c_conn; /* must be connected to use command */
char c_hidden; /* a hidden command or alias (won't show up in help) */
int (*c_handler)(int, char **); /* function to call */
char *c_help; /* help string */
char *c_usage; /* usage string or NULL, to ask the function itself. */
};
#define NCMDS ((int) ((sizeof (cmdtab) / sizeof (struct cmd)) - 1))
struct macel {
char mac_name[9]; /* macro name */
char *mac_start; /* start of macro in macbuf */
char *mac_end; /* end of macro in macbuf */
};
struct types {
char *t_name;
char *t_mode;
int t_type;
char *t_arg;
};
struct lslist {
char *string;
struct lslist *next;
};
int settype(int argc, char **argv);
int _settype(char *typename);
int setbinary(int argc, char **argv);
int setascii(int argc, char **argv);
int put(int argc, char **argv);
int mput(int argc, char **argv);
int rem_glob_one(char *pattern);
int get(int argc, char **argv);
void mabort SIG_PARAMS;
int mget(int argc, char **argv);
char *remglob(char *argv[], int *);
int setverbose(int argc, char **argv);
int setprompt(int argc, char **argv);
int setdebug(int argc, char **argv);
void fix_options(void);
int cd(int argc, char **argv);
int implicit_cd(char *dir);
int _cd(char *dir);
int lcd(int argc, char **argv);
int do_delete(int argc, char **argv);
int mdelete(int argc, char **argv);
int renamefile(int argc, char **argv);
int ls(int argc, char **argv);
int shell(int argc, char **argv);
int do_user(int argc, char **argv);
int pwd(int argc, char **argv);
int makedir(int argc, char **argv);
int removedir(int argc, char **argv);
int quote(int argc, char **argv);
int rmthelp(int argc, char **argv);
int quit(int argc, char **argv);
void close_streams(int wantShutDown);
int disconnect(int argc, char **argv);
int close_up_shop(void);
int globulize(char **cpp);
int cdup(int argc, char **argv);
int syst(int argc, char **argv);
int make_macro(char *name, FILE *fp);
int macdef(int argc, char **argv);
int domacro(int argc, char **argv);
int sizecmd(int argc, char **argv);
int modtime(int argc, char **argv);
int lookup(int argc, char **argv);
int rmtstatus(int argc, char **argv);
int create(int argc, char **argv);
int getlocalhostname(char *host, size_t size);
int show_version(int argc, char **argv);
void PurgeLineBuffer(void);
int ShowLineBuffer(int argc, char **argv);
int MallocStatusCmd(int argc, char **argv);
int unimpl(int argc, char **argv);
long GetDateSizeFromLSLine(char *fName, unsigned long *mod_time);
long GetDateAndSize(char *fName, unsigned long *mod_time);
int SetTypeByNumber(int i);
int setpassive(int argc, char **argv);
int setrestrict(int argc, char **argv);
/* In util.c: */
void cmd_help(struct cmd *c);
void cmd_usage(struct cmd *c);
struct cmd *getcmd(char *name);
#endif /* _cmd_h_ */

View File

@ -1,280 +0,0 @@
/* cmdtab.c */
/* $RCSfile: cmdtab.c,v $
* $Revision: 14020.11 $
* $Date: 93/07/09 11:04:56 $
*/
#include "sys.h"
#include "util.h"
#include "cmds.h"
#include "main.h"
#include "ftp.h"
#include "ftprc.h"
#include "glob.h"
#include "open.h"
#include "set.h"
#include "copyright.h"
#define REMOTEFILE " remote-file-name"
#define REMOTEFILES " remote-file-names and/or UNIX-style-wildcards"
#define LOCALFILE " local-file-name"
#define LOCALFILES " local-file-names and/or UNIX-style-wildcards"
#define LDIRNAME " local-directory-name"
#define RMTDIRNAME " remote-directory-name"
#define EMPTYSTR ""
#define TOGGLE " [on | off] (no argument toggles the switch)"
#define BINARYHELP "transfer files as binary files, without CR/LF translation"
#define BINARYUSAGE EMPTYSTR
#define CHDIRHELP "changes the current remote working directory"
#define CHDIRUSAGE RMTDIRNAME
#define CLOSEHELP "closes FTP connection to current remote host"
#define CLOSEUSAGE EMPTYSTR
#define DELETEHELP "deletes the specified file on the remote host"
#define DELETEUSAGE REMOTEFILE
#define DIRUSAGE " \
[flags] [remote-items] [>outfile or \"|pipecmd [cmd-args]\"]\n\
Note that there must be no whitespace between > and outfile, or | and\n\
pipecmd, and if the pipe-command needs arguments, you must enclose the\n\
whole thing with double quotes.\n\
Examples:\n\
dir -s\n\
dir remoteFile\n\
dir /pub/mac \"|head -20\"\n\
dir -rtR file1 file2 dir1 >contents.txt"
#define GETUSAGE " remote-file-name [local-file-name or |pipecommand]\n\
Examples:\n\
get myfile.txt\n\
get MYFILE.ZIP myfile.zip\n\
get myfile.txt |head\n\
get myfile.txt \"|head -20\"\n\
get ./help/newuser.txt (./newuser.txt will be local-file-name)\n\
get ./help/newuser.txt ./docs/newbie.help\n\
get my*.txt (pseudo-filename-completion if match is unique, i.e. myfile.txt)"
#define HELPHELP "shows commands, and optionally tell you how to use a specific one"
#define HELPUSAGE " [command-name | showall (shows hidden commands) | helpall"
#define LSHELP "prints remote directory contents (short-mode)"
#define LSUSAGE " \
[flags] [remote-items] [>outfile or \"|pipecmd [cmd-args]\"]\n\
Note that there must be no whitespace between > and outfile, or | and\n\
pipecmd, and if the pipe-command needs arguments, you must enclose the\n\
whole thing with double quotes.\n\
Examples:\n\
ls -s\n\
ls remoteFile\n\
ls /pub/mac \"|head -20\"\n\
ls -lrtR file1 file2 dir1 >contents.txt"
#define OPENHELP "connects to a new remote host, and optionally fetches a file\n\
or sets the current remote working directory"
#define OPENUSAGE " \
[-a | -u] [-i] [-p N] [-r [-d N] [-g N]] hostname[:pathname]\n\
-a : Open anonymously (this is the default).\n\
-u : Open, specify user/password.\n\
-i : Ignore machine entry in your .netrc.\n\
-p N : Use port #N for connection.\n\
-r : \"Redial\" until connected.\n\
-d N : Redial, pausing N seconds between tries.\n\
-g N : Redial, giving up after N tries.\n\
:path : Open site, then retrieve file \"path.\" WWW-style paths are\n\
also acceptable, i.e. 'ftp://cse.unl.edu/mgleason/README.'"
#define PAGEHELP "view a file on the remote host with your $PAGER"
#define PAGEUSAGE REMOTEFILE
#define PASSIVEHELP "enter passive transfer mode"
#define PDIRUSAGE " [flags] [remote-files]"
#define PUTHELP "sends a local file to the current remote host"
#define PUTUSAGE " local-file-name [remote-file-name]"
#define QUITHELP "quits the program"
#define QUITUSAGE EMPTYSTR
#define RESTRICTHELP "toggle restriction of data port range"
#define RHELPHELP "asks the remote-server for help"
#define RHELPUSAGE " [help-topic (i.e. FTP command)]"
#define UNIMPLHELP "this command is not supported"
#define UNIMPLUSAGE (NULL)
struct cmd cmdtab[] = {
/* name ; must-be-connected ; hidden ; help-string ; usage-string */
{ "!", 0, 0, shell,
"spawns a shell for you to run other commands",
" [single-command-and-arguments]" },
{ "$", 0, 0, domacro,
"runs a macro previously defined in your NETRC, or with the macdef cmd",
"macro-number" },
{ "account", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "append", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "ascii", 1, 1, setascii,
"transfer files as text files, with proper CR/LF translation",
"" },
{ "bell", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "binary", 1, 1, setbinary, BINARYHELP, BINARYUSAGE },
{ "bye", 0, 1, quit, QUITHELP, QUITUSAGE },
{ "case", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "cd", 1, 0, cd, CHDIRHELP, CHDIRUSAGE },
{ "cdup", 1, 0, cdup,
"changes the current remote working directory to it's parent",
"" },
{ "chdir", 1, 1, cd, CHDIRHELP, CHDIRUSAGE },
{ "close", 1, 1, disconnect, CLOSEHELP, CLOSEUSAGE },
{ "connect", 0, 1, cmdOpen, OPENHELP, OPENUSAGE },
{ "cr", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "create", 1, 0, create,
"create an empty file on the remote host",
REMOTEFILE },
{ "delete", 1, 0, do_delete, DELETEHELP, DELETEUSAGE },
{ "debug", 0, 1, setdebug,
"to print debugging messages during execution of the program",
TOGGLE },
{ "dir", 1, 0, ls,
"prints remote directory contents (long-mode)",
DIRUSAGE },
{ "erase", 1, 1, do_delete, DELETEHELP, DELETEUSAGE },
{ "exit", 0, 1, quit, QUITHELP, QUITUSAGE },
{ "form", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "get", 1, 0, get,
"fetches a file from the current remote host", GETUSAGE },
{ "glob", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "hash", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "help", 0, 0, help, HELPHELP, HELPUSAGE },
{ "idle", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "image", 1, 1, setbinary, BINARYHELP, BINARYUSAGE },
{ "lcd", 0, 0, lcd,
"changes the current local directory", LDIRNAME },
{ "lookup", 0, 0, lookup,
"uses the name-server to tell you a host's IP number given it's\n\
name, or it's name given it's IP number",
" hostname | host-IP-number" },
{ "ls", 1, 0, ls, LSHELP, LSUSAGE },
{ "macdef", 0, 0, macdef,
"defines a macro which is expanded when you use the $ command",
" new-macro-name" },
{ "mdelete", 1, 0, mdelete,
"deletes multiple files on the remote host", REMOTEFILES },
{ "mdir", 1, 1, ls, LSHELP, LSUSAGE },
#if LIBMALLOC != LIBC_MALLOC
{ "memchk", 0, 0, MallocStatusCmd,
"show debugging information about memory usage.", EMPTYSTR },
#endif
{ "mget", 1, 0, mget,
"fetches multiple files from the remote host", REMOTEFILES },
{ "mkdir", 1, 0, makedir,
"creates a new sub-directory on the current remote host",
RMTDIRNAME },
{ "mls", 1, 0, ls, LSHELP, LSUSAGE },
{ "mode", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "modtime", 1, 0, modtime,
"shows the last modification date for a remote file",
REMOTEFILE },
{ "more", 1, 1, get, PAGEHELP, PAGEUSAGE },
{ "mput", 1, 0, mput,
"sends multiple local files to the current remote host",
LOCALFILES },
{ "newer", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "nlist", 1, 1, ls, LSHELP, LSUSAGE },
{ "nmap", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "ntrans", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "open", 0, 0, cmdOpen, OPENHELP, OPENUSAGE },
{ "p", 1, 1, get, PAGEHELP, PAGEUSAGE },
{ "passive", 0, 0, setpassive, PASSIVEHELP, EMPTYSTR },
{ "page", 1, 0, get, PAGEHELP, PAGEUSAGE },
{ "pdir", 1, 0, ls,
"view a remote directory listing (long mode) with your $PAGER",
PDIRUSAGE },
{ "pls", 1, 0, ls,
"view a remote directory listing (short mode) with your $PAGER",
PDIRUSAGE },
{ "predir", 1, 0, ShowLineBuffer,
"view the last remote directory listing with your $PAGER",
EMPTYSTR },
{ "prompt", 0, 1, setprompt,
"toggle interactive prompting on multiple commands",
TOGGLE },
{ "proxy", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "put", 1, 0, put, PUTHELP, PUTUSAGE },
{ "pwd", 1, 0, pwd,
"prints the name of the current remote directory",
EMPTYSTR },
{ "quit", 0, 0, quit, QUITHELP, QUITUSAGE },
{ "quote", 1, 0, quote,
"allows advanced users to directly enter FTP commands verbatim",
" FTP-commands" },
{ "redir", 1, 0, ShowLineBuffer,
"re-prints the last directory listing",
EMPTYSTR },
{ "reget", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "remotehelp", 1, 0, rmthelp, RHELPHELP, RHELPUSAGE },
{ "reset", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "restart", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "restrict", 0, 0, setrestrict, RESTRICTHELP, EMPTYSTR },
{ "rm", 1, 1, do_delete, DELETEHELP, DELETEUSAGE },
{ "rstatus", 1, 0, rmtstatus,
"asks the remote-server for it's status",
EMPTYSTR },
{ "rhelp", 1, 1, rmthelp, RHELPHELP, RHELPUSAGE },
{ "rename", 1, 0, renamefile,
"changes the name of a file on the current remote host",
" old-name new-name" },
{ "rmdir", 1, 0, removedir,
"deletes a directory on the current remote host",
RMTDIRNAME },
{ "runique", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "send", 1, 1, put, PUTHELP, PUTUSAGE },
{ "sendport", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "show", 0, 0, do_show,
"prints the value of some or all program variables",
" all | variable-names" },
{ "set", 0, 0, set,
"changes the value of a program variable; for numeric/boolean\n\
variables sets them to 1/true",
" variable-name [= new-value]" },
{ "site", 1, 0, quote,
"allows advanced users to send site-specific commands to the host",
" site-specific-commands\n\
Example (to try on wuarchive.wustl.edu):\n\
site locate emacs" },
{ "size", 1, 0, sizecmd,
"shows the size of a remote file",
REMOTEFILE },
{ "struct", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "sunique", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "system", 1, 0, syst,
"tells you what type of machine the current remote host is",
EMPTYSTR },
{ "tenex", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "umask", 0, 1, unimpl, UNIMPLHELP, UNIMPLUSAGE },
{ "unset", 0, 0, set,
"resets the value of a program variable to it's default state, or for\n\
numeric/boolean variables, sets them to 0/false",
" variable-name" },
{ "user", 1, 0, do_user,
"lets you login as a new user (with appropriate password)",
" new-user-name [new-password]" },
{ "type", 1, 0, settype,
"changes the current file transfer method",
" ascii | binary | ebcdic | tenex" },
{ "verbose", 0, 0, setverbose,
"controls how many message the program prints in response to commands",
" -1 (quiet) | 0 (errs) | 1 (terse) | 2 (verbose)" },
{ "version", 0, 0, show_version,
"prints information about the program",
EMPTYSTR },
{ "?", 0, 1, help, HELPHELP, HELPUSAGE },
{ NULL, 0, 0, NULL, NULL, NULL }
};
/* eof cmdtab.c */

View File

@ -1,25 +0,0 @@
/* Copyright.h */
/*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Copyright (c) 1992-1995 Mike Gleason, NCEMRSoft.
* Copyright (c) 1985, 1989 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that: (1) source distributions retain this entire copyright notice and
* comment, and (2) distributions may not be sold for profit on physical
* media such as disks, tapes, and CD-ROMS, without expressed written
* permission.
*/
#ifdef _main_c_
#ifndef lint
static char copyright[] = "@(#) Copyright (c) 1992, 1993, 1994, 1995 by NCEMRSoft and Copyright (c) 1985, 1989 Regents of the University of California.\n All rights reserved.\n";
#endif /* not lint */
#endif /* _main_c_ */
/* eof copyright.h */

View File

@ -1,142 +0,0 @@
/* Defaults.h: default values for ftp's common variables */
/* These are all surrounded by #ifndef blocks so you can just use
* the -D flag with your compiler (i.e. -DZCAT=\"/usr/local/bin/zcat\").
*/
#ifndef _DEFAULTS_H_
#define _DEFAULTS_H_
/* $RCSfile: defaults.h,v $
* $Revision: 14020.13 $
* $Date: 93/07/09 10:58:27 $
*/
#ifndef NEWMAILMESSAGE /* For english speakers, "You have new mail." */
#define NEWMAILMESSAGE "You have new mail."
#endif
#ifndef ZCAT /* Usually "zcat," but use the full pathname */
/* if possible. */
# ifdef GZCAT /* If you said you had gnu's zcat, use it
* since it can do .Z files too.
*/
# define ZCAT GZCAT
# else /* !GZCAT */
# define ZCAT "zcat"
# endif /* ifdef GZCAT */
#endif /* ifndef ZCAT */
#ifndef MAX_XFER_BUFSIZE
#define MAX_XFER_BUFSIZE 32768
#endif
#ifndef dANONOPEN /* 1 or 0, usually 1 */
#define dANONOPEN 1
#endif
#ifndef dDEBUG /* 1 or 0, usually 0 */
#define dDEBUG 0
#endif
#ifndef dMPROMPT /* Usually 1, I prefer 0... */
#define dMPROMPT 0
#endif
/* If passive FTP can be used, this specifies whether it is turned on
* by default. If not, we have passive mode available, but are using
* Port ftp by default.
*/
#ifndef dPASSIVE
#define dPASSIVE 0 /* Use PORT for more portability... */
#endif
#ifndef dRESTRICT
#define dRESTRICT 1 /* should be safe to be 1 */
#endif
#ifndef dVERBOSE /* V_QUIET, V_ERRS, V_TERSE, V_VERBOSE */
#define dVERBOSE V_TERSE
#endif
#ifndef dPROMPT /* short: "@Bftp@P>" */
/* long: "@B@E @UNcFTP@P @B@M@D@P ->" */
#define dPROMPT "@B@c@Mncftp@P>" /* new two line prompt */
#endif
#ifndef dPAGER /* if set to empty string, act like 'cat' */
#define dPAGER "more"
#endif
#ifndef dLOGNAME /* usu. put in the user's home directory. */
#define dLOGNAME "~/.ftplog"
#endif
#ifndef dRECENTF /* usu. put in the user's home directory. */
#define dRECENTF "~/.ncrecent"
#endif
#ifndef dMAXRECENTS /* limit to how many recent sites to save. */
#define dMAXRECENTS 50
#endif
#ifndef dRECENT_ON /* Do you want the recent log on? */
/* usually 1. */
#define dRECENT_ON 1
#endif
/* Do you want logging on by default? */
#ifndef dLOGGING /* usually 0 */
#define dLOGGING 0
#endif
#ifndef dTYPE /* usually TYPE_A */
#define dTYPE TYPE_A
#endif
#ifndef dTYPESTR /* usually "ascii" */
#define dTYPESTR "ascii"
#endif
#ifndef dREDIALDELAY /* usu. 60 (seconds). */
#define dREDIALDELAY 60
#endif
#ifndef CMDLINELEN
#define CMDLINELEN 256
#endif
#ifndef RECEIVEDLINELEN
#define RECEIVEDLINELEN 256
#endif
#ifndef MAXMACROS
#define MAXMACROS 16
#endif
#ifndef MACBUFLEN /* usually 4096. */
#define MACBUFLEN 4096
#endif
/* Do you want binary transfers by default? */
#ifndef dAUTOBINARY /* usually 1 */
#define dAUTOBINARY 1
#endif
#ifndef dPROGRESS
#define dPROGRESS pr_philbar /* can be: pr_none, pr_percent, pr_philbar,
* or pr_kbytes
*/
#endif
/* Default login name at gateway */
#ifdef GATEWAY
# ifndef dGATEWAY_LOGIN
# define dGATEWAY_LOGIN "ftp"
# endif
#endif
#endif /* _DEFAULTS_H_ */
/* eof */

File diff suppressed because it is too large Load Diff

View File

@ -1,67 +0,0 @@
/* ftp.h */
#ifndef _ftp_h_
#define _ftp_h_
/* $RCSfile: ftp.h,v $
* $Revision: 14020.11 $
* $Date: 93/07/09 11:04:12 $
*/
#define IS_FILE 1
#define IS_STREAM 0
#define IS_PIPE -1
/* Progress-meter types. */
#define pr_none 0
#define pr_percent 1
#define pr_philbar 2
#define pr_kbytes 3
#define pr_dots 4
#define pr_last pr_dots
/* Values sent to CommandWithFlags() to determine whether to read a reply
* from the remote host after sending the command.
*/
#define DONT_WAIT_FOR_REPLY 0
#define WAIT_FOR_REPLY 1
/* Expect EOF values for getreply() */
#define DONT_EXPECT_EOF 0
#define EXPECT_EOF 1
int hookup(char *, unsigned int);
int Login(char *userNamePtr, char *passWordPtr, char *accountPtr, int doInit);
void cmdabort SIG_PARAMS;
int CommandWithFlags(char *, int);
int command(char *);
int command_noreply(char *);
int quiet_command(char *);
int verbose_command(char *);
int getreply(int);
int start_progress(int, char *);
int progress_report(int);
void end_progress(char *, char *, char *);
void close_file(FILE **, int);
void abortsend SIG_PARAMS;
int sendrequest(char *, char *, char *);
void abortrecv SIG_PARAMS;
void GetLSRemoteDir(char *, char *);
int AdjustLocalFileName(char *);
int SetToAsciiForLS(int, int);
int IssueCommand(char *, char *);
FILE *OpenOutputFile(int, char *, char *, Sig_t *);
void ReceiveBinary(FILE *, FILE *, int *, char *);
void AddRedirLine(char *);
void ReceiveAscii(FILE *, FILE *, int *, char *, int);
void CloseOutputFile(FILE *, int, char *, time_t);
void ResetOldType(int);
int FileType(char *);
void CloseData(void);
int recvrequest(char *, char *, char *, char *);
int initconn(void);
FILE *dataconn(char *);
#endif /* _ftp_h_ */
/* eof ftp.h */

View File

@ -1,615 +0,0 @@
/* ftprc.c */
/* $RCSfile: ftprc.c,v $
* $Revision: 14020.11 $
* $Date: 93/07/09 10:58:37 $
*/
#include "sys.h"
#include <sys/stat.h>
#include <ctype.h>
#include <signal.h>
#include "util.h"
#include "ftprc.h"
#include "main.h"
#include "cmds.h"
#include "set.h"
#include "defaults.h"
#include "copyright.h"
/* ftprc.c global variables */
siteptr firstsite = NULL, lastsite = NULL;
recentsite recents[dMAXRECENTS];
int nRecents = 0;
int nSites = 0;
int keep_recent = dRECENT_ON;
longstring rcname;
longstring recent_file;
int parsing_rc = 0;
extern char *line, *margv[];
extern int margc, fromatty;
extern string anon_password; /* most likely your email address */
extern string pager;
extern struct userinfo uinfo;
int thrash_rc(void)
{
struct stat st;
string word, str;
longstring cwd;
char *cp, *dp, *rc;
FILE *fp;
int i;
(void) get_cwd(cwd, sizeof(cwd));
if (cwd[strlen(cwd) - 1] != '/')
(void) Strncat(cwd, "/");
/* Because some versions of regular ftp complain about ncftp's
* #set commands, FTPRC takes precedence over NETRC.
*/
cp = getenv("DOTDIR");
for (i=0; i<2; i++) {
rc = (i == 0) ? FTPRC : NETRC;
(void) sprintf(rcname, "%s%s", cwd, rc);
if (stat(rcname, &st) == 0)
goto foundrc;
(void) sprintf(rcname, "%s.%s", cwd, rc);
if (stat(rcname, &st) == 0)
goto foundrc;
if (cp != NULL) {
(void) sprintf(rcname, "%s/.%s", cp, rc);
if (stat(rcname, &st) == 0)
goto foundrc;
}
(void) sprintf(rcname, "%s/.%s", uinfo.homedir, rc);
if (stat(rcname, &st) == 0)
goto foundrc;
}
return (0); /* it's OK not to have an rc. */
foundrc:
if ((st.st_mode & 077) != 0) /* rc must be unreadable by others. */
(void) chmod(rcname, 0600);
if ((fp = fopen(rcname, "r")) == NULL) {
PERROR("thrash_rc", rcname);
return -1;
}
parsing_rc = 1;
while ((cp = FGets(str, fp)) != 0) {
while (isspace(*cp)) ++cp; /* skip leading space. */
if (*cp == '#') {
if ((strncmp("set", ++cp, (size_t)3) == 0) || (strncmp("unset", cp, (size_t)5) == 0)) {
(void) strcpy(line, cp);
makeargv();
(void) set(margc, margv);
/* setting or unsetting a variable. */
} /* else a comment. */
} else {
if (strncmp(cp, "machine", (size_t) 7) == 0) {
/* We have a new machine record. */
cp += 7;
while (isspace(*cp)) ++cp; /* skip delimiting space. */
dp = word;
while (*cp && !isspace(*cp)) *dp++ = *cp++; /* copy the name. */
*dp = 0;
AddNewSitePtr(word);
}
}
}
(void) fclose(fp);
parsing_rc = 0;
return 1;
} /* thrash_rc */
void AddNewSitePtr(char *word)
{
siteptr s;
if ((s = (siteptr) malloc(sizeof(site))) != 0) {
s->next = NULL;
if ((s->name = malloc(strlen(word) + 1)) != 0) {
(void) strcpy(s->name, word);
if (firstsite == NULL)
firstsite = lastsite = s;
else {
lastsite->next = s;
lastsite = s;
}
++nSites;
} else {
Free(s);
}
}
} /* AddNewSitePtr */
static int RecentCmp(recentsite *a, recentsite *b)
{
int i = 1;
if (a->lastcall > b->lastcall)
i = -1;
else if (a->lastcall == b->lastcall)
i = 0;
return i;
} /* RecentCmp */
static siteptr FindNetrcSite(char *host, int exact)
{
register siteptr s, s2;
string str, host2;
(void) Strncpy(host2, host);
StrLCase(host2);
/* see if 'host' is in our list of favorite sites (in NETRC). */
for (s = firstsite; s != NULL; s2=s->next, s=s2) {
(void) Strncpy(str, s->name);
StrLCase(str);
if (exact) {
if (strcmp(str, host2) == 0)
return s;
} else {
if (strstr(str, host2) != NULL)
return s;
}
}
return NULL;
} /* FindNetrcSite */
static recentsite *FindRecentSite(char *host, int exact)
{
register recentsite *r;
register int i;
string str, host2;
(void) Strncpy(host2, host);
StrLCase(host2);
/* see if 'host' is in our list of favorite sites (in recent-log). */
for (i=0; i<nRecents; i++) {
r = &recents[i];
(void) Strncpy(str, r->name);
StrLCase(str);
if (exact) {
if (strcmp(str, host2) == 0)
return r;
} else {
if (strstr(str, host2) != NULL)
return r;
}
}
return NULL;
} /* FindRecentSite */
void ReadRecentSitesFile(void)
{
FILE *rfp;
recentsite *r;
char name[64];
int offset;
longstring str;
nRecents = 0;
if (recent_file[0] != 0 && keep_recent) {
rfp = fopen(recent_file, "r");
if (rfp != NULL) {
for (; nRecents < dMAXRECENTS; ) {
r = &recents[nRecents];
if (FGets(str, rfp) == NULL)
break;
(void) RemoveTrailingNewline(str, NULL);
name[0] = 0;
offset = 45;
if (sscanf(str, "%s %lu %n",
name,
(unsigned long *) &r->lastcall,
&offset) >= 2)
{
if ((r->name = NewString(name)) != NULL) {
r->dir = NewString(str + offset);
if (r->dir != NULL)
nRecents++;
else {
free(r->name);
r->name = r->dir = NULL;
}
}
}
}
(void) fclose(rfp);
}
}
} /* ReadRecentSitesFile */
static void SortRecentList(void)
{
QSort(recents, nRecents, sizeof(recentsite), RecentCmp);
} /* SortRecentList */
int WriteRecentSitesFile(void)
{
FILE *rfp;
recentsite *r;
int i;
int retcode = 0;
if ((recent_file[0] != 0) && (nRecents > 0) && (keep_recent)) {
dbprintf("Attempting to write %s...\n", recent_file);
rfp = fopen(recent_file, "w");
if (rfp != NULL) {
SortRecentList();
for (i=0; i<nRecents; i++) {
r = &recents[i];
(void) fprintf(rfp, "%-32s %11lu %s\n", r->name,
(unsigned long) r->lastcall, r->dir);
}
(void) fclose(rfp);
dbprintf("%s written successfully.\n", recent_file);
(void) chmod(recent_file, 0600);
} else {
perror(recent_file);
++retcode;
}
}
return retcode;
} /* WriteRecentSitesFile */
void AddRecentSite(char *host, char *lastdir)
{
char *nhost, *ndir;
recentsite *r;
if (keep_recent) {
nhost = NewString(host);
/* Use '/' to denote that the current directory wasn't known,
* because we won't try to cd to the root directory.
*/
ndir = NewString(*lastdir ? lastdir : "/");
/* Don't bother if we don't have the memory, or if it is already
* in our NETRC.
*/
if ((ndir != NULL) && (nhost != NULL) &&
(FindNetrcSite(host, 1) == NULL)) {
if (nRecents == dMAXRECENTS) {
SortRecentList();
r = &recents[dMAXRECENTS - 1];
if (r->name != NULL)
free(r->name);
if (r->dir != NULL)
free(r->dir);
} else {
r = &recents[nRecents];
nRecents++;
}
r->name = nhost;
r->dir = ndir;
(void) time(&r->lastcall);
SortRecentList();
}
}
} /* AddRecentSite */
/*
* After you are done with a site (by closing it or quitting), we
* need to update the list of recent sites called.
*/
void UpdateRecentSitesList(char *host, char *lastdir)
{
recentsite *r;
char *ndir;
if (keep_recent) {
r = FindRecentSite(host, 1);
if (r == NULL)
AddRecentSite(host, lastdir);
else {
/* Update the last time connected, and the directory we left in. */
if ((ndir = NewString(*lastdir ? lastdir : "/")) != NULL) {
free(r->dir);
r->dir = ndir;
}
(void) time(&r->lastcall);
}
}
} /* UpdateRecentSitesList */
/*
* Prints out the number of sites we know about, so the user can figure out
* an abbreviation or type it's number to open (setpeer).
*/
void PrintSiteList(void)
{
int i, j;
siteptr s, s2;
FILE *pagerfp;
Sig_t sigpipe;
if (fromatty) {
j = 0;
i = 1;
sigpipe = Signal(SIGPIPE, SIG_IGN);
if ((pagerfp = popen(pager + 1, "w")) == NULL)
pagerfp = stdout;
if (nRecents > 0) {
j++;
(void) fprintf(pagerfp, "\nRecently called sites:\n");
for (; i<=nRecents; i++) {
(void) fprintf(pagerfp, "%4d. %-32s", i, recents[i-1].name);
i++;
if (i <= nRecents) {
(void) fprintf(pagerfp, "%5d. %-32s", i, recents[i-1].name);
} else {
(void) fprintf(pagerfp, "\n");
break;
}
(void) fprintf(pagerfp, "\n");
}
}
if (nSites > 0) {
j++;
(void) fprintf(pagerfp, "Sites in your netrc (%s):\n", rcname);
for (s = firstsite; s != NULL; s2=s->next, s=s2, ++i) {
(void) fprintf(pagerfp, "%4d. %-32s", i, s->name);
s2=s->next;
s=s2;
i++;
if (s != NULL) {
(void) fprintf(pagerfp, "%5d. %-32s", i, s->name);
} else {
(void) fprintf(pagerfp, "\n");
break;
}
(void) fprintf(pagerfp, "\n");
}
}
if (j > 0) {
(void) fprintf(pagerfp, "\
Note that you can specify an abbreviation of any name, or #x, where x is the\n\
number of the site you want to connect to.\n\n");
}
if (pagerfp != stdout)
(void) pclose(pagerfp);
Signal(SIGPIPE, sigpipe);
}
} /* PrintRecentSiteList */
/*
* Given a sitename, check to see if the name was really an abbreviation
* of a site in the NETRC, or a site in our list of recently connected
* sites. Also check if the name was in the format #x, where x which
* would mean to use recents[x].name as the site; if x was greater than
* the number of sites in the recent list, then index into the netrc
* site list.
*/
#include <netdb.h>
void GetFullSiteName(char *host, char *lastdir)
{
register siteptr s, s2;
register recentsite *r;
char *ndir, *nhost, *cp;
int x, i, isAllDigits, exact;
struct hostent *hostentp;
ndir = nhost = NULL;
x = exact = 0;
/* First, see if the "abbreviation" is really just the name of
* a machine in the local domain, or if it was a full hostname
* already. That way we can avoid problems associated with
* short names, such as having "ce" as a machine in the local
* domain, but having "faces.unl.edu", where we would most likely
* want to use ce instead of faces if the user said "open ce".
* This will also prevent problems when you have a host named
* xx.yy.unl.edu, and another host named yy.unl.edu. If the user
* said "open yy.unl.edu" we should use yy.unl.edu, and not look
* for matches containing yy.unl.edu.
*/
if ((hostentp = gethostbyname(host)) != NULL) {
strcpy(host, hostentp->h_name);
exact = 1;
}
/* Don't allow just numbers as abbreviations; "open 2" could be
* confused between site numbers in the open 'menu,' like
* "2. unlinfo.unl.edu" and IP numbers "128.93.2.1" or even numbers
* in the site name like "simtel20.army.mil."
*/
for (isAllDigits = 1, cp = host; *cp != 0; cp++) {
if (!isdigit(*cp)) {
isAllDigits = 0;
break;
}
}
if (!isAllDigits) {
if (host[0] == '#')
(void) sscanf(host + 1, "%d", &x);
/* Try matching the abbreviation, since it isn't just a number. */
/* see if 'host' is in our list of favorite sites (in NETRC). */
if (x == 0) {
if ((s = FindNetrcSite(host, exact)) != NULL) {
nhost = s->name;
} else if ((r = FindRecentSite(host, exact)) != NULL) {
nhost = r->name;
ndir = r->dir;
}
}
} else if (sscanf(host, "%d", &x) != 1) {
x = 0;
}
if (--x >= 0) {
if (x < nRecents) {
nhost = recents[x].name;
ndir = recents[x].dir;
} else {
x -= nRecents;
if (x < nSites) {
for (i = 0, s = firstsite; i < x; s2=s->next, s=s2)
++i;
nhost = s->name;
}
}
}
if (nhost != NULL) {
(void) strcpy(host, nhost);
if (lastdir != NULL) {
*lastdir = 0;
/* Don't cd if the dir is the root directory. */
if (ndir != NULL && (strcmp("/", ndir) != 0))
(void) strcpy(lastdir, ndir);
}
}
} /* GetFullSiteName */
int ruserpass2(char *host, char **username, char **pass, char **acct)
{
FILE *fp;
char *cp, *dp, *dst, *ep;
str32 macname;
char *varname;
int site_found;
string str;
static string auser;
static str32 apass, aacct;
site_found = 0;
if ((fp = fopen(rcname, "r")) != NULL) {
parsing_rc = 1;
while (FGets(str, fp)) {
if ((cp = strstr(str, "machine")) != 0) {
/* Look for the machine token. */
cp += 7;
while (isspace(*cp))
cp++;
} else
continue;
if (strncmp(host, cp, strlen(host)) == 0) {
site_found = 1;
while (!isspace(*cp))
++cp; /* skip the site name. */
do {
/* Skip any comments ahead of time. */
for (dp=cp; *dp; dp++) {
if (*dp == '#') {
*dp = 0;
break;
}
}
ep = cp;
while (1) {
varname = strtok(ep, RC_DELIM);
if (!varname) break;
dst = ep = NULL;
switch (*varname) {
case 'u': /* user */
*username = dst = auser;
break;
case 'l': /* login */
*username = dst = auser;
break;
case 'p': /* password */
*pass = dst = apass;
break;
case 'a': /* account */
*acct = dst = aacct;
break;
/* case 'd': /o default */
/* unused -- use 'set anon_password.' */
case 'm': /* macdef or machine */
if (strcmp(varname, "macdef"))
goto done; /* new machine record... */
dst = macname;
break;
default:
(void) fprintf(stderr, "Unknown .netrc keyword \"%s\"\n",
varname
);
}
if (dst) {
dp = strtok(ep, RC_DELIM);
if (dp)
(void) strcpy(dst, dp);
if (dst == macname) {
/*
* Read in the lines of the macro.
* The macro's end is denoted by
* a blank line.
*/
(void) make_macro(macname, fp);
goto nextline;
}
}
}
nextline: ;
} while ((cp = FGets(str, fp)) != 0);
break;
} /* end if we found the machine record. */
}
done:
parsing_rc = 0;
(void) fclose(fp);
}
if (!site_found) {
/* didn't find it in the rc. */
return (0);
}
return (1); /* found */
} /* ruserpass2 */
/* eof ftprc.c */

View File

@ -1,39 +0,0 @@
/* ftprc.h */
#ifndef _ftprc_h_
#define _ftprc_h_
/* $RCSfile: ftprc.h,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:45:31 $
*/
#define NETRC "netrc"
#define FTPRC "ncftprc"
#define RC_DELIM " \n\t,"
typedef struct site *siteptr;
typedef struct site {
char *name; /* name (or IP address) of site */
siteptr next;
} site;
typedef struct recentsite {
char *name; /* name (or IP address) of site */
char *dir; /* directory we were in last time we called. */
time_t lastcall; /* when this site was called last. */
} recentsite;
int thrash_rc(void);
void AddNewSitePtr(char *word);
int ruserpass2(char *host, char **user, char **pass, char **acct);
void GetFullSiteName(char *host, char *lastdir);
void ReadRecentSitesFile(void);
int WriteRecentSitesFile(void);
void AddRecentSite(char *host, char *lastdir);
void UpdateRecentSitesList(char *host, char *lastdir);
void PrintSiteList(void);
#endif
/* eof */

View File

@ -1,160 +0,0 @@
/* Getpass.c */
/* $RCSfile: getpass.c,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:44:36 $
*/
#include "sys.h"
#include <signal.h>
#include "util.h"
#include "cmds.h"
#include "getpass.h"
#include "copyright.h"
#ifndef GETPASS
#ifndef sun /* ...both unnecessary, and conflicting with <termios.h> */
#include <sys/ioctl.h>
#endif
#ifdef TERMIOS
# include <termios.h>
#else
# ifdef SGTTYB
# include <sgtty.h>
# else
# include <termio.h>
# endif
#endif /* !TERMIOS */
#ifdef STRICT_PROTOS
int ioctl(int, int, ...);
#endif
#endif /* GETPASS */
void Echo(FILE *fp, int on)
{
#ifndef GETPASS /* Otherwise just do nothing which is ok. */
#ifdef TERMIOS
static struct termios orig, noecho, *tp;
#else
# ifdef SGTTYB
static struct sgttyb orig, noecho, *tp;
# else
static struct termio orig, noecho, *tp;
# endif
#endif
static int state = 0;
int fd = fileno(fp);
if (!isatty(fd))
return;
if (state == 0) {
#ifdef TERMIOS
if (tcgetattr(fd, &orig) < 0)
PERROR("echo", "tcgetattr");
noecho = orig;
noecho.c_lflag &= ~ECHO;
#else
# ifdef SGTTYB
if (ioctl(fd, TIOCGETP, &orig) < 0)
PERROR("echo", "ioctl");
noecho = orig;
noecho.sg_flags &= ~ECHO;
# else
if (ioctl(fd, TCGETA, &orig) < 0)
PERROR("echo", "ioctl");
noecho = orig;
noecho.c_lflag &= ~ECHO;
# endif
#endif
state = 1;
}
tp = NULL;
if (on && state == 2) {
/* Turn echo back on. */
tp = &orig;
state = 1;
} else if (!on && state == 1) {
/* Turn echo off. */
tp = &noecho;
state = 2;
}
if (tp != NULL) {
#ifdef TERMIOS
if (tcsetattr(fd, TCSANOW, tp) < 0)
PERROR("echo", "tcsetattr");
#else
# ifdef SGTTYB
if (ioctl(fd, TIOCSETP, tp) < 0)
PERROR("echo", "ioctl");
# else
if (ioctl(fd, TCSETA, tp) < 0)
PERROR("echo", "ioctl");
# endif
#endif /* !TERMIOS */
}
#endif /* GETPASS */
} /* Echo */
#ifndef GETPASS
char *Getpass(char *promptstr)
{
register int ch;
register char *p;
FILE *fp, *outfp;
Sig_t oldintr;
static char buf[kMaxPassLen + 1];
/*
* read and write to /dev/tty if possible; else read from
* stdin and write to stderr.
*/
#if !defined(BOTCHED_FOPEN_RW)
if ((outfp = fp = fopen("/dev/tty", "w+")) == NULL) {
outfp = stderr;
fp = stdin;
}
#else
/* SCO 32v2 botches "w+" open */
if ((fp = fopen("/dev/tty", "r")) == NULL)
fp = stdin;
if ((outfp = fopen("/dev/tty", "w")) == NULL)
outfp = stderr;
#endif
oldintr = Signal(SIGINT, SIG_IGN);
Echo(fp, 0); /* Turn echoing off. */
(void) fputs(promptstr, outfp);
(void) rewind(outfp); /* implied flush */
for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';)
if (p < buf + kMaxPassLen)
*p++ = ch;
*p = '\0';
(void)write(fileno(outfp), "\n", 1);
Echo(fp, 1);
(void) Signal(SIGINT, oldintr);
if (fp != stdin)
(void)fclose(fp);
#if defined(BOTCHED_FOPEN_RW)
if (outfp != stderr)
(void)fclose(outfp);
#endif
return(buf);
} /* Getpass */
#endif /* GETPASS */
/* eof Getpass.c */

View File

@ -1,23 +0,0 @@
/* Getpass.h */
#ifndef _getpass_h_
#define _getpass_h_
/* $RCSfile: getpass.h,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:45:36 $
*/
#define kMaxPassLen 127
#ifdef GETPASS
extern char *getpass(); /* Use the system supplied getpass. */
#else
char *Getpass(char *prompt);
#endif
void Echo(FILE *fp, int on);
#endif /* _getpass_h_ */
/* eof Getpass.h */

View File

@ -1,655 +0,0 @@
/* glob.c */
/* $RCSfile: glob.c,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:44:32 $
*/
#include "sys.h"
#include <sys/stat.h>
/* Dir.h. Try <sys/dir.h> (add -DSYSDIRH) if <dirent.h> doesn't exist. */
#ifndef SYSDIRH
# include <dirent.h>
#else
# include <sys/dir.h>
#endif
#ifdef SCO324
# define direct dirent
#endif
#include <errno.h>
#include <pwd.h>
#include "util.h"
#include "glob.h"
#include "cmds.h"
#include "copyright.h"
#ifndef NCARGS
# define NCARGS 4096 /* # characters in exec arglist */
#endif
#define L_CURLY '{'
#define R_CURLY '}'
#define QUOTE 0200
#define TRIM 0177
#define eq(a,b) (strcmp(a, b)==0)
#define GAVSIZ (NCARGS/6)
#define isdir(d) ((d.st_mode & S_IFMT) == S_IFDIR)
static void ginit(char **agargv);
static void collect(char *as);
static void acollect(char *as);
static void sort(void);
static void expand(char *as);
static void matchdir(char *pattern);
static int execbrc(char *p, char *s);
static match(char *s, char *p);
static amatch(char *s, char *p);
#if UNUSED
static Gmatch(char *s, char *p);
#endif
static void Gcat(char *s1, char *s2);
static void addpath(char c);
static void rscan(char **t, int (*f )(char));
static tglob(char c);
static char *strspl(char *cp, char *dp);
static char *strend(char *cp);
static char **gargv; /* Pointer to the (stack) arglist */
static int gargc; /* Number args in gargv */
static int gnleft;
static short gflag;
char *globerr;
char *home; /* you must initialize this elsewhere! */
extern int errno;
static int globcnt;
char *globchars = "`{[*?";
static char *gpath, *gpathp, *lastgpathp;
static int globbed;
static char *entp;
static char **sortbas;
char **
glob(char *v)
{
char agpath[BUFSIZ];
char *agargv[GAVSIZ];
char *vv[2];
vv[0] = v;
vv[1] = 0;
gflag = (short) 0;
rscan(vv, tglob);
if (gflag == (short) 0)
return (copyblk(vv));
globerr = 0;
gpath = agpath; gpathp = gpath; *gpathp = 0;
lastgpathp = &gpath[sizeof agpath - 2];
ginit(agargv); globcnt = 0;
collect(v);
if (globcnt == 0 && (gflag & (short)1)) {
blkfree(gargv), gargv = 0;
return (0);
} else
return (gargv = copyblk(gargv));
}
static
void ginit(char **agargv)
{
agargv[0] = 0; gargv = agargv; sortbas = agargv; gargc = 0;
gnleft = NCARGS - 4;
}
static
void collect(char *as)
{
if (eq(as, "{") || eq(as, "{}")) {
Gcat(as, "");
sort();
} else
acollect(as);
}
static
void acollect(char *as)
{
register int ogargc = gargc;
gpathp = gpath; *gpathp = 0; globbed = 0;
expand(as);
if (gargc != ogargc)
sort();
}
static
void sort(void)
{
register char **p1, **p2, *c;
char **Gvp = &gargv[gargc];
p1 = sortbas;
while (p1 < Gvp-1) {
p2 = p1;
while (++p2 < Gvp)
if (strcmp(*p1, *p2) > 0)
c = *p1, *p1 = *p2, *p2 = c;
p1++;
}
sortbas = Gvp;
}
static
void expand(char *as)
{
register char *cs;
register char *sgpathp, *oldcs;
struct stat stb;
sgpathp = gpathp;
cs = as;
if (*cs == '~' && gpathp == gpath) {
addpath('~');
for (cs++; letter(*cs) || digit(*cs) || *cs == '-';)
addpath(*cs++);
if (!*cs || *cs == '/') {
if (gpathp != gpath + 1) {
*gpathp = 0;
if (gethdir(gpath + 1))
globerr = "Unknown user name after ~";
(void) strcpy(gpath, gpath + 1);
} else
(void) strcpy(gpath, home);
gpathp = strend(gpath);
}
}
while (!any(*cs, globchars)) {
if (*cs == 0) {
if (!globbed)
Gcat(gpath, "");
else if (stat(gpath, &stb) >= 0) {
Gcat(gpath, "");
globcnt++;
}
goto endit;
}
addpath(*cs++);
}
oldcs = cs;
while (cs > as && *cs != '/')
cs--, gpathp--;
if (*cs == '/')
cs++, gpathp++;
*gpathp = 0;
if (*oldcs == L_CURLY) {
(void) execbrc(cs, ((char *)0));
return;
}
matchdir(cs);
endit:
gpathp = sgpathp;
*gpathp = 0;
}
static
void matchdir(char *pattern)
{
struct stat stb;
#ifdef SYSDIRH
register struct direct *dp;
#else
register struct dirent *dp;
#endif
DIR *dirp;
dirp = opendir((*gpath ? gpath : "."));
if (dirp == NULL) {
if (globbed)
return;
goto patherr2;
}
if (fstat(dirp->dd_fd, &stb) < 0)
goto patherr1;
if (!isdir(stb)) {
errno = ENOTDIR;
goto patherr1;
}
while ((dp = readdir(dirp)) != NULL) {
if (dp->d_ino == 0)
continue;
if (match(dp->d_name, pattern)) {
Gcat(gpath, dp->d_name);
globcnt++;
}
}
(void) closedir(dirp);
return;
patherr1:
(void) closedir(dirp);
patherr2:
globerr = "Bad directory components";
}
static
int execbrc(char *p, char *s)
{
char restbuf[BUFSIZ + 2];
register char *pe, *pm, *pl;
int brclev = 0;
char *lm, savec, *sgpathp;
for (lm = restbuf; *p != L_CURLY; *lm++ = *p++)
continue;
for (pe = ++p; *pe; pe++)
switch (*pe) {
case L_CURLY:
brclev++;
continue;
case R_CURLY:
if (brclev == 0)
goto pend;
brclev--;
continue;
case '[':
for (pe++; *pe && *pe != ']'; pe++)
continue;
continue;
}
pend:
brclev = 0;
for (pl = pm = p; pm <= pe; pm++)
switch (*pm & (QUOTE|TRIM)) {
case L_CURLY:
brclev++;
continue;
case R_CURLY:
if (brclev) {
brclev--;
continue;
}
goto doit;
case ','|QUOTE:
case ',':
if (brclev)
continue;
doit:
savec = *pm;
*pm = 0;
(void) strcpy(lm, pl);
(void) strcat(restbuf, pe + 1);
*pm = savec;
if (s == 0) {
sgpathp = gpathp;
expand(restbuf);
gpathp = sgpathp;
*gpathp = 0;
} else if (amatch(s, restbuf))
return (1);
sort();
pl = pm + 1;
if (brclev)
return (0);
continue;
case '[':
for (pm++; *pm && *pm != ']'; pm++)
continue;
if (!*pm)
pm--;
continue;
}
if (brclev)
goto doit;
return (0);
}
static
int match(char *s, char *p)
{
register int c;
register char *sentp;
char sglobbed = globbed;
if (*s == '.' && *p != '.')
return (0);
sentp = entp;
entp = s;
c = amatch(s, p);
entp = sentp;
globbed = sglobbed;
return (c);
}
static
int amatch(char *s, char *p)
{
register int scc;
int ok, lc;
char *sgpathp;
struct stat stb;
int c, cc;
globbed = 1;
for (;;) {
scc = *s++ & TRIM;
switch (c = *p++) {
case L_CURLY:
return (execbrc(p - 1, s - 1));
case '[':
ok = 0;
lc = 077777;
while ((cc = *p++) != '\0') {
if (cc == ']') {
if (ok)
break;
return (0);
}
if (cc == '-') {
if (lc <= scc && scc <= *p++)
ok++;
} else
if (scc == (lc = cc))
ok++;
}
if (cc == 0)
if (ok)
p--;
else
return 0;
continue;
case '*':
if (!*p)
return (1);
if (*p == '/') {
p++;
goto slash;
}
s--;
do {
if (amatch(s, p))
return (1);
} while (*s++);
return (0);
case 0:
return (scc == 0);
default:
if (c != scc)
return (0);
continue;
case '?':
if (scc == 0)
return (0);
continue;
case '/':
if (scc)
return (0);
slash:
s = entp;
sgpathp = gpathp;
while (*s)
addpath(*s++);
addpath('/');
if (stat(gpath, &stb) == 0 && isdir(stb))
if (*p == 0) {
Gcat(gpath, "");
globcnt++;
} else
expand(p);
gpathp = sgpathp;
*gpathp = 0;
return (0);
}
}
}
#if UNUSED
static
Gmatch(char *s, char *p)
{
register int scc;
int ok, lc;
int c, cc;
for (;;) {
scc = *s++ & TRIM;
switch (c = *p++) {
case '[':
ok = 0;
lc = 077777;
while (cc = *p++) {
if (cc == ']') {
if (ok)
break;
return (0);
}
if (cc == '-') {
if (lc <= scc && scc <= *p++)
ok++;
} else
if (scc == (lc = cc))
ok++;
}
if (cc == 0)
if (ok)
p--;
else
return 0;
continue;
case '*':
if (!*p)
return (1);
for (s--; *s; s++)
if (Gmatch(s, p))
return (1);
return (0);
case 0:
return (scc == 0);
default:
if ((c & TRIM) != scc)
return (0);
continue;
case '?':
if (scc == 0)
return (0);
continue;
}
}
}
#endif
static
void Gcat(char *s1, char *s2)
{
register int len = strlen(s1) + strlen(s2) + 1;
if (len >= gnleft || gargc >= GAVSIZ - 1)
globerr = "Arguments too long";
else {
gargc++;
gnleft -= len;
gargv[gargc] = 0;
gargv[gargc - 1] = strspl(s1, s2);
}
}
static
void addpath(char c)
{
if (gpathp >= lastgpathp)
globerr = "Pathname too long";
else {
*gpathp++ = c;
*gpathp = 0;
}
}
static
void rscan(char **t, int (*f )(char))
{
register char *p, c;
while ((p = *t++) != 0) {
if (f == tglob)
if (*p == '~')
gflag |= (short) 2;
else if (eq(p, "{") || eq(p, "{}"))
continue;
while ((c = *p++) != '\0')
(*f)(c);
}
}
/*
static
scan(t, f)
register char **t;
int (*f)(char);
{
register char *p, c;
while (p = *t++)
while (c = *p)
*p++ = (*f)(c);
} */
static
int tglob(char c)
{
if (any(c, globchars))
gflag |= (c == L_CURLY ? (short)2 : (short)1);
return (c);
}
/*
static
trim(c)
char c;
{
return (c & TRIM);
} */
int letter(char c)
{
return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_');
}
int digit(char c)
{
return (c >= '0' && c <= '9');
}
int any(int c, char *s)
{
while (*s)
if (*s++ == c)
return(1);
return(0);
}
int blklen(char **av)
{
register int i = 0;
while (*av++)
i++;
return (i);
}
char **
blkcpy(char **oav, char **bv)
{
register char **av = oav;
while ((*av++ = *bv++) != 0)
continue;
return (oav);
}
void blkfree(char **av0)
{
register char **av = av0;
while (*av)
free(*av++);
}
static
char *
strspl(char *cp, char *dp)
{
register char *ep = (char *) malloc((size_t)(strlen(cp) + strlen(dp) + 1L));
if (ep == (char *)0)
fatal("Out of memory");
(void) strcpy(ep, cp);
(void) strcat(ep, dp);
return (ep);
}
char **
copyblk(char **v)
{
register char **nv = (char **)malloc((size_t)((blklen(v) + 1) *
sizeof(char **)));
if (nv == (char **)0)
fatal("Out of memory");
return (blkcpy(nv, v));
}
static
char *
strend(char *cp)
{
while (*cp)
cp++;
return (cp);
}
/*
* Extract a home directory from the password file
* The argument points to a buffer where the name of the
* user whose home directory is sought is currently.
* We write the home directory of the user back there.
*/
int gethdir(char *home_dir)
{
register struct passwd *pp = getpwnam(home_dir);
if (pp == 0)
return (1);
(void) strcpy(home_dir, pp->pw_dir);
return (0);
} /* gethdir */
/* eof glob.c */

View File

@ -1,22 +0,0 @@
/* glob.h */
#ifndef _glob_h_
#define _glob_h_ 1
/* $RCSfile: glob.h,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:45:32 $
*/
char **glob(char *v);
int letter(char c);
int digit(char c);
int any(int c, char *s);
int blklen(char **av);
char **blkcpy(char **oav, char **bv);
void blkfree(char **av0);
char **copyblk(char **v);
int gethdir(char *home_dir);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,45 +0,0 @@
/* main.h */
#ifndef _main_h_
#define _main_h_
struct userinfo {
str32 username;
string homedir;
string shell;
string hostname;
int uid;
};
void intr SIG_PARAMS;
int getuserinfo(void);
int init_arrays(void);
void init_transfer_buffer(void);
void init_prompt(void);
void lostpeer SIG_PARAMS;
int cmdscanner(int top);
char *strprompt(void);
void makeargv(void);
char *slurpstring(void);
int help(int argc, char **argv);
void trim_log(void);
int CheckNewMail(void);
#ifdef CURSES
void tcap_put(char *cap);
void termcap_init(void);
int termcap_get(char **dest, char *attr);
# ifndef TERMH /* <term.h> would take care of this. */
# ifdef NO_CONST
extern char *tgetstr(char *, char **);
# else
extern char *tgetstr(const char *, char **);
# endif
# endif /* TERMH */
#endif /* CURSES */
/* Should be in a 'tips.h,' but... */
void PrintTip(void);
#endif /* _main_h_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,644 +0,0 @@
/* open.c */
/* $RCSfile: open.c,v $
* $Revision: 1.1 $
* $Date: 93/07/09 11:27:07 $
*/
#include "sys.h"
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/ftp.h>
#include <errno.h>
#include "util.h"
#include "open.h"
#include "cmds.h"
#include "ftp.h"
#include "ftprc.h"
#include "main.h"
#include "defaults.h"
#include "copyright.h"
/* open.c globals */
int remote_is_unix; /* TRUE if remote host is unix. */
int auto_binary = dAUTOBINARY;
int anon_open = dANONOPEN;
/* Anonymous logins by default? */
int connected = 0; /* TRUE if connected to server */
/* If TRUE, set binary each connection. */
int www = 0; /* TRUE if use URL */
Hostname hostname; /* Name of current host */
RemoteSiteInfo gRmtInfo;
#ifdef GATEWAY
string gateway; /* node name of firewall gateway */
string gate_login; /* login at firewall gateway */
#endif
/* open.c externs */
extern char *reply_string, *line, *Optarg, *margv[];
extern int Optind, margc, verbose, macnum;
extern long eventnumber;
extern struct servent serv;
extern FILE *cout;
extern string anon_password;
/* Given a pointer to an OpenOptions (structure containing all variables
* that can be set from the command line), this routine makes sure all
* the variables have valid values by setting them to their defaults.
*/
void InitOpenOptions(OpenOptions *openopt)
{
/* How do you want to open a site if neither -a or -u are given?
* anon_open is true (default to anonymous login), unless
* defaults.h was edited to set dANONOPEN to 0 instead.
*/
openopt->openmode = anon_open ? openImplicitAnon : openImplicitUser;
/* Normally you don't want to ignore the entry in your netrc. */
openopt->ignore_rc = 0;
/* Set the default delay if the user specifies redial mode without
* specifying the redial delay.
*/
openopt->redial_delay = dREDIALDELAY;
/* Normally, you only want to try once. If you specify redial mode,
* this is changed.
*/
openopt->max_dials = 1;
/* You don't want to cat the file to stdout by default. */
openopt->ftpcat = NO_FTPCAT;
/* Setup the port number to try. */
#ifdef dFTP_PORT
/* If dFTP_PORT is defined, we use a different port number by default
* than the one supplied in the servent structure.
*/
openopt->port = dFTP_PORT;
/* Make sure the correct byte order is supplied! */
openopt->port = htons(openopt->port);
#else
/* Use the port number supplied by the operating system's servent
* structure.
*/
openopt->port = serv.s_port;
#endif
/* We are not in colon-mode (yet). */
openopt->colonmodepath[0] = 0;
/* Set the hostname to a null string, since there is no default host. */
openopt->hostname[0] = 0;
/* Set the opening directory path to a null string. */
openopt->cdpath[0] = 0;
} /* InitOpenOptions */
/* This is responsible for parsing the command line and setting variables
* in the OpenOptions structure according to the user's flags.
*/
int GetOpenOptions(int argc, char **argv, OpenOptions *openopt)
{
int opt;
char *cp, *hostp, *cpath;
/* First setup the openopt variables. */
InitOpenOptions(openopt);
/* Tell Getopt() that we want to start over with a new command. */
Getopt_Reset();
while ((opt = Getopt(argc, argv, "aiup:rd:g:cm")) >= 0) {
switch (opt) {
case 'a':
/* User wants to open anonymously. */
openopt->openmode = openExplicitAnon;
break;
case 'u':
/* User wants to open with a login and password. */
openopt->openmode = openExplicitUser;
break;
case 'i':
/* User wants to ignore the entry in the netrc. */
openopt->ignore_rc = 1;
break;
case 'p':
/* User supplied a port number different from the default
* ftp port.
*/
openopt->port = atoi(Optarg);
if (openopt->port <= 0) {
/* Probably never happen, but just in case. */
(void) printf("%s: bad port number (%s).\n", argv[0], Optarg);
goto usage;
}
/* Must ensure that the port is in the correct byte order! */
openopt->port = htons(openopt->port);
break;
case 'd':
/* User supplied a delay (in seconds) that differs from
* the default.
*/
openopt->redial_delay = atoi(Optarg);
break;
case 'g':
/* User supplied an upper-bound on the number of redials
* to try.
*/
openopt->max_dials = atoi(Optarg);
break;
case 'r':
openopt->max_dials = -1;
break;
case 'm':
/* ftpcat mode is only available from your shell command-line,
* not from the ncftp shell. Do that yourself with 'more zz'.
*/
if (eventnumber == 0L) {
/* If eventnumber is zero, then we were called directly
* from main(), and before the ftp shell has started.
*/
openopt->ftpcat = FTPMORE;
/* ftpcat mode is really ftpmore mode. */
break;
} else {
fprintf(stderr,
"You can only use this form of colon-mode (-m) from your shell command line.\n\
Try 'ncftp -m wuarchive.wustl.edu:/README'\n");
goto usage;
}
/* break; */
case 'c':
/* ftpcat mode is only available from your shell command-line,
* not from the ncftp shell. Do that yourself with 'get zz -'.
*/
if (eventnumber == 0L) {
/* If eventnumber is zero, then we were called directly
* from main(), and before the ftp shell has started.
*/
openopt->ftpcat = FTPCAT;
break;
} else {
fprintf(stderr,
"You can only use ftpcat/colon-mode from your shell command line.\n\
Try 'ncftp -c wuarchive.wustl.edu:/README > file.'\n");
goto usage;
}
/* break; */
default:
usage:
return USAGE;
}
}
if (argv[Optind] == NULL) {
/* No host was supplied. Print out the list of sites we know
* about and ask the user for one.
*/
PrintSiteList();
(void) Gets("(site to open) ", openopt->hostname, sizeof(openopt->hostname));
/* Make sure the user just didn't hit return, in which case we
* just give up and go home.
*/
if (openopt->hostname[0] == 0)
goto usage;
} else {
/* The user gave us a host to open.
*
* First, check to see if they gave us a colon-mode path
* along with the hostname. We also understand a WWW path,
* like "ftp://bang.nta.no/pub/fm2html.v.0.8.4.tar.Z".
*/
hostp = argv[Optind];
cpath = NULL;
if ((cp = index(hostp, ':')) != NULL) {
*cp++ = '\0';
cpath = cp;
www = 0; /* Is 0 or 1, depending on the type of path. */
if ((*cp == '/') && (cp[1] == '/')) {
/* First make sure the path was intended to be used
* with ftp and not one of the other URLs.
*/
if (strcmp(argv[Optind], "ftp")) {
fprintf(
stderr,
"Bad URL '%s' -- WWW paths must be prefixed by 'ftp://'.\n",
argv[Optind]
);
goto usage;
}
cp += 2;
hostp = cp;
cpath = NULL; /* It could have been ftp://hostname only. */
if ((cp = index(hostp, '/')) != NULL) {
*cp++ = '\0';
cpath = cp;
}
www = 1;
}
if (cpath != NULL) {
(void) Strncpy(openopt->colonmodepath, www ? "/" : "");
(void) Strncat(openopt->colonmodepath, cpath);
dbprintf("Colon-Mode Path = '%s'\n", openopt->colonmodepath);
}
}
(void) Strncpy(openopt->hostname, hostp);
dbprintf("Host = '%s'\n", hostp);
}
return NOERR;
} /* GetOpenOptions */
/* This examines the format of the string stored in the hostname
* field of the OpenOptions, and sees if has to strip out a colon-mode
* pathname (to store in the colonmodepath field). Since colon-mode
* is run quietly (without any output being generated), we init the
* login_verbosity variable here to quiet if we are running colon-mode.
*/
int CheckForColonMode(OpenOptions *openopt, int *login_verbosity)
{
/* Usually the user doesn't supply hostname in colon-mode format,
* and wants to interactively browse the remote host, so set the
* login_verbosity to whatever it is set to now.
*/
*login_verbosity = verbose;
if (openopt->colonmodepath[0] != 0) {
/* But if the user does use colon-mode, we want to do our business
* and leave, without all the login messages, etc., so set
* login_verbosity to quiet so we won't print anything until
* we finish. Colon-mode can be specified from the shell command
* line, so we would like to be able to execute ncftp as a one
* line command from the shell without spewing gobs of output.
*/
*login_verbosity = V_QUIET;
} else if (openopt->ftpcat != 0) {
/* User specified ftpcat mode, but didn't supply the host:file. */
(void) fprintf(stderr, "You didn't use colon mode correctly.\n\
If you use -c or -m, you need to do something like this:\n\
ncftp -c wuarchive.wustl.edu:/pub/README (to cat this file to stdout).\n");
return USAGE;
}
return NOERR;
} /* CheckForColonMode */
/* All this short routine does is to hookup a socket to either the
* remote host or the firewall gateway host.
*/
int HookupToRemote(OpenOptions *openopt)
{
int hErr;
#ifdef GATEWAY
/* Try connecting to the gateway host. */
if (*gateway) {
hErr = hookup(gateway, openopt->port);
(void) Strncpy(hostname, openopt->hostname);
} else
#endif
hErr = hookup(openopt->hostname, openopt->port);
return hErr;
} /* HookupToRemote */
void CheckRemoteSystemType(int force_binary)
{
int tmpverbose;
char *cp, c;
/* As of this writing, UNIX is pretty much standard. */
remote_is_unix = 1;
/* Do a SYSTem command quietly. */
tmpverbose = verbose;
verbose = V_QUIET;
if (command("SYST") == COMPLETE) {
if (tmpverbose == V_VERBOSE) {
/* Find the system type embedded in the reply_string,
* and separate it from the rest of the junk.
*/
cp = index(reply_string+4, ' ');
if (cp == NULL)
cp = index(reply_string+4, '\r');
if (cp) {
if (cp[-1] == '.')
cp--;
c = *cp;
*cp = '\0';
}
(void) printf("Remote system type is %s.\n",
reply_string+4);
if (cp)
*cp = c;
}
remote_is_unix = !strncmp(reply_string + 4, "UNIX", (size_t) 4);
}
/* Set to binary mode if any of the following are true:
* (a) The user has auto-binary set;
* (b) The user is using colon-mode (force_binary);
* (c) The reply-string from SYST said it was UNIX with 8-bit chars.
*/
if (auto_binary || force_binary
|| !strncmp(reply_string, "215 UNIX Type: L8", (size_t) 17)) {
(void) _settype("binary");
if (tmpverbose > V_TERSE)
(void) printf("Using binary mode to transfer files.\n");
}
/* Print a warning for that (extremely) rare Tenex machine. */
if (tmpverbose >= V_ERRS &&
!strncmp(reply_string, "215 TOPS20", (size_t) 10)) {
(void) _settype("tenex");
(void) printf("Using tenex mode to transfer files.\n");
}
verbose = tmpverbose;
} /* CheckRemoteSystemType */
/* This is called if the user opened the host with a file appended to
* the host's name, like "wuarchive.wustl.edu:/pub/readme," or
* "wuarchive.wustl.edu:/pub." In the former case, we open wuarchive,
* and fetch "readme." In the latter case, we open wuarchive, then set
* the current remote directory to "/pub." If we are fetching a file,
* we can do some other tricks if "ftpcat mode" is enabled. This mode
* must be selected from your shell's command line, and this allows you
* to use the program as a one-liner to pipe a remote file into something,
* like "ncftp -c wu:/pub/README | wc." If the user uses ftpcat mode,
* the program immediately quits instead of going into it's own command
* shell.
*/
void ColonMode(OpenOptions *openopt)
{
int tmpverbose;
int cmdstatus;
/* How do we tell if colonmodepath is a file or a directory?
* We first try cd'ing to the path first. If we can, then it
* was a directory. If we could not, we'll assume it was a file.
*/
/* Shut up, so cd won't print 'foobar: Not a directory.' */
tmpverbose = verbose;
verbose = V_QUIET;
/* If we are using ftpcat|more mode, or we couldn't cd to the
* colon-mode path (then it must be a file to fetch), then
* we need to fetch a file.
*/
if (openopt->ftpcat || ! _cd(openopt->colonmodepath)) {
/* We call the appropriate fetching routine, so we have to
* have the argc and argv set up correctly. To do this,
* we just make an entire command line, then let makeargv()
* convert it to argv/argc.
*/
if (openopt->ftpcat == FTPCAT)
(void) sprintf(line, "get %s -", openopt->colonmodepath);
else if (openopt->ftpcat == FTPMORE)
(void) sprintf(line, "more %s", openopt->colonmodepath);
else {
/* Regular colon-mode, where we fetch the file, putting the
* copy in the current local directory.
*/
(void) sprintf(line, "mget %s", openopt->colonmodepath);
}
makeargv();
/* Turn on messaging if we aren't catting. */
if (openopt->ftpcat == 0)
verbose = tmpverbose;
/* get() also handles 'more'. */
if (openopt->ftpcat)
cmdstatus = get(margc, margv);
else
cmdstatus = mget(margc, margv);
/* If we were invoked from the command line, quit
* after we got this file.
*/
if (eventnumber == 0L) {
(void) quit(cmdstatus == CMDERR ? -1 : 0, NULL);
}
}
verbose = tmpverbose;
} /* ColonMode */
/* Given a properly set up OpenOptions, we try connecting to the site,
* redialing if necessary, and do some initialization steps so the user
* can send commands.
*/
int Open(OpenOptions *openopt)
{
int hErr;
int dials;
char *ruser, *rpass, *racct;
int siteInRC;
char *user, *pass, *acct;
int login_verbosity, oldv;
int result = CMDERR;
macnum = 0; /* Reset macros. */
/* If the hostname supplied is in the form host.name.str:/path/file,
* then colon mode was used, and we need to fix the hostname to be
* just the hostname, copy the /path/file to colonmode path, and init
* the login_verbosity variable.
*/
if (CheckForColonMode(openopt, &login_verbosity) == USAGE)
return USAGE;
/* If the hostname supplied was an abbreviation, such as just
* "wu" (wuarchive.wustl.edu), look through the list of sites
* we know about and get the whole name. We also would like
* the path we want to start out in, if it is available.
*/
GetFullSiteName(openopt->hostname, openopt->cdpath);
#ifdef GATEWAY
/* Make sure the gateway host name is a full name and not an
* abbreviation.
*/
if (*gateway)
GetFullSiteName(gateway, NULL);
#endif
ruser = rpass = racct = NULL;
/* This also loads the init macro. */
siteInRC = ruserpass2(openopt->hostname, &ruser, &rpass, &racct);
if (ISANONOPEN(openopt->openmode)) {
user = "anonymous";
pass = anon_password;
} else {
user = NULL;
pass = NULL;
}
acct = NULL;
if (siteInRC && !openopt->ignore_rc) {
acct = racct;
if (ruser != NULL) {
/* We were given a username. If we were given explicit
* instructions from the command line, follow those and
* ignore what the RC had. Otherwise if no -a or -u
* was specified, we use whatever was in the RC.
*/
if (ISIMPLICITOPEN(openopt->openmode)) {
user = ruser;
pass = rpass;
}
}
}
for (
dials = 0;
openopt->max_dials < 0 || dials < openopt->max_dials;
dials++)
{
if (dials > 0) {
/* If this is the second dial or higher, sleep a bit. */
(void) sleep(openopt->redial_delay);
(void) fprintf(stderr, "Retry Number: %d\n", dials + 1);
}
if ((hErr = HookupToRemote(openopt)) == -2)
/* Recoverable, so we can try re-dialing. */
continue;
else if (hErr == NOERR) {
/* We were hookup'd successfully. */
connected = 1;
oldv = verbose; verbose = login_verbosity;
#ifdef GATEWAY
if (*gateway) {
if ((Login(
user,
pass,
acct,
(!openopt->ignore_rc && !openopt->colonmodepath[0])
) != NOERR) || cout == NULL)
goto nextdial; /* error! */
}
#endif
#ifdef GATEWAY
if (!*gateway) {
#endif
/* We don't want to run the init macro for colon-mode. */
if ((Login(
user,
pass,
acct,
(!openopt->ignore_rc && !openopt->colonmodepath[0])
) != NOERR) || cout == NULL)
{
goto nextdial; /* error! */
}
#ifdef GATEWAY
}
#endif
verbose = oldv;
/* We need to check for unix and see if we should set binary
* mode automatically.
*/
CheckRemoteSystemType(openopt->colonmodepath[0] != (char)0);
if (openopt->colonmodepath[0]) {
ColonMode(openopt);
} else if (openopt->cdpath[0]) {
/* If we didn't have a colon-mode path, we try setting
* the current remote directory to cdpath. cdpath is
* usually the last directory we were in the previous
* time we called this site.
*/
(void) _cd(openopt->cdpath);
} else {
/* Freshen 'cwd' variable for the prompt.
* We have to do atleast one 'cd' so our variable
* cwd (which is saved by _cd()) is set to something
* valid.
*/
(void) _cd(NULL);
}
result = NOERR;
break; /* we are connected, so break the redial loop. */
/* end if we are connected */
} else {
/* Irrecoverable error, so don't bother redialing. */
/* The error message should have already been printed
* from Hookup().
*/
break;
}
nextdial:
disconnect(0, NULL);
continue; /* Try re-dialing. */
}
return (result);
} /* Open */
/* This stub is called by our command parser. */
int cmdOpen(int argc, char **argv)
{
OpenOptions openopt;
int result = NOERR;
/* If there is already a site open, close that one so we can
* open a new one.
*/
if (connected && NOT_VQUIET && hostname[0]) {
(void) printf("Closing %s...\n", hostname);
(void) disconnect(0, NULL);
}
/* Reset the remote info structure for the new site we want to open.
* Assume we have these properties until we discover otherwise.
*/
gRmtInfo.hasSIZE = 1;
gRmtInfo.hasMDTM = 1;
if ((GetOpenOptions(argc, argv, &openopt) == USAGE) ||
((result = Open(&openopt)) == USAGE))
return USAGE;
/* Return an error if colon-mode/URL didn't work. */
return (openopt.colonmodepath[0] != '\0' ? result : NOERR);
} /* cmdOpen */
/* eof open.c */

View File

@ -1,50 +0,0 @@
/* open.h */
#ifndef _open_h_
#define _open_h_ 1
/* Variables for Open() that can be changed from the command line. */
typedef struct OpenOptions {
int openmode;
int ignore_rc;
unsigned int port;
int redial_delay;
int max_dials;
int ftpcat;
Hostname hostname;
longstring cdpath;
longstring colonmodepath;
} OpenOptions;
typedef struct RemoteSiteInfo {
int hasSIZE;
int hasMDTM;
} RemoteSiteInfo;
/* Open modes. */
#define openImplicitAnon 1
#define openImplicitUser 4
#define openExplicitAnon 3
#define openExplicitUser 2
#define ISUSEROPEN(a) ((a==openImplicitUser)||(a==openExplicitUser))
#define ISANONOPEN(a) (!ISUSEROPEN(a))
#define ISEXPLICITOPEN(a) ((a==openExplicitAnon)||(a==openExplicitUser))
#define ISIMPLICITOPEN(a) (!ISEXPLICITOPEN(a))
/* ftpcat modes. */
#define NO_FTPCAT 0
#define FTPCAT 1
#define FTPMORE 2
/* Protos: */
void InitOpenOptions(OpenOptions *openopt);
int GetOpenOptions(int argc, char **argv, OpenOptions *openopt);
int CheckForColonMode(OpenOptions *openopt, int *login_verbosity);
int HookupToRemote(OpenOptions *openopt);
void CheckRemoteSystemType(int);
void ColonMode(OpenOptions *openopt);
int Open(OpenOptions *openopt);
int cmdOpen(int argc, char **argv);
#endif /* _open_h_ */

View File

@ -1,158 +0,0 @@
v1.9.5 - October 29, 1995. Termcap needs ospeed initialization for BSD.
v1.9.4 - April 15, 1995. Using PORT by default instead of PASV by default.
Method to get the mail pathname changed.
v1.9.3 - March 5, 1995. Support for NetBSD and DELL added. Linger works
with passive mode now.
v1.9.2 - January 20, 1995. Another passive mode fix with the SOCKS library.
Trying to avoid going into the interactive shell if colon-mode fails.
v1.9.1 - January 1, 1995. Passive mode fix with the SOCKS library.
v1.9.0 - December 22, 1994. The program won't exit from the interactive shell
if it's working from a tty. For example, it won't exit if you do an mget
on a pattern that won't match anything. Added padding around jmp_buf's
for SunOS. SunOS needs sigjmp_buf's, but plenty of OS's don't support
sigjmp_buf's yet. Fixed the tips to reflect the new archive site.
v1.8.9 - December 20, 1994. Can now set "passive" user variable, or use
passive command to toggle PASV/PORT ftp. Debug mode now prints remote
responses. Can now get around buggy FTP servers like boombox.micro.umn.edu,
that give back invalid port numbers to PASV.
v1.8.8 - December 19, 1994. Now falls back to port FTP if passive FTP fails.
v1.8.7 - December 11, 1994. Tweaks for FreeBSD. Passive mode enabled and
turned on by default.
v1.8.6 - October 30, 1994. Tweaks for Solaris in sys.h.
v1.8.5 - September 20, 1994. Better(?) support for term.
v1.8.4 - September 19, 1994. Bug in Makefile fixed. Bug involving getwd
fixed.
v1.8.3 - August 27, 1994. Bug fixed where failed connection attempts when
using a numeric IP address would fail.
v1.8.2 - August 4, 1994. Can compile with DONT_TIMESTAMP to turn off syncing
timestamps of fetched files with their remote counterparts. IP_TOS now
utilized.
v1.8.1 - July 4, 1994. Forgot <signal.h> in ftprc.c.
v1.8.0 - July 4, 1994. Tweak for DEC OSF/1. NO_FORMATTING added.
Support for QNX added. Reporting an error if the recent file could
not be written. Bumped up the max recents to 50; the open menu will
now be fed through your pager to avoid the problem of scrolling off
screen. Fixed problem with redialing and running out of descriptors.
v1.7.8 - June 30, 1994. No longer defining TERMH for linux.
v1.7.7 - June 21, 1994. Deleted a space in front of an " #endif".
No functionality change whatsoever...
v1.7.6 - June 18, 1994. Added commands and code to support the
PASV command for passive negotiation of the data connection from
the host server to the client. This facilitates operation of the
client software from within a firewall. (J. B. Harrell)
v1.7.5 - May 28, 1994. Fixed a rare problem with dimmed text. Fixed
compilation problem with Dynix. Defining the domain name now takes
precedence over the getdomainname() function.
v1.7.4 - May 16, 1994. Tweaked hookup() a bit, to (try to) handle
hosts with multiple addresses better. Fixed error with GMT offsets.
Fixed 'addr_t' typo in SVR4 section. Moved SVR4 block down in sys.h.
v1.7.3 - April 13, 1994. Fixed minor error in syslog reporting.
Trying both getpwnam() and getpwuid(), instead of just one of them,
increasing the probability the program can get your passwd entry.
Better compatibility with other types of password input devices.
v1.7.2 - April 5, 1994. Bytes/sec is now correct. Fixed error when
NO_VARARGS was defined. Added support for <varargs.h>.
v1.7.1 - March 27, 1994. Defining HAS_DOMAINNAME for NeXT. Term hack can
share sockets, plus some term stuff added to the Makefile. Trimmed
some old stuff from the patchlevel.h file, and putting new versions
first now. Smarter about determining abbreviations from local hostnames.
Fixed bug where progress meter would go beserk after trying to get
a non-existant file.
v1.7.0 - March 14, 1994. More verbose when logging to the system log,
and making sure that syslog() itself is called with a total of 5
or less parameters. Official patch posted which incorporates all
the fixes to 1.6.0 (i.e. 1.6.1, 1.6.2, ... 1.6.9).
v1.6.9 - March 11, 1994. Added DOMAIN_NAME and Solaris CPP symbols.
Better handling of getting the domain name, specifically with SunOS.
BSDi support added.
v1.6.8 - March 4, 1994. Ensuring that tmp files are not public.
Trying harder to get the real hostname, and fixed problem with
disappearing progress meters (both due to T. Lindgren).
v1.6.7 - February 20, 1994. Using getpwnam() instead of getpwuid().
Supporting WWW paths (i.e. ftp://host.name/path/name).
v1.6.6 - February 15, 1994. Prevented scenario of fclosing a NULL FILE *.
Edited term ftp's hookup() a little. More defs for linux in sys.h.
Not updating a recent entry unless you were fully logged in.
v1.6.5 - January 6, 1994. Fixed error with an #ifndef/#endif block having
whitespace before the #. No longer confirming "ls >file" actions.
Changed echo() to Echo(). AIX 3 uses TERMIOS.
v1.6.4 - December 30, 1993. Fixed rare problem with GetDateAndTime.
confirm() will return true if you're running the init macro.
v1.6.3 - December 28, 1993. Added a new diagnostic command, memchk,
to print stats from a special malloc library if you used one.
Using SIZE and MDTM when the remote site supports it. Using a new
set of routines for term (again).
v1.6.2 - December 10, 1993.
Term hack no longer depends on the PASV command (!). The BROKEN_MEMCPY
problem worked-around. More wary of symbolic-link recursion.
Fixed local path expander. Fixed inadvertant flushing of the typeahead
buffer. Debug mode won't print your password. Progress meters
no longer goof up when the file is huge. Added time-remaining to the
Philbar.
v1.6.1 - November 5, 1993.
Checking if we have permission to write over a file to fetch.
A few very minor changes. BSD no longer trying to use strchr :-)
v1.6.0 - October 31, 1993.
Added "term" support for Linux users. Better SCO Xenix support. Added
-DLINGER, if you have a connection requiring it (so 'puts' to the remote
system complete). Added -DNET_ERRNO_H if you need to include
<net/errno.h>. Including more headers in sys.h. Fixed another globulize
bug. Fixed a bug in confirm() where prompt was overwriting a str32.
Added -DNO_CURSES_H if you do not want to try and include <curses.h>.
Added -DHAS_GETCWD (usually automatic) and HAS_DOMAINNAME. Logins as
"ftp" act like "anonymous." Fixed bug with "open #x". Making sure you
defined GZCAT as a string. Turning off termcap attributes one by one,
instead of using the turn-off-all-attributes. A few fixes for the man
page, including documentation of the progress-meter types. AIX 2.x,
AIX 3.x, ISC Unix, Dynix/PTX, and Besta support added to sys.h. Safer
use of getwd(). Colon-mode is quieter. Getuserinfo function tweaked.
Eliminated unnecessary GetHomeDir function in util.c. Reworked Gets(),
since it wasn't always stripping \n's. Recent file can now read dir
names with whitespace. Opening msg uses a larger buffer, because of
escape codes. Philbar now prints K/sec stats.
v1.5.6 - September 20, 1993...
v1.5.5 - September 16, 1993...
v1.5.4 - September 14, 1993...
v1.5.3 - September 2, 1993...
v1.5.2 - August 30, 1993...
v1.5.1 - August 29, 1993...
v1.5.0 - August 22, 1993...
v1.0.2 - Jan 17, 1993...
v1.0.1 - December 8, 1992...
v1.0.0 - December 6, 1992. Initial release.

View File

@ -1,370 +0,0 @@
/* Set.c */
/* $RCSfile: set.c,v $
* $Revision: 14020.12 $
* $Date: 93/07/09 11:45:48 $
*/
#include "sys.h"
#include <ctype.h>
#include "util.h"
#include "cmds.h"
#include "main.h"
#include "set.h"
#include "defaults.h"
#include "copyright.h"
#ifdef TERM_FTP
extern int compress_toggle;
#endif
/* Set.c globals: */
char *verbose_msgs[4] = {
"Not printing anything.\n",
"Only printing necessary error messages.\n",
"Printing error messages and announcements from the remote host.\n",
"Printing all messages, errors, acknowledgments, and announcements.\n"
};
char *short_verbose_msgs[4] = {
"Quiet (-1)",
"Errors Only (0)",
"Terse (1)",
"Verbose (2)"
};
string vstr;
/* Set.c externs: */
extern int progress_meter, connected;
extern int parsing_rc, keep_recent;
extern string pager, anon_password, prompt;
extern str32 curtypename;
extern long logsize;
extern FILE *logf;
extern longstring rcname, logfname, lcwd;
extern int auto_binary, ansi_escapes, debug;
extern int mprompt, remote_is_unix, verbose;
extern int startup_msg, anon_open, passivemode;
extern int restricted_data_ports;
#ifndef NO_TIPS
extern int tips;
#endif
#ifdef GATEWAY
extern string gateway, gate_login;
#endif
/* The variables must be sorted in alphabetical order, or else
* match_var() will choke.
*/
struct var vars[] = {
VARENTRY("anon-open", BOOL, 0, &anon_open, NULL),
VARENTRY("anon-password", STR, 0, anon_password, NULL),
VARENTRY("ansi-escapes", BOOL, 0, &ansi_escapes, NULL),
VARENTRY("auto-binary", BOOL, 0, &auto_binary, NULL),
#ifdef TERM_FTP
VARENTRY("compress", INT, 0,
&compress_toggle,NULL),
#endif
VARENTRY("debug", INT, 0, &debug, NULL),
#ifdef GATEWAY
VARENTRY("gateway-login", STR, 0, gate_login, set_gatelogin),
VARENTRY("gateway-host", STR, 0, gateway, NULL),
#endif
VARENTRY("local-dir", STR, 0, lcwd, set_ldir),
VARENTRY("logfile", STR, 0, logfname, set_log),
VARENTRY("logsize", LONG, 0, &logsize, NULL),
VARENTRY("mprompt", BOOL, 0, &mprompt, NULL),
VARENTRY("netrc", -STR, 0, rcname, NULL),
VARENTRY("passive", BOOL, 0, &passivemode, NULL),
VARENTRY("pager", STR, 0, pager + 1, set_pager),
VARENTRY("prompt", STR, 0, prompt, set_prompt),
VARENTRY("progress-reports",INT, 0, &progress_meter,NULL),
VARENTRY("recent-list", BOOL, 0, &keep_recent, NULL),
VARENTRY("remote-is-unix", BOOL, 1, &remote_is_unix,NULL),
VARENTRY("restricted-data-ports",BOOL, 0, &restricted_data_ports, NULL),
VARENTRY("startup-msg", BOOL, 0, &startup_msg, NULL), /* TAR */
#ifndef NO_TIPS
VARENTRY("tips", BOOL, 0, &tips, NULL),
#endif
VARENTRY("type", STR, 1, curtypename, set_type),
VARENTRY("verbose", STR, 0, vstr, set_verbose),
};
void set_verbose(char *new, int unset)
{
int i, c;
if (unset == -1) verbose = !verbose;
else if (unset || !new) verbose = V_ERRS;
else {
if (isalpha(*new)) {
c = islower(*new) ? toupper(*new) : *new;
for (i=0; i<(int)(sizeof(short_verbose_msgs)/sizeof(char *)); i++) {
if (short_verbose_msgs[i][0] == c)
verbose = i - 1;
}
} else {
i = atoi(new);
if (i < V_QUIET) i = V_QUIET;
else if (i > V_VERBOSE) i = V_VERBOSE;
verbose = i;
}
}
(void) Strncpy(vstr, short_verbose_msgs[verbose+1]);
if (!parsing_rc && NOT_VQUIET)
(void) fputs(verbose_msgs[verbose+1], stdout);
} /* set_verbose */
void set_prompt(char *new, int unset)
{
(void) Strncpy(prompt, (unset || !new) ? dPROMPT : new);
init_prompt();
} /* set_prompt */
void set_log(char *fname, int unset)
{
if (logf) {
(void) fclose(logf);
logf = NULL;
}
if (!unset && fname) {
(void) Strncpy(logfname, fname);
logf = fopen (LocalDotPath(logfname), "a");
}
} /* set_log */
void set_pager(char *new, int unset)
{
if (unset)
(void) strcpy(pager, "-");
else {
if (!new)
new = dPAGER;
if (!new[0])
(void) Strncpy(pager, "-");
else {
(void) sprintf(pager, "|%s", (*new == '|' ? new + 1 : new));
(void) LocalPath(pager + 1);
}
}
} /* set_pager */
void set_type(char *newtype, int unset)
{
int t = verbose;
verbose = V_QUIET;
if (!connected && t > V_QUIET)
(void) printf("Not connected.\n");
else if (newtype != NULL && !unset)
(void) _settype(newtype);
verbose = t;
} /* set_type */
void set_ldir(char *ldir, int unset)
{
int t = verbose;
char *argv[2];
if (ldir && !unset) {
verbose = V_QUIET;
argv[1] = ldir;
(void) lcd(2, argv);
verbose = t;
}
} /* set_ldir */
#ifdef GATEWAY
void set_gatelogin(char *glogin, int unset)
{
if (unset || !glogin) {
gate_login[0] = gateway[0] = 0;
} else
(void) strcpy(gate_login, glogin);
} /* set_gatelogin */
#endif
struct var *match_var(char *varname)
{
int i, ambig;
struct var *v;
short c;
c = (short) strlen(varname);
for (i=0, v=vars; i<NVARS; i++, v++) {
if (strcmp(v->name, varname) == 0)
return v; /* exact match. */
if (c < v->nmlen) {
if (strncmp(v->name, varname, (size_t) c) == 0) {
/* Now make sure that it only matches one var name. */
if (c >= v[1].nmlen || (i == (NVARS - 1)))
ambig = 0;
else
ambig = !strncmp(v[1].name, varname, (size_t) c);
if (!ambig)
return v;
(void) fprintf(stderr, "%s: ambiguous variable name.\n", varname);
goto xx;
}
}
}
(void) fprintf(stderr, "%s: unknown variable.\n", varname);
xx:
return ((struct var *)0);
} /* match_var */
void show_var(struct var *v)
{
int c;
if (v != (struct var *)0) {
(void) printf("%-20s= ", v->name);
c = v->type;
if (c < 0) c = -c;
if (v->conn_required && !connected)
(void) printf("(not connected)\n");
else switch (c) {
case INT:
(void) printf("%d\n", *(int *)v->var); break;
case LONG:
(void) printf("%ld\n", *(long *)v->var); break;
case STR:
(void) printf("\"%s\"\n", (char *)v->var); break;
case BOOL:
(void) printf("%s\n", *(int *)v->var == 0 ? "no" : "yes");
}
}
} /* show_var */
void show(char *varname)
{
int i;
struct var *v;
if ((varname == NULL) /* (Denotes show all vars) */
|| (strcmp("all", varname) == 0))
{
for (i=0; i<NVARS; i++)
show_var(&vars[i]);
} else {
if ((v = match_var(varname)) != (struct var *)0)
show_var(v);
}
} /* show */
int do_show(int argc, char **argv)
{
int i;
if (argc < 2)
show(NULL);
else
for (i=1; i<argc; i++)
show(argv[i]);
return NOERR;
} /* do_show */
int set(int argc, char **argv)
{
int unset;
struct var *v;
char *var, *val = NULL;
if (argc < 2 || strncmp(argv[1], "all", (size_t)3) == 0) {
show(NULL); /* show all variables. */
} else {
unset = argv[0][0] == 'u';
var = argv[1];
if (argc > 2) {
/* could be '= value' or just 'value.' */
if (*argv[2] == '=') {
if (argc > 3)
val = argv[3];
else return USAGE; /* can't do 'set var =' */
} else
val = argv[2];
if (val[0] == 0)
val = NULL;
}
v = match_var(var);
if (v != NULL) {
if (v->conn_required && !connected)
(void) fprintf(stderr, "%s: must be connected.\n", var);
else if (v->type < 0)
(void) fprintf(stderr, "%s: read-only variable.\n", var);
else if (v->proc != (setvarproc) 0) {
(*v->proc)(val, unset); /* a custom set proc. */
} else if (unset) switch(v->type) {
case BOOL:
case INT:
*(int *) v->var = 0; break;
case LONG:
*(long *) v->var = 0; break;
case STR:
*(char *) v->var = 0; break;
} else {
if (val == NULL) switch(v->type) {
/* User just said "set varname" */
case BOOL:
case INT:
*(int *) v->var = 1; break;
case LONG:
*(long *) v->var = 1; break;
case STR:
*(char *) v->var = 0; break;
} else {
/* User said "set varname = value" */
switch (v->type) {
case BOOL:
*(int *)v->var = StrToBool(val); break;
case INT:
(void) sscanf(val, "%d", (int *) v->var); break;
case LONG:
(void) sscanf(val, "%ld", (long *) v->var); break;
case STR:
(void) strcpy(v->var, val); break;
}
}
}
}
}
return NOERR;
} /* set */
/* eof Set.c */

View File

@ -1,46 +0,0 @@
/* Set.h */
#ifndef _set_h_
#define _set_h_
/* $RCSfile: set.h,v $
* $Revision: 14020.11 $
* $Date: 93/06/26 06:21:32 $
*/
/* Variable types. */
#define INT 1
#define LONG 2
#define STR 3
#define BOOL 4
typedef void (*setvarproc)(char *, int);
struct var {
char *name;
short nmlen;
short type;
short conn_required;
void *var;
setvarproc proc;
};
#define VARENTRY(n,t,c,v,p) { (n), (short)(sizeof(n) - 1), (t), (c), (v), (setvarproc)(p) }
#define NVARS ((int) (sizeof(vars)/sizeof(struct var)))
void set_prompt(char *new, int unset);
void set_log(char *fname, int unset);
void set_ldir(char *ldir, int unset);
#ifdef GATEWAY
void set_gateway(char *, int);
void set_gatelogin(char *, int);
#endif
void set_pager(char *new, int unset);
void set_verbose(char *new, int unset);
void set_type(char *newtype, int unset);
struct var *match_var(char *varname);
void show_var(struct var *v);
void show(char *varname);
int do_show(int argc, char **argv);
int set(int argc, char **argv);
#endif /* _set_h_ */

View File

@ -1,636 +0,0 @@
/* Sys.h
* See the README for details.
*/
/* $RCSfile: sys.h,v $
* $Revision: 14020.13 $
* $Date: 93/06/21 06:42:11 $
*/
#ifdef __sun
# ifndef sun
# define sun 1
# endif
#endif
#ifdef sun
# if !defined(__GNUC__) && !defined(__STDC__) && !defined(SunOverride)
/* If you choke here, but you know what you're doing, just
* define SunOverride.
*/
^^^ "You need to use an ANSI C compiler. Try using gcc or acc." ^^^
# endif
# ifdef Solaris /* not predefined. */
# ifndef SYSV
# define SYSV 1
# endif
# define System "Solaris"
# else
# define System "SunOS"
# ifndef RINDEX
# define RINDEX 1
# endif
# endif /* not Solaris */
# ifndef TERMIOS
# define TERMIOS 1
# endif
# ifndef HAS_DOMAINNAME
# define HAS_DOMAINNAME 1
# endif
#endif /* sun */
#ifdef __sgi
# ifndef sgi
# define sgi 1
# endif
#endif
#ifdef sgi
# define System "IRIX"
# ifndef SYSV
# define SYSV 1
# endif
# ifndef HERROR
# define HERROR 1
# endif
# ifndef U_WAIT
# define U_WAIT 1
# endif
# ifndef STRICT_PROTOS
# define STRICT_PROTOS 1
# endif
# ifndef TERMIOS
# define TERMIOS 1
# endif
#endif /* sgi */
#ifdef AIX
# define System "AIX 2.2.1"
# define BSD_INCLUDES
# define SYSV
# define NO_STDLIB
# define NO_UTIME_H
# define NO_STRFTIME
# define NO_STRSTR
# define NO_MKTIME
#endif /* AIX */
#ifdef _AIX
# define System "AIX 3.x"
# define SYSSELECTH 1
# define TERMIOS 1
#endif /* _AIX */
#ifdef __QNX__
# define QNX
# define System "QNX 4.21 (POSIX)"
# define SYSSELECTH
# define TERMIOS
# define _POSIX_SOURCE
# define GETCWDSIZET
# define STRICT_PROTOS
# define RINDEX
# define NO_CURSES_H
# define unlink remove
# define bcopy(s,d,l) memcpy((d),(s),(l))
# define bzero(cp,l) memset((cp),0,(l))
# define NO_SYSPARAM
# include <limits.h>
# define NCARGS _POSIX_ARG_MAX
#endif
#ifdef SCOXNX
# define System "SCO Xenix"
# define LAI_TCP
# define NO_UTIMEH
# define NO_MKTIME
# define NO_STRFTIME
# define NO_STRSTR
# define NO_RENAME
# define LINGER /* else SCO bug causes incomplete transfers */
# define SYSV 1
#endif /* SCOXNX */
#ifdef SCO322
# define System "SCO Unix 3.2v2"
# define BOTCHED_FOPEN_RW
# define NO_RENAME /* it exists, but it corrupts filesystems */
# define BROKEN_MEMCPY 1
# define SYSV 1
#endif /* SCO322 */
#ifdef SCO324
# define System "SCO Unix 3.2v4"
# ifndef SYSV
# define SYSV 1
# endif
# ifndef BROKEN_MEMCPY
# define BROKEN_MEMCPY 1
# endif
#endif /* SCO324 */
#ifdef linux
# define System "Linux"
# ifndef HAS_DOMAINNAME
# define HAS_DOMAINNAME 1
# endif
# ifndef TERMIOS
# define TERMIOS 1
# endif
# ifndef SYSV
# define SYSV 1
# endif
#endif
#ifdef ISC
# define System "Interactive Unix"
# ifndef SYSV
# define SYSV 1
# endif
# ifndef BROKEN_MEMCPY
# define BROKEN_MEMCPY 1
# endif
# ifndef NET_ERRNO_H
# define NET_ERRNO_H 1
# endif
#endif /* ISC */
#ifdef aux
# define System "A/UX"
# ifndef BROKEN_MEMCPY
# define BROKEN_MEMCPY 1
# endif
# ifndef SYSV
# define SYSV 1
# endif
#endif
#ifdef NeXT
# define System "NeXTStep"
# ifndef RINDEX
# define RINDEX 1
# endif
# ifndef BSD
# define BSD 1
# endif
# ifndef NO_UNISTDH
# define NO_UNISTDH 1
# endif
# ifndef NO_UTIMEH
# define NO_UTIMEH
# endif
# ifndef HAS_DOMAINNAME
# define HAS_DOMAINNAME 1
# endif
#endif
#ifdef pyr
# define System "OSx"
# ifndef BSD
# define BSD 1
# endif
# ifndef SGTTYB
# define SGTTYB 1
# endif
# ifndef NO_STDLIBH
# define NO_STDLIBH 1
# endif
extern int errno;
#endif /* pyr */
#ifdef _SEQUENT_
# if !defined(DYNIXPTX) && !defined(DYNIX)
# define DYNIXPTX 1
# endif
#endif
#if DYNIXPTX
# define System "Dynix/PTX"
# ifndef SYSV
# define SYSV 1
# endif
# ifndef TRY_NOREPLY
# define TRY_NOREPLY 1
# endif
# define gettimeofday(a, b) get_process_stats(a, getpid(), 0, 0)
#endif /* DYNIXPTX */
#ifdef DYNIX
# define System "Dynix"
# ifndef BSD
# define BSD 1
# endif
# ifndef SGTTYB
# define SGTTYB 1
# endif
# ifndef NO_UTIMEH
# define NO_UTIMEH 1
# endif
# ifndef NO_STDLIBH
# define NO_STDLIBH 1
# endif
# ifndef NO_VARARGS
# define NO_VARARGS 1
# endif
#endif /* DYNIX */
#ifdef ultrix
# define System "Ultrix"
# ifndef BSD
# define BSD 1
# endif
# ifndef USE_GETPWUID
# define USE_GETPWUID 1
# endif
# ifndef __GNUC__
# ifndef NO_CONST
# define NO_CONST 1
# endif
# endif
#endif /* ultrix */
#ifdef __hpux
# ifndef HPUX
# define HPUX 1
# endif
# define Select(a,b,c,d,e) select((a), (int *)(b), (c), (d), (e))
#endif
#ifdef HPUX
# define System "HP-UX"
# ifndef _HPUX_SOURCE
# define _HPUX_SOURCE 1
# endif
# ifndef GETCWDSIZET
# define GETCWDSIZET 1
# endif
# define SYSV 1
#endif /* HPUX */
#ifdef SINIX
# define System "SINIX"
# ifndef SYSV
# define SYSV 1
# endif
/* You may need to add -lresolv, -lport, -lcurses to MORELIBS in Makefile. */
#endif
#ifdef BULL /* added 23nov92 for Bull DPX/2 */
# define _POSIX_SOURCE
# define _XOPEN_SOURCE
# define _BULL_SOURCE
# ifndef SYSV
# define SYSV 1
# endif
# define bull
# define System "Bull DPX/2 BOS"
# define SYSSELECTH
#endif /* BULL */ /* added 23nov92 for Bull DPX/2 */
#ifdef __dgux
# ifndef DGUX
# define DGUX 1
# endif
#endif
#ifdef DGUX
# ifndef _DGUX_SOURCE
# define _DGUX_SOURCE
# endif
# define GETCWDSIZET 1
# define BAD_INETADDR 1
# define SYSV 1
# define System "DG/UX"
#endif /* DGUX */
#ifdef apollo
# ifndef BSD
# define BSD 43
# endif
# define NO_UTIMEH 1
# define System "Apollo"
#endif
#ifdef __Besta__
# define SYSV 1
# define SYSSELECTH 1
# define NO_UNISTDH 1
# define NO_STDLIBH 1
# define NO_UTIMEH 1
# ifndef BROKEN_MEMCPY
# define BROKEN_MEMCPY 1
# endif
# include <sys/types.h>
#endif
#ifdef __osf__
# ifdef __alpha /* DEC OSF/1 */
# define GETCWDSIZET 1
# endif
# ifndef System
# define System "DEC OSF/1"
# endif
#endif
#ifdef DELL
# ifndef System
# define System "DELL SVR4 Issue 2.2"
# endif
# ifndef HAS_DOMAINNAME
# define HAS_DOMAINNAME 1
# endif
# ifndef LINGER
# define LINGER /* SVR4/386 Streams TCP/IP bug on close */
# endif
#endif /* DELL */
/* -------------------------------------------------------------------- */
#ifdef _SYSV
# ifndef SYSV
# define SYSV 1
# endif
#endif
#ifdef USG
# ifndef SYSV
# define SYSV 1
# endif
#endif
#ifdef _BSD
# ifndef BSD
# define BSD 1
# endif
#endif
#ifdef SVR4
# ifndef System
# define System "System V.4"
# endif
# ifndef SYSV
# define SYSV 1
# endif
# ifndef VOID
# define VOID void
# endif
# ifndef HERROR
# define HERROR 1
# endif
# ifdef TERMH
# define TERMH 1
# endif
# ifndef Gettimeofday
# define Gettimeofday gettimeofday
# endif
#endif /* SVR4 */
#ifdef SYSV
# ifndef RINDEX
# define RINDEX 1
# endif
# define bcopy(s,d,l) memcpy((d),(s),(l))
# define bzero(cp,l) memset((cp),0,(l))
# ifndef HAS_GETCWD
# define HAS_GETCWD 1
# endif
#endif
#ifdef __bsdi__
# define System "BSDi"
# ifndef BSD
# define BSD 1
# endif
# ifndef SYSSELECTH
# define SYSSELECTH 1
# endif
# ifndef GETCWDSIZET
# define GETCWDSIZET 1
# endif
# ifndef HERROR
# define HERROR 1
# endif
#endif /* BSDi */
#ifdef __FreeBSD__
# define System "FreeBSD"
# define GZCAT "/usr/bin/gzcat"
# define HAS_DOMAINNAME 1
# include <sys/types.h>
# include <sys/param.h> /* this two for BSD definition */
/* to avoid redefinition of it to 1 */
# define HERROR 1
# define TERMIOS 1
# define HAS_GETCWD 1
# define U_WAIT 1
#endif
#ifdef __NetBSD__
# define System "NetBSD"
# define GZCAT "/usr/bin/zcat"
# define HERROR 1
# define TERMIOS 1
# define HAS_GETCWD 1
# define HAS_DOMAINNAME 1
# define U_WAIT 1
# define GETCWDSIZET 1
# define NO_CONST 1 /* avoid prototype conflict */
# include <sys/types.h>
# include <sys/param.h>
#endif
#ifdef BSD
# ifndef __FreeBSD__
# ifndef SYSDIRH
# define SYSDIRH 1
# endif
# endif
# ifndef SGTTYB
# define SGTTYB 1
# endif
#endif
/*
* Generic pointer type, e.g. as returned by malloc().
*/
#ifndef PTRTYPE
# define PTRTYPE void
#endif
#ifndef Free
# define Free(a) free((PTRTYPE *)(a))
#endif
/*
* Some systems besides System V don't use rindex/index (like SunOS).
* Add -DRINDEX to your SDEFS line if you need to.
*/
#ifdef RINDEX
/* or #include <strings.h> if you have it. */
# define rindex strrchr
# define index strchr
#endif /* RINDEX */
#ifdef SOCKS
#define Getsockname(d,a,l) Rgetsockname((d), (struct sockaddr *)(a), (l))
#else
#ifdef SYSV
# define Getsockname(d,a,l) getsockname((d), (void *)(a), (l))
#else
# define Getsockname(d,a,l) getsockname((d), (struct sockaddr *)(a), (l))
#endif
#endif
#ifndef Select
# define Select(a,b,c,d,e) select((a), (b), (c), (d), (e))
#endif
#ifndef Connect
#ifndef SVR4
# define Connect(a,b,c) (connect((a), (struct sockaddr *)(b), (int)(c)))
# define Bind(a,b,c) (bind((a), (struct sockaddr *)(b), (int)(c)))
# define Accept(a,b,c) (accept((a), (struct sockaddr *)(b), (int *)(c)))
#else /* SVR4 */
# define Connect(a,b,c) (connect((a), (caddr_t)(b), (int)(c)))
# define Bind(a,b,c) (bind((a), (caddr_t)(b), (int)(c)))
# define Accept(a,b,c) (accept((a), (caddr_t)(b), (int *)(c)))
#endif /* SVR4 */
#endif /* Connect */
#ifndef Gettimeofday
# define Gettimeofday(a) gettimeofday(a, (struct timezone *)0)
#endif /* Gettimeofday */
#ifdef GETPASS
# define Getpass getpass
#endif
/* Enable connections through firewall gateways */
#ifndef GATEWAY
# define GATEWAY 1
#endif
#ifdef _POSIX_SOURCE
# define TERMIOS
#endif
/* Include frequently used headers: */
#include <sys/types.h>
#ifndef NO_SYSPARAM
#include <sys/param.h>
#endif
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#ifndef NO_STDLIBH
# include <stdlib.h>
#else
extern PTRTYPE *malloc(size_t);
extern PTRTYPE *calloc(size_t, size_t);
extern PTRTYPE *malloc(size_t);
extern void free(PTRTYPE *);
extern PTRTYPE *realloc(PTRTYPE *, size_t);
extern void exit(int);
#ifdef NO_CONST
extern char *getenv(char *);
extern int atoi(char *);
#else
extern char *getenv(const char *);
extern int atoi(const char *);
#endif
#endif /* NO_STDLIBH */
#ifndef NO_UNISTDH
# include <unistd.h>
#else
char *getlogin (void);
# ifdef NO_CONST
extern char *getenv(char *);
# else
extern char *getenv(const char *);
# endif
#endif /* NO_UNISTDH */
#ifdef NO_STD_PROTOS
extern int _filbuf(FILE *);
extern int _flsbuf(int, FILE *);
extern int fflush(FILE *);
extern int fgetc(FILE *);
extern int fprintf(FILE *, char *, ...);
extern int fputc(int, FILE *);
extern int fputs(char *, FILE *);
extern int fclose(FILE *);
extern int pclose(FILE *);
extern void perror(char *);
extern int printf(char *, ...);
extern int rewind(FILE *);
extern int sscanf(char *, char *, ...);
extern int vfprintf(FILE *, char *, char *);
extern char * mktemp(char *);
extern int rename(char *, char *);
extern int gettimeofday(struct timeval *, struct timezone *);
extern time_t mktime(struct tm *);
extern int strftime(char *, int, char *, struct tm *);
extern time_t time(time_t *);
extern int tolower(int);
extern int toupper(int);
#ifndef bcopy
extern void bcopy(char *, char *, size_t);
#endif
#ifndef bzero
extern void bzero(char *, size_t);
#endif
#ifdef SOCKS
extern int Raccept(int, struct sockaddr *, int *);
extern int Rbind(int, struct sockaddr *, int, unsigned long);
extern int Rconnect(int, struct sockaddr *, int);
extern int Rlisten(int, int);
extern int Rgetsockname(int, struct sockaddr *, int *);
#else
extern int accept(int, struct sockaddr *, int *);
extern int bind(int, struct sockaddr *, int);
extern int connect(int, struct sockaddr *, int);
extern int listen(int, int);
extern int getsockname(int, struct sockaddr *, int *);
#endif
extern int gethostname(char *, int), getdomainname(char *, int);
#ifndef Select
extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
#endif
extern int send(int, char *, int, int);
extern int setsockopt(int, int, int, char *, int);
extern int shutdown(int, int);
extern int socket(int, int, int);
#endif /* NO_STD_PROTOS */
/* This malloc stuff is mostly for our own use. */
#define LIBC_MALLOC 0
#define FAST_MALLOC 1
#define DEBUG_MALLOC 2
#ifdef LIBMALLOC
# if LIBMALLOC != LIBC_MALLOC
/* Make sure you use -I to use the malloc.h of choice. */
# include <malloc.h>
# endif
#else
# define LIBMALLOC LIBC_MALLOC
#endif
/* End of personal malloc junk. */
/* eof sys.h */

View File

@ -1,150 +0,0 @@
/* tips.c */
/* $RCSfile: tips.c,v $
* $Revision: 14020.11 $
* $Date: 93/05/21 05:44:39 $
*/
#include "sys.h"
#ifndef NO_TIPS
#include "util.h"
/* Make sure that the indentations are spaces, not tabs.
* Try newform -i-4 < tips.c > tips.c.new
*
* Always add new tips right above the last one.
*/
static char *tiplist[] = {
"Have you tried typing 'open' by itself lately?",
"You know what? You're using obselete software. Ask your sysadmin \n\
to upgrade to a version of ncftp numbered 2.2 or higher.",
"If you don't want a .ncrecent file in your home directory, put the \n\
command '#unset recent-list' in your .ncftprc file.",
"pseudo-filename-completion is supported in some commands. To use it,\n\
use a wildcard expression that will match exactly one file. I.e., if you\n\
want to fetch obnoxiouslylongfilename.zip, try 'get obn*.zip.' Note that\n\
you can't use the cd command with this feature (yet).",
"You don't need to type the exact site name with open. If a site is in\n\
your .ncftprc or the recent-file (.ncrecent), just type a unique\n\
abbreviation (substring really). I.e. 'open wuar' if you have the site\n\
wuarchive.wustl.edu in your rc or recent-file.",
"You can put set commands in your .ncftprc, by adding lines such\n\
as '#set local-dir /usr/tmp' to the file, which will be run at startup.",
"Use the .ncftprc file to set variables at startup and to add sites that \n\
need init macros.\n\
Sample .ncftprc:\n\
#set pager \"less -M\"\n\
\n\
machine wuarchive.wustl.edu\n\
macdef init\n\
cd /pub\n\
get README\n\
dir\n\
(blank line to end macro)",
"If you want to keep your .netrc's for ftp and ncftp separate, name\n\
ncftp's rc to .ncftprc.",
"Type 'open' by itself to get a list of the sites in your recent-file and\n\
your .ncftprc. You can then supply '#5' at the prompt, or use 'open #5'\n\
later.",
"Colon-mode is a quick way to get a file from your shell. Try something\n\
like 'ncftp wuarchive.wustl.edu:/pub/README.'",
"The open command accepts several flags. Do a 'help open' for details.",
"Sometimes a directory listing is several screens long and you won't\n\
remember the thing you wanted. Use the 'predir' command to re-view the\n\
listing. The program keeps the copy locally, so you won't have to wait\n\
for the remote server to re-send it to you.",
"Use the 'page' (or 'more') command to view a remote file with your pager.",
"ncftp may be keeping detailed information on everything you transfer.\n\
Run the 'version' command and if you see SYSLOG, your actions are being\n\
recorded on the system log.",
"Try the 'redir' command to re-display the last directory listing (ls,\n\
dir, ls -lrt, etc). 'predir' does the same, only with your pager.",
"This program is pronounced Nik-F-T-P. NCEMRSoft is Nik'-mer-soft.",
#ifdef GETLINE
"NcFTP was compiled with the Getline command-line/history editor! (by\n\
Chris Thewalt <thewalt@ce.berkeley.edu>). To activate it, use the up\n\
and down arrows to scroll through the history, and/or use EMACS-style\n\
commands to edit the line.",
#endif
#ifdef READLINE
"NcFTP was compiled with the GNU Readline command-line/history editor!\n\
To activate it, use the up & down arrows to scroll through the history,\n\
and/or use EMACS-style (or maybe VI-style) commands to edit the line.",
#endif
"You can get the newest version of NcFTP from ftp.cs.unl.edu, in the\n\
/pub/ncftp directory, AFTER business hours.",
"The type of progress-meter that will be used depends if the remote host\n\
supports the SIZE command, and whether your terminal is capable of ANSI\n\
escape codes.",
"To report a bug, mail your message to mgleason@cse.unl.edu. Include the\n\
output of the 'version' command in your message. An easy way to do that\n\
is to compose your message, then do a 'ncftp -H >> msg.'",
"Don't put a site in your .ncftprc unless you want an 'init' macro. The \n\
recent-file saves sites with the last directory you were in, unlike \n\
the rc file, while still letting you use sitename abbreviations.",
"You can use World Wide Web style paths instead of colon-mode paths.\n\
For example, if the colon-mode path was 'ftp.cs.unl.edu:pub/ncftp',\n\
the WWW-style path would be 'ftp://ftp.cs.unl.edu/pub/ncftp'.",
"Sick and tired of these tips? Put '#unset tips' in your .ncftprc."
};
/* Not another dinky header, por favor. */
#define NTIPS ((int) (sizeof(tiplist) / sizeof(char *)))
void PrintTip(void);
extern int fromatty, debug;
int tips = 1;
#endif /* NO_TIPS */
void PrintTip(void)
{
#ifndef NO_TIPS
int cheap_rn, i, tn;
string str;
if (tips && fromatty) {
cheap_rn = (int) getpid() % NTIPS;
if (debug) {
(void) printf("pid: %d; ntips: %d\n", getpid(), NTIPS);
(void) Gets("*** Tip# (-1 == all): ", str, sizeof(str));
tn = atoi(str) - 1;
if (tn == -1)
tn = 0;
if (tn < -1)
for(i=0; i<NTIPS; i++)
(void) printf("Tip: %s\n", tiplist[i]);
else if (tn < NTIPS)
(void) printf("Tip: %s\n", tiplist[tn]);
} else
(void) printf("Tip: %s\n", tiplist[cheap_rn]);
}
#endif /* NO_TIPS */
} /* PrintTip */
/* tips.c */

View File

@ -1,922 +0,0 @@
/* Util.c */
/* $RCSfile: util.c,v $
* $Revision: 14020.13 $
* $Date: 93/05/23 09:38:13 $
*/
#include "sys.h"
#include <errno.h>
#include <ctype.h>
#include <pwd.h>
#ifndef NO_VARARGS
# ifdef NO_STDARGH
# include <varargs.h>
# else
# include <stdarg.h>
# endif
#endif
#ifdef READLINE
# include <readline/readline.h>
#endif /* READLINE */
#ifdef GETLINE
# include <getline.h>
#endif
#include "util.h"
#include "cmds.h"
#include "main.h"
#include "ftp.h"
#include "ftprc.h"
#include "defaults.h"
#include "copyright.h"
/* Util.c globals */
int Opterr = 1; /* if error message should be printed */
int Optind = 1; /* index into parent argv vector */
int Optopt; /* character checked for validity */
char *Optarg; /* argument associated with option */
char *Optplace = EMSG; /* saved position in an arg */
/* Util.c externs */
extern int toatty, fromatty;
extern int verbose, doingInitMacro;
extern string prompt2;
extern char *line, *margv[];
extern int margc;
extern int debug, mprompt, activemcmd;
extern string progname;
extern struct cmd cmdtab[];
extern struct userinfo uinfo;
#ifndef NO_VARARGS
/*VARARGS*/
#ifdef NO_STDARGH
void dbprintf(va_alist)
va_dcl
#else
void dbprintf(char *fmt0, ...)
#endif
{
va_list ap;
char *fmt;
#ifdef NO_STDARGH
va_start(ap);
fmt = va_arg(ap, char *);
#else
va_start(ap, fmt0);
fmt = fmt0;
#endif
if (debug) {
(void) fprintf(DB_STREAM, "#DB# ");
(void) vfprintf(DB_STREAM, fmt, ap);
(void) fflush(DB_STREAM);
}
va_end(ap);
} /* dbprintf */
#endif /* have varargs */
/*
* Concatenate src on the end of dst. The resulting string will have at most
* n-1 characters, not counting the NUL terminator which is always appended
* unlike strncat. The other big difference is that strncpy uses n as the
* max number of characters _appended_, while this routine uses n to limit
* the overall length of dst.
*/
char *_Strncat(char *dst, char *src, register size_t n)
{
register size_t i;
register char *d, *s;
if (n != 0 && ((i = strlen(dst)) < (n - 1))) {
d = dst + i;
s = src;
/* If they specified a maximum of n characters, use n - 1 chars to
* hold the copy, and the last character in the array as a NUL.
* This is the difference between the regular strncpy routine.
* strncpy doesn't guarantee that your new string will have a
* NUL terminator, but this routine does.
*/
for (++i; i<n; i++) {
if ((*d++ = *s++) == 0) {
/* Pad with zeros. */
for (; i<n; i++)
*d++ = 0;
return dst;
}
}
/* If we get here, then we have a full string, with n - 1 characters,
* so now we NUL terminate it and go home.
*/
*d = 0;
}
return (dst);
} /* _Strncat */
/*
* Copy src to dst, truncating or null-padding to always copy n-1 bytes.
* Return dst.
*/
char *_Strncpy(char *dst, char *src, register size_t n)
{
register char *d;
register char *s;
register size_t i;
d = dst;
*d = 0;
if (n != 0) {
s = src;
/* If they specified a maximum of n characters, use n - 1 chars to
* hold the copy, and the last character in the array as a NUL.
* This is the difference between the regular strncpy routine.
* strncpy doesn't guarantee that your new string will have a
* NUL terminator, but this routine does.
*/
for (i=1; i<n; i++) {
if ((*d++ = *s++) == 0) {
/* Pad with zeros. */
for (; i<n; i++)
*d++ = 0;
return dst;
}
}
/* If we get here, then we have a full string, with n - 1 characters,
* so now we NUL terminate it and go home.
*/
*d = 0;
}
return (dst);
} /* _Strncpy */
/* Converts any uppercase characters in the string to lowercase.
* Never would have guessed that, huh?
*/
void StrLCase(char *dst)
{
register char *cp;
for (cp=dst; *cp != '\0'; cp++)
if (isupper((int) *cp))
*cp = (char) tolower(*cp);
}
char *Strpcpy(char *dst, char *src)
{
while ((*dst++ = *src++) != '\0')
;
return (--dst); /* return current value of dst, NOT original value! */
} /* Strpcpy */
/*
* malloc's a copy of oldstr.
*/
char *NewString(char *oldstr)
{
size_t howLong;
char *newstr;
howLong = strlen(oldstr);
if ((newstr = malloc(howLong + 1)) != NULL)
(void) strcpy(newstr, oldstr);
return newstr;
} /* NewString */
void Getopt_Reset(void)
{
Optind = 1;
Optplace = "";
} /* Getopt_Reset */
static char *NextOption(char *ostr)
{
if ((Optopt = (int) *Optplace++) == (int) ':')
return 0;
return index(ostr, Optopt);
}
int Getopt(int nargc, char **nargv, char *ostr)
{
register char *oli; /* Option letter list index */
if (!*Optplace) { /* update scanning pointer */
if (Optind >= nargc || *(Optplace = nargv[Optind]) != '-')
return (EOF);
if (Optplace[1] && *++Optplace == '-') { /* found "--" */
++Optind;
return (EOF);
}
} /* Option letter okay? */
oli = NextOption(ostr);
if (oli == NULL) {
if (!*Optplace)
++Optind;
if (Opterr) {
(void) fprintf(stderr, "%s%s%c\n", *nargv, ": illegal option -- ", Optopt);
return(BADCH);
}
}
if (*++oli != ':') { /* don't need argument */
Optarg = NULL;
if (!*Optplace)
++Optind;
} else { /* need an argument */
if (*Optplace) /* no white space */
Optarg = Optplace;
else if (nargc <= ++Optind) { /* no arg */
Optplace = EMSG;
if (Opterr) {
(void) fprintf(stderr, "%s%s%c\n", *nargv, ": option requires an argument -- ", Optopt);
return(BADCH);
}
} else /* white space */
Optarg = nargv[Optind];
Optplace = EMSG;
++Optind;
}
return (Optopt); /* dump back Option letter */
} /* Getopt */
/*
* Converts an ls date, in either the "Feb 4 1992" or "Jan 16 13:42"
* format to a time_t.
*/
unsigned long UnLSDate(char *dstr)
{
#ifdef NO_MKTIME
return (MDTM_UNKNOWN);
#else
char *cp = dstr;
int mon, day, year, hr, min;
time_t now, mt;
unsigned long result = MDTM_UNKNOWN;
struct tm ut, *t;
switch (*cp++) {
case 'A':
mon = (*cp == 'u') ? 7 : 3;
break;
case 'D':
mon = 11;
break;
case 'F':
mon = 1;
break;
default: /* shut up un-init warning */
case 'J':
if (*cp++ == 'u')
mon = (*cp == 'l') ? 6 : 5;
else
mon = 0;
break;
case 'M':
mon = (*++cp == 'r') ? 2 : 4;
break;
case 'N':
mon = 10;
break;
case 'O':
mon = 9;
break;
case 'S':
mon = 8;
}
cp = dstr + 4;
day = 0;
if (*cp != ' ')
day = 10 * (*cp - '0');
cp++;
day += *cp++ - '0';
min = 0;
(void) time(&now);
t = localtime(&now);
if (*++cp != ' ') {
/* It's a time, XX:YY, not a year. */
cp[2] = ' ';
(void) sscanf(cp, "%d %d", &hr, &min);
cp[2] = ':';
year = t->tm_year;
if (mon > t->tm_mon)
--year;
} else {
hr = min = 0;
(void) sscanf(cp, "%d", &year);
year -= 1900;
}
/* Copy the whole structure of the 'tm' pointed to by t, so it will
* also set all fields we don't specify explicitly to be the same as
* they were in t. That way we copy non-standard fields such as
* tm_gmtoff, if it exists or not.
*/
ut = *t;
ut.tm_sec = 1;
ut.tm_min = min;
ut.tm_hour = hr;
ut.tm_mday = day;
ut.tm_mon = mon;
ut.tm_year = year;
ut.tm_wday = ut.tm_yday = 0;
mt = mktime(&ut);
if (mt != (time_t) -1)
result = (unsigned long) mt;
return (result);
#endif /* NO_MKTIME */
} /* UnLSDate */
/*
* Converts a MDTM date, like "213 19930602204445\n"
* format to a time_t.
*/
unsigned long UnMDTMDate(char *dstr)
{
#ifdef NO_MKTIME
return (MDTM_UNKNOWN);
#else
struct tm ut;
time_t mt;
unsigned long result = MDTM_UNKNOWN;
/* Clear out the whole structure, along with any non-standard fields. */
bzero((char *)&ut, sizeof (struct tm));
if (sscanf(dstr, "%*s %04d%02d%02d%02d%02d%02d",
&ut.tm_year,
&ut.tm_mon,
&ut.tm_mday,
&ut.tm_hour,
&ut.tm_min,
&ut.tm_sec) == 6)
{
--ut.tm_mon;
ut.tm_year -= 1900;
mt = mktime(&ut);
if (mt != (time_t) -1)
result = (unsigned long) mt;
}
return result;
#endif /* NO_MKTIME */
} /* UnMDTMDate */
void Perror(
#ifdef DB_ERRS
char *fromProc
,
#ifdef __LINE__
int lineNum,
#endif
#endif
char *msg
)
{
extern int errno;
if (NOT_VQUIET) {
#ifdef sun
/*
* There is a problem in the SunOS headers when compiling with an ANSI
* compiler. The problem is that there are macros in the form of
* #define MAC(x) 'x', and this will always be the character x instead
* of whatever parameter was passed to MAC. If we get these errors, it
* usually means that you are trying to compile with gcc when you haven't
* run the 'fixincludes' script that fixes these macros. We will ignore
* the error, but it means that the echo() function won't work correctly,
* and you will see your password echo.
*/
if (errno == ENOTTY)
return;
#endif
(void) fprintf(stderr, "NcFTP");
#ifdef DB_ERRS
if (fromProc != NULL)
(void) fprintf(stderr, "/%s", fromProc);
#ifdef __LINE__
(void) fprintf(stderr, "/%d", lineNum);
#endif
#endif
(void) fprintf(stderr, ": ");
if (msg != NULL)
(void) fprintf(stderr, "%s (%d): ", msg, errno);
perror(NULL);
}
} /* Perror */
size_t RemoveTrailingNewline(char *cp, int *stripped)
{
size_t len;
int nBytesStripped = 0;
if (cp != NULL) {
cp += (len = strlen(cp)) - 1;
if (*cp == '\n') {
*cp-- = 0; /* get rid of the newline. */
nBytesStripped++;
}
if (*cp == '\r') { /* no returns either, please. */
*cp = 0;
nBytesStripped++;
}
if (stripped != NULL)
*stripped = nBytesStripped;
return len;
}
return (size_t)0;
} /* RemoveTrailingNewline */
#ifdef GETLINE
extern size_t epromptlen;
/*
* The Getline library doesn't detect the ANSI escape sequences, so the
* library would think that a string is longer than actually appears on
* screen. This function lets Getline work properly. This function is
* intended to fix that problem for the main command prompt only. If any
* other prompts want to use ANSI escapes, a (costly) function would have
* to scan the prompt for all escape sequences.
*/
/*ARGSUSED*/
static size_t MainPromptLen(char *pr)
{
return (int)epromptlen;
}
#endif
static char *StdioGets(char *promptstr, char *sline, size_t size)
{
char *cp;
if (fromatty) {
/* It's okay to print a prompt if we are redirecting stdout,
* as long as stdin is still a tty. Otherwise, don't print
* a prompt at all if stdin is redirected.
*/
#ifdef CURSES
tcap_put(promptstr);
#else
(void) fputs(promptstr, stdout);
#endif
}
sline[0] = 0;
(void) fflush(stdout); /* for svr4 */
cp = fgets(sline, (int)(size - 2), stdin);
(void) RemoveTrailingNewline(sline, NULL);
return cp;
} /* StdioGets */
/* Given a prompt string, a destination string, and it's size, return feedback
* from the user in the destination string, with any trailing newlines
* stripped. Returns NULL if EOF encountered.
*/
char *Gets(char *promptstr, char *sline, size_t size)
{
char *cp, ch;
string plines;
#ifdef GETLINE
int ismainprompt = (promptstr == prompt2);
#endif
if (!fromatty || !toatty) {
/* Don't worry about a cmdline/history editor if you redirected a
* file at me.
*/
return (StdioGets(promptstr, sline, size));
}
sline[0] = 0; /* Clear it, in case of an error later. */
/*
* The prompt string may actually be several lines if the user put a
* newline in it with the @N option. In this case we only want to print
* the very last line, so the command-line editors won't screw up. So
* now we print all the lines except the last line.
*/
cp = rindex(promptstr, '\n');
if (cp != NULL) {
ch = *++cp;
*cp = 0;
(void) Strncpy(plines, promptstr);
*cp = ch;
promptstr = cp;
#ifdef CURSES
tcap_put(plines);
#else
(void) fputs(plines, stdout);
#endif
}
#ifdef READLINE
if ((cp = readline(promptstr)) != NULL) {
(void) _Strncpy(sline, cp, size);
free(cp);
(void) RemoveTrailingNewline(cp = sline, NULL);
if (*cp != 0) /* Don't add blank lines to history buffer. */
add_history(cp);
}
#else /* READLINE */
#ifdef GETLINE
if (toatty) {
if (ismainprompt)
gl_strwidth(MainPromptLen);
if ((cp = getline(promptstr)) != NULL) {
if (*cp == '\0') /* You hit ^D. */
return NULL;
cp = _Strncpy(sline, cp, size);
(void) RemoveTrailingNewline(cp, NULL);
if (*cp != '\0') { /* Don't add blank lines to history buffer. */
gl_histadd(cp);
}
}
/* Hope your strlen is declared as returning a size_t. */
gl_strwidth(strlen);
} else {
cp = StdioGets(promptstr, sline, size);
}
#else /* !GETLINE */
cp = StdioGets(promptstr, sline, size);
#endif /* !GETLINE */
#endif /* !READLINE */
return cp;
} /* Gets */
char **re_makeargv(char *promptstr, int *argc)
{
size_t sz;
(void) strcat(line, " ");
sz = strlen(line);
(void) Gets(promptstr, &line[sz], (size_t) (CMDLINELEN - sz)) ;
(void) makeargv();
*argc = margc;
return (margv);
} /* re_makeargv */
#ifndef HAS_GETCWD
extern char *getwd(char *);
#endif
char *get_cwd(char *buf, int size)
{
#ifdef HAS_GETCWD
# ifdef NO_UNISTDH
# ifdef GETCWDSIZET
extern char *getcwd(char *, size_t);
# else
extern char *getcwd(char *, int);
# endif
# endif
return (getcwd(buf, size - 1));
#else
#ifndef MAXPATHLEN
# define MAXPATHLEN (1024)
#endif
static char *cwdbuf = NULL;
if (cwdbuf == NULL) {
cwdbuf = (char *)malloc((size_t) MAXPATHLEN);
if (cwdbuf == NULL)
fatal("out of memory for getwd buffer.");
}
getwd(cwdbuf);
return (_Strncpy(buf, cwdbuf, (size_t)size));
#endif
} /* get_cwd */
int tmp_name(char *str)
{
(void) strcpy(str, "/tmp/ncftpXXXXXX");
return (!mktemp(str));
} /* tmp_name */
char *onoff(int boolf)
{
return (boolf ? "on" : "off");
} /* onoff */
int StrToBool(char *s)
{
int c;
int result;
c = tolower(*s);
result = 0;
switch (c) {
case 'f': /* false */
case 'n': /* no */
break;
case 'o': /* test for "off" and "on" */
c = tolower(s[1]);
if (c == 'f')
break;
/* fall through */
case 't': /* true */
case 'y': /* yes */
result = 1;
break;
default: /* 1, 0, -1, other number? */
if (atoi(s) != 0)
result = 1;
}
return result;
} /* StrToBool */
int confirm(char *cmd, char *file)
{
string str, pr;
if (!fromatty || (activemcmd && !mprompt) || (doingInitMacro))
return 1;
(void) sprintf(pr, "%s %s? ", cmd, file);
(void) Gets(pr, str, sizeof(str));
return (*str != 'n' && *str != 'N');
} /* confirm */
void fatal(char *msg)
{
(void) fprintf(stderr, "%s: %s\n", progname, msg);
close_up_shop();
exit(1);
} /* fatal */
int UserLoggedIn(void)
{
static int inited = 0;
static int parent_pid, stderr_was_tty;
if (!inited) {
stderr_was_tty = isatty(2);
parent_pid = getppid();
inited++;
}
if ((stderr_was_tty && !isatty(2)) || (getppid() != parent_pid))
return 0;
return 1;
} /* UserLoggedIn */
struct cmd *getcmd(char *name)
{
struct cmd *c, *found;
int nmatches;
size_t len;
char *p;
found = (struct cmd *)0;
if (name != NULL) {
len = strlen(name);
nmatches = 0;
for (c = cmdtab; (p = c->c_name) != NULL; c++) {
if (strcmp(name, p) == 0) {
/* Exact match. */
found = c;
goto xx;
}
if (c->c_handler == unimpl)
continue;
if (strncmp(name, p, len) == 0) {
if (++nmatches > 1) {
found = ((struct cmd *) -1);
goto xx;
}
found = c;
} else if (found != NULL)
break;
}
}
xx:
return (found);
} /* getcmd */
void cmd_help(struct cmd *c)
{
(void) printf("%s: %s.\n",
c->c_name,
c->c_help
);
} /* cmd_help */
void cmd_usage(struct cmd *c)
{
if (c->c_usage != NULL)
(void) printf("Usage: %s%s\n",
c->c_name,
c->c_usage
);
} /* cmd_usage */
/*
* A simple function that translates most pathnames with ~, ~user, or
* environment variables as the first item. It won't do paths with env vars
* or ~s in the middle of the path, but those are extremely rare.
*/
char *LocalPath(char *path)
{
longstring orig;
struct passwd *pw;
char *firstent;
char *cp, *dp, *rest;
(void) Strncpy(orig, path);
firstent = orig;
if ((cp = index(orig, '/')) != NULL) {
if (cp == orig) {
/* If we got here, the path is actually a full path name,
* with the first character as a slash, so just leave it
* alone.
*/
return (path);
}
/* Otherwise we can look at the first word of the path, and
* try to expand it, like $HOME/ or ~/, or it is a relative path,
* which is okay since we won't really do anything with it.
*/
*cp = 0;
rest = cp + 1;
/* 'firstent' now contains the first 'word' in the path. */
} else {
/* Path was just a single word, or it is a full path, like:
* /usr/tmp/zz, so firstent is just the entire given "path."
*/
rest = NULL;
}
if (orig[0] == '~') {
if (orig[1] == 0) {
firstent = uinfo.homedir;
} else {
pw = getpwnam(orig + 1);
if (pw != NULL)
firstent = pw->pw_dir;
}
} else if (orig[0] == '$') {
cp = orig + 1;
dp = orig + strlen(orig) - 1;
if ((*cp == '(' && *dp == ')') || (*cp == '{' && *dp == '}')) {
cp++;
*dp = 0;
}
firstent = getenv(cp);
if (firstent == NULL) {
(void) fprintf(stderr, "%s: no such environment variable.\n", cp);
firstent = "badEnvVar";
}
}
if (rest == NULL)
(void) strcpy(path, firstent);
else
(void) sprintf(path, "%s/%s", firstent, rest);
return (path);
} /* LocalPath */
/*
* A special case, where invisible dot-files that would normally appear in
* your home directory will appear instead as visible files in your $DOTDIR
* directory if you have one.
*/
#define LCMP(b) (strncmp(path, (b), (o = sizeof(b) - 1)) == 0)
char *LocalDotPath(char *path)
{
size_t o;
longstring s, s2;
char *cp = getenv("DOTDIR");
if (cp == NULL) {
goto aa;
} else {
if (*cp != '/' && *cp != '~') {
/* then maybe they mean relative to $HOME. */
(void) sprintf(s2, "%s/%s", uinfo.homedir, cp);
cp = s2;
}
if (LCMP("~/.") ||
LCMP("$HOME/.") ||
LCMP("$home/.") ||
LCMP("$(HOME)/.") ||
LCMP("${HOME}/.")
) {
(void) Strncpy(s, path);
(void) sprintf(path, "%s/%s", cp, s + o);
cp = path;
} else {
aa: cp = LocalPath(path);
}
}
return cp;
} /* LocalDotPath */
#ifdef NO_STRSTR
/*
* The Elm Mail System - $Revision: 5.1 $ $State: Exp $
*
* Copyright (c) 1988-1992 USENET Community Trust
* Copyright (c) 1986,1987 Dave Taylor
*/
char *strstr(s1, s2)
char *s1, *s2;
{
int len;
char *ptr;
char *tmpptr;
ptr = NULL;
len = strlen(s2);
if ( len <= strlen(s1)) {
tmpptr = s1;
while ((ptr = index(tmpptr, (int)*s2)) != NULL) {
if (strncmp(ptr, s2, len) == 0) {
break;
}
tmpptr = ptr+1;
}
}
return (ptr);
}
#endif
#ifdef NO_RENAME
int rename(oldname, newname)
const char *oldname, *newname;
{
return (link(oldname, newname) == 0 ? unlink(oldname) : -1);
}
#endif /*NO_RENAME*/
/* eof Util.c */

View File

@ -1,104 +0,0 @@
/* Util.h */
#ifndef _util_h_
#define _util_h_
/* $RCSfile: util.h,v $
* $Revision: 14020.12 $
* $Date: 93/07/09 11:32:49 $
*/
typedef char string[128], str32[32], longstring[512];
typedef char Hostname[64];
/* For Perror. */
#ifdef DB_ERRS
# ifdef __LINE__
# define PERROR(p,e) Perror(p, __LINE__, e)
void Perror(char *, int, char *);
# else
# define PERROR(p,e) Perror(p, e)
void Perror(char *, char *);
# endif
#else
# define PERROR(p,e) Perror(e)
void Perror(char *);
#endif
#ifdef NO_VARARGS
extern int debug;
# define dbprintf if (debug) (void) printf
#else
# ifndef DB_STREAM
# define DB_STREAM stdout
# endif
#ifndef NO_STDARGH
void dbprintf(char *fmt0, ...);
#else
void dbprintf(int va_alist);
#endif
#endif
/* For 'Getopt.' */
#define BADCH ((int)'?')
#define EMSG ""
/* Handy macros. */
#define Strncpy(d,s) _Strncpy((char *) (d), (char *) (s), (size_t) sizeof(d))
#define Strncat(d,s) _Strncat((char *) (d), (char *) (s), (size_t) sizeof(d))
#define FGets(a,b) fgets((a), (int) (sizeof(a) - 2), (b))
#ifndef NO_CONST
typedef int (*cmp_t)(const void *, const void *);
#else
typedef int (*cmp_t)(void *, void *);
#endif
#define QSort(base,n,sz,cmp) \
qsort(base, (size_t)(n), (size_t)(sz), (cmp_t)(cmp))
#ifndef SIG_PARAMS
#define SIG_PARAMS (int sig)
#endif
typedef void (*Sig_t) SIG_PARAMS;
#define Signal(a,proc) signal((a), (Sig_t)(proc))
/* Quiets warnings */
#if defined(sun) /* ...actually, any UNIX system */
# if defined(__GNUC__)
# undef SIG_DFL
# undef SIG_IGN
# define SIG_DFL (Sig_t)0
# define SIG_IGN (Sig_t)1
# endif
#endif
/* Protos. */
char *_Strncat(char *dst, char *src, register size_t n);
char *_Strncpy(char *dst, char *src, register size_t n);
void StrLCase(char *dst);
char *NewString(char *oldstr);
char **re_makeargv(char *promptstr, int *argc);
char *onoff(int);
int StrToBool(char *s);
int confirm(char *cmd, char *file);
void fatal(char *msg);
char *get_cwd(char *buf, int size);
int tmp_name(char *str);
int Getopt(int argc, char **argv, char *opstring);
void Getopt_Reset(void);
char *Gets(char *promptstr, char *sline, size_t size);
size_t RemoveTrailingNewline(char *cp, int *stripped);
unsigned long UnLSDate(char *dstr);
unsigned long UnMDTMDate(char *dstr);
char *Strpcpy(char *dst, char *src);
int UserLoggedIn(void);
char *LocalPath(char *path);
char *LocalDotPath(char *path);
#ifdef NO_STRSTR
char *strstr(char *s1, char *s2);
#endif
#endif /* _util_h_ */