1 /* $OpenBSD: cmdtab.c,v 1.17 2003/12/16 21:46:22 deraadt 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 #if !defined(lint) && !defined(SMALL) 34 static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.17 2003/12/16 21:46:22 deraadt Exp $"; 35 #endif /* not lint and not SMALL */ 36 37 #include <stdio.h> 38 #include "ftp_var.h" 39 40 /* 41 * User FTP -- Command Tables. 42 */ 43 44 char accounthelp[] = "send account command to remote server"; 45 char appendhelp[] = "append to a file"; 46 char asciihelp[] = "set ascii transfer type"; 47 char beephelp[] = "beep when command completed"; 48 char binaryhelp[] = "set binary transfer type"; 49 char casehelp[] = "toggle mget upper/lower case id mapping"; 50 char cdhelp[] = "change remote working directory"; 51 char cduphelp[] = "change remote working directory to parent directory"; 52 char chmodhelp[] = "change file permissions of remote file"; 53 char connecthelp[] = "connect to remote ftp server"; 54 char crhelp[] = "toggle carriage return stripping on ascii gets"; 55 char debughelp[] = "toggle/set debugging mode"; 56 char deletehelp[] = "delete remote file"; 57 char dirhelp[] = "list contents of remote directory"; 58 char disconhelp[] = "terminate ftp session"; 59 char domachelp[] = "execute macro"; 60 #ifndef SMALL 61 char edithelp[] = "toggle command line editing"; 62 #endif /* !SMALL */ 63 char epsv4help[] = "toggle use of EPSV/EPRT on IPv4 ftp"; 64 char formhelp[] = "set file transfer format"; 65 char gatehelp[] = "toggle gate-ftp; specify host[:port] to change proxy"; 66 char globhelp[] = "toggle metacharacter expansion of local file names"; 67 char hashhelp[] = "toggle printing `#' marks; specify number to set size"; 68 char helphelp[] = "print local help information"; 69 char idlehelp[] = "get (set) idle timer on remote side"; 70 char lcdhelp[] = "change local working directory"; 71 char lpwdhelp[] = "print local working directory"; 72 char lshelp[] = "list contents of remote directory"; 73 char macdefhelp[] = "define a macro"; 74 char mdeletehelp[] = "delete multiple files"; 75 char mdirhelp[] = "list contents of multiple remote directories"; 76 char mgethelp[] = "get multiple files"; 77 char mkdirhelp[] = "make directory on the remote machine"; 78 char mlshelp[] = "list contents of multiple remote directories"; 79 char modehelp[] = "set file transfer mode"; 80 char modtimehelp[] = "show last modification time of remote file"; 81 char mputhelp[] = "send multiple files"; 82 char newerhelp[] = "get file if remote file is newer than local file "; 83 char nlisthelp[] = "nlist contents of remote directory"; 84 char nmaphelp[] = "set templates for default file name mapping"; 85 char ntranshelp[] = "set translation table for default file name mapping"; 86 char pagehelp[] = "view a remote file through your pager"; 87 char passivehelp[] = "toggle passive transfer mode"; 88 char porthelp[] = "toggle use of PORT/LPRT cmd for each data connection"; 89 char preservehelp[] ="toggle preservation of modification time of " 90 "retrieved files"; 91 char progresshelp[] ="toggle transfer progress meter"; 92 char prompthelp[] = "toggle interactive prompting on multiple commands"; 93 char proxyhelp[] = "issue command on alternate connection"; 94 char pwdhelp[] = "print working directory on remote machine"; 95 char quithelp[] = "terminate ftp session and exit"; 96 char quotehelp[] = "send arbitrary ftp command"; 97 char receivehelp[] = "receive file"; 98 char regethelp[] = "get file restarting at end of local file"; 99 char remotehelp[] = "get help from remote server"; 100 char renamehelp[] = "rename file"; 101 char resethelp[] = "clear queued command replies"; 102 char restarthelp[]= "restart file transfer at bytecount"; 103 char rmdirhelp[] = "remove directory on the remote machine"; 104 char rmtstatushelp[]="show status of remote machine"; 105 char runiquehelp[] = "toggle store unique for local files"; 106 char sendhelp[] = "send one file"; 107 char shellhelp[] = "escape to the shell"; 108 char sitehelp[] = "send site specific command to remote server\n" 109 "\t\tTry \"rhelp site\" or \"site help\" " 110 "for more information"; 111 char sizecmdhelp[] = "show size of remote file"; 112 char statushelp[] = "show current status"; 113 char structhelp[] = "set file transfer structure"; 114 char suniquehelp[] = "toggle store unique on remote machine"; 115 char systemhelp[] = "show remote system type"; 116 char tenexhelp[] = "set tenex file transfer type"; 117 char tracehelp[] = "toggle packet tracing"; 118 char typehelp[] = "set file transfer type"; 119 char umaskhelp[] = "get (set) umask on remote side"; 120 char userhelp[] = "send new user information"; 121 char verbosehelp[] = "toggle verbose mode"; 122 123 #ifdef SMALL 124 #define CMPL(x) 125 #define CMPL0 126 #else /* !SMALL */ 127 #define CMPL(x) __STRING(x), 128 #define CMPL0 "", 129 #endif /* !SMALL */ 130 131 struct cmd cmdtab[] = { 132 { "!", shellhelp, 0, 0, 0, CMPL0 shell }, 133 { "$", domachelp, 1, 0, 0, CMPL0 domacro }, 134 { "account", accounthelp, 0, 1, 1, CMPL0 account}, 135 { "append", appendhelp, 1, 1, 1, CMPL(lr) put }, 136 { "ascii", asciihelp, 0, 1, 1, CMPL0 setascii }, 137 { "bell", beephelp, 0, 0, 0, CMPL0 setbell }, 138 { "binary", binaryhelp, 0, 1, 1, CMPL0 setbinary }, 139 { "bye", quithelp, 0, 0, 0, CMPL0 quit }, 140 { "case", casehelp, 0, 0, 1, CMPL0 setcase }, 141 { "cd", cdhelp, 0, 1, 1, CMPL(r) cd }, 142 { "cdup", cduphelp, 0, 1, 1, CMPL0 cdup }, 143 { "chmod", chmodhelp, 0, 1, 1, CMPL(nr) do_chmod }, 144 { "close", disconhelp, 0, 1, 1, CMPL0 disconnect }, 145 { "cr", crhelp, 0, 0, 0, CMPL0 setcr }, 146 { "debug", debughelp, 0, 0, 0, CMPL0 setdebug }, 147 { "delete", deletehelp, 0, 1, 1, CMPL(r) delete }, 148 { "dir", dirhelp, 1, 1, 1, CMPL(rl) ls }, 149 { "disconnect", disconhelp, 0, 1, 1, CMPL0 disconnect }, 150 #ifndef SMALL 151 { "edit", edithelp, 0, 0, 0, CMPL0 setedit }, 152 #endif /* !SMALL */ 153 { "epsv4", epsv4help, 0, 0, 0, CMPL0 setepsv4 }, 154 { "exit", quithelp, 0, 0, 0, CMPL0 quit }, 155 { "form", formhelp, 0, 1, 1, CMPL0 setform }, 156 { "ftp", connecthelp, 0, 0, 1, CMPL0 setpeer }, 157 { "get", receivehelp, 1, 1, 1, CMPL(rl) get }, 158 { "gate", gatehelp, 0, 0, 0, CMPL0 setgate }, 159 { "glob", globhelp, 0, 0, 0, CMPL0 setglob }, 160 { "hash", hashhelp, 0, 0, 0, CMPL0 sethash }, 161 { "help", helphelp, 0, 0, 1, CMPL(C) help }, 162 { "idle", idlehelp, 0, 1, 1, CMPL0 idle }, 163 { "image", binaryhelp, 0, 1, 1, CMPL0 setbinary }, 164 { "lcd", lcdhelp, 0, 0, 0, CMPL(l) lcd }, 165 { "less", pagehelp, 1, 1, 1, CMPL(r) page }, 166 { "lpwd", lpwdhelp, 0, 0, 0, CMPL0 lpwd }, 167 { "ls", lshelp, 1, 1, 1, CMPL(rl) ls }, 168 { "macdef", macdefhelp, 0, 0, 0, CMPL0 macdef }, 169 { "mdelete", mdeletehelp, 1, 1, 1, CMPL(R) mdelete }, 170 { "mdir", mdirhelp, 1, 1, 1, CMPL(R) mls }, 171 { "mget", mgethelp, 1, 1, 1, CMPL(R) mget }, 172 { "mkdir", mkdirhelp, 0, 1, 1, CMPL(r) makedir }, 173 { "mls", mlshelp, 1, 1, 1, CMPL(R) mls }, 174 { "mode", modehelp, 0, 1, 1, CMPL0 setftmode }, 175 { "modtime", modtimehelp, 0, 1, 1, CMPL(r) modtime }, 176 { "more", pagehelp, 1, 1, 1, CMPL(r) page }, 177 { "mput", mputhelp, 1, 1, 1, CMPL(L) mput }, 178 { "msend", mputhelp, 1, 1, 1, CMPL(L) mput }, 179 { "newer", newerhelp, 1, 1, 1, CMPL(r) newer }, 180 { "nlist", nlisthelp, 1, 1, 1, CMPL(rl) ls }, 181 { "nmap", nmaphelp, 0, 0, 1, CMPL0 setnmap }, 182 { "ntrans", ntranshelp, 0, 0, 1, CMPL0 setntrans }, 183 { "open", connecthelp, 0, 0, 1, CMPL0 setpeer }, 184 { "page", pagehelp, 1, 1, 1, CMPL(r) page }, 185 { "passive", passivehelp, 0, 0, 0, CMPL0 setpassive }, 186 { "preserve", preservehelp, 0, 0, 0, CMPL0 setpreserve }, 187 { "progress", progresshelp, 0, 0, 0, CMPL0 setprogress }, 188 { "prompt", prompthelp, 0, 0, 0, CMPL0 setprompt }, 189 { "proxy", proxyhelp, 0, 0, 1, CMPL(c) doproxy }, 190 { "put", sendhelp, 1, 1, 1, CMPL(lr) put }, 191 { "pwd", pwdhelp, 0, 1, 1, CMPL0 pwd }, 192 { "quit", quithelp, 0, 0, 0, CMPL0 quit }, 193 { "quote", quotehelp, 1, 1, 1, CMPL0 quote }, 194 { "recv", receivehelp, 1, 1, 1, CMPL(rl) get }, 195 { "reget", regethelp, 1, 1, 1, CMPL(rl) reget }, 196 { "rename", renamehelp, 0, 1, 1, CMPL(rr) renamefile }, 197 { "reset", resethelp, 0, 1, 1, CMPL0 reset }, 198 { "restart", restarthelp, 1, 1, 1, CMPL0 restart }, 199 { "rhelp", remotehelp, 0, 1, 1, CMPL0 rmthelp }, 200 { "rmdir", rmdirhelp, 0, 1, 1, CMPL(r) removedir }, 201 { "rstatus", rmtstatushelp, 0, 1, 1, CMPL(r) rmtstatus }, 202 { "runique", runiquehelp, 0, 0, 1, CMPL0 setrunique }, 203 { "send", sendhelp, 1, 1, 1, CMPL(lr) put }, 204 { "sendport", porthelp, 0, 0, 0, CMPL0 setport }, 205 { "site", sitehelp, 0, 1, 1, CMPL0 site }, 206 { "size", sizecmdhelp, 1, 1, 1, CMPL(r) sizecmd }, 207 { "status", statushelp, 0, 0, 1, CMPL0 status }, 208 { "struct", structhelp, 0, 1, 1, CMPL0 setstruct }, 209 { "sunique", suniquehelp, 0, 0, 1, CMPL0 setsunique }, 210 { "system", systemhelp, 0, 1, 1, CMPL0 syst }, 211 { "tenex", tenexhelp, 0, 1, 1, CMPL0 settenex }, 212 { "trace", tracehelp, 0, 0, 0, CMPL0 settrace }, 213 { "type", typehelp, 0, 1, 1, CMPL0 settype }, 214 { "umask", umaskhelp, 0, 1, 1, CMPL0 do_umask }, 215 { "user", userhelp, 0, 1, 1, CMPL0 user }, 216 { "verbose", verbosehelp, 0, 0, 0, CMPL0 setverbose }, 217 { "?", helphelp, 0, 0, 1, CMPL(C) help }, 218 { 0 }, 219 }; 220 221 int NCMDS = (sizeof(cmdtab) / sizeof(cmdtab[0])) - 1; 222