1 /*	$OpenBSD: cmdtab.c,v 1.20 2006/04/25 05:45:20 tedu Exp $	*/
2 /*	$NetBSD: cmdtab.c,v 1.17 1997/08/18 10:20:17 lukem Exp $	*/
3 
4 /*
5  * Copyright (c) 1985, 1989, 1993, 1994
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  */
32 
33 #include <stdio.h>
34 #include "ftp_var.h"
35 
36 __RCSID("$MirOS: src/usr.bin/ftp/cmdtab.c,v 1.6 2013/09/15 11:01:28 tg Exp $");
37 
38 /*
39  * User FTP -- Command Tables.
40  */
41 
42 #ifndef SMALL
43 char	accounthelp[] =	"send account command to remote server";
44 char	appendhelp[] =	"append to a file";
45 char	asciihelp[] =	"set ascii transfer type";
46 char	beephelp[] =	"beep when command completed";
47 char	binaryhelp[] =	"set binary transfer type";
48 char	casehelp[] =	"toggle mget upper/lower case id mapping";
49 char	cdhelp[] =	"change remote working directory";
50 char	cduphelp[] =	"change remote working directory to parent directory";
51 char	chmodhelp[] =	"change file permissions of remote file";
52 char	connecthelp[] =	"connect to remote ftp server";
53 char	crhelp[] =	"toggle carriage return stripping on ascii gets";
54 char	debughelp[] =	"toggle/set debugging mode";
55 char	deletehelp[] =	"delete remote file";
56 char	dirhelp[] =	"list contents of remote directory";
57 char	disconhelp[] =	"terminate ftp session";
58 char	domachelp[] =	"execute macro";
59 char	edithelp[] =	"toggle command line editing";
60 char	epsv4help[] =	"toggle use of EPSV/EPRT on IPv4 ftp";
61 char	formhelp[] =	"set file transfer format";
62 char	gatehelp[] =	"toggle gate-ftp; specify host[:port] to change proxy";
63 char	globhelp[] =	"toggle metacharacter expansion of local file names";
64 char	hashhelp[] =	"toggle printing `#' marks; specify number to set size";
65 char	helphelp[] =	"print local help information";
66 char	idlehelp[] =	"get (set) idle timer on remote side";
67 char	lcdhelp[] =	"change local working directory";
68 char	lpwdhelp[] =	"print local working directory";
69 char	lshelp[] =	"list contents of remote directory";
70 char	macdefhelp[] =  "define a macro";
71 char	mdeletehelp[] =	"delete multiple files";
72 char	mdirhelp[] =	"list contents of multiple remote directories";
73 char	mgethelp[] =	"get multiple files";
74 char	mkdirhelp[] =	"make directory on the remote machine";
75 char	mlshelp[] =	"list contents of multiple remote directories";
76 char	modehelp[] =	"set file transfer mode";
77 char	modtimehelp[] = "show last modification time of remote file";
78 char	mputhelp[] =	"send multiple files";
79 char	newerhelp[] =	"get file if remote file is newer than local file ";
80 char	nlisthelp[] =	"nlist contents of remote directory";
81 char	nmaphelp[] =	"set templates for default file name mapping";
82 char	ntranshelp[] =	"set translation table for default file name mapping";
83 char	pagehelp[] =	"view a remote file through your pager";
84 char	passivehelp[] =	"toggle passive transfer mode";
85 char	porthelp[] =	"toggle use of PORT/LPRT cmd for each data connection";
86 char	preservehelp[] ="toggle preservation of modification time of "
87 			"retrieved files";
88 char	progresshelp[] ="toggle transfer progress meter";
89 char	prompthelp[] =	"toggle interactive prompting on multiple commands";
90 char	proxyhelp[] =	"issue command on alternate connection";
91 char	pwdhelp[] =	"print working directory on remote machine";
92 char	quithelp[] =	"terminate ftp session and exit";
93 char	quotehelp[] =	"send arbitrary ftp command";
94 char	receivehelp[] =	"receive file";
95 char	regethelp[] =	"get file restarting at end of local file";
96 char	remotehelp[] =	"get help from remote server";
97 char	renamehelp[] =	"rename file";
98 char	resethelp[] =	"clear queued command replies";
99 char	restarthelp[]=	"restart file transfer at bytecount";
100 char	rmdirhelp[] =	"remove directory on the remote machine";
101 char	rmtstatushelp[]="show status of remote machine";
102 char	runiquehelp[] = "toggle store unique for local files";
103 char	sendhelp[] =	"send one file";
104 char	shellhelp[] =	"escape to the shell";
105 char	sitehelp[] =	"send site specific command to remote server\n"
106 			"\t\tTry \"rhelp site\" or \"site help\" "
107 			"for more information";
108 char	sizecmdhelp[] = "show size of remote file";
109 char	statushelp[] =	"show current status";
110 char	structhelp[] =	"set file transfer structure";
111 char	suniquehelp[] = "toggle store unique on remote machine";
112 char	systemhelp[] =  "show remote system type";
113 char	tenexhelp[] =	"set tenex file transfer type";
114 char	tracehelp[] =	"toggle packet tracing";
115 char	typehelp[] =	"set file transfer type";
116 char	umaskhelp[] =	"get (set) umask on remote side";
117 char	userhelp[] =	"send new user information";
118 char	verbosehelp[] =	"toggle verbose mode";
119 #endif /* !SMALL */
120 
121 char	empty[] = "";
122 
123 #ifdef SMALL
124 #define CMPL(x)
125 #define CMPL0
126 #define H(x)	empty
127 #else  /* !SMALL */
128 #define CMPL(x)	__STRING(x),
129 #define CMPL0	"",
130 #define H(x)	x
131 #endif /* !SMALL */
132 
133 struct cmd cmdtab[] = {
134 	{ "!",		H(shellhelp),	0, 0, 0, CMPL0		shell },
135 	{ "$",		H(domachelp),	1, 0, 0, CMPL0		domacro },
136 	{ "account",	H(accounthelp),	0, 1, 1, CMPL0		account},
137 	{ "append",	H(appendhelp),	1, 1, 1, CMPL(lr)	put },
138 	{ "ascii",	H(asciihelp),	0, 1, 1, CMPL0		setascii },
139 	{ "bell",	H(beephelp),	0, 0, 0, CMPL0		setbell },
140 	{ "binary",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
141 	{ "bye",	H(quithelp),	0, 0, 0, CMPL0		quit },
142 	{ "case",	H(casehelp),	0, 0, 1, CMPL0		setcase },
143 	{ "cd",		H(cdhelp),	0, 1, 1, CMPL(r)	cd },
144 	{ "cdup",	H(cduphelp),	0, 1, 1, CMPL0		cdup },
145 	{ "chmod",	H(chmodhelp),	0, 1, 1, CMPL(nr)	do_chmod },
146 	{ "close",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
147 	{ "cr",		H(crhelp),	0, 0, 0, CMPL0		setcr },
148 	{ "debug",	H(debughelp),	0, 0, 0, CMPL0		setdebug },
149 	{ "delete",	H(deletehelp),	0, 1, 1, CMPL(r)	deletecmd },
150 	{ "dir",	H(dirhelp),	1, 1, 1, CMPL(rl)	ls },
151 	{ "disconnect",	H(disconhelp),	0, 1, 1, CMPL0		disconnect },
152 #ifndef SMALL
153 	{ "edit",	H(edithelp),	0, 0, 0, CMPL0		setedit },
154 #endif /* !SMALL */
155 	{ "epsv4",	H(epsv4help),	0, 0, 0, CMPL0		setepsv4 },
156 	{ "exit",	H(quithelp),	0, 0, 0, CMPL0		quit },
157 	{ "form",	H(formhelp),	0, 1, 1, CMPL0		setform },
158 	{ "ftp",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
159 	{ "get",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
160 	{ "gate",	H(gatehelp),	0, 0, 0, CMPL0		setgate },
161 	{ "glob",	H(globhelp),	0, 0, 0, CMPL0		setglob },
162 	{ "hash",	H(hashhelp),	0, 0, 0, CMPL0		sethash },
163 	{ "help",	H(helphelp),	0, 0, 1, CMPL(C)	help },
164 	{ "idle",	H(idlehelp),	0, 1, 1, CMPL0		idle },
165 	{ "image",	H(binaryhelp),	0, 1, 1, CMPL0		setbinary },
166 	{ "lcd",	H(lcdhelp),	0, 0, 0, CMPL(l)	lcd },
167 	{ "less",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
168 	{ "lpwd",	H(lpwdhelp),	0, 0, 0, CMPL0		lpwd },
169 	{ "ls",		H(lshelp),	1, 1, 1, CMPL(rl)	ls },
170 	{ "macdef",	H(macdefhelp),	0, 0, 0, CMPL0		macdef },
171 	{ "mdelete",	H(mdeletehelp),	1, 1, 1, CMPL(R)	mdelete },
172 	{ "mdir",	H(mdirhelp),	1, 1, 1, CMPL(R)	mls },
173 	{ "mget",	H(mgethelp),	1, 1, 1, CMPL(R)	mget },
174 	{ "mkdir",	H(mkdirhelp),	0, 1, 1, CMPL(r)	makedir },
175 	{ "mls",	H(mlshelp),	1, 1, 1, CMPL(R)	mls },
176 	{ "mode",	H(modehelp),	0, 1, 1, CMPL0		setftmode },
177 	{ "modtime",	H(modtimehelp),	0, 1, 1, CMPL(r)	modtime },
178 	{ "more",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
179 	{ "mput",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
180 	{ "msend",	H(mputhelp),	1, 1, 1, CMPL(L)	mput },
181 	{ "newer",	H(newerhelp),	1, 1, 1, CMPL(r)	newer },
182 	{ "nlist",	H(nlisthelp),	1, 1, 1, CMPL(rl)	ls },
183 	{ "nmap",	H(nmaphelp),	0, 0, 1, CMPL0		setnmap },
184 	{ "ntrans",	H(ntranshelp),	0, 0, 1, CMPL0		setntrans },
185 	{ "open",	H(connecthelp),	0, 0, 1, CMPL0		setpeer },
186 	{ "page",	H(pagehelp),	1, 1, 1, CMPL(r)	page },
187 	{ "passive",	H(passivehelp),	0, 0, 0, CMPL0		setpassive },
188 	{ "preserve",	H(preservehelp),0, 0, 0, CMPL0		setpreserve },
189 	{ "progress",	H(progresshelp),0, 0, 0, CMPL0		setprogress },
190 	{ "prompt",	H(prompthelp),	0, 0, 0, CMPL0		setprompt },
191 	{ "proxy",	H(proxyhelp),	0, 0, 1, CMPL(c)	doproxy },
192 	{ "put",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
193 	{ "pwd",	H(pwdhelp),	0, 1, 1, CMPL0		pwd },
194 	{ "quit",	H(quithelp),	0, 0, 0, CMPL0		quit },
195 	{ "quote",	H(quotehelp),	1, 1, 1, CMPL0		quote },
196 	{ "recv",	H(receivehelp),	1, 1, 1, CMPL(rl)	get },
197 	{ "reget",	H(regethelp),	1, 1, 1, CMPL(rl)	reget },
198 	{ "rename",	H(renamehelp),	0, 1, 1, CMPL(rr)	renamefile },
199 	{ "reset",	H(resethelp),	0, 1, 1, CMPL0		reset },
200 	{ "restart",	H(restarthelp),	1, 1, 1, CMPL0		restart },
201 	{ "rhelp",	H(remotehelp),	0, 1, 1, CMPL0		rmthelp },
202 	{ "rmdir",	H(rmdirhelp),	0, 1, 1, CMPL(r)	removedir },
203 	{ "rstatus",	H(rmtstatushelp),0, 1, 1, CMPL(r)	rmtstatus },
204 	{ "runique",	H(runiquehelp),	0, 0, 1, CMPL0		setrunique },
205 	{ "send",	H(sendhelp),	1, 1, 1, CMPL(lr)	put },
206 	{ "sendport",	H(porthelp),	0, 0, 0, CMPL0		setport },
207 	{ "site",	H(sitehelp),	0, 1, 1, CMPL0		site },
208 	{ "size",	H(sizecmdhelp),	1, 1, 1, CMPL(r)	sizecmd },
209 #ifndef SMALL
210 	{ "status",	H(statushelp),	0, 0, 1, CMPL0		status },
211 #endif /* !SMALL */
212 	{ "struct",	H(structhelp),	0, 1, 1, CMPL0		setstruct },
213 	{ "sunique",	H(suniquehelp),	0, 0, 1, CMPL0		setsunique },
214 	{ "system",	H(systemhelp),	0, 1, 1, CMPL0		syst },
215 #ifndef SMALL
216 	{ "tenex",	H(tenexhelp),	0, 1, 1, CMPL0		settenex },
217 #endif /* !SMALL */
218 	{ "trace",	H(tracehelp),	0, 0, 0, CMPL0		settrace },
219 	{ "type",	H(typehelp),	0, 1, 1, CMPL0		settype },
220 	{ "umask",	H(umaskhelp),	0, 1, 1, CMPL0		do_umask },
221 	{ "user",	H(userhelp),	0, 1, 1, CMPL0		user },
222 	{ "verbose",	H(verbosehelp),	0, 0, 0, CMPL0		setverbose },
223 	{ "?",		H(helphelp),	0, 0, 1, CMPL(C)	help },
224 	{ 0 }
225 };
226 
227 int	NCMDS = (sizeof(cmdtab) / sizeof(cmdtab[0])) - 1;
228