main.c revision 0b6880ccdcd9dcd62a25f7600853d3880075ab68
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* FTP User Program -- Command Interface.
*/
#define EXTERN
#include "ftp_var.h"
#include <deflt.h> /* macros that make using libcmd easier */
static void usage(void);
static void timeout_sig(int sig);
static void cmdscanner(int top);
static char *slurpstring(void);
extern int use_eprt;
#include <gssapi/gssapi_ext.h>
#define GETOPT_STR "dginpstvET:axfm:"
#define USAGE_STR "[-adfginpstvx] [-m mech] [-T timeout] " \
"[hostname [port]]"
int
{
char *cp;
int c, top;
char homedir[MAXPATHLEN];
char *temp_string = NULL;
return (1);
}
doglob = 1;
interactive = 1;
autologin = 1;
autoauth = 0;
/* by default SYST command will be sent to determine system type */
skipsyst = 0;
fflag = 0;
autoencrypt = 0;
goteof = 0;
mechstr[0] = '\0';
passivemode = 0;
switch (c) {
case 'd':
debug++;
break;
case 'g':
doglob = 0;
break;
case 'i':
interactive = 0;
break;
case 'n':
autologin = 0;
break;
case 'p':
passivemode = 1;
break;
case 't':
trace++;
break;
case 'v':
verbose++;
break;
/* undocumented option: allows testing of EPRT */
case 'E':
use_eprt = 1;
break;
case 'T':
"ftp: bad timeout: \"%s\"\n", optarg);
break;
}
break;
case 'a':
autoauth = 1;
break;
case 'f':
autoauth = 1;
fflag = 1;
break;
case 'm':
autoauth = 1;
if (code != 0)
exit(1);
break;
case 'x':
autoauth = 1;
autoencrypt = 1;
break;
case 's':
skipsyst = 1;
break;
case '?':
default:
usage();
}
}
if (argc > 2)
usage();
/*
* Scan env, then DEFAULTFTPFILE
* for FTP_LS_SENDS_NLST
*/
if (defopen(DEFAULTFTPFILE) == 0) {
/*
* turn off case sensitivity
*/
}
}
if (temp_string != NULL &&
/*
* Set up defaults for FTP.
*/
if (fromatty)
verbose++;
cpend = 0; /* no pending replies */
proxy = 0; /* proxy not active */
if (mechstr[0] == '\0') {
}
/*
* Set up the home directory in case we're globbing.
*/
}
}
if (setjmp(timeralarm)) {
(void) printf("Connection timeout\n");
exit(1);
}
reset_timer();
if (argc > 0) {
int nargc = 0;
char *nargv[4];
return (0);
if (argc > 1)
}
if (top) {
}
for (;;) {
top = 1;
}
}
static void
usage(void)
{
exit(1);
}
void
{
/* The test is just to reduce syscalls if timeouts aren't used */
if (timeout)
}
void
{
if (timeout)
alarm(0);
}
/*ARGSUSED*/
static void
timeout_sig(int sig)
{
}
/*ARGSUSED*/
static void
{
}
/*ARGSUSED*/
void
{
extern int data;
if (connected) {
}
if (data >= 0) {
data = -1;
}
connected = 0;
goteof = 0;
}
pswitch(1);
if (connected) {
}
connected = 0;
goteof = 0;
}
proxflag = 0;
pswitch(0);
}
/*
* Command parser.
*/
static void
cmdscanner(int top)
{
struct cmd *c;
if (!top)
(void) putchar('\n');
for (;;) {
stop_timer();
if (fromatty) {
(void) printf("ftp> ");
}
break;
}
if (line[0] == 0)
break;
/* If not all, just discard rest of line */
;
(void) printf("Line too long\n");
continue;
} else
makeargv();
if (margc == 0) {
continue;
}
if (c == (struct cmd *)-1) {
(void) printf("?Ambiguous command\n");
continue;
}
if (c == 0) {
(void) printf("?Invalid command\n");
continue;
}
(void) printf("Not connected.\n");
continue;
}
reset_timer();
#ifndef CTRL
#define CTRL(c) ((c)&037)
#endif
stop_timer();
break;
}
}
struct cmd *
{
char *p, *q;
return (0);
longest = 0;
nmatches = 0;
found = 0;
for (q = name; *q == *p++; q++)
if (*q == 0) /* exact match? */
return (c);
if (!*q) { /* the name was a prefix */
nmatches = 1;
found = c;
nmatches++;
}
}
if (nmatches > 1)
return ((struct cmd *)-1);
return (found);
}
/*
*/
static int slrflag;
#define MARGV_INC 20
void
makeargv(void)
{
char **argp;
static int margv_size;
margc = 0;
slrflag = 0;
if (!margv) {
fatal("Out of memory");
}
while (*argp++ = slurpstring()) {
margc++;
if (margc == margv_size) {
margv_size += MARGV_INC;
margv_size * sizeof (char *))) == NULL)
fatal("Out of memory");
}
}
}
/*
* Parse string into argbuf;
* implemented with FSM to
* handle quoting and strings
*/
static char *
slurpstring(void)
{
int got_one = 0;
char *sb = stringbase;
int len;
switch (slrflag) { /* and $ as token for macro invoke */
case 0:
slrflag++;
stringbase++;
case 1:
slrflag++;
altarg = stringbase;
break;
default:
break;
}
}
S0:
switch (*sb) {
case '\0':
goto OUT;
case ' ':
case '\t':
default:
switch (slrflag) {
case 0:
slrflag++;
break;
case 1:
slrflag++;
break;
default:
break;
}
goto S1;
}
S1:
switch (*sb) {
case ' ':
case '\t':
case '\0':
goto OUT; /* end of token */
case '\\':
case '"':
default:
len = 1;
got_one = 1;
goto S1;
}
S2:
switch (*sb) {
case '\0':
goto OUT;
default:
len = 1;
got_one = 1;
goto S1;
}
S3:
switch (*sb) {
case '\0':
goto OUT;
case '"':
default:
len = 1;
got_one = 1;
goto S3;
}
OUT:
if (got_one)
*ap++ = '\0';
if (got_one) {
return (tmp);
}
switch (slrflag) {
case 0:
slrflag++;
break;
case 1:
slrflag++;
altarg = (char *)0;
break;
default:
break;
}
return ((char *)0);
}
#define HELPINDENT (sizeof ("directory"))
/*
* Help command.
* Call each command handler with argc == 0 and argv[0] == name.
*/
void
{
struct cmd *c;
if (argc == 1) {
int i, j, w, k;
extern int NCMDS;
(void) printf(
"Commands may be abbreviated. Commands are:\n\n");
}
if (columns == 0)
columns = 1;
for (i = 0; i < lines; i++) {
for (j = 0; j < columns; j++) {
} else if (c->c_name) {
k++) {
(void) putchar(' ');
}
}
(void) printf("\n");
break;
}
while (w < width) {
w = (w + 8) &~ 7;
(void) putchar('\t');
}
}
}
return;
}
while (--argc > 0) {
char *arg;
if (c == (struct cmd *)-1)
else if (c == (struct cmd *)0)
else
}
}
/*
* Call routine with argc, argv set from args (terminated by 0).
*/
void
{
char *argv[10];
int argc = 0;
argc++;
}