1/*	$NetBSD: cmdtab.c,v 1.11 2009/05/20 12:53:47 lukem Exp $	*/
2/*	from	NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp	*/
3
4/*-
5 * Copyright (c) 1996-2009 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Luke Mewburn.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/*
34 * Copyright (c) 1985, 1989, 1993, 1994
35 *	The Regents of the University of California.  All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 *    notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 *    notice, this list of conditions and the following disclaimer in the
44 *    documentation and/or other materials provided with the distribution.
45 * 3. Neither the name of the University nor the names of its contributors
46 *    may be used to endorse or promote products derived from this software
47 *    without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 */
61
62#include "tnftp.h"
63
64#if 0	/* tnftp */
65
66#include <sys/cdefs.h>
67#ifndef lint
68#if 0
69static char sccsid[] = "@(#)cmdtab.c	8.4 (Berkeley) 10/9/94";
70#else
71__RCSID(" NetBSD: cmdtab.c,v 1.51 2009/04/12 10:18:52 lukem Exp  ");
72#endif
73#endif /* not lint */
74
75#include <stdio.h>
76
77#endif	/* tnftp */
78
79#include "ftp_var.h"
80
81/*
82 * User FTP -- Command Tables.
83 */
84
85#define HSTR	static const char
86
87#ifndef NO_HELP
88HSTR	accounthelp[] =	"send account command to remote server";
89HSTR	appendhelp[] =	"append to a file";
90HSTR	asciihelp[] =	"set ascii transfer type";
91HSTR	beephelp[] =	"beep when command completed";
92HSTR	binaryhelp[] =	"set binary transfer type";
93HSTR	casehelp[] =	"toggle mget upper/lower case id mapping";
94HSTR	cdhelp[] =	"change remote working directory";
95HSTR	cduphelp[] =	"change remote working directory to parent directory";
96HSTR	chmodhelp[] =	"change file permissions of remote file";
97HSTR	connecthelp[] =	"connect to remote ftp server";
98HSTR	crhelp[] =	"toggle carriage return stripping on ascii gets";
99HSTR	debughelp[] =	"toggle/set debugging mode";
100HSTR	deletehelp[] =	"delete remote file";
101HSTR	disconhelp[] =	"terminate ftp session";
102HSTR	domachelp[] =	"execute macro";
103HSTR	edithelp[] =	"toggle command line editing";
104HSTR	epsvhelp[] =	"toggle use of EPSV/EPRT on both IPv4 and IPV6 ftp";
105HSTR	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
106HSTR	epsv6help[] =	"toggle use of EPSV/EPRT on IPv6 ftp";
107HSTR	feathelp[] =	"show FEATures supported by remote system";
108HSTR	formhelp[] =	"set file transfer format";
109HSTR	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
110HSTR	globhelp[] =	"toggle metacharacter expansion of local file names";
111HSTR	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
112HSTR	helphelp[] =	"print local help information";
113HSTR	idlehelp[] =	"get (set) idle timer on remote side";
114HSTR	lcdhelp[] =	"change local working directory";
115HSTR	lpagehelp[] =	"view a local file through your pager";
116HSTR	lpwdhelp[] =	"print local working directory";
117HSTR	lshelp[] =	"list contents of remote path";
118HSTR	macdefhelp[] =  "define a macro";
119HSTR	mdeletehelp[] =	"delete multiple files";
120HSTR	mgethelp[] =	"get multiple files";
121HSTR	mregethelp[] =	"get multiple files restarting at end of local file";
122HSTR	fgethelp[] =	"get files using a localfile as a source of names";
123HSTR	mkdirhelp[] =	"make directory on the remote machine";
124HSTR	mlshelp[] =	"list contents of multiple remote directories";
125HSTR	mlsdhelp[] =	"list contents of remote directory in a machine "
126			"parsable form";
127HSTR	mlsthelp[] =	"list remote path in a machine parsable form";
128HSTR	modehelp[] =	"set file transfer mode";
129HSTR	modtimehelp[] = "show last modification time of remote file";
130HSTR	mputhelp[] =	"send multiple files";
131HSTR	newerhelp[] =	"get file if remote file is newer than local file ";
132HSTR	nmaphelp[] =	"set templates for default file name mapping";
133HSTR	ntranshelp[] =	"set translation table for default file name mapping";
134HSTR	optshelp[] =	"show or set options for remote commands";
135HSTR	pagehelp[] =	"view a remote file through your pager";
136HSTR	passivehelp[] =	"toggle use of passive transfer mode";
137HSTR	plshelp[] =	"list contents of remote path through your pager";
138HSTR	pmlsdhelp[] =	"list contents of remote directory in a machine "
139			"parsable form through your pager";
140HSTR	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
141HSTR	preservehelp[] ="toggle preservation of modification time of "
142			"retrieved files";
143HSTR	progresshelp[] ="toggle transfer progress meter";
144HSTR	prompthelp[] =	"force interactive prompting on multiple commands";
145HSTR	proxyhelp[] =	"issue command on alternate connection";
146HSTR	pwdhelp[] =	"print working directory on remote machine";
147HSTR	quithelp[] =	"terminate ftp session and exit";
148HSTR	quotehelp[] =	"send arbitrary ftp command";
149HSTR	ratehelp[] =	"set transfer rate limit (in bytes/second)";
150HSTR	receivehelp[] =	"receive file";
151HSTR	regethelp[] =	"get file restarting at end of local file";
152HSTR	remotehelp[] =	"get help from remote server";
153HSTR	renamehelp[] =	"rename file";
154HSTR	resethelp[] =	"clear queued command replies";
155HSTR	restarthelp[]=	"restart file transfer at bytecount";
156HSTR	rmdirhelp[] =	"remove directory on the remote machine";
157HSTR	rmtstatushelp[]="show status of remote machine";
158HSTR	runiquehelp[] = "toggle store unique for local files";
159HSTR	sendhelp[] =	"send one file";
160HSTR	sethelp[] =	"set or display options";
161HSTR	shellhelp[] =	"escape to the shell";
162HSTR	sitehelp[] =	"send site specific command to remote server\n"
163			"\t\tTry \"rhelp site\" or \"site help\" "
164			"for more information";
165HSTR	sizecmdhelp[] = "show size of remote file";
166HSTR	statushelp[] =	"show current status";
167HSTR	structhelp[] =	"set file transfer structure";
168HSTR	suniquehelp[] = "toggle store unique on remote machine";
169HSTR	systemhelp[] =  "show remote system type";
170HSTR	tenexhelp[] =	"set tenex file transfer type";
171HSTR	tracehelp[] =	"toggle packet tracing";
172HSTR	typehelp[] =	"set file transfer type";
173HSTR	umaskhelp[] =	"get (set) umask on remote side";
174HSTR	unsethelp[] =	"unset an option";
175HSTR	usagehelp[] =	"show command usage";
176HSTR	userhelp[] =	"send new user information";
177HSTR	verbosehelp[] =	"toggle verbose mode";
178HSTR	xferbufhelp[] =	"set socket send/receive buffer size";
179#endif
180
181HSTR	empty[] = "";
182
183#ifdef NO_HELP
184#define H(x)	empty
185#else
186#define H(x)	x
187#endif
188
189#ifdef NO_EDITCOMPLETE
190#define	CMPL(x)
191#define	CMPL0
192#else  /* !NO_EDITCOMPLETE */
193#define	CMPL(x)	#x,
194#define	CMPL0	empty,
195#endif /* !NO_EDITCOMPLETE */
196
197struct cmd cmdtab[] = {
198	{ "!",		H(shellhelp),	0, 0, 0, CMPL0		shell },
199	{ "$",		H(domachelp),	1, 0, 0, CMPL0		domacro },
200	{ "account",	H(accounthelp),	0, 1, 1, CMPL0		account},
201	{ "append",	H(appendhelp),	1, 1, 1, CMPL(lr)	put },
202	{ "ascii",	H(asciihelp),	0, 1, 1, CMPL0		setascii },
203	{ "bell",	H(beephelp),	0, 0, 0, CMPL0		setbell },
204	{ "binary",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
205	{ "bye",	H(quithelp),	0, 0, 0, CMPL0		quit },
206	{ "case",	H(casehelp),	0, 0, 1, CMPL0		setcase },
207	{ "cd",		H(cdhelp),	0, 1, 1, CMPL(r)	cd },
208	{ "cdup",	H(cduphelp),	0, 1, 1, CMPL0		cdup },
209	{ "chmod",	H(chmodhelp),	0, 1, 1, CMPL(nr)	do_chmod },
210	{ "close",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
211	{ "cr",		H(crhelp),	0, 0, 0, CMPL0		setcr },
212	{ "debug",	H(debughelp),	0, 0, 0, CMPL0		setdebug },
213	{ "delete",	H(deletehelp),	0, 1, 1, CMPL(r)	delete },
214	{ "dir",	H(lshelp),	1, 1, 1, CMPL(rl)	ls },
215	{ "disconnect",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
216	{ "edit",	H(edithelp),	0, 0, 0, CMPL0		setedit },
217	{ "epsv",	H(epsvhelp),	0, 0, 0, CMPL0		setepsv },
218	{ "epsv4",	H(epsv4help),	0, 0, 0, CMPL0		setepsv4 },
219	{ "epsv6",	H(epsv6help),	0, 0, 0, CMPL0		setepsv6 },
220	{ "exit",	H(quithelp),	0, 0, 0, CMPL0		quit },
221	{ "features",	H(feathelp),	0, 1, 1, CMPL0		feat },
222	{ "fget",	H(fgethelp),	1, 1, 1, CMPL(l)	fget },
223	{ "form",	H(formhelp),	0, 1, 1, CMPL0		setform },
224	{ "ftp",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
225	{ "gate",	H(gatehelp),	0, 0, 0, CMPL0		setgate },
226	{ "get",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
227	{ "glob",	H(globhelp),	0, 0, 0, CMPL0		setglob },
228	{ "hash",	H(hashhelp),	0, 0, 0, CMPL0		sethash },
229	{ "help",	H(helphelp),	0, 0, 1, CMPL(C)	help },
230	{ "idle",	H(idlehelp),	0, 1, 1, CMPL0		idlecmd },
231	{ "image",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
232	{ "lcd",	H(lcdhelp),	0, 0, 0, CMPL(l)	lcd },
233	{ "less",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
234	{ "lpage",	H(lpagehelp),	0, 0, 0, CMPL(l)	lpage },
235	{ "lpwd",	H(lpwdhelp),	0, 0, 0, CMPL0		lpwd },
236	{ "ls",		H(lshelp),	1, 1, 1, CMPL(rl)	ls },
237	{ "macdef",	H(macdefhelp),	0, 0, 0, CMPL0		macdef },
238	{ "mdelete",	H(mdeletehelp),	1, 1, 1, CMPL(R)	mdelete },
239	{ "mdir",	H(mlshelp),	1, 1, 1, CMPL(R)	mls },
240	{ "mget",	H(mgethelp),	1, 1, 1, CMPL(R)	mget },
241	{ "mkdir",	H(mkdirhelp),	0, 1, 1, CMPL(r)	makedir },
242	{ "mls",	H(mlshelp),	1, 1, 1, CMPL(R)	mls },
243	{ "mlsd",	H(mlsdhelp),	1, 1, 1, CMPL(r)	ls },
244	{ "mlst",	H(mlsthelp),	1, 1, 1, CMPL(r)	mlst },
245	{ "mode",	H(modehelp),	0, 1, 1, CMPL0		setftmode },
246	{ "modtime",	H(modtimehelp),	0, 1, 1, CMPL(r)	modtime },
247	{ "more",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
248	{ "mput",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
249	{ "mreget",	H(mregethelp),	1, 1, 1, CMPL(R)	mget },
250	{ "msend",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
251	{ "newer",	H(newerhelp),	1, 1, 1, CMPL(r)	newer },
252	{ "nlist",	H(lshelp),	1, 1, 1, CMPL(rl)	ls },
253	{ "nmap",	H(nmaphelp),	0, 0, 1, CMPL0		setnmap },
254	{ "ntrans",	H(ntranshelp),	0, 0, 1, CMPL0		setntrans },
255	{ "open",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
256	{ "page",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
257	{ "passive",	H(passivehelp),	0, 0, 0, CMPL0		setpassive },
258	{ "pdir",	H(plshelp),	1, 1, 1, CMPL(r)	ls },
259	{ "pls",	H(plshelp),	1, 1, 1, CMPL(r)	ls },
260	{ "pmlsd",	H(pmlsdhelp),	1, 1, 1, CMPL(r)	ls },
261	{ "preserve",	H(preservehelp),0, 0, 0, CMPL0		setpreserve },
262	{ "progress",	H(progresshelp),0, 0, 0, CMPL0		setprogress },
263	{ "prompt",	H(prompthelp),	0, 0, 0, CMPL0		setprompt },
264	{ "proxy",	H(proxyhelp),	0, 0, 1, CMPL(c)	doproxy },
265	{ "put",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
266	{ "pwd",	H(pwdhelp),	0, 1, 1, CMPL0		pwd },
267	{ "quit",	H(quithelp),	0, 0, 0, CMPL0		quit },
268	{ "quote",	H(quotehelp),	1, 1, 1, CMPL0		quote },
269	{ "rate",	H(ratehelp),	0, 0, 0, CMPL0		setrate },
270	{ "rcvbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
271	{ "recv",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
272	{ "reget",	H(regethelp),	1, 1, 1, CMPL(rl)	reget },
273	{ "remopts",	H(optshelp),	0, 1, 1, CMPL0		opts },
274	{ "rename",	H(renamehelp),	0, 1, 1, CMPL(rr)	renamefile },
275	{ "reset",	H(resethelp),	0, 1, 1, CMPL0		reset },
276	{ "restart",	H(restarthelp),	1, 1, 1, CMPL0		restart },
277	{ "rhelp",	H(remotehelp),	0, 1, 1, CMPL0		rmthelp },
278	{ "rmdir",	H(rmdirhelp),	0, 1, 1, CMPL(r)	removedir },
279	{ "rstatus",	H(rmtstatushelp),0, 1, 1, CMPL(r)	rmtstatus },
280	{ "runique",	H(runiquehelp),	0, 0, 1, CMPL0		setrunique },
281	{ "send",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
282	{ "sendport",	H(porthelp),	0, 0, 0, CMPL0		setport },
283	{ "set",	H(sethelp),	0, 0, 0, CMPL(o)	setoption },
284	{ "site",	H(sitehelp),	0, 1, 1, CMPL0		site },
285	{ "size",	H(sizecmdhelp),	1, 1, 1, CMPL(r)	sizecmd },
286	{ "sndbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
287	{ "status",	H(statushelp),	0, 0, 1, CMPL0		status },
288	{ "struct",	H(structhelp),	0, 1, 1, CMPL0		setstruct },
289	{ "sunique",	H(suniquehelp),	0, 0, 1, CMPL0		setsunique },
290	{ "system",	H(systemhelp),	0, 1, 1, CMPL0		syst },
291	{ "tenex",	H(tenexhelp),	0, 1, 1, CMPL0		settenex },
292	{ "throttle",	H(ratehelp),	0, 0, 0, CMPL0		setrate },
293	{ "trace",	H(tracehelp),	0, 0, 0, CMPL0		settrace },
294	{ "type",	H(typehelp),	0, 1, 1, CMPL0		settype },
295	{ "umask",	H(umaskhelp),	0, 1, 1, CMPL0		do_umask },
296	{ "unset",	H(unsethelp),	0, 0, 0, CMPL(o)	unsetoption },
297	{ "usage",	H(usagehelp),	0, 0, 1, CMPL(C)	help },
298	{ "user",	H(userhelp),	0, 1, 1, CMPL0		user },
299	{ "verbose",	H(verbosehelp),	0, 0, 0, CMPL0		setverbose },
300	{ "xferbuf",	H(xferbufhelp),	0, 0, 0, CMPL0		setxferbuf },
301	{ "?",		H(helphelp),	0, 0, 1, CMPL(C)	help },
302	{ NULL,		NULL,		0, 0, 0, CMPL0		NULL },
303};
304
305struct option optiontab[] = {
306	{ "anonpass",	NULL },
307	{ "ftp_proxy",	NULL },
308	{ "http_proxy",	NULL },
309	{ "no_proxy",	NULL },
310	{ "pager",	NULL },
311	{ "prompt",	NULL },
312	{ "rprompt",	NULL },
313	{ NULL,		NULL },
314};
315