summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile28
-rw-r--r--src/Makefile.am52
-rw-r--r--src/Makefile.in828
-rw-r--r--src/cmds.c500
-rw-r--r--src/cmdtab.c29
-rw-r--r--src/complete.c76
-rw-r--r--src/domacro.c17
-rw-r--r--src/extern.h45
-rw-r--r--src/fetch.c651
-rw-r--r--src/ftp.1357
-rw-r--r--src/ftp.c686
-rw-r--r--src/ftp.cat11055
-rw-r--r--src/ftp_var.h60
-rw-r--r--src/main.c233
-rw-r--r--src/progressbar.c103
-rw-r--r--src/progressbar.h23
-rw-r--r--src/ruserpass.c84
-rw-r--r--src/util.c662
-rw-r--r--src/version.h15
19 files changed, 2829 insertions, 2675 deletions
diff --git a/src/Makefile b/src/Makefile
deleted file mode 100644
index 79cc5a6060d42..0000000000000
--- a/src/Makefile
+++ /dev/null
@@ -1,28 +0,0 @@
-# $NetBSD: Makefile,v 1.30 2005/02/11 15:13:28 jmc Exp $
-# from: @(#)Makefile 8.2 (Berkeley) 4/3/94
-
-.include <bsd.own.mk>
-
-PROG= ftp
-SRCS= cmds.c cmdtab.c complete.c domacro.c fetch.c ftp.c main.c \
- progressbar.c ruserpass.c util.c
-
-# Uncomment the following to provide defaults for gate-ftp operation
-#
-#CPPFLAGS+=-DGATE_SERVER=\"ftp-gw.host\" # -DGATE_PORT=21
-
-.if defined(SMALLPROG)
-CPPFLAGS+=-DNO_EDITCOMPLETE -DNO_ABOUT -DNO_AUTH -DNO_HELP -DNO_STATUS
-.else
-LDADD+= -ledit -ltermcap
-DPADD+= ${LIBEDIT} ${LIBTERMCAP}
-.endif
-
-.if (!defined(SMALLPROG) || defined(SMALLPROG_INET6)) && (${USE_INET6} != "no")
-CPPFLAGS+= -DINET6
-.endif
-
-cmds.o fetch.o: version.h
-main.o: ftp_var.h
-
-.include <bsd.prog.mk>
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000000000..8ac32f98fe241
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,52 @@
+## $NetBSD: Makefile.am,v 1.2 2010/01/04 06:24:20 lukem Exp $
+
+bin_PROGRAMS = tnftp
+
+tnftp_SOURCES = \
+ cmds.c \
+ cmdtab.c \
+ complete.c \
+ domacro.c \
+ fetch.c \
+ ftp.c \
+ main.c \
+ progressbar.c \
+ ruserpass.c \
+ util.c
+
+tnftp_CPPFLAGS = \
+ -DHAVE_TNFTPD_H=1 \
+ -D_DEFAULT_CONFDIR=\"${sysconfdir}\" \
+ -I$(srcdir) \
+ -I$(top_srcdir)/libnetbsd \
+ -I$(top_srcdir) \
+ -I$(top_builddir)
+
+tnftp_LDADD = \
+ ../libnetbsd/libnetbsd.la
+
+
+if USE_LIBEDIT
+tnftp_CPPFLAGS += \
+ -I$(top_srcdir)/libedit
+
+tnftp_LDADD += \
+ ../libedit/libedit.la
+endif
+
+
+man1_MANS = \
+ tnftp.1
+
+tnftp.1: ftp.1
+ cp $(srcdir)/ftp.1 tnftp.1
+
+CLEANFILES = \
+ tnftp.1
+
+EXTRA_DIST = \
+ extern.h \
+ ftp.1 \
+ ftp_var.h \
+ progressbar.h \
+ version.h
diff --git a/src/Makefile.in b/src/Makefile.in
index bb60f1086764e..e11a81add7ef0 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -1,43 +1,809 @@
-#
-# $Id: Makefile.in,v 1.8 2000/08/08 07:04:27 lukem Exp $
-#
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
-srcdir = @srcdir@
-VPATH = @srcdir@
-SHELL = /bin/sh
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
-prefix = @prefix@
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = tnftp$(EXEEXT)
+@USE_LIBEDIT_TRUE@am__append_1 = \
+@USE_LIBEDIT_TRUE@ -I$(top_srcdir)/libedit
+
+@USE_LIBEDIT_TRUE@am__append_2 = \
+@USE_LIBEDIT_TRUE@ ../libedit/libedit.la
+
+subdir = src
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/tnftp_config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_tnftp_OBJECTS = tnftp-cmds.$(OBJEXT) tnftp-cmdtab.$(OBJEXT) \
+ tnftp-complete.$(OBJEXT) tnftp-domacro.$(OBJEXT) \
+ tnftp-fetch.$(OBJEXT) tnftp-ftp.$(OBJEXT) tnftp-main.$(OBJEXT) \
+ tnftp-progressbar.$(OBJEXT) tnftp-ruserpass.$(OBJEXT) \
+ tnftp-util.$(OBJEXT)
+tnftp_OBJECTS = $(am_tnftp_OBJECTS)
+tnftp_DEPENDENCIES = ../libnetbsd/libnetbsd.la $(am__append_2)
+AM_V_lt = $(am__v_lt_$(V))
+am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY))
+am__v_lt_0 = --silent
+DEFAULT_INCLUDES =
+depcomp = $(SHELL) $(top_srcdir)/buildaux/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+AM_V_CC = $(am__v_CC_$(V))
+am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY))
+am__v_CC_0 = @echo " CC " $@;
+AM_V_at = $(am__v_at_$(V))
+am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY))
+am__v_at_0 = @
+CCLD = $(CC)
+LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+AM_V_CCLD = $(am__v_CCLD_$(V))
+am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY))
+am__v_CCLD_0 = @echo " CCLD " $@;
+AM_V_GEN = $(am__v_GEN_$(V))
+am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
+am__v_GEN_0 = @echo " GEN " $@;
+SOURCES = $(tnftp_SOURCES)
+DIST_SOURCES = $(tnftp_SOURCES)
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+man1dir = $(mandir)/man1
+NROFF = nroff
+MANS = $(man1_MANS)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+ALLOCA = @ALLOCA@
+AMTAR = @AMTAR@
+AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DSYMUTIL = @DSYMUTIL@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NMEDIT = @NMEDIT@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
exec_prefix = @exec_prefix@
-bindir = @bindir@
-mandir = @mandir@
-transform = @program_transform_name@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+tnftp_SOURCES = \
+ cmds.c \
+ cmdtab.c \
+ complete.c \
+ domacro.c \
+ fetch.c \
+ ftp.c \
+ main.c \
+ progressbar.c \
+ ruserpass.c \
+ util.c
+
+tnftp_CPPFLAGS = -DHAVE_TNFTPD_H=1 \
+ -D_DEFAULT_CONFDIR=\"${sysconfdir}\" -I$(srcdir) \
+ -I$(top_srcdir)/libnetbsd -I$(top_srcdir) -I$(top_builddir) \
+ $(am__append_1)
+tnftp_LDADD = ../libnetbsd/libnetbsd.la $(am__append_2)
+man1_MANS = \
+ tnftp.1
+
+CLEANFILES = \
+ tnftp.1
+
+EXTRA_DIST = \
+ extern.h \
+ ftp.1 \
+ ftp_var.h \
+ progressbar.h \
+ version.h
+
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign src/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+ @$(NORMAL_INSTALL)
+ test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed 's/$(EXEEXT)$$//' | \
+ while read p p1; do if test -f $$p || test -f $$p1; \
+ then echo "$$p"; echo "$$p"; else :; fi; \
+ done | \
+ sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+ -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+ sed 'N;N;N;s,\n, ,g' | \
+ $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+ { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+ if ($$2 == $$4) files[d] = files[d] " " $$1; \
+ else { print "f", $$3 "/" $$4, $$1; } } \
+ END { for (d in files) print "f", d, files[d] }' | \
+ while read type dir files; do \
+ if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+ test -z "$$files" || { \
+ echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+ $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+ } \
+ ; done
+
+uninstall-binPROGRAMS:
+ @$(NORMAL_UNINSTALL)
+ @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+ files=`for p in $$list; do echo "$$p"; done | \
+ sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+ -e 's/$$/$(EXEEXT)/' `; \
+ test -n "$$list" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+ @list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+tnftp$(EXEEXT): $(tnftp_OBJECTS) $(tnftp_DEPENDENCIES)
+ @rm -f tnftp$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(tnftp_OBJECTS) $(tnftp_LDADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-cmds.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-cmdtab.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-complete.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-domacro.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-fetch.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-ftp.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-progressbar.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-ruserpass.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnftp-util.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+tnftp-cmds.o: cmds.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-cmds.o -MD -MP -MF $(DEPDIR)/tnftp-cmds.Tpo -c -o tnftp-cmds.o `test -f 'cmds.c' || echo '$(srcdir)/'`cmds.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-cmds.Tpo $(DEPDIR)/tnftp-cmds.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cmds.c' object='tnftp-cmds.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-cmds.o `test -f 'cmds.c' || echo '$(srcdir)/'`cmds.c
+
+tnftp-cmds.obj: cmds.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-cmds.obj -MD -MP -MF $(DEPDIR)/tnftp-cmds.Tpo -c -o tnftp-cmds.obj `if test -f 'cmds.c'; then $(CYGPATH_W) 'cmds.c'; else $(CYGPATH_W) '$(srcdir)/cmds.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-cmds.Tpo $(DEPDIR)/tnftp-cmds.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cmds.c' object='tnftp-cmds.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-cmds.obj `if test -f 'cmds.c'; then $(CYGPATH_W) 'cmds.c'; else $(CYGPATH_W) '$(srcdir)/cmds.c'; fi`
+
+tnftp-cmdtab.o: cmdtab.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-cmdtab.o -MD -MP -MF $(DEPDIR)/tnftp-cmdtab.Tpo -c -o tnftp-cmdtab.o `test -f 'cmdtab.c' || echo '$(srcdir)/'`cmdtab.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-cmdtab.Tpo $(DEPDIR)/tnftp-cmdtab.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cmdtab.c' object='tnftp-cmdtab.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-cmdtab.o `test -f 'cmdtab.c' || echo '$(srcdir)/'`cmdtab.c
+
+tnftp-cmdtab.obj: cmdtab.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-cmdtab.obj -MD -MP -MF $(DEPDIR)/tnftp-cmdtab.Tpo -c -o tnftp-cmdtab.obj `if test -f 'cmdtab.c'; then $(CYGPATH_W) 'cmdtab.c'; else $(CYGPATH_W) '$(srcdir)/cmdtab.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-cmdtab.Tpo $(DEPDIR)/tnftp-cmdtab.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cmdtab.c' object='tnftp-cmdtab.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-cmdtab.obj `if test -f 'cmdtab.c'; then $(CYGPATH_W) 'cmdtab.c'; else $(CYGPATH_W) '$(srcdir)/cmdtab.c'; fi`
+
+tnftp-complete.o: complete.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-complete.o -MD -MP -MF $(DEPDIR)/tnftp-complete.Tpo -c -o tnftp-complete.o `test -f 'complete.c' || echo '$(srcdir)/'`complete.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-complete.Tpo $(DEPDIR)/tnftp-complete.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='complete.c' object='tnftp-complete.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-complete.o `test -f 'complete.c' || echo '$(srcdir)/'`complete.c
+
+tnftp-complete.obj: complete.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-complete.obj -MD -MP -MF $(DEPDIR)/tnftp-complete.Tpo -c -o tnftp-complete.obj `if test -f 'complete.c'; then $(CYGPATH_W) 'complete.c'; else $(CYGPATH_W) '$(srcdir)/complete.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-complete.Tpo $(DEPDIR)/tnftp-complete.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='complete.c' object='tnftp-complete.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-complete.obj `if test -f 'complete.c'; then $(CYGPATH_W) 'complete.c'; else $(CYGPATH_W) '$(srcdir)/complete.c'; fi`
+
+tnftp-domacro.o: domacro.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-domacro.o -MD -MP -MF $(DEPDIR)/tnftp-domacro.Tpo -c -o tnftp-domacro.o `test -f 'domacro.c' || echo '$(srcdir)/'`domacro.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-domacro.Tpo $(DEPDIR)/tnftp-domacro.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='domacro.c' object='tnftp-domacro.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-domacro.o `test -f 'domacro.c' || echo '$(srcdir)/'`domacro.c
+
+tnftp-domacro.obj: domacro.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-domacro.obj -MD -MP -MF $(DEPDIR)/tnftp-domacro.Tpo -c -o tnftp-domacro.obj `if test -f 'domacro.c'; then $(CYGPATH_W) 'domacro.c'; else $(CYGPATH_W) '$(srcdir)/domacro.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-domacro.Tpo $(DEPDIR)/tnftp-domacro.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='domacro.c' object='tnftp-domacro.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-domacro.obj `if test -f 'domacro.c'; then $(CYGPATH_W) 'domacro.c'; else $(CYGPATH_W) '$(srcdir)/domacro.c'; fi`
+
+tnftp-fetch.o: fetch.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-fetch.o -MD -MP -MF $(DEPDIR)/tnftp-fetch.Tpo -c -o tnftp-fetch.o `test -f 'fetch.c' || echo '$(srcdir)/'`fetch.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-fetch.Tpo $(DEPDIR)/tnftp-fetch.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='fetch.c' object='tnftp-fetch.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-fetch.o `test -f 'fetch.c' || echo '$(srcdir)/'`fetch.c
+
+tnftp-fetch.obj: fetch.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-fetch.obj -MD -MP -MF $(DEPDIR)/tnftp-fetch.Tpo -c -o tnftp-fetch.obj `if test -f 'fetch.c'; then $(CYGPATH_W) 'fetch.c'; else $(CYGPATH_W) '$(srcdir)/fetch.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-fetch.Tpo $(DEPDIR)/tnftp-fetch.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='fetch.c' object='tnftp-fetch.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-fetch.obj `if test -f 'fetch.c'; then $(CYGPATH_W) 'fetch.c'; else $(CYGPATH_W) '$(srcdir)/fetch.c'; fi`
+
+tnftp-ftp.o: ftp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-ftp.o -MD -MP -MF $(DEPDIR)/tnftp-ftp.Tpo -c -o tnftp-ftp.o `test -f 'ftp.c' || echo '$(srcdir)/'`ftp.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-ftp.Tpo $(DEPDIR)/tnftp-ftp.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ftp.c' object='tnftp-ftp.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-ftp.o `test -f 'ftp.c' || echo '$(srcdir)/'`ftp.c
+
+tnftp-ftp.obj: ftp.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-ftp.obj -MD -MP -MF $(DEPDIR)/tnftp-ftp.Tpo -c -o tnftp-ftp.obj `if test -f 'ftp.c'; then $(CYGPATH_W) 'ftp.c'; else $(CYGPATH_W) '$(srcdir)/ftp.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-ftp.Tpo $(DEPDIR)/tnftp-ftp.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ftp.c' object='tnftp-ftp.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-ftp.obj `if test -f 'ftp.c'; then $(CYGPATH_W) 'ftp.c'; else $(CYGPATH_W) '$(srcdir)/ftp.c'; fi`
+
+tnftp-main.o: main.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-main.o -MD -MP -MF $(DEPDIR)/tnftp-main.Tpo -c -o tnftp-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-main.Tpo $(DEPDIR)/tnftp-main.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='main.c' object='tnftp-main.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-main.o `test -f 'main.c' || echo '$(srcdir)/'`main.c
+
+tnftp-main.obj: main.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-main.obj -MD -MP -MF $(DEPDIR)/tnftp-main.Tpo -c -o tnftp-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-main.Tpo $(DEPDIR)/tnftp-main.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='main.c' object='tnftp-main.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-main.obj `if test -f 'main.c'; then $(CYGPATH_W) 'main.c'; else $(CYGPATH_W) '$(srcdir)/main.c'; fi`
+
+tnftp-progressbar.o: progressbar.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-progressbar.o -MD -MP -MF $(DEPDIR)/tnftp-progressbar.Tpo -c -o tnftp-progressbar.o `test -f 'progressbar.c' || echo '$(srcdir)/'`progressbar.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-progressbar.Tpo $(DEPDIR)/tnftp-progressbar.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='progressbar.c' object='tnftp-progressbar.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-progressbar.o `test -f 'progressbar.c' || echo '$(srcdir)/'`progressbar.c
+
+tnftp-progressbar.obj: progressbar.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-progressbar.obj -MD -MP -MF $(DEPDIR)/tnftp-progressbar.Tpo -c -o tnftp-progressbar.obj `if test -f 'progressbar.c'; then $(CYGPATH_W) 'progressbar.c'; else $(CYGPATH_W) '$(srcdir)/progressbar.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-progressbar.Tpo $(DEPDIR)/tnftp-progressbar.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='progressbar.c' object='tnftp-progressbar.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-progressbar.obj `if test -f 'progressbar.c'; then $(CYGPATH_W) 'progressbar.c'; else $(CYGPATH_W) '$(srcdir)/progressbar.c'; fi`
+
+tnftp-ruserpass.o: ruserpass.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-ruserpass.o -MD -MP -MF $(DEPDIR)/tnftp-ruserpass.Tpo -c -o tnftp-ruserpass.o `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-ruserpass.Tpo $(DEPDIR)/tnftp-ruserpass.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ruserpass.c' object='tnftp-ruserpass.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-ruserpass.o `test -f 'ruserpass.c' || echo '$(srcdir)/'`ruserpass.c
+
+tnftp-ruserpass.obj: ruserpass.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-ruserpass.obj -MD -MP -MF $(DEPDIR)/tnftp-ruserpass.Tpo -c -o tnftp-ruserpass.obj `if test -f 'ruserpass.c'; then $(CYGPATH_W) 'ruserpass.c'; else $(CYGPATH_W) '$(srcdir)/ruserpass.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-ruserpass.Tpo $(DEPDIR)/tnftp-ruserpass.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='ruserpass.c' object='tnftp-ruserpass.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-ruserpass.obj `if test -f 'ruserpass.c'; then $(CYGPATH_W) 'ruserpass.c'; else $(CYGPATH_W) '$(srcdir)/ruserpass.c'; fi`
+
+tnftp-util.o: util.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-util.o -MD -MP -MF $(DEPDIR)/tnftp-util.Tpo -c -o tnftp-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-util.Tpo $(DEPDIR)/tnftp-util.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='util.c' object='tnftp-util.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-util.o `test -f 'util.c' || echo '$(srcdir)/'`util.c
+
+tnftp-util.obj: util.c
+@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tnftp-util.obj -MD -MP -MF $(DEPDIR)/tnftp-util.Tpo -c -o tnftp-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi`
+@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tnftp-util.Tpo $(DEPDIR)/tnftp-util.Po
+@am__fastdepCC_FALSE@ $(AM_V_CC) @AM_BACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='util.c' object='tnftp-util.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(tnftp_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tnftp-util.obj `if test -f 'util.c'; then $(CYGPATH_W) 'util.c'; else $(CYGPATH_W) '$(srcdir)/util.c'; fi`
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+install-man1: $(man1_MANS)
+ @$(NORMAL_INSTALL)
+ test -z "$(man1dir)" || $(MKDIR_P) "$(DESTDIR)$(man1dir)"
+ @list='$(man1_MANS)'; test -n "$(man1dir)" || exit 0; \
+ { for i in $$list; do echo "$$i"; done; \
+ } | while read p; do \
+ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; echo "$$p"; \
+ done | \
+ sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
+ sed 'N;N;s,\n, ,g' | { \
+ list=; while read file base inst; do \
+ if test "$$base" = "$$inst"; then list="$$list $$file"; else \
+ echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man1dir)/$$inst'"; \
+ $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man1dir)/$$inst" || exit $$?; \
+ fi; \
+ done; \
+ for i in $$list; do echo "$$i"; done | $(am__base_list) | \
+ while read files; do \
+ test -z "$$files" || { \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man1dir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(man1dir)" || exit $$?; }; \
+ done; }
+
+uninstall-man1:
+ @$(NORMAL_UNINSTALL)
+ @list='$(man1_MANS)'; test -n "$(man1dir)" || exit 0; \
+ files=`{ for i in $$list; do echo "$$i"; done; \
+ } | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^1][0-9a-z]*$$,1,;x' \
+ -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
+ test -z "$$files" || { \
+ echo " ( cd '$(DESTDIR)$(man1dir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(man1dir)" && rm -f $$files; }
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @list='$(MANS)'; if test -n "$$list"; then \
+ list=`for p in $$list; do \
+ if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
+ if test -f "$$d$$p"; then echo "$$d$$p"; else :; fi; done`; \
+ if test -n "$$list" && \
+ grep 'ab help2man is required to generate this page' $$list >/dev/null; then \
+ echo "error: found man pages containing the \`missing help2man' replacement text:" >&2; \
+ grep -l 'ab help2man is required to generate this page' $$list | sed 's/^/ /' >&2; \
+ echo " to fix them, install help2man, remove and regenerate the man pages;" >&2; \
+ echo " typically \`make maintainer-clean' will remove them" >&2; \
+ exit 1; \
+ else :; fi; \
+ else :; fi
+ @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+ list='$(DISTFILES)'; \
+ dist_files=`for file in $$list; do echo $$file; done | \
+ sed -e "s|^$$srcdirstrip/||;t" \
+ -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+ case $$dist_files in \
+ */*) $(MKDIR_P) `echo "$$dist_files" | \
+ sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+ sort -u` ;; \
+ esac; \
+ for file in $$dist_files; do \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test -d "$(distdir)/$$file"; then \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+ find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+ fi; \
+ cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+ else \
+ test -f "$(distdir)/$$file" \
+ || cp -p $$d/$$file "$(distdir)/$$file" \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS) $(MANS)
+installdirs:
+ for dir in "$(DESTDIR)$(bindir)" "$(DESTDIR)$(man1dir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-man
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man: install-man1
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
-mandircat1 = ${mandir}/cat1
+ps: ps-am
-CC = @CC@
-CFLAGS = -I${srcdir} -I${srcdir}/.. -I. -I.. @INCLUDES@ @CFLAGS@
-LIBS = @LIBS@
-LDFLAGS = @LDFLAGS@
+ps-am:
-INSTALL = @INSTALL@
+uninstall-am: uninstall-binPROGRAMS uninstall-man
-PROG = ftp
-OBJS = cmds.o cmdtab.o complete.o domacro.o fetch.o ftp.o main.o \
- ruserpass.o util.o
+uninstall-man: uninstall-man1
-all: ${PROG}
+.MAKE: install-am install-strip
-install: all
- -mkdir -p ${bindir}
- ${INSTALL} -m 555 ${PROG} ${bindir}/`echo ${PROG}|sed '$(transform)'`
- -mkdir -p ${mandircat1}
- ${INSTALL} -m 444 ${srcdir}/${PROG}.cat1 ${mandircat1}/`echo ${PROG}|sed '$(transform)'`.1
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+ clean-generic clean-libtool ctags distclean distclean-compile \
+ distclean-generic distclean-libtool distclean-tags distdir dvi \
+ dvi-am html html-am info info-am install install-am \
+ install-binPROGRAMS install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-man1 install-pdf install-pdf-am install-ps \
+ install-ps-am install-strip installcheck installcheck-am \
+ installdirs maintainer-clean maintainer-clean-generic \
+ mostlyclean mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
+ uninstall-am uninstall-binPROGRAMS uninstall-man \
+ uninstall-man1
-${PROG}: ${OBJS} @LIBDEPENDS@
- ${CC} ${CFLAGS} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBS}
-clean:
- rm -f core ${PROG} ${OBJS}
+tnftp.1: ftp.1
+ cp $(srcdir)/ftp.1 tnftp.1
-distclean: clean
- rm -f Makefile
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/src/cmds.c b/src/cmds.c
index 69dbd18195bf5..7be3a7782a174 100644
--- a/src/cmds.c
+++ b/src/cmds.c
@@ -1,7 +1,8 @@
-/* $NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $ */
+/* $NetBSD: cmds.c,v 1.17 2010/01/12 06:55:47 lukem Exp $ */
+/* from NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp */
/*-
- * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -19,13 +20,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -98,12 +92,16 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cmds.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $");
+__RCSID(" NetBSD: cmds.c,v 1.130 2009/07/13 19:05:41 roy Exp ");
#endif
#endif /* not lint */
@@ -122,57 +120,73 @@ __RCSID("$NetBSD: cmds.c,v 1.112 2005/04/11 01:49:31 lukem Exp $");
#include <limits.h>
#include <netdb.h>
#include <paths.h>
+#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <libutil.h>
+
+#endif /* tnftp */
#include "ftp_var.h"
#include "version.h"
-struct types {
- char *t_name;
- char *t_mode;
- int t_type;
- char *t_arg;
+static struct types {
+ const char *t_name;
+ const char *t_mode;
+ int t_type;
+ const char *t_arg;
} types[] = {
{ "ascii", "A", TYPE_A, 0 },
{ "binary", "I", TYPE_I, 0 },
{ "image", "I", TYPE_I, 0 },
{ "ebcdic", "E", TYPE_E, 0 },
{ "tenex", "L", TYPE_L, bytename },
- { NULL }
+ { NULL, NULL, 0, NULL }
};
-sigjmp_buf jabort;
-const char *mname;
+static sigjmp_buf jabort;
static int confirm(const char *, const char *);
+static void mintr(int);
+static void mabort(const char *);
+static void set_type(const char *);
static const char *doprocess(char *, size_t, const char *, int, int, int);
static const char *domap(char *, size_t, const char *);
static const char *docase(char *, size_t, const char *);
static const char *dotrans(char *, size_t, const char *);
+/*
+ * Confirm if "cmd" is to be performed upon "file".
+ * If "file" is NULL, generate a "Continue with" prompt instead.
+ */
static int
confirm(const char *cmd, const char *file)
{
- char line[BUFSIZ];
+ const char *errormsg;
+ char cline[BUFSIZ];
+ const char *promptleft, *promptright;
if (!interactive || confirmrest)
return (1);
+ if (file == NULL) {
+ promptleft = "Continue with";
+ promptright = cmd;
+ } else {
+ promptleft = cmd;
+ promptright = file;
+ }
while (1) {
- fprintf(ttyout, "%s %s [anpqy?]? ", cmd, file);
+ fprintf(ttyout, "%s %s [anpqy?]? ", promptleft, promptright);
(void)fflush(ttyout);
- if (fgets(line, sizeof(line), stdin) == NULL) {
+ if (get_line(stdin, cline, sizeof(cline), &errormsg) < 0) {
mflag = 0;
- fprintf(ttyout, "\nEOF received; %s aborted\n", mname);
- clearerr(stdin);
+ fprintf(ttyout, "%s; %s aborted\n", errormsg, cmd);
return (0);
}
- switch (tolower((unsigned char)*line)) {
+ switch (tolower((unsigned char)*cline)) {
case 'a':
confirmrest = 1;
fprintf(ttyout,
@@ -184,7 +198,7 @@ confirm(const char *cmd, const char *file)
break;
case 'q':
mflag = 0;
- fprintf(ttyout, "%s aborted.\n", mname);
+ fprintf(ttyout, "%s aborted.\n", cmd);
/* FALLTHROUGH */
case 'n':
return (0);
@@ -212,12 +226,11 @@ void
settype(int argc, char *argv[])
{
struct types *p;
- int comret;
if (argc == 0 || argc > 2) {
- char *sep;
+ const char *sep;
- fprintf(ttyout, "usage: %s [", argv[0]);
+ UPRINTF("usage: %s [", argv[0]);
sep = " ";
for (p = types; p->t_name; p++) {
fprintf(ttyout, "%s%s", sep, p->t_name);
@@ -232,11 +245,20 @@ settype(int argc, char *argv[])
code = 0;
return;
}
+ set_type(argv[1]);
+}
+
+void
+set_type(const char *ttype)
+{
+ struct types *p;
+ int comret;
+
for (p = types; p->t_name; p++)
- if (strcmp(argv[1], p->t_name) == 0)
+ if (strcmp(ttype, p->t_name) == 0)
break;
if (p->t_name == 0) {
- fprintf(ttyout, "%s: unknown mode.\n", argv[1]);
+ fprintf(ttyout, "%s: unknown mode.\n", ttype);
code = -1;
return;
}
@@ -265,14 +287,13 @@ changetype(int newtype, int show)
newtype = TYPE_I;
if (newtype == curtype)
return;
- if (debug == 0 && show == 0)
+ if (ftp_debug == 0 && show == 0)
verbose = 0;
for (p = types; p->t_name; p++)
if (newtype == p->t_type)
break;
if (p->t_name == 0) {
- warnx("internal error: unknown type %d.", newtype);
- return;
+ errx(1, "changetype: unknown type %d", newtype);
}
if (newtype == TYPE_L && bytename[0] != '\0')
comret = command("TYPE %s %s", p->t_mode, bytename);
@@ -283,12 +304,6 @@ changetype(int newtype, int show)
verbose = oldverbose;
}
-char *stype[] = {
- "type",
- "",
- 0
-};
-
/*
* Set binary transfer type.
*/
@@ -298,12 +313,11 @@ setbinary(int argc, char *argv[])
{
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
- stype[1] = "binary";
- settype(2, stype);
+ set_type("binary");
}
/*
@@ -315,12 +329,11 @@ setascii(int argc, char *argv[])
{
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
- stype[1] = "ascii";
- settype(2, stype);
+ set_type("ascii");
}
/*
@@ -332,12 +345,11 @@ settenex(int argc, char *argv[])
{
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
- stype[1] = "tenex";
- settype(2, stype);
+ set_type("tenex");
}
/*
@@ -349,7 +361,7 @@ setftmode(int argc, char *argv[])
{
if (argc != 2) {
- fprintf(ttyout, "usage: %s mode-name\n", argv[0]);
+ UPRINTF("usage: %s mode-name\n", argv[0]);
code = -1;
return;
}
@@ -366,7 +378,7 @@ setform(int argc, char *argv[])
{
if (argc != 2) {
- fprintf(ttyout, "usage: %s format\n", argv[0]);
+ UPRINTF("usage: %s format\n", argv[0]);
code = -1;
return;
}
@@ -383,7 +395,7 @@ setstruct(int argc, char *argv[])
{
if (argc != 2) {
- fprintf(ttyout, "usage: %s struct-mode\n", argv[0]);
+ UPRINTF("usage: %s struct-mode\n", argv[0]);
code = -1;
return;
}
@@ -398,7 +410,7 @@ void
put(int argc, char *argv[])
{
char buf[MAXPATHLEN];
- char *cmd;
+ const char *cmd;
int loc = 0;
char *locfile;
const char *remfile;
@@ -412,8 +424,7 @@ put(int argc, char *argv[])
goto usage;
if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
usage:
- fprintf(ttyout, "usage: %s local-file [remote-file]\n",
- argv[0]);
+ UPRINTF("usage: %s local-file [remote-file]\n", argv[0]);
code = -1;
return;
}
@@ -457,15 +468,14 @@ mput(int argc, char *argv[])
const char *tp;
if (argc == 0 || (argc == 1 && !another(&argc, &argv, "local-files"))) {
- fprintf(ttyout, "usage: %s local-files\n", argv[0]);
+ UPRINTF("usage: %s local-files\n", argv[0]);
code = -1;
return;
}
- mname = argv[0];
mflag = 1;
oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1))
- mabort();
+ mabort(argv[0]);
if (proxy) {
char *cp;
@@ -483,7 +493,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", "mput")) {
+ if (confirm(argv[0], NULL)) {
mflag++;
}
interactive = ointer;
@@ -507,7 +517,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", "mput")) {
+ if (confirm(argv[0], NULL)) {
mflag++;
}
interactive = ointer;
@@ -519,7 +529,7 @@ mput(int argc, char *argv[])
memset(&gl, 0, sizeof(gl));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) {
- warnx("%s: not found", argv[i]);
+ warnx("Glob pattern `%s' not found", argv[i]);
globfree(&gl);
continue;
}
@@ -535,7 +545,7 @@ mput(int argc, char *argv[])
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", "mput")) {
+ if (confirm(argv[0], NULL)) {
mflag++;
}
interactive = ointer;
@@ -569,7 +579,7 @@ get(int argc, char *argv[])
* If restartit is -1, restart the xfer only if the remote file is newer.
*/
int
-getit(int argc, char *argv[], int restartit, const char *mode)
+getit(int argc, char *argv[], int restartit, const char *gmode)
{
int loc, rval;
char *remfile, *olocfile;
@@ -586,8 +596,7 @@ getit(int argc, char *argv[], int restartit, const char *mode)
goto usage;
if ((argc < 3 && !another(&argc, &argv, "local-file")) || argc > 3) {
usage:
- fprintf(ttyout, "usage: %s remote-file [local-file]\n",
- argv[0]);
+ UPRINTF("usage: %s remote-file [local-file]\n", argv[0]);
code = -1;
return (0);
}
@@ -610,7 +619,7 @@ getit(int argc, char *argv[], int restartit, const char *mode)
ret = stat(locfile, &stbuf);
if (restartit == 1) {
if (ret < 0) {
- warn("local: %s", locfile);
+ warn("Can't stat `%s'", locfile);
goto freegetit;
}
restart_point = stbuf.st_size;
@@ -629,7 +638,7 @@ getit(int argc, char *argv[], int restartit, const char *mode)
}
}
- recvrequest("RETR", locfile, remfile, mode,
+ recvrequest("RETR", locfile, remfile, gmode,
remfile != argv[1] || locfile != argv[2], loc);
restart_point = 0;
freegetit:
@@ -638,7 +647,7 @@ getit(int argc, char *argv[], int restartit, const char *mode)
}
/* ARGSUSED */
-void
+static void
mintr(int signo)
{
@@ -648,8 +657,8 @@ mintr(int signo)
siglongjmp(jabort, 1);
}
-void
-mabort(void)
+static void
+mabort(const char *cmd)
{
int ointer, oconf;
@@ -658,7 +667,7 @@ mabort(void)
oconf = confirmrest;
interactive = 1;
confirmrest = 0;
- if (confirm("Continue with", mname)) {
+ if (confirm(cmd, NULL)) {
interactive = ointer;
confirmrest = oconf;
return;
@@ -679,15 +688,14 @@ mget(int argc, char *argv[])
int ointer;
char *cp;
const char *tp;
- int restartit;
+ int volatile restartit;
if (argc == 0 ||
(argc == 1 && !another(&argc, &argv, "remote-files"))) {
- fprintf(ttyout, "usage: %s remote-files\n", argv[0]);
+ UPRINTF("usage: %s remote-files\n", argv[0]);
code = -1;
return;
}
- mname = argv[0];
mflag = 1;
restart_point = 0;
restartit = 0;
@@ -701,7 +709,7 @@ mget(int argc, char *argv[])
}
oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1))
- mabort();
+ mabort(argv[0]);
while ((cp = remglob(argv, proxy, NULL)) != NULL) {
char buf[MAXPATHLEN];
if (*cp == '\0' || !connected) {
@@ -724,7 +732,7 @@ mget(int argc, char *argv[])
if (stat(tp, &stbuf) == 0)
restart_point = stbuf.st_size;
else
- warn("stat %s", tp);
+ warn("Can't stat `%s'", tp);
}
recvrequest("RETR", tp, cp, restart_point ? "r+" : "w",
tp != cp || !interactive, 1);
@@ -732,7 +740,7 @@ mget(int argc, char *argv[])
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", "mget"))
+ if (confirm(argv[0], NULL))
mflag++;
interactive = ointer;
}
@@ -747,41 +755,41 @@ mget(int argc, char *argv[])
void
fget(int argc, char *argv[])
{
- char *buf, *mode;
+ const char *gmode;
FILE *fp;
+ char buf[MAXPATHLEN], cmdbuf[MAX_C_NAME];
if (argc != 2) {
- fprintf(ttyout, "usage: %s localfile\n", argv[0]);
+ UPRINTF("usage: %s localfile\n", argv[0]);
code = -1;
return;
}
fp = fopen(argv[1], "r");
if (fp == NULL) {
- fprintf(ttyout, "Cannot open source file %s\n", argv[1]);
+ fprintf(ttyout, "Can't open source file %s\n", argv[1]);
code = -1;
return;
}
- argv[0] = "get";
- mode = restart_point ? "r+" : "w";
+ (void)strlcpy(cmdbuf, "get", sizeof(cmdbuf));
+ argv[0] = cmdbuf;
+ gmode = restart_point ? "r+" : "w";
- for (;
- (buf = fparseln(fp, NULL, NULL, "\0\0\0", 0)) != NULL;
- free(buf)) {
+ while (get_line(fp, buf, sizeof(buf), NULL) >= 0) {
if (buf[0] == '\0')
continue;
argv[1] = buf;
- (void)getit(argc, argv, 0, mode);
+ (void)getit(argc, argv, 0, gmode);
}
fclose(fp);
}
-char *
-onoff(int bool)
+const char *
+onoff(int val)
{
- return (bool ? "on" : "off");
+ return (val ? "on" : "off");
}
/*
@@ -793,7 +801,7 @@ status(int argc, char *argv[])
{
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -854,6 +862,8 @@ status(int argc, char *argv[])
fprintf(ttyout, "Use of PORT cmds: %s.\n", onoff(sendport));
fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv4: %s%s.\n", onoff(epsv4),
epsv4bad ? " (disabled for this connection)" : "");
+ fprintf(ttyout, "Use of EPSV/EPRT cmds for IPv6: %s%s.\n", onoff(epsv6),
+ epsv6bad ? " (disabled for this connection)" : "");
fprintf(ttyout, "Command line editing: %s.\n",
#ifdef NO_EDITCOMPLETE
"support not compiled in"
@@ -887,7 +897,7 @@ togglevar(int argc, char *argv[], int *var, const char *mesg)
} else if (argc == 2 && strcasecmp(argv[1], "off") == 0) {
*var = 0;
} else {
- fprintf(ttyout, "usage: %s [ on | off ]\n", argv[0]);
+ UPRINTF("usage: %s [ on | off ]\n", argv[0]);
return (-1);
}
if (mesg)
@@ -916,7 +926,7 @@ setedit(int argc, char *argv[])
#ifdef NO_EDITCOMPLETE
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -950,7 +960,7 @@ sethash(int argc, char *argv[])
if (argc == 1)
hash = !hash;
else if (argc != 2) {
- fprintf(ttyout, "usage: %s [ on | off | bytecount ]\n",
+ UPRINTF("usage: %s [ on | off | bytecount ]\n",
argv[0]);
code = -1;
return;
@@ -1036,7 +1046,7 @@ setgate(int argc, char *argv[])
static char gsbuf[MAXHOSTNAMELEN];
if (argc == 0 || argc > 3) {
- fprintf(ttyout,
+ UPRINTF(
"usage: %s [ on | off | gateserver [port] ]\n", argv[0]);
code = -1;
return;
@@ -1049,7 +1059,7 @@ setgate(int argc, char *argv[])
gatemode = 0;
else {
if (argc == 3)
- gateport = xstrdup(argv[2]);
+ gateport = ftp_strdup(argv[2]);
(void)strlcpy(gsbuf, argv[1], sizeof(gsbuf));
gateserver = gsbuf;
gatemode = 1;
@@ -1097,15 +1107,14 @@ void
setdebug(int argc, char *argv[])
{
if (argc == 0 || argc > 2) {
- fprintf(ttyout, "usage: %s [ on | off | debuglevel ]\n",
- argv[0]);
+ UPRINTF("usage: %s [ on | off | debuglevel ]\n", argv[0]);
code = -1;
return;
} else if (argc == 2) {
if (strcasecmp(argv[1], "on") == 0)
- debug = 1;
+ ftp_debug = 1;
else if (strcasecmp(argv[1], "off") == 0)
- debug = 0;
+ ftp_debug = 0;
else {
int val;
@@ -1116,16 +1125,16 @@ setdebug(int argc, char *argv[])
code = -1;
return;
}
- debug = val;
+ ftp_debug = val;
}
} else
- debug = !debug;
- if (debug)
+ ftp_debug = !ftp_debug;
+ if (ftp_debug)
options |= SO_DEBUG;
else
options &= ~SO_DEBUG;
- fprintf(ttyout, "Debugging %s (debug=%d).\n", onoff(debug), debug);
- code = debug > 0;
+ fprintf(ttyout, "Debugging %s (ftp_debug=%d).\n", onoff(ftp_debug), ftp_debug);
+ code = ftp_debug > 0;
}
/*
@@ -1138,7 +1147,7 @@ cd(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "remote-directory"))) {
- fprintf(ttyout, "usage: %s remote-directory\n", argv[0]);
+ UPRINTF("usage: %s remote-directory\n", argv[0]);
code = -1;
return;
}
@@ -1169,13 +1178,13 @@ lcd(int argc, char *argv[])
argv[1] = localhome;
}
if (argc != 2) {
- fprintf(ttyout, "usage: %s [local-directory]\n", argv[0]);
+ UPRINTF("usage: %s [local-directory]\n", argv[0]);
return;
}
if ((locdir = globulize(argv[1])) == NULL)
return;
if (chdir(locdir) == -1)
- warn("lcd %s", locdir);
+ warn("Can't chdir `%s'", locdir);
else {
updatelocalcwd();
if (localcwd[0]) {
@@ -1197,7 +1206,7 @@ delete(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "remote-file"))) {
- fprintf(ttyout, "usage: %s remote-file\n", argv[0]);
+ UPRINTF("usage: %s remote-file\n", argv[0]);
code = -1;
return;
}
@@ -1217,15 +1226,14 @@ mdelete(int argc, char *argv[])
if (argc == 0 ||
(argc == 1 && !another(&argc, &argv, "remote-files"))) {
- fprintf(ttyout, "usage: %s [remote-files]\n", argv[0]);
+ UPRINTF("usage: %s [remote-files]\n", argv[0]);
code = -1;
return;
}
- mname = argv[0];
mflag = 1;
oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1))
- mabort();
+ mabort(argv[0]);
while ((cp = remglob(argv, 0, NULL)) != NULL) {
if (*cp == '\0') {
mflag = 0;
@@ -1237,7 +1245,7 @@ mdelete(int argc, char *argv[])
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", "mdelete")) {
+ if (confirm(argv[0], NULL)) {
mflag++;
}
interactive = ointer;
@@ -1259,7 +1267,7 @@ renamefile(int argc, char *argv[])
goto usage;
if ((argc < 3 && !another(&argc, &argv, "to-name")) || argc > 3) {
usage:
- fprintf(ttyout, "usage: %s from-name to-name\n", argv[0]);
+ UPRINTF("usage: %s from-name to-name\n", argv[0]);
code = -1;
return;
}
@@ -1277,18 +1285,20 @@ renamefile(int argc, char *argv[])
* mlsd MLSD
* nlist NLST
* pdir, pls LIST |$PAGER
- * mmlsd MLSD |$PAGER
+ * pmlsd MLSD |$PAGER
*/
void
ls(int argc, char *argv[])
{
const char *cmd;
- char *remdir, *locfile;
- int freelocfile, pagecmd, mlsdcmd;
+ char *remdir, *locbuf;
+ const char *locfile;
+ int pagecmd, mlsdcmd;
remdir = NULL;
+ locbuf = NULL;
locfile = "-";
- freelocfile = pagecmd = mlsdcmd = 0;
+ pagecmd = mlsdcmd = 0;
/*
* the only commands that start with `p' are
* the `pager' versions.
@@ -1320,41 +1330,38 @@ ls(int argc, char *argv[])
if (argc > 3 || ((pagecmd | mlsdcmd) && argc > 2)) {
usage:
if (pagecmd || mlsdcmd)
- fprintf(ttyout,
- "usage: %s [remote-path]\n", argv[0]);
+ UPRINTF("usage: %s [remote-path]\n", argv[0]);
else
- fprintf(ttyout,
- "usage: %s [remote-path [local-file]]\n",
+ UPRINTF("usage: %s [remote-path [local-file]]\n",
argv[0]);
code = -1;
goto freels;
}
if (pagecmd) {
- char *p;
- int len;
+ const char *p;
+ size_t len;
p = getoptionvalue("pager");
if (EMPTYSTRING(p))
p = DEFAULTPAGER;
len = strlen(p) + 2;
- locfile = xmalloc(len);
- locfile[0] = '|';
- (void)strlcpy(locfile + 1, p, len - 1);
- freelocfile = 1;
+ locbuf = ftp_malloc(len);
+ locbuf[0] = '|';
+ (void)strlcpy(locbuf + 1, p, len - 1);
+ locfile = locbuf;
} else if ((strcmp(locfile, "-") != 0) && *locfile != '|') {
- mname = argv[0];
- if ((locfile = globulize(locfile)) == NULL ||
- !confirm("output to local-file:", locfile)) {
+ if ((locbuf = globulize(locfile)) == NULL ||
+ !confirm("output to local-file:", locbuf)) {
code = -1;
goto freels;
}
- freelocfile = 1;
+ locfile = locbuf;
}
recvrequest(cmd, locfile, remdir, "w", 0, 0);
freels:
- if (freelocfile && locfile)
- (void)free(locfile);
+ if (locbuf)
+ (void)free(locbuf);
}
/*
@@ -1365,8 +1372,9 @@ mls(int argc, char *argv[])
{
sigfunc oldintr;
int ointer, i;
- int dolist;
- char *mode, *dest, *odest;
+ int volatile dolist;
+ char * volatile dest, *odest;
+ const char *lmode;
if (argc == 0)
goto usage;
@@ -1374,13 +1382,12 @@ mls(int argc, char *argv[])
goto usage;
if (argc < 3 && !another(&argc, &argv, "local-file")) {
usage:
- fprintf(ttyout, "usage: %s remote-files local-file\n", argv[0]);
+ UPRINTF("usage: %s remote-files local-file\n", argv[0]);
code = -1;
return;
}
odest = dest = argv[argc - 1];
argv[argc - 1] = NULL;
- mname = argv[0];
if (strcmp(dest, "-") && *dest != '|')
if (((dest = globulize(dest)) == NULL) ||
!confirm("output to local-file:", dest)) {
@@ -1391,15 +1398,15 @@ mls(int argc, char *argv[])
mflag = 1;
oldintr = xsignal(SIGINT, mintr);
if (sigsetjmp(jabort, 1))
- mabort();
+ mabort(argv[0]);
for (i = 1; mflag && i < argc-1 && connected; i++) {
- mode = (i == 1) ? "w" : "a";
- recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], mode,
+ lmode = (i == 1) ? "w" : "a";
+ recvrequest(dolist ? "LIST" : "NLST", dest, argv[i], lmode,
0, 0);
if (!mflag && fromatty) {
ointer = interactive;
interactive = 1;
- if (confirm("Continue with", argv[0])) {
+ if (confirm(argv[0], NULL)) {
mflag++;
}
interactive = ointer;
@@ -1420,11 +1427,12 @@ shell(int argc, char *argv[])
{
pid_t pid;
sigfunc oldintr;
- char shellnam[MAXPATHLEN], *shell, *namep;
+ char shellnam[MAXPATHLEN];
+ const char *shellp, *namep;
int wait_status;
if (argc == 0) {
- fprintf(ttyout, "usage: %s [command [args]]\n", argv[0]);
+ UPRINTF("usage: %s [command [args]]\n", argv[0]);
code = -1;
return;
}
@@ -1433,26 +1441,26 @@ shell(int argc, char *argv[])
for (pid = 3; pid < 20; pid++)
(void)close(pid);
(void)xsignal(SIGINT, SIG_DFL);
- shell = getenv("SHELL");
- if (shell == NULL)
- shell = _PATH_BSHELL;
- namep = strrchr(shell, '/');
+ shellp = getenv("SHELL");
+ if (shellp == NULL)
+ shellp = _PATH_BSHELL;
+ namep = strrchr(shellp, '/');
if (namep == NULL)
- namep = shell;
+ namep = shellp;
else
namep++;
(void)strlcpy(shellnam, namep, sizeof(shellnam));
- if (debug) {
- fputs(shell, ttyout);
+ if (ftp_debug) {
+ fputs(shellp, ttyout);
putc('\n', ttyout);
}
if (argc > 1) {
- execl(shell, shellnam, "-c", altarg, (char *)0);
+ execl(shellp, shellnam, "-c", altarg, (char *)0);
}
else {
- execl(shell, shellnam, (char *)0);
+ execl(shellp, shellnam, (char *)0);
}
- warn("%s", shell);
+ warn("Can't execute `%s'", shellp);
code = -1;
exit(1);
}
@@ -1461,7 +1469,7 @@ shell(int argc, char *argv[])
;
(void)xsignal(SIGINT, oldintr);
if (pid == -1) {
- warn("Try again later");
+ warn("Can't fork a subshell; try again later");
code = -1;
} else
code = 0;
@@ -1473,7 +1481,8 @@ shell(int argc, char *argv[])
void
user(int argc, char *argv[])
{
- char acct[80];
+ char *password;
+ char emptypass[] = "";
int n, aflag = 0;
if (argc == 0)
@@ -1482,7 +1491,7 @@ user(int argc, char *argv[])
(void)another(&argc, &argv, "username");
if (argc < 2 || argc > 4) {
usage:
- fprintf(ttyout, "usage: %s username [password [account]]\n",
+ UPRINTF("usage: %s username [password [account]]\n",
argv[0]);
code = -1;
return;
@@ -1490,34 +1499,35 @@ user(int argc, char *argv[])
n = command("USER %s", argv[1]);
if (n == CONTINUE) {
if (argc < 3) {
- argv[2] = getpass("Password: ");
- argc++;
+ password = getpass("Password: ");
+ if (password == NULL)
+ password = emptypass;
+ } else {
+ password = argv[2];
}
- n = command("PASS %s", argv[2]);
+ n = command("PASS %s", password);
+ memset(password, 0, strlen(password));
}
if (n == CONTINUE) {
+ aflag++;
if (argc < 4) {
- (void)fputs("Account: ", ttyout);
- (void)fflush(ttyout);
- if (fgets(acct, sizeof(acct) - 1, stdin) == NULL) {
- fprintf(ttyout,
- "\nEOF received; login aborted.\n");
- clearerr(stdin);
- code = -1;
- return;
- }
- acct[strlen(acct) - 1] = '\0';
- argv[3] = acct; argc++;
+ password = getpass("Account: ");
+ if (password == NULL)
+ password = emptypass;
+ } else {
+ password = argv[3];
}
- n = command("ACCT %s", argv[3]);
- aflag++;
+ n = command("ACCT %s", password);
+ memset(password, 0, strlen(password));
}
if (n != COMPLETE) {
fputs("Login failed.\n", ttyout);
return;
}
if (!aflag && argc == 4) {
- (void)command("ACCT %s", argv[3]);
+ password = argv[3];
+ (void)command("ACCT %s", password);
+ memset(password, 0, strlen(password));
}
connected = -1;
getremoteinfo();
@@ -1533,7 +1543,7 @@ pwd(int argc, char *argv[])
code = -1;
if (argc != 1) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
return;
}
if (! remotecwd[0])
@@ -1555,7 +1565,7 @@ lpwd(int argc, char *argv[])
code = -1;
if (argc != 1) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
return;
}
if (! localcwd[0])
@@ -1578,7 +1588,7 @@ makedir(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "directory-name"))) {
- fprintf(ttyout, "usage: %s directory-name\n", argv[0]);
+ UPRINTF("usage: %s directory-name\n", argv[0]);
code = -1;
return;
}
@@ -1603,7 +1613,7 @@ removedir(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "directory-name"))) {
- fprintf(ttyout, "usage: %s directory-name\n", argv[0]);
+ UPRINTF("usage: %s directory-name\n", argv[0]);
code = -1;
return;
}
@@ -1627,7 +1637,7 @@ quote(int argc, char *argv[])
if (argc == 0 ||
(argc == 1 && !another(&argc, &argv, "command line to send"))) {
- fprintf(ttyout, "usage: %s line-to-send\n", argv[0]);
+ UPRINTF("usage: %s line-to-send\n", argv[0]);
code = -1;
return;
}
@@ -1645,7 +1655,7 @@ site(int argc, char *argv[])
if (argc == 0 ||
(argc == 1 && !another(&argc, &argv, "arguments to SITE command"))){
- fprintf(ttyout, "usage: %s line-to-send\n", argv[0]);
+ UPRINTF("usage: %s line-to-send\n", argv[0]);
code = -1;
return;
}
@@ -1683,7 +1693,7 @@ do_chmod(int argc, char *argv[])
goto usage;
if ((argc < 3 && !another(&argc, &argv, "remote-file")) || argc > 3) {
usage:
- fprintf(ttyout, "usage: %s mode remote-file\n", argv[0]);
+ UPRINTF("usage: %s mode remote-file\n", argv[0]);
code = -1;
return;
}
@@ -1702,7 +1712,7 @@ do_umask(int argc, char *argv[])
int oldverbose = verbose;
if (argc == 0) {
- fprintf(ttyout, "usage: %s [umask]\n", argv[0]);
+ UPRINTF("usage: %s [umask]\n", argv[0]);
code = -1;
return;
}
@@ -1717,7 +1727,7 @@ idlecmd(int argc, char *argv[])
int oldverbose = verbose;
if (argc < 1 || argc > 2) {
- fprintf(ttyout, "usage: %s [seconds]\n", argv[0]);
+ UPRINTF("usage: %s [seconds]\n", argv[0]);
code = -1;
return;
}
@@ -1735,7 +1745,7 @@ rmthelp(int argc, char *argv[])
int oldverbose = verbose;
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -1755,7 +1765,7 @@ quit(int argc, char *argv[])
/* this may be called with argc == 0, argv == NULL */
if (argc == 0 && argv != NULL) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -1777,7 +1787,7 @@ disconnect(int argc, char *argv[])
/* this may be called with argc == 0, argv == NULL */
if (argc == 0 && argv != NULL) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -1791,17 +1801,22 @@ void
account(int argc, char *argv[])
{
char *ap;
+ char emptypass[] = "";
if (argc == 0 || argc > 2) {
- fprintf(ttyout, "usage: %s [password]\n", argv[0]);
+ UPRINTF("usage: %s [password]\n", argv[0]);
code = -1;
return;
}
else if (argc == 2)
ap = argv[1];
- else
+ else {
ap = getpass("Account:");
+ if (ap == NULL)
+ ap = emptypass;
+ }
(void)command("ACCT %s", ap);
+ memset(ap, 0, strlen(ap));
}
sigjmp_buf abortprox;
@@ -1831,9 +1846,10 @@ doproxy(int argc, char *argv[])
struct cmd *c;
int cmdpos;
sigfunc oldintr;
+ char cmdbuf[MAX_C_NAME];
if (argc == 0 || (argc == 1 && !another(&argc, &argv, "command"))) {
- fprintf(ttyout, "usage: %s command\n", argv[0]);
+ UPRINTF("usage: %s command\n", argv[0]);
code = -1;
return;
}
@@ -1869,7 +1885,8 @@ doproxy(int argc, char *argv[])
cmdpos = strcspn(line, " \t");
if (cmdpos > 0) /* remove leading "proxy " from input buffer */
memmove(line, line + cmdpos + 1, strlen(line) - cmdpos + 1);
- argv[1] = c->c_name;
+ (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
+ argv[1] = cmdbuf;
(*c->c_handler)(argc-1, argv+1);
if (connected) {
proxflag = 1;
@@ -1925,7 +1942,7 @@ setntrans(int argc, char *argv[])
{
if (argc == 0 || argc > 3) {
- fprintf(ttyout, "usage: %s [inchars [outchars]]\n", argv[0]);
+ UPRINTF("usage: %s [inchars [outchars]]\n", argv[0]);
code = -1;
return;
}
@@ -1961,7 +1978,7 @@ dotrans(char *dst, size_t dlen, const char *src)
found++;
if (i < ostop) {
*cp2++ = *(ntout + i);
- if (cp2 - dst >= dlen - 1)
+ if (cp2 - dst >= (ptrdiff_t)(dlen - 1))
goto out;
}
break;
@@ -1989,7 +2006,7 @@ setnmap(int argc, char *argv[])
}
if (argc == 0 ||
(argc < 3 && !another(&argc, &argv, "mapout")) || argc > 3) {
- fprintf(ttyout, "usage: %s [mapin mapout]\n", argv[0]);
+ UPRINTF("usage: %s [mapin mapout]\n", argv[0]);
code = -1;
return;
}
@@ -2189,7 +2206,7 @@ setpassive(int argc, char *argv[])
activefallback = passivemode;
} else if (argc != 2) {
passiveusage:
- fprintf(ttyout, "usage: %s [ on | off | auto ]\n", argv[0]);
+ UPRINTF("usage: %s [ on | off | auto ]\n", argv[0]);
code = -1;
return;
} else if (strcasecmp(argv[1], "on") == 0) {
@@ -2208,16 +2225,31 @@ setpassive(int argc, char *argv[])
code = passivemode;
}
+
void
setepsv4(int argc, char *argv[])
{
-
code = togglevar(argc, argv, &epsv4,
verbose ? "EPSV/EPRT on IPv4" : NULL);
epsv4bad = 0;
}
void
+setepsv6(int argc, char *argv[])
+{
+ code = togglevar(argc, argv, &epsv6,
+ verbose ? "EPSV/EPRT on IPv6" : NULL);
+ epsv6bad = 0;
+}
+
+void
+setepsv(int argc, char*argv[])
+{
+ setepsv4(argc,argv);
+ setepsv6(argc,argv);
+}
+
+void
setsunique(int argc, char *argv[])
{
@@ -2240,11 +2272,11 @@ parserate(int argc, char *argv[], int cmdlineopt)
if (argc > 4 || (argc < (cmdlineopt ? 3 : 2))) {
usage:
if (cmdlineopt)
- fprintf(ttyout,
+ UPRINTF(
"usage: %s (all|get|put),maximum-bytes[,increment-bytes]]\n",
argv[0]);
else
- fprintf(ttyout,
+ UPRINTF(
"usage: %s (all|get|put) [maximum-bytes [increment-bytes]]\n",
argv[0]);
return -1;
@@ -2316,7 +2348,7 @@ cdup(int argc, char *argv[])
int r;
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -2341,7 +2373,7 @@ restart(int argc, char *argv[])
{
if (argc == 0 || argc > 2) {
- fprintf(ttyout, "usage: %s [restart-point]\n", argv[0]);
+ UPRINTF("usage: %s [restart-point]\n", argv[0]);
code = -1;
return;
}
@@ -2378,7 +2410,7 @@ syst(int argc, char *argv[])
int oldverbose = verbose;
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -2403,7 +2435,7 @@ macdef(int argc, char *argv[])
}
if ((argc < 2 && !another(&argc, &argv, "macro name")) || argc > 2) {
usage:
- fprintf(ttyout, "usage: %s macro_name\n", argv[0]);
+ UPRINTF("usage: %s macro_name\n", argv[0]);
code = -1;
return;
}
@@ -2461,7 +2493,7 @@ sizecmd(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "remote-file"))) {
- fprintf(ttyout, "usage: %s remote-file\n", argv[0]);
+ UPRINTF("usage: %s remote-file\n", argv[0]);
code = -1;
return;
}
@@ -2482,13 +2514,14 @@ modtime(int argc, char *argv[])
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "remote-file"))) {
- fprintf(ttyout, "usage: %s remote-file\n", argv[0]);
+ UPRINTF("usage: %s remote-file\n", argv[0]);
code = -1;
return;
}
mtime = remotemodtime(argv[1], 1);
if (mtime != -1)
- fprintf(ttyout, "%s\t%s", argv[1], asctime(localtime(&mtime)));
+ fprintf(ttyout, "%s\t%s", argv[1],
+ rfc2822time(localtime(&mtime)));
code = (mtime > 0);
}
@@ -2500,7 +2533,7 @@ rmtstatus(int argc, char *argv[])
{
if (argc == 0) {
- fprintf(ttyout, "usage: %s [remote-file]\n", argv[0]);
+ UPRINTF("usage: %s [remote-file]\n", argv[0]);
code = -1;
return;
}
@@ -2526,12 +2559,13 @@ newer(int argc, char *argv[])
void
lpage(int argc, char *argv[])
{
- int len;
- char *p, *pager, *locfile;
+ size_t len;
+ const char *p;
+ char *pager, *locfile;
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "local-file"))) {
- fprintf(ttyout, "usage: %s local-file\n", argv[0]);
+ UPRINTF("usage: %s local-file\n", argv[0]);
code = -1;
return;
}
@@ -2543,7 +2577,7 @@ lpage(int argc, char *argv[])
if (EMPTYSTRING(p))
p = DEFAULTPAGER;
len = strlen(p) + strlen(locfile) + 2;
- pager = xmalloc(len);
+ pager = ftp_malloc(len);
(void)strlcpy(pager, p, len);
(void)strlcat(pager, " ", len);
(void)strlcat(pager, locfile, len);
@@ -2559,12 +2593,14 @@ lpage(int argc, char *argv[])
void
page(int argc, char *argv[])
{
- int ohash, orestart_point, overbose, len;
- char *p, *pager;
+ int ohash, orestart_point, overbose;
+ size_t len;
+ const char *p;
+ char *pager;
if (argc == 0 || argc > 2 ||
(argc == 1 && !another(&argc, &argv, "remote-file"))) {
- fprintf(ttyout, "usage: %s remote-file\n", argv[0]);
+ UPRINTF("usage: %s remote-file\n", argv[0]);
code = -1;
return;
}
@@ -2572,7 +2608,7 @@ page(int argc, char *argv[])
if (EMPTYSTRING(p))
p = DEFAULTPAGER;
len = strlen(p) + 2;
- pager = xmalloc(len);
+ pager = ftp_malloc(len);
pager[0] = '|';
(void)strlcpy(pager + 1, p, len - 1);
@@ -2597,7 +2633,7 @@ setxferbuf(int argc, char *argv[])
if (argc != 2) {
usage:
- fprintf(ttyout, "usage: %s size\n", argv[0]);
+ UPRINTF("usage: %s size\n", argv[0]);
code = -1;
return;
}
@@ -2637,7 +2673,7 @@ setoption(int argc, char *argv[])
code = -1;
if (argc == 0 || (argc != 1 && argc != 3)) {
- fprintf(ttyout, "usage: %s [option value]\n", argv[0]);
+ UPRINTF("usage: %s [option value]\n", argv[0]);
return;
}
@@ -2648,20 +2684,28 @@ setoption(int argc, char *argv[])
o->name, o->value ? o->value : "");
}
} else {
- o = getoption(argv[1]);
- if (o == NULL) {
- fprintf(ttyout, "No such option `%s'.\n", argv[1]);
- return;
- }
- FREEPTR(o->value);
- o->value = xstrdup(argv[2]);
- if (verbose)
- fprintf(ttyout, "Setting `%s' to `%s'.\n",
- o->name, o->value);
+ set_option(argv[1], argv[2], 1);
}
code = 0;
}
+void
+set_option(const char * option, const char * value, int doverbose)
+{
+ struct option *o;
+
+ o = getoption(option);
+ if (o == NULL) {
+ fprintf(ttyout, "No such option `%s'.\n", option);
+ return;
+ }
+ FREEPTR(o->value);
+ o->value = ftp_strdup(value);
+ if (verbose && doverbose)
+ fprintf(ttyout, "Setting `%s' to `%s'.\n",
+ o->name, o->value);
+}
+
/*
* Unset an option
*/
@@ -2672,7 +2716,7 @@ unsetoption(int argc, char *argv[])
code = -1;
if (argc == 0 || argc != 2) {
- fprintf(ttyout, "usage: %s option\n", argv[0]);
+ UPRINTF("usage: %s option\n", argv[0]);
return;
}
@@ -2695,7 +2739,7 @@ feat(int argc, char *argv[])
int oldverbose = verbose;
if (argc == 0) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
@@ -2715,7 +2759,7 @@ mlst(int argc, char *argv[])
int oldverbose = verbose;
if (argc < 1 || argc > 2) {
- fprintf(ttyout, "usage: %s [remote-path]\n", argv[0]);
+ UPRINTF("usage: %s [remote-path]\n", argv[0]);
code = -1;
return;
}
@@ -2735,7 +2779,7 @@ opts(int argc, char *argv[])
int oldverbose = verbose;
if (argc < 2 || argc > 3) {
- fprintf(ttyout, "usage: %s command [options]\n", argv[0]);
+ UPRINTF("usage: %s command [options]\n", argv[0]);
code = -1;
return;
}
diff --git a/src/cmdtab.c b/src/cmdtab.c
index 04efade1fd1ce..dec48e817abb9 100644
--- a/src/cmdtab.c
+++ b/src/cmdtab.c
@@ -1,7 +1,8 @@
-/* $NetBSD: cmdtab.c,v 1.44 2005/04/11 01:49:31 lukem Exp $ */
+/* $NetBSD: cmdtab.c,v 1.11 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -65,16 +59,23 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cmdtab.c 8.4 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: cmdtab.c,v 1.44 2005/04/11 01:49:31 lukem Exp $");
+__RCSID(" NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp ");
#endif
#endif /* not lint */
#include <stdio.h>
+
+#endif /* tnftp */
+
#include "ftp_var.h"
/*
@@ -100,7 +101,9 @@ HSTR deletehelp[] = "delete remote file";
HSTR disconhelp[] = "terminate ftp session";
HSTR domachelp[] = "execute macro";
HSTR edithelp[] = "toggle command line editing";
+HSTR epsvhelp[] = "toggle use of EPSV/EPRT on both IPv4 and IPV6 ftp";
HSTR epsv4help[] = "toggle use of EPSV/EPRT on IPv4 ftp";
+HSTR epsv6help[] = "toggle use of EPSV/EPRT on IPv6 ftp";
HSTR feathelp[] = "show FEATures supported by remote system";
HSTR formhelp[] = "set file transfer format";
HSTR gatehelp[] = "toggle gate-ftp; specify host[:port] to change proxy";
@@ -211,7 +214,9 @@ struct cmd cmdtab[] = {
{ "dir", H(lshelp), 1, 1, 1, CMPL(rl) ls },
{ "disconnect", H(disconhelp), 0, 1, 1, CMPL0 disconnect },
{ "edit", H(edithelp), 0, 0, 0, CMPL0 setedit },
+ { "epsv", H(epsvhelp), 0, 0, 0, CMPL0 setepsv },
{ "epsv4", H(epsv4help), 0, 0, 0, CMPL0 setepsv4 },
+ { "epsv6", H(epsv6help), 0, 0, 0, CMPL0 setepsv6 },
{ "exit", H(quithelp), 0, 0, 0, CMPL0 quit },
{ "features", H(feathelp), 0, 1, 1, CMPL0 feat },
{ "fget", H(fgethelp), 1, 1, 1, CMPL(l) fget },
@@ -294,7 +299,7 @@ struct cmd cmdtab[] = {
{ "verbose", H(verbosehelp), 0, 0, 0, CMPL0 setverbose },
{ "xferbuf", H(xferbufhelp), 0, 0, 0, CMPL0 setxferbuf },
{ "?", H(helphelp), 0, 0, 1, CMPL(C) help },
- { 0 },
+ { NULL, NULL, 0, 0, 0, CMPL0 NULL },
};
struct option optiontab[] = {
@@ -305,5 +310,5 @@ struct option optiontab[] = {
{ "pager", NULL },
{ "prompt", NULL },
{ "rprompt", NULL },
- { 0 },
+ { NULL, NULL },
};
diff --git a/src/complete.c b/src/complete.c
index 8831bc199420c..df75d3a417218 100644
--- a/src/complete.c
+++ b/src/complete.c
@@ -1,7 +1,8 @@
-/* $NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $ */
+/* $NetBSD: complete.c,v 1.10 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -36,9 +30,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $");
+__RCSID(" NetBSD: complete.c,v 1.46 2009/04/12 10:18:52 lukem Exp ");
#endif /* not lint */
/*
@@ -54,6 +52,8 @@ __RCSID("$NetBSD: complete.c,v 1.38 2000/05/01 10:35:17 lukem Exp $");
#include <stdlib.h>
#include <string.h>
+#endif /* tnftp */
+
#include "ftp_var.h"
#ifndef NO_EDITCOMPLETE
@@ -68,7 +68,7 @@ static unsigned char complete_remote (char *, int);
static int
comparstr(const void *a, const void *b)
{
- return (strcmp(*(const char **)a, *(const char **)b));
+ return (strcmp(*(const char * const *)a, *(const char * const *)b));
}
/*
@@ -87,7 +87,7 @@ complete_ambiguous(char *word, int list, StringList *words)
{
char insertstr[MAXPATHLEN];
char *lastmatch, *p;
- int i, j;
+ size_t i, j;
size_t matchlen, wordlen;
wordlen = strlen(word);
@@ -143,14 +143,14 @@ complete_command(char *word, int list)
size_t wordlen;
unsigned char rv;
- words = xsl_init();
+ words = ftp_sl_init();
wordlen = strlen(word);
for (c = cmdtab; c->c_name != NULL; c++) {
if (wordlen > strlen(c->c_name))
continue;
if (strncmp(word, c->c_name, wordlen) == 0)
- xsl_add(words, c->c_name);
+ ftp_sl_add(words, ftp_strdup(c->c_name));
}
rv = complete_ambiguous(word, list, words);
@@ -158,7 +158,7 @@ complete_command(char *word, int list)
if (el_insertstr(el, " ") == -1)
rv = CC_ERROR;
}
- sl_free(words, 0);
+ sl_free(words, 1);
return (rv);
}
@@ -200,7 +200,7 @@ complete_local(char *word, int list)
if ((dd = opendir(dir)) == NULL)
return (CC_ERROR);
- words = xsl_init();
+ words = ftp_sl_init();
len = strlen(file);
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
@@ -217,8 +217,8 @@ complete_local(char *word, int list)
if (strncmp(file, dp->d_name, len) == 0) {
char *tcp;
- tcp = xstrdup(dp->d_name);
- xsl_add(words, tcp);
+ tcp = ftp_strdup(dp->d_name);
+ ftp_sl_add(words, tcp);
}
}
closedir(dd);
@@ -255,14 +255,14 @@ complete_option(char *word, int list)
size_t wordlen;
unsigned char rv;
- words = xsl_init();
+ words = ftp_sl_init();
wordlen = strlen(word);
for (o = optiontab; o->name != NULL; o++) {
if (wordlen > strlen(o->name))
continue;
if (strncmp(word, o->name, wordlen) == 0)
- xsl_add(words, o->name);
+ ftp_sl_add(words, ftp_strdup(o->name));
}
rv = complete_ambiguous(word, list, words);
@@ -270,7 +270,7 @@ complete_option(char *word, int list)
if (el_insertstr(el, " ") == -1)
rv = CC_ERROR;
}
- sl_free(words, 0);
+ sl_free(words, 1);
return (rv);
}
@@ -285,10 +285,13 @@ complete_remote(char *word, int list)
StringList *words;
char dir[MAXPATHLEN];
char *file, *cp;
- int i;
+ size_t i;
unsigned char rv;
+ char cmdbuf[MAX_C_NAME];
+ char *dummyargv[3] = { NULL, NULL, NULL };
- char *dummyargv[] = { "complete", NULL, NULL };
+ (void)strlcpy(cmdbuf, "complete", sizeof(cmdbuf));
+ dummyargv[0] = cmdbuf;
dummyargv[1] = dir;
if ((file = strrchr(word, '/')) == NULL) {
@@ -304,11 +307,11 @@ complete_remote(char *word, int list)
if (dirchange || dirlist == NULL ||
strcmp(dir, lastdir) != 0) { /* dir not cached */
- char *emesg;
+ const char *emesg;
if (dirlist != NULL)
sl_free(dirlist, 1);
- dirlist = xsl_init();
+ dirlist = ftp_sl_init();
mflag = 1;
emesg = NULL;
@@ -326,8 +329,8 @@ complete_remote(char *word, int list)
tcp++;
else
tcp = cp;
- tcp = xstrdup(tcp);
- xsl_add(dirlist, tcp);
+ tcp = ftp_strdup(tcp);
+ ftp_sl_add(dirlist, tcp);
}
if (emesg != NULL) {
fprintf(ttyout, "\n%s\n", emesg);
@@ -337,13 +340,13 @@ complete_remote(char *word, int list)
dirchange = 0;
}
- words = xsl_init();
+ words = ftp_sl_init();
for (i = 0; i < dirlist->sl_cur; i++) {
cp = dirlist->sl_str[i];
if (strlen(file) > strlen(cp))
continue;
if (strncmp(file, cp, strlen(file)) == 0)
- xsl_add(words, cp);
+ ftp_sl_add(words, cp);
}
rv = complete_ambiguous(file, list, words);
sl_free(words, 0);
@@ -354,17 +357,17 @@ complete_remote(char *word, int list)
* Generic complete routine
*/
unsigned char
-complete(EditLine *el, int ch)
+complete(EditLine *cel, int ch)
{
static char word[FTPBUFLEN];
- static int lastc_argc, lastc_argo;
+ static size_t lastc_argc, lastc_argo;
struct cmd *c;
const LineInfo *lf;
- int celems, dolist, cmpltype;
- size_t len;
+ int dolist, cmpltype;
+ size_t celems, len;
- lf = el_line(el);
+ lf = el_line(cel);
len = lf->lastchar - lf->buffer;
if (len >= sizeof(line))
return (CC_ERROR);
@@ -383,7 +386,7 @@ complete(EditLine *el, int ch)
&& strncmp(word, margv[cursor_argc] ? margv[cursor_argc] : "",
cursor_argo) == 0)
dolist = 1;
- else if (cursor_argc < margc)
+ else if (cursor_argc < (size_t)margc)
(void)strlcpy(word, margv[cursor_argc], cursor_argo + 1);
word[cursor_argo] = '\0';
@@ -426,7 +429,8 @@ complete(EditLine *el, int ch)
}
return (complete_remote(word, dolist));
default:
- errx(1, "unknown complete type `%c'", cmpltype);
+ errx(1, "complete: unknown complete type `%c'",
+ cmpltype);
return (CC_ERROR);
}
/* NOTREACHED */
diff --git a/src/domacro.c b/src/domacro.c
index 2e10e1c69e88d..b8fde0c4df347 100644
--- a/src/domacro.c
+++ b/src/domacro.c
@@ -1,4 +1,5 @@
-/* $NetBSD: domacro.c,v 1.20 2003/08/07 11:13:53 agc Exp $ */
+/* $NetBSD: domacro.c,v 1.8 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: domacro.c,v 1.22 2009/04/12 10:18:52 lukem Exp */
/*
* Copyright (c) 1985, 1993, 1994
@@ -29,12 +30,16 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)domacro.c 8.3 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: domacro.c,v 1.20 2003/08/07 11:13:53 agc Exp $");
+__RCSID(" NetBSD: domacro.c,v 1.22 2009/04/12 10:18:52 lukem Exp ");
#endif
#endif /* not lint */
@@ -42,6 +47,8 @@ __RCSID("$NetBSD: domacro.c,v 1.20 2003/08/07 11:13:53 agc Exp $");
#include <stdio.h>
#include <string.h>
+#endif /* tnftp */
+
#include "ftp_var.h"
void
@@ -50,10 +57,11 @@ domacro(int argc, char *argv[])
int i, j, count = 2, loopflg = 0;
char *cp1, *cp2, line2[FTPBUFLEN];
struct cmd *c;
+ char cmdbuf[MAX_C_NAME];
if ((argc == 0 && argv != NULL) ||
(argc < 2 && !another(&argc, &argv, "macro name"))) {
- fprintf(ttyout, "usage: %s macro_name [args]\n", argv[0]);
+ UPRINTF("usage: %s macro_name [args]\n", argv[0]);
code = -1;
return;
}
@@ -126,7 +134,8 @@ domacro(int argc, char *argv[])
fputs(line, ttyout);
putc('\n', ttyout);
}
- margv[0] = c->c_name;
+ (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
+ margv[0] = cmdbuf;
(*c->c_handler)(margc, margv);
if (bell && c->c_bell)
(void)putc('\007', ttyout);
diff --git a/src/extern.h b/src/extern.h
index f2b802ac5b0ca..9b6c6458c2ec5 100644
--- a/src/extern.h
+++ b/src/extern.h
@@ -1,7 +1,8 @@
-/* $NetBSD: extern.h,v 1.67 2005/05/14 15:26:43 lukem Exp $ */
+/* $NetBSD: extern.h,v 1.12 2009/11/15 10:12:37 lukem Exp $ */
+/* from NetBSD: extern.h,v 1.77 2009/07/13 19:05:41 roy Exp */
/*-
- * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -118,7 +112,7 @@ void cmdabort(int);
void cmdtimeout(int);
void cmdscanner(void);
int command(const char *, ...)
- __attribute__((__format__(__printf__, 1, 2)));
+ ;
#ifndef NO_EDITCOMPLETE
unsigned char complete(EditLine *, int);
void controlediting(void);
@@ -141,6 +135,7 @@ int ftp_login(const char *, const char *, const char *);
void get(int, char **);
struct cmd *getcmd(const char *);
int getit(int, char **, int, const char *);
+int get_line(FILE *, char *, size_t, const char **);
struct option *getoption(const char *);
char *getoptionvalue(const char *);
void getremoteinfo(void);
@@ -148,7 +143,7 @@ int getreply(int);
char *globulize(const char *);
char *gunique(const char *);
void help(int, char **);
-char *hookup(char *, char *);
+char *hookup(const char *, const char *);
void idlecmd(int, char **);
int initconn(void);
void intr(int);
@@ -159,22 +154,19 @@ void lostpeer(int);
void lpage(int, char **);
void lpwd(int, char **);
void ls(int, char **);
-void mabort(void);
void macdef(int, char **);
void makeargv(void);
void makedir(int, char **);
void mdelete(int, char **);
void mget(int, char **);
-void mintr(int);
void mls(int, char **);
void mlst(int, char **);
void modtime(int, char **);
void mput(int, char **);
-char *onoff(int);
+const char *onoff(int);
void opts(int, char **);
void newer(int, char **);
void page(int, char **);
-int parseport(const char *, int);
int parserate(int, char **, int);
char *prompt(void);
void proxabort(int);
@@ -189,18 +181,18 @@ void quote1(const char *, int, char **);
void recvrequest(const char *, const char *, const char *,
const char *, int, int);
void reget(int, char **);
-char *remglob(char **, int, char **);
+char *remglob(char **, int, const char **);
time_t remotemodtime(const char *, int);
off_t remotesize(const char *, int);
void removedir(int, char **);
void renamefile(int, char **);
void reset(int, char **);
void restart(int, char **);
+const char *rfc2822time(const struct tm *);
void rmthelp(int, char **);
void rmtstatus(int, char **);
char *rprompt(void);
-int ruserpass(const char *, const char **, const char **,
- const char **);
+int ruserpass(const char *, char **, char **, char **);
void sendrequest(const char *, const char *, const char *, int);
void setascii(int, char **);
void setbell(int, char **);
@@ -210,6 +202,8 @@ void setcr(int, char **);
void setdebug(int, char **);
void setedit(int, char **);
void setepsv4(int, char **);
+void setepsv6(int, char **);
+void setepsv(int, char **);
void setform(int, char **);
void setftmode(int, char **);
void setgate(int, char **);
@@ -235,6 +229,7 @@ void settype(int, char **);
void setupsockbufsize(int);
void setverbose(int, char **);
void setxferbuf(int, char **);
+void set_option(const char *, const char *, int);
void shell(int, char **);
void site(int, char **);
void sizecmd(int, char **);
@@ -248,10 +243,10 @@ void updatelocalcwd(void);
void updateremotecwd(void);
void usage(void);
void user(int, char **);
-int xconnect(int, const struct sockaddr *, socklen_t);
-int xlisten(int, int);
-int xpoll(struct pollfd *, int, int);
-void *xmalloc(size_t);
-StringList *xsl_init(void);
-void xsl_add(StringList *, char *);
-char *xstrdup(const char *);
+int ftp_connect(int, const struct sockaddr *, socklen_t);
+int ftp_listen(int, int);
+int ftp_poll(struct pollfd *, int, int);
+void *ftp_malloc(size_t);
+StringList *ftp_sl_init(void);
+void ftp_sl_add(StringList *, char *);
+char *ftp_strdup(const char *);
diff --git a/src/fetch.c b/src/fetch.c
index e2acb01de178d..91b49fd2435a6 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -1,7 +1,8 @@
-/* $NetBSD: fetch.c,v 1.158 2005/05/14 15:26:43 lukem Exp $ */
+/* $NetBSD: fetch.c,v 1.18 2009/11/15 10:12:37 lukem Exp $ */
+/* from NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp */
/*-
- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -18,13 +19,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -39,9 +33,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fetch.c,v 1.158 2005/05/14 15:26:43 lukem Exp $");
+__RCSID(" NetBSD: fetch.c,v 1.191 2009/08/17 09:08:16 christos Exp ");
#endif /* not lint */
/*
@@ -69,7 +67,8 @@ __RCSID("$NetBSD: fetch.c,v 1.158 2005/05/14 15:26:43 lukem Exp $");
#include <string.h>
#include <unistd.h>
#include <time.h>
-#include <libutil.h>
+
+#endif /* tnftp */
#include "ftp_var.h"
#include "version.h"
@@ -113,7 +112,7 @@ static int redirect_loop;
* Determine if token is the next word in buf (case insensitive).
* If so, advance buf past the token and any trailing LWS, and
* return a pointer to the token (in buf). Otherwise, return NULL.
- * token may be preceeded by LWS.
+ * token may be preceded by LWS.
* token must be followed by LWS or NUL. (I.e, don't partial match).
*/
static const char *
@@ -147,9 +146,10 @@ static int
auth_url(const char *challenge, char **response, const char *guser,
const char *gpass)
{
- const char *cp, *scheme;
+ const char *cp, *scheme, *errormsg;
char *ep, *clear, *realm;
- char user[BUFSIZ], *pass;
+ char uuser[BUFSIZ], *gotpass;
+ const char *upass;
int rval;
size_t len, clen, rlen;
@@ -158,12 +158,12 @@ auth_url(const char *challenge, char **response, const char *guser,
rval = -1;
cp = challenge;
scheme = "Basic"; /* only support Basic authentication */
+ gotpass = NULL;
- if (debug)
- fprintf(ttyout, "auth_url: challenge `%s'\n", challenge);
+ DPRINTF("auth_url: challenge `%s'\n", challenge);
if (! match_token(&cp, scheme)) {
- warnx("Unsupported authentication challenge - `%s'",
+ warnx("Unsupported authentication challenge `%s'",
challenge);
goto cleanup_auth_url;
}
@@ -172,50 +172,54 @@ auth_url(const char *challenge, char **response, const char *guser,
if (STRNEQUAL(cp, REALM))
cp += sizeof(REALM) - 1;
else {
- warnx("Unsupported authentication challenge - `%s'",
+ warnx("Unsupported authentication challenge `%s'",
challenge);
goto cleanup_auth_url;
}
/* XXX: need to improve quoted-string parsing to support \ quoting, etc. */
if ((ep = strchr(cp, '\"')) != NULL) {
- size_t len = ep - cp;
-
- realm = (char *)xmalloc(len + 1);
+ len = ep - cp;
+ realm = (char *)ftp_malloc(len + 1);
(void)strlcpy(realm, cp, len + 1);
} else {
- warnx("Unsupported authentication challenge - `%s'",
+ warnx("Unsupported authentication challenge `%s'",
challenge);
goto cleanup_auth_url;
}
fprintf(ttyout, "Username for `%s': ", realm);
if (guser != NULL) {
- (void)strlcpy(user, guser, sizeof(user));
- fprintf(ttyout, "%s\n", user);
+ (void)strlcpy(uuser, guser, sizeof(uuser));
+ fprintf(ttyout, "%s\n", uuser);
} else {
(void)fflush(ttyout);
- if (fgets(user, sizeof(user) - 1, stdin) == NULL) {
- clearerr(stdin);
+ if (get_line(stdin, uuser, sizeof(uuser), &errormsg) < 0) {
+ warnx("%s; can't authenticate", errormsg);
goto cleanup_auth_url;
}
- user[strlen(user) - 1] = '\0';
}
if (gpass != NULL)
- pass = (char *)gpass;
- else
- pass = getpass("Password: ");
+ upass = gpass;
+ else {
+ gotpass = getpass("Password: ");
+ if (gotpass == NULL) {
+ warnx("Can't read password");
+ goto cleanup_auth_url;
+ }
+ upass = gotpass;
+ }
- clen = strlen(user) + strlen(pass) + 2; /* user + ":" + pass + "\0" */
- clear = (char *)xmalloc(clen);
- (void)strlcpy(clear, user, clen);
+ clen = strlen(uuser) + strlen(upass) + 2; /* user + ":" + pass + "\0" */
+ clear = (char *)ftp_malloc(clen);
+ (void)strlcpy(clear, uuser, clen);
(void)strlcat(clear, ":", clen);
- (void)strlcat(clear, pass, clen);
- if (gpass == NULL)
- memset(pass, 0, strlen(pass));
+ (void)strlcat(clear, upass, clen);
+ if (gotpass)
+ memset(gotpass, 0, strlen(gotpass));
/* scheme + " " + enc + "\0" */
rlen = strlen(scheme) + 1 + (clen + 2) * 4 / 3 + 1;
- *response = (char *)xmalloc(rlen);
+ *response = (char *)ftp_malloc(rlen);
(void)strlcpy(*response, scheme, rlen);
len = strlcat(*response, " ", rlen);
/* use `clen - 1' to not encode the trailing NUL */
@@ -240,7 +244,7 @@ base64_encode(const unsigned char *clear, size_t len, unsigned char *encoded)
static const unsigned char enc[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned char *cp;
- int i;
+ size_t i;
cp = encoded;
for (i = 0; i < len; i += 3) {
@@ -284,7 +288,7 @@ url_decode(char *url)
/*
- * Parse URL of form:
+ * Parse URL of form (per RFC3986):
* <type>://[<user>[:<password>]@]<host>[:<port>][/<path>]
* Returns -1 if a parse error occurred, otherwise 0.
* It's the caller's responsibility to url_decode() the returned
@@ -294,12 +298,9 @@ url_decode(char *url)
* malloc(3)ed strings of the relevant section, and port to
* the number given, or ftpport if ftp://, or httpport if http://.
*
- * If <host> is surrounded by `[' and ']', it's parsed as an
- * IPv6 address (as per RFC 2732).
- *
- * XXX: this is not totally RFC 1738 compliant; <path> will have the
+ * XXX: this is not totally RFC3986 compliant; <path> will have the
* leading `/' unless it's an ftp:// URL, as this makes things easier
- * for file:// and http:// URLs. ftp:// URLs have the `/' between the
+ * for file:// and http:// URLs. ftp:// URLs have the `/' between the
* host and the URL-path removed, but any additional leading slashes
* in the URL-path are retained (because they imply that we should
* later do "CWD" with a null argument).
@@ -307,50 +308,56 @@ url_decode(char *url)
* Examples:
* input URL output path
* --------- -----------
- * "ftp://host" NULL
- * "http://host/" NULL
+ * "http://host" "/"
+ * "http://host/" "/"
+ * "http://host/path" "/path"
* "file://host/dir/file" "dir/file"
+ * "ftp://host" ""
* "ftp://host/" ""
- * "ftp://host//" NULL
+ * "ftp://host//" "/"
+ * "ftp://host/dir/file" "dir/file"
* "ftp://host//dir/file" "/dir/file"
*/
static int
-parse_url(const char *url, const char *desc, url_t *type,
- char **user, char **pass, char **host, char **port,
+parse_url(const char *url, const char *desc, url_t *utype,
+ char **uuser, char **pass, char **host, char **port,
in_port_t *portnum, char **path)
{
- const char *origurl;
- char *cp, *ep, *thost, *tport;
+ const char *origurl, *tport;
+ char *cp, *ep, *thost;
size_t len;
- if (url == NULL || desc == NULL || type == NULL || user == NULL
+ if (url == NULL || desc == NULL || utype == NULL || uuser == NULL
|| pass == NULL || host == NULL || port == NULL || portnum == NULL
|| path == NULL)
errx(1, "parse_url: invoked with NULL argument!");
+ DPRINTF("parse_url: %s `%s'\n", desc, url);
origurl = url;
- *type = UNKNOWN_URL_T;
- *user = *pass = *host = *port = *path = NULL;
+ *utype = UNKNOWN_URL_T;
+ *uuser = *pass = *host = *port = *path = NULL;
*portnum = 0;
tport = NULL;
if (STRNEQUAL(url, HTTP_URL)) {
url += sizeof(HTTP_URL) - 1;
- *type = HTTP_URL_T;
+ *utype = HTTP_URL_T;
*portnum = HTTP_PORT;
tport = httpport;
} else if (STRNEQUAL(url, FTP_URL)) {
url += sizeof(FTP_URL) - 1;
- *type = FTP_URL_T;
+ *utype = FTP_URL_T;
*portnum = FTP_PORT;
tport = ftpport;
} else if (STRNEQUAL(url, FILE_URL)) {
url += sizeof(FILE_URL) - 1;
- *type = FILE_URL_T;
+ *utype = FILE_URL_T;
} else {
warnx("Invalid %s `%s'", desc, url);
cleanup_parse_url:
- FREEPTR(*user);
+ FREEPTR(*uuser);
+ if (*pass != NULL)
+ memset(*pass, 0, strlen(*pass));
FREEPTR(*pass);
FREEPTR(*host);
FREEPTR(*port);
@@ -364,29 +371,29 @@ parse_url(const char *url, const char *desc, url_t *type,
/* find [user[:pass]@]host[:port] */
ep = strchr(url, '/');
if (ep == NULL)
- thost = xstrdup(url);
+ thost = ftp_strdup(url);
else {
len = ep - url;
- thost = (char *)xmalloc(len + 1);
+ thost = (char *)ftp_malloc(len + 1);
(void)strlcpy(thost, url, len + 1);
- if (*type == FTP_URL_T) /* skip first / for ftp URLs */
+ if (*utype == FTP_URL_T) /* skip first / for ftp URLs */
ep++;
- *path = xstrdup(ep);
+ *path = ftp_strdup(ep);
}
cp = strchr(thost, '@'); /* look for user[:pass]@ in URLs */
if (cp != NULL) {
- if (*type == FTP_URL_T)
+ if (*utype == FTP_URL_T)
anonftp = 0; /* disable anonftp */
- *user = thost;
+ *uuser = thost;
*cp = '\0';
- thost = xstrdup(cp + 1);
- cp = strchr(*user, ':');
+ thost = ftp_strdup(cp + 1);
+ cp = strchr(*uuser, ':');
if (cp != NULL) {
*cp = '\0';
- *pass = xstrdup(cp + 1);
+ *pass = ftp_strdup(cp + 1);
}
- url_decode(*user);
+ url_decode(*uuser);
if (*pass)
url_decode(*pass);
}
@@ -394,7 +401,7 @@ parse_url(const char *url, const char *desc, url_t *type,
#ifdef INET6
/*
* Check if thost is an encoded IPv6 address, as per
- * RFC 2732:
+ * RFC3986:
* `[' ipv6-address ']'
*/
if (*thost == '[') {
@@ -420,16 +427,17 @@ parse_url(const char *url, const char *desc, url_t *type,
cp = NULL;
} else
#endif /* INET6 */
- if ((cp = strchr(thost, ':')) != NULL)
- *cp++ = '\0';
+ if ((cp = strchr(thost, ':')) != NULL)
+ *cp++ = '\0';
*host = thost;
/* look for [:port] */
if (cp != NULL) {
- long nport;
+ unsigned long nport;
- nport = parseport(cp, -1);
- if (nport == -1) {
+ nport = strtoul(cp, &ep, 10);
+ if (*cp == '\0' || *ep != '\0' ||
+ nport < 1 || nport > MAX_IN_PORT_T) {
warnx("Unknown port `%s' in %s `%s'",
cp, desc, origurl);
goto cleanup_parse_url;
@@ -439,17 +447,19 @@ parse_url(const char *url, const char *desc, url_t *type,
}
if (tport != NULL)
- *port = xstrdup(tport);
- if (*path == NULL)
- *path = xstrdup("/");
-
- if (debug)
- fprintf(ttyout,
- "parse_url: user `%s' pass `%s' host %s port %s(%d) "
- "path `%s'\n",
- *user ? *user : "<null>", *pass ? *pass : "<null>",
- *host ? *host : "<null>", *port ? *port : "<null>",
- *portnum ? *portnum : -1, *path ? *path : "<null>");
+ *port = ftp_strdup(tport);
+ if (*path == NULL) {
+ const char *emptypath = "/";
+ if (*utype == FTP_URL_T) /* skip first / for ftp URLs */
+ emptypath++;
+ *path = ftp_strdup(emptypath);
+ }
+
+ DPRINTF("parse_url: user `%s' pass `%s' host %s port %s(%d) "
+ "path `%s'\n",
+ STRorNULL(*uuser), STRorNULL(*pass),
+ STRorNULL(*host), STRorNULL(*port),
+ *portnum ? *portnum : -1, STRorNULL(*path));
return (0);
}
@@ -469,53 +479,50 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
{
struct addrinfo hints, *res, *res0 = NULL;
int error;
- char hbuf[NI_MAXHOST];
- volatile sigfunc oldintr, oldintp;
- volatile int s;
+ sigfunc volatile oldintr;
+ sigfunc volatile oldintp;
+ int volatile s;
struct stat sb;
- int ischunked, isproxy, rval, hcode;
- size_t len;
+ int volatile ischunked;
+ int volatile isproxy;
+ int volatile rval;
+ int volatile hcode;
+ int len;
+ size_t flen;
static size_t bufsize;
static char *xferbuf;
const char *cp, *token;
- char *ep, *buf, *savefile;
- char *auth, *location, *message;
- char *user, *pass, *host, *port, *path, *decodedpath;
+ char *ep;
+ char buf[FTPBUFLEN];
+ const char *errormsg;
+ char *volatile savefile;
+ char *volatile auth;
+ char *volatile location;
+ char *volatile message;
+ char *uuser, *pass, *host, *port, *path;
+ char *volatile decodedpath;
char *puser, *ppass, *useragent;
off_t hashbytes, rangestart, rangeend, entitylen;
- int (*closefunc)(FILE *);
- FILE *fin, *fout;
+ int (*volatile closefunc)(FILE *);
+ FILE *volatile fin;
+ FILE *volatile fout;
time_t mtime;
url_t urltype;
in_port_t portnum;
+ DPRINTF("fetch_url: `%s' proxyenv `%s'\n", url, STRorNULL(proxyenv));
+
oldintr = oldintp = NULL;
closefunc = NULL;
fin = fout = NULL;
s = -1;
- buf = savefile = NULL;
+ savefile = NULL;
auth = location = message = NULL;
ischunked = isproxy = hcode = 0;
rval = 1;
- user = pass = host = path = decodedpath = puser = ppass = NULL;
-
-#ifdef __GNUC__ /* shut up gcc warnings */
- (void)&closefunc;
- (void)&fin;
- (void)&fout;
- (void)&buf;
- (void)&savefile;
- (void)&rval;
- (void)&isproxy;
- (void)&hcode;
- (void)&ischunked;
- (void)&message;
- (void)&location;
- (void)&auth;
- (void)&decodedpath;
-#endif
+ uuser = pass = host = path = decodedpath = puser = ppass = NULL;
- if (parse_url(url, "URL", &urltype, &user, &pass, &host, &port,
+ if (parse_url(url, "URL", &urltype, &uuser, &pass, &host, &port,
&portnum, &path) == -1)
goto cleanup_fetch_url;
@@ -536,29 +543,27 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
}
}
- decodedpath = xstrdup(path);
+ decodedpath = ftp_strdup(path);
url_decode(decodedpath);
if (outfile)
- savefile = xstrdup(outfile);
+ savefile = ftp_strdup(outfile);
else {
cp = strrchr(decodedpath, '/'); /* find savefile */
if (cp != NULL)
- savefile = xstrdup(cp + 1);
+ savefile = ftp_strdup(cp + 1);
else
- savefile = xstrdup(decodedpath);
+ savefile = ftp_strdup(decodedpath);
}
+ DPRINTF("fetch_url: savefile `%s'\n", savefile);
if (EMPTYSTRING(savefile)) {
if (urltype == FTP_URL_T) {
rval = fetch_ftp(url);
goto cleanup_fetch_url;
}
- warnx("no file after directory (you must specify an "
+ warnx("No file after directory (you must specify an "
"output file) `%s'", url);
goto cleanup_fetch_url;
- } else {
- if (debug)
- fprintf(ttyout, "savefile `%s'\n", savefile);
}
restart_point = 0;
@@ -574,7 +579,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
direction = "copied";
fin = fopen(decodedpath, "r");
if (fin == NULL) {
- warn("Cannot open file `%s'", decodedpath);
+ warn("Can't open `%s'", decodedpath);
goto cleanup_fetch_url;
}
if (fstat(fileno(fin), &sb) == 0) {
@@ -583,7 +588,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
}
if (restart_point) {
if (lseek(fileno(fin), restart_point, SEEK_SET) < 0) {
- warn("Can't lseek to restart `%s'",
+ warn("Can't seek to restart `%s'",
decodedpath);
goto cleanup_fetch_url;
}
@@ -596,7 +601,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
fputs("\n", ttyout);
}
} else { /* ftp:// or http:// URLs */
- char *leading;
+ const char *leading;
int hasleading;
if (proxyenv == NULL) {
@@ -610,26 +615,26 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
url_t purltype;
char *phost, *ppath;
char *pport, *no_proxy;
+ in_port_t pportnum;
isproxy = 1;
/* check URL against list of no_proxied sites */
no_proxy = getoptionvalue("no_proxy");
if (! EMPTYSTRING(no_proxy)) {
- char *np, *np_copy;
- long np_port;
+ char *np, *np_copy, *np_iter;
+ unsigned long np_port;
size_t hlen, plen;
- np_copy = xstrdup(no_proxy);
+ np_iter = np_copy = ftp_strdup(no_proxy);
hlen = strlen(host);
- while ((cp = strsep(&np_copy, " ,")) != NULL) {
+ while ((cp = strsep(&np_iter, " ,")) != NULL) {
if (*cp == '\0')
continue;
if ((np = strrchr(cp, ':')) != NULL) {
- *np = '\0';
- np_port =
- strtol(np + 1, &ep, 10);
- if (*ep != '\0')
+ *np++ = '\0';
+ np_port = strtoul(np, &ep, 10);
+ if (*np == '\0' || *ep != '\0')
continue;
if (np_port != portnum)
continue;
@@ -651,8 +656,13 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
}
if (isproxy) {
+ if (restart_point) {
+ warnx("Can't restart via proxy URL `%s'",
+ proxyenv);
+ goto cleanup_fetch_url;
+ }
if (parse_url(proxyenv, "proxy URL", &purltype,
- &puser, &ppass, &phost, &pport, &portnum,
+ &puser, &ppass, &phost, &pport, &pportnum,
&ppath) == -1)
goto cleanup_fetch_url;
@@ -684,7 +694,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
FREEPTR(port);
port = pport;
FREEPTR(path);
- path = xstrdup(url);
+ path = ftp_strdup(url);
FREEPTR(ppath);
}
} /* ! EMPTYSTRING(proxyenv) */
@@ -694,9 +704,11 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- error = getaddrinfo(host, NULL, &hints, &res0);
+ error = getaddrinfo(host, port, &hints, &res0);
if (error) {
- warnx("%s", gai_strerror(error));
+ warnx("Can't lookup `%s:%s': %s", host, port,
+ (error == EAI_SYSTEM) ? strerror(errno)
+ : gai_strerror(error));
goto cleanup_fetch_url;
}
if (res0->ai_canonname)
@@ -704,28 +716,31 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
s = -1;
for (res = res0; res; res = res->ai_next) {
- /*
- * see comment in hookup()
- */
+ char hname[NI_MAXHOST], sname[NI_MAXSERV];
+
ai_unmapped(res);
if (getnameinfo(res->ai_addr, res->ai_addrlen,
- hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST) != 0)
- strlcpy(hbuf, "invalid", sizeof(hbuf));
+ hname, sizeof(hname), sname, sizeof(sname),
+ NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ strlcpy(hname, "?", sizeof(hname));
+ strlcpy(sname, "?", sizeof(sname));
+ }
- if (verbose && res != res0)
- fprintf(ttyout, "Trying %s...\n", hbuf);
+ if (verbose && res0->ai_next) {
+ fprintf(ttyout, "Trying %s:%s ...\n",
+ hname, sname);
+ }
- ((struct sockaddr_in *)res->ai_addr)->sin_port =
- htons(portnum);
s = socket(res->ai_family, SOCK_STREAM,
res->ai_protocol);
if (s < 0) {
- warn("Can't create socket");
+ warn(
+ "Can't create socket for connection to "
+ "`%s:%s'", hname, sname);
continue;
}
- if (xconnect(s, res->ai_addr, res->ai_addrlen) < 0) {
- warn("Connect to address `%s'", hbuf);
+ if (ftp_connect(s, res->ai_addr, res->ai_addrlen) < 0) {
close(s);
s = -1;
continue;
@@ -736,7 +751,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
}
if (s < 0) {
- warn("Can't connect to %s", host);
+ warnx("Can't connect to `%s:%s'", host, port);
goto cleanup_fetch_url;
}
@@ -767,7 +782,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
* strip off IPv6 scope identifier, since it is
* local to the node
*/
- h = xstrdup(host);
+ h = ftp_strdup(host);
if (isipv6addr(h) &&
(p = strchr(h, '%')) != NULL) {
*p = '\0';
@@ -826,14 +841,16 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
}
/* Read the response */
- if ((buf = fparseln(fin, &len, NULL, "\0\0\0", 0)) == NULL) {
- warn("Receiving HTTP reply");
+ len = get_line(fin, buf, sizeof(buf), &errormsg);
+ if (len < 0) {
+ if (*errormsg == '\n')
+ errormsg++;
+ warnx("Receiving HTTP reply: %s", errormsg);
goto cleanup_fetch_url;
}
while (len > 0 && (ISLWS(buf[len-1])))
buf[--len] = '\0';
- if (debug)
- fprintf(ttyout, "received `%s'\n", buf);
+ DPRINTF("fetch_url: received `%s'\n", buf);
/* Determine HTTP response code */
cp = strchr(buf, ' ');
@@ -844,22 +861,22 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
hcode = strtol(cp, &ep, 10);
if (*ep != '\0' && !isspace((unsigned char)*ep))
goto improper;
- message = xstrdup(cp);
+ message = ftp_strdup(cp);
/* Read the rest of the header. */
while (1) {
- FREEPTR(buf);
- if ((buf = fparseln(fin, &len, NULL, "\0\0\0", 0))
- == NULL) {
- warn("Receiving HTTP reply");
+ len = get_line(fin, buf, sizeof(buf), &errormsg);
+ if (len < 0) {
+ if (*errormsg == '\n')
+ errormsg++;
+ warnx("Receiving HTTP reply: %s", errormsg);
goto cleanup_fetch_url;
}
while (len > 0 && (ISLWS(buf[len-1])))
buf[--len] = '\0';
if (len == 0)
break;
- if (debug)
- fprintf(ttyout, "received `%s'\n", buf);
+ DPRINTF("fetch_url: received `%s'\n", buf);
/*
* Look for some headers
@@ -871,10 +888,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
filesize = STRTOLL(cp, &ep, 10);
if (filesize < 0 || *ep != '\0')
goto improper;
- if (debug)
- fprintf(ttyout,
- "parsed len as: " LLF "\n",
- (LLT)filesize);
+ DPRINTF("fetch_url: parsed len as: " LLF "\n",
+ (LLT)filesize);
} else if (match_token(&cp, "Content-Range:")) {
if (! match_token(&cp, "bytes"))
@@ -906,7 +921,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (*cp != '\0')
goto improper;
- if (debug) {
+#ifndef NO_DEBUG
+ if (ftp_debug) {
fprintf(ttyout, "parsed range as: ");
if (rangestart == -1)
fprintf(ttyout, "*");
@@ -916,6 +932,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
(LLT)rangeend);
fprintf(ttyout, "/" LLF "\n", (LLT)entitylen);
}
+#endif
if (! restart_point) {
warnx(
"Received unexpected Content-Range header");
@@ -926,11 +943,12 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
struct tm parsed;
char *t;
- /* RFC 1123 */
+ memset(&parsed, 0, sizeof(parsed));
+ /* RFC1123 */
if ((t = strptime(cp,
"%a, %d %b %Y %H:%M:%S GMT",
&parsed))
- /* RFC 850 */
+ /* RFC0850 */
|| (t = strptime(cp,
"%a, %d-%b-%y %H:%M:%S GMT",
&parsed))
@@ -941,55 +959,50 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
parsed.tm_isdst = -1;
if (*t == '\0')
mtime = timegm(&parsed);
- if (debug && mtime != -1) {
+#ifndef NO_DEBUG
+ if (ftp_debug && mtime != -1) {
fprintf(ttyout,
"parsed date as: %s",
- ctime(&mtime));
+ rfc2822time(localtime(&mtime)));
}
+#endif
}
} else if (match_token(&cp, "Location:")) {
- location = xstrdup(cp);
- if (debug)
- fprintf(ttyout,
- "parsed location as `%s'\n", cp);
+ location = ftp_strdup(cp);
+ DPRINTF("fetch_url: parsed location as `%s'\n",
+ cp);
} else if (match_token(&cp, "Transfer-Encoding:")) {
if (match_token(&cp, "binary")) {
warnx(
- "Bogus transfer encoding - `binary' (fetching anyway)");
+ "Bogus transfer encoding `binary' (fetching anyway)");
continue;
}
if (! (token = match_token(&cp, "chunked"))) {
warnx(
- "Unsupported transfer encoding - `%s'",
+ "Unsupported transfer encoding `%s'",
token);
goto cleanup_fetch_url;
}
ischunked++;
- if (debug)
- fprintf(ttyout,
- "using chunked encoding\n");
+ DPRINTF("fetch_url: using chunked encoding\n");
} else if (match_token(&cp, "Proxy-Authenticate:")
|| match_token(&cp, "WWW-Authenticate:")) {
if (! (token = match_token(&cp, "Basic"))) {
- if (debug)
- fprintf(ttyout,
- "skipping unknown auth scheme `%s'\n",
+ DPRINTF(
+ "fetch_url: skipping unknown auth scheme `%s'\n",
token);
continue;
}
FREEPTR(auth);
- auth = xstrdup(token);
- if (debug)
- fprintf(ttyout,
- "parsed auth as `%s'\n", cp);
+ auth = ftp_strdup(token);
+ DPRINTF("fetch_url: parsed auth as `%s'\n", cp);
}
}
/* finished parsing header */
- FREEPTR(buf);
switch (hcode) {
case 200:
@@ -1005,6 +1018,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
case 302:
case 303:
case 305:
+ case 307:
if (EMPTYSTRING(location)) {
warnx(
"No redirection Location provided by server");
@@ -1036,7 +1050,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (hcode == 401) {
authp = &wwwauth;
- auser = user;
+ auser = uuser;
apass = pass;
} else {
authp = &proxyauth;
@@ -1056,9 +1070,8 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
fprintf(ttyout,
"Authorization failed. Retry (y/n)? ");
- if (fgets(reply, sizeof(reply), stdin)
- == NULL) {
- clearerr(stdin);
+ if (get_line(stdin, reply, sizeof(reply), NULL)
+ < 0) {
goto cleanup_fetch_url;
}
if (tolower((unsigned char)reply[0]) != 'y')
@@ -1077,7 +1090,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
#endif
default:
if (message)
- warnx("Error retrieving file - `%s'", message);
+ warnx("Error retrieving file `%s'", message);
else
warnx("Unknown error retrieving file");
goto cleanup_fetch_url;
@@ -1091,7 +1104,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
oldintp = xsignal(SIGPIPE, SIG_IGN);
fout = popen(savefile + 1, "w");
if (fout == NULL) {
- warn("Can't run `%s'", savefile + 1);
+ warn("Can't execute `%s'", savefile + 1);
goto cleanup_fetch_url;
}
closefunc = pclose;
@@ -1129,11 +1142,11 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
(void)xsignal(SIGQUIT, psummary);
oldintr = xsignal(SIGINT, aborthttp);
- if (rcvbuf_size > bufsize) {
+ if ((size_t)rcvbuf_size > bufsize) {
if (xferbuf)
(void)free(xferbuf);
bufsize = rcvbuf_size;
- xferbuf = xmalloc(bufsize);
+ xferbuf = ftp_malloc(bufsize);
}
bytes = 0;
@@ -1143,33 +1156,53 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
/* Finally, suck down the file. */
do {
long chunksize;
+ short lastchunk;
chunksize = 0;
- /* read chunksize */
+ lastchunk = 0;
+ /* read chunk-size */
if (ischunked) {
if (fgets(xferbuf, bufsize, fin) == NULL) {
- warnx("Unexpected EOF reading chunksize");
+ warnx("Unexpected EOF reading chunk-size");
goto cleanup_fetch_url;
}
+ errno = 0;
chunksize = strtol(xferbuf, &ep, 16);
+ if (ep == xferbuf) {
+ warnx("Invalid chunk-size");
+ goto cleanup_fetch_url;
+ }
+ if (errno == ERANGE || chunksize < 0) {
+ errno = ERANGE;
+ warn("Chunk-size `%.*s'",
+ (int)(ep-xferbuf), xferbuf);
+ goto cleanup_fetch_url;
+ }
/*
* XXX: Work around bug in Apache 1.3.9 and
* 1.3.11, which incorrectly put trailing
- * space after the chunksize.
+ * space after the chunk-size.
*/
while (*ep == ' ')
ep++;
+ /* skip [ chunk-ext ] */
+ if (*ep == ';') {
+ while (*ep && *ep != '\r')
+ ep++;
+ }
+
if (strcmp(ep, "\r\n") != 0) {
- warnx("Unexpected data following chunksize");
+ warnx("Unexpected data following chunk-size");
goto cleanup_fetch_url;
}
- if (debug)
- fprintf(ttyout, "got chunksize of " LLF "\n",
- (LLT)chunksize);
- if (chunksize == 0)
- break;
+ DPRINTF("fetch_url: got chunk-size of " LLF "\n",
+ (LLT)chunksize);
+ if (chunksize == 0) {
+ lastchunk = 1;
+ goto chunkdone;
+ }
}
/* transfer file or chunk */
while (1) {
@@ -1178,18 +1211,18 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (rate_get)
(void)gettimeofday(&then, NULL);
- bufrem = rate_get ? rate_get : bufsize;
+ bufrem = rate_get ? rate_get : (off_t)bufsize;
if (ischunked)
bufrem = MIN(chunksize, bufrem);
while (bufrem > 0) {
- len = fread(xferbuf, sizeof(char),
- MIN(bufsize, bufrem), fin);
- if (len <= 0)
+ flen = fread(xferbuf, sizeof(char),
+ MIN((off_t)bufsize, bufrem), fin);
+ if (flen <= 0)
goto chunkdone;
- bytes += len;
- bufrem -= len;
- if (fwrite(xferbuf, sizeof(char), len, fout)
- != len) {
+ bytes += flen;
+ bufrem -= flen;
+ if (fwrite(xferbuf, sizeof(char), flen, fout)
+ != flen) {
warn("Writing `%s'", savefile);
goto cleanup_fetch_url;
}
@@ -1201,7 +1234,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
(void)fflush(ttyout);
}
if (ischunked) {
- chunksize -= len;
+ chunksize -= flen;
if (chunksize <= 0)
break;
}
@@ -1221,14 +1254,21 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
/* read CRLF after chunk*/
chunkdone:
if (ischunked) {
- if (fgets(xferbuf, bufsize, fin) == NULL)
- break;
+ if (fgets(xferbuf, bufsize, fin) == NULL) {
+ warnx("Unexpected EOF reading chunk CRLF");
+ goto cleanup_fetch_url;
+ }
if (strcmp(xferbuf, "\r\n") != 0) {
warnx("Unexpected data following chunk");
goto cleanup_fetch_url;
}
+ if (lastchunk)
+ break;
}
} while (ischunked);
+
+/* XXX: deal with optional trailer & CRLF here? */
+
if (hash && !progress && bytes > 0) {
if (bytes < mark)
(void)putc('#', ttyout);
@@ -1252,7 +1292,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (utimes(savefile, tval) == -1) {
fprintf(ttyout,
"Can't change modification time to %s",
- asctime(localtime(&mtime)));
+ rfc2822time(localtime(&mtime)));
}
}
if (bytes > 0)
@@ -1263,7 +1303,7 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
goto cleanup_fetch_url;
improper:
- warnx("Improper response from `%s'", host);
+ warnx("Improper response from `%s:%s'", host, port);
cleanup_fetch_url:
if (oldintr)
@@ -1279,15 +1319,18 @@ fetch_url(const char *url, const char *proxyenv, char *proxyauth, char *wwwauth)
if (res0)
freeaddrinfo(res0);
FREEPTR(savefile);
- FREEPTR(user);
+ FREEPTR(uuser);
+ if (pass != NULL)
+ memset(pass, 0, strlen(pass));
FREEPTR(pass);
FREEPTR(host);
FREEPTR(port);
FREEPTR(path);
FREEPTR(decodedpath);
FREEPTR(puser);
+ if (ppass != NULL)
+ memset(ppass, 0, strlen(ppass));
FREEPTR(ppass);
- FREEPTR(buf);
FREEPTR(auth);
FREEPTR(location);
FREEPTR(message);
@@ -1301,7 +1344,7 @@ void
aborthttp(int notused)
{
char msgbuf[100];
- int len;
+ size_t len;
sigint_raised = 1;
alarmtimer(0);
@@ -1319,21 +1362,25 @@ static int
fetch_ftp(const char *url)
{
char *cp, *xargv[5], rempath[MAXPATHLEN];
- char *host, *path, *dir, *file, *user, *pass;
+ char *host, *path, *dir, *file, *uuser, *pass;
char *port;
- int dirhasglob, filehasglob, oautologin, rval, type, xargc;
+ char cmdbuf[MAXPATHLEN];
+ char dirbuf[4];
+ int dirhasglob, filehasglob, rval, transtype, xargc;
+ int oanonftp, oautologin;
in_port_t portnum;
url_t urltype;
- host = path = dir = file = user = pass = NULL;
+ DPRINTF("fetch_ftp: `%s'\n", url);
+ host = path = dir = file = uuser = pass = NULL;
port = NULL;
rval = 1;
- type = TYPE_I;
+ transtype = TYPE_I;
if (STRNEQUAL(url, FTP_URL)) {
- if ((parse_url(url, "URL", &urltype, &user, &pass,
+ if ((parse_url(url, "URL", &urltype, &uuser, &pass,
&host, &port, &portnum, &path) == -1) ||
- (user != NULL && *user == '\0') ||
+ (uuser != NULL && *uuser == '\0') ||
EMPTYSTRING(host)) {
warnx("Invalid URL `%s'", url);
goto cleanup_fetch_ftp;
@@ -1346,9 +1393,9 @@ fetch_ftp(const char *url)
/* check for trailing ';type=[aid]' */
if (! EMPTYSTRING(path) && (cp = strrchr(path, ';')) != NULL) {
if (strcasecmp(cp, ";type=a") == 0)
- type = TYPE_A;
+ transtype = TYPE_A;
else if (strcasecmp(cp, ";type=i") == 0)
- type = TYPE_I;
+ transtype = TYPE_I;
else if (strcasecmp(cp, ";type=d") == 0) {
warnx(
"Directory listing via a URL is not supported");
@@ -1362,18 +1409,18 @@ fetch_ftp(const char *url)
}
} else { /* classic style `[user@]host:[file]' */
urltype = CLASSIC_URL_T;
- host = xstrdup(url);
+ host = ftp_strdup(url);
cp = strchr(host, '@');
if (cp != NULL) {
*cp = '\0';
- user = host;
+ uuser = host;
anonftp = 0; /* disable anonftp */
- host = xstrdup(cp + 1);
+ host = ftp_strdup(cp + 1);
}
cp = strchr(host, ':');
if (cp != NULL) {
*cp = '\0';
- path = xstrdup(cp + 1);
+ path = ftp_strdup(cp + 1);
}
}
if (EMPTYSTRING(host))
@@ -1407,7 +1454,8 @@ fetch_ftp(const char *url)
cp = strrchr(dir, '/');
if (cp == dir && urltype == CLASSIC_URL_T) {
file = cp + 1;
- dir = "/";
+ (void)strlcpy(dirbuf, "/", sizeof(dirbuf));
+ dir = dirbuf;
} else if (cp != NULL) {
*cp++ = '\0';
file = cp;
@@ -1421,14 +1469,11 @@ fetch_ftp(const char *url)
url_decode(file);
/* but still don't url_decode(dir) */
}
- if (debug)
- fprintf(ttyout,
- "fetch_ftp: user `%s' pass `%s' host %s port %s "
- "path `%s' dir `%s' file `%s'\n",
- user ? user : "<null>", pass ? pass : "<null>",
- host ? host : "<null>", port ? port : "<null>",
- path ? path : "<null>",
- dir ? dir : "<null>", file ? file : "<null>");
+ DPRINTF("fetch_ftp: user `%s' pass `%s' host %s port %s "
+ "path `%s' dir `%s' file `%s'\n",
+ STRorNULL(uuser), STRorNULL(pass),
+ STRorNULL(host), STRorNULL(port),
+ STRorNULL(path), STRorNULL(dir), STRorNULL(file));
dirhasglob = filehasglob = 0;
if (doglob && urltype == CLASSIC_URL_T) {
@@ -1439,9 +1484,12 @@ fetch_ftp(const char *url)
}
/* Set up the connection */
+ oanonftp = anonftp;
if (connected)
disconnect(0, NULL);
- xargv[0] = (char *)getprogname(); /* XXX discards const */
+ anonftp = oanonftp;
+ (void)strlcpy(cmdbuf, getprogname(), sizeof(cmdbuf));
+ xargv[0] = cmdbuf;
xargv[1] = host;
xargv[2] = NULL;
xargc = 2;
@@ -1456,12 +1504,13 @@ fetch_ftp(const char *url)
setpeer(xargc, xargv);
autologin = oautologin;
if ((connected == 0) ||
- (connected == 1 && !ftp_login(host, user, pass))) {
- warnx("Can't connect or login to host `%s'", host);
+ (connected == 1 && !ftp_login(host, uuser, pass))) {
+ warnx("Can't connect or login to host `%s:%s'",
+ host, port ? port : "?");
goto cleanup_fetch_ftp;
}
- switch (type) {
+ switch (transtype) {
case TYPE_A:
setascii(1, xargv);
break;
@@ -1469,7 +1518,7 @@ fetch_ftp(const char *url)
setbinary(1, xargv);
break;
default:
- errx(1, "fetch_ftp: unknown transfer type %d", type);
+ errx(1, "fetch_ftp: unknown transfer type %d", transtype);
}
/*
@@ -1488,12 +1537,12 @@ fetch_ftp(const char *url)
* directories in one step.
*
* If we are dealing with an `ftp://host/path' URL
- * (urltype is FTP_URL_T), then RFC 1738 says we need to
+ * (urltype is FTP_URL_T), then RFC3986 says we need to
* send a separate CWD command for each unescaped "/"
* in the path, and we have to interpret %hex escaping
* *after* we find the slashes. It's possible to get
* empty components here, (from multiple adjacent
- * slashes in the path) and RFC 1738 says that we should
+ * slashes in the path) and RFC3986 says that we should
* still do `CWD ' (with a null argument) in such cases.
*
* Many ftp servers don't support `CWD ', so if there's an
@@ -1551,12 +1600,11 @@ fetch_ftp(const char *url)
url_decode(dir);
} else
nextpart = NULL;
- if (debug)
- fprintf(ttyout, "dir `%s', nextpart `%s'\n",
- dir ? dir : "<null>",
- nextpart ? nextpart : "<null>");
+ DPRINTF("fetch_ftp: dir `%s', nextpart `%s'\n",
+ STRorNULL(dir), STRorNULL(nextpart));
if (urltype == FTP_URL_T || *dir != '\0') {
- xargv[0] = "cd";
+ (void)strlcpy(cmdbuf, "cd", sizeof(cmdbuf));
+ xargv[0] = cmdbuf;
xargv[1] = dir;
xargv[2] = NULL;
dirchange = 0;
@@ -1566,8 +1614,8 @@ fetch_ftp(const char *url)
fprintf(stderr,
"\n"
"ftp: The `CWD ' command (without a directory), which is required by\n"
-" RFC 1738 to support the empty directory in the URL pathname (`//'),\n"
-" conflicts with the server's conformance to RFC 959.\n"
+" RFC3986 to support the empty directory in the URL pathname (`//'),\n"
+" conflicts with the server's conformance to RFC0959.\n"
" Try the same URL without the `//' in the URL pathname.\n"
"\n");
goto cleanup_fetch_ftp;
@@ -1591,7 +1639,8 @@ fetch_ftp(const char *url)
/* Fetch the file(s). */
xargc = 2;
- xargv[0] = "get";
+ (void)strlcpy(cmdbuf, "get", sizeof(cmdbuf));
+ xargv[0] = cmdbuf;
xargv[1] = file;
xargv[2] = NULL;
if (dirhasglob || filehasglob) {
@@ -1600,9 +1649,10 @@ fetch_ftp(const char *url)
ointeractive = interactive;
interactive = 0;
if (restartautofetch)
- xargv[0] = "mreget";
+ (void)strlcpy(cmdbuf, "mreget", sizeof(cmdbuf));
else
- xargv[0] = "mget";
+ (void)strlcpy(cmdbuf, "mget", sizeof(cmdbuf));
+ xargv[0] = cmdbuf;
mget(xargc, xargv);
interactive = ointeractive;
} else {
@@ -1626,9 +1676,12 @@ fetch_ftp(const char *url)
rval = 0;
cleanup_fetch_ftp:
+ FREEPTR(port);
FREEPTR(host);
FREEPTR(path);
- FREEPTR(user);
+ FREEPTR(uuser);
+ if (pass)
+ memset(pass, 0, strlen(pass));
FREEPTR(pass);
return (rval);
}
@@ -1648,7 +1701,7 @@ fetch_ftp(const char *url)
static int
go_fetch(const char *url)
{
- char *proxy;
+ char *proxyenv;
#ifndef NO_ABOUT
/*
@@ -1697,8 +1750,8 @@ go_fetch(const char *url)
* If ftpproxy is set with an FTP URL, use fetch_url()
* Othewise, use fetch_ftp().
*/
- proxy = getoptionvalue("ftp_proxy");
- if (!EMPTYSTRING(proxy) && STRNEQUAL(url, FTP_URL))
+ proxyenv = getoptionvalue("ftp_proxy");
+ if (!EMPTYSTRING(proxyenv) && STRNEQUAL(url, FTP_URL))
return (fetch_url(url, NULL, NULL, NULL));
return (fetch_ftp(url));
@@ -1719,10 +1772,9 @@ go_fetch(const char *url)
int
auto_fetch(int argc, char *argv[])
{
- volatile int argpos;
- int rval;
+ volatile int argpos, rval;
- argpos = 0;
+ argpos = rval = 0;
if (sigsetjmp(toplevel, 1)) {
if (connected)
@@ -1737,7 +1789,7 @@ auto_fetch(int argc, char *argv[])
/*
* Loop through as long as there's files to fetch.
*/
- for (rval = 0; (rval == 0) && (argpos < argc); argpos++) {
+ for (; (rval == 0) && (argpos < argc); argpos++) {
if (strchr(argv[argpos], ':') == NULL)
break;
redirect_loop = 0;
@@ -1757,38 +1809,47 @@ auto_fetch(int argc, char *argv[])
}
+/*
+ * Upload multiple files from the command line.
+ *
+ * If an error occurs the return value will be the offset+1 in
+ * argv[] of the file that caused a problem (i.e, argv[x]
+ * returns x+1)
+ * Otherwise, 0 is returned if all files uploaded successfully.
+ */
int
auto_put(int argc, char **argv, const char *uploadserver)
{
char *uargv[4], *path, *pathsep;
- int uargc, rval, len;
-
- uargc = 0;
- uargv[uargc++] = "mput";
- uargv[uargc++] = argv[0];
+ int uargc, rval, argpos;
+ size_t len;
+ char cmdbuf[MAX_C_NAME];
+
+ (void)strlcpy(cmdbuf, "mput", sizeof(cmdbuf));
+ uargv[0] = cmdbuf;
+ uargv[1] = argv[0];
+ uargc = 2;
uargv[2] = uargv[3] = NULL;
pathsep = NULL;
rval = 1;
- if (debug)
- fprintf(ttyout, "auto_put: target `%s'\n", uploadserver);
+ DPRINTF("auto_put: target `%s'\n", uploadserver);
- path = xstrdup(uploadserver);
+ path = ftp_strdup(uploadserver);
len = strlen(path);
if (path[len - 1] != '/' && path[len - 1] != ':') {
/*
* make sure we always pass a directory to auto_fetch
*/
if (argc > 1) { /* more than one file to upload */
- int len;
-
len = strlen(uploadserver) + 2; /* path + "/" + "\0" */
free(path);
- path = (char *)xmalloc(len);
+ path = (char *)ftp_malloc(len);
(void)strlcpy(path, uploadserver, len);
(void)strlcat(path, "/", len);
} else { /* single file to upload */
- uargv[0] = "put";
+ (void)strlcpy(cmdbuf, "put", sizeof(cmdbuf));
+ uargv[0] = cmdbuf;
pathsep = strrchr(path, '/');
if (pathsep == NULL) {
pathsep = strrchr(path, ':');
@@ -1797,38 +1858,44 @@ auto_put(int argc, char **argv, const char *uploadserver)
goto cleanup_auto_put;
}
pathsep++;
- uargv[2] = xstrdup(pathsep);
+ uargv[2] = ftp_strdup(pathsep);
pathsep[0] = '/';
} else
- uargv[2] = xstrdup(pathsep + 1);
+ uargv[2] = ftp_strdup(pathsep + 1);
pathsep[1] = '\0';
uargc++;
}
}
- if (debug)
- fprintf(ttyout, "auto_put: URL `%s' argv[2] `%s'\n",
- path, uargv[2] ? uargv[2] : "<null>");
+ DPRINTF("auto_put: URL `%s' argv[2] `%s'\n",
+ path, STRorNULL(uargv[2]));
/* connect and cwd */
rval = auto_fetch(1, &path);
- free(path);
if(rval >= 0)
goto cleanup_auto_put;
+ rval = 0;
+
+ /* target filename provided; upload 1 file */
/* XXX : is this the best way? */
if (uargc == 3) {
uargv[1] = argv[0];
put(uargc, uargv);
- goto cleanup_auto_put;
- }
-
- for(; argv[0] != NULL; argv++) {
- uargv[1] = argv[0];
- mput(uargc, uargv);
+ if ((code / 100) != COMPLETE)
+ rval = 1;
+ } else { /* otherwise a target dir: upload all files to it */
+ for(argpos = 0; argv[argpos] != NULL; argpos++) {
+ uargv[1] = argv[argpos];
+ mput(uargc, uargv);
+ if ((code / 100) != COMPLETE) {
+ rval = argpos + 1;
+ break;
+ }
+ }
}
- rval = 0;
cleanup_auto_put:
+ free(path);
FREEPTR(uargv[2]);
return (rval);
}
diff --git a/src/ftp.1 b/src/ftp.1
index 917980f4081ff..34a88c23520bc 100644
--- a/src/ftp.1
+++ b/src/ftp.1
@@ -1,6 +1,7 @@
-.\" $NetBSD: ftp.1,v 1.109 2005/02/20 20:54:01 wiz Exp $
+.\" $NetBSD: ftp.1,v 1.13 2009/11/15 10:12:37 lukem Exp $
+.\" from NetBSD: ftp.1,v 1.130 2009/07/11 18:35:48 joerg Exp
.\"
-.\" Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1996-2008 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
@@ -14,13 +15,6 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation nor the names of its
-.\" contributors may be used to endorse or promote products derived
-.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -64,16 +58,15 @@
.\"
.\" @(#)ftp.1 8.3 (Berkeley) 10/9/94
.\"
-.Dd January 15, 2005
+.Dd May 10, 2008
.Dt FTP 1
.Os
.Sh NAME
.Nm ftp
-.Nd
-Internet file transfer program
+.Nd Internet file transfer program
.Sh SYNOPSIS
.Nm
-.Op Fl 46AadefginpRtvV
+.Op Fl 46AadefginpRtVv
.Bk -words
.Op Fl N Ar netrc
.Ek
@@ -89,6 +82,7 @@ Internet file transfer program
.Bk -words
.Op Fl r Ar retry
.Ek
+.Op Fl s Ar srcaddr
.Bk -words
.\" [-T dir,max[,inc]]
.Oo
@@ -179,7 +173,7 @@ below for more information.
.Pp
Options may be specified at the command line, or to the
command interpreter.
-.Bl -tag -width "port "
+.Bl -tag -width Fl
.It Fl 4
Forces
.Nm
@@ -219,6 +213,14 @@ Disables file name globbing.
.It Fl i
Turns off interactive prompting during
multiple file transfers.
+.It Fl N Ar netrc
+Use
+.Ar netrc
+instead of
+.Pa ~/.netrc .
+Refer to
+.Sx THE .netrc FILE
+for more information.
.It Fl n
Restrains
.Nm
@@ -238,14 +240,6 @@ identity on the local machine), and, if necessary, prompt for a password
and an account with which to login.
To override the auto-login for auto-fetch transfers, specify the
username (and optionally, password) as appropriate.
-.It Fl N Ar netrc
-Use
-.Ar netrc
-instead of
-.Pa ~/.netrc .
-Refer to
-.Sx THE .netrc FILE
-for more information.
.It Fl o Ar output
When auto-fetching files, save the contents in
.Ar output .
@@ -263,35 +257,32 @@ then only the first file specified will be retrieved into
.Ar output ;
all other files will be retrieved into the basename of their
remote name.
+.It Fl P Ar port
+Sets the port number to
+.Ar port .
.It Fl p
Enable passive mode operation for use behind connection filtering firewalls.
This option has been deprecated as
.Nm
now tries to use passive mode by default, falling back to active mode
if the server does not support passive connections.
-.It Fl P Ar port
-Sets the port number to
-.Ar port .
-.It Fl r Ar wait
-Retry the connection attempt if it failed, pausing for
-.Ar wait
-seconds.
.It Fl q Ar quittime
Quit if the connection has stalled for
.Ar quittime
seconds.
.It Fl R
Restart all non-proxied auto-fetches.
+.It Fl r Ar wait
+Retry the connection attempt if it failed, pausing for
+.Ar wait
+seconds.
+.It Fl s Ar srcaddr
+Uses
+.Ar srcaddr
+as the local IP address for all connections.
.It Fl t
Enables packet tracing.
-.It Xo
-.Fl T
-.Sm off
-.Ar direction ,
-.Ar maximum
-.Op , Ar increment
-.Sm on
-.Xc
+.It Fl T Ar direction Ns , Ns Ar maximum Ns Oo , Ns Ar increment Oc
Set the maximum transfer rate for
.Ar direction
to
@@ -312,6 +303,12 @@ is one of the ftp URL types as supported by auto-fetch
(with an optional target filename for single file uploads), and
.Ar file
is one or more local files to be uploaded.
+.It Fl V
+Disable
+.Ic verbose
+and
+.Ic progress ,
+overriding the default of enabled when output is to a terminal.
.It Fl v
Enable
.Ic verbose
@@ -325,12 +322,6 @@ Forces
.Nm
to show all responses from the remote server, as well
as report on data transfer statistics.
-.It Fl V
-Disable
-.Ic verbose
-and
-.Ic progress ,
-overriding the default of enabled when output is to a terminal.
.El
.Pp
The client host with which
@@ -351,8 +342,8 @@ is awaiting commands from the user the prompt
is provided to the user.
The following commands are recognized
by
-.Nm ftp :
-.Bl -tag -width Fl
+.Nm ftp :
+.Bl -tag -width Ic
.It Ic \&! Op Ar command Op Ar args
Invoke an interactive shell on the local machine.
If there are arguments, the first is taken to be a command to execute
@@ -455,16 +446,6 @@ when an ascii type transfer is made, these linefeeds may be
distinguished from a record delimiter only when
.Ic \&cr
is off.
-.It Ic debug Op Ar debug-value
-Toggle debugging mode.
-If an optional
-.Ar debug-value
-is specified it is used to set the debugging level.
-When debugging is on,
-.Nm
-prints each command sent to the remote machine, preceded
-by the string
-.Ql \-\-\*[Gt]
.It Ic delete Ar remote-file
Delete the file
.Ar remote-file
@@ -500,12 +481,13 @@ Toggle command line editing, and context sensitive command and file
completion.
This is automatically enabled if input is from a terminal, and
disabled otherwise.
-.It Ic epsv4
+.It Ic epsv epsv4 epsv6
Toggle the use of the extended
.Dv EPSV
and
.Dv EPRT
-commands on IPv4 connections; first try
+commands on all IP, IPv4, and IPv6 connections respectively.
+First try
.Dv EPSV /
.Dv EPRT ,
and then
@@ -514,7 +496,10 @@ and then
This is enabled by default.
If an extended command fails then this option will be temporarily
disabled for the duration of the current connection, or until
-.Ic epsv4
+.Ic epsv ,
+.Ic epsv4 ,
+or
+.Ic epsv6
is executed again.
.It Ic exit
A synonym for
@@ -538,6 +523,16 @@ format is
.It Ic ftp Ar host Op Ar port
A synonym for
.Ic open .
+.It Ic ftp_debug Op Ar ftp_debug-value
+Toggle debugging mode.
+If an optional
+.Ar ftp_debug-value
+is specified it is used to set the debugging level.
+When debugging is on,
+.Nm
+prints each command sent to the remote machine, preceded
+by the string
+.Ql \-\-\*[Gt] .
.It Ic gate Op Ar host Op Ar port
Toggle gate-ftp mode, which used to connect through the
TIS FWTK and Gauntlet ftp proxies.
@@ -613,8 +608,9 @@ transferring a
.Xr tar 1
archive of the subtree (in binary mode).
.It Ic hash Op Ar size
-Toggle hash-sign (``#'') printing for each data block
-transferred.
+Toggle hash-sign
+.Pq Sq #
+printing for each data block transferred.
The size of a data block defaults to 1024 bytes.
This can be changed by specifying
.Ar size
@@ -663,24 +659,49 @@ A synonym for
Define a macro.
Subsequent lines are stored as the macro
.Ar macro-name ;
-a null line (consecutive newline characters
-in a file or
-carriage returns from the terminal) terminates macro input mode.
+a null line (consecutive newline characters in a file or carriage
+returns from the terminal) terminates macro input mode.
There is a limit of 16 macros and 4096 total characters in all
defined macros.
-Macros remain defined until a
+Macro names can be a maximum of 8 characters.
+Macros are only applicable to the current session they are
+defined within (or if defined outside a session, to the session
+invoked with the next
+.Ic open
+command), and remain defined until a
.Ic close
command is executed.
-The macro processor interprets `$' and `\e' as special characters.
-A `$' followed by a number (or numbers) is replaced by the
+To invoke a macro, use the
+.Ic $
+command (see above).
+.Pp
+The macro processor interprets
+.Sq $
+and
+.Sq \e
+as special characters.
+A
+.Sq $
+followed by a number (or numbers) is replaced by the
corresponding argument on the macro invocation command line.
-A `$' followed by an `i' signals that macro processor that the
-executing macro is to be looped.
-On the first pass `$i' is
-replaced by the first argument on the macro invocation command line,
-on the second pass it is replaced by the second argument, and so on.
-A `\e' followed by any character is replaced by that character.
-Use the `\e' to prevent special treatment of the `$'.
+A
+.Sq $
+followed by an
+.Sq i
+signals the macro processor that the executing macro is to be
+looped.
+On the first pass
+.Dq $i
+is replaced by the first argument on the macro invocation command
+line, on the second pass it is replaced by the second argument,
+and so on.
+A
+.Sq \e
+followed by any character is replaced by that character.
+Use the
+.Sq \e
+to prevent special treatment of the
+.Sq $ .
.It Ic mdelete Op Ar remote-files
Delete the
.Ar remote-files
@@ -756,7 +777,9 @@ The default (and only supported)
mode is
.Dq stream .
.It Ic modtime Ar remote-file
-Show the last modification time of the file on the remote machine.
+Show the last modification time of the file on the remote machine, in
+.Li RFC2822
+format.
.It Ic more Ar file
A synonym for
.Ic page .
@@ -823,9 +846,18 @@ and
.Ic case
settings).
Variable templating is accomplished by including the
-sequences `$1', `$2', ..., `$9' in
+sequences
+.Dq $1 ,
+.Dq $2 ,
+\&...
+.Dq $9
+in
.Ar inpattern .
-Use `\\' to prevent this special treatment of the `$' character.
+Use
+.Sq \e
+to prevent this special treatment of the
+.Sq $
+character.
All other characters are treated literally, and are used to determine the
.Ic nmap
.Op Ar inpattern
@@ -837,13 +869,19 @@ $1.$2 and the remote file name "mydata.data", $1 would have the value
The
.Ar outpattern
determines the resulting mapped filename.
-The sequences `$1', `$2', ...., `$9' are replaced by any value resulting
-from the
+The sequences
+.Dq $1 ,
+.Dq $2 ,
+\&...
+.Dq $9
+are replaced by any value resulting from the
.Ar inpattern
template.
-The sequence `$0' is replace by the original filename.
+The sequence
+.Dq $0
+is replaced by the original filename.
Additionally, the sequence
-.Ql Op Ar seq1 , Ar seq2
+.Dq Op Ar seq1 , Ar seq2
is replaced by
.Op Ar seq1
if
@@ -862,9 +900,18 @@ the output filename "myfile.data" for input filenames "myfile.data" and
"myfile.myfile" for the input filename ".myfile".
Spaces may be included in
.Ar outpattern ,
-as in the example: `nmap $1 sed "s/ *$//" \*[Gt] $1' .
-Use the `\e' character to prevent special treatment
-of the `$','[',']', and `,' characters.
+as in the example:
+.Dl nmap $1 sed "s/ *$//" \*[Gt] $1
+Use the
+.Sq \e
+character to prevent special treatment
+of the
+.Sq $ ,
+.Sq \&[ ,
+.Sq \&] ,
+and
+.Sq \&,
+characters.
.It Ic ntrans Op Ar inchars Op Ar outchars
Set or unset the filename character translation mechanism.
If no arguments are specified, the filename character
@@ -952,7 +999,7 @@ traffic.
servers are required to support the
.Dv PASV
command by
-.Li RFC 1123 ,
+.Li RFC1123 ,
some do not.)
.It Ic pdir Op Ar remote-path
Perform
@@ -1100,10 +1147,7 @@ A synonym for
The arguments specified are sent, verbatim, to the remote
.Tn FTP
server.
-.It Xo
-.Ic rate Ar direction
-.Op Ar maximum Op Ar increment
-.Xc
+.It Ic rate Ar direction Oo Ar maximum Oo Ar increment Oc Oc
Throttle the maximum transfer rate to
.Ar maximum
bytes/second.
@@ -1126,7 +1170,6 @@ Outgoing transfers.
can be modified on the fly by
.Ar increment
bytes (default: 1024) each time a given signal is received:
-.B
.Bl -tag -width "SIGUSR1" -offset indent
.It Dv SIGUSR1
Increment
@@ -1388,10 +1431,7 @@ for more information.
.It Ic usage Ar command
Print the usage message for
.Ar command .
-.It Xo
-.Ic user Ar user-name
-.Op Ar password Op Ar account
-.Xc
+.It Ic user Ar user-name Oo Ar password Oo Ar account Oc Oc
Identify yourself to the remote
.Tn FTP
server.
@@ -1439,7 +1479,9 @@ A synonym for
.El
.Pp
Command arguments which have embedded spaces may be quoted with
-quote `"' marks.
+quote
+.Sq \&"
+marks.
.Pp
Commands which toggle settings can take an explicit
.Ic on
@@ -1491,14 +1533,8 @@ on the command line.
The following formats are valid syntax for an auto-fetch element:
.Bl -tag -width "FOO "
.\" [user@]host:[path][/]
-.It Xo
-.Sm off
-.Op Ar user Li \&@
-.Ar host Li \&:
-.Op Ar path
-.Op Li /
-.Sm on
-.Xc
+.It Oo Ar user Ns Li \&@ Oc Ns Ar host Ns Li \&: Ns Oo Ar path Oc \
+Ns Oo Li / Oc
.Dq Classic
.Tn FTP
format.
@@ -1523,18 +1559,9 @@ in the current directory.
Otherwise, the full remote name is used as the local name,
relative to the local root directory.
.\" ftp://[user[:password]@]host[:port]/path[/][;type=X]
-.It Xo
-.Sm off
-.Li ftp://
-.Oo Ar user
-.Op Li \&: Ar password
-.Li \&@ Oc
-.Ar host Oo Li \&: Ar port Oc
-.Li / Ar path
-.Op Li /
-.Op Li ;type= Ar X
-.Sm on
-.Xc
+.It Li ftp:// Ns Oo Ar user Ns Oo Ns Li \&: Ns Ar password Oc Ns Li \&@ Oc \
+Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path Ns Oo Li / Oc \
+Ns Oo Li ;type= Ns Ar X Oc
An
.Tn FTP
URL, retrieved using the
@@ -1565,7 +1592,7 @@ ascii or binary (respectively).
The default transfer type is binary.
.Pp
In order to be compliant with
-.Li RFC 1738 ,
+.Li RFC3986 ,
.Nm
interprets the
.Ar path
@@ -1618,7 +1645,7 @@ Any
.Sq Li \&% Ns Ar XX
codes
(per
-.Li RFC 1738 )
+.Li RFC3986 )
within the path components are decoded, with
.Ar XX
representing a character code in hexadecimal.
@@ -1705,16 +1732,8 @@ intermediate directories that is used in the equivalent of a
command.
.El
.\" http://[user[:password]@]host[:port]/path
-.It Xo
-.Sm off
-.Li http://
-.Oo Ar user
-.Op Li \&: Ar password
-.Li \&@ Oc
-.Ar host Oo Li \&: Ar port Oc
-.Li / Ar path
-.Sm on
-.Xc
+.It Li http:// Ns Oo Ar user Ns Oo Li \&: Ns Ar password Oc Ns Li \&@ Oc \
+Ns Ar host Ns Oo Li \&: Ns Ar port Oc Ns Li / Ns Ar path
An
.Tn HTTP
URL, retrieved using the
@@ -1735,14 +1754,25 @@ and
.Sq password )
is in the URL, use them for the first attempt to authenticate.
.\" file:///path
-.It Xo
-.Sm off
-.Li file:/// Ar path
-.Sm on
-.Xc
+.It Li file:/// Ns Ar path
A local URL, copied from
.Pa / Ns Ar path
on the local host.
+.\" about:
+.It Li about: Ns Ar topic
+Display information regarding
+.Ar topic ;
+no file is retrieved for this auto-fetched element.
+Supported values include:
+.Bl -tag -width "about:version"
+.It Li about:ftp
+Information about
+.Nm ftp .
+.It Li about:version
+The version of
+.Nm ftp .
+Useful to provide when reporting problems.
+.El
.El
.Pp
Unless noted otherwise above, and
@@ -1868,11 +1898,12 @@ A particularly
useful example of this mechanism is:
.Dq Li dir \&"\&" \&|more .
.It
-Failing the above checks, if ``globbing'' is enabled,
-local file names are expanded
-according to the rules used in the
+Failing the above checks, if
+.Dq globbing
+is enabled, local file names are expanded according to the rules
+used in the
.Xr csh 1 ;
-c.f. the
+see the
.Ic glob
command.
If the
@@ -2038,6 +2069,20 @@ next
.Pa .netrc
line and continue until a blank line (consecutive new-line
characters) is encountered.
+Like the other tokens in the
+.Pa .netrc
+file, a
+.Ic macdef
+is applicable only to the
+.Ic machine
+definition preceding it.
+A
+.Ic macdef
+entry cannot be used by multiple
+.Ic machine
+definitions; rather, it must be defined following each
+.Ic machine
+it is intended to be used with.
If a macro named
.Ic init
is defined, it is automatically executed as the last step in the
@@ -2100,14 +2145,7 @@ information:
.It Li \&%/
The current remote working directory.
.\" %c[[0]n], %.[[0]n]
-.It Xo
-.Sm off
-.Li \&%c
-.Op Oo Li 0 Oc Ar n Ns ,
-.Li \&%.
-.Op Oo Li 0 Oc Ar n
-.Sm on
-.Xc
+.It \&%c Ns Oo Oo Li 0 Oc Ns Ar n Oc , Ns Li \&%. Ns Oo Oo Li 0 Oc Ns Ar n Oc
The trailing component of the current remote working directory, or
.Em n
trailing components if a digit
@@ -2248,7 +2286,7 @@ URL characters are required in the username or password
or
.Sq / ) ,
encode them with
-.Li RFC 1738
+.Li RFC3986
.Sq Li \&% Ns Ar XX
encoding.
.Pp
@@ -2291,16 +2329,27 @@ for an example of how to make this automatic.
.Xr ftpd 8
.Sh STANDARDS
.Nm
-attempts to be compliant with
-.Li RFC 959 ,
-.Li RFC 1123 ,
-.Li RFC 1738 ,
-.Li RFC 2068 ,
-.Li RFC 2389 ,
-.Li RFC 2428 ,
-.Li RFC 2732 ,
-and
-.Cm draft-ietf-ftpext-mlst-11 .
+attempts to be compliant with:
+.Bl -tag -offset indent -width 8n
+.It Li RFC0959
+.Em File Transfer Protocol
+.It Li RFC1123
+.Em Requirements for Internet Hosts - Application and Support
+.It Li RFC1635
+.Em How to Use Anonymous FTP
+.It Li RFC2389
+.Em Feature negotiation mechanism for the File Transfer Protocol
+.It Li RFC2428
+.Em FTP Extensions for IPv6 and NATs
+.It Li RFC2616
+.Em Hypertext Transfer Protocol -- HTTP/1.1
+.It Li RFC2822
+.Em Internet Message Format
+.It Li RFC3659
+.Em Extensions to FTP
+.It Li RFC3986
+.Em Uniform Resource Identifier (URI)
+.El
.Sh HISTORY
The
.Nm
diff --git a/src/ftp.c b/src/ftp.c
index dae61313fd87f..4c4942f1bc1d1 100644
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -1,7 +1,8 @@
-/* $NetBSD: ftp.c,v 1.132 2005/05/14 15:26:43 lukem Exp $ */
+/* $NetBSD: ftp.c,v 1.18 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: ftp.c,v 1.159 2009/04/15 03:42:33 jld Exp */
/*-
- * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -94,12 +88,17 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+#include <arpa/telnet.h>
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ftp.c 8.6 (Berkeley) 10/27/94";
#else
-__RCSID("$NetBSD: ftp.c,v 1.132 2005/05/14 15:26:43 lukem Exp $");
+__RCSID(" NetBSD: ftp.c,v 1.159 2009/04/15 03:42:33 jld Exp ");
#endif
#endif /* not lint */
@@ -127,6 +126,8 @@ __RCSID("$NetBSD: ftp.c,v 1.132 2005/05/14 15:26:43 lukem Exp $");
#include <unistd.h>
#include <stdarg.h>
+#endif /* tnftp */
+
#include "ftp_var.h"
volatile sig_atomic_t abrtflag;
@@ -146,12 +147,12 @@ struct sockinet {
struct sockaddr_in6 su_sin6;
#endif
} si_su;
-#if !HAVE_SOCKADDR_SA_LEN
+#if !defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
int si_len;
#endif
};
-#if !HAVE_SOCKADDR_SA_LEN
+#if !defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
# define su_len si_len
#else
# define su_len si_su.su_sin.sin_len
@@ -162,27 +163,26 @@ struct sockinet {
struct sockinet myctladdr, hisctladdr, data_addr;
char *
-hookup(char *host, char *port)
+hookup(const char *host, const char *port)
{
- int s = -1, error, portnum;
+ int s = -1, error;
struct addrinfo hints, *res, *res0;
- char hbuf[MAXHOSTNAMELEN];
static char hostnamebuf[MAXHOSTNAMELEN];
- char *cause = "unknown";
socklen_t len;
int on = 1;
memset((char *)&hisctladdr, 0, sizeof (hisctladdr));
memset((char *)&myctladdr, 0, sizeof (myctladdr));
memset(&hints, 0, sizeof(hints));
- portnum = parseport(port, FTP_PORT);
hints.ai_flags = AI_CANONNAME;
hints.ai_family = family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
- error = getaddrinfo(host, NULL, &hints, &res0);
+ error = getaddrinfo(host, port, &hints, &res0);
if (error) {
- warnx("%s", gai_strerror(error));
+ warnx("Can't lookup `%s:%s': %s", host, port,
+ (error == EAI_SYSTEM) ? strerror(errno)
+ : gai_strerror(error));
code = -1;
return (0);
}
@@ -195,53 +195,26 @@ hookup(char *host, char *port)
hostname = hostnamebuf;
for (res = res0; res; res = res->ai_next) {
- /*
- * make sure that ai_addr is NOT an IPv4 mapped address.
- * IPv4 mapped address complicates too many things in FTP
- * protocol handling, as FTP protocol is defined differently
- * between IPv4 and IPv6.
- *
- * This may not be the best way to handle this situation,
- * since the semantics of IPv4 mapped address is defined in
- * the kernel. There are configurations where we should use
- * IPv4 mapped address as native IPv6 address, not as
- * "an IPv6 address that embeds IPv4 address" (namely, SIIT).
- *
- * More complete solution would be to have an additional
- * getsockopt to grab "real" peername/sockname. "real"
- * peername/sockname will be AF_INET if IPv4 mapped address
- * is used to embed IPv4 address, and will be AF_INET6 if
- * we use it as native. What a mess!
- */
+ char hname[NI_MAXHOST], sname[NI_MAXSERV];
+
ai_unmapped(res);
-#if 0 /*old behavior*/
- if (res != res0) /* not on the first address */
-#else
- if (res0->ai_next) /* if we have multiple possibilities */
-#endif
- {
- if (getnameinfo(res->ai_addr, res->ai_addrlen,
- hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST))
- strlcpy(hbuf, "?", sizeof(hbuf));
- fprintf(ttyout, "Trying %s...\n", hbuf);
+ if (getnameinfo(res->ai_addr, res->ai_addrlen,
+ hname, sizeof(hname), sname, sizeof(sname),
+ NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ strlcpy(hname, "?", sizeof(hname));
+ strlcpy(sname, "?", sizeof(sname));
+ }
+ if (verbose && res0->ai_next) {
+ /* if we have multiple possibilities */
+ fprintf(ttyout, "Trying %s:%s ...\n", hname, sname);
}
- ((struct sockaddr_in *)res->ai_addr)->sin_port = htons(portnum);
s = socket(res->ai_family, SOCK_STREAM, res->ai_protocol);
if (s < 0) {
- cause = "socket";
+ warn("Can't create socket for connection to `%s:%s'",
+ hname, sname);
continue;
}
- error = xconnect(s, res->ai_addr, res->ai_addrlen);
- if (error) {
- /* this "if" clause is to prevent print warning twice */
- if (res->ai_next) {
- if (getnameinfo(res->ai_addr, res->ai_addrlen,
- hbuf, sizeof(hbuf), NULL, 0,
- NI_NUMERICHOST))
- strlcpy(hbuf, "?", sizeof(hbuf));
- warn("connect to address %s", hbuf);
- }
- cause = "connect";
+ if (ftp_connect(s, res->ai_addr, res->ai_addrlen) < 0) {
close(s);
s = -1;
continue;
@@ -251,7 +224,7 @@ hookup(char *host, char *port)
break;
}
if (s < 0) {
- warn("%s", cause);
+ warnx("Can't connect to `%s:%s'", host, port);
code = -1;
freeaddrinfo(res0);
return 0;
@@ -263,7 +236,8 @@ hookup(char *host, char *port)
len = hisctladdr.su_len;
if (getsockname(s, (struct sockaddr *)&myctladdr.si_su, &len) == -1) {
- warn("getsockname");
+ warn("Can't determine my address of connection to `%s:%s'",
+ host, port);
code = -1;
goto bad;
}
@@ -274,8 +248,7 @@ hookup(char *host, char *port)
int tos = IPTOS_LOWDELAY;
if (setsockopt(s, IPPROTO_IP, IP_TOS,
(void *)&tos, sizeof(tos)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)",
+ DWARN("setsockopt %s (ignored)",
"IPTOS_LOWDELAY");
}
}
@@ -283,7 +256,7 @@ hookup(char *host, char *port)
cin = fdopen(s, "r");
cout = fdopen(s, "w");
if (cin == NULL || cout == NULL) {
- warnx("fdopen failed.");
+ warnx("Can't fdopen socket");
if (cin)
(void)fclose(cin);
if (cout)
@@ -304,8 +277,7 @@ hookup(char *host, char *port)
if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
(void *)&on, sizeof(on)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)", "SO_OOBINLINE");
+ DWARN("setsockopt %s (ignored)", "SO_OOBINLINE");
}
return (hostname);
@@ -351,7 +323,8 @@ command(const char *fmt, ...)
int r;
sigfunc oldsigint;
- if (debug) {
+#ifndef NO_DEBUG
+ if (ftp_debug) {
fputs("---> ", ttyout);
va_start(ap, fmt);
if (strncmp("PASS ", fmt, 5) == 0)
@@ -363,8 +336,9 @@ command(const char *fmt, ...)
va_end(ap);
putc('\n', ttyout);
}
+#endif
if (cout == NULL) {
- warnx("No control connection for command.");
+ warnx("No control connection for command");
code = -1;
return (0);
}
@@ -386,11 +360,17 @@ command(const char *fmt, ...)
return (r);
}
+static const char *m421[] = {
+ "remote server timed out. Connection closed",
+ "user interrupt. Connection closed",
+ "remote server has closed connection",
+};
+
int
getreply(int expecteof)
{
char current_line[BUFSIZ]; /* last line of previous reply */
- int c, n, line;
+ int c, n, lineno;
int dig;
int originalcode = 0, continuation = 0;
sigfunc oldsigint, oldsigalrm;
@@ -403,10 +383,11 @@ getreply(int expecteof)
oldsigint = xsignal(SIGINT, cmdabort);
oldsigalrm = xsignal(SIGALRM, cmdtimeout);
- for (line = 0 ;; line++) {
+ for (lineno = 0 ;; lineno++) {
dig = n = code = 0;
cp = current_line;
- while (alarmtimer(60),((c = getc(cin)) != '\n')) {
+ while (alarmtimer(quit_time ? quit_time : 60),
+ ((c = getc(cin)) != '\n')) {
if (c == IAC) { /* handle telnet commands */
switch (c = getc(cin)) {
case WILL:
@@ -445,18 +426,15 @@ getreply(int expecteof)
cpend = 0;
lostpeer(0);
if (verbose) {
+ size_t midx;
if (reply_timeoutflag)
- fputs(
- "421 Service not available, remote server timed out. Connection closed\n",
- ttyout);
+ midx = 0;
else if (reply_abrtflag)
- fputs(
- "421 Service not available, user interrupt. Connection closed.\n",
- ttyout);
+ midx = 1;
else
- fputs(
- "421 Service not available, remote server has closed connection.\n",
- ttyout);
+ midx = 2;
+ (void)fprintf(ttyout,
+ "421 Service not available, %s.\n", m421[midx]);
(void)fflush(ttyout);
}
code = 421;
@@ -505,15 +483,15 @@ getreply(int expecteof)
if (verbose > 0 || ((verbose > -1 && n == '5') &&
(n < '5' || !retry_connect))) {
(void)putc(c, ttyout);
- (void)fflush (ttyout);
+ (void)fflush(ttyout);
}
if (cp[-1] == '\r')
cp[-1] = '\0';
*cp = '\0';
- if (line == 0)
+ if (lineno == 0)
(void)strlcpy(reply_string, current_line,
sizeof(reply_string));
- if (line > 0 && code == 0 && reply_callback != NULL)
+ if (lineno > 0 && code == 0 && reply_callback != NULL)
(*reply_callback)(current_line);
if (continuation && code != originalcode) {
if (originalcode == 0)
@@ -537,14 +515,14 @@ getreply(int expecteof)
}
static int
-empty(FILE *cin, FILE *din, int sec)
+empty(FILE *ecin, FILE *din, int sec)
{
int nr, nfd;
struct pollfd pfd[2];
nfd = 0;
- if (cin) {
- pfd[nfd].fd = fileno(cin);
+ if (ecin) {
+ pfd[nfd].fd = fileno(ecin);
pfd[nfd++].events = POLLIN;
}
@@ -553,12 +531,12 @@ empty(FILE *cin, FILE *din, int sec)
pfd[nfd++].events = POLLIN;
}
- if ((nr = xpoll(pfd, nfd, sec * 1000)) <= 0)
+ if ((nr = ftp_poll(pfd, nfd, sec * 1000)) <= 0)
return nr;
nr = 0;
nfd = 0;
- if (cin)
+ if (ecin)
nr |= (pfd[nfd++].revents & POLLIN) ? 1 : 0;
if (din)
nr |= (pfd[nfd++].revents & POLLIN) ? 2 : 0;
@@ -585,8 +563,7 @@ abortxfer(int notused)
strlcpy(msgbuf, "\nsend", sizeof(msgbuf));
break;
default:
- errx(1, "abortxfer called with unknown direction `%s'",
- direction);
+ errx(1, "abortxfer: unknown direction `%s'", direction);
}
len = strlcat(msgbuf, " aborted. Waiting for remote to finish abort.\n",
sizeof(msgbuf));
@@ -594,30 +571,108 @@ abortxfer(int notused)
siglongjmp(xferabort, 1);
}
+/*
+ * Read data from infd & write to outfd, using buf/bufsize as the temporary
+ * buffer, dealing with short writes.
+ * If rate_limit != 0, rate-limit the transfer.
+ * If hash_interval != 0, fputc('c', ttyout) every hash_interval bytes.
+ * Updates global variables: bytes.
+ * Returns 0 if ok, 1 if there was a read error, 2 if there was a write error.
+ * In the case of error, errno contains the appropriate error code.
+ */
+static int
+copy_bytes(int infd, int outfd, char *buf, size_t bufsize,
+ int rate_limit, int hash_interval)
+{
+ volatile off_t hashc;
+ ssize_t inc, outc;
+ char *bufp;
+ struct timeval tvthen, tvnow, tvdiff;
+ off_t bufrem, bufchunk;
+ int serr;
+
+ hashc = hash_interval;
+ if (rate_limit)
+ bufchunk = rate_limit;
+ else
+ bufchunk = bufsize;
+
+ while (1) {
+ if (rate_limit) {
+ (void)gettimeofday(&tvthen, NULL);
+ }
+ errno = 0;
+ inc = outc = 0;
+ /* copy bufchunk at a time */
+ bufrem = bufchunk;
+ while (bufrem > 0) {
+ inc = read(infd, buf, MIN((off_t)bufsize, bufrem));
+ if (inc <= 0)
+ goto copy_done;
+ bytes += inc;
+ bufrem -= inc;
+ bufp = buf;
+ while (inc > 0) {
+ outc = write(outfd, bufp, inc);
+ if (outc < 0)
+ goto copy_done;
+ inc -= outc;
+ bufp += outc;
+ }
+ if (hash_interval) {
+ while (bytes >= hashc) {
+ (void)putc('#', ttyout);
+ hashc += hash_interval;
+ }
+ (void)fflush(ttyout);
+ }
+ }
+ if (rate_limit) { /* rate limited; wait if necessary */
+ while (1) {
+ (void)gettimeofday(&tvnow, NULL);
+ timersub(&tvnow, &tvthen, &tvdiff);
+ if (tvdiff.tv_sec > 0)
+ break;
+ usleep(1000000 - tvdiff.tv_usec);
+ }
+ }
+ }
+
+ copy_done:
+ serr = errno;
+ if (hash_interval && bytes > 0) {
+ if (bytes < hash_interval)
+ (void)putc('#', ttyout);
+ (void)putc('\n', ttyout);
+ (void)fflush(ttyout);
+ }
+ errno = serr;
+ if (inc == -1)
+ return 1;
+ if (outc == -1)
+ return 2;
+
+ return 0;
+}
+
void
sendrequest(const char *cmd, const char *local, const char *remote,
int printnames)
{
struct stat st;
- int c, d;
- FILE *fin, *dout;
- int (*closefunc)(FILE *);
- sigfunc oldintr, oldintp;
- volatile off_t hashbytes;
- char *lmode, *bufp;
+ int c;
+ FILE *volatile fin;
+ FILE *volatile dout;
+ int (*volatile closefunc)(FILE *);
+ sigfunc volatile oldintr;
+ sigfunc volatile oldintp;
+ off_t volatile hashbytes;
+ int hash_interval;
+ const char *lmode;
static size_t bufsize;
static char *buf;
int oprogress;
-#ifdef __GNUC__ /* to shut up gcc warnings */
- (void)&fin;
- (void)&dout;
- (void)&closefunc;
- (void)&oldintr;
- (void)&oldintp;
- (void)&lmode;
-#endif
-
hashbytes = mark;
direction = "sent";
dout = NULL;
@@ -625,7 +680,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
filesize = -1;
oprogress = progress;
if (verbose && printnames) {
- if (local && *local != '-')
+ if (*local != '-')
fprintf(ttyout, "local: %s ", local);
if (remote)
fprintf(ttyout, "remote: %s\n", remote);
@@ -655,7 +710,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
oldintp = xsignal(SIGPIPE, SIG_IGN);
fin = popen(local + 1, "r");
if (fin == NULL) {
- warn("%s", local + 1);
+ warn("Can't execute `%s'", local + 1);
code = -1;
goto cleanupsend;
}
@@ -664,7 +719,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
} else {
fin = fopen(local, "r");
if (fin == NULL) {
- warn("local: %s", local);
+ warn("Can't open `%s'", local);
code = -1;
goto cleanupsend;
}
@@ -698,7 +753,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
break;
}
if (rc < 0) {
- warn("local: %s", local);
+ warn("Can't seek to restart `%s'", local);
goto cleanupsend;
}
if (command("REST " LLF, (LLT)restart_point) != CONTINUE)
@@ -717,90 +772,28 @@ sendrequest(const char *cmd, const char *local, const char *remote,
if (dout == NULL)
goto abort;
- if (sndbuf_size > bufsize) {
+ if ((size_t)sndbuf_size > bufsize) {
if (buf)
(void)free(buf);
bufsize = sndbuf_size;
- buf = xmalloc(bufsize);
+ buf = ftp_malloc(bufsize);
}
progressmeter(-1);
oldintp = xsignal(SIGPIPE, SIG_IGN);
+ hash_interval = (hash && (!progress || filesize < 0)) ? mark : 0;
switch (curtype) {
case TYPE_I:
case TYPE_L:
- if (rate_put) { /* rate limited */
- while (1) {
- struct timeval then, now, td;
- off_t bufrem;
-
- (void)gettimeofday(&then, NULL);
- errno = c = d = 0;
- bufrem = rate_put;
- while (bufrem > 0) {
- if ((c = read(fileno(fin), buf,
- MIN(bufsize, bufrem))) <= 0)
- goto senddone;
- bytes += c;
- bufrem -= c;
- for (bufp = buf; c > 0;
- c -= d, bufp += d)
- if ((d = write(fileno(dout),
- bufp, c)) <= 0)
- break;
- if (d < 0)
- goto senddone;
- if (hash &&
- (!progress || filesize < 0) ) {
- while (bytes >= hashbytes) {
- (void)putc('#', ttyout);
- hashbytes += mark;
- }
- (void)fflush(ttyout);
- }
- }
- while (1) {
- (void)gettimeofday(&now, NULL);
- timersub(&now, &then, &td);
- if (td.tv_sec > 0)
- break;
- usleep(1000000 - td.tv_usec);
- }
- }
- } else { /* simpler/faster; no rate limit */
- while (1) {
- errno = c = d = 0;
- if ((c = read(fileno(fin), buf, bufsize)) <= 0)
- goto senddone;
- bytes += c;
- for (bufp = buf; c > 0; c -= d, bufp += d)
- if ((d = write(fileno(dout), bufp, c))
- <= 0)
- break;
- if (d < 0)
- goto senddone;
- if (hash && (!progress || filesize < 0) ) {
- while (bytes >= hashbytes) {
- (void)putc('#', ttyout);
- hashbytes += mark;
- }
- (void)fflush(ttyout);
- }
- }
- }
- senddone:
- if (hash && (!progress || filesize < 0) && bytes > 0) {
- if (bytes < mark)
- (void)putc('#', ttyout);
- (void)putc('\n', ttyout);
- }
- if (c < 0)
- warn("local: %s", local);
- if (d < 0) {
+ c = copy_bytes(fileno(fin), fileno(dout), buf, bufsize,
+ rate_put, hash_interval);
+ if (c == 1) {
+ warn("Reading `%s'", local);
+ } else if (c == 2) {
if (errno != EPIPE)
- warn("netout");
+ warn("Writing to network");
bytes = -1;
}
break;
@@ -808,8 +801,7 @@ sendrequest(const char *cmd, const char *local, const char *remote,
case TYPE_A:
while ((c = getc(fin)) != EOF) {
if (c == '\n') {
- while (hash && (!progress || filesize < 0) &&
- (bytes >= hashbytes)) {
+ while (hash_interval && bytes >= hashbytes) {
(void)putc('#', ttyout);
(void)fflush(ttyout);
hashbytes += mark;
@@ -821,23 +813,23 @@ sendrequest(const char *cmd, const char *local, const char *remote,
}
(void)putc(c, dout);
bytes++;
-#if 0 /* this violates RFC */
+#if 0 /* this violates RFC0959 */
if (c == '\r') {
(void)putc('\0', dout);
bytes++;
}
#endif
}
- if (hash && (!progress || filesize < 0)) {
+ if (hash_interval) {
if (bytes < hashbytes)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
}
if (ferror(fin))
- warn("local: %s", local);
+ warn("Reading `%s'", local);
if (ferror(dout)) {
if (errno != EPIPE)
- warn("netout");
+ warn("Writing to network");
bytes = -1;
}
break;
@@ -894,32 +886,28 @@ sendrequest(const char *cmd, const char *local, const char *remote,
}
void
-recvrequest(const char *cmd, const char *local, const char *remote,
+recvrequest(const char *cmd, const char *volatile local, const char *remote,
const char *lmode, int printnames, int ignorespecial)
{
- FILE *fout, *din;
- int (*closefunc)(FILE *);
- sigfunc oldintr, oldintp;
+ FILE *volatile fout;
+ FILE *volatile din;
+ int (*volatile closefunc)(FILE *);
+ sigfunc volatile oldintr;
+ sigfunc volatile oldintp;
int c, d;
- volatile int is_retr, tcrflag, bare_lfs;
+ int volatile is_retr;
+ int volatile tcrflag;
+ int volatile bare_lfs;
static size_t bufsize;
static char *buf;
- volatile off_t hashbytes;
+ off_t volatile hashbytes;
+ int hash_interval;
struct stat st;
time_t mtime;
struct timeval tval[2];
int oprogress;
int opreserve;
-#ifdef __GNUC__ /* to shut up gcc warnings */
- (void)&local;
- (void)&fout;
- (void)&din;
- (void)&closefunc;
- (void)&oldintr;
- (void)&oldintp;
-#endif
-
fout = NULL;
din = NULL;
hashbytes = mark;
@@ -931,7 +919,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
opreserve = preserve;
is_retr = (strcmp(cmd, "RETR") == 0);
if (is_retr && verbose && printnames) {
- if (local && (ignorespecial || *local != '-'))
+ if (ignorespecial || *local != '-')
fprintf(ttyout, "local: %s ", local);
if (remote)
fprintf(ttyout, "remote: %s\n", remote);
@@ -957,7 +945,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
char *dir = strrchr(local, '/');
if (errno != ENOENT && errno != EACCES) {
- warn("local: %s", local);
+ warn("Can't access `%s'", local);
code = -1;
goto cleanuprecv;
}
@@ -968,13 +956,13 @@ recvrequest(const char *cmd, const char *local, const char *remote,
if (dir != NULL)
*dir = '/';
if (d < 0) {
- warn("local: %s", local);
+ warn("Can't access `%s'", local);
code = -1;
goto cleanuprecv;
}
if (!runique && errno == EACCES &&
chmod(local, (S_IRUSR|S_IWUSR)) < 0) {
- warn("local: %s", local);
+ warn("Can't chmod `%s'", local);
code = -1;
goto cleanuprecv;
}
@@ -1026,7 +1014,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
oldintp = xsignal(SIGPIPE, SIG_IGN);
fout = popen(local + 1, "w");
if (fout == NULL) {
- warn("%s", local+1);
+ warn("Can't execute `%s'", local+1);
goto abort;
}
progress = 0;
@@ -1035,7 +1023,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
} else {
fout = fopen(local, lmode);
if (fout == NULL) {
- warn("local: %s", local);
+ warn("Can't open `%s'", local);
goto abort;
}
closefunc = fclose;
@@ -1045,14 +1033,15 @@ recvrequest(const char *cmd, const char *local, const char *remote,
progress = 0;
preserve = 0;
}
- if (rcvbuf_size > bufsize) {
+ if ((size_t)rcvbuf_size > bufsize) {
if (buf)
(void)free(buf);
bufsize = rcvbuf_size;
- buf = xmalloc(bufsize);
+ buf = ftp_malloc(bufsize);
}
progressmeter(-1);
+ hash_interval = (hash && (!progress || filesize < 0)) ? mark : 0;
switch (curtype) {
@@ -1060,76 +1049,17 @@ recvrequest(const char *cmd, const char *local, const char *remote,
case TYPE_L:
if (is_retr && restart_point &&
lseek(fileno(fout), restart_point, SEEK_SET) < 0) {
- warn("local: %s", local);
+ warn("Can't seek to restart `%s'", local);
goto cleanuprecv;
}
- if (rate_get) { /* rate limiting */
- while (1) {
- struct timeval then, now, td;
- off_t bufrem;
-
- (void)gettimeofday(&then, NULL);
- errno = c = d = 0;
- for (bufrem = rate_get; bufrem > 0; ) {
- if ((c = read(fileno(din), buf,
- MIN(bufsize, bufrem))) <= 0)
- goto recvdone;
- bytes += c;
- bufrem -=c;
- if ((d = write(fileno(fout), buf, c))
- != c)
- goto recvdone;
- if (hash &&
- (!progress || filesize < 0)) {
- while (bytes >= hashbytes) {
- (void)putc('#', ttyout);
- hashbytes += mark;
- }
- (void)fflush(ttyout);
- }
- }
- /* sleep until time is up */
- while (1) {
- (void)gettimeofday(&now, NULL);
- timersub(&now, &then, &td);
- if (td.tv_sec > 0)
- break;
- usleep(1000000 - td.tv_usec);
- }
- }
- } else { /* faster code (no limiting) */
- while (1) {
- errno = c = d = 0;
- if ((c = read(fileno(din), buf, bufsize)) <= 0)
- goto recvdone;
- bytes += c;
- if ((d = write(fileno(fout), buf, c)) != c)
- goto recvdone;
- if (hash && (!progress || filesize < 0)) {
- while (bytes >= hashbytes) {
- (void)putc('#', ttyout);
- hashbytes += mark;
- }
- (void)fflush(ttyout);
- }
- }
- }
- recvdone:
- if (hash && (!progress || filesize < 0) && bytes > 0) {
- if (bytes < mark)
- (void)putc('#', ttyout);
- (void)putc('\n', ttyout);
- }
- if (c < 0) {
+ c = copy_bytes(fileno(din), fileno(fout), buf, bufsize,
+ rate_get, hash_interval);
+ if (c == 1) {
if (errno != EPIPE)
- warn("netin");
+ warn("Reading from network");
bytes = -1;
- }
- if (d < c) {
- if (d < 0)
- warn("local: %s", local);
- else
- warnx("%s: short write", local);
+ } else if (c == 2) {
+ warn("Writing `%s'", local);
}
break;
@@ -1148,7 +1078,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
}
if (fseeko(fout, (off_t)0, SEEK_CUR) < 0) {
done:
- warn("local: %s", local);
+ warn("Can't seek to restart `%s'", local);
goto cleanuprecv;
}
}
@@ -1156,8 +1086,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
if (c == '\n')
bare_lfs++;
while (c == '\r') {
- while (hash && (!progress || filesize < 0) &&
- (bytes >= hashbytes)) {
+ while (hash_interval && bytes >= hashbytes) {
(void)putc('#', ttyout);
(void)fflush(ttyout);
hashbytes += mark;
@@ -1180,18 +1109,18 @@ recvrequest(const char *cmd, const char *local, const char *remote,
contin2: ;
}
break2:
- if (hash && (!progress || filesize < 0)) {
+ if (hash_interval) {
if (bytes < hashbytes)
(void)putc('#', ttyout);
(void)putc('\n', ttyout);
}
if (ferror(din)) {
if (errno != EPIPE)
- warn("netin");
+ warn("Reading from network");
bytes = -1;
}
if (ferror(fout))
- warn("local: %s", local);
+ warn("Writing `%s'", local);
break;
}
@@ -1221,7 +1150,8 @@ recvrequest(const char *cmd, const char *local, const char *remote,
if (utimes(local, tval) == -1) {
fprintf(ttyout,
"Can't change modification time on %s to %s",
- local, asctime(localtime(&mtime)));
+ local,
+ rfc2822time(localtime(&mtime)));
}
}
}
@@ -1230,7 +1160,7 @@ recvrequest(const char *cmd, const char *local, const char *remote,
abort:
/*
- * abort using RFC 959 recommended IP,SYNC sequence
+ * abort using RFC0959 recommended IP,SYNC sequence
*/
if (! sigsetjmp(xferabort, 1)) {
/* this is the first call */
@@ -1274,38 +1204,48 @@ initconn(void)
int result, tmpno = 0;
int on = 1;
int error;
- u_int addr[16], port[2];
- u_int af, hal, pal;
+ unsigned int addr[16], port[2];
+ unsigned int af, hal, pal;
socklen_t len;
- char *pasvcmd = NULL;
+ const char *pasvcmd = NULL;
+ int overbose;
#ifdef INET6
- if (myctladdr.su_family == AF_INET6 && debug &&
+#ifndef NO_DEBUG
+ if (myctladdr.su_family == AF_INET6 && ftp_debug &&
(IN6_IS_ADDR_LINKLOCAL(&myctladdr.si_su.su_sin6.sin6_addr) ||
IN6_IS_ADDR_SITELOCAL(&myctladdr.si_su.su_sin6.sin6_addr))) {
- warnx("use of scoped address can be troublesome");
+ warnx("Use of scoped addresses can be troublesome");
}
#endif
+#endif
+
reinit:
if (passivemode) {
data_addr = myctladdr;
data = socket(data_addr.su_family, SOCK_STREAM, 0);
if (data < 0) {
- warn("socket");
+ warn("Can't create socket for data connection");
return (1);
}
if ((options & SO_DEBUG) &&
setsockopt(data, SOL_SOCKET, SO_DEBUG,
(void *)&on, sizeof(on)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)", "SO_DEBUG");
+ DWARN("setsockopt %s (ignored)", "SO_DEBUG");
}
result = COMPLETE + 1;
switch (data_addr.su_family) {
case AF_INET:
if (epsv4 && !epsv4bad) {
pasvcmd = "EPSV";
+ overbose = verbose;
+ if (ftp_debug == 0)
+ verbose = -1;
result = command("EPSV");
+ verbose = overbose;
+ if (verbose > 0 &&
+ (result == COMPLETE || !connected))
+ fprintf(ttyout, "%s\n", reply_string);
if (!connected)
return (1);
/*
@@ -1320,10 +1260,8 @@ initconn(void)
}
if (result != COMPLETE) {
epsv4bad = 1;
- if (debug)
- fputs(
- "disabling epsv4 for this connection\n",
- ttyout);
+ DPRINTF("disabling epsv4 for this "
+ "connection\n");
}
}
if (result != COMPLETE) {
@@ -1335,16 +1273,33 @@ initconn(void)
break;
#ifdef INET6
case AF_INET6:
- pasvcmd = "EPSV";
- result = command("EPSV");
- if (!connected)
- return (1);
- /* this code is to be friendly with broken BSDI ftpd */
- if (code / 10 == 22 && code != 229) {
- fputs(
-"wrong server: return code must be 229\n",
- ttyout);
- result = COMPLETE + 1;
+ if (epsv6 && !epsv6bad) {
+ pasvcmd = "EPSV";
+ overbose = verbose;
+ if (ftp_debug == 0)
+ verbose = -1;
+ result = command("EPSV");
+ verbose = overbose;
+ if (verbose > 0 &&
+ (result == COMPLETE || !connected))
+ fprintf(ttyout, "%s\n", reply_string);
+ if (!connected)
+ return (1);
+ /*
+ * this code is to be friendly with
+ * broken BSDI ftpd
+ */
+ if (code / 10 == 22 && code != 229) {
+ fputs(
+ "wrong server: return code must be 229\n",
+ ttyout);
+ result = COMPLETE + 1;
+ }
+ if (result != COMPLETE) {
+ epsv6bad = 1;
+ DPRINTF("disabling epsv6 for this "
+ "connection\n");
+ }
}
if (result != COMPLETE) {
pasvcmd = "LPSV";
@@ -1476,7 +1431,7 @@ initconn(void)
data_addr.su_family = AF_INET6;
data_addr.su_len = sizeof(struct sockaddr_in6);
{
- int i;
+ size_t i;
for (i = 0; i < sizeof(struct in6_addr); i++) {
data_addr.si_su.su_sin6.sin6_addr.s6_addr[i] =
UC(addr[i]);
@@ -1516,8 +1471,8 @@ initconn(void)
} else
goto bad;
- while (xconnect(data, (struct sockaddr *)&data_addr.si_su,
- data_addr.su_len) < 0) {
+ if (ftp_connect(data, (struct sockaddr *)&data_addr.si_su,
+ data_addr.su_len) < 0) {
if (activefallback) {
(void)close(data);
data = -1;
@@ -1527,7 +1482,6 @@ initconn(void)
#endif
goto reinit;
}
- warn("connect for data channel");
goto bad;
}
#ifdef IPTOS_THROUGHPUT
@@ -1535,9 +1489,8 @@ initconn(void)
on = IPTOS_THROUGHPUT;
if (setsockopt(data, IPPROTO_IP, IP_TOS,
(void *)&on, sizeof(on)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)",
- "IPTOS_THROUGHPUT");
+ DWARN("setsockopt %s (ignored)",
+ "IPTOS_THROUGHPUT");
}
}
#endif
@@ -1552,7 +1505,7 @@ initconn(void)
(void)close(data);
data = socket(data_addr.su_family, SOCK_STREAM, 0);
if (data < 0) {
- warn("socket");
+ warn("Can't create socket for data connection");
if (tmpno)
sendport = 1;
return (1);
@@ -1560,33 +1513,31 @@ initconn(void)
if (!sendport)
if (setsockopt(data, SOL_SOCKET, SO_REUSEADDR,
(void *)&on, sizeof(on)) == -1) {
- warn("setsockopt %s", "SO_REUSEADDR");
+ warn("Can't set SO_REUSEADDR on data connection");
goto bad;
}
if (bind(data, (struct sockaddr *)&data_addr.si_su,
data_addr.su_len) < 0) {
- warn("bind");
+ warn("Can't bind for data connection");
goto bad;
}
if ((options & SO_DEBUG) &&
setsockopt(data, SOL_SOCKET, SO_DEBUG,
(void *)&on, sizeof(on)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)", "SO_DEBUG");
+ DWARN("setsockopt %s (ignored)", "SO_DEBUG");
}
len = sizeof(data_addr.si_su);
memset((char *)&data_addr, 0, sizeof (data_addr));
if (getsockname(data, (struct sockaddr *)&data_addr.si_su, &len) == -1) {
- warn("getsockname");
+ warn("Can't determine my address of data connection");
goto bad;
}
data_addr.su_len = len;
- if (xlisten(data, 1) < 0)
- warn("listen");
+ if (ftp_listen(data, 1) < 0)
+ warn("Can't listen to data connection");
if (sendport) {
char hname[NI_MAXHOST], sname[NI_MAXSERV];
- int af;
struct sockinet tmp;
switch (data_addr.su_family) {
@@ -1598,6 +1549,10 @@ initconn(void)
/* FALLTHROUGH */
#ifdef INET6
case AF_INET6:
+ if (!epsv6 || epsv6bad) {
+ result = COMPLETE + 1;
+ break;
+ }
#endif
af = (data_addr.su_family == AF_INET) ? 1 : 2;
tmp = data_addr;
@@ -1610,16 +1565,21 @@ initconn(void)
sizeof(sname), NI_NUMERICHOST | NI_NUMERICSERV)) {
result = ERROR;
} else {
- result = command("EPRT |%d|%s|%s|", af, hname,
+ overbose = verbose;
+ if (ftp_debug == 0)
+ verbose = -1;
+ result = command("EPRT |%u|%s|%s|", af, hname,
sname);
+ verbose = overbose;
+ if (verbose > 0 &&
+ (result == COMPLETE || !connected))
+ fprintf(ttyout, "%s\n", reply_string);
if (!connected)
return (1);
if (result != COMPLETE) {
epsv4bad = 1;
- if (debug)
- fputs(
- "disabling epsv4 for this connection\n",
- ttyout);
+ DPRINTF("disabling epsv4 for this "
+ "connection\n");
}
}
break;
@@ -1672,10 +1632,9 @@ initconn(void)
if (data_addr.su_family == AF_INET) {
on = IPTOS_THROUGHPUT;
if (setsockopt(data, IPPROTO_IP, IP_TOS,
- (void *)&on, sizeof(on)) == -1)
- if (debug)
- warn("setsockopt %s (ignored)",
- "IPTOS_THROUGHPUT");
+ (void *)&on, sizeof(on)) == -1) {
+ DWARN("setsockopt %s (ignored)", "IPTOS_THROUGHPUT");
+ }
}
#endif
return (0);
@@ -1720,14 +1679,14 @@ dataconn(const char *lmode)
timeout = td.tv_sec * 1000 + td.tv_usec/1000;
if (timeout < 0)
timeout = 0;
- rv = xpoll(pfd, 1, timeout);
+ rv = ftp_poll(pfd, 1, timeout);
} while (rv == -1 && errno == EINTR); /* loop until poll ! EINTR */
if (rv == -1) {
- warn("poll waiting before accept");
+ warn("Can't poll waiting before accept");
goto dataconn_failed;
}
if (rv == 0) {
- warn("poll timeout waiting before accept");
+ warnx("Poll timeout waiting before accept");
goto dataconn_failed;
}
@@ -1737,7 +1696,7 @@ dataconn(const char *lmode)
s = accept(data, (struct sockaddr *) &from.si_su, &fromlen);
} while (s == -1 && errno == EINTR); /* loop until accept ! EINTR */
if (s == -1) {
- warn("accept");
+ warn("Can't accept data connection");
goto dataconn_failed;
}
@@ -1751,9 +1710,7 @@ dataconn(const char *lmode)
int tos = IPTOS_THROUGHPUT;
if (setsockopt(s, IPPROTO_IP, IP_TOS,
(void *)&tos, sizeof(tos)) == -1) {
- if (debug)
- warn("setsockopt %s (ignored)",
- "IPTOS_THROUGHPUT");
+ DWARN("setsockopt %s (ignored)", "IPTOS_THROUGHPUT");
}
}
#endif
@@ -1880,15 +1837,10 @@ abortpt(int notused)
void
proxtrans(const char *cmd, const char *local, const char *remote)
{
- sigfunc oldintr;
+ sigfunc volatile oldintr;
int prox_type, nfnd;
- volatile int secndflag;
- char *cmd2;
-
-#ifdef __GNUC__ /* to shut up gcc warnings */
- (void)&oldintr;
- (void)&cmd2;
-#endif
+ int volatile secndflag;
+ const char *volatile cmd2;
oldintr = NULL;
secndflag = 0;
@@ -1992,7 +1944,7 @@ proxtrans(const char *cmd, const char *local, const char *remote)
if (cpend) {
if ((nfnd = empty(cin, NULL, 10)) <= 0) {
if (nfnd < 0)
- warn("abort");
+ warn("Error aborting proxy command");
if (ptabflg)
code = -1;
lostpeer(0);
@@ -2014,13 +1966,13 @@ reset(int argc, char *argv[])
int nfnd = 1;
if (argc == 0 && argv != NULL) {
- fprintf(ttyout, "usage: %s\n", argv[0]);
+ UPRINTF("usage: %s\n", argv[0]);
code = -1;
return;
}
while (nfnd > 0) {
if ((nfnd = empty(cin, NULL, 0)) < 0) {
- warn("reset");
+ warn("Error resetting connection");
code = -1;
lostpeer(0);
} else if (nfnd)
@@ -2042,7 +1994,7 @@ gunique(const char *local)
if (cp)
*cp = '/';
if (d < 0) {
- warn("local: %s", local);
+ warn("Can't access `%s'", local);
return (NULL);
}
len = strlcpy(new, local, sizeof(new));
@@ -2102,7 +2054,7 @@ abort_remote(FILE *din)
int nfnd;
if (cout == NULL) {
- warnx("Lost control connection for abort.");
+ warnx("Lost control connection for abort");
if (ptabflg)
code = -1;
lostpeer(0);
@@ -2116,12 +2068,12 @@ abort_remote(FILE *din)
buf[1] = IP;
buf[2] = IAC;
if (send(fileno(cout), buf, 3, MSG_OOB) != 3)
- warn("abort");
+ warn("Can't send abort message");
fprintf(cout, "%cABOR\r\n", DM);
(void)fflush(cout);
if ((nfnd = empty(cin, din, 10)) <= 0) {
if (nfnd < 0)
- warn("abort");
+ warn("Can't send abort message");
if (ptabflg)
code = -1;
lostpeer(0);
@@ -2137,6 +2089,24 @@ abort_remote(FILE *din)
(void)getreply(0);
}
+/*
+ * Ensure that ai->ai_addr is NOT an IPv4 mapped address.
+ * IPv4 mapped address complicates too many things in FTP
+ * protocol handling, as FTP protocol is defined differently
+ * between IPv4 and IPv6.
+ *
+ * This may not be the best way to handle this situation,
+ * since the semantics of IPv4 mapped address is defined in
+ * the kernel. There are configurations where we should use
+ * IPv4 mapped address as native IPv6 address, not as
+ * "an IPv6 address that embeds IPv4 address" (namely, SIIT).
+ *
+ * More complete solution would be to have an additional
+ * getsockopt to grab "real" peername/sockname. "real"
+ * peername/sockname will be AF_INET if IPv4 mapped address
+ * is used to embed IPv4 address, and will be AF_INET6 if
+ * we use it as native. What a mess!
+ */
void
ai_unmapped(struct addrinfo *ai)
{
@@ -2162,10 +2132,18 @@ ai_unmapped(struct addrinfo *ai)
sin.sin_port = sin6->sin6_port;
ai->ai_family = AF_INET;
-#if HAVE_SOCKADDR_SA_LEN
+#if defined(HAVE_STRUCT_SOCKADDR_IN_SIN_LEN)
sin.sin_len = len;
#endif
memcpy(ai->ai_addr, &sin, len);
ai->ai_addrlen = len;
#endif
}
+
+#ifdef NO_USAGE
+void
+xusage(void)
+{
+ fputs("Usage error\n", ttyout);
+}
+#endif
diff --git a/src/ftp.cat1 b/src/ftp.cat1
deleted file mode 100644
index 091a1190c2f70..0000000000000
--- a/src/ftp.cat1
+++ /dev/null
@@ -1,1055 +0,0 @@
-FTP(1) NetBSD Reference Manual FTP(1)
-
-NNAAMMEE
- ffttpp - Internet file transfer program
-
-SSYYNNOOPPSSIISS
- ffttpp [--4466AAaaddeeffggiinnppRRttvvVV] [--NN _n_e_t_r_c] [--oo _o_u_t_p_u_t] [--PP _p_o_r_t] [--rr _r_e_t_r_y] [--TT
- _d_i_r,_m_a_x[,_i_n_c]] [[_u_s_e_r@]_h_o_s_t [_p_o_r_t]] [_u_s_e_r@]_h_o_s_t:[_p_a_t_h][/]
- [file:///_p_a_t_h] [ftp://[_u_s_e_r[:_p_a_s_s_w_o_r_d]@]_h_o_s_t[:_p_o_r_t]/_p_a_t_h[/]]
- [http://[_u_s_e_r[:_p_a_s_s_w_o_r_d]@]_h_o_s_t[:_p_o_r_t]/_p_a_t_h] [_._._.]
- ffttpp --uu _u_r_l file [_._._.]
-
-DDEESSCCRRIIPPTTIIOONN
- ffttpp is the user interface to the Internet standard File Transfer Proto-
- col. The program allows a user to transfer files to and from a remote
- network site.
-
- The last five arguments will fetch a file using the FTP or HTTP proto-
- cols, or by direct copying, into the current directory. This is ideal
- for scripts. Refer to _A_U_T_O_-_F_E_T_C_H_I_N_G _F_I_L_E_S below for more information.
-
- Options may be specified at the command line, or to the command inter-
- preter.
-
- --44 Forces ffttpp to only use IPv4 addresses.
-
- --66 Forces ffttpp to only use IPv6 addresses.
-
- --AA Force active mode ftp. By default, ffttpp will try to use passive
- mode ftp and fall back to active mode if passive is not support-
- ed by the server. This option causes ffttpp to always use an ac-
- tive connection. It is only useful for connecting to very old
- servers that do not implement passive mode properly.
-
- --aa Causes ffttpp to bypass normal login procedure, and use an anony-
- mous login instead.
-
- --dd Enables debugging.
-
- --ee Disables command line editing. This is useful for Emacs ange-
- ftp mode.
-
- --ff Forces a cache reload for transfers that go through the FTP or
- HTTP proxies.
-
- --gg Disables file name globbing.
-
- --ii Turns off interactive prompting during multiple file transfers.
-
- --nn Restrains ffttpp from attempting ``auto-login'' upon initial con-
- nection. If auto-login is enabled, ffttpp will check the _._n_e_t_r_c
- (see below) file in the user's home directory for an entry de-
- scribing an account on the remote machine. If no entry exists,
- ffttpp will prompt for the remote machine login name (default is
- the user identity on the local machine), and, if necessary,
- prompt for a password and an account with which to login.
-
- --NN _n_e_t_r_c
- Use _n_e_t_r_c instead of _~_/_._n_e_t_r_c. Refer to _T_H_E _._n_e_t_r_c _F_I_L_E for
- more information.
-
- --oo _o_u_t_p_u_t
- When auto-fetching files, save the contents in _o_u_t_p_u_t. _o_u_t_p_u_t
- is parsed according to the _F_I_L_E _N_A_M_I_N_G _C_O_N_V_E_N_T_I_O_N_S below. If
- _o_u_t_p_u_t is not `-' or doesn't start with `|', then only the first
- file specified will be retrieved into _o_u_t_p_u_t; all other files
- will be retrieved into the basename of their remote name.
-
- --pp Enable passive mode operation for use behind connection filter-
- ing firewalls. This option has been deprecated as ffttpp now tries
- to use passive mode by default, falling back to active mode if
- the server does not support passive connections.
-
- --PP _p_o_r_t Sets the port number to _p_o_r_t.
-
- --rr _w_a_i_t Retry the connection attempt if it failed, pausing for _w_a_i_t sec-
- onds.
-
- --RR Restart all non-proxied auto-fetches.
-
- --tt Enables packet tracing.
-
- --TT _d_i_r_e_c_t_i_o_n,_m_a_x_i_m_u_m[,_i_n_c_r_e_m_e_n_t]
- Set the maximum transfer rate for _d_i_r_e_c_t_i_o_n to _m_a_x_i_m_u_m
- bytes/second, and if specified, the increment to _i_n_c_r_e_m_e_n_t
- bytes/second. Refer to rraattee for more information.
-
- --uu _u_r_l _f_i_l_e [...]
- Upload files on the command line to _u_r_l where _u_r_l is one of the
- ftp URL types as supported by auto-fetch (with an optional tar-
- get filename for single file uploads), and _f_i_l_e is one or more
- local files to be uploaded.
-
- --vv Enable vveerrbboossee and pprrooggrreessss. This is the default if output is
- to a terminal (and in the case of pprrooggrreessss, ffttpp is the fore-
- ground process). Forces ffttpp to show all responses from the re-
- mote server, as well as report on data transfer statistics.
-
- --VV Disable vveerrbboossee and pprrooggrreessss, overriding the default of enabled
- when output is to a terminal.
-
- The client host with which ffttpp is to communicate may be specified on the
- command line. If this is done, ffttpp will immediately attempt to establish
- a connection to an FTP server on that host; otherwise, ffttpp will enter its
- command interpreter and await instructions from the user. When ffttpp is
- awaiting commands from the user the prompt `ftp>' is provided to the us-
- er. The following commands are recognized by ffttpp:
-
- !! [_c_o_m_m_a_n_d [_a_r_g_s]]
- Invoke an interactive shell on the local machine. If there
- are arguments, the first is taken to be a command to execute
- directly, with the rest of the arguments as its arguments.
-
- $$ _m_a_c_r_o_-_n_a_m_e [_a_r_g_s]
- Execute the macro _m_a_c_r_o_-_n_a_m_e that was defined with the mmaaccddeeff
- command. Arguments are passed to the macro unglobbed.
-
- aaccccoouunntt [_p_a_s_s_w_d]
- Supply a supplemental password required by a remote system
- for access to resources once a login has been successfully
- completed. If no argument is included, the user will be
- prompted for an account password in a non-echoing input mode.
-
- aappppeenndd _l_o_c_a_l_-_f_i_l_e [_r_e_m_o_t_e_-_f_i_l_e]
- Append a local file to a file on the remote machine. If
- _r_e_m_o_t_e_-_f_i_l_e is left unspecified, the local file name is used
- in naming the remote file after being altered by any nnttrraannss
- or nnmmaapp setting. File transfer uses the current settings for
- ttyyppee, ffoorrmmaatt, mmooddee, and ssttrruuccttuurree.
-
- aasscciiii Set the file transfer ttyyppee to network ASCII. This is the de-
- fault type.
-
- bbeellll Arrange that a bell be sounded after each file transfer com-
- mand is completed.
-
- bbiinnaarryy Set the file transfer ttyyppee to support binary image transfer.
-
- bbyyee Terminate the FTP session with the remote server and exit
- ffttpp. An end of file will also terminate the session and ex-
- it.
-
- ccaassee Toggle remote computer file name case mapping during ggeett,
- mmggeett and mmppuutt commands. When ccaassee is on (default is off),
- remote computer file names with all letters in upper case are
- written in the local directory with the letters mapped to
- lower case.
-
- ccdd _r_e_m_o_t_e_-_d_i_r_e_c_t_o_r_y
- Change the working directory on the remote machine to _r_e_m_o_t_e_-
- _d_i_r_e_c_t_o_r_y.
-
- ccdduupp Change the remote machine working directory to the parent of
- the current remote machine working directory.
-
- cchhmmoodd _m_o_d_e _r_e_m_o_t_e_-_f_i_l_e
- Change the permission modes of the file _r_e_m_o_t_e_-_f_i_l_e on the
- remote system to _m_o_d_e.
-
- cclloossee Terminate the FTP session with the remote server, and return
- to the command interpreter. Any defined macros are erased.
-
- ccrr Toggle carriage return stripping during ascii type file re-
- trieval. Records are denoted by a carriage return/linefeed
- sequence during ascii type file transfer. When ccrr is on (the
- default), carriage returns are stripped from this sequence to
- conform with the UNIX single linefeed record delimiter.
- Records on non-UNIX remote systems may contain single line-
- feeds; when an ascii type transfer is made, these linefeeds
- may be distinguished from a record delimiter only when ccrr is
- off.
-
- ddeebbuugg [_d_e_b_u_g_-_v_a_l_u_e]
- Toggle debugging mode. If an optional _d_e_b_u_g_-_v_a_l_u_e is speci-
- fied it is used to set the debugging level. When debugging
- is on, ffttpp prints each command sent to the remote machine,
- preceded by the string `-->'
-
- ddeelleettee _r_e_m_o_t_e_-_f_i_l_e
- Delete the file _r_e_m_o_t_e_-_f_i_l_e on the remote machine.
-
- ddiirr [_r_e_m_o_t_e_-_p_a_t_h [_l_o_c_a_l_-_f_i_l_e]]
- Print a listing of the contents of a directory on the remote
- machine. The listing includes any system-dependent informa-
- tion that the server chooses to include; for example, most
- UNIX systems will produce output from the command `ls -l'.
- If _r_e_m_o_t_e_-_p_a_t_h is left unspecified, the current working di-
- rectory is used. If interactive prompting is on, ffttpp will
- prompt the user to verify that the last argument is indeed
- the target local file for receiving ddiirr output. If no local
- file is specified, or if _l_o_c_a_l_-_f_i_l_e is `--', the output is
- sent to the terminal.
-
- ddiissccoonnnneecctt A synonym for cclloossee.
-
- eeddiitt Toggle command line editing, and context sensitive command
- and file completion. This is automatically enabled if input
- is from a terminal, and disabled otherwise.
-
- eeppssvv44 Toggle the use of the extended EPSV and EPRT commands on IPv4
- connections; first try EPSV / EPRT, and then PASV / PORT.
- This is enabled by default. If an extended command fails
- then this option will be temporarily disabled for the dura-
- tion of the current connection, or until eeppssvv44 is executed
- again.
-
- eexxiitt A synonym for bbyyee.
-
- ffeeaattuurreess Display what features the remote server supports (using the
- FEAT command).
-
- ffggeett _l_o_c_a_l_f_i_l_e
- Retrieve the files listed in _l_o_c_a_l_f_i_l_e, which has one line
- per filename.
-
- ffoorrmm _f_o_r_m_a_t
- Set the file transfer ffoorrmm to _f_o_r_m_a_t. The default (and only
- supported) format is ``non-print''.
-
- ffttpp _h_o_s_t [_p_o_r_t]
- A synonym for ooppeenn.
-
- ggaattee [_h_o_s_t [_p_o_r_t]]
- Toggle gate-ftp mode, which used to connect through the TIS
- FWTK and Gauntlet ftp proxies. This will not be permitted if
- the gate-ftp server hasn't been set (either explicitly by the
- user, or from the FTPSERVER environment variable). If _h_o_s_t
- is given, then gate-ftp mode will be enabled, and the gate-
- ftp server will be set to _h_o_s_t. If _p_o_r_t is also given, that
- will be used as the port to connect to on the gate-ftp serv-
- er.
-
- ggeett _r_e_m_o_t_e_-_f_i_l_e [_l_o_c_a_l_-_f_i_l_e]
- Retrieve the _r_e_m_o_t_e_-_f_i_l_e and store it on the local machine.
- If the local file name is not specified, it is given the same
- name it has on the remote machine, subject to alteration by
- the current ccaassee, nnttrraannss, and nnmmaapp settings. The current
- settings for ttyyppee, ffoorrmm, mmooddee, and ssttrruuccttuurree are used while
- transferring the file.
-
- gglloobb Toggle filename expansion for mmddeelleettee, mmggeett, mmppuutt, and
- mmrreeggeett. If globbing is turned off with gglloobb, the file name
- arguments are taken literally and not expanded. Globbing for
- mmppuutt is done as in csh(1). For mmddeelleettee, mmggeett, and mmrreeggeett,
- each remote file name is expanded separately on the remote
- machine and the lists are not merged. Expansion of a direc-
- tory name is likely to be different from expansion of the
- name of an ordinary file: the exact result depends on the
- foreign operating system and ftp server, and can be previewed
- by doing `mls remote-files -' Note: mmggeett, mmppuutt and mmrreeggeett are
- not meant to transfer entire directory subtrees of files.
- That can be done by transferring a tar(1) archive of the sub-
- tree (in binary mode).
-
- hhaasshh [_s_i_z_e]
- Toggle hash-sign (``#'') printing for each data block trans-
- ferred. The size of a data block defaults to 1024 bytes.
- This can be changed by specifying _s_i_z_e in bytes. Enabling
- hhaasshh disables pprrooggrreessss.
-
- hheellpp [_c_o_m_m_a_n_d]
- Print an informative message about the meaning of _c_o_m_m_a_n_d.
- If no argument is given, ffttpp prints a list of the known com-
- mands.
-
- iiddllee [_s_e_c_o_n_d_s]
- Set the inactivity timer on the remote server to _s_e_c_o_n_d_s sec-
- onds. If _s_e_c_o_n_d_s is omitted, the current inactivity timer is
- printed.
-
- iimmaaggee A synonym for bbiinnaarryy.
-
- llccdd [_d_i_r_e_c_t_o_r_y]
- Change the working directory on the local machine. If no
- _d_i_r_e_c_t_o_r_y is specified, the user's home directory is used.
-
- lleessss _f_i_l_e A synonym for ppaaggee.
-
- llppaaggee _l_o_c_a_l_-_f_i_l_e
- Display _l_o_c_a_l_-_f_i_l_e with the program specified by the sseett
- ppaaggeerr option.
-
- llppwwdd Print the working directory on the local machine.
-
- llss [_r_e_m_o_t_e_-_p_a_t_h [_l_o_c_a_l_-_f_i_l_e]]
- A synonym for ddiirr.
-
- mmaaccddeeff _m_a_c_r_o_-_n_a_m_e
- Define a macro. Subsequent lines are stored as the macro
- _m_a_c_r_o_-_n_a_m_e; a null line (consecutive newline characters in a
- file or carriage returns from the terminal) terminates macro
- input mode. There is a limit of 16 macros and 4096 total
- characters in all defined macros. Macros remain defined un-
- til a cclloossee command is executed. The macro processor inter-
- prets `$' and `\' as special characters. A `$' followed by a
- number (or numbers) is replaced by the corresponding argument
- on the macro invocation command line. A `$' followed by an
- `i' signals that macro processor that the executing macro is
- to be looped. On the first pass `$i' is replaced by the
- first argument on the macro invocation command line, on the
- second pass it is replaced by the second argument, and so on.
- A `\' followed by any character is replaced by that charac-
- ter. Use the `\' to prevent special treatment of the `$'.
-
- mmddeelleettee [_r_e_m_o_t_e_-_f_i_l_e_s]
- Delete the _r_e_m_o_t_e_-_f_i_l_e_s on the remote machine.
-
- mmddiirr _r_e_m_o_t_e_-_f_i_l_e_s _l_o_c_a_l_-_f_i_l_e
- Like ddiirr, except multiple remote files may be specified. If
- interactive prompting is on, ffttpp will prompt the user to ver-
- ify that the last argument is indeed the target local file
- for receiving mmddiirr output.
-
- mmggeett _r_e_m_o_t_e_-_f_i_l_e_s
- Expand the _r_e_m_o_t_e_-_f_i_l_e_s on the remote machine and do a ggeett
- for each file name thus produced. See gglloobb for details on
- the filename expansion. Resulting file names will then be
- processed according to ccaassee, nnttrraannss, and nnmmaapp settings.
- Files are transferred into the local working directory, which
- can be changed with `lcd directory'; new local directories
- can be created with `! mkdir directory'.
-
- mmkkddiirr _d_i_r_e_c_t_o_r_y_-_n_a_m_e
- Make a directory on the remote machine.
-
- mmllss _r_e_m_o_t_e_-_f_i_l_e_s _l_o_c_a_l_-_f_i_l_e
- Like llss, except multiple remote files may be specified, and
- the _l_o_c_a_l_-_f_i_l_e must be specified. If interactive prompting
- is on, ffttpp will prompt the user to verify that the last argu-
- ment is indeed the target local file for receiving mmllss out-
- put.
-
- mmllssdd [_r_e_m_o_t_e_-_p_a_t_h]
- Display the contents of _r_e_m_o_t_e_-_p_a_t_h (which should default to
- the current directory if not given) in a machine-parsable
- form, using MLSD. The format of display can be changed with
- `remopts mlst ...'.
-
- mmllsstt [_r_e_m_o_t_e_-_p_a_t_h]
- Display the details about _r_e_m_o_t_e_-_p_a_t_h (which should default
- to the current directory if not given) in a machine-parsable
- form, using MLST. The format of display can be changed with
- `remopts mlst ...'.
-
- mmooddee _m_o_d_e_-_n_a_m_e
- Set the file transfer mmooddee to _m_o_d_e_-_n_a_m_e. The default (and
- only supported) mode is ``stream''.
-
- mmooddttiimmee _r_e_m_o_t_e_-_f_i_l_e
- Show the last modification time of the file on the remote ma-
- chine.
-
- mmoorree _f_i_l_e A synonym for ppaaggee.
-
- mmppuutt _l_o_c_a_l_-_f_i_l_e_s
- Expand wild cards in the list of local files given as argu-
- ments and do a ppuutt for each file in the resulting list. See
- gglloobb for details of filename expansion. Resulting file names
- will then be processed according to nnttrraannss and nnmmaapp settings.
-
- mmrreeggeett _r_e_m_o_t_e_-_f_i_l_e_s
- As per mmggeett, but performs a rreeggeett instead of ggeett.
-
- mmsseenndd _l_o_c_a_l_-_f_i_l_e_s
- A synonym for mmppuutt.
-
- nneewweerr _r_e_m_o_t_e_-_f_i_l_e [_l_o_c_a_l_-_f_i_l_e]
- Get the file only if the modification time of the remote file
- is more recent that the file on the current system. If the
- file does not exist on the current system, the remote file is
- considered nneewweerr. Otherwise, this command is identical to
- _g_e_t.
-
- nnlliisstt [_r_e_m_o_t_e_-_p_a_t_h [_l_o_c_a_l_-_f_i_l_e]]
- A synonym for llss.
-
- nnmmaapp [_i_n_p_a_t_t_e_r_n _o_u_t_p_a_t_t_e_r_n]
- Set or unset the filename mapping mechanism. If no arguments
- are specified, the filename mapping mechanism is unset. If
- arguments are specified, remote filenames are mapped during
- mmppuutt commands and ppuutt commands issued without a specified re-
- mote target filename. If arguments are specified, local
- filenames are mapped during mmggeett commands and ggeett commands
- issued without a specified local target filename. This com-
- mand is useful when connecting to a non-UNIX remote computer
- with different file naming conventions or practices. The
- mapping follows the pattern set by _i_n_p_a_t_t_e_r_n and _o_u_t_p_a_t_t_e_r_n.
- [_I_n_p_a_t_t_e_r_n] is a template for incoming filenames (which may
- have already been processed according to the nnttrraannss and ccaassee
- settings). Variable templating is accomplished by including
- the sequences `$1', `$2', ..., `$9' in _i_n_p_a_t_t_e_r_n. Use `\' to
- prevent this special treatment of the `$' character. All
- other characters are treated literally, and are used to de-
- termine the nnmmaapp [_i_n_p_a_t_t_e_r_n] variable values. For example,
- given _i_n_p_a_t_t_e_r_n $1.$2 and the remote file name "mydata.data",
- $1 would have the value "mydata", and $2 would have the value
- "data". The _o_u_t_p_a_t_t_e_r_n determines the resulting mapped file-
- name. The sequences `$1', `$2', ...., `$9' are replaced by
- any value resulting from the _i_n_p_a_t_t_e_r_n template. The se-
- quence `$0' is replace by the original filename. Additional-
- ly, the sequence `[_s_e_q_1, _s_e_q_2]' is replaced by [_s_e_q_1] if _s_e_q_1
- is not a null string; otherwise it is replaced by _s_e_q_2. For
- example, the command
-
- nmap $1.$2.$3 [$1,$2].[$2,file]
-
- would yield the output filename "myfile.data" for input file-
- names "myfile.data" and "myfile.data.old", "myfile.file" for
- the input filename "myfile", and "myfile.myfile" for the in-
- put filename ".myfile". Spaces may be included in
- _o_u_t_p_a_t_t_e_r_n, as in the example: `nmap $1 sed "s/ *$//" > $1'
- . Use the `\' character to prevent special treatment of the
- `$','[',']', and `,' characters.
-
- nnttrraannss [_i_n_c_h_a_r_s [_o_u_t_c_h_a_r_s]]
- Set or unset the filename character translation mechanism.
- If no arguments are specified, the filename character trans-
- lation mechanism is unset. If arguments are specified, char-
- acters in remote filenames are translated during mmppuutt com-
- mands and ppuutt commands issued without a specified remote tar-
- get filename. If arguments are specified, characters in lo-
- cal filenames are translated during mmggeett commands and ggeett
- commands issued without a specified local target filename.
- This command is useful when connecting to a non-UNIX remote
- computer with different file naming conventions or practices.
- Characters in a filename matching a character in _i_n_c_h_a_r_s are
- replaced with the corresponding character in _o_u_t_c_h_a_r_s. If
- the character's position in _i_n_c_h_a_r_s is longer than the length
- of _o_u_t_c_h_a_r_s, the character is deleted from the file name.
-
- ooppeenn _h_o_s_t [_p_o_r_t]
- Establish a connection to the specified _h_o_s_t FTP server. An
- optional port number may be supplied, in which case, ffttpp will
- attempt to contact an FTP server at that port. If the aauuttoo--
- llooggiinn option is on (default), ffttpp will also attempt to auto-
- matically log the user in to the FTP server (see below).
-
- ppaaggee _f_i_l_e Retrieve ffiillee and display with the program specified by the
- sseett ppaaggeerr option.
-
- ppaassssiivvee [aauuttoo]
- Toggle passive mode (if no arguments are given). If aauuttoo is
- given, act as if FTPMODE is set to `auto'. If passive mode
- is turned on (default), ffttpp will send a PASV command for all
- data connections instead of a PORT command. The PASV command
- requests that the remote server open a port for the data con-
- nection and return the address of that port. The remote
- server listens on that port and the client connects to it.
- When using the more traditional PORT command, the client lis-
- tens on a port and sends that address to the remote server,
- who connects back to it. Passive mode is useful when using
- ffttpp through a gateway router or host that controls the direc-
- tionality of traffic. (Note that though FTP servers are re-
- quired to support the PASV command by RFC 1123, some do not.)
-
- ppddiirr [_r_e_m_o_t_e_-_p_a_t_h]
- Perform ddiirr [_r_e_m_o_t_e_-_p_a_t_h], and display the result with the
- program specified by the sseett ppaaggeerr option.
-
- ppllss [_r_e_m_o_t_e_-_p_a_t_h]
- Perform llss [_r_e_m_o_t_e_-_p_a_t_h], and display the result with the
- program specified by the sseett ppaaggeerr option.
-
- ppmmllssdd [_r_e_m_o_t_e_-_p_a_t_h]
- Perform mmllssdd [_r_e_m_o_t_e_-_p_a_t_h], and display the result with the
- program specified by the sseett ppaaggeerr option.
-
- pprreesseerrvvee Toggle preservation of modification times on retrieved files.
-
- pprrooggrreessss Toggle display of transfer progress bar. The progress bar
- will be disabled for a transfer that has _l_o_c_a_l_-_f_i_l_e as `--' or
- a command that starts with `|'. Refer to _F_I_L_E _N_A_M_I_N_G
- _C_O_N_V_E_N_T_I_O_N_S for more information. Enabling pprrooggrreessss disables
- hhaasshh.
-
- pprroommpptt Toggle interactive prompting. Interactive prompting occurs
- during multiple file transfers to allow the user to selec-
- tively retrieve or store files. If prompting is turned off
- (default is on), any mmggeett or mmppuutt will transfer all files,
- and any mmddeelleettee will delete all files.
-
- When prompting is on, the following commands are available at
- a prompt:
-
- aa Answer `yes' to the current file, and automatically
- answer `yes' to any remaining files for the current
- command.
-
- nn Answer `no', and do not transfer the file.
-
- pp Answer `yes' to the current file, and turn off
- prompt mode (as is ``prompt off'' had been given).
-
- qq Terminate the current operation.
-
- yy Answer `yes', and transfer the file.
-
- ?? Display a help message.
-
- Any other reponse will answer `yes' to the current file.
-
- pprrooxxyy _f_t_p_-_c_o_m_m_a_n_d
- Execute an ftp command on a secondary control connection.
- This command allows simultaneous connection to two remote FTP
- servers for transferring files between the two servers. The
- first pprrooxxyy command should be an ooppeenn, to establish the sec-
- ondary control connection. Enter the command "proxy ?" to
- see other FTP commands executable on the secondary connec-
- tion. The following commands behave differently when pref-
- aced by pprrooxxyy: ooppeenn will not define new macros during the au-
- to-login process, cclloossee will not erase existing macro defini-
- tions, ggeett and mmggeett transfer files from the host on the pri-
- mary control connection to the host on the secondary control
- connection, and ppuutt, mmppuutt, and aappppeenndd transfer files from the
- host on the secondary control connection to the host on the
- primary control connection. Third party file transfers de-
- pend upon support of the FTP protocol PASV command by the
- server on the secondary control connection.
-
- ppuutt _l_o_c_a_l_-_f_i_l_e [_r_e_m_o_t_e_-_f_i_l_e]
- Store a local file on the remote machine. If _r_e_m_o_t_e_-_f_i_l_e is
- left unspecified, the local file name is used after process-
- ing according to any nnttrraannss or nnmmaapp settings in naming the
- remote file. File transfer uses the current settings for
- ttyyppee, ffoorrmmaatt, mmooddee, and ssttrruuccttuurree.
-
- ppwwdd Print the name of the current working directory on the remote
- machine.
-
- qquuiitt A synonym for bbyyee.
-
- qquuoottee _a_r_g_1 _a_r_g_2 _._._.
- The arguments specified are sent, verbatim, to the remote FTP
- server.
-
- rraattee _d_i_r_e_c_t_i_o_n [_m_a_x_i_m_u_m [_i_n_c_r_e_m_e_n_t]]
- Throttle the maximum transfer rate to _m_a_x_i_m_u_m bytes/second.
- If _m_a_x_i_m_u_m is 0, disable the throttle.
-
- _d_i_r_e_c_t_i_o_n may be one of:
- aallll Both directions.
- ggeett Incoming transfers.
- ppuutt Outgoing transfers.
-
- _m_a_x_i_m_u_m can by modified on the fly by _i_n_c_r_e_m_e_n_t bytes (de-
- fault: 1024) each time a given signal is received:
-
- SIGUSR1 Increment _m_a_x_i_m_u_m by _i_n_c_r_e_m_e_n_t bytes.
-
- SIGUSR2 Decrement _m_a_x_i_m_u_m by _i_n_c_r_e_m_e_n_t bytes. The re-
- sult must be a positive number.
-
- If _m_a_x_i_m_u_m is not supplied, the current throttle rates are
- displayed.
-
- Note: rraattee is not yet implemented for ascii mode transfers.
-
- rrccvvbbuuff _s_i_z_e
- Set the size of the socket receive buffer to _s_i_z_e.
-
- rreeccvv _r_e_m_o_t_e_-_f_i_l_e [_l_o_c_a_l_-_f_i_l_e]
- A synonym for ggeett.
-
- rreeggeett _r_e_m_o_t_e_-_f_i_l_e [_l_o_c_a_l_-_f_i_l_e]
- rreeggeett acts like ggeett, except that if _l_o_c_a_l_-_f_i_l_e exists and is
- smaller than _r_e_m_o_t_e_-_f_i_l_e, _l_o_c_a_l_-_f_i_l_e is presumed to be a par-
- tially transferred copy of _r_e_m_o_t_e_-_f_i_l_e and the transfer is
- continued from the apparent point of failure. This command
- is useful when transferring very large files over networks
- that are prone to dropping connections.
-
- rreemmooppttss _c_o_m_m_a_n_d [_c_o_m_m_a_n_d_-_o_p_t_i_o_n_s]
- Set options on the remote FTP server for _c_o_m_m_a_n_d to _c_o_m_m_a_n_d_-
- _o_p_t_i_o_n_s (whose absence is handled on a command-specific ba-
- sis). Remote FTP commands known to support options include:
- `MLST' (used for MLSD and MLST).
-
- rreennaammee [_f_r_o_m [_t_o]]
- Rename the file _f_r_o_m on the remote machine, to the file _t_o.
-
- rreesseett Clear reply queue. This command re-synchronizes command/re-
- ply sequencing with the remote FTP server. Resynchronization
- may be necessary following a violation of the FTP protocol by
- the remote server.
-
- rreessttaarrtt _m_a_r_k_e_r
- Restart the immediately following ggeett or ppuutt at the indicated
- _m_a_r_k_e_r. On UNIX systems, marker is usually a byte offset in-
- to the file.
-
- rrhheellpp [_c_o_m_m_a_n_d_-_n_a_m_e]
- Request help from the remote FTP server. If a _c_o_m_m_a_n_d_-_n_a_m_e
- is specified it is supplied to the server as well.
-
- rrmmddiirr _d_i_r_e_c_t_o_r_y_-_n_a_m_e
- Delete a directory on the remote machine.
-
- rrssttaattuuss [_r_e_m_o_t_e_-_f_i_l_e]
- With no arguments, show status of remote machine. If _r_e_m_o_t_e_-
- _f_i_l_e is specified, show status of _r_e_m_o_t_e_-_f_i_l_e on remote ma-
- chine.
-
- rruunniiqquuee Toggle storing of files on the local system with unique file-
- names. If a file already exists with a name equal to the
- target local filename for a ggeett or mmggeett command, a ".1" is
- appended to the name. If the resulting name matches another
- existing file, a ".2" is appended to the original name. If
- this process continues up to ".99", an error message is
- printed, and the transfer does not take place. The generated
- unique filename will be reported. Note that rruunniiqquuee will not
- affect local files generated from a shell command (see be-
- low). The default value is off.
-
- sseenndd _l_o_c_a_l_-_f_i_l_e [_r_e_m_o_t_e_-_f_i_l_e]
- A synonym for ppuutt.
-
- sseennddppoorrtt Toggle the use of PORT commands. By default, ffttpp will at-
- tempt to use a PORT command when establishing a connection
- for each data transfer. The use of PORT commands can prevent
- delays when performing multiple file transfers. If the PORT
- command fails, ffttpp will use the default data port. When the
- use of PORT commands is disabled, no attempt will be made to
- use PORT commands for each data transfer. This is useful for
- certain FTP implementations which do ignore PORT commands
- but, incorrectly, indicate they've been accepted.
-
- sseett [_o_p_t_i_o_n _v_a_l_u_e]
- Set _o_p_t_i_o_n to _v_a_l_u_e. If _o_p_t_i_o_n and _v_a_l_u_e are not given, dis-
- play all of the options and their values. The currently sup-
- ported options are:
-
- anonpass Defaults to $FTPANONPASS
-
- ftp_proxy Defaults to $ftp_proxy.
-
- http_proxy Defaults to $http_proxy.
-
- no_proxy Defaults to $no_proxy.
-
- pager Defaults to $PAGER.
-
- prompt Defaults to $FTPPROMPT.
-
- rprompt Defaults to $FTPRPROMPT.
-
- ssiittee _a_r_g_1 _a_r_g_2 _._._.
- The arguments specified are sent, verbatim, to the remote FTP
- server as a SITE command.
-
- ssiizzee _r_e_m_o_t_e_-_f_i_l_e
- Return size of _r_e_m_o_t_e_-_f_i_l_e on remote machine.
-
- ssnnddbbuuff _s_i_z_e
- Set the size of the socket send buffer to _s_i_z_e.
-
- ssttaattuuss Show the current status of ffttpp.
-
- ssttrruucctt _s_t_r_u_c_t_-_n_a_m_e
- Set the file transfer _s_t_r_u_c_t_u_r_e to _s_t_r_u_c_t_-_n_a_m_e. The default
- (and only supported) structure is ``file''.
-
- ssuunniiqquuee Toggle storing of files on remote machine under unique file
- names. The remote FTP server must support FTP protocol STOU
- command for successful completion. The remote server will
- report unique name. Default value is off.
-
- ssyysstteemm Show the type of operating system running on the remote ma-
- chine.
-
- tteenneexx Set the file transfer type to that needed to talk to TENEX
- machines.
-
- tthhrroottttllee A synonym for rraattee.
-
- ttrraaccee Toggle packet tracing.
-
- ttyyppee [_t_y_p_e_-_n_a_m_e]
- Set the file transfer ttyyppee to _t_y_p_e_-_n_a_m_e. If no type is spec-
- ified, the current type is printed. The default type is net-
- work ASCII.
-
- uummaasskk [_n_e_w_m_a_s_k]
- Set the default umask on the remote server to _n_e_w_m_a_s_k. If
- _n_e_w_m_a_s_k is omitted, the current umask is printed.
-
- uunnsseett _o_p_t_i_o_n
- Unset _o_p_t_i_o_n. Refer to sseett for more information.
-
- uussaaggee _c_o_m_m_a_n_d
- Print the usage message for _c_o_m_m_a_n_d.
-
- uusseerr _u_s_e_r_-_n_a_m_e [_p_a_s_s_w_o_r_d [_a_c_c_o_u_n_t]]
- Identify yourself to the remote FTP server. If the _p_a_s_s_w_o_r_d
- is not specified and the server requires it, ffttpp will prompt
- the user for it (after disabling local echo). If an _a_c_c_o_u_n_t
- field is not specified, and the FTP server requires it, the
- user will be prompted for it. If an _a_c_c_o_u_n_t field is speci-
- fied, an account command will be relayed to the remote server
- after the login sequence is completed if the remote server
- did not require it for logging in. Unless ffttpp is invoked
- with ``auto-login'' disabled, this process is done automati-
- cally on initial connection to the FTP server.
-
- vveerrbboossee Toggle verbose mode. In verbose mode, all responses from the
- FTP server are displayed to the user. In addition, if ver-
- bose is on, when a file transfer completes, statistics re-
- garding the efficiency of the transfer are reported. By de-
- fault, verbose is on.
-
- xxffeerrbbuuff _s_i_z_e
- Set the size of the socket send and receive buffers to _s_i_z_e.
-
- ?? [_c_o_m_m_a_n_d]
- A synonym for hheellpp.
-
- Command arguments which have embedded spaces may be quoted with quote `"'
- marks.
-
- Commands which toggle settings can take an explicit oonn or ooffff argument to
- force the setting appropriately.
-
- Commands which take a byte count as an argument (e.g., hhaasshh, rraattee, and
- xxffeerrbbuuff) support an optional suffix on the argument which changes the in-
- terpretation of the argument. Supported suffixes are:
- b Causes no modification. (Optional)
- k Kilo; multiply the argument by 1024
- m Mega; multiply the argument by 1048576
- g Giga; multiply the argument by 1073741824
-
- If ffttpp receives a SIGINFO (see the ``status'' argument of stty(1)) or
- SIGQUIT signal whilst a transfer is in progress, the current transfer
- rate statistics will be written to the standard error output, in the same
- format as the standard completion message.
-
-AAUUTTOO--FFEETTCCHHIINNGG FFIILLEESS
- In addition to standard commands, this version of ffttpp supports an auto-
- fetch feature. To enable auto-fetch, simply pass the list of host-
- names/files on the command line.
-
- The following formats are valid syntax for an auto-fetch element:
-
- [user@]host:[path][/]
- ``Classic'' FTP format.
-
- If _p_a_t_h contains a glob character and globbing is enabled, (see
- gglloobb), then the equivalent of `mget path' is performed.
-
- If the directory component of _p_a_t_h contains no globbing characters,
- it is stored locally with the name basename (see basename(1)) of
- ppaatthh, in the current directory. Otherwise, the full remote name is
- used as the local name, relative to the local root directory.
-
- ftp://[user[:password]@]host[:port]/path[/][;type=X]
- An FTP URL, retrieved using the FTP protocol if sseett ffttpp__pprrooxxyy isn't
- defined. Otherwise, transfer the URL using HTTP via the proxy de-
- fined in sseett ffttpp__pprrooxxyy. If sseett ffttpp__pprrooxxyy isn't defined and _u_s_e_r is
- given, login as _u_s_e_r. In this case, use _p_a_s_s_w_o_r_d if supplied, oth-
- erwise prompt the user for one.
-
- In order to be compliant with RRFFCC 11773388, ffttpp strips the leading `/'
- from _p_a_t_h, resulting in a transfer relative from the default login
- directory of the user. If the _/ directory is required, use a lead-
- ing path of ``%2F''. If a user's home directory is required (and
- the remote server supports the syntax), use a leading path of
- ``%7Euser/''. For example, to retrieve _/_e_t_c_/_m_o_t_d from `localhost'
- as the user `myname' with the password `mypass', use
- ``ftp://myname:mypass@localhost/%2fetc/motd''
-
- If a suffix of `;type=A' or `;type=I' is supplied, then the trans-
- fer type will take place as ascii or binary (respectively). The
- default transfer type is binary.
-
- http://[user[:password]@]host[:port]/path
- An HTTP URL, retrieved using the HTTP protocol. If sseett hhttttpp__pprrooxxyy
- is defined, it is used as a URL to an HTTP proxy server. If HTTP
- authorisation is required to retrieve _p_a_t_h, and `user' (and option-
- ally `password') is in the URL, use them for the first attempt to
- authenticate.
-
- file:///path
- A local URL, copied from _/_p_a_t_h.
-
- Unless noted otherwise above, and --oo _o_u_t_p_u_t is not given, the file is
- stored in the current directory as the basename(1) of _p_a_t_h.
-
- If a classic format or an FTP URL format has a trailing `/' or an empty
- _p_a_t_h component, then ffttpp will connect to the site and ccdd to the directory
- given as the path, and leave the user in interactive mode ready for fur-
- ther input. This will not work if sseett ffttpp__pprrooxxyy is being used.
-
- Direct HTTP transfers use HTTP 1.1. Proxied FTP and HTTP transfers use
- HTTP 1.0.
-
- If --RR is given, all auto-fetches that don't go via the FTP or HTTP prox-
- ies will be restarted. For FTP, this is implemented by using rreeggeett in-
- stead of ggeett. For HTTP, this is implemented by using the `Range: bytes='
- HTTP/1.1 directive.
-
- If WWW or proxy WWW authentication is required, you will be prompted to
- enter a username and password to authenticate with.
-
- When specifying IPv6 numeric addresses in a URL, you need to surround the
- address in square brackets. E.g.: ``ftp://[::1]:21/''. This is because
- colons are used in IPv6 numeric address as well as being the separator
- for the port number.
-
-AABBOORRTTIINNGG AA FFIILLEE TTRRAANNSSFFEERR
- To abort a file transfer, use the terminal interrupt key (usually Ctrl-
- C). Sending transfers will be immediately halted. Receiving transfers
- will be halted by sending an FTP protocol ABOR command to the remote
- server, and discarding any further data received. The speed at which
- this is accomplished depends upon the remote server's support for ABOR
- processing. If the remote server does not support the ABOR command, the
- prompt will not appear until the remote server has completed sending the
- requested file.
-
- If the terminal interrupt key sequence is used whilst ffttpp is awaiting a
- reply from the remote server for the ABOR processing, then the connection
- will be closed. This is different from the traditional behaviour (which
- ignores the terminal interrupt during this phase), but is considered more
- useful.
-
-FFIILLEE NNAAMMIINNGG CCOONNVVEENNTTIIOONNSS
- Files specified as arguments to ffttpp commands are processed according to
- the following rules.
-
- 1. If the file name `--' is specified, the _s_t_d_i_n (for reading) or _s_t_d_o_u_t
- (for writing) is used.
-
- 2. If the first character of the file name is `|', the remainder of the
- argument is interpreted as a shell command. ffttpp then forks a shell,
- using popen(3) with the argument supplied, and reads (writes) from
- the stdout (stdin). If the shell command includes spaces, the argu-
- ment must be quoted; e.g. ``"| ls -lt"''. A particularly useful
- example of this mechanism is: ``dir "" |more''.
-
- 3. Failing the above checks, if ``globbing'' is enabled, local file
- names are expanded according to the rules used in the csh(1); c.f.
- the gglloobb command. If the ffttpp command expects a single local file
- (e.g. ppuutt), only the first filename generated by the "globbing" op-
- eration is used.
-
- 4. For mmggeett commands and ggeett commands with unspecified local file
- names, the local filename is the remote filename, which may be al-
- tered by a ccaassee, nnttrraannss, or nnmmaapp setting. The resulting filename
- may then be altered if rruunniiqquuee is on.
-
- 5. For mmppuutt commands and ppuutt commands with unspecified remote file
- names, the remote filename is the local filename, which may be al-
- tered by a nnttrraannss or nnmmaapp setting. The resulting filename may then
- be altered by the remote server if ssuunniiqquuee is on.
-
-FFIILLEE TTRRAANNSSFFEERR PPAARRAAMMEETTEERRSS
- The FTP specification specifies many parameters which may affect a file
- transfer. The ttyyppee may be one of ``ascii'', ``image'' (binary),
- ``ebcdic'', and ``local byte size'' (for PDP-10's and PDP-20's mostly).
- ffttpp supports the ascii and image types of file transfer, plus local byte
- size 8 for tteenneexx mode transfers.
-
- ffttpp supports only the default values for the remaining file transfer pa-
- rameters: mmooddee, ffoorrmm, and ssttrruucctt.
-
-TTHHEE ..nneettrrcc FFIILLEE
- The _._n_e_t_r_c file contains login and initialization information used by the
- auto-login process. It resides in the user's home directory, unless
- overridden with the --NN _n_e_t_r_c option, or specified in the NETRC environ-
- ment variable. The following tokens are recognized; they may be separat-
- ed by spaces, tabs, or new-lines:
-
- mmaacchhiinnee _n_a_m_e
- Identify a remote machine _n_a_m_e. The auto-login process search-
- es the _._n_e_t_r_c file for a mmaacchhiinnee token that matches the remote
- machine specified on the ffttpp command line or as an ooppeenn command
- argument. Once a match is made, the subsequent _._n_e_t_r_c tokens
- are processed, stopping when the end of file is reached or an-
- other mmaacchhiinnee or a ddeeffaauulltt token is encountered.
-
- ddeeffaauulltt This is the same as mmaacchhiinnee _n_a_m_e except that ddeeffaauulltt matches
- any name. There can be only one ddeeffaauulltt token, and it must be
- after all mmaacchhiinnee tokens. This is normally used as:
-
- default login anonymous password user@site
-
- thereby giving the user an automatic anonymous FTP login to ma-
- chines not specified in _._n_e_t_r_c. This can be overridden by us-
- ing the --nn flag to disable auto-login.
-
- llooggiinn _n_a_m_e
- Identify a user on the remote machine. If this token is pre-
- sent, the auto-login process will initiate a login using the
- specified _n_a_m_e.
-
- ppaasssswwoorrdd _s_t_r_i_n_g
- Supply a password. If this token is present, the auto-login
- process will supply the specified string if the remote server
- requires a password as part of the login process. Note that if
- this token is present in the _._n_e_t_r_c file for any user other
- than _a_n_o_n_y_m_o_u_s, ffttpp will abort the auto-login process if the
- _._n_e_t_r_c is readable by anyone besides the user.
-
- aaccccoouunntt _s_t_r_i_n_g
- Supply an additional account password. If this token is pre-
- sent, the auto-login process will supply the specified string
- if the remote server requires an additional account password,
- or the auto-login process will initiate an ACCT command if it
- does not.
-
- mmaaccddeeff _n_a_m_e
- Define a macro. This token functions like the ffttpp mmaaccddeeff com-
- mand functions. A macro is defined with the specified name;
- its contents begin with the next _._n_e_t_r_c line and continue until
- a blank line (consecutive new-line characters) is encountered.
- If a macro named iinniitt is defined, it is automatically executed
- as the last step in the auto-login process.
-
-CCOOMMMMAANNDD LLIINNEE EEDDIITTIINNGG
- ffttpp supports interactive command line editing, via the editline(3) li-
- brary. It is enabled with the eeddiitt command, and is enabled by default if
- input is from a tty. Previous lines can be recalled and edited with the
- arrow keys, and other GNU Emacs-style editing keys may be used as well.
-
- The editline(3) library is configured with a _._e_d_i_t_r_c file - refer to
- editrc(5) for more information.
-
- An extra key binding is available to ffttpp to provide context sensitive
- command and filename completion (including remote file completion). To
- use this, bind a key to the editline(3) command ffttpp--ccoommpplleettee. By de-
- fault, this is bound to the TAB key.
-
-CCOOMMMMAANNDD LLIINNEE PPRROOMMPPTT
- By default, ffttpp displays a command line prompt of ``ftp>'' to the user.
- This can be changed with the sseett pprroommpptt command.
-
- A prompt can be displayed on the right side of the screen (after the com-
- mand input) with the sseett rrpprroommpptt command.
-
- The following formatting sequences are replaced by the given information:
-
- %/ The current remote working directory.
-
- %c[[0]_n], %.[[0]_n]
- The trailing component of the current remote working directo-
- ry, or _n trailing components if a digit _n is given. If _n be-
- gins with `0', the number of skipped components precede the
- trailing component(s) in the format ``/_<_s_k_i_p_p_e_d_>trailing''
- (for `%c') or ``...trailing'' (for `%.').
-
- %M The remote host name.
-
- %m The remote host name, up to the first `.'.
-
- %n The remote user name.
-
- %% A single `%'.
-
-EENNVVIIRROONNMMEENNTT
- ffttpp uses the following environment variables.
-
- FTPANONPASS Password to send in an anonymous FTP transfer. Defaults
- to ```whoami`@''.
-
- FTPMODE Overrides the default operation mode. Support values are:
-
- active active mode FTP only
-
- auto automatic determination of passive or active
- (this is the default)
-
- gate gate-ftp mode
-
- passive passive mode FTP only
-
- FTPPROMPT Command-line prompt to use. Defaults to ``ftp>''. Refer
- to _C_O_M_M_A_N_D _L_I_N_E _P_R_O_M_P_T for more information.
-
- FTPRPROMPT Command-line right side prompt to use. Defaults to ``''.
- Refer to _C_O_M_M_A_N_D _L_I_N_E _P_R_O_M_P_T for more information.
-
- FTPSERVER Host to use as gate-ftp server when ggaattee is enabled.
-
- FTPSERVERPORT Port to use when connecting to gate-ftp server when ggaattee
- is enabled. Default is port returned by a ggeettsseerrvvbbyynnaammee()
- lookup of ``ftpgate/tcp''.
-
- HOME For default location of a _._n_e_t_r_c file, if one exists.
-
- NETRC An alternate location of the _._n_e_t_r_c file.
-
- PAGER Used by various commands to display files. Defaults to
- more(1) if empty or not set.
-
- SHELL For default shell.
-
- ftp_proxy URL of FTP proxy to use when making FTP URL requests (if
- not defined, use the standard FTP protocol).
-
- _N_O_T_E: this is not used for interactive sessions, only for
- command-line fetches.
-
- http_proxy URL of HTTP proxy to use when making HTTP URL requests.
- If proxy authentication is required and there is a user-
- name and password in this URL, they will automatically be
- used in the first attempt to authenticate to the proxy.
-
- Note that the use of a username and password in ftp_proxy
- and http_proxy may be incompatible with other programs
- that use it (such as lynx(1)).
-
- _N_O_T_E: this is not used for interactive sessions, only for
- command-line fetches.
-
- no_proxy A space or comma separated list of hosts (or domains) for
- which proxying is not to be used. Each entry may have an
- optional trailing ":port", which restricts the matching to
- connections to that port.
-
-SSEEEE AALLSSOO
- getservbyname(3), editrc(5), services(5), ftpd(8)
-
-SSTTAANNDDAARRDDSS
- ffttpp attempts to be compliant with RRFFCC 995599, RRFFCC 11112233, RRFFCC 11773388, RRFFCC 22006688,
- RRFFCC 22338899, RRFFCC 22442288, RRFFCC 22773322, and ddrraafftt--iieettff--ffttppeexxtt--mmllsstt--1111.
-
-HHIISSTTOORRYY
- The ffttpp command appeared in 4.2BSD.
-
- Various features such as command line editing, context sensitive command
- and file completion, dynamic progress bar, automatic fetching of files
- and URLs, modification time preservation, transfer rate throttling, con-
- figurable command line prompt, and other enhancements over the standard
- BSD ffttpp were implemented in NetBSD 1.3 and later releases by Luke Mewburn
- <lukem@netbsd.org>.
-
- IPv6 support was added by the WIDE/KAME project (but may not be present
- in all non-NetBSD versions of this program, depending if the operating
- system supports IPv6 in a similar manner to KAME).
-
-BBUUGGSS
- Correct execution of many commands depends upon proper behavior by the
- remote server.
-
- An error in the treatment of carriage returns in the 4.2BSD ascii-mode
- transfer code has been corrected. This correction may result in incor-
- rect transfers of binary files to and from 4.2BSD servers using the ascii
- type. Avoid this problem by using the binary image type.
-
- ffttpp assumes that all IPv4 mapped addresses (IPv6 addresses with a form
- like ::ffff:10.1.1.1) indicate IPv4 destinations which can be handled by
- AF_INET sockets. However, in certain IPv6 network configurations, this
- assumption is not true. In such an environment, IPv4 mapped addresses
- must be passed to AF_INET6 sockets directly. For example, if your site
- uses a SIIT translator for IPv6-to-IPv4 translation, ffttpp is unable to
- support your configuration.
-
-NetBSD 1.6_BETA1 May 18, 2002 16
diff --git a/src/ftp_var.h b/src/ftp_var.h
index 25f13d48f3244..cd6dcbf2b5cf9 100644
--- a/src/ftp_var.h
+++ b/src/ftp_var.h
@@ -1,7 +1,8 @@
-/* $NetBSD: ftp_var.h,v 1.71 2005/04/11 01:49:31 lukem Exp $ */
+/* $NetBSD: ftp_var.h,v 1.10 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: ftp_var.h,v 1.81 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1996-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -107,6 +101,8 @@
#define NO_PROGRESS
#endif
+#if 0 /* tnftp */
+
#include <sys/param.h>
#include <netinet/in.h>
@@ -117,6 +113,8 @@
#include <setjmp.h>
#include <stringlist.h>
+#endif /* tnftp */
+
#ifndef NO_EDITCOMPLETE
#include <histedit.h>
#endif /* !NO_EDITCOMPLETE */
@@ -128,7 +126,7 @@
* Format of command table.
*/
struct cmd {
- char *c_name; /* name of command */
+ const char *c_name; /* name of command */
const char *c_help; /* help string */
char c_bell; /* give bell when command completes */
char c_conn; /* must be connected to use command */
@@ -139,6 +137,8 @@ struct cmd {
void (*c_handler)(int, char **); /* function to call */
};
+#define MAX_C_NAME 12 /* maximum length of cmd.c_name */
+
/*
* Format of macro table
*/
@@ -152,8 +152,8 @@ struct macel {
* Format of option table
*/
struct option {
- char *name;
- char *value;
+ const char *name;
+ char *value;
};
/*
@@ -210,14 +210,14 @@ GLOBAL int sendport; /* use PORT/LPRT cmd for each data connection */
GLOBAL int connected; /* 1 = connected to server, -1 = logged in */
GLOBAL int interactive; /* interactively prompt on m* cmds */
GLOBAL int confirmrest; /* confirm rest of current m* cmd */
-GLOBAL int debug; /* debugging level */
+GLOBAL int ftp_debug; /* debugging level */
GLOBAL int bell; /* ring bell on cmd completion */
GLOBAL int doglob; /* glob local file names */
GLOBAL int autologin; /* establish user account on connection */
GLOBAL int proxy; /* proxy server connection active */
GLOBAL int proxflag; /* proxy connection exists */
GLOBAL int gatemode; /* use gate-ftp */
-GLOBAL char *gateserver; /* server to use for gate-ftp */
+GLOBAL const char *gateserver; /* server to use for gate-ftp */
GLOBAL int sunique; /* store files on server with unique name */
GLOBAL int runique; /* store local files with unique name */
GLOBAL int mcase; /* map upper to lower case for mget names */
@@ -252,9 +252,11 @@ GLOBAL int rate_get_incr; /* increment for get xfer rate */
GLOBAL int rate_put; /* maximum put xfer rate */
GLOBAL int rate_put_incr; /* increment for put xfer rate */
GLOBAL int retry_connect; /* seconds between retrying connection */
-GLOBAL char *tmpdir; /* temporary directory */
+GLOBAL const char *tmpdir; /* temporary directory */
GLOBAL int epsv4; /* use EPSV/EPRT on IPv4 connections */
GLOBAL int epsv4bad; /* EPSV doesn't work on the current server */
+GLOBAL int epsv6; /* use EPSV/EPRT on IPv6 connections */
+GLOBAL int epsv6bad; /* EPSV doesn't work on the current server */
GLOBAL int editing; /* command line editing enabled */
GLOBAL int features[FEAT_max]; /* remote FEATures supported */
@@ -266,8 +268,6 @@ GLOBAL size_t cursor_argc; /* location of cursor in margv */
GLOBAL size_t cursor_argo; /* offset of cursor in margv[cursor_argc] */
#endif /* !NO_EDITCOMPLETE */
-GLOBAL char *direction; /* direction transfer is occurring */
-
GLOBAL char *hostname; /* name of host connected to */
GLOBAL int unix_server; /* server is unix, can use binary for ascii */
GLOBAL int unix_proxy; /* proxy is unix, can use binary for ascii */
@@ -276,9 +276,10 @@ GLOBAL char remotecwd[MAXPATHLEN]; /* remote dir */
GLOBAL char *username; /* name of user logged in as. (dynamic) */
GLOBAL sa_family_t family; /* address family to use for connections */
-GLOBAL char *ftpport; /* port number to use for FTP connections */
-GLOBAL char *httpport; /* port number to use for HTTP connections */
-GLOBAL char *gateport; /* port number to use for gateftp connections */
+GLOBAL const char *ftpport; /* port number to use for FTP connections */
+GLOBAL const char *httpport; /* port number to use for HTTP connections */
+GLOBAL const char *gateport; /* port number to use for gateftp connections */
+GLOBAL struct addrinfo *bindai; /* local address to bind as */
GLOBAL char *outfile; /* filename to output URLs to */
GLOBAL int restartautofetch; /* restart auto-fetch */
@@ -327,7 +328,7 @@ extern struct option optiontab[];
#define FREEPTR(x) if ((x) != NULL) { free(x); (x) = NULL; }
#ifdef BSD4_4
-# define HAVE_SOCKADDR_SA_LEN 1
+# define HAVE_STRUCT_SOCKADDR_IN_SIN_LEN 1
#endif
#ifdef NO_LONG_LONG
@@ -335,3 +336,20 @@ extern struct option optiontab[];
#else
# define STRTOLL(x,y,z) strtoll(x,y,z)
#endif
+
+#ifdef NO_DEBUG
+#define DPRINTF(...)
+#define DWARN(...)
+#else
+#define DPRINTF(...) if (ftp_debug) (void)fprintf(ttyout, __VA_ARGS__)
+#define DWARN(...) if (ftp_debug) warn(__VA_ARGS__)
+#endif
+
+#define STRorNULL(s) ((s) ? (s) : "<null>")
+
+#ifdef NO_USAGE
+void xusage(void);
+#define UPRINTF(...) xusage()
+#else
+#define UPRINTF(...) (void)fprintf(ttyout, __VA_ARGS__)
+#endif
diff --git a/src/main.c b/src/main.c
index 5d60cdbcd7706..c2d922b93dbec 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,8 @@
-/* $NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $ */
+/* $NetBSD: main.c,v 1.17 2009/11/15 10:12:37 lukem Exp $ */
+/* from NetBSD: main.c,v 1.117 2009/07/13 19:05:41 roy Exp */
/*-
- * Copyright (c) 1996-2004 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -94,17 +88,22 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\
+ The Regents of the University of California. All rights reserved.\
+ Copyright 1996-2008 The NetBSD Foundation, Inc. All rights reserved");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
#else
-__RCSID("$NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $");
+__RCSID(" NetBSD: main.c,v 1.117 2009/07/13 19:05:41 roy Exp ");
#endif
#endif /* not lint */
@@ -123,9 +122,12 @@ __RCSID("$NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <locale.h>
+#endif /* tnftp */
+
#define GLOBAL /* force GLOBAL decls in ftp_var.h to be declared */
#include "ftp_var.h"
@@ -134,19 +136,24 @@ __RCSID("$NetBSD: main.c,v 1.94 2005/05/13 05:03:49 lukem Exp $");
#define NO_PROXY "no_proxy" /* env var with list of non-proxied
* hosts, comma or space separated */
-static void setupoption(char *, char *, char *);
+static void setupoption(const char *, const char *, const char *);
int main(int, char *[]);
int
-main(int argc, char *argv[])
+main(int volatile argc, char **volatile argv)
{
int ch, rval;
struct passwd *pw;
- char *cp, *ep, *anonuser, *anonpass, *upload_path;
- int dumbterm, s, len, isupload;
+ char *cp, *ep, *anonpass, *upload_path, *src_addr;
+ const char *anonuser;
+ int dumbterm, s, isupload;
+ size_t len;
socklen_t slen;
+ tzset();
+#if 0 /* tnftp */ /* XXX */
setlocale(LC_ALL, "");
+#endif /* tnftp */
setprogname(argv[0]);
sigint_raised = 0;
@@ -184,14 +191,22 @@ main(int argc, char *argv[])
rate_put_incr = DEFAULTINCR;
#ifdef INET6
epsv4 = 1;
+ epsv6 = 1;
#else
epsv4 = 0;
+ epsv6 = 0;
#endif
epsv4bad = 0;
+ epsv6bad = 0;
+ src_addr = NULL;
upload_path = NULL;
isupload = 0;
reply_callback = NULL;
+#ifdef INET6
family = AF_UNSPEC;
+#else
+ family = AF_INET; /* force AF_INET if no INET6 support */
+#endif
netrc[0] = '\0';
cp = getenv("NETRC");
@@ -206,15 +221,15 @@ main(int argc, char *argv[])
*/
s = socket(AF_INET, SOCK_STREAM, 0);
if (s == -1)
- err(1, "can't create socket");
+ err(1, "Can't create socket to determine default socket sizes");
slen = sizeof(rcvbuf_size);
if (getsockopt(s, SOL_SOCKET, SO_RCVBUF,
(void *)&rcvbuf_size, &slen) == -1)
- err(1, "unable to get default rcvbuf size");
+ err(1, "Unable to get default rcvbuf size");
slen = sizeof(sndbuf_size);
if (getsockopt(s, SOL_SOCKET, SO_SNDBUF,
(void *)&sndbuf_size, &slen) == -1)
- err(1, "unable to get default sndbuf size");
+ err(1, "Unable to get default sndbuf size");
(void)close(s);
/* sanity check returned buffer sizes */
if (rcvbuf_size <= 0)
@@ -227,7 +242,7 @@ main(int argc, char *argv[])
if (rcvbuf_size > 8 * 1024 * 1024)
rcvbuf_size = 8 * 1024 * 1024;
- marg_sl = xsl_init();
+ marg_sl = ftp_sl_init();
if ((tmpdir = getenv("TMPDIR")) == NULL)
tmpdir = _PATH_TMP;
@@ -245,7 +260,7 @@ main(int argc, char *argv[])
passivemode = 1;
activefallback = 1;
} else
- warnx("unknown $FTPMODE '%s'; using defaults", cp);
+ warnx("Unknown $FTPMODE `%s'; using defaults", cp);
}
if (strcmp(getprogname(), "pftp") == 0) {
@@ -286,7 +301,7 @@ main(int argc, char *argv[])
}
}
- while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:RtT:u:vV")) != -1) {
+ while ((ch = getopt(argc, argv, "46AadefginN:o:pP:q:r:Rs:tT:u:vV")) != -1) {
switch (ch) {
case '4':
family = AF_INET;
@@ -311,7 +326,7 @@ main(int argc, char *argv[])
case 'd':
options |= SO_DEBUG;
- debug++;
+ ftp_debug++;
break;
case 'e':
@@ -361,19 +376,23 @@ main(int argc, char *argv[])
case 'q':
quit_time = strtol(optarg, &ep, 10);
if (quit_time < 1 || *ep != '\0')
- errx(1, "bad quit value: %s", optarg);
+ errx(1, "Bad quit value: %s", optarg);
break;
case 'r':
retry_connect = strtol(optarg, &ep, 10);
if (retry_connect < 1 || *ep != '\0')
- errx(1, "bad retry value: %s", optarg);
+ errx(1, "Bad retry value: %s", optarg);
break;
case 'R':
restartautofetch = 1;
break;
+ case 's':
+ src_addr = optarg;
+ break;
+
case 't':
trace = 1;
break;
@@ -382,15 +401,18 @@ main(int argc, char *argv[])
{
int targc;
char *targv[6], *oac;
+ char cmdbuf[MAX_C_NAME];
/* look for `dir,max[,incr]' */
targc = 0;
- targv[targc++] = "-T";
- oac = xstrdup(optarg);
+ (void)strlcpy(cmdbuf, "-T", sizeof(cmdbuf));
+ targv[targc++] = cmdbuf;
+ oac = ftp_strdup(optarg);
while ((cp = strsep(&oac, ",")) != NULL) {
if (*cp == '\0') {
- warnx("bad throttle value: %s", optarg);
+ warnx("Bad throttle value `%s'",
+ optarg);
usage();
/* NOTREACHED */
}
@@ -408,7 +430,7 @@ main(int argc, char *argv[])
{
isupload = 1;
interactive = 0;
- upload_path = xstrdup(optarg);
+ upload_path = ftp_strdup(optarg);
break;
}
@@ -435,6 +457,22 @@ main(int argc, char *argv[])
crflag = 1; /* strip c.r. on ascii gets */
sendport = -1; /* not using ports */
+ if (src_addr != NULL) {
+ struct addrinfo hints;
+ int error;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = family;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_PASSIVE;
+ error = getaddrinfo(src_addr, NULL, &hints, &bindai);
+ if (error) {
+ errx(1, "Can't lookup `%s': %s", src_addr,
+ (error == EAI_SYSTEM) ? strerror(errno)
+ : gai_strerror(error));
+ }
+ }
+
/*
* Cache the user name and home directory.
*/
@@ -443,7 +481,7 @@ main(int argc, char *argv[])
anonuser = "anonymous";
cp = getenv("HOME");
if (! EMPTYSTRING(cp))
- localhome = xstrdup(cp);
+ localhome = ftp_strdup(cp);
pw = NULL;
cp = getlogin();
if (cp != NULL)
@@ -452,8 +490,8 @@ main(int argc, char *argv[])
pw = getpwuid(getuid());
if (pw != NULL) {
if (localhome == NULL && !EMPTYSTRING(pw->pw_dir))
- localhome = xstrdup(pw->pw_dir);
- localname = xstrdup(pw->pw_name);
+ localhome = ftp_strdup(pw->pw_dir);
+ localname = ftp_strdup(pw->pw_name);
anonuser = localname;
}
if (netrc[0] == '\0' && localhome != NULL) {
@@ -465,7 +503,7 @@ main(int argc, char *argv[])
}
}
if (localhome == NULL)
- localhome = xstrdup("/");
+ localhome = ftp_strdup("/");
/*
* Every anonymous FTP server I've encountered will accept the
@@ -475,7 +513,7 @@ main(int argc, char *argv[])
* - thorpej@NetBSD.org
*/
len = strlen(anonuser) + 2;
- anonpass = xmalloc(len);
+ anonpass = ftp_malloc(len);
(void)strlcpy(anonpass, anonuser, len);
(void)strlcat(anonpass, "@", len);
@@ -502,11 +540,6 @@ main(int argc, char *argv[])
(void)xsignal(SIGUSR2, crankrate);
(void)xsignal(SIGWINCH, setttywidth);
-#ifdef __GNUC__ /* to shut up gcc warnings */
- (void)&argc;
- (void)&argv;
-#endif
-
if (argc > 0) {
if (isupload) {
rval = auto_put(argc, argv, upload_path);
@@ -522,22 +555,23 @@ main(int argc, char *argv[])
if (rval >= 0) /* -1 == connected and cd-ed */
goto sigint_or_rval_exit;
} else {
- char *xargv[4], *user, *host;
+ char *xargv[4], *uuser, *host;
+ char cmdbuf[MAXPATHLEN];
if ((rval = sigsetjmp(toplevel, 1)))
goto sigint_or_rval_exit;
(void)xsignal(SIGINT, intr);
(void)xsignal(SIGPIPE, lostpeer);
- user = NULL;
+ uuser = NULL;
host = argv[0];
cp = strchr(host, '@');
if (cp) {
*cp = '\0';
- user = host;
+ uuser = host;
host = cp + 1;
}
- /* XXX discards const */
- xargv[0] = (char *)getprogname();
+ (void)strlcpy(cmdbuf, getprogname(), sizeof(cmdbuf));
+ xargv[0] = cmdbuf;
xargv[1] = host;
xargv[2] = argv[1];
xargv[3] = NULL;
@@ -545,14 +579,14 @@ main(int argc, char *argv[])
int oautologin;
oautologin = autologin;
- if (user != NULL) {
+ if (uuser != NULL) {
anonftp = 0;
autologin = 0;
}
setpeer(argc+1, xargv);
autologin = oautologin;
- if (connected == 1 && user != NULL)
- (void)ftp_login(host, user, NULL);
+ if (connected == 1 && uuser != NULL)
+ (void)ftp_login(host, uuser, NULL);
if (!retry_connect)
break;
if (!connected) {
@@ -586,18 +620,18 @@ main(int argc, char *argv[])
char *
prompt(void)
{
- static char **prompt;
+ static char **promptopt;
static char buf[MAXPATHLEN];
- if (prompt == NULL) {
+ if (promptopt == NULL) {
struct option *o;
o = getoption("prompt");
if (o == NULL)
- errx(1, "no such option `prompt'");
- prompt = &(o->value);
+ errx(1, "prompt: no such option `prompt'");
+ promptopt = &(o->value);
}
- formatbuf(buf, sizeof(buf), *prompt ? *prompt : DEFAULTPROMPT);
+ formatbuf(buf, sizeof(buf), *promptopt ? *promptopt : DEFAULTPROMPT);
return (buf);
}
@@ -607,18 +641,18 @@ prompt(void)
char *
rprompt(void)
{
- static char **rprompt;
+ static char **rpromptopt;
static char buf[MAXPATHLEN];
- if (rprompt == NULL) {
+ if (rpromptopt == NULL) {
struct option *o;
o = getoption("rprompt");
if (o == NULL)
- errx(1, "no such option `rprompt'");
- rprompt = &(o->value);
+ errx(1, "rprompt: no such option `rprompt'");
+ rpromptopt = &(o->value);
}
- formatbuf(buf, sizeof(buf), *rprompt ? *rprompt : DEFAULTRPROMPT);
+ formatbuf(buf, sizeof(buf), *rpromptopt ? *rpromptopt : DEFAULTRPROMPT);
return (buf);
}
@@ -630,7 +664,12 @@ cmdscanner(void)
{
struct cmd *c;
char *p;
- int num;
+#ifndef NO_EDITCOMPLETE
+ int ch;
+ size_t num;
+#endif
+ int len;
+ char cmdbuf[MAX_C_NAME];
for (;;) {
#ifndef NO_EDITCOMPLETE
@@ -641,34 +680,33 @@ cmdscanner(void)
p = rprompt();
if (*p)
fprintf(ttyout, "%s ", p);
- (void)fflush(ttyout);
}
- if (fgets(line, sizeof(line), stdin) == NULL) {
+ (void)fflush(ttyout);
+ len = get_line(stdin, line, sizeof(line), NULL);
+ switch (len) {
+ case -1: /* EOF */
+ case -2: /* error */
if (fromatty)
putc('\n', ttyout);
quit(0, NULL);
- }
- num = strlen(line);
- if (num == 0)
- break;
- if (line[--num] == '\n') {
- if (num == 0)
- break;
- line[num] = '\0';
- } else if (num == sizeof(line) - 2) {
+ /* NOTREACHED */
+ case -3: /* too long; try again */
fputs("Sorry, input line is too long.\n",
ttyout);
- while ((num = getchar()) != '\n' && num != EOF)
- /* void */;
+ continue;
+ case 0: /* empty; try again */
+ continue;
+ default: /* all ok */
break;
- } /* else it was a line without a newline */
+ }
#ifndef NO_EDITCOMPLETE
} else {
const char *buf;
HistEvent ev;
cursor_pos = NULL;
- buf = el_gets(el, &num);
+ buf = el_gets(el, &ch);
+ num = ch;
if (buf == NULL || num == 0) {
if (fromatty)
putc('\n', ttyout);
@@ -707,6 +745,7 @@ cmdscanner(void)
* such commands as invalid.
*/
if (strchr(margv[0], ':') != NULL ||
+ !editing ||
el_parse(el, margc, (const char **)margv) != 0)
#endif /* !NO_EDITCOMPLETE */
fputs("?Invalid command.\n", ttyout);
@@ -717,7 +756,8 @@ cmdscanner(void)
continue;
}
confirmrest = 0;
- margv[0] = c->c_name;
+ (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
+ margv[0] = cmdbuf;
(*c->c_handler)(margc, margv);
if (bell && c->c_bell)
(void)putc('\007', ttyout);
@@ -776,7 +816,7 @@ makeargv(void)
marg_sl->sl_cur = 0; /* reset to start of marg_sl */
for (margc = 0; ; margc++) {
argp = slurpstring();
- xsl_add(marg_sl, argp);
+ ftp_sl_add(marg_sl, argp);
if (argp == NULL)
break;
}
@@ -811,6 +851,8 @@ makeargv(void)
char *
slurpstring(void)
{
+ static char bangstr[2] = { '!', '\0' };
+ static char dollarstr[2] = { '$', '\0' };
int got_one = 0;
char *sb = stringbase;
char *ap = argbase;
@@ -821,7 +863,7 @@ slurpstring(void)
case 0:
slrflag++;
INC_CHKCURSOR(stringbase);
- return ((*sb == '!') ? "!" : "$");
+ return ((*sb == '!') ? bangstr : dollarstr);
/* NOTREACHED */
case 1:
slrflag++;
@@ -944,27 +986,28 @@ void
help(int argc, char *argv[])
{
struct cmd *c;
- char *nargv[1], *p, *cmd;
+ char *nargv[1], *cmd;
+ const char *p;
int isusage;
cmd = argv[0];
isusage = (strcmp(cmd, "usage") == 0);
if (argc == 0 || (isusage && argc == 1)) {
- fprintf(ttyout, "usage: %s [command [...]]\n", cmd);
+ UPRINTF("usage: %s [command [...]]\n", cmd);
return;
}
if (argc == 1) {
StringList *buf;
- buf = xsl_init();
+ buf = ftp_sl_init();
fprintf(ttyout,
"%sommands may be abbreviated. Commands are:\n\n",
proxy ? "Proxy c" : "C");
for (c = cmdtab; (p = c->c_name) != NULL; c++)
if (!proxy || c->c_proxy)
- xsl_add(buf, p);
+ ftp_sl_add(buf, ftp_strdup(p));
list_vertical(buf);
- sl_free(buf, 0);
+ sl_free(buf, 1);
return;
}
@@ -972,6 +1015,7 @@ help(int argc, char *argv[])
while (--argc > 0) {
char *arg;
+ char cmdbuf[MAX_C_NAME];
arg = *++argv;
c = getcmd(arg);
@@ -983,7 +1027,8 @@ help(int argc, char *argv[])
cmd, arg);
else {
if (isusage) {
- nargv[0] = c->c_name;
+ (void)strlcpy(cmdbuf, c->c_name, sizeof(cmdbuf));
+ nargv[0] = cmdbuf;
(*c->c_handler)(0, nargv);
} else
fprintf(ttyout, "%-*s\t%s\n", HELPINDENT,
@@ -1013,27 +1058,18 @@ getoptionvalue(const char *name)
struct option *c;
if (name == NULL)
- errx(1, "getoptionvalue() invoked with NULL name");
+ errx(1, "getoptionvalue: invoked with NULL name");
c = getoption(name);
if (c != NULL)
return (c->value);
- errx(1, "getoptionvalue() invoked with unknown option `%s'", name);
+ errx(1, "getoptionvalue: invoked with unknown option `%s'", name);
/* NOTREACHED */
}
static void
-setupoption(char *name, char *value, char *defaultvalue)
+setupoption(const char *name, const char *value, const char *defaultvalue)
{
- char *nargv[3];
- int overbose;
-
- nargv[0] = "setupoption()";
- nargv[1] = name;
- nargv[2] = (value ? value : defaultvalue);
- overbose = verbose;
- verbose = 0;
- setoption(3, nargv);
- verbose = overbose;
+ set_option(name, value ? value : defaultvalue, 0);
}
void
@@ -1042,9 +1078,10 @@ usage(void)
const char *progname = getprogname();
(void)fprintf(stderr,
-"usage: %s [-46AadefginpRtvV] [-N netrc] [-o outfile] [-P port] [-q quittime]\n"
-" [-r retry] [-T dir,max[,inc][[user@]host [port]]] [host:path[/]]\n"
-" [file:///file] [ftp://[user[:pass]@]host[:port]/path[/]]\n"
+"usage: %s [-46AadefginpRtVv] [-N netrc] [-o outfile] [-P port] [-q quittime]\n"
+" [-r retry] [-s srcaddr] [-T dir,max[,inc]]\n"
+" [[user@]host [port]] [host:path[/]] [file:///file]\n"
+" [ftp://[user[:pass]@]host[:port]/path[/]]\n"
" [http://[user[:pass]@]host[:port]/path] [...]\n"
" %s -u URL file [...]\n", progname, progname);
exit(1);
diff --git a/src/progressbar.c b/src/progressbar.c
index d0bd35fd027b3..bd4d76d46f15d 100644
--- a/src/progressbar.c
+++ b/src/progressbar.c
@@ -1,7 +1,8 @@
-/* $NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $ */
+/* $NetBSD: progressbar.c,v 1.14 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -36,9 +30,13 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $");
+__RCSID(" NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp ");
#endif /* not lint */
/*
@@ -46,7 +44,6 @@ __RCSID("$NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $");
*/
#include <sys/types.h>
#include <sys/param.h>
-#include <sys/time.h>
#include <err.h>
#include <errno.h>
@@ -55,12 +52,12 @@ __RCSID("$NetBSD: progressbar.c,v 1.7 2005/04/11 01:49:31 lukem Exp $");
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <tzfile.h>
#include <unistd.h>
-#include "progressbar.h"
+#endif /* tnftp */
-#define SECSPERHOUR (60 * 60)
-#define SECSPERDAY ((long)60 * 60 * 24)
+#include "progressbar.h"
#if !defined(NO_PROGRESS)
/*
@@ -72,7 +69,11 @@ foregroundproc(void)
static pid_t pgrp = -1;
if (pgrp == -1)
+#if GETPGRP_VOID
pgrp = getpgrp();
+#else /* ! GETPGRP_VOID */
+ pgrp = getpgrp(0);
+#endif /* ! GETPGRP_VOID */
return (tcgetpgrp(fileno(ttyout)) == pgrp);
}
@@ -94,10 +95,23 @@ updateprogressmeter(int dummy)
}
/*
- * List of order of magnitude prefixes.
- * The last is `P', as 2^64 = 16384 Petabytes
+ * List of order of magnitude suffixes, per IEC 60027-2.
*/
-static const char prefixes[] = " KMGTP";
+static const char * const suffixes[] = {
+ "", /* 2^0 (byte) */
+ "KiB", /* 2^10 Kibibyte */
+ "MiB", /* 2^20 Mebibyte */
+ "GiB", /* 2^30 Gibibyte */
+ "TiB", /* 2^40 Tebibyte */
+ "PiB", /* 2^50 Pebibyte */
+ "EiB", /* 2^60 Exbibyte */
+#if 0
+ /* The following are not necessary for signed 64-bit off_t */
+ "ZiB", /* 2^70 Zebibyte */
+ "YiB", /* 2^80 Yobibyte */
+#endif
+};
+#define NSUFFIXES (int)(sizeof(suffixes) / sizeof(suffixes[0]))
/*
* Display a transfer progress bar if progress is non-zero.
@@ -124,7 +138,7 @@ progressmeter(int flag)
struct timeval td;
off_t abbrevsize, bytespersec;
double elapsed;
- int ratio, barlength, i, remaining;
+ int ratio, i, remaining, barlength;
/*
* Work variables for progress bar.
@@ -135,10 +149,10 @@ progressmeter(int flag)
* these appropriately.
*/
#endif
- int len;
+ size_t len;
char buf[256]; /* workspace for progress bar */
#ifndef NO_PROGRESS
-#define BAROVERHEAD 43 /* non `*' portion of progress bar */
+#define BAROVERHEAD 45 /* non `*' portion of progress bar */
/*
* stars should contain at least
* sizeof(buf) - BAROVERHEAD entries
@@ -170,8 +184,8 @@ progressmeter(int flag)
"transfer aborted because stalled for %lu sec.\r\n",
getprogname(), (unsigned long)wait.tv_sec);
(void)write(fileno(ttyout), buf, len);
- (void)xsignal(SIGALRM, SIG_DFL);
alarmtimer(0);
+ (void)xsignal(SIGALRM, SIG_DFL);
siglongjmp(toplevel, 1);
}
#endif /* !STANDALONE_PROGRESS */
@@ -188,8 +202,8 @@ progressmeter(int flag)
(void)xsignal_restart(SIGALRM, updateprogressmeter, 1);
alarmtimer(1); /* set alarm timer for 1 Hz */
} else if (flag == 1) {
- (void)xsignal(SIGALRM, SIG_DFL);
alarmtimer(0);
+ (void)xsignal(SIGALRM, SIG_DFL);
}
}
#ifndef NO_PROGRESS
@@ -216,23 +230,24 @@ progressmeter(int flag)
* calculate the length of the `*' bar, ensuring that
* the number of stars won't exceed the buffer size
*/
- barlength = MIN(sizeof(buf) - 1, ttywidth) - BAROVERHEAD;
+ barlength = MIN((int)(sizeof(buf) - 1), ttywidth) - BAROVERHEAD;
if (prefix)
- barlength -= strlen(prefix);
+ barlength -= (int)strlen(prefix);
if (barlength > 0) {
i = barlength * ratio / 100;
len += snprintf(buf + len, BUFLEFT,
- "|%.*s%*s|", i, stars, barlength - i, "");
+ "|%.*s%*s|", i, stars, (int)(barlength - i), "");
}
}
abbrevsize = cursize;
- for (i = 0; abbrevsize >= 100000 && i < sizeof(prefixes); i++)
+ for (i = 0; abbrevsize >= 100000 && i < NSUFFIXES; i++)
abbrevsize >>= 10;
- len += snprintf(buf + len, BUFLEFT, " " LLFP("5") " %c%c ",
+ if (i == NSUFFIXES)
+ i--;
+ len += snprintf(buf + len, BUFLEFT, " " LLFP("5") " %-3s ",
(LLT)abbrevsize,
- prefixes[i],
- i == 0 ? ' ' : 'B');
+ suffixes[i]);
timersub(&now, &start, &td);
elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
@@ -243,13 +258,13 @@ progressmeter(int flag)
if (elapsed > 0.0)
bytespersec /= elapsed;
}
- for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++)
+ for (i = 1; bytespersec >= 1024000 && i < NSUFFIXES; i++)
bytespersec >>= 10;
len += snprintf(buf + len, BUFLEFT,
- " " LLFP("3") ".%02d %cB/s ",
+ " " LLFP("3") ".%02d %.2sB/s ",
(LLT)(bytespersec / 1024),
(int)((bytespersec % 1024) * 100 / 1024),
- prefixes[i]);
+ suffixes[i]);
if (filesize > 0) {
if (bytes <= 0 || elapsed <= 0.0 || cursize > filesize) {
@@ -299,7 +314,8 @@ ptransfer(int siginfo)
struct timeval now, td, wait;
double elapsed;
off_t bytespersec;
- int remaining, hh, i, len;
+ int remaining, hh, i;
+ size_t len;
char buf[256]; /* Work variable for transfer status. */
@@ -334,12 +350,14 @@ ptransfer(int siginfo)
len += snprintf(buf + len, BUFLEFT,
"%02d:%02d ", remaining / 60, remaining % 60);
- for (i = 1; bytespersec >= 1024000 && i < sizeof(prefixes); i++)
+ for (i = 1; bytespersec >= 1024000 && i < NSUFFIXES; i++)
bytespersec >>= 10;
- len += snprintf(buf + len, BUFLEFT, "(" LLF ".%02d %cB/s)",
+ if (i == NSUFFIXES)
+ i--;
+ len += snprintf(buf + len, BUFLEFT, "(" LLF ".%02d %.2sB/s)",
(LLT)(bytespersec / 1024),
(int)((bytespersec % 1024) * 100 / 1024),
- prefixes[i]);
+ suffixes[i]);
if (siginfo && bytes > 0 && elapsed > 0.0 && filesize >= 0
&& bytes + restart_point <= filesize) {
@@ -400,6 +418,16 @@ alarmtimer(int wait)
sigfunc
xsignal_restart(int sig, sigfunc func, int restartable)
{
+#ifdef ultrix /* XXX: this is lame - how do we test sigvec vs. sigaction? */
+ struct sigvec vec, ovec;
+
+ vec.sv_handler = func;
+ sigemptyset(&vec.sv_mask);
+ vec.sv_flags = 0;
+ if (sigvec(sig, &vec, &ovec) < 0)
+ return (SIG_ERR);
+ return (ovec.sv_handler);
+#else /* ! ultrix */
struct sigaction act, oact;
act.sa_handler = func;
@@ -414,6 +442,7 @@ xsignal_restart(int sig, sigfunc func, int restartable)
if (sigaction(sig, &act, &oact) < 0)
return (SIG_ERR);
return (oact.sa_handler);
+#endif /* ! ultrix */
}
/*
@@ -457,7 +486,7 @@ xsignal(int sig, sigfunc func)
* This is unpleasant, but I don't know what would be better.
* Right now, this "can't happen"
*/
- errx(1, "xsignal_restart called with signal %d", sig);
+ errx(1, "xsignal_restart: called with signal %d", sig);
}
return(xsignal_restart(sig, func, restartable));
diff --git a/src/progressbar.h b/src/progressbar.h
index 9e004f415b62b..70e2df32382cb 100644
--- a/src/progressbar.h
+++ b/src/progressbar.h
@@ -1,7 +1,8 @@
-/* $NetBSD: progressbar.h,v 1.5 2005/02/10 16:00:38 jmc Exp $ */
+/* $NetBSD: progressbar.h,v 1.9 2009/05/20 12:53:47 lukem Exp $ */
+/* from NetBSD: progressbar.h,v 1.8 2009/04/12 10:18:52 lukem Exp */
/*-
- * Copyright (c) 1996-2003 The NetBSD Foundation, Inc.
+ * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -15,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -66,7 +60,7 @@ GLOBAL int fromatty; /* input is from a terminal */
GLOBAL int verbose; /* print messages coming back from server */
GLOBAL int quit_time; /* maximum time to wait if stalled */
-GLOBAL char *direction; /* direction transfer is occurring */
+GLOBAL const char *direction; /* direction transfer is occurring */
GLOBAL sigjmp_buf toplevel; /* non-local goto stuff for cmd scanner */
#endif /* !STANDALONE_PROGRESS */
@@ -90,10 +84,19 @@ void ptransfer(int);
# define ULLFP(x) "%" x "lu"
# define ULLT unsigned long
#else
+#if defined(HAVE_PRINTF_QD)
+# define LLF "%qd"
+# define LLFP(x) "%" x "qd"
+# define LLT long long
+# define ULLF "%qu"
+# define ULLFP(x) "%" x "qu"
+# define ULLT unsigned long long
+#else /* !defined(HAVE_PRINTF_QD) */
# define LLF "%lld"
# define LLFP(x) "%" x "lld"
# define LLT long long
# define ULLF "%llu"
# define ULLFP(x) "%" x "llu"
# define ULLT unsigned long long
+#endif /* !defined(HAVE_PRINTF_QD) */
#endif
diff --git a/src/ruserpass.c b/src/ruserpass.c
index 9cb318a090903..a2e036041956f 100644
--- a/src/ruserpass.c
+++ b/src/ruserpass.c
@@ -1,4 +1,5 @@
-/* $NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $ */
+/* $NetBSD: ruserpass.c,v 1.8 2007/08/06 04:33:24 lukem Exp $ */
+/* from NetBSD: ruserpass.c,v 1.33 2007/04/17 05:52:04 lukem Exp */
/*
* Copyright (c) 1985, 1993, 1994
@@ -29,12 +30,16 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ruserpass.c 8.4 (Berkeley) 4/27/95";
#else
-__RCSID("$NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $");
+__RCSID(" NetBSD: ruserpass.c,v 1.33 2007/04/17 05:52:04 lukem Exp ");
#endif
#endif /* not lint */
@@ -50,6 +55,8 @@ __RCSID("$NetBSD: ruserpass.c,v 1.29 2003/08/07 11:13:57 agc Exp $");
#include <string.h>
#include <unistd.h>
+#endif /* tnftp */
+
#include "ftp_var.h"
static int token(void);
@@ -66,7 +73,7 @@ static FILE *cfile;
static char tokval[100];
static struct toktab {
- char *tokstr;
+ const char *tokstr;
int tval;
} toktab[] = {
{ "default", DEFAULT },
@@ -80,11 +87,11 @@ static struct toktab {
};
int
-ruserpass(const char *host, const char **aname, const char **apass,
- const char **aacct)
+ruserpass(const char *host, char **aname, char **apass, char **aacct)
{
char *tmp;
- char myname[MAXHOSTNAMELEN + 1], *mydomain;
+ const char *mydomain;
+ char myname[MAXHOSTNAMELEN + 1];
int t, i, c, usedefault = 0;
struct stat stb;
@@ -93,7 +100,7 @@ ruserpass(const char *host, const char **aname, const char **apass,
cfile = fopen(netrc, "r");
if (cfile == NULL) {
if (errno != ENOENT)
- warn("%s", netrc);
+ warn("Can't read `%s'", netrc);
return (0);
}
if (gethostname(myname, sizeof(myname)) < 0)
@@ -102,7 +109,7 @@ ruserpass(const char *host, const char **aname, const char **apass,
if ((mydomain = strchr(myname, '.')) == NULL)
mydomain = "";
next:
- while ((t = token())) switch(t) {
+ while ((t = token()) > 0) switch(t) {
case DEFAULT:
usedefault = 1;
@@ -110,7 +117,9 @@ ruserpass(const char *host, const char **aname, const char **apass,
case MACH:
if (!usedefault) {
- if (token() != ID)
+ if ((t = token()) == -1)
+ goto bad;
+ if (t != ID)
continue;
/*
* Allow match either for user's input host name
@@ -134,12 +143,15 @@ ruserpass(const char *host, const char **aname, const char **apass,
continue;
}
match:
- while ((t = token()) && t != MACH && t != DEFAULT) switch(t) {
+ while ((t = token()) > 0 &&
+ t != MACH && t != DEFAULT) switch(t) {
case LOGIN:
- if (token()) {
+ if ((t = token()) == -1)
+ goto bad;
+ if (t) {
if (*aname == NULL)
- *aname = xstrdup(tokval);
+ *aname = ftp_strdup(tokval);
else {
if (strcmp(*aname, tokval))
goto next;
@@ -150,22 +162,26 @@ ruserpass(const char *host, const char **aname, const char **apass,
if ((*aname == NULL || strcmp(*aname, "anonymous")) &&
fstat(fileno(cfile), &stb) >= 0 &&
(stb.st_mode & 077) != 0) {
- warnx("Error: .netrc file is readable by others.");
- warnx("Remove password or make file unreadable by others.");
+ warnx("Error: .netrc file is readable by others");
+ warnx("Remove password or make file unreadable by others");
goto bad;
}
- if (token() && *apass == NULL)
- *apass = xstrdup(tokval);
+ if ((t = token()) == -1)
+ goto bad;
+ if (t && *apass == NULL)
+ *apass = ftp_strdup(tokval);
break;
case ACCOUNT:
if (fstat(fileno(cfile), &stb) >= 0
&& (stb.st_mode & 077) != 0) {
- warnx("Error: .netrc file is readable by others.");
- warnx("Remove account or make file unreadable by others.");
+ warnx("Error: .netrc file is readable by others");
+ warnx("Remove account or make file unreadable by others");
goto bad;
}
- if (token() && *aacct == NULL)
- *aacct = xstrdup(tokval);
+ if ((t = token()) == -1)
+ goto bad;
+ if (t && *aacct == NULL)
+ *aacct = ftp_strdup(tokval);
break;
case MACDEF:
if (proxy) {
@@ -225,9 +241,13 @@ ruserpass(const char *host, const char **aname, const char **apass,
}
*tmp = c;
if (*tmp == '\n') {
- if (*(tmp-1) == '\0') {
- macros[macnum++].mac_end = tmp - 1;
- break;
+ if (tmp == macros[macnum].mac_start) {
+ macros[macnum++].mac_end = tmp;
+ break;
+ } else if (*(tmp - 1) == '\0') {
+ macros[macnum++].mac_end =
+ tmp - 1;
+ break;
}
*tmp = '\0';
}
@@ -240,12 +260,14 @@ ruserpass(const char *host, const char **aname, const char **apass,
}
break;
default:
- warnx("Unknown .netrc keyword %s", tokval);
+ warnx("Unknown .netrc keyword `%s'", tokval);
break;
}
goto done;
}
done:
+ if (t == -1)
+ goto bad;
(void)fclose(cfile);
return (0);
bad:
@@ -271,16 +293,26 @@ token(void)
if (c == '"') {
while ((c = getc(cfile)) != EOF && c != '"') {
if (c == '\\')
- c = getc(cfile);
+ if ((c = getc(cfile)) == EOF)
+ break;
*cp++ = c;
+ if (cp == tokval + sizeof(tokval)) {
+ warnx("Token in .netrc too long");
+ return (-1);
+ }
}
} else {
*cp++ = c;
while ((c = getc(cfile)) != EOF
&& c != '\n' && c != '\t' && c != ' ' && c != ',') {
if (c == '\\')
- c = getc(cfile);
+ if ((c = getc(cfile)) == EOF)
+ break;
*cp++ = c;
+ if (cp == tokval + sizeof(tokval)) {
+ warnx("Token in .netrc too long");
+ return (-1);
+ }
}
}
*cp = 0;
diff --git a/src/util.c b/src/util.c
index 6f94bb04b943e..366b19450b84e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,7 +1,8 @@
-/* $NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $ */
+/* $NetBSD: util.c,v 1.21 2009/11/15 10:12:37 lukem Exp $ */
+/* from NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp */
/*-
- * Copyright (c) 1997-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1997-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -19,13 +20,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -69,9 +63,13 @@
* SUCH DAMAGE.
*/
+#include "tnftp.h"
+
+#if 0 /* tnftp */
+
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $");
+__RCSID(" NetBSD: util.c,v 1.152 2009/07/13 19:05:41 roy Exp ");
#endif /* not lint */
/*
@@ -90,6 +88,7 @@ __RCSID("$NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $");
#include <fcntl.h>
#include <glob.h>
#include <signal.h>
+#include <libgen.h>
#include <limits.h>
#include <netdb.h>
#include <stdio.h>
@@ -97,11 +96,12 @@ __RCSID("$NetBSD: util.c,v 1.123 2005/05/14 18:56:45 dsl Exp $");
#include <string.h>
#include <termios.h>
#include <time.h>
+#include <tzfile.h>
#include <unistd.h>
-#include "ftp_var.h"
+#endif /* tnftp */
-#define TM_YEAR_BASE 1900
+#include "ftp_var.h"
/*
* Connect to peer server and auto-login, if possible.
@@ -110,7 +110,7 @@ void
setpeer(int argc, char *argv[])
{
char *host;
- char *port;
+ const char *port;
if (argc == 0)
goto usage;
@@ -124,7 +124,7 @@ setpeer(int argc, char *argv[])
(void)another(&argc, &argv, "to");
if (argc < 2 || argc > 3) {
usage:
- fprintf(ttyout, "usage: %s host-name [port]\n", argv[0]);
+ UPRINTF("usage: %s host-name [port]\n", argv[0]);
code = -1;
return;
}
@@ -137,7 +137,7 @@ setpeer(int argc, char *argv[])
if (gatemode) {
if (gateserver == NULL || *gateserver == '\0')
- errx(1, "gateserver not defined (shouldn't happen)");
+ errx(1, "main: gateserver not defined");
host = hookup(gateserver, port);
} else
host = hookup(argv[1], port);
@@ -170,25 +170,25 @@ setpeer(int argc, char *argv[])
}
static void
-parse_feat(const char *line)
+parse_feat(const char *fline)
{
/*
* work-around broken ProFTPd servers that can't
- * even obey RFC 2389.
+ * even obey RFC2389.
*/
- while (*line && isspace((int)*line))
- line++;
+ while (*fline && isspace((int)*fline))
+ fline++;
- if (strcasecmp(line, "MDTM") == 0)
+ if (strcasecmp(fline, "MDTM") == 0)
features[FEAT_MDTM] = 1;
- else if (strncasecmp(line, "MLST", sizeof("MLST") - 1) == 0) {
+ else if (strncasecmp(fline, "MLST", sizeof("MLST") - 1) == 0) {
features[FEAT_MLST] = 1;
- } else if (strcasecmp(line, "REST STREAM") == 0)
+ } else if (strcasecmp(fline, "REST STREAM") == 0)
features[FEAT_REST_STREAM] = 1;
- else if (strcasecmp(line, "SIZE") == 0)
+ else if (strcasecmp(fline, "SIZE") == 0)
features[FEAT_SIZE] = 1;
- else if (strcasecmp(line, "TVFS") == 0)
+ else if (strcasecmp(fline, "TVFS") == 0)
features[FEAT_TVFS] = 1;
}
@@ -202,7 +202,7 @@ getremoteinfo(void)
int overbose, i;
overbose = verbose;
- if (debug == 0)
+ if (ftp_debug == 0)
verbose = -1;
/* determine remote system type */
@@ -268,7 +268,8 @@ getremoteinfo(void)
features[FEAT_FEAT] = 1;
} else
features[FEAT_FEAT] = 0;
- if (debug) {
+#ifndef NO_DEBUG
+ if (ftp_debug) {
#define DEBUG_FEAT(x) fprintf(ttyout, "features[" #x "] = %d\n", features[(x)])
DEBUG_FEAT(FEAT_FEAT);
DEBUG_FEAT(FEAT_MDTM);
@@ -278,6 +279,7 @@ getremoteinfo(void)
DEBUG_FEAT(FEAT_TVFS);
#undef DEBUG_FEAT
}
+#endif
reply_callback = NULL;
verbose = overbose;
@@ -308,6 +310,7 @@ cleanuppeer(void)
anonftp = 0;
data = -1;
epsv4bad = 0;
+ epsv6bad = 0;
if (username)
free(username);
username = NULL;
@@ -373,99 +376,105 @@ lostpeer(int dummy)
* Return non-zero if successful.
*/
int
-ftp_login(const char *host, const char *user, const char *pass)
+ftp_login(const char *host, const char *luser, const char *lpass)
{
char tmp[80];
- const char *acct;
- int n, aflag, rval, freeuser, freepass, freeacct;
+ char *fuser, *pass, *facct, *p;
+ char emptypass[] = "";
+ const char *errormsg;
+ int n, aflag, rval, nlen;
- acct = NULL;
- aflag = rval = freeuser = freepass = freeacct = 0;
-
- if (debug)
- fprintf(ttyout, "ftp_login: user `%s' pass `%s' host `%s'\n",
- user ? user : "<null>", pass ? pass : "<null>",
- host ? host : "<null>");
+ aflag = rval = 0;
+ fuser = pass = facct = NULL;
+ if (luser)
+ fuser = ftp_strdup(luser);
+ if (lpass)
+ pass = ftp_strdup(lpass);
+ DPRINTF("ftp_login: user `%s' pass `%s' host `%s'\n",
+ STRorNULL(fuser), STRorNULL(pass), STRorNULL(host));
/*
* Set up arguments for an anonymous FTP session, if necessary.
*/
if (anonftp) {
- user = "anonymous"; /* as per RFC 1635 */
- pass = getoptionvalue("anonpass");
+ FREEPTR(fuser);
+ fuser = ftp_strdup("anonymous"); /* as per RFC1635 */
+ FREEPTR(pass);
+ pass = ftp_strdup(getoptionvalue("anonpass"));
}
- if (user == NULL)
- freeuser = 1;
- if (pass == NULL)
- freepass = 1;
- freeacct = 1;
- if (ruserpass(host, &user, &pass, &acct) < 0) {
+ if (ruserpass(host, &fuser, &pass, &facct) < 0) {
code = -1;
goto cleanup_ftp_login;
}
- while (user == NULL) {
+ while (fuser == NULL) {
if (localname)
fprintf(ttyout, "Name (%s:%s): ", host, localname);
else
fprintf(ttyout, "Name (%s): ", host);
- *tmp = '\0';
- if (fgets(tmp, sizeof(tmp) - 1, stdin) == NULL) {
- fprintf(ttyout, "\nEOF received; login aborted.\n");
- clearerr(stdin);
+ errormsg = NULL;
+ nlen = get_line(stdin, tmp, sizeof(tmp), &errormsg);
+ if (nlen < 0) {
+ fprintf(ttyout, "%s; %s aborted.\n", errormsg, "login");
code = -1;
goto cleanup_ftp_login;
+ } else if (nlen == 0) {
+ fuser = ftp_strdup(localname);
+ } else {
+ fuser = ftp_strdup(tmp);
}
- tmp[strlen(tmp) - 1] = '\0';
- freeuser = 0;
- if (*tmp == '\0')
- user = localname;
- else
- user = tmp;
}
if (gatemode) {
char *nuser;
- int len;
+ size_t len;
- len = strlen(user) + 1 + strlen(host) + 1;
- nuser = xmalloc(len);
- (void)strlcpy(nuser, user, len);
+ len = strlen(fuser) + 1 + strlen(host) + 1;
+ nuser = ftp_malloc(len);
+ (void)strlcpy(nuser, fuser, len);
(void)strlcat(nuser, "@", len);
(void)strlcat(nuser, host, len);
- freeuser = 1;
- user = nuser;
+ FREEPTR(fuser);
+ fuser = nuser;
}
- n = command("USER %s", user);
+ n = command("USER %s", fuser);
if (n == CONTINUE) {
if (pass == NULL) {
- freepass = 0;
- pass = getpass("Password:");
+ p = getpass("Password: ");
+ if (p == NULL)
+ p = emptypass;
+ pass = ftp_strdup(p);
+ memset(p, 0, strlen(p));
}
n = command("PASS %s", pass);
+ memset(pass, 0, strlen(pass));
}
if (n == CONTINUE) {
aflag++;
- if (acct == NULL) {
- freeacct = 0;
- acct = getpass("Account:");
+ if (facct == NULL) {
+ p = getpass("Account: ");
+ if (p == NULL)
+ p = emptypass;
+ facct = ftp_strdup(p);
+ memset(p, 0, strlen(p));
}
- if (acct[0] == '\0') {
- warnx("Login failed.");
+ if (facct[0] == '\0') {
+ warnx("Login failed");
goto cleanup_ftp_login;
}
- n = command("ACCT %s", acct);
+ n = command("ACCT %s", facct);
+ memset(facct, 0, strlen(facct));
}
if ((n != COMPLETE) ||
- (!aflag && acct != NULL && command("ACCT %s", acct) != COMPLETE)) {
- warnx("Login failed.");
+ (!aflag && facct != NULL && command("ACCT %s", facct) != COMPLETE)) {
+ warnx("Login failed");
goto cleanup_ftp_login;
}
rval = 1;
- username = xstrdup(user);
+ username = ftp_strdup(fuser);
if (proxy)
goto cleanup_ftp_login;
@@ -483,12 +492,13 @@ ftp_login(const char *host, const char *user, const char *pass)
updateremotecwd();
cleanup_ftp_login:
- if (user != NULL && freeuser)
- free((char *)user);
- if (pass != NULL && freepass)
- free((char *)pass);
- if (acct != NULL && freeacct)
- free((char *)acct);
+ FREEPTR(fuser);
+ if (pass != NULL)
+ memset(pass, 0, strlen(pass));
+ FREEPTR(pass);
+ if (facct != NULL)
+ memset(facct, 0, strlen(facct));
+ FREEPTR(facct);
return (rval);
}
@@ -499,23 +509,26 @@ ftp_login(const char *host, const char *user, const char *pass)
* Returns false if no new arguments have been added.
*/
int
-another(int *pargc, char ***pargv, const char *prompt)
+another(int *pargc, char ***pargv, const char *aprompt)
{
- int len = strlen(line), ret;
+ const char *errormsg;
+ int ret, nlen;
+ size_t len;
+ len = strlen(line);
if (len >= sizeof(line) - 3) {
- fputs("sorry, arguments too long.\n", ttyout);
+ fputs("Sorry, arguments too long.\n", ttyout);
intr(0);
}
- fprintf(ttyout, "(%s) ", prompt);
+ fprintf(ttyout, "(%s) ", aprompt);
line[len++] = ' ';
- if (fgets(&line[len], sizeof(line) - len, stdin) == NULL) {
- clearerr(stdin);
+ errormsg = NULL;
+ nlen = get_line(stdin, line + len, sizeof(line)-len, &errormsg);
+ if (nlen < 0) {
+ fprintf(ttyout, "%s; %s aborted.\n", errormsg, "operation");
intr(0);
}
- len += strlen(&line[len]);
- if (len > 0 && line[len - 1] == '\n')
- line[len - 1] = '\0';
+ len += nlen;
makeargv();
ret = margc > *pargc;
*pargc = margc;
@@ -529,83 +542,83 @@ another(int *pargc, char ***pargv, const char *prompt)
* of writing to the screen.
*/
char *
-remglob(char *argv[], int doswitch, char **errbuf)
+remglob(char *argv[], int doswitch, const char **errbuf)
{
- char temp[MAXPATHLEN];
- static char buf[MAXPATHLEN];
- static FILE *ftemp = NULL;
- static char **args;
- int oldverbose, oldhash, oldprogress, fd, len;
- char *cp, *mode;
-
- if (!mflag || !connected) {
- if (!doglob)
- args = NULL;
- else {
- if (ftemp) {
- (void)fclose(ftemp);
- ftemp = NULL;
- }
- }
- return (NULL);
- }
- if (!doglob) {
- if (args == NULL)
- args = argv;
- if ((cp = *++args) == NULL)
- args = NULL;
- return (cp);
- }
- if (ftemp == NULL) {
+ static char buf[MAXPATHLEN];
+ static FILE *ftemp = NULL;
+ static char **args;
+ char temp[MAXPATHLEN];
+ int oldverbose, oldhash, oldprogress, fd;
+ char *cp;
+ const char *rmode;
+ size_t len;
+
+ if (!mflag || !connected) {
+ if (!doglob)
+ args = NULL;
+ else {
+ if (ftemp) {
+ (void)fclose(ftemp);
+ ftemp = NULL;
+ }
+ }
+ return (NULL);
+ }
+ if (!doglob) {
+ if (args == NULL)
+ args = argv;
+ if ((cp = *++args) == NULL)
+ args = NULL;
+ return (cp);
+ }
+ if (ftemp == NULL) {
len = strlcpy(temp, tmpdir, sizeof(temp));
if (temp[len - 1] != '/')
(void)strlcat(temp, "/", sizeof(temp));
(void)strlcat(temp, TMPFILE, sizeof(temp));
- if ((fd = mkstemp(temp)) < 0) {
- warn("unable to create temporary file %s", temp);
- return (NULL);
- }
- close(fd);
- oldverbose = verbose;
+ if ((fd = mkstemp(temp)) < 0) {
+ warn("Unable to create temporary file `%s'", temp);
+ return (NULL);
+ }
+ close(fd);
+ oldverbose = verbose;
verbose = (errbuf != NULL) ? -1 : 0;
- oldhash = hash;
+ oldhash = hash;
oldprogress = progress;
- hash = 0;
+ hash = 0;
progress = 0;
- if (doswitch)
- pswitch(!proxy);
- for (mode = "w"; *++argv != NULL; mode = "a")
- recvrequest("NLST", temp, *argv, mode, 0, 0);
+ if (doswitch)
+ pswitch(!proxy);
+ for (rmode = "w"; *++argv != NULL; rmode = "a")
+ recvrequest("NLST", temp, *argv, rmode, 0, 0);
if ((code / 100) != COMPLETE) {
if (errbuf != NULL)
*errbuf = reply_string;
}
- if (doswitch)
- pswitch(!proxy);
- verbose = oldverbose;
+ if (doswitch)
+ pswitch(!proxy);
+ verbose = oldverbose;
hash = oldhash;
progress = oldprogress;
- ftemp = fopen(temp, "r");
- (void)unlink(temp);
- if (ftemp == NULL) {
+ ftemp = fopen(temp, "r");
+ (void)unlink(temp);
+ if (ftemp == NULL) {
if (errbuf == NULL)
- fputs(
- "can't find list of remote files, oops.\n",
- ttyout);
+ warnx("Can't find list of remote files");
else
*errbuf =
- "can't find list of remote files, oops.";
- return (NULL);
- }
- }
- if (fgets(buf, sizeof(buf), ftemp) == NULL) {
- (void)fclose(ftemp);
+ "Can't find list of remote files";
+ return (NULL);
+ }
+ }
+ if (fgets(buf, sizeof(buf), ftemp) == NULL) {
+ (void)fclose(ftemp);
ftemp = NULL;
- return (NULL);
- }
- if ((cp = strchr(buf, '\n')) != NULL)
- *cp = '\0';
- return (buf);
+ return (NULL);
+ }
+ if ((cp = strchr(buf, '\n')) != NULL)
+ *cp = '\0';
+ return (buf);
}
/*
@@ -623,16 +636,16 @@ globulize(const char *pattern)
char *p;
if (!doglob)
- return (xstrdup(pattern));
+ return (ftp_strdup(pattern));
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_TILDE;
memset(&gl, 0, sizeof(gl));
if (glob(pattern, flags, NULL, &gl) || gl.gl_pathc == 0) {
- warnx("%s: not found", pattern);
+ warnx("Glob pattern `%s' not found", pattern);
globfree(&gl);
return (NULL);
}
- p = xstrdup(gl.gl_pathv[0]);
+ p = ftp_strdup(gl.gl_pathv[0]);
globfree(&gl);
return (p);
}
@@ -648,7 +661,7 @@ remotesize(const char *file, int noisy)
overbose = verbose;
size = -1;
- if (debug == 0)
+ if (ftp_debug == 0)
verbose = -1;
if (! features[FEAT_SIZE]) {
if (noisy)
@@ -670,7 +683,7 @@ remotesize(const char *file, int noisy)
} else {
if (r == ERROR && code == 500 && features[FEAT_SIZE] == -1)
features[FEAT_SIZE] = 0;
- if (noisy && debug == 0) {
+ if (noisy && ftp_debug == 0) {
fputs(reply_string, ttyout);
putc('\n', ttyout);
}
@@ -692,7 +705,7 @@ remotemodtime(const char *file, int noisy)
overbose = verbose;
ocode = code;
rtime = -1;
- if (debug == 0)
+ if (ftp_debug == 0)
verbose = -1;
if (! features[FEAT_MDTM]) {
if (noisy)
@@ -704,7 +717,6 @@ remotemodtime(const char *file, int noisy)
if (r == COMPLETE) {
struct tm timebuf;
char *timestr, *frac;
- int yy, mo, day, hour, min, sec;
/*
* time-val = 14DIGIT [ "." 1*DIGIT ]
@@ -736,33 +748,30 @@ remotemodtime(const char *file, int noisy)
timestr[1] = '0';
fprintf(ttyout, "Converted to `%s'\n", timestr);
}
+ memset(&timebuf, 0, sizeof(timebuf));
if (strlen(timestr) != 14 ||
- sscanf(timestr, "%04d%02d%02d%02d%02d%02d",
- &yy, &mo, &day, &hour, &min, &sec) != 6) {
+ (strptime(timestr, "%Y%m%d%H%M%S", &timebuf) == NULL)) {
bad_parse_time:
fprintf(ttyout, "Can't parse time `%s'.\n", timestr);
goto cleanup_parse_time;
}
- memset(&timebuf, 0, sizeof(timebuf));
- timebuf.tm_sec = sec;
- timebuf.tm_min = min;
- timebuf.tm_hour = hour;
- timebuf.tm_mday = day;
- timebuf.tm_mon = mo - 1;
- timebuf.tm_year = yy - TM_YEAR_BASE;
timebuf.tm_isdst = -1;
rtime = timegm(&timebuf);
if (rtime == -1) {
- if (noisy || debug != 0)
+ if (noisy || ftp_debug != 0)
goto bad_parse_time;
else
goto cleanup_parse_time;
- } else if (debug)
- fprintf(ttyout, "parsed date as: %s", ctime(&rtime));
+ } else {
+ DPRINTF("remotemodtime: parsed date `%s' as " LLF
+ ", %s",
+ timestr, (LLT)rtime,
+ rfc2822time(localtime(&rtime)));
+ }
} else {
if (r == ERROR && code == 500 && features[FEAT_MDTM] == -1)
features[FEAT_MDTM] = 0;
- if (noisy && debug == 0) {
+ if (noisy && ftp_debug == 0) {
fputs(reply_string, ttyout);
putc('\n', ttyout);
}
@@ -775,6 +784,21 @@ remotemodtime(const char *file, int noisy)
}
/*
+ * Format tm in an RFC2822 compatible manner, with a trailing \n.
+ * Returns a pointer to a static string containing the result.
+ */
+const char *
+rfc2822time(const struct tm *tm)
+{
+ static char result[50];
+
+ if (strftime(result, sizeof(result),
+ "%a, %d %b %Y %H:%M:%S %z\n", tm) == 0)
+ errx(1, "Can't convert RFC2822 time: buffer too small");
+ return result;
+}
+
+/*
* Update global `localcwd', which contains the state of the local cwd
*/
void
@@ -783,8 +807,7 @@ updatelocalcwd(void)
if (getcwd(localcwd, sizeof(localcwd)) == NULL)
localcwd[0] = '\0';
- if (debug)
- fprintf(ttyout, "got localcwd as `%s'\n", localcwd);
+ DPRINTF("updatelocalcwd: got `%s'\n", localcwd);
}
/*
@@ -793,12 +816,13 @@ updatelocalcwd(void)
void
updateremotecwd(void)
{
- int overbose, ocode, i;
+ int overbose, ocode;
+ size_t i;
char *cp;
overbose = verbose;
ocode = code;
- if (debug == 0)
+ if (ftp_debug == 0)
verbose = -1;
if (command("PWD") != COMPLETE)
goto badremotecwd;
@@ -816,8 +840,7 @@ updateremotecwd(void)
remotecwd[i] = *cp;
}
remotecwd[i] = '\0';
- if (debug)
- fprintf(ttyout, "got remotecwd as `%s'\n", remotecwd);
+ DPRINTF("updateremotecwd: got `%s'\n", remotecwd);
goto cleanupremotecwd;
badremotecwd:
remotecwd[0]='\0';
@@ -833,20 +856,26 @@ updateremotecwd(void)
int
fileindir(const char *file, const char *dir)
{
- char realfile[PATH_MAX+1];
+ char parentdirbuf[PATH_MAX+1], *parentdir;
+ char realdir[PATH_MAX+1];
size_t dirlen;
- if (realpath(file, realfile) == NULL) {
- warn("Unable to determine real path of `%s'", file);
+ /* determine parent directory of file */
+ (void)strlcpy(parentdirbuf, file, sizeof(parentdirbuf));
+ parentdir = dirname(parentdirbuf);
+ if (strcmp(parentdir, ".") == 0)
+ return 1; /* current directory is ok */
+
+ /* find the directory */
+ if (realpath(parentdir, realdir) == NULL) {
+ warn("Unable to determine real path of `%s'", parentdir);
return 0;
}
- if (realfile[0] != '/') /* relative result */
+ if (realdir[0] != '/') /* relative result is ok */
return 1;
dirlen = strlen(dir);
-#if 0
-printf("file %s realfile %s dir %s [%d]\n", file, realfile, dir, dirlen);
-#endif
- if (strncmp(realfile, dir, dirlen) == 0 && realfile[dirlen] == '/')
+ if (strncmp(realdir, dir, dirlen) == 0 &&
+ (realdir[dirlen] == '/' || realdir[dirlen] == '\0'))
return 1;
return 0;
}
@@ -857,9 +886,10 @@ printf("file %s realfile %s dir %s [%d]\n", file, realfile, dir, dirlen);
void
list_vertical(StringList *sl)
{
- int i, j, w;
- int columns, width, lines;
+ size_t i, j;
+ size_t columns, lines;
char *p;
+ size_t w, width;
width = 0;
@@ -883,10 +913,12 @@ list_vertical(StringList *sl)
putc('\n', ttyout);
break;
}
- w = strlen(p);
- while (w < width) {
- w = (w + 8) &~ 7;
- (void)putc('\t', ttyout);
+ if (p) {
+ w = strlen(p);
+ while (w < width) {
+ w = (w + 8) &~ 7;
+ (void)putc('\t', ttyout);
+ }
}
}
}
@@ -1031,11 +1063,11 @@ setupsockbufsize(int sock)
if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF,
(void *)&sndbuf_size, sizeof(sndbuf_size)) == -1)
- warn("unable to set sndbuf size %d", sndbuf_size);
+ warn("Unable to set sndbuf size %d", sndbuf_size);
if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
(void *)&rcvbuf_size, sizeof(rcvbuf_size)) == -1)
- warn("unable to set rcvbuf size %d", rcvbuf_size);
+ warn("Unable to set rcvbuf size %d", rcvbuf_size);
}
/*
@@ -1044,7 +1076,7 @@ setupsockbufsize(int sock)
void
ftpvis(char *dst, size_t dstlen, const char *src, size_t srclen)
{
- int di, si;
+ size_t di, si;
for (di = si = 0;
src[si] != '\0' && di < dstlen && si < srclen;
@@ -1073,9 +1105,9 @@ ftpvis(char *dst, size_t dstlen, const char *src, size_t srclen)
void
formatbuf(char *buf, size_t len, const char *src)
{
- const char *p;
- char *p2, *q;
- int i, op, updirs, pdirs;
+ const char *p, *p2, *q;
+ size_t i;
+ int op, updirs, pdirs;
#define ADDBUF(x) do { \
if (i >= len - 1) \
@@ -1153,7 +1185,7 @@ formatbuf(char *buf, size_t len, const char *src)
case 'M':
case 'm':
- for (p2 = connected && username ? username : "-";
+ for (p2 = connected && hostname ? hostname : "-";
*p2 ; p2++) {
if (op == 'm' && *p2 == '.')
break;
@@ -1182,39 +1214,6 @@ formatbuf(char *buf, size_t len, const char *src)
}
/*
- * Parse `port' into a TCP port number, defaulting to `defport' if `port' is
- * an unknown service name. If defport != -1, print a warning upon bad parse.
- */
-int
-parseport(const char *port, int defport)
-{
- int rv;
- long nport;
- char *p, *ep;
-
- p = xstrdup(port);
- nport = strtol(p, &ep, 10);
- if (*ep != '\0' && ep == p) {
- struct servent *svp;
-
- svp = getservbyname(port, "tcp");
- if (svp == NULL) {
- badparseport:
- if (defport != -1)
- warnx("Unknown port `%s', using port %d",
- port, defport);
- rv = defport;
- } else
- rv = ntohs(svp->s_port);
- } else if (nport < 1 || nport > MAX_IN_PORT_T || *ep != '\0')
- goto badparseport;
- else
- rv = nport;
- free(p);
- return (rv);
-}
-
-/*
* Determine if given string is an IPv6 address or not.
* Return 1 for yes, 0 for no
*/
@@ -1226,7 +1225,7 @@ isipv6addr(const char *addr)
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_INET6;
+ hints.ai_family = AF_INET6;
hints.ai_socktype = SOCK_DGRAM; /*dummy*/
hints.ai_flags = AI_NUMERICHOST;
if (getaddrinfo(addr, "0", &hints, &res) != 0)
@@ -1235,35 +1234,124 @@ isipv6addr(const char *addr)
rv = 1;
freeaddrinfo(res);
}
- if (debug)
- fprintf(ttyout, "isipv6addr: got %d for %s\n", rv, addr);
+ DPRINTF("isipv6addr: got %d for %s\n", rv, addr);
#endif
return (rv == 1) ? 1 : 0;
}
+/*
+ * Read a line from the FILE stream into buf/buflen using fgets(), so up
+ * to buflen-1 chars will be read and the result will be NUL terminated.
+ * If the line has a trailing newline it will be removed.
+ * If the line is too long, excess characters will be read until
+ * newline/EOF/error.
+ * If EOF/error occurs or a too-long line is encountered and errormsg
+ * isn't NULL, it will be changed to a description of the problem.
+ * (The EOF message has a leading \n for cosmetic purposes).
+ * Returns:
+ * >=0 length of line (excluding trailing newline) if all ok
+ * -1 error occurred
+ * -2 EOF encountered
+ * -3 line was too long
+ */
+int
+get_line(FILE *stream, char *buf, size_t buflen, const char **errormsg)
+{
+ int rv, ch;
+ size_t len;
+
+ if (fgets(buf, buflen, stream) == NULL) {
+ if (feof(stream)) { /* EOF */
+ rv = -2;
+ if (errormsg)
+ *errormsg = "\nEOF received";
+ } else { /* error */
+ rv = -1;
+ if (errormsg)
+ *errormsg = "Error encountered";
+ }
+ clearerr(stream);
+ return rv;
+ }
+ len = strlen(buf);
+ if (buf[len-1] == '\n') { /* clear any trailing newline */
+ buf[--len] = '\0';
+ } else if (len == buflen-1) { /* line too long */
+ while ((ch = getchar()) != '\n' && ch != EOF)
+ continue;
+ if (errormsg)
+ *errormsg = "Input line is too long";
+ clearerr(stream);
+ return -3;
+ }
+ if (errormsg)
+ *errormsg = NULL;
+ return len;
+}
/*
- * Internal version of connect(2); sets socket buffer sizes first and
+ * Internal version of connect(2); sets socket buffer sizes,
+ * binds to a specific local address (if set), and
* supports a connection timeout using a non-blocking connect(2) with
* a poll(2).
* Socket fcntl flags are temporarily updated to include O_NONBLOCK;
* these will not be reverted on connection failure.
- * Returns -1 upon failure (with errno set to the problem), or 0 on success.
+ * Returns 0 on success, or -1 upon failure (with an appropriate
+ * error message displayed.)
*/
int
-xconnect(int sock, const struct sockaddr *name, socklen_t namelen)
+ftp_connect(int sock, const struct sockaddr *name, socklen_t namelen)
{
int flags, rv, timeout, error;
socklen_t slen;
struct timeval endtime, now, td;
struct pollfd pfd[1];
+ char hname[NI_MAXHOST];
+ char sname[NI_MAXSERV];
setupsockbufsize(sock);
+ if (getnameinfo(name, namelen,
+ hname, sizeof(hname), sname, sizeof(sname),
+ NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ strlcpy(hname, "?", sizeof(hname));
+ strlcpy(sname, "?", sizeof(sname));
+ }
+
+ if (bindai != NULL) { /* bind to specific addr */
+ struct addrinfo *ai;
+
+ for (ai = bindai; ai != NULL; ai = ai->ai_next) {
+ if (ai->ai_family == name->sa_family)
+ break;
+ }
+ if (ai == NULL)
+ ai = bindai;
+ if (bind(sock, ai->ai_addr, ai->ai_addrlen) == -1) {
+ char bname[NI_MAXHOST];
+ int saveerr;
+
+ saveerr = errno;
+ if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
+ bname, sizeof(bname), NULL, 0, NI_NUMERICHOST) != 0)
+ strlcpy(bname, "?", sizeof(bname));
+ errno = saveerr;
+ warn("Can't bind to `%s'", bname);
+ return -1;
+ }
+ }
- if ((flags = fcntl(sock, F_GETFL, 0)) == -1)
- return -1; /* get current socket flags */
- if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1)
- return -1; /* set non-blocking connect */
+ /* save current socket flags */
+ if ((flags = fcntl(sock, F_GETFL, 0)) == -1) {
+ warn("Can't %s socket flags for connect to `%s:%s'",
+ "save", hname, sname);
+ return -1;
+ }
+ /* set non-blocking connect */
+ if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) {
+ warn("Can't set socket non-blocking for connect to `%s:%s'",
+ hname, sname);
+ return -1;
+ }
/* NOTE: we now must restore socket flags on successful exit */
@@ -1277,8 +1365,11 @@ xconnect(int sock, const struct sockaddr *name, socklen_t namelen)
rv = connect(sock, name, namelen); /* inititate the connection */
if (rv == -1) { /* connection error */
- if (errno != EINPROGRESS) /* error isn't "please wait" */
+ if (errno != EINPROGRESS) { /* error isn't "please wait" */
+ connecterror:
+ warn("Can't connect to `%s:%s'", hname, sname);
return -1;
+ }
/* connect EINPROGRESS; wait */
do {
@@ -1292,34 +1383,39 @@ xconnect(int sock, const struct sockaddr *name, socklen_t namelen)
timeout = INFTIM;
}
pfd[0].revents = 0;
- rv = xpoll(pfd, 1, timeout);
+ rv = ftp_poll(pfd, 1, timeout);
/* loop until poll ! EINTR */
} while (rv == -1 && errno == EINTR);
if (rv == 0) { /* poll (connect) timed out */
errno = ETIMEDOUT;
- return -1;
+ goto connecterror;
}
if (rv == -1) { /* poll error */
- return -1;
+ goto connecterror;
} else if (pfd[0].revents & (POLLIN|POLLOUT)) {
slen = sizeof(error); /* OK, or pending error */
if (getsockopt(sock, SOL_SOCKET, SO_ERROR,
- &error, &slen) == -1)
- return -1; /* Solaris pending error */
- if (error != 0) {
+ &error, &slen) == -1) {
+ /* Solaris pending error */
+ goto connecterror;
+ } else if (error != 0) {
errno = error; /* BSD pending error */
- return -1;
+ goto connecterror;
}
} else {
errno = EBADF; /* this shouldn't happen ... */
- return -1;
+ goto connecterror;
}
}
- if (fcntl(sock, F_SETFL, flags) == -1) /* restore socket flags */
+ if (fcntl(sock, F_SETFL, flags) == -1) {
+ /* restore socket flags */
+ warn("Can't %s socket flags for connect to `%s:%s'",
+ "restore", hname, sname);
return -1;
+ }
return 0;
}
@@ -1327,7 +1423,7 @@ xconnect(int sock, const struct sockaddr *name, socklen_t namelen)
* Internal version of listen(2); sets socket buffer sizes first.
*/
int
-xlisten(int sock, int backlog)
+ftp_listen(int sock, int backlog)
{
setupsockbufsize(sock);
@@ -1339,16 +1435,74 @@ xlisten(int sock, int backlog)
* on platforms without the former.
*/
int
-xpoll(struct pollfd *fds, int nfds, int timeout)
+ftp_poll(struct pollfd *fds, int nfds, int timeout)
{
+#if defined(HAVE_POLL)
return poll(fds, nfds, timeout);
+
+#elif defined(HAVE_SELECT)
+ /* implement poll(2) using select(2) */
+ fd_set rset, wset, xset;
+ const int rsetflags = POLLIN | POLLRDNORM;
+ const int wsetflags = POLLOUT | POLLWRNORM;
+ const int xsetflags = POLLRDBAND;
+ struct timeval tv, *ptv;
+ int i, max, rv;
+
+ FD_ZERO(&rset); /* build list of read & write events */
+ FD_ZERO(&wset);
+ FD_ZERO(&xset);
+ max = 0;
+ for (i = 0; i < nfds; i++) {
+ if (fds[i].fd > FD_SETSIZE) {
+ warnx("can't select fd %d", fds[i].fd);
+ errno = EINVAL;
+ return -1;
+ } else if (fds[i].fd > max)
+ max = fds[i].fd;
+ if (fds[i].events & rsetflags)
+ FD_SET(fds[i].fd, &rset);
+ if (fds[i].events & wsetflags)
+ FD_SET(fds[i].fd, &wset);
+ if (fds[i].events & xsetflags)
+ FD_SET(fds[i].fd, &xset);
+ }
+
+ ptv = &tv; /* determine timeout */
+ if (timeout == -1) { /* wait forever */
+ ptv = NULL;
+ } else if (timeout == 0) { /* poll once */
+ ptv->tv_sec = 0;
+ ptv->tv_usec = 0;
+ }
+ else if (timeout != 0) { /* wait timeout milliseconds */
+ ptv->tv_sec = timeout / 1000;
+ ptv->tv_usec = (timeout % 1000) * 1000;
+ }
+ rv = select(max + 1, &rset, &wset, &xset, ptv);
+ if (rv <= 0) /* -1 == error, 0 == timeout */
+ return rv;
+
+ for (i = 0; i < nfds; i++) { /* determine results */
+ if (FD_ISSET(fds[i].fd, &rset))
+ fds[i].revents |= (fds[i].events & rsetflags);
+ if (FD_ISSET(fds[i].fd, &wset))
+ fds[i].revents |= (fds[i].events & wsetflags);
+ if (FD_ISSET(fds[i].fd, &xset))
+ fds[i].revents |= (fds[i].events & xsetflags);
+ }
+ return rv;
+
+#else
+# error no way to implement xpoll
+#endif
}
/*
* malloc() with inbuilt error checking
*/
void *
-xmalloc(size_t size)
+ftp_malloc(size_t size)
{
void *p;
@@ -1362,7 +1516,7 @@ xmalloc(size_t size)
* sl_init() with inbuilt error checking
*/
StringList *
-xsl_init(void)
+ftp_sl_init(void)
{
StringList *p;
@@ -1376,7 +1530,7 @@ xsl_init(void)
* sl_add() with inbuilt error checking
*/
void
-xsl_add(StringList *sl, char *i)
+ftp_sl_add(StringList *sl, char *i)
{
if (sl_add(sl, i) == -1)
@@ -1387,12 +1541,12 @@ xsl_add(StringList *sl, char *i)
* strdup() with inbuilt error checking
*/
char *
-xstrdup(const char *str)
+ftp_strdup(const char *str)
{
char *s;
if (str == NULL)
- errx(1, "xstrdup() called with NULL argument");
+ errx(1, "ftp_strdup: called with NULL argument");
s = strdup(str);
if (s == NULL)
err(1, "Unable to allocate memory for string copy");
diff --git a/src/version.h b/src/version.h
index 7b69df13235fd..6bb3631030711 100644
--- a/src/version.h
+++ b/src/version.h
@@ -1,6 +1,8 @@
-/* $NetBSD: version.h,v 1.50 2005/05/14 15:26:43 lukem Exp $ */
+/* $NetBSD: version.h,v 1.4 2009/11/15 10:12:37 lukem Exp $ */
+/* from NetBSD: version.h,v 1.80 2009/11/15 10:03:16 lukem Exp */
+
/*-
- * Copyright (c) 1999-2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
@@ -14,13 +16,6 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the NetBSD
- * Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -40,5 +35,5 @@
#endif
#ifndef FTP_VERSION
-#define FTP_VERSION "20050514"
+#define FTP_VERSION "20090915"
#endif