main.c revision 1.74 1 1.74 lukem /* $NetBSD: main.c,v 1.74 2000/11/15 00:11:03 lukem Exp $ */
2 1.59 lukem
3 1.59 lukem /*-
4 1.70 lukem * Copyright (c) 1996-2000 The NetBSD Foundation, Inc.
5 1.59 lukem * All rights reserved.
6 1.59 lukem *
7 1.59 lukem * This code is derived from software contributed to The NetBSD Foundation
8 1.59 lukem * by Luke Mewburn.
9 1.59 lukem *
10 1.59 lukem * Redistribution and use in source and binary forms, with or without
11 1.59 lukem * modification, are permitted provided that the following conditions
12 1.59 lukem * are met:
13 1.59 lukem * 1. Redistributions of source code must retain the above copyright
14 1.59 lukem * notice, this list of conditions and the following disclaimer.
15 1.59 lukem * 2. Redistributions in binary form must reproduce the above copyright
16 1.59 lukem * notice, this list of conditions and the following disclaimer in the
17 1.59 lukem * documentation and/or other materials provided with the distribution.
18 1.59 lukem * 3. All advertising materials mentioning features or use of this software
19 1.59 lukem * must display the following acknowledgement:
20 1.59 lukem * This product includes software developed by the NetBSD
21 1.59 lukem * Foundation, Inc. and its contributors.
22 1.59 lukem * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.59 lukem * contributors may be used to endorse or promote products derived
24 1.59 lukem * from this software without specific prior written permission.
25 1.59 lukem *
26 1.59 lukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.59 lukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.59 lukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.59 lukem * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.59 lukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.59 lukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.59 lukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.59 lukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.59 lukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.59 lukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.59 lukem * POSSIBILITY OF SUCH DAMAGE.
37 1.59 lukem */
38 1.45 itojun
39 1.45 itojun /*
40 1.55 lukem * Copyright (c) 1985, 1989, 1993, 1994
41 1.55 lukem * The Regents of the University of California. All rights reserved.
42 1.55 lukem *
43 1.45 itojun * Redistribution and use in source and binary forms, with or without
44 1.45 itojun * modification, are permitted provided that the following conditions
45 1.45 itojun * are met:
46 1.45 itojun * 1. Redistributions of source code must retain the above copyright
47 1.45 itojun * notice, this list of conditions and the following disclaimer.
48 1.45 itojun * 2. Redistributions in binary form must reproduce the above copyright
49 1.45 itojun * notice, this list of conditions and the following disclaimer in the
50 1.45 itojun * documentation and/or other materials provided with the distribution.
51 1.55 lukem * 3. All advertising materials mentioning features or use of this software
52 1.55 lukem * must display the following acknowledgement:
53 1.55 lukem * This product includes software developed by the University of
54 1.55 lukem * California, Berkeley and its contributors.
55 1.55 lukem * 4. Neither the name of the University nor the names of its contributors
56 1.45 itojun * may be used to endorse or promote products derived from this software
57 1.45 itojun * without specific prior written permission.
58 1.55 lukem *
59 1.55 lukem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.45 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.45 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.55 lukem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.45 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.45 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.45 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.45 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.45 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.45 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.45 itojun * SUCH DAMAGE.
70 1.45 itojun */
71 1.12 lukem
72 1.1 cgd /*
73 1.55 lukem * Copyright (C) 1997 and 1998 WIDE Project.
74 1.55 lukem * All rights reserved.
75 1.55 lukem *
76 1.1 cgd * Redistribution and use in source and binary forms, with or without
77 1.1 cgd * modification, are permitted provided that the following conditions
78 1.1 cgd * are met:
79 1.1 cgd * 1. Redistributions of source code must retain the above copyright
80 1.1 cgd * notice, this list of conditions and the following disclaimer.
81 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
82 1.1 cgd * notice, this list of conditions and the following disclaimer in the
83 1.1 cgd * documentation and/or other materials provided with the distribution.
84 1.55 lukem * 3. Neither the name of the project nor the names of its contributors
85 1.1 cgd * may be used to endorse or promote products derived from this software
86 1.1 cgd * without specific prior written permission.
87 1.55 lukem *
88 1.55 lukem * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
89 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91 1.55 lukem * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
92 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
94 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
98 1.1 cgd * SUCH DAMAGE.
99 1.1 cgd */
100 1.1 cgd
101 1.23 lukem #include <sys/cdefs.h>
102 1.1 cgd #ifndef lint
103 1.23 lukem __COPYRIGHT("@(#) Copyright (c) 1985, 1989, 1993, 1994\n\
104 1.23 lukem The Regents of the University of California. All rights reserved.\n");
105 1.1 cgd #endif /* not lint */
106 1.1 cgd
107 1.1 cgd #ifndef lint
108 1.8 tls #if 0
109 1.8 tls static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 10/9/94";
110 1.8 tls #else
111 1.74 lukem __RCSID("$NetBSD: main.c,v 1.74 2000/11/15 00:11:03 lukem Exp $");
112 1.8 tls #endif
113 1.1 cgd #endif /* not lint */
114 1.1 cgd
115 1.1 cgd /*
116 1.1 cgd * FTP User Program -- Command Interface.
117 1.1 cgd */
118 1.3 cgd #include <sys/types.h>
119 1.1 cgd #include <sys/socket.h>
120 1.1 cgd
121 1.3 cgd #include <err.h>
122 1.61 lukem #include <errno.h>
123 1.1 cgd #include <netdb.h>
124 1.56 lukem #include <paths.h>
125 1.1 cgd #include <pwd.h>
126 1.3 cgd #include <stdio.h>
127 1.22 lukem #include <stdlib.h>
128 1.9 cgd #include <string.h>
129 1.3 cgd #include <unistd.h>
130 1.1 cgd
131 1.57 lukem #define GLOBAL /* force GLOBAL decls in ftp_var.h to be declared */
132 1.3 cgd #include "ftp_var.h"
133 1.1 cgd
134 1.65 lukem #define FTP_PROXY "ftp_proxy" /* env var with FTP proxy location */
135 1.65 lukem #define HTTP_PROXY "http_proxy" /* env var with HTTP proxy location */
136 1.65 lukem #define NO_PROXY "no_proxy" /* env var with list of non-proxied
137 1.35 lukem * hosts, comma or space separated */
138 1.35 lukem
139 1.70 lukem static void setupoption(char *, char *, char *);
140 1.70 lukem int main(int, char *[]);
141 1.23 lukem
142 1.3 cgd int
143 1.70 lukem main(int argc, char *argv[])
144 1.1 cgd {
145 1.64 lukem int ch, rval;
146 1.74 lukem struct passwd *pw;
147 1.71 lukem char *cp, *ep, *anonuser, *anonpass, *upload_path;
148 1.71 lukem int dumbterm, s, len, isupload;
149 1.1 cgd
150 1.45 itojun ftpport = "ftp";
151 1.45 itojun httpport = "http";
152 1.45 itojun gateport = NULL;
153 1.24 lukem cp = getenv("FTPSERVERPORT");
154 1.45 itojun if (cp != NULL)
155 1.45 itojun gateport = cp;
156 1.45 itojun else
157 1.45 itojun gateport = "ftpgate";
158 1.1 cgd doglob = 1;
159 1.1 cgd interactive = 1;
160 1.1 cgd autologin = 1;
161 1.31 lukem passivemode = 1;
162 1.31 lukem activefallback = 1;
163 1.13 lukem preserve = 1;
164 1.17 lukem verbose = 0;
165 1.17 lukem progress = 0;
166 1.24 lukem gatemode = 0;
167 1.57 lukem data = -1;
168 1.39 lukem outfile = NULL;
169 1.39 lukem restartautofetch = 0;
170 1.43 cgd #ifndef NO_EDITCOMPLETE
171 1.18 lukem editing = 0;
172 1.21 lukem el = NULL;
173 1.21 lukem hist = NULL;
174 1.18 lukem #endif
175 1.60 lukem bytes = 0;
176 1.12 lukem mark = HASHBYTES;
177 1.44 lukem rate_get = 0;
178 1.44 lukem rate_get_incr = DEFAULTINCR;
179 1.44 lukem rate_put = 0;
180 1.44 lukem rate_put_incr = DEFAULTINCR;
181 1.49 lukem #ifdef INET6
182 1.47 itojun epsv4 = 1;
183 1.49 lukem #else
184 1.49 lukem epsv4 = 0;
185 1.49 lukem #endif
186 1.58 lukem epsv4bad = 0;
187 1.71 lukem upload_path = NULL;
188 1.71 lukem isupload = 0;
189 1.73 lukem reply_callback = NULL;
190 1.50 lukem
191 1.74 lukem netrc[0] = '\0';
192 1.74 lukem cp = getenv("NETRC");
193 1.74 lukem if (cp != NULL && strlcpy(netrc, cp, sizeof(netrc)) >= sizeof(netrc))
194 1.74 lukem errx(1, "$NETRC `%s': %s", cp, strerror(ENAMETOOLONG));
195 1.74 lukem
196 1.50 lukem /*
197 1.50 lukem * Get the default socket buffer sizes if we don't already have them.
198 1.50 lukem * It doesn't matter which socket we do this to, because on the first
199 1.50 lukem * call no socket buffer sizes will have been modified, so we are
200 1.50 lukem * guaranteed to get the system defaults.
201 1.50 lukem */
202 1.50 lukem s = socket(AF_INET, SOCK_STREAM, 0);
203 1.50 lukem if (s == -1)
204 1.50 lukem err(1, "can't create socket");
205 1.51 lukem len = sizeof(rcvbuf_size);
206 1.51 lukem if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, (void *) &rcvbuf_size, &len)
207 1.51 lukem < 0)
208 1.51 lukem err(1, "unable to get default rcvbuf size");
209 1.50 lukem len = sizeof(sndbuf_size);
210 1.50 lukem if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size, &len)
211 1.50 lukem < 0)
212 1.50 lukem err(1, "unable to get default sndbuf size");
213 1.51 lukem (void)close(s);
214 1.51 lukem /* sanity check returned buffer sizes */
215 1.51 lukem if (rcvbuf_size <= 0)
216 1.51 lukem rcvbuf_size = 8192;
217 1.51 lukem if (sndbuf_size <= 0)
218 1.51 lukem sndbuf_size = 8192;
219 1.44 lukem
220 1.69 lukem marg_sl = xsl_init();
221 1.25 lukem if ((tmpdir = getenv("TMPDIR")) == NULL)
222 1.25 lukem tmpdir = _PATH_TMP;
223 1.3 cgd
224 1.31 lukem /* Set default operation mode based on FTPMODE environment variable */
225 1.31 lukem if ((cp = getenv("FTPMODE")) != NULL) {
226 1.65 lukem if (strcasecmp(cp, "passive") == 0) {
227 1.31 lukem passivemode = 1;
228 1.31 lukem activefallback = 0;
229 1.65 lukem } else if (strcasecmp(cp, "active") == 0) {
230 1.31 lukem passivemode = 0;
231 1.31 lukem activefallback = 0;
232 1.65 lukem } else if (strcasecmp(cp, "gate") == 0) {
233 1.31 lukem gatemode = 1;
234 1.65 lukem } else if (strcasecmp(cp, "auto") == 0) {
235 1.31 lukem passivemode = 1;
236 1.31 lukem activefallback = 1;
237 1.31 lukem } else
238 1.31 lukem warnx("unknown $FTPMODE '%s'; using defaults", cp);
239 1.31 lukem }
240 1.31 lukem
241 1.32 lukem if (strcmp(__progname, "pftp") == 0) {
242 1.15 lukem passivemode = 1;
243 1.31 lukem activefallback = 0;
244 1.32 lukem } else if (strcmp(__progname, "gate-ftp") == 0)
245 1.24 lukem gatemode = 1;
246 1.24 lukem
247 1.24 lukem gateserver = getenv("FTPSERVER");
248 1.24 lukem if (gateserver == NULL || *gateserver == '\0')
249 1.24 lukem gateserver = GATE_SERVER;
250 1.24 lukem if (gatemode) {
251 1.24 lukem if (*gateserver == '\0') {
252 1.24 lukem warnx(
253 1.42 lukem "Neither $FTPSERVER nor GATE_SERVER is defined; disabling gate-ftp");
254 1.24 lukem gatemode = 0;
255 1.24 lukem }
256 1.24 lukem }
257 1.15 lukem
258 1.22 lukem cp = getenv("TERM");
259 1.22 lukem if (cp == NULL || strcmp(cp, "dumb") == 0)
260 1.22 lukem dumbterm = 1;
261 1.22 lukem else
262 1.22 lukem dumbterm = 0;
263 1.17 lukem fromatty = isatty(fileno(stdin));
264 1.37 lukem ttyout = stdout;
265 1.37 lukem if (isatty(fileno(ttyout))) {
266 1.41 lukem verbose = 1; /* verbose if to a tty */
267 1.37 lukem if (! dumbterm) {
268 1.43 cgd #ifndef NO_EDITCOMPLETE
269 1.41 lukem if (fromatty) /* editing mode on if tty is usable */
270 1.41 lukem editing = 1;
271 1.43 cgd #endif
272 1.43 cgd #ifndef NO_PROGRESS
273 1.37 lukem if (foregroundproc())
274 1.37 lukem progress = 1; /* progress bar on if fg */
275 1.43 cgd #endif
276 1.37 lukem }
277 1.18 lukem }
278 1.17 lukem
279 1.74 lukem while ((ch = getopt(argc, argv, "AadefginN:o:pP:r:RtT:u:vV")) != -1) {
280 1.6 mycroft switch (ch) {
281 1.31 lukem case 'A':
282 1.31 lukem activefallback = 0;
283 1.31 lukem passivemode = 0;
284 1.31 lukem break;
285 1.31 lukem
286 1.12 lukem case 'a':
287 1.12 lukem anonftp = 1;
288 1.12 lukem break;
289 1.12 lukem
290 1.3 cgd case 'd':
291 1.3 cgd options |= SO_DEBUG;
292 1.3 cgd debug++;
293 1.3 cgd break;
294 1.12 lukem
295 1.18 lukem case 'e':
296 1.43 cgd #ifndef NO_EDITCOMPLETE
297 1.18 lukem editing = 0;
298 1.18 lukem #endif
299 1.18 lukem break;
300 1.18 lukem
301 1.36 lukem case 'f':
302 1.36 lukem flushcache = 1;
303 1.36 lukem break;
304 1.36 lukem
305 1.3 cgd case 'g':
306 1.3 cgd doglob = 0;
307 1.3 cgd break;
308 1.1 cgd
309 1.3 cgd case 'i':
310 1.3 cgd interactive = 0;
311 1.3 cgd break;
312 1.1 cgd
313 1.3 cgd case 'n':
314 1.3 cgd autologin = 0;
315 1.3 cgd break;
316 1.1 cgd
317 1.74 lukem case 'N':
318 1.74 lukem if (strlcpy(netrc, optarg, sizeof(netrc))
319 1.74 lukem >= sizeof(netrc))
320 1.74 lukem errx(1, "%s: %s", optarg,
321 1.74 lukem strerror(ENAMETOOLONG));
322 1.74 lukem break;
323 1.74 lukem
324 1.31 lukem case 'o':
325 1.31 lukem outfile = optarg;
326 1.31 lukem if (strcmp(outfile, "-") == 0)
327 1.31 lukem ttyout = stderr;
328 1.31 lukem break;
329 1.31 lukem
330 1.12 lukem case 'p':
331 1.12 lukem passivemode = 1;
332 1.31 lukem activefallback = 0;
333 1.12 lukem break;
334 1.12 lukem
335 1.12 lukem case 'P':
336 1.45 itojun ftpport = optarg;
337 1.12 lukem break;
338 1.12 lukem
339 1.31 lukem case 'r':
340 1.31 lukem retry_connect = strtol(optarg, &ep, 10);
341 1.39 lukem if (retry_connect < 1 || *ep != '\0')
342 1.31 lukem errx(1, "bad retry value: %s", optarg);
343 1.31 lukem break;
344 1.31 lukem
345 1.39 lukem case 'R':
346 1.39 lukem restartautofetch = 1;
347 1.39 lukem break;
348 1.39 lukem
349 1.3 cgd case 't':
350 1.17 lukem trace = 1;
351 1.3 cgd break;
352 1.1 cgd
353 1.44 lukem case 'T':
354 1.44 lukem {
355 1.44 lukem int targc;
356 1.44 lukem char *targv[6], *oac;
357 1.44 lukem
358 1.44 lukem /* look for `dir,max[,incr]' */
359 1.44 lukem targc = 0;
360 1.44 lukem targv[targc++] = "-T";
361 1.44 lukem oac = xstrdup(optarg);
362 1.44 lukem
363 1.44 lukem while ((cp = strsep(&oac, ",")) != NULL) {
364 1.44 lukem if (*cp == '\0') {
365 1.44 lukem warnx("bad throttle value: %s", optarg);
366 1.44 lukem usage();
367 1.44 lukem /* NOTREACHED */
368 1.44 lukem }
369 1.44 lukem targv[targc++] = cp;
370 1.44 lukem if (targc >= 5)
371 1.44 lukem break;
372 1.44 lukem }
373 1.44 lukem if (parserate(targc, targv, 1) == -1)
374 1.44 lukem usage();
375 1.44 lukem free(oac);
376 1.44 lukem break;
377 1.44 lukem }
378 1.44 lukem
379 1.71 lukem case 'u':
380 1.71 lukem {
381 1.71 lukem isupload = 1;
382 1.71 lukem interactive = 0;
383 1.71 lukem upload_path = xstrdup(optarg);
384 1.71 lukem
385 1.71 lukem break;
386 1.71 lukem }
387 1.71 lukem
388 1.3 cgd case 'v':
389 1.37 lukem progress = verbose = 1;
390 1.17 lukem break;
391 1.17 lukem
392 1.17 lukem case 'V':
393 1.37 lukem progress = verbose = 0;
394 1.3 cgd break;
395 1.1 cgd
396 1.3 cgd default:
397 1.14 lukem usage();
398 1.3 cgd }
399 1.1 cgd }
400 1.37 lukem /* set line buffering on ttyout */
401 1.37 lukem setvbuf(ttyout, NULL, _IOLBF, 0);
402 1.3 cgd argc -= optind;
403 1.3 cgd argv += optind;
404 1.3 cgd
405 1.1 cgd cpend = 0; /* no pending replies */
406 1.1 cgd proxy = 0; /* proxy not active */
407 1.1 cgd crflag = 1; /* strip c.r. on ascii gets */
408 1.1 cgd sendport = -1; /* not using ports */
409 1.74 lukem
410 1.1 cgd /*
411 1.74 lukem * Cache the user name and home directory.
412 1.1 cgd */
413 1.74 lukem localhome = NULL;
414 1.74 lukem localname = NULL;
415 1.74 lukem anonuser = "anonymous";
416 1.74 lukem cp = getenv("HOME");
417 1.74 lukem if (! EMPTYSTRING(cp))
418 1.74 lukem localhome = xstrdup(cp);
419 1.74 lukem pw = NULL;
420 1.1 cgd cp = getlogin();
421 1.65 lukem if (cp != NULL)
422 1.1 cgd pw = getpwnam(cp);
423 1.1 cgd if (pw == NULL)
424 1.1 cgd pw = getpwuid(getuid());
425 1.65 lukem if (pw != NULL) {
426 1.74 lukem if (localhome == NULL && !EMPTYSTRING(pw->pw_dir))
427 1.74 lukem localhome = xstrdup(pw->pw_dir);
428 1.74 lukem localname = xstrdup(pw->pw_name);
429 1.74 lukem anonuser = localname;
430 1.74 lukem }
431 1.74 lukem if (netrc[0] == '\0' && localhome != NULL) {
432 1.74 lukem if (strlcpy(netrc, localhome, sizeof(netrc)) >= sizeof(netrc) ||
433 1.74 lukem strlcat(netrc, "/.netrc", sizeof(netrc)) >= sizeof(netrc)) {
434 1.74 lukem warnx("%s/.netrc: %s", localhome,
435 1.74 lukem strerror(ENAMETOOLONG));
436 1.74 lukem netrc[0] = '\0';
437 1.74 lukem }
438 1.65 lukem }
439 1.74 lukem if (localhome == NULL)
440 1.74 lukem localhome = xstrdup("/");
441 1.65 lukem
442 1.65 lukem /*
443 1.65 lukem * Every anonymous FTP server I've encountered will accept the
444 1.65 lukem * string "username@", and will append the hostname itself. We
445 1.65 lukem * do this by default since many servers are picky about not
446 1.65 lukem * having a FQDN in the anonymous password.
447 1.65 lukem * - thorpej (at) netbsd.org
448 1.65 lukem */
449 1.65 lukem len = strlen(anonuser) + 2;
450 1.65 lukem anonpass = xmalloc(len);
451 1.65 lukem (void)strlcpy(anonpass, anonuser, len);
452 1.65 lukem (void)strlcat(anonpass, "@", len);
453 1.65 lukem
454 1.67 lukem /*
455 1.67 lukem * set all the defaults for options defined in
456 1.67 lukem * struct option optiontab[] declared in cmdtab.c
457 1.67 lukem */
458 1.65 lukem setupoption("anonpass", getenv("FTPANONPASS"), anonpass);
459 1.66 lukem setupoption("ftp_proxy", getenv(FTP_PROXY), "");
460 1.66 lukem setupoption("http_proxy", getenv(HTTP_PROXY), "");
461 1.66 lukem setupoption("no_proxy", getenv(NO_PROXY), "");
462 1.66 lukem setupoption("pager", getenv("PAGER"), DEFAULTPAGER);
463 1.67 lukem setupoption("prompt", getenv("FTPPROMPT"), DEFAULTPROMPT);
464 1.67 lukem setupoption("rprompt", getenv("FTPRPROMPT"), DEFAULTRPROMPT);
465 1.66 lukem
466 1.66 lukem free(anonpass);
467 1.12 lukem
468 1.17 lukem setttywidth(0);
469 1.60 lukem #ifdef SIGINFO
470 1.60 lukem (void)xsignal(SIGINFO, psummary);
471 1.60 lukem #endif
472 1.60 lukem (void)xsignal(SIGQUIT, psummary);
473 1.44 lukem (void)xsignal(SIGUSR1, crankrate);
474 1.44 lukem (void)xsignal(SIGUSR2, crankrate);
475 1.60 lukem (void)xsignal(SIGWINCH, setttywidth);
476 1.23 lukem
477 1.31 lukem #ifdef __GNUC__ /* to shut up gcc warnings */
478 1.23 lukem (void)&argc;
479 1.23 lukem (void)&argv;
480 1.23 lukem #endif
481 1.17 lukem
482 1.1 cgd if (argc > 0) {
483 1.71 lukem if (isupload) {
484 1.71 lukem rval = auto_put(argc, argv, upload_path);
485 1.71 lukem exit(rval);
486 1.71 lukem } else if (strchr(argv[0], ':') != NULL
487 1.71 lukem && ! isipv6addr(argv[0])) {
488 1.39 lukem rval = auto_fetch(argc, argv);
489 1.16 lukem if (rval >= 0) /* -1 == connected and cd-ed */
490 1.16 lukem exit(rval);
491 1.16 lukem } else {
492 1.68 lukem char *xargv[4], *user, *host;
493 1.3 cgd
494 1.61 lukem if (sigsetjmp(toplevel, 1))
495 1.16 lukem exit(0);
496 1.61 lukem (void)xsignal(SIGINT, intr);
497 1.65 lukem (void)xsignal(SIGPIPE, lostpeer);
498 1.68 lukem user = NULL;
499 1.68 lukem host = argv[0];
500 1.68 lukem cp = strchr(host, '@');
501 1.68 lukem if (cp) {
502 1.68 lukem *cp = '\0';
503 1.68 lukem user = host;
504 1.68 lukem host = cp + 1;
505 1.68 lukem }
506 1.16 lukem xargv[0] = __progname;
507 1.68 lukem xargv[1] = host;
508 1.16 lukem xargv[2] = argv[1];
509 1.68 lukem xargv[3] = NULL;
510 1.31 lukem do {
511 1.68 lukem int oautologin;
512 1.68 lukem
513 1.68 lukem oautologin = autologin;
514 1.68 lukem if (user != NULL) {
515 1.68 lukem anonftp = 0;
516 1.68 lukem autologin = 0;
517 1.68 lukem }
518 1.31 lukem setpeer(argc+1, xargv);
519 1.68 lukem autologin = oautologin;
520 1.68 lukem if (connected == 1 && user != NULL)
521 1.68 lukem (void)ftp_login(host, user, NULL);
522 1.31 lukem if (!retry_connect)
523 1.31 lukem break;
524 1.31 lukem if (!connected) {
525 1.31 lukem macnum = 0;
526 1.31 lukem fprintf(ttyout,
527 1.31 lukem "Retrying in %d seconds...\n",
528 1.31 lukem retry_connect);
529 1.31 lukem sleep(retry_connect);
530 1.31 lukem }
531 1.31 lukem } while (!connected);
532 1.31 lukem retry_connect = 0; /* connected, stop hiding msgs */
533 1.16 lukem }
534 1.1 cgd }
535 1.71 lukem if (isupload)
536 1.71 lukem usage();
537 1.71 lukem
538 1.43 cgd #ifndef NO_EDITCOMPLETE
539 1.21 lukem controlediting();
540 1.43 cgd #endif /* !NO_EDITCOMPLETE */
541 1.64 lukem
542 1.64 lukem (void)sigsetjmp(toplevel, 1);
543 1.64 lukem (void)xsignal(SIGINT, intr);
544 1.65 lukem (void)xsignal(SIGPIPE, lostpeer);
545 1.64 lukem for (;;)
546 1.64 lukem cmdscanner();
547 1.1 cgd }
548 1.1 cgd
549 1.3 cgd /*
550 1.16 lukem * Generate a prompt
551 1.16 lukem */
552 1.3 cgd char *
553 1.70 lukem prompt(void)
554 1.1 cgd {
555 1.66 lukem static char **prompt;
556 1.66 lukem static char buf[MAXPATHLEN];
557 1.66 lukem
558 1.66 lukem if (prompt == NULL) {
559 1.66 lukem struct option *o;
560 1.66 lukem
561 1.66 lukem o = getoption("prompt");
562 1.66 lukem if (o == NULL)
563 1.66 lukem errx(1, "no such option `prompt'");
564 1.66 lukem prompt = &(o->value);
565 1.66 lukem }
566 1.67 lukem formatbuf(buf, sizeof(buf), *prompt ? *prompt : DEFAULTPROMPT);
567 1.67 lukem return (buf);
568 1.67 lukem }
569 1.67 lukem
570 1.67 lukem /*
571 1.67 lukem * Generate an rprompt
572 1.67 lukem */
573 1.67 lukem char *
574 1.70 lukem rprompt(void)
575 1.67 lukem {
576 1.67 lukem static char **rprompt;
577 1.67 lukem static char buf[MAXPATHLEN];
578 1.67 lukem
579 1.67 lukem if (rprompt == NULL) {
580 1.67 lukem struct option *o;
581 1.66 lukem
582 1.67 lukem o = getoption("rprompt");
583 1.67 lukem if (o == NULL)
584 1.67 lukem errx(1, "no such option `rprompt'");
585 1.67 lukem rprompt = &(o->value);
586 1.66 lukem }
587 1.67 lukem formatbuf(buf, sizeof(buf), *rprompt ? *rprompt : DEFAULTRPROMPT);
588 1.66 lukem return (buf);
589 1.1 cgd }
590 1.3 cgd
591 1.1 cgd /*
592 1.1 cgd * Command parser.
593 1.1 cgd */
594 1.3 cgd void
595 1.70 lukem cmdscanner(void)
596 1.1 cgd {
597 1.67 lukem struct cmd *c;
598 1.67 lukem char *p;
599 1.67 lukem int num;
600 1.1 cgd
601 1.1 cgd for (;;) {
602 1.43 cgd #ifndef NO_EDITCOMPLETE
603 1.16 lukem if (!editing) {
604 1.43 cgd #endif /* !NO_EDITCOMPLETE */
605 1.16 lukem if (fromatty) {
606 1.31 lukem fputs(prompt(), ttyout);
607 1.67 lukem p = rprompt();
608 1.67 lukem if (*p)
609 1.67 lukem fprintf(ttyout, "%s ", p);
610 1.31 lukem (void)fflush(ttyout);
611 1.16 lukem }
612 1.63 lukem if (fgets(line, sizeof(line), stdin) == NULL) {
613 1.63 lukem if (fromatty)
614 1.63 lukem putc('\n', ttyout);
615 1.73 lukem quit(0, NULL);
616 1.63 lukem }
617 1.16 lukem num = strlen(line);
618 1.16 lukem if (num == 0)
619 1.16 lukem break;
620 1.16 lukem if (line[--num] == '\n') {
621 1.16 lukem if (num == 0)
622 1.16 lukem break;
623 1.16 lukem line[num] = '\0';
624 1.16 lukem } else if (num == sizeof(line) - 2) {
625 1.31 lukem fputs("sorry, input line too long.\n", ttyout);
626 1.16 lukem while ((num = getchar()) != '\n' && num != EOF)
627 1.16 lukem /* void */;
628 1.16 lukem break;
629 1.16 lukem } /* else it was a line without a newline */
630 1.43 cgd #ifndef NO_EDITCOMPLETE
631 1.17 lukem } else {
632 1.16 lukem const char *buf;
633 1.26 christos HistEvent ev;
634 1.16 lukem cursor_pos = NULL;
635 1.16 lukem
636 1.63 lukem if ((buf = el_gets(el, &num)) == NULL || num == 0) {
637 1.63 lukem if (fromatty)
638 1.63 lukem putc('\n', ttyout);
639 1.73 lukem quit(0, NULL);
640 1.63 lukem }
641 1.40 lukem if (buf[--num] == '\n') {
642 1.16 lukem if (num == 0)
643 1.16 lukem break;
644 1.16 lukem } else if (num >= sizeof(line)) {
645 1.31 lukem fputs("sorry, input line too long.\n", ttyout);
646 1.1 cgd break;
647 1.16 lukem }
648 1.16 lukem memcpy(line, buf, num);
649 1.16 lukem line[num] = '\0';
650 1.26 christos history(hist, &ev, H_ENTER, buf);
651 1.16 lukem }
652 1.43 cgd #endif /* !NO_EDITCOMPLETE */
653 1.16 lukem
654 1.1 cgd makeargv();
655 1.16 lukem if (margc == 0)
656 1.1 cgd continue;
657 1.1 cgd c = getcmd(margv[0]);
658 1.1 cgd if (c == (struct cmd *)-1) {
659 1.31 lukem fputs("?Ambiguous command.\n", ttyout);
660 1.1 cgd continue;
661 1.1 cgd }
662 1.30 lukem if (c == NULL) {
663 1.43 cgd #if !defined(NO_EDITCOMPLETE)
664 1.30 lukem /*
665 1.30 lukem * attempt to el_parse() unknown commands.
666 1.30 lukem * any command containing a ':' would be parsed
667 1.30 lukem * as "[prog:]cmd ...", and will result in a
668 1.30 lukem * false positive if prog != "ftp", so treat
669 1.30 lukem * such commands as invalid.
670 1.30 lukem */
671 1.38 lukem if (strchr(margv[0], ':') != NULL ||
672 1.30 lukem el_parse(el, margc, margv) != 0)
673 1.43 cgd #endif /* !NO_EDITCOMPLETE */
674 1.31 lukem fputs("?Invalid command.\n", ttyout);
675 1.1 cgd continue;
676 1.1 cgd }
677 1.1 cgd if (c->c_conn && !connected) {
678 1.31 lukem fputs("Not connected.\n", ttyout);
679 1.1 cgd continue;
680 1.1 cgd }
681 1.13 lukem confirmrest = 0;
682 1.1 cgd (*c->c_handler)(margc, margv);
683 1.1 cgd if (bell && c->c_bell)
684 1.31 lukem (void)putc('\007', ttyout);
685 1.1 cgd if (c->c_handler != help)
686 1.1 cgd break;
687 1.1 cgd }
688 1.61 lukem (void)xsignal(SIGINT, intr);
689 1.65 lukem (void)xsignal(SIGPIPE, lostpeer);
690 1.1 cgd }
691 1.1 cgd
692 1.1 cgd struct cmd *
693 1.70 lukem getcmd(const char *name)
694 1.1 cgd {
695 1.13 lukem const char *p, *q;
696 1.3 cgd struct cmd *c, *found;
697 1.3 cgd int nmatches, longest;
698 1.11 pk
699 1.11 pk if (name == NULL)
700 1.11 pk return (0);
701 1.1 cgd
702 1.1 cgd longest = 0;
703 1.1 cgd nmatches = 0;
704 1.1 cgd found = 0;
705 1.12 lukem for (c = cmdtab; (p = c->c_name) != NULL; c++) {
706 1.1 cgd for (q = name; *q == *p++; q++)
707 1.1 cgd if (*q == 0) /* exact match? */
708 1.1 cgd return (c);
709 1.1 cgd if (!*q) { /* the name was a prefix */
710 1.1 cgd if (q - name > longest) {
711 1.1 cgd longest = q - name;
712 1.1 cgd nmatches = 1;
713 1.1 cgd found = c;
714 1.1 cgd } else if (q - name == longest)
715 1.1 cgd nmatches++;
716 1.1 cgd }
717 1.1 cgd }
718 1.1 cgd if (nmatches > 1)
719 1.1 cgd return ((struct cmd *)-1);
720 1.1 cgd return (found);
721 1.1 cgd }
722 1.1 cgd
723 1.1 cgd /*
724 1.1 cgd * Slice a string up into argc/argv.
725 1.1 cgd */
726 1.1 cgd
727 1.1 cgd int slrflag;
728 1.1 cgd
729 1.3 cgd void
730 1.70 lukem makeargv(void)
731 1.1 cgd {
732 1.16 lukem char *argp;
733 1.1 cgd
734 1.1 cgd stringbase = line; /* scan from first of buffer */
735 1.1 cgd argbase = argbuf; /* store from first of buffer */
736 1.1 cgd slrflag = 0;
737 1.16 lukem marg_sl->sl_cur = 0; /* reset to start of marg_sl */
738 1.10 pk for (margc = 0; ; margc++) {
739 1.16 lukem argp = slurpstring();
740 1.69 lukem xsl_add(marg_sl, argp);
741 1.16 lukem if (argp == NULL)
742 1.10 pk break;
743 1.10 pk }
744 1.43 cgd #ifndef NO_EDITCOMPLETE
745 1.16 lukem if (cursor_pos == line) {
746 1.16 lukem cursor_argc = 0;
747 1.16 lukem cursor_argo = 0;
748 1.16 lukem } else if (cursor_pos != NULL) {
749 1.16 lukem cursor_argc = margc;
750 1.16 lukem cursor_argo = strlen(margv[margc-1]);
751 1.16 lukem }
752 1.43 cgd #endif /* !NO_EDITCOMPLETE */
753 1.16 lukem }
754 1.10 pk
755 1.43 cgd #ifdef NO_EDITCOMPLETE
756 1.65 lukem #define INC_CHKCURSOR(x) (x)++
757 1.43 cgd #else /* !NO_EDITCOMPLETE */
758 1.65 lukem #define INC_CHKCURSOR(x) { (x)++ ; \
759 1.16 lukem if (x == cursor_pos) { \
760 1.16 lukem cursor_argc = margc; \
761 1.16 lukem cursor_argo = ap-argbase; \
762 1.16 lukem cursor_pos = NULL; \
763 1.16 lukem } }
764 1.38 lukem
765 1.43 cgd #endif /* !NO_EDITCOMPLETE */
766 1.1 cgd
767 1.1 cgd /*
768 1.1 cgd * Parse string into argbuf;
769 1.1 cgd * implemented with FSM to
770 1.1 cgd * handle quoting and strings
771 1.1 cgd */
772 1.1 cgd char *
773 1.70 lukem slurpstring(void)
774 1.1 cgd {
775 1.1 cgd int got_one = 0;
776 1.3 cgd char *sb = stringbase;
777 1.3 cgd char *ap = argbase;
778 1.1 cgd char *tmp = argbase; /* will return this if token found */
779 1.1 cgd
780 1.1 cgd if (*sb == '!' || *sb == '$') { /* recognize ! as a token for shell */
781 1.1 cgd switch (slrflag) { /* and $ as token for macro invoke */
782 1.1 cgd case 0:
783 1.1 cgd slrflag++;
784 1.16 lukem INC_CHKCURSOR(stringbase);
785 1.1 cgd return ((*sb == '!') ? "!" : "$");
786 1.1 cgd /* NOTREACHED */
787 1.1 cgd case 1:
788 1.1 cgd slrflag++;
789 1.1 cgd altarg = stringbase;
790 1.1 cgd break;
791 1.1 cgd default:
792 1.1 cgd break;
793 1.1 cgd }
794 1.1 cgd }
795 1.1 cgd
796 1.1 cgd S0:
797 1.1 cgd switch (*sb) {
798 1.1 cgd
799 1.1 cgd case '\0':
800 1.1 cgd goto OUT;
801 1.1 cgd
802 1.1 cgd case ' ':
803 1.1 cgd case '\t':
804 1.16 lukem INC_CHKCURSOR(sb);
805 1.16 lukem goto S0;
806 1.1 cgd
807 1.1 cgd default:
808 1.1 cgd switch (slrflag) {
809 1.1 cgd case 0:
810 1.1 cgd slrflag++;
811 1.1 cgd break;
812 1.1 cgd case 1:
813 1.1 cgd slrflag++;
814 1.1 cgd altarg = sb;
815 1.1 cgd break;
816 1.1 cgd default:
817 1.1 cgd break;
818 1.1 cgd }
819 1.1 cgd goto S1;
820 1.1 cgd }
821 1.1 cgd
822 1.1 cgd S1:
823 1.1 cgd switch (*sb) {
824 1.1 cgd
825 1.1 cgd case ' ':
826 1.1 cgd case '\t':
827 1.1 cgd case '\0':
828 1.1 cgd goto OUT; /* end of token */
829 1.1 cgd
830 1.1 cgd case '\\':
831 1.16 lukem INC_CHKCURSOR(sb);
832 1.16 lukem goto S2; /* slurp next character */
833 1.1 cgd
834 1.1 cgd case '"':
835 1.16 lukem INC_CHKCURSOR(sb);
836 1.16 lukem goto S3; /* slurp quoted string */
837 1.1 cgd
838 1.1 cgd default:
839 1.16 lukem *ap = *sb; /* add character to token */
840 1.16 lukem ap++;
841 1.16 lukem INC_CHKCURSOR(sb);
842 1.1 cgd got_one = 1;
843 1.1 cgd goto S1;
844 1.1 cgd }
845 1.1 cgd
846 1.1 cgd S2:
847 1.1 cgd switch (*sb) {
848 1.1 cgd
849 1.1 cgd case '\0':
850 1.1 cgd goto OUT;
851 1.1 cgd
852 1.1 cgd default:
853 1.16 lukem *ap = *sb;
854 1.16 lukem ap++;
855 1.16 lukem INC_CHKCURSOR(sb);
856 1.1 cgd got_one = 1;
857 1.1 cgd goto S1;
858 1.1 cgd }
859 1.1 cgd
860 1.1 cgd S3:
861 1.1 cgd switch (*sb) {
862 1.1 cgd
863 1.1 cgd case '\0':
864 1.1 cgd goto OUT;
865 1.1 cgd
866 1.1 cgd case '"':
867 1.16 lukem INC_CHKCURSOR(sb);
868 1.16 lukem goto S1;
869 1.1 cgd
870 1.1 cgd default:
871 1.16 lukem *ap = *sb;
872 1.16 lukem ap++;
873 1.16 lukem INC_CHKCURSOR(sb);
874 1.1 cgd got_one = 1;
875 1.1 cgd goto S3;
876 1.1 cgd }
877 1.1 cgd
878 1.1 cgd OUT:
879 1.1 cgd if (got_one)
880 1.1 cgd *ap++ = '\0';
881 1.1 cgd argbase = ap; /* update storage pointer */
882 1.1 cgd stringbase = sb; /* update scan pointer */
883 1.1 cgd if (got_one) {
884 1.3 cgd return (tmp);
885 1.1 cgd }
886 1.1 cgd switch (slrflag) {
887 1.1 cgd case 0:
888 1.1 cgd slrflag++;
889 1.1 cgd break;
890 1.1 cgd case 1:
891 1.1 cgd slrflag++;
892 1.28 lukem altarg = NULL;
893 1.1 cgd break;
894 1.1 cgd default:
895 1.1 cgd break;
896 1.1 cgd }
897 1.28 lukem return (NULL);
898 1.1 cgd }
899 1.1 cgd
900 1.1 cgd /*
901 1.65 lukem * Help/usage command.
902 1.1 cgd * Call each command handler with argc == 0 and argv[0] == name.
903 1.1 cgd */
904 1.3 cgd void
905 1.70 lukem help(int argc, char *argv[])
906 1.1 cgd {
907 1.3 cgd struct cmd *c;
908 1.67 lukem char *nargv[1], *p, *cmd;
909 1.65 lukem int isusage;
910 1.1 cgd
911 1.67 lukem cmd = argv[0];
912 1.67 lukem isusage = (strcmp(cmd, "usage") == 0);
913 1.65 lukem if (argc == 0 || (isusage && argc == 1)) {
914 1.67 lukem fprintf(ttyout, "usage: %s [command [...]]\n", cmd);
915 1.65 lukem return;
916 1.65 lukem }
917 1.1 cgd if (argc == 1) {
918 1.16 lukem StringList *buf;
919 1.1 cgd
920 1.69 lukem buf = xsl_init();
921 1.31 lukem fprintf(ttyout,
922 1.31 lukem "%sommands may be abbreviated. Commands are:\n\n",
923 1.16 lukem proxy ? "Proxy c" : "C");
924 1.65 lukem for (c = cmdtab; (p = c->c_name) != NULL; c++)
925 1.65 lukem if (!proxy || c->c_proxy)
926 1.69 lukem xsl_add(buf, p);
927 1.16 lukem list_vertical(buf);
928 1.16 lukem sl_free(buf, 0);
929 1.1 cgd return;
930 1.1 cgd }
931 1.16 lukem
932 1.65 lukem #define HELPINDENT ((int) sizeof("disconnect"))
933 1.16 lukem
934 1.1 cgd while (--argc > 0) {
935 1.3 cgd char *arg;
936 1.16 lukem
937 1.1 cgd arg = *++argv;
938 1.1 cgd c = getcmd(arg);
939 1.1 cgd if (c == (struct cmd *)-1)
940 1.65 lukem fprintf(ttyout, "?Ambiguous %s command `%s'\n",
941 1.67 lukem cmd, arg);
942 1.28 lukem else if (c == NULL)
943 1.65 lukem fprintf(ttyout, "?Invalid %s command `%s'\n",
944 1.67 lukem cmd, arg);
945 1.65 lukem else {
946 1.65 lukem if (isusage) {
947 1.65 lukem nargv[0] = arg;
948 1.65 lukem (*c->c_handler)(0, nargv);
949 1.65 lukem } else
950 1.65 lukem fprintf(ttyout, "%-*s\t%s\n", HELPINDENT,
951 1.65 lukem c->c_name, c->c_help);
952 1.65 lukem }
953 1.1 cgd }
954 1.65 lukem }
955 1.65 lukem
956 1.65 lukem struct option *
957 1.70 lukem getoption(const char *name)
958 1.65 lukem {
959 1.65 lukem const char *p;
960 1.65 lukem struct option *c;
961 1.65 lukem
962 1.65 lukem if (name == NULL)
963 1.65 lukem return (NULL);
964 1.65 lukem for (c = optiontab; (p = c->name) != NULL; c++) {
965 1.65 lukem if (strcasecmp(p, name) == 0)
966 1.65 lukem return (c);
967 1.65 lukem }
968 1.65 lukem return (NULL);
969 1.65 lukem }
970 1.65 lukem
971 1.65 lukem char *
972 1.70 lukem getoptionvalue(const char *name)
973 1.65 lukem {
974 1.65 lukem struct option *c;
975 1.65 lukem
976 1.65 lukem if (name == NULL)
977 1.65 lukem errx(1, "getoptionvalue() invoked with NULL name");
978 1.66 lukem c = getoption(name);
979 1.66 lukem if (c != NULL)
980 1.66 lukem return (c->value);
981 1.65 lukem errx(1, "getoptionvalue() invoked with unknown option `%s'", name);
982 1.72 lukem /* NOTREACHED */
983 1.65 lukem }
984 1.65 lukem
985 1.65 lukem static void
986 1.70 lukem setupoption(char *name, char *value, char *defaultvalue)
987 1.65 lukem {
988 1.65 lukem char *nargv[3];
989 1.65 lukem int overbose;
990 1.65 lukem
991 1.65 lukem nargv[0] = "setupoption()";
992 1.65 lukem nargv[1] = name;
993 1.65 lukem nargv[2] = (value ? value : defaultvalue);
994 1.65 lukem overbose = verbose;
995 1.65 lukem verbose = 0;
996 1.65 lukem setoption(3, nargv);
997 1.65 lukem verbose = overbose;
998 1.12 lukem }
999 1.12 lukem
1000 1.14 lukem void
1001 1.70 lukem usage(void)
1002 1.14 lukem {
1003 1.14 lukem (void)fprintf(stderr,
1004 1.74 lukem "usage: %s [-AadefginpRtvV] [-N netrc] [-o outfile] [-P port] [-r retry]\n"
1005 1.71 lukem " [-T dir,max[,inc][[user@]host [port]]] [host:path[/]]\n"
1006 1.71 lukem " [file:///file] [ftp://[user[:pass]@]host[:port]/path[/]]\n"
1007 1.71 lukem " [http://[user[:pass]@]host[:port]/path] [...]\n"
1008 1.71 lukem " %s -u url file [...]\n", __progname, __progname);
1009 1.14 lukem exit(1);
1010 1.1 cgd }
1011